pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoIr/IrIntakeOperateMapper.java
@@ -39,6 +39,14 @@ int updateByCommandId(@Param("commandId") Long commandId, @Param("commandResult") Byte commandResult, @Param("failureFactors") String failureFactors); /** * 根据主键修改命令ID * @param commandId * @param id * @return */ int updateCommandId(@Param("commandId") Long commandId, @Param("id") Long id); /** * 根据计划ID获取待终止的取水口ID(已发布开发命令,无论是否成功) * @param planId * @return pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoPr/PrIntakeControllerMapper.java
@@ -59,4 +59,11 @@ * @return */ int updateByIntakeSelective(PrIntakeController record); /** * 根据取水口ID获取取水口名称 * @param intakeId * @return */ String getIntakeNameById(@Param("intakeId") Long intakeId); } pipIrr-platform/pipIrr-global/src/main/resources/mapper/IrIntakeOperateMapper.xml
@@ -156,6 +156,13 @@ where command_id = #{commandId} </update> <!--根据主键修改命令ID--> <update id="updateCommandId"> update ir_intake_operate set command_id = #{commandId} where id = #{id} </update> <!--根据计划ID获取待终止的取水口ID(已发布开发命令,无论是否成功)--> <select id="getToTerminateIntakeIds" resultType="java.lang.Long"> SELECT pipIrr-platform/pipIrr-global/src/main/resources/mapper/IrIrrigatePlanMapper.xml
@@ -434,7 +434,7 @@ FROM ir_irrigate_schedule sche INNER JOIN ir_plan_schedule ps ON schedule_id = sche.id WHERE ps.plan_id = #{planId} LIMIT 1 <!-- LIMIT 1--> ) AS has_intersection </select> pipIrr-platform/pipIrr-global/src/main/resources/mapper/PrIntakeControllerMapper.xml
@@ -210,4 +210,9 @@ </set> where intakeId = #{intakeid,jdbcType=BIGINT} </update> <!--根据取水口ID获取取水口名称--> <select id="getIntakeNameById" resultType="java.lang.String"> SELECT name AS intakeName FROM pr_intake WHERE id = #{intakeId} </select> </mapper> pipIrr-platform/pipIrr-web/pipIrr-web-terminal/src/main/java/com/dy/pipIrrTerminal/card/CardSv.java
@@ -1,18 +1,21 @@ package com.dy.pipIrrTerminal.card; import com.dy.common.webUtil.BaseResponse; import com.dy.common.webUtil.BaseResponseUtils; import com.dy.pipIrrGlobal.daoPr.PrWaterPriceMapper; import com.dy.pipIrrGlobal.daoSe.SeCardOperateMapper; import com.dy.pipIrrGlobal.daoSe.SeClientCardMapper; import com.dy.pipIrrGlobal.daoSe.SeClientMapper; import com.dy.pipIrrGlobal.pojoSe.SeCardOperate; import com.dy.pipIrrGlobal.pojoSe.SeClientCard; import com.dy.pipIrrGlobal.pojoSe.SeRechargeHistory; import com.dy.pipIrrGlobal.voSe.VoTermRecharge; import com.dy.pipIrrTerminal.card.dto.ActiveCard; import com.dy.pipIrrTerminal.card.dto.DtoRecharge; import com.dy.pipIrrTerminal.card.enums.CardStateENUM; import com.dy.pipIrrTerminal.card.enums.LastOperateENUM; import com.dy.pipIrrTerminal.card.enums.OperateTypeENUM; import com.dy.pipIrrTerminal.card.enums.RechargeTypeENUM; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -264,4 +267,124 @@ return map; } public Map canRecharge(DtoRecharge po) { Map map = new HashMap<>(); map.put("success", false); map.put("content", null); String stateName = Optional.ofNullable(seClientCardMapper.getCardStateByCardNum(po.getCardNum())).orElse(""); // 单独充值时卡片必须为正常 if((po.getRechargeType() == RechargeTypeENUM.RECHARGE.getCode()) && !stateName.equals("正常")) { map.put("msg", stateName + ", " + "水卡状态不支持当前操作"); return map; } map.put("success", true); return map; } public Map addRecharge(DtoRecharge po) { Map map = new HashMap<>(); map.put("success", false); map.put("content", null); /** * cardId 水卡编号(依据水卡编号获取) * clientId 农户编号(依据水卡编号获取) * cardNum 水卡编号 * money 卡片余额 * amount 充值金额 * gift 赠送金额 * afterRecharge 充值后余额 * paymentId 支付方式编号 * price 水价 * remarks 备注 * operator 操作人编号 * rechargeTime 充值时间 */ //Long cardId = 0L; //Long clientId = 0L; //Long cardNum = po.getCardNum(); //Float money = po.getMoney(); //Float amount = po.getAmount(); //Float gift = po.getGift(); //Float afterRecharge = money + amount + gift; //Long paymentId = po.getPaymentId(); //Float price = po.getPrice(); //String remarks = po.getRemarks(); //Long operator = po.getOperator(); //Date rechargeTime = new Date(); Map map_canRecharge = canRecharge(po); if(map_canRecharge.get("success").equals(false)) { map.put("msg", map_canRecharge.get("msg").toString()); return map; } /** * 依据水卡编号获取水卡表主键及农户编号 */ Map map_cardAndClient = seClientCardMapper.getCardIdAndClientNum(po.getCardNum()); if (map_cardAndClient == null || map_cardAndClient.size() <= 0) { map.put("msg", "卡号错误,该卡不存在"); return map; } Long cardId = Long.parseLong(map_cardAndClient.get("cardId").toString()); Long clientId = Long.parseLong(map_cardAndClient.get("clientId").toString()); /** * 添加水卡充值操作记录 */ SeCardOperate seCardOperate = new SeCardOperate(); seCardOperate.setCardId(cardId); seCardOperate.setClientId(clientId); seCardOperate.setMoney(po.getMoney()); seCardOperate.setTradeAmount(po.getAmount()); seCardOperate.setGift(po.getGift()); seCardOperate.setOperateType(OperateTypeENUM.RECHARGE.getCode()); seCardOperate.setPaymentId(po.getPaymentId()); seCardOperate.setPrice(po.getPrice()); seCardOperate.setRemarks(po.getRemarks()); seCardOperate.setOperator(po.getOperator()); seCardOperate.setOperateDt(new Date()); seCardOperate.setOperateValid((byte) 1); seCardOperateMapper.insert(seCardOperate); Long rec = Optional.ofNullable(seCardOperate.getId()).orElse(0L); if (rec == 0) { //return BaseResponseUtils.buildErrorMsg("充值失败-充值记录写入异常"); } /** * 添加充值历史记录 */ SeRechargeHistory seRechargeHistory = new SeRechargeHistory(); seRechargeHistory.setCardid(cardId); seRechargeHistory.setClientid(clientId); seRechargeHistory.setMoney(po.getMoney()); seRechargeHistory.setAmount(po.getAmount()); seRechargeHistory.setGift(po.getGift()); Float afterRecharge = po.getMoney() + po.getAmount() + po.getGift(); seRechargeHistory.setAfterrecharge(afterRecharge); seRechargeHistory.setPaymentid(po.getPaymentId()); seRechargeHistory.setPrice(po.getPrice()); seRechargeHistory.setRemarks(po.getRemarks()); seRechargeHistory.setOperator(po.getOperator()); seRechargeHistory.setOperatedt(new Date()); seRechargeHistory.setOperateValid((byte) 1); //seRechargeHistoryMapper.insert(seRechargeHistory); Long rec_seRechargeHistory = Optional.ofNullable(seRechargeHistory.getId()).orElse(0L); //if (rec_seRechargeHistory == 0) { // return BaseResponseUtils.buildErrorMsg("充值失败-充值历史记录写入异常"); //} //Map map_response = new HashMap(); //map_response.put("projectNo", String.format("%02x", projectNo)); //map_response.put("orderNumber", rec); //map_response.put("cardNum", cardNum); //return BaseResponseUtils.buildSuccess(map_response); return map; } } pipIrr-platform/pipIrr-web/pipIrr-web-terminal/src/main/java/com/dy/pipIrrTerminal/card/dto/DtoRecharge.java
@@ -70,4 +70,9 @@ */ @Positive(message = "操作人编号必须为大于0的整数") private Long operator; /** * 充值类型:1-开卡同步充值,2-充值 */ private Byte rechargeType; } pipIrr-platform/pipIrr-web/pipIrr-web-terminal/src/main/java/com/dy/pipIrrTerminal/card/enums/RechargeTypeENUM.java
New file @@ -0,0 +1,21 @@ package com.dy.pipIrrTerminal.card.enums; import lombok.AllArgsConstructor; import lombok.Getter; /** * @author ZhuBaoMin * @date 2025-05-09 20:12 * @LastEditTime 2025-05-09 20:12 * @Description */ @Getter @AllArgsConstructor public enum RechargeTypeENUM { PLUS((byte)1, "开卡同步充值"), RECHARGE((byte)2, "充值"); private final Byte code; private final String message; } pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/command/CommandSv.java
@@ -22,6 +22,7 @@ import com.dy.pipIrrGlobal.command.ComSupport; import com.dy.pipIrrGlobal.command.dto.Param; import com.dy.pipIrrGlobal.daoIr.IrIntakeOperateMapper; import com.dy.pipIrrGlobal.daoPr.PrIntakeControllerMapper; import com.dy.pipIrrGlobal.daoPr.PrIntakeMapper; import com.dy.pipIrrGlobal.daoPr.PrIntakeVcMapper; import com.dy.pipIrrGlobal.daoPr.PrWaterPriceMapper; @@ -40,6 +41,8 @@ import com.dy.pipIrrWechat.command.dto.AutomaticClose; import com.dy.pipIrrWechat.command.dto.ValveClose; import com.dy.pipIrrWechat.command.dto.ValveOpen; import com.dy.pipIrrWechat.irrigatePlan.IrrigatePlanSv; import com.dy.pipIrrWechat.irrigation.IrrigationSv; import com.dy.pipIrrWechat.result.WechatResultCode; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -72,6 +75,8 @@ private final RmOpenCloseValveLastMapper rmOpenCloseValveLastMapper; //private final PrCommonIntakesMapper prCommonIntakesMapper; private final IrIntakeOperateMapper irIntakeOperateMapper; private final IrrigationSv irrigationSv; private final PrIntakeControllerMapper prIntakeControllerMapper; @Value("${mw.rtuCallbackUrl_wx}") private String rtuCallbackUrl_wx; @@ -85,7 +90,7 @@ private String pro_mw = "mw"; private String key_mw = "comSendUrl"; @Autowired public CommandSv(RmCommandHistoryMapper rmCommandHistoryMapper,RmOpenCloseValveLastMapper rmOpenCloseValveLastMapper, SeVirtualCardMapper seVirtualCardMapper, PrIntakeMapper prIntakeMapper, PrWaterPriceMapper prWaterPriceMapper, PrIntakeVcMapper prIntakeVcMapper, SeClientCardMapper seClientCardMapper, RmIrrigateProfileMapper rmIrrigateProfileMapper, Environment env, IrIntakeOperateMapper irIntakeOperateMapper) { public CommandSv(RmCommandHistoryMapper rmCommandHistoryMapper,RmOpenCloseValveLastMapper rmOpenCloseValveLastMapper, SeVirtualCardMapper seVirtualCardMapper, PrIntakeMapper prIntakeMapper, PrWaterPriceMapper prWaterPriceMapper, PrIntakeVcMapper prIntakeVcMapper, SeClientCardMapper seClientCardMapper, RmIrrigateProfileMapper rmIrrigateProfileMapper, Environment env, IrIntakeOperateMapper irIntakeOperateMapper, IrrigationSv irrigationSv, PrIntakeControllerMapper prIntakeControllerMapper) { this.rmCommandHistoryMapper = rmCommandHistoryMapper; this.rmOpenCloseValveLastMapper = rmOpenCloseValveLastMapper; //this.prCommonIntakesMapper = prCommonIntakesMapper; @@ -97,6 +102,8 @@ this.rmIrrigateProfileMapper = rmIrrigateProfileMapper; this.env = env; this.irIntakeOperateMapper = irIntakeOperateMapper; this.irrigationSv = irrigationSv; this.prIntakeControllerMapper = prIntakeControllerMapper; } /** * 虚拟卡ID换虚拟卡对象 @@ -127,6 +134,7 @@ com.type = "innerCommand"; comSendUrl = env.getProperty(pro_mw + "." + DataSourceContext.get() + "." + key_mw); JSONObject response = (JSONObject) JSON.toJSON(sendCom2Mw(com)); String aa = response.toJSONString(); JSONArray jsonArray = new JSONArray(); if(response != null && response.getString("code").equals("0001")) { @@ -268,8 +276,10 @@ Long operator = automaticClose.getOperator(); Byte openType = automaticClose.getOpenType(); Long comId = new IDLongGenerator().generate(); String intakeName = Optional.ofNullable(prIntakeControllerMapper.getIntakeNameById(intakeId)).orElse(""); // 如果是轮灌 Long operateId = null; if(openType != null && openType == 1) { IrIntakeOperate irIntakeOperate = new IrIntakeOperate(); irIntakeOperate.setPlanId(planId); @@ -279,8 +289,8 @@ irIntakeOperate.setStartTime(startTime); irIntakeOperate.setDuration(duration); Long id = addIntakeOperate(irIntakeOperate); if(id == null) { operateId = addIntakeOperate(irIntakeOperate); if(operateId == null) { Map map = new HashMap<>(); map.put("success", false); map.put("msg", "添加取水口操作记录失败"); @@ -307,7 +317,7 @@ Map map = new HashMap<>(); map.put("success", false); map.put("msg", WechatResultCode.PLEASE_SELECT_A_VC.getMessage() + "(" + intakeId + ")"); map.put("msg", WechatResultCode.PLEASE_SELECT_A_VC.getMessage() + "(" + intakeName + ")"); map.put("content", null); return map; } @@ -320,14 +330,14 @@ Map map = new HashMap<>(); map.put("success", false); map.put("msg", WechatResultCode.PLEASE_SELECT_A_VC.getMessage() + "(" + intakeId + ")"); map.put("msg", WechatResultCode.PLEASE_SELECT_A_VC.getMessage() + "(" + intakeName + ")"); map.put("content", null); return map; } String vcNum = vc.getVcNum().toString(); Double moneyRemain = vc.getMoney(); if(moneyRemain < 100) { irIntakeOperateMapper.updateByCommandId(comId, (byte)2, "虚拟卡余额不足,请充值" + "(" + intakeId + ")"); irIntakeOperateMapper.updateByCommandId(comId, (byte)2, "虚拟卡余额不足,请充值" + "(" + intakeName + ")"); Map map = new HashMap<>(); map.put("success", false); map.put("msg", "虚拟卡余额不足,请充值"); @@ -338,6 +348,7 @@ // 获取水价 Double waterPrice = getPrice(); if(waterPrice == null) { irIntakeOperateMapper.updateByCommandId(comId, (byte)2, WechatResultCode.NO_WATER_PRICE.getMessage() + "(" + intakeName + ")"); Map map = new HashMap<>(); map.put("success", false); map.put("msg", WechatResultCode.NO_WATER_PRICE.getMessage()); @@ -348,7 +359,7 @@ // 取水口ID换阀控器地址及通讯协议 JSONObject job_rtu = getRtu(intakeId, null); if(job_rtu == null) { irIntakeOperateMapper.updateByCommandId(comId, (byte)2, WechatResultCode.RTU_NOT_EXIST.getMessage() + "(" + intakeId + ")"); irIntakeOperateMapper.updateByCommandId(comId, (byte)2, WechatResultCode.RTU_NOT_EXIST.getMessage() + "(" + intakeName + ")"); Map map = new HashMap<>(); map.put("success", false); @@ -364,11 +375,22 @@ // 生成订单号 String orderNo = generateOrderNo(); if(orderNo == null) { irIntakeOperateMapper.updateByCommandId(comId, (byte)2, WechatResultCode.NO_ORDER_NUMBER.getMessage() + "(" + intakeId + ")"); irIntakeOperateMapper.updateByCommandId(comId, (byte)2, WechatResultCode.NO_ORDER_NUMBER.getMessage() + "(" + intakeName + ")"); Map map = new HashMap<>(); map.put("success", false); map.put("msg", WechatResultCode.NO_ORDER_NUMBER.getMessage()); map.put("content", null); return map; } // 判断阀控器是否已经开阀 Boolean isOpen = irrigationSv.getOpenCloseStatus(rtuAddr); if(isOpen) { irIntakeOperateMapper.updateByCommandId(comId, (byte)2, intakeName + " 阀门为打开状态"); Map map = new HashMap<>(); map.put("success", false); map.put("msg", intakeName + " 阀门为打开状态"); map.put("content", null); return map; } @@ -419,8 +441,12 @@ BaseResponse<Boolean> result = dealWithCommandResult(myParam); // 如果命令执行失败,则再次执行命令 if(!result.isSuccess()) { myParam.setComId(new IDLongGenerator().generate()); Long newComId = new IDLongGenerator().generate(); myParam.setComId(newComId); result = dealWithCommandResult(myParam); // 根据operateId修改取水口操作记录中的commandId irIntakeOperateMapper.updateCommandId(newComId, operateId); } Map map = new HashMap<>(); pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/irrigatePlan/IrrigatePlanSv.java
@@ -285,6 +285,13 @@ for (VoIrrigateSchedule schedule : schedules) { Long groupId = schedule.getGroupId(); List<Long> intakeIds = getIntakeIdsByGroupId(groupId); if(intakeIds == null || intakeIds.size() <= 0) { Map map = new HashMap<>(); map.put("success", false); map.put("msg", "当前轮灌组内没有有效的取水口"); map.put("content", null); return map; } for (Long intakeId : intakeIds) { if (schedule.getDuration() > 0) { // 今发布灌溉时长大于0的 pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/irrigation/IrrigationSv.java
@@ -191,7 +191,8 @@ return false; } if(response.getJSONObject("content").getJSONObject("attachment").get("valveOpenTrueCloseFalse").equals("true")) { // if(response.getJSONObject("content").getJSONObject("attachment").get("valveOpenTrueCloseFalse").equals("true")) { if(response.getJSONObject("content").getJSONObject("attachment").getBoolean("valveOpenTrueCloseFalse")) { return true; } else {