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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package com.dy.pipIrrRemote.monitor.common;
 
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.dy.pipIrrGlobal.command.CommandSv;
import com.dy.pipIrrGlobal.daoPr.PrCommonIntakesMapper;
import com.dy.pipIrrGlobal.daoPr.PrControllerMapper;
import com.dy.pipIrrGlobal.daoRm.RmCommandHistoryMapper;
import com.dy.pipIrrGlobal.pojoPr.PrCommonIntakes;
import com.dy.pipIrrGlobal.pojoPr.PrController;
import com.dy.pipIrrGlobal.pojoRm.RmCommandHistory;
import com.dy.pipIrrGlobal.voRm.VoUnclosedParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.Date;
 
/**
 * @Author: liurunyu
 * @Date: 2025/5/9 14:45
 * @Description
 */
public class ComSv extends CommandSv {
 
    @Autowired
    protected PrControllerMapper prControllerDao ;
    @Autowired
    protected RmCommandHistoryMapper rmCommandHistoryDao ;
    @Autowired
    private PrCommonIntakesMapper prCommonIntakesDao;
 
    public PrController getRtu(Long intakeId){
        return this.getRtu(prControllerDao, intakeId);
    }
    /**
     * 创建命令日志对象
     *
     * @param comId       主键
     * @param commandCode 功能码
     * @param rtuAddr     阀控器地址
     * @param protocol    通讯协议名称
     * @param param       参数数据
     * @param operator    操作员
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public RmCommandHistory saveComHistoryPo(Long comId,
                                             String protocol,
                                             String commandCode,
                                             String commandName,
                                             Long intakeId,
                                             String rtuAddr,
                                             Object param,
                                             Long operator) {
        return this.saveComHistoryPo(rmCommandHistoryDao, comId, protocol, commandCode, commandName, intakeId, rtuAddr, param, operator) ;
    }
 
 
    /**
     * 添加常用取水口或更新使用信息
     * @param operatorId
     * @param intakeId
     * @return
     */
    public PrCommonIntakes addOrUpdateOftenUseIntake(Long operatorId, Long intakeId) {
        PrCommonIntakes po = prCommonIntakesDao.selectByOperatorAndIntake(operatorId, intakeId);
        if(po == null) {
            po = new PrCommonIntakes();
            po.setOperatorId(operatorId);
            po.setIntakeId(intakeId);
            po.setLastUsedTime(new Date());
            po.setUsageCount(1);
            prCommonIntakesDao.insert(po);
        }else{
            po.setLastUsedTime(new Date());
            po.setUsageCount(po.getUsageCount() + 1);
            prCommonIntakesDao.updateByPrimaryKeySelective(po);
        }
        return po ;
    }
 
 
    /**
     * 根据取水口ID获取该取水口未关阀参数,平台选择取水口关阀使用
     * @param intakeId
     * @return
     */
    public VoUnclosedParam selectUncloseParam(Long intakeId, String rtuAddr) {
        JSONArray jsonArr = new JSONArray();
        JSONObject jsonObj = new JSONObject();
        jsonObj.put("rtuAddr", rtuAddr);
        jsonObj.put("isOnLine", true);
        jsonArr.add(jsonObj);
        return rmCommandHistoryDao.getUncloseParam(jsonArr.toJSONString(), intakeId);
    }
}