|  |  |  | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.pojoSe.SeVirtualCard; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.voRm.VoUnclosedValve; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.voSe.VoVirtualCard; | 
|---|
|  |  |  | import com.dy.pipIrrSell.virtualCard.enums.LastOperateENUM; | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | 
|---|
|  |  |  | public BaseResponse<Boolean> open(@RequestBody @Valid ValveOpen valve, BindingResult bindingResult) { | 
|---|
|  |  |  | DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyMMddHHmmss"); | 
|---|
|  |  |  | if(bindingResult != null && bindingResult.hasErrors()){ | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Long intakeId = valve.getIntakeId(); | 
|---|
|  |  |  | 
|---|
|  |  |  | if(vcId == null) { | 
|---|
|  |  |  | vcId = commandSv.getVcIdByIntakeId(intakeId); | 
|---|
|  |  |  | if(vcId == null) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(WechatResultCode.PLEASE_SELECT_A_VC.getMessage()); | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(WechatResultCode.PLEASE_SELECT_A_VC.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | if(!setuped) { | 
|---|
|  |  |  | setUp(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 取水口ID换取水口对象 | 
|---|
|  |  |  | // 如果取水口为打开状态,则不允许被开阀 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 虚拟卡ID换虚拟卡对象 | 
|---|
|  |  |  | VoVirtualCard vc = commandSv.getVcById(vcId); | 
|---|
|  |  |  | if(vc == null) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(WechatResultCode.PLEASE_SELECT_A_VC.getMessage()); | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(WechatResultCode.PLEASE_SELECT_A_VC.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(vc.getInUse() == 1) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(WechatResultCode.IN_USE_VC_CANNOT_OPEN_VALVE.getMessage()); | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(WechatResultCode.IN_USE_VC_CANNOT_OPEN_VALVE.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 获取水价 | 
|---|
|  |  |  | 
|---|
|  |  |  | // 取水口ID换阀控器地址及通讯协议 | 
|---|
|  |  |  | JSONObject job_rtu = getRtu(intakeId, null); | 
|---|
|  |  |  | if(job_rtu == null) { | 
|---|
|  |  |  | return BaseResponseUtils.buildError(WechatResultCode.RTU_NOT_EXIST.getMessage()); | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(WechatResultCode.RTU_NOT_EXIST.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String rtuAddr = job_rtu.getString("rtuAddr"); | 
|---|
|  |  |  | String protocol = job_rtu.getString("protocol"); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 回调失败 | 
|---|
|  |  |  | if(!response_CallBack.getCode().equals("0001")) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(response_CallBack.getMsg()); | 
|---|
|  |  |  | //return BaseResponseUtils.buildFail(response_CallBack.getContent().toString()); | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(response_CallBack.getMsg()); | 
|---|
|  |  |  | //return BaseResponseUtils.buildErrorMsg(response_CallBack.getContent().toString()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 回调成功,再判断执行是否成功 | 
|---|
|  |  |  | 
|---|
|  |  |  | System.out.println(job_subData); | 
|---|
|  |  |  | Boolean dealResult = job_subData.getBoolean("success"); | 
|---|
|  |  |  | if(!dealResult) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(response_CallBack.getContent().toString()); | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(response_CallBack.getContent().toString()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 执行成功 | 
|---|
|  |  |  | * 更改虚拟卡状态:是否使用中、最后操作、最后操作时间 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | 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(); | 
|---|
|  |  |  | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | // 请求失败 | 
|---|
|  |  |  | JSONObject job_param = response_SendCom.getJSONObject("content").getJSONObject("param"); | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(job_param.getString("message")); | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(job_param.getString("message")); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else if(protocol.equals("p206V1_0_1")) { | 
|---|
|  |  |  | // 获取功能码 | 
|---|
|  |  |  | 
|---|
|  |  |  | // 处理回调 | 
|---|
|  |  |  | 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.buildErrorMsg(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.buildErrorMsg(WechatResultCode.GET_RESULT_IN_ONE_MINUTE.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 回调成功,再判断执行是否成功 | 
|---|
|  |  |  | 
|---|
|  |  |  | System.out.println(job_subData); | 
|---|
|  |  |  | Boolean dealResult = job_subData.getBoolean("success"); | 
|---|
|  |  |  | if(!dealResult) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(response_CallBack.getContent().toString()); | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(response_CallBack.getContent().toString()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | // 请求失败 | 
|---|
|  |  |  | JSONObject job_param = response_SendCom.getJSONObject("content").getJSONObject("param"); | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(job_param.getString("message")); | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(job_param.getString("message")); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("系统暂不支持该协议"); | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg("系统暂不支持该协议"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | public BaseResponse<Boolean> close(@RequestBody @Valid ValveClose valve, BindingResult bindingResult) { | 
|---|
|  |  |  | DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyMMddHHmmss"); | 
|---|
|  |  |  | if(bindingResult != null && bindingResult.hasErrors()){ | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String rtuAddr = valve.getRtuAddr(); | 
|---|
|  |  |  | 
|---|
|  |  |  | // 阀控器地址换取水口ID和通讯协议 | 
|---|
|  |  |  | JSONObject job_rtu = getRtu(null, rtuAddr); | 
|---|
|  |  |  | if(job_rtu == null) { | 
|---|
|  |  |  | return BaseResponseUtils.buildError(WechatResultCode.RTU_NOT_EXIST.getMessage()); | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(WechatResultCode.RTU_NOT_EXIST.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Long intakeId = job_rtu.getLong("intakeId"); | 
|---|
|  |  |  | String protocol = job_rtu.getString("protocol"); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 回调失败 | 
|---|
|  |  |  | if(!response_CallBack.getCode().equals("0001")) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(response_CallBack.getMsg()); | 
|---|
|  |  |  | //return BaseResponseUtils.buildError(WechatResultCode.GET_RESULT_ERROR.getMessage()); | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(response_CallBack.getMsg()); | 
|---|
|  |  |  | //return BaseResponseUtils.buildErrorMsg(WechatResultCode.GET_RESULT_ERROR.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 回调成功,再判断执行是否成功 | 
|---|
|  |  |  | 
|---|
|  |  |  | System.out.println(job_subData); | 
|---|
|  |  |  | Boolean dealResult = job_subData.getBoolean("success"); | 
|---|
|  |  |  | if(!dealResult) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(response_CallBack.getContent().toString()); | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(response_CallBack.getContent().toString()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 执行成功 | 
|---|
|  |  |  | * 更改虚拟卡状态:是否使用中、最后操作、最后操作时间 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | 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(); | 
|---|
|  |  |  | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | // 请求失败 | 
|---|
|  |  |  | JSONObject job_param = response_SendCom.getJSONObject("content").getJSONObject("param"); | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(job_param.getString("message")); | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(job_param.getString("message")); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else if(protocol.equals("p206V1_0_1")) { | 
|---|
|  |  |  | // 获取功能码 | 
|---|
|  |  |  | 
|---|
|  |  |  | // 处理回调 | 
|---|
|  |  |  | 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.buildErrorMsg(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.buildErrorMsg(WechatResultCode.GET_RESULT_IN_ONE_MINUTE.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 回调成功,再判断执行是否成功 | 
|---|
|  |  |  | 
|---|
|  |  |  | System.out.println(job_subData); | 
|---|
|  |  |  | Boolean dealResult = job_subData.getBoolean("success"); | 
|---|
|  |  |  | if(!dealResult) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(response_CallBack.getContent().toString()); | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(response_CallBack.getContent().toString()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | // 请求失败 | 
|---|
|  |  |  | JSONObject job_param = response_SendCom.getJSONObject("content").getJSONObject("param"); | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(job_param.getString("message")); | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(job_param.getString("message")); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("系统暂不支持该协议"); | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg("系统暂不支持该协议"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @GetMapping(path = "/get") | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | //@SsoAop() | 
|---|
|  |  |  | public BaseResponse<List<VoUnclosedValve>> getUnclosedValves(@RequestParam Long operator){ | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | List<VoUnclosedValve> res = commandSv.getUnclosedValves(operator); | 
|---|