|  |  |  | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.command.enums.LastOperateENUM; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.command.result.CommandResultCode; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.daoBa.BaSettingsMapper; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.daoIr.IrIntakeOperateMapper; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.daoPr.PrCommonIntakesMapper; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.daoPr.PrControllerMapper; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.daoRm.RmCommandHistoryMapper; | 
|---|
|  |  |  | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private PrCommonIntakesMapper prCommonIntakesMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private IrIntakeOperateMapper irIntakeOperateMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static ComSupport comSupport; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | Object param = po.getParam(); | 
|---|
|  |  |  | String rtuResultSendWebUrl = po.getRtuResultSendWebUrl(); | 
|---|
|  |  |  | Long operator = po.getOperator(); | 
|---|
|  |  |  | Byte openType = po.getOpenType(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 构造命令 | 
|---|
|  |  |  | Command com = command(comId, commandCode, rtuAddr, protocol, rtuResultSendWebUrl, param); | 
|---|
|  |  |  | 
|---|
|  |  |  | rmCommandHistory.setResult((byte) 0); | 
|---|
|  |  |  | rmCommandHistoryMapper.updateByPrimaryKeySelective(rmCommandHistory); | 
|---|
|  |  |  | //return BaseResponseUtils.buildErrorMsg(response_CallBack.getContent().toString()); | 
|---|
|  |  |  | irIntakeOperateMapper.updateByCommandId(comId, (byte)2, response_CallBack.getMsg()); | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(response_CallBack.getMsg()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | rmCommandHistory.setComId(comId); | 
|---|
|  |  |  | rmCommandHistory.setResult((byte) 0); | 
|---|
|  |  |  | rmCommandHistoryMapper.updateByPrimaryKeySelective(rmCommandHistory); | 
|---|
|  |  |  | irIntakeOperateMapper.updateByCommandId(comId, (byte)2, "回调超时"); | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(CommandResultCode.GET_RESULT_IN_ONE_MINUTE.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | 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(openType != null && openType == 1 ) { | 
|---|
|  |  |  | irIntakeOperateMapper.updateByCommandId(comId, (byte)2, "开阀失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 开阀失败则解除占用,关阀失败则占用 | 
|---|
|  |  |  | if (comType != null) { | 
|---|
|  |  |  | 
|---|
|  |  |  | if (comType == 1) { | 
|---|
|  |  |  | virtualCard.setInUse((byte) 0); | 
|---|
|  |  |  | virtualCard.setIntakeId(null); | 
|---|
|  |  |  | virtualCard.setOpenTime(null); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | virtualCard.setInUse((byte) 1); | 
|---|
|  |  |  | virtualCard.setIntakeId(intakeId); | 
|---|
|  |  |  | 
|---|
|  |  |  | 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(openType != null && openType == 1) { | 
|---|
|  |  |  | irIntakeOperateMapper.updateByCommandId(comId, (byte)1, null); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 开阀成功则占用,关阀成功不占用 | 
|---|
|  |  |  | if (comType != null) { | 
|---|
|  |  |  | 
|---|
|  |  |  | 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); | 
|---|