Fancy
2024-10-16 7a1ab2693de593026b420fd89b977881eee484ff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package com.dy.pmsTest.command;
 
import com.dy.common.webUtil.QueryResultVo;
import com.dy.pmsGlobal.daoTst.TstCommandMapper;
import com.dy.pmsGlobal.pojoTst.TstCommand;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.common.utils.PojoUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.List;
import java.util.Map;
 
@Slf4j
@Service
public class CommandSv {
    private TstCommandMapper dao;
 
    @Autowired
    public void setDao(TstCommandMapper dao) {
        this.dao = dao;
    }
 
    @Transactional
    public int save(TstCommand command) throws RuntimeException {
        if(dao.selectByNameId(command.id,command.proId,command.name)>0){
            throw new RuntimeException("指令名称已存在");
        }
        int count = dao.insertSelective(command);
        return count;
    }
 
    /**
     * 逻辑删除实体
     * @param id 实体ID
     * @return 影响记录数量
     */
    @Transactional
    public int delete(Long id) {
        return this.dao.deleteLogicById(id);
    }
 
 
    @Transactional
    public int update(TstCommand command) throws RuntimeException {
        if(dao.selectByNameId(command.id,command.proId,command.name)>0){
            throw new RuntimeException("指令名称已存在");
        }
        int count = dao.updateByPrimaryKeySelective(command);
        return count;
    }
 
    public TstCommand selectById(String lineId) {
        return dao.selectByPrimaryKey(Long.valueOf(lineId));
    }
 
    /**
     * 获取列表
     */
    public QueryResultVo<List<TstCommand>> selectSome(QueryVo queryVo) {
        Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo);
 
        //查询符合条件的记录总数
        Long itemTotal = this.dao.selectSomeCount(params);
 
        QueryResultVo<List<TstCommand>> rsVo = new QueryResultVo<>(queryVo.pageSize, queryVo.pageCurr) ;
        //计算分页等信息
        rsVo.calculateAndSet(itemTotal, params);
 
        //查询符合条件的记录
        rsVo.obj = this.dao.selectSome(params) ;
        return rsVo ;
    }
 
    public List<TstCommand> selectAll() {
        return dao.selectAll();
    }
}