Administrator
2024-05-30 11c7a9b0270cbf529ebb5e434b5fe0593dd209f0
pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/valve/ValveCtrl.java
@@ -1,16 +1,19 @@
package com.dy.pipIrrRemote.valve;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.dy.common.aop.SsoAop;
import com.dy.common.mw.protocol.Command;
import com.dy.common.mw.protocol.Data;
import com.dy.common.mw.protocol.p206V202404.CodeV202404;
import com.dy.common.mw.protocol.p206V202404.downVos.ComCd92_A2Vo;
import com.dy.common.mw.protocol.p206V202404.downVos.ComCd93_A3Vo;
import com.dy.common.util.IDLongGenerator;
import com.dy.common.webUtil.BaseResponse;
import com.dy.common.webUtil.BaseResponseUtils;
import com.dy.pipIrrGlobal.daoPr.PrWaterPriceMapper;
import com.dy.pipIrrGlobal.daoRm.RmCommandHistoryMapper;
import com.dy.pipIrrGlobal.daoSe.SeVirtualCardMapper;
import com.dy.pipIrrGlobal.pojoPr.PrController;
import com.dy.pipIrrGlobal.pojoRm.RmCommandHistory;
import com.dy.pipIrrGlobal.pojoSe.SeVirtualCard;
import com.dy.pipIrrGlobal.voRm.VoUnclosedValve;
@@ -46,7 +49,7 @@
 */
@Slf4j
@Tag(name = "分水房管理", description = "分水房操作")
@Tag(name = "阀门管理", description = "阀门操作")
@RestController
@RequestMapping(path="valve")
@RequiredArgsConstructor
@@ -55,7 +58,7 @@
    private final CommandSv commandSv;
    private final SeVirtualCardMapper seVirtualCardMapper;
    private final PrWaterPriceMapper prWaterPriceMapper;
    private final RmCommandHistoryMapper rmCommandHistoryMapper;
    private final IDLongGenerator idLongGenerator;
    /**
     * 远程开阀(平台、APP)
@@ -76,7 +79,7 @@
        Long vcId = valve.getVcId();
        Integer userType = valve.getUserType();
        Long operator = valve.getOperator();
        String comId = null;
        Long comId = idLongGenerator.generate();
        // 获取系统参数
        if(!setuped) {
@@ -88,11 +91,13 @@
        // 获取水价
        Double waterPrice = prWaterPriceMapper.getPrice();
        // 取水口ID换阀控器地址
        String rtuAddr = commandSv.getRtuAddrByIntakeId(intakeId);
        if(rtuAddr == null || rtuAddr.length() == 0) {
            return BaseResponseUtils.buildError(RemoteResultCode.RTU_ADDR_CANNOT_BE_NULL.getMessage());
        // 取水口ID换阀控器地址及通讯协议
        PrController prController = commandSv.getControllerByIntakeId(intakeId);
        if(prController == null) {
            return BaseResponseUtils.buildError(RemoteResultCode.RTU_NOT_EXIST.getMessage());
        }
        String rtuAddr = prController.getRtuAddr();
        String protocol = prController.getProtocol();
        // 生成订单号
        LocalDateTime dateTime = LocalDateTime.now();
@@ -106,7 +111,7 @@
        String orderNo = dtf.format(dateTime) + sb.toString();
        String commandCode = null;
        if(protocolName.equals("p206V202404")) {
        if(protocol.equals("p206V202404")) {
            // 获取功能码
            if(userType == 1) {
                // 平台开阀
@@ -127,13 +132,40 @@
            param.elePrice = 0.0;
            param.orderNo = orderNo;
            // 创建命令日志对象并添加到数据库中
            RmCommandHistory rmCommandHistory = getComHistory(commandCode, rtuAddr, param, operator);
            comId = commandSv.insert(rmCommandHistory);
            // 构造命令
            Command com = command(comId, commandCode, rtuAddr, protocol, param);
            // 构造并发送命令
            Command com = command(comId, commandCode, rtuAddr, param);
            sendCom2Mw(com);
            // 发送命令
            JSONObject response_SendCom= (JSONObject) JSON.toJSON(sendCom2Mw(com));
            if(response_SendCom != null && response_SendCom.getString("code").equals("0001")) {
                // 请求成功
                // 创建命令日志对象并添加到数据库中
                RmCommandHistory rmCommandHistory = getComHistory(comId, commandCode, intakeId, rtuAddr, protocol, param, operator);
                commandSv.insert(rmCommandHistory);
                // 处理回调
                BaseResponse response_CallBack = dealWithCallBack(comId);
                if(!response_CallBack.getCode().equals("0001")) {
                    return BaseResponseUtils.buildError(RemoteResultCode.GET_RESULT_ERROR.getMessage());
                }
                // 更改虚拟卡状态:是否使用中、最后操作、最后操作时间
                SeVirtualCard virtualCard = new SeVirtualCard();
                virtualCard.setId(vcId);
                virtualCard.setInUse((byte) 1);
                virtualCard.setLastOperate(LastOperateENUM.OPEN_VALVE.getCode());
                virtualCard.setLastOperateTime(new Date());
                seVirtualCardMapper.updateByPrimaryKeySelective(virtualCard);
                // 回调返回的内容
                Data myData = (Data)response_CallBack.getContent();
                return BaseResponseUtils.buildSuccess(myData) ;
            } else {
                // 请求失败
                JSONObject job_param = response_SendCom.getJSONObject("content").getJSONObject("param");
                return BaseResponseUtils.buildFail(job_param.getString("message"));
            }
        } else {
            // 获取功能码
            if(userType == 1) {
@@ -148,30 +180,15 @@
            ComCd92_A2Vo param = new ComCd92_A2Vo();
            // 创建命令日志对象并添加到数据库中
            RmCommandHistory rmCommandHistory = getComHistory(commandCode, rtuAddr, param, operator);
            comId = commandSv.insert(rmCommandHistory);
            //RmCommandHistory rmCommandHistory = getComHistory(commandCode, rtuAddr, protocol, param, operator);
            //comId = commandSv.insert(rmCommandHistory);
            // 构造并发送命令
            Command com = command(comId, commandCode, rtuAddr, param);
            Command com = command(comId, commandCode, rtuAddr, protocol, param);
            sendCom2Mw(com);
            return BaseResponseUtils.buildSuccess();
        }
        // 处理回调
        BaseResponse response = dealWithCallBack(comId);
        if(!response.getCode().equals("0001")) {
            return BaseResponseUtils.buildError(RemoteResultCode.GET_RESULT_ERROR.getMessage());
        }
        // 更改虚拟卡状态:是否使用中、最后操作、最后操作时间
        SeVirtualCard virtualCard = new SeVirtualCard();
        virtualCard.setId(vcId);
        virtualCard.setInUse((byte) 1);
        virtualCard.setLastOperate(LastOperateENUM.OPEN_VALVE.getCode());
        virtualCard.setLastOperateTime(new Date());
        seVirtualCardMapper.updateByPrimaryKeySelective(virtualCard);
        Data myData = (Data)response.getContent();
        return BaseResponseUtils.buildSuccess(myData) ;
    }
    /**
@@ -194,15 +211,23 @@
        String orderNo = valve.getOrderNo();
        Integer userType = valve.getUserType();
        Long operator = valve.getOperator();
        String comId = null;
        Long comId = idLongGenerator.generate();
        // 获取系统参数
        if(!setuped) {
            setUp();
        }
        // 阀控器地址换取水口ID和通讯协议
        PrController prController = commandSv.getControllerByRtuAddr(rtuAddr);
        if(prController == null) {
            return BaseResponseUtils.buildError(RemoteResultCode.RTU_NOT_EXIST.getMessage());
        }
        Long intakeId = prController.getIntakeId();
        String protocol = prController.getProtocol();
        String commandCode = null;
        if(protocolName.equals("p206V202404")) {
        if(protocol.equals("p206V202404")) {
            // 获取功能码
            if (userType == 1) {
                // 平台关阀
@@ -219,13 +244,41 @@
            param.icCardNo = vcNum;
            param.orderNo = orderNo;
            // 创建命令日志对象并添加到数据库中
            RmCommandHistory rmCommandHistory = getComHistory(commandCode, rtuAddr, param, operator);
            comId = commandSv.insert(rmCommandHistory);
            // 构造命令
            Command com = command(comId, commandCode, rtuAddr, protocol, param);
            // 构造并发送命令
            Command com = command(comId, commandCode, rtuAddr, param);
            sendCom2Mw(com);
            // 发送命令
            JSONObject response_SendCom= (JSONObject) JSON.toJSON(sendCom2Mw(com));
            if(response_SendCom != null && response_SendCom.getString("code").equals("0001")) {
                // 请求成功
                // 创建命令日志对象并添加到数据库中
                RmCommandHistory rmCommandHistory = getComHistory(comId, commandCode, intakeId, rtuAddr, protocol, param, operator);
                commandSv.insert(rmCommandHistory);
                // 处理回调
                BaseResponse response_CallBack = dealWithCallBack(comId);
                if(!response_CallBack.getCode().equals("0001")) {
                    return BaseResponseUtils.buildError(RemoteResultCode.GET_RESULT_ERROR.getMessage());
                }
                // 更改虚拟卡状态:是否使用中、最后操作、最后操作时间
                Long vcId = seVirtualCardMapper.getVcIdByNum(vcNum);
                SeVirtualCard virtualCard = new SeVirtualCard();
                virtualCard.setId(vcId);
                virtualCard.setInUse((byte) 1);
                virtualCard.setLastOperate(LastOperateENUM.OPEN_VALVE.getCode());
                virtualCard.setLastOperateTime(new Date());
                seVirtualCardMapper.updateByPrimaryKeySelective(virtualCard);
                // 回调返回的内容
                Data myData = (Data)response_CallBack.getContent();
                return BaseResponseUtils.buildSuccess(myData) ;
            } else {
                // 请求失败
                JSONObject job_param = response_SendCom.getJSONObject("content").getJSONObject("param");
                return BaseResponseUtils.buildFail(job_param.getString("message"));
            }
        } else {
            // 获取功能码
            if (userType == 1) {
@@ -244,11 +297,11 @@
            param.orderNo = orderNo;
            // 创建命令日志对象并添加到数据库中
            RmCommandHistory rmCommandHistory = getComHistory(commandCode, rtuAddr, param, operator);
            RmCommandHistory rmCommandHistory = getComHistory(comId, commandCode, intakeId, rtuAddr, protocol, param, operator);
            comId = commandSv.insert(rmCommandHistory);
            // 构造并发送命令
            Command com = command(comId, commandCode, rtuAddr, param);
            Command com = command(comId, commandCode, rtuAddr, protocol, param);
            sendCom2Mw(com);
        }