Administrator
2024-06-07 818e68817af88d2616f8b61dd5a428d58af40838
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/command/ValveCtrl.java
@@ -17,10 +17,12 @@
import com.dy.pipIrrGlobal.command.ComSupport;
import com.dy.pipIrrGlobal.daoSe.SeVirtualCardMapper;
import com.dy.pipIrrGlobal.pojoRm.RmCommandHistory;
import com.dy.pipIrrGlobal.pojoSe.SeVirtualCard;
import com.dy.pipIrrGlobal.voRm.VoUnclosedValve;
import com.dy.pipIrrGlobal.voSe.VoVirtualCard;
import com.dy.pipIrrWechat.command.dto.ValveClose;
import com.dy.pipIrrWechat.command.dto.ValveOpen;
import com.dy.pipIrrWechat.command.enums.LastOperateENUM;
import com.dy.pipIrrWechat.result.WechatResultCode;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
@@ -32,6 +34,7 @@
import org.springframework.web.bind.annotation.*;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;
import java.util.Objects;
@@ -89,8 +92,6 @@
        if(!setuped) {
            setUp();
        }
// 取水口ID换取水口对象
// 如果取水口为打开状态,则不允许被开阀
        // 虚拟卡ID换虚拟卡对象
        VoVirtualCard vc = commandSv.getVcById(vcId);
@@ -211,10 +212,36 @@
                // 处理回调
                BaseResponse response_CallBack = dealWithCallBack(comId);
                //回调失败
                //回调异常
                if(!response_CallBack.getCode().equals("0001")) {
                    return BaseResponseUtils.buildFail(response_CallBack.getMsg());
                    //return BaseResponseUtils.buildFail(response_CallBack.getContent().toString());
                    // 命令日志执行结果改为失败
                    rmCommandHistory = new RmCommandHistory();
                    rmCommandHistory.setId(comId);
                    rmCommandHistory.setResult((byte)0);
                    commandSv.update(rmCommandHistory);
                    return BaseResponseUtils.buildFail(response_CallBack.getContent().toString());
                }
                // 回调超时
                if(response_CallBack.getContent().toString().equals(WechatResultCode.GET_RESULT_IN_ONE_MINUTE.getMessage())) {
                    /**
                     * 回调超时,暂时认为执行失败
                     * 命令置为失败
                     * 虚拟卡依旧保持使用中的状态
                     */
                    rmCommandHistory = new RmCommandHistory();
                    rmCommandHistory.setId(comId);
                    rmCommandHistory.setResult((byte)0);
                    commandSv.update(rmCommandHistory);
                    //SeVirtualCard virtualCard = new SeVirtualCard();
                    //virtualCard.setId(vcId);
                    //virtualCard.setInUse((byte) 1);
                    //virtualCard.setLastOperate(LastOperateENUM.OPEN_VALVE.getCode());
                    //virtualCard.setLastOperateTime(new Date());
                    //seVirtualCardMapper.updateByPrimaryKeySelective(virtualCard);
                    return BaseResponseUtils.buildFail(WechatResultCode.GET_RESULT_IN_ONE_MINUTE.getMessage());
                }
                // 回调成功,再判断执行是否成功
@@ -231,12 +258,12 @@
                 * 执行成功
                 * 更改虚拟卡状态:是否使用中、最后操作、最后操作时间
                 */
                //SeVirtualCard virtualCard = new SeVirtualCard();
                //virtualCard.setId(vcId);
                //virtualCard.setInUse((byte) 1);
                //virtualCard.setLastOperate(LastOperateENUM.OPEN_VALVE.getCode());
                //virtualCard.setLastOperateTime(new Date());
                //seVirtualCardMapper.updateByPrimaryKeySelective(virtualCard);
                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();
@@ -375,10 +402,37 @@
                // 处理回调
                BaseResponse response_CallBack = dealWithCallBack(comId);
                // 回调失败
                // 回调异常
                if(!response_CallBack.getCode().equals("0001")) {
                    return BaseResponseUtils.buildFail(response_CallBack.getMsg());
                    //return BaseResponseUtils.buildError(WechatResultCode.GET_RESULT_ERROR.getMessage());
                    // 命令日志执行结果改为失败
                    rmCommandHistory = new RmCommandHistory();
                    rmCommandHistory.setId(comId);
                    rmCommandHistory.setResult((byte)0);
                    commandSv.update(rmCommandHistory);
                    return BaseResponseUtils.buildFail(response_CallBack.getContent().toString());
                }
                // 回调超时
                if(response_CallBack.getContent().toString().equals(WechatResultCode.GET_RESULT_IN_ONE_MINUTE.getMessage())) {
                    /**
                     * 回调超时,暂时认为执行失败
                     * 命令置为失败
                     * 虚拟卡依旧保持使用中的状态
                     */
                    rmCommandHistory = new RmCommandHistory();
                    rmCommandHistory.setId(comId);
                    rmCommandHistory.setResult((byte)0);
                    commandSv.update(rmCommandHistory);
                    //Long vcId = seVirtualCardMapper.getVcIdByNum(vcNum);
                    //SeVirtualCard virtualCard = new SeVirtualCard();
                    //virtualCard.setId(vcId);
                    //virtualCard.setInUse((byte) 0);
                    //virtualCard.setLastOperate(LastOperateENUM.OPEN_VALVE.getCode());
                    //virtualCard.setLastOperateTime(new Date());
                    //seVirtualCardMapper.updateByPrimaryKeySelective(virtualCard);
                    return BaseResponseUtils.buildFail(WechatResultCode.GET_RESULT_IN_ONE_MINUTE.getMessage());
                }
                // 回调成功,再判断执行是否成功
@@ -395,13 +449,13 @@
                 * 执行成功
                 * 更改虚拟卡状态:是否使用中、最后操作、最后操作时间
                 */
                //Long vcId = seVirtualCardMapper.getVcIdByNum(vcNum);
                //SeVirtualCard virtualCard = new SeVirtualCard();
                //virtualCard.setId(vcId);
                //virtualCard.setInUse((byte) 0);
                //virtualCard.setLastOperate(LastOperateENUM.OPEN_VALVE.getCode());
                //virtualCard.setLastOperateTime(new Date());
                //seVirtualCardMapper.updateByPrimaryKeySelective(virtualCard);
                Long vcId = seVirtualCardMapper.getVcIdByNum(vcNum);
                SeVirtualCard virtualCard = new SeVirtualCard();
                virtualCard.setId(vcId);
                virtualCard.setInUse((byte) 0);
                virtualCard.setLastOperate(LastOperateENUM.OPEN_VALVE.getCode());
                virtualCard.setLastOperateTime(new Date());
                seVirtualCardMapper.updateByPrimaryKeySelective(virtualCard);
                // 回调返回的内容
                Data myData = (Data)response_CallBack.getContent();