|  |  | 
 |  |  | import com.dy.common.util.Callback; | 
 |  |  | import com.dy.common.webUtil.BaseResponse; | 
 |  |  | import com.dy.common.webUtil.BaseResponseUtils; | 
 |  |  | import com.dy.pipIrrGlobal.pojoRm.RmCommandOpen; | 
 |  |  | import com.dy.pipIrrGlobal.voSe.VoVirtualCard; | 
 |  |  | import com.dy.pipIrrRemote.common.dto.DtoBase; | 
 |  |  | import com.dy.pipIrrRemote.monitor.common.ComCtrl; | 
 |  |  | 
 |  |  | import org.springframework.web.bind.annotation.RequestMapping; | 
 |  |  | import org.springframework.web.bind.annotation.RestController; | 
 |  |  |  | 
 |  |  | import java.util.Date; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  |  * @Author: liurunyu | 
 |  |  |  * @Date: 2025/5/15 09:21 | 
 |  |  | 
 |  |  |  */ | 
 |  |  | @Slf4j | 
 |  |  | @Tag(name = "远程命令", description = "App远程开阀") | 
 |  |  | @RestController("cdA2Ctrl") | 
 |  |  | @RestController("p202404V201CdA2Ctrl") | 
 |  |  | @RequestMapping(path = "p202404V201/cdA2") | 
 |  |  | @RequiredArgsConstructor | 
 |  |  | @Scope("prototype") //因为有对象类属性,所以采用原型模式,每次请求新建一个实例对象 | 
 |  |  | 
 |  |  |     private static final String RtuSuccessMsg = "控制器接收并执行命令成功,无返回数据"; | 
 |  |  |  | 
 |  |  |     private static final String ComCode = "A2" ; | 
 |  |  |  | 
 |  |  |     private static final Double MaxRemainMoney = com.dy.pipIrrRemote.monitor.p202404V201.cd92.CdCtrl.MaxRemainMoney;//协议支持的剩余金额最大值 | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private CdSv sv ; | 
 |  |  | 
 |  |  |                 if(vcPo.getMoney() <= 0.0){ | 
 |  |  |                     return BaseResponseUtils.buildErrorMsg("农户该虚拟卡中剩余金额为0,不能再应用其开阀") ; | 
 |  |  |                 } | 
 |  |  |                 if(vcPo.getMoney() >= MaxRemainMoney){ | 
 |  |  |                     return BaseResponseUtils.buildErrorMsg("农户该虚拟卡中剩余金额大于协议支持的最大值" + MaxRemainMoney + ",不能再应用其开阀") ; | 
 |  |  |                 } | 
 |  |  |                 Double waterPrice = sv.selectWaterPrice() ; | 
 |  |  |                 if(waterPrice == null){ | 
 |  |  |                     return BaseResponseUtils.buildErrorMsg("服务端出错,未得到水价") ; | 
 |  |  |                 } | 
 |  |  |                 String orderNo = RandomStringUtils.randomNumeric(16) ; | 
 |  |  |                 CdParam comParam = CdParam.builder().commandCode(ComCode).projectNo(projectNo).controllerType(controllerType) | 
 |  |  |                         .icCardNo("" + vcPo.getVcNum())//用户卡序列号(17位数字)(6字节BCD,2字节HEX) | 
 |  |  |                         .waterRemain(0.0)//用户剩余水量, 两个小数点, 单位m3, 0~99999999.99 | 
 |  |  |                         .moneyRemain(vcPo.getMoney())//用户剩余水量, 两个小数点, 单位m3, 0~99999999.99 | 
 |  |  |                         .waterPrice(waterPrice)//水量单价 单位:元, 2个小数点 | 
 |  |  |                         .elePrice(0.0)//电量单价 单位:元, 2个小数点 | 
 |  |  |                         .orderNo(RandomStringUtils.randomNumeric(16))//订单号(16位数字) | 
 |  |  |                         .orderNo(orderNo)//订单号(16位数字) | 
 |  |  |                         .build(); | 
 |  |  |                 //发送命令前-3:保存命令日志 | 
 |  |  |                 res = super.pre3(sv, dto.getIntakeId(), dto.getOperator(), ComCode, comParam); | 
 |  |  | 
 |  |  |                                         sv.addOrUpdateOftenUseIntake(dto.getOperator(), dto.getIntakeId()) ; | 
 |  |  |                                         //开阀成功,虚拟卡记录上标记已被占用 | 
 |  |  |                                         sv.setVcUsed(vcPo.getId(), dto.getIntakeId()); | 
 |  |  |                                         //记录开阀命令,以备远程关阀 | 
 |  |  |                                         RmCommandOpen comOpen = sv.getCommandOpen(dto.getIntakeId()); | 
 |  |  |                                         if(comOpen == null){ | 
 |  |  |                                             RmCommandOpen po = newRmCommandOpen(comId, ctrlPo.getProtocol(), ComCode, comName, dto.getIntakeId(), ctrlPo.getRtuAddr(), vcPo.getVcNum(), orderNo, dto.getOperator()) ; | 
 |  |  |                                             sv.saveCommandOpen(po); | 
 |  |  |                                         }else{ | 
 |  |  |                                             setRmCommandOpen(comOpen, comId, ctrlPo.getProtocol(), ComCode, comName, dto.getIntakeId(), ctrlPo.getRtuAddr(), vcPo.getVcNum(), orderNo, dto.getOperator()) ; | 
 |  |  |                                             sv.updateCommandOpen(comOpen); | 
 |  |  |                                         } | 
 |  |  |                                     } | 
 |  |  |                                 } | 
 |  |  |                                 @Override | 
 |  |  | 
 |  |  |                 DataCd92_A2Vo cvo = JSON.parseObject(json, DataCd92_A2Vo.class) ; | 
 |  |  |                 if(cvo != null){ | 
 |  |  |                     if(callback != null){ | 
 |  |  |                         if(cvo.opResult != null && cvo.opResult.byteValue() == (byte)0){ | 
 |  |  |                         if(cvo.opResult != null && cvo.opResult.byteValue() == (byte)1){ | 
 |  |  |                             callback.call(true);//开阀成功 | 
 |  |  |                         }else{ | 
 |  |  |                             callback.call(false);//开阀失败 | 
 |  |  | 
 |  |  |         } | 
 |  |  |         return msg; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private RmCommandOpen newRmCommandOpen(Long comId, | 
 |  |  |                                            String protocol, | 
 |  |  |                                            String comCode, | 
 |  |  |                                            String comName, | 
 |  |  |                                            Long intakeId, | 
 |  |  |                                            String rtuAddr, | 
 |  |  |                                            Long vcNum, | 
 |  |  |                                            String orderNo, | 
 |  |  |                                            Long operator){ | 
 |  |  |         RmCommandOpen po = new RmCommandOpen() ; | 
 |  |  |         this.setRmCommandOpen(po, comId, protocol, comCode, comName, intakeId, rtuAddr, vcNum, orderNo, operator); | 
 |  |  |         return po ; | 
 |  |  |     } | 
 |  |  |     private void setRmCommandOpen(RmCommandOpen po, | 
 |  |  |                                   Long comId, | 
 |  |  |                                   String protocol, | 
 |  |  |                                   String comCode, | 
 |  |  |                                   String comName, | 
 |  |  |                                   Long intakeId, | 
 |  |  |                                   String rtuAddr, | 
 |  |  |                                   Long vcNum, | 
 |  |  |                                   String orderNo, | 
 |  |  |                                   Long operator){ | 
 |  |  |         po.comId = comId ; | 
 |  |  |         po.protocol = protocol ; | 
 |  |  |         po.commandCode = comCode ; | 
 |  |  |         po.commandName = comName ; | 
 |  |  |         po.intakeId = intakeId ; | 
 |  |  |         po.rtuAddr = rtuAddr ; | 
 |  |  |         po.vcNum = vcNum ; | 
 |  |  |         po.orderNo = orderNo ; | 
 |  |  |         po.operator = operator ; | 
 |  |  |         po.sendTime = new Date() ; | 
 |  |  |     } | 
 |  |  | } |