Administrator
2024-06-06 1376d5627f5f41fce93d51235f5bcc1255586184
pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/valve/ValveCtrl.java
@@ -17,11 +17,13 @@
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.pipIrrRemote.common.CommandSv;
import com.dy.pipIrrRemote.common.dto.ValveClose;
import com.dy.pipIrrRemote.common.dto.ValveOpen;
import com.dy.pipIrrRemote.common.enums.LastOperateENUM;
import com.dy.pipIrrRemote.result.RemoteResultCode;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
@@ -33,6 +35,7 @@
import org.springframework.web.bind.annotation.*;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;
import java.util.Objects;
@@ -90,8 +93,6 @@
        if(!setuped) {
            setUp();
        }
// 取水口ID换取水口对象
// 如果取水口为打开状态,则不允许被开阀
        // 虚拟卡ID换虚拟卡对象
        VoVirtualCard vc = commandSv.getVcById(vcId);
@@ -182,8 +183,15 @@
                //seVirtualCardMapper.updateByPrimaryKeySelective(virtualCard);
                // 回调返回的内容
                Data myData = (Data)response_CallBack.getContent();
                return BaseResponseUtils.buildSuccess(myData) ;
                //Data myData = (Data)response_CallBack.getContent();
                //return BaseResponseUtils.buildSuccess(myData);
                JSONObject job_response = new JSONObject();
                job_response.put("rtuAddr", rtuAddr);
                job_response.put("vcNum", vc.getVcNum());
                job_response.put("orderNo", orderNo);
                //job_response.put("operator", operator);
                return BaseResponseUtils.buildSuccess(job_response);
            } else {
                // 请求失败
                JSONObject job_param = response_SendCom.getJSONObject("content").getJSONObject("param");
@@ -217,15 +225,29 @@
                // 处理回调
                BaseResponse response_CallBack = dealWithCallBack(comId);
                //回调失败
                //回调异常
                if(!response_CallBack.getCode().equals("0001")) {
                    // 命令日志执行结果改为失败
                    //rmCommandHistory = new RmCommandHistory();
                    //rmCommandHistory.setId(comId);
                    //rmCommandHistory.setResult((byte)0);
                    //commandSv.updateCommandResult(rmCommandHistory);
                    return BaseResponseUtils.buildFail(response_CallBack.getMsg());
                    //return BaseResponseUtils.buildFail(response_CallBack.getContent().toString());
                    rmCommandHistory = new RmCommandHistory();
                    rmCommandHistory.setId(comId);
                    rmCommandHistory.setResult((byte)0);
                    commandSv.updateCommandResult(rmCommandHistory);
                    return BaseResponseUtils.buildFail(response_CallBack.getContent().toString());
                }
                // 回调超时
                if(response_CallBack.getContent().toString().equals(RemoteResultCode.GET_RESULT_IN_ONE_MINUTE.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);
                    return BaseResponseUtils.buildSuccess(RemoteResultCode.GET_RESULT_IN_ONE_MINUTE.getMessage());
                }
                // 回调成功,再判断执行是否成功
@@ -242,16 +264,24 @@
                 * 执行成功
                 * 更改虚拟卡状态:是否使用中、最后操作、最后操作时间
                 */
                //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();
                return BaseResponseUtils.buildSuccess(myData) ;
                //Data myData = (Data)response_CallBack.getContent();
                //return BaseResponseUtils.buildSuccess(myData) ;
                JSONObject job_response = new JSONObject();
                job_response.put("rtuAddr", rtuAddr);
                job_response.put("vcNum", vc.getVcNum());
                job_response.put("orderNo", orderNo);
                //job_response.put("operator", operator);
                return BaseResponseUtils.buildSuccess(job_response);
            } else {
                // 请求失败
                JSONObject job_param = response_SendCom.getJSONObject("content").getJSONObject("param");
@@ -391,15 +421,30 @@
                // 处理回调
                BaseResponse response_CallBack = dealWithCallBack(comId);
                // 回调失败
                // 回调异常
                if(!response_CallBack.getCode().equals("0001")) {
                    // 命令日志执行结果改为失败
                    //rmCommandHistory = new RmCommandHistory();
                    //rmCommandHistory.setId(comId);
                    //rmCommandHistory.setResult((byte)0);
                    //commandSv.updateCommandResult(rmCommandHistory);
                    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.updateCommandResult(rmCommandHistory);
                    return BaseResponseUtils.buildFail(response_CallBack.getContent().toString());
                }
                // 回调超时
                if(response_CallBack.getContent().toString().equals(RemoteResultCode.GET_RESULT_IN_ONE_MINUTE.getMessage())) {
                    /**
                     * 糊掉超时,暂时认为执行成功
                     * 更改虚拟卡状态:是否使用中、最后操作、最后操作时间
                     */
                    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.buildSuccess(RemoteResultCode.GET_RESULT_IN_ONE_MINUTE.getMessage());
                }
                // 回调成功,再判断执行是否成功
@@ -416,13 +461,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();