zhubaomin
2024-11-13 7d387aa126262ee12068f5b31aad661501edd286
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/command/ComSupport.java
@@ -5,7 +5,7 @@
import com.dy.common.mw.protocol.Command;
import com.dy.common.mw.protocol.CommandType;
import com.dy.common.mw.protocol.Data;
import com.dy.common.mw.protocol.p206V1_0_0.CodeV1_0_1;
import com.dy.common.mw.protocol.p206V1.CodeV1;
import com.dy.common.webUtil.BaseResponse;
import com.dy.common.webUtil.BaseResponseUtils;
import com.dy.pipIrrGlobal.command.dto.Param;
@@ -30,12 +30,11 @@
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
@@ -329,35 +328,96 @@
         * 如果是开关阀:更改虚拟卡状态:是否使用中、最后操作、最后操作时间
         * 更新执行结果、返回结果时间、结果内容
         * 返回回调内容
         * ***************************** 虚拟卡使用状态不依赖开关阀意愿,依赖开关阀成功与否
         */
        if (comType != null) {
            SeVirtualCard virtualCard = new SeVirtualCard();
            virtualCard.setId(vcId);
            if (comType == 1) {
                virtualCard.setInUse((byte) 1);
            } else {
                virtualCard.setInUse((byte) 0);
            }
            virtualCard.setLastOperate(LastOperateENUM.OPEN_VALVE.getCode());
            virtualCard.setLastOperateTime(new Date());
            seVirtualCardMapper.updateByPrimaryKeySelective(virtualCard);
        }
        //if (comType != null) {
        //    SeVirtualCard virtualCard = new SeVirtualCard();
        //    virtualCard.setId(vcId);
        //    if (comType == 1) {
        //        virtualCard.setInUse((byte) 1);
        //    } else {
        //        virtualCard.setInUse((byte) 0);
        //    }
        //    virtualCard.setLastOperate(LastOperateENUM.OPEN_VALVE.getCode());
        //    virtualCard.setLastOperateTime(new Date());
        //    seVirtualCardMapper.updateByPrimaryKeySelective(virtualCard);
        //}
        // 如果是开发命令(92-平台开阀,91-小程序开阀),返回结果中添加阀控器地址、虚拟卡编号、订单号
        //if(commandCode.equals("92") || commandCode.equals("97")) {
        if(commandCode.equals(CodeV1_0_1.cd_92) || commandCode.equals(CodeV1_0_1.cd_97)
                || commandCode.equals(CodeV1_0_1.cd_99) || commandCode.equals(CodeV1_0_1.cd_A0)
                || commandCode.equals(CodeV1_0_1.cd_A1) || commandCode.equals(CodeV1_0_1.cd_A2)) {
        if(commandCode.equals(CodeV1.cd_92) || commandCode.equals(CodeV1.cd_97)
                || commandCode.equals(CodeV1.cd_99) || commandCode.equals(CodeV1.cd_A0)
                || commandCode.equals(CodeV1.cd_A1) || commandCode.equals(CodeV1.cd_A2)) {
            JSONObject job_response = (JSONObject) JSON.toJSON(response_CallBack);
            JSONObject job_param = (JSONObject) JSON.toJSON(param);
            JSONObject job_data = job_response.getJSONObject("content").getJSONObject("data");
            if(!job_data.getBoolean("success")) {
                // 开关阀失败
                // 开关阀失败,更新命令执行状态及虚拟卡状态
                rmCommandHistory = new RmCommandHistory();
                rmCommandHistory.setComId(comId);
                rmCommandHistory.setResult((byte) 0);
                rmCommandHistoryMapper.updateByPrimaryKeySelective(rmCommandHistory);
                // 开阀失败则解除占用,关阀失败则占用
                if (comType != null) {
                    SeVirtualCard virtualCard = new SeVirtualCard();
                    virtualCard.setId(vcId);
                    if (comType == 1) {
                        virtualCard.setInUse((byte) 0);
                        virtualCard.setIntakeId(null);
                        virtualCard.setOpenTime(null);
                    } else {
                        virtualCard.setInUse((byte) 1);
                        virtualCard.setIntakeId(intakeId);
                    }
                    virtualCard.setLastOperate(LastOperateENUM.OPEN_VALVE.getCode());
                    virtualCard.setLastOperateTime(new Date());
                    seVirtualCardMapper.updateByPrimaryKeySelective(virtualCard);
                }
                response_CallBack.setCode("10003");
                response_CallBack.setMsg(CommandResultCode.OPEN_CLOSE_FAIL.getMessage());
                response_CallBack.setSuccess(false);
            }else {
                // 开关阀成功
                // 开关阀成功,更新命令执行状态及虚拟卡状态
                rmCommandHistory = new RmCommandHistory();
                rmCommandHistory.setComId(comId);
                rmCommandHistory.setResult((byte) 1);
                rmCommandHistoryMapper.updateByPrimaryKeySelective(rmCommandHistory);
                // 开阀成功则占用,关阀成功不占用
                if (comType != null) {
                    SeVirtualCard virtualCard = new SeVirtualCard();
                    virtualCard.setId(vcId);
                    if (comType == 1) {
                        virtualCard.setInUse((byte) 1);
                        virtualCard.setIntakeId(intakeId);
                        // 如果是计划开阀,从命令日志中获取计划时间,否则取当前时间
                        if(commandCode.equals(CodeV1.cd_A1) || commandCode.equals(CodeV1.cd_A2)) {
                            // 计划开阀
                            Date openTime = null;
                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                            try {
                                openTime = sdf.parse(rmCommandHistoryMapper.getTimeByCommId(comId));
                            }catch (ParseException e) {
                            }
                            virtualCard.setOpenTime(openTime);
                        }else {
                            // 非计划开阀
                            virtualCard.setOpenTime(new Date());
                        }
                    } else {
                        virtualCard.setInUse((byte) 0);
                        virtualCard.setIntakeId(null);
                    }
                    virtualCard.setLastOperate(LastOperateENUM.OPEN_VALVE.getCode());
                    virtualCard.setLastOperateTime(new Date());
                    seVirtualCardMapper.updateByPrimaryKeySelective(virtualCard);
                }
                job_data.remove("success");
                job_data.put("intakeId", intakeId);
                job_data.put("rtuAddr", rtuAddr);