|  |  | 
 |  |  | 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.daoSe.SeRechargeHistoryMapper; | 
 |  |  | import com.dy.pipIrrGlobal.pojoSe.SeCardOperate; | 
 |  |  | import com.dy.pipIrrGlobal.pojoSe.SeClientCard; | 
 |  |  | import com.dy.pipIrrGlobal.pojoSe.SeRechargeHistory; | 
 |  |  | import com.dy.pipIrrGlobal.voSe.VoAfterRecharge; | 
 |  |  | import com.dy.pipIrrGlobal.voSe.VoTermActiveCard; | 
 |  |  | 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.dto.*; | 
 |  |  | 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; | 
 |  |  | import org.springframework.stereotype.Service; | 
 |  |  | import org.springframework.transaction.annotation.Transactional; | 
 |  |  |  | 
 |  |  | import java.time.Duration; | 
 |  |  | import java.time.LocalDateTime; | 
 |  |  | import java.time.format.DateTimeFormatter; | 
 |  |  | import java.util.*; | 
 |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private PrWaterPriceMapper prWaterPriceMapper; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private SeRechargeHistoryMapper seRechargeHistoryMapper; | 
 |  |  |  | 
 |  |  |     @Value("${project.projectNo}") | 
 |  |  |     private Integer projectNo; | 
 |  |  |  | 
 |  |  | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         return false; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 根据水卡编号判断该卡是否可以充值 | 
 |  |  |      * @param po | 
 |  |  |      * @return true:可以充值 | 
 |  |  |      */ | 
 |  |  |     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; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 根据水卡编号判断该卡是否可以挂失 | 
 |  |  |      * @param po | 
 |  |  |      * @return true:可以报失 | 
 |  |  |      */ | 
 |  |  |     public Map canReportLoss(DtoLoss po) { | 
 |  |  |         Map map = new HashMap<>(); | 
 |  |  |         map.put("success", false); | 
 |  |  |         map.put("content", null); | 
 |  |  |  | 
 |  |  |         Long cardNum = po.getCardNum(); | 
 |  |  |         String stateName = seClientCardMapper.getCardStateByCardNum(cardNum); | 
 |  |  |         if(stateName == null || stateName.equals("") || !stateName.equals("正常")) { | 
 |  |  |             map.put("msg", stateName + ", " + "水卡状态不支持当前操作"); | 
 |  |  |             return map; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         /** | 
 |  |  |          * 依据水卡编号获取水卡表主键及农户编号 | 
 |  |  |          */ | 
 |  |  |         Map map_card = Optional.ofNullable(seClientCardMapper.getCardIdAndClientNum(cardNum)).orElse(new HashMap()); | 
 |  |  |         if (map_card == null || map_card.size() <= 0) { | 
 |  |  |             map.put("msg", "卡号错误,该卡不存在"); | 
 |  |  |             return map; | 
 |  |  |         } | 
 |  |  |         CardSimple card = new CardSimple(); | 
 |  |  |         card.setCardId(Long.parseLong(map_card.get("cardId").toString())); | 
 |  |  |         card.setClientId(Long.parseLong(map_card.get("clientId").toString())); | 
 |  |  |         //card.setProtocol(map_card.get("protocol").toString()); | 
 |  |  |  | 
 |  |  |         map.put("success", true); | 
 |  |  |         map.put("content", card); | 
 |  |  |         return map; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 根据水卡编号判断该卡是否可以补卡 | 
 |  |  |      * @param po | 
 |  |  |      * @return true:可以补卡 | 
 |  |  |      */ | 
 |  |  |     public Map canReissue(DtoReissue po) { | 
 |  |  |         Map map = new HashMap<>(); | 
 |  |  |         map.put("success", false); | 
 |  |  |         map.put("content", null); | 
 |  |  |  | 
 |  |  |         Long cardNum = po.getCardNum(); | 
 |  |  |         Integer lostCount = seClientCardMapper.getLostCount(cardNum); | 
 |  |  |         Integer replacedCount = seClientCardMapper.getReplacedCount(cardNum); | 
 |  |  |         if(lostCount == 0 || replacedCount > 0) { | 
 |  |  |             map.put("msg", "水卡未挂失或已补卡,不能补卡"); | 
 |  |  |             return map; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         Float reissueAmount = po.getReissueAmount(); | 
 |  |  |         if (reissueAmount != null && reissueAmount > 0) { | 
 |  |  |             Double tradeAmount = seCardOperateMapper.getTradeAmountByCardNo(cardNum); | 
 |  |  |             if (tradeAmount != null && tradeAmount > 0) { | 
 |  |  |                 map.put("msg", "原卡挂失时已退款,补卡时不能补费用"); | 
 |  |  |                 return map; | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         Map map_card = Optional.ofNullable(seClientCardMapper.getCardIdAndClientNum(cardNum)).orElse(new HashMap()); | 
 |  |  |         if (map_card == null || map_card.size() <= 0) { | 
 |  |  |             map.put("msg", "卡号错误,该卡不存在"); | 
 |  |  |             return map; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         CardSimple card = new CardSimple(); | 
 |  |  |         card.setCardId(Long.parseLong(map_card.get("cardId").toString())); | 
 |  |  |         card.setClientId(Long.parseLong(map_card.get("clientId").toString())); | 
 |  |  |         card.setProtocol(map_card.get("protocol").toString()); | 
 |  |  |  | 
 |  |  |         map.put("success", true); | 
 |  |  |         map.put("content", card); | 
 |  |  |         return map; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  | 
 |  |  |         return dtf.format(dateTime) + sb.toString(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     @Transactional(rollbackFor = Exception.class) | 
 |  |  |     public Map addCardAndOperate(ActiveCard po, Long cardNum, String orderNo) { | 
 |  |  |         Map map = new HashMap<>(); | 
 |  |  |         map.put("success", false); | 
 |  |  | 
 |  |  |         seClientCard.setClientid(po.getClientId()); | 
 |  |  |         seClientCard.setMoney(po.getAmount()); | 
 |  |  |         seClientCard.setState(CardStateENUM.INVALID.getCode()); | 
 |  |  |         seClientCard.setOrderNo(orderNo); | 
 |  |  |         if (po.getOriginalCardId() != null) { | 
 |  |  |             // 补卡 | 
 |  |  |             seClientCard.setOriginalCardId(po.getOriginalCardId()); | 
 |  |  | 
 |  |  |         return map; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public Map plusRecharge(ActiveCard po, Long cardNum) { | 
 |  |  |     /** | 
 |  |  |      * 开卡附加充值 | 
 |  |  |      * @param po | 
 |  |  |      * @param cardNum | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     @Transactional(rollbackFor = Exception.class) | 
 |  |  |     public Map plusRecharge(ActiveCard po, Long cardNum, String orderNo) { | 
 |  |  |         Map map = new HashMap<>(); | 
 |  |  |         map.put("success", false); | 
 |  |  |         map.put("content", null); | 
 |  |  |  | 
 |  |  |         /** | 
 |  |  |          * 添加水卡操作记录 | 
 |  |  |          */ | 
 |  |  |         DtoRecharge dtoRecharge = new DtoRecharge(); | 
 |  |  |         dtoRecharge.setCardNum(cardNum); | 
 |  |  |         dtoRecharge.setAmount(po.getAmount()); | 
 |  |  | 
 |  |  |         dtoRecharge.setMoney(0f); | 
 |  |  |         dtoRecharge.setGift(0f); | 
 |  |  |         dtoRecharge.setPrice(0f); | 
 |  |  |         //BaseResponse<Boolean> job = cardOperateSv.addRecharge(dtoRecharge); | 
 |  |  |         BaseResponse<Boolean> job = null; | 
 |  |  |         if (!job.getCode().equals("0001")) { | 
 |  |  |         Map map_plusRecharge = addRecharge(dtoRecharge, orderNo); | 
 |  |  |         if (!map_plusRecharge.get("success").equals(true)) { | 
 |  |  |             map.put("msg", "开卡失败-充值异常"); | 
 |  |  |             return map; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         map.put("success", true); | 
 |  |  |         return map; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 激活或补卡 | 
 |  |  |      * @param po | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     @Transactional(rollbackFor = Exception.class) | 
 |  |  |     public Map activeOrReissueTermCard(ActiveCard po) { | 
 |  |  |         Map map = new HashMap<>(); | 
 |  |  |         map.put("success", false); | 
 |  |  | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         if (amount != null && amount > 0 && originalCardId == null) { | 
 |  |  |             Map map_plusRecharge = plusRecharge(po, cardNum); | 
 |  |  |             Map map_plusRecharge = plusRecharge(po, cardNum, orderNo); | 
 |  |  |             if(map_plusRecharge.get("success").equals(false)) { | 
 |  |  |                 map.put("msg", map_plusRecharge.get("msg").toString()); | 
 |  |  |                 return map; | 
 |  |  | 
 |  |  |         Float balance = Optional.ofNullable(seClientCardMapper.getMoneyByCardNum(cardNum)).orElse(0f); | 
 |  |  |         Double waterPrice = prWaterPriceMapper.getPrice(); | 
 |  |  |  | 
 |  |  |         VoTermActiveCard voTermActiveCard = new VoTermActiveCard(); | 
 |  |  |         voTermActiveCard.setProjectNo(projectNo); | 
 |  |  |         voTermActiveCard.setCardNum(cardNum); | 
 |  |  |         voTermActiveCard.setBalance(balance); | 
 |  |  |         voTermActiveCard.setWaterPrice(waterPrice); | 
 |  |  |         voTermActiveCard.setTime(new Date()); | 
 |  |  |         voTermActiveCard.setOrderNo(orderNo); | 
 |  |  |  | 
 |  |  |         map.put("success", true); | 
 |  |  |         map.put("msg", "操作成功"); | 
 |  |  |         map.put("content", voTermActiveCard); | 
 |  |  |         return map; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 充值 | 
 |  |  |      * @param po | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     @Transactional(rollbackFor = Exception.class) | 
 |  |  |     public Map addRecharge(DtoRecharge po, String orderNo) { | 
 |  |  |         Map map = new HashMap<>(); | 
 |  |  |         map.put("success", false); | 
 |  |  |         map.put("content", null); | 
 |  |  |  | 
 |  |  |         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()); | 
 |  |  |         if(orderNo == null || orderNo.length() <= 0) { | 
 |  |  |             orderNo = generateOrderNo(); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         /** | 
 |  |  |          * 添加水卡充值操作记录 | 
 |  |  |          */ | 
 |  |  |         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.setOrderNo(orderNo + "p"); | 
 |  |  |         seCardOperate.setOperateValid((byte) 1); | 
 |  |  |         seCardOperateMapper.insert(seCardOperate); | 
 |  |  |         Long rec = Optional.ofNullable(seCardOperate.getId()).orElse(0L); | 
 |  |  |         if (rec == 0) { | 
 |  |  |             map.put("msg", "充值失败-充值记录写入异常"); | 
 |  |  |             return map; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         /** | 
 |  |  |          * 添加充值历史记录 | 
 |  |  |          */ | 
 |  |  |         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); | 
 |  |  |         seRechargeHistory.setOrderNo(orderNo); | 
 |  |  |         seRechargeHistoryMapper.insert(seRechargeHistory); | 
 |  |  |         Long rec_seRechargeHistory = Optional.ofNullable(seRechargeHistory.getId()).orElse(0L); | 
 |  |  |         if (rec_seRechargeHistory == 0) { | 
 |  |  |             map.put("msg", "充值失败-充值历史记录写入异常"); | 
 |  |  |             return map; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         VoTermRecharge voTermRecharge = new VoTermRecharge(); | 
 |  |  |         voTermRecharge.setProjectNo(projectNo); | 
 |  |  |         voTermRecharge.setCardNum(cardNum); | 
 |  |  |         voTermRecharge.setBalance(balance); | 
 |  |  |         voTermRecharge.setWaterPrice(waterPrice); | 
 |  |  |         voTermRecharge.setTime(new Date()); | 
 |  |  |         voTermRecharge.setCardNum(po.getCardNum()); | 
 |  |  |         voTermRecharge.setOrderNo(orderNo); | 
 |  |  |  | 
 |  |  |         map.put("success", true); | 
 |  |  | 
 |  |  |         return map; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 补卡 | 
 |  |  |      * @param po | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     @Transactional(rollbackFor = Exception.class) | 
 |  |  |     public Map reissue(DtoReissue po) { | 
 |  |  |         Map map = new HashMap<>(); | 
 |  |  |         map.put("success", false); | 
 |  |  |         map.put("content", null); | 
 |  |  |  | 
 |  |  |         Map map_canReissue = canReissue(po); | 
 |  |  |         if(map_canReissue.get("success").equals(false)) { | 
 |  |  |             map.put("msg", map_canReissue.get("msg").toString()); | 
 |  |  |             return map; | 
 |  |  |         } | 
 |  |  |         CardSimple card = (CardSimple) map_canReissue.get("content"); | 
 |  |  |         Long cardId = card.getCardId(); | 
 |  |  |         Long clientId = card.getClientId(); | 
 |  |  |         String protocol = card.getProtocol(); | 
 |  |  |  | 
 |  |  |         /** | 
 |  |  |          * 添加开卡记录,退还金额冲到新卡中 | 
 |  |  |          */ | 
 |  |  |         ActiveCard activeCard = new ActiveCard(); | 
 |  |  |         activeCard.setProtocol(protocol); | 
 |  |  |         activeCard.setCardAddr(po.getCardAddr()); | 
 |  |  |         activeCard.setClientId(clientId); | 
 |  |  |         activeCard.setOriginalCardId(cardId); | 
 |  |  |         activeCard.setCardCost(po.getCardCost()); | 
 |  |  |         activeCard.setAmount(po.getReissueAmount()); | 
 |  |  |         activeCard.setPaymentId(po.getPaymentId()); | 
 |  |  |         activeCard.setRemarks(po.getRemarks()); | 
 |  |  |         activeCard.setOperator(po.getOperator()); | 
 |  |  |  | 
 |  |  |         Map map_newCard = activeOrReissueTermCard(activeCard); | 
 |  |  |         VoTermActiveCard voTermActiveCard = (VoTermActiveCard) map_newCard.get("content"); | 
 |  |  |  | 
 |  |  |         map.put("success", true); | 
 |  |  |         map.put("msg", "操作成功"); | 
 |  |  |         map.put("content", voTermActiveCard); | 
 |  |  |         return map; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Transactional(rollbackFor = Exception.class) | 
 |  |  |     public Map reportLoss(DtoLoss po) { | 
 |  |  |         Map map = new HashMap<>(); | 
 |  |  |         map.put("success", false); | 
 |  |  |         map.put("content", null); | 
 |  |  |  | 
 |  |  |         Map map_canReportLoss = canReportLoss(po); | 
 |  |  |         if(map_canReportLoss.get("success").equals(false)) { | 
 |  |  |             map.put("msg", map_canReportLoss.get("msg").toString()); | 
 |  |  |             return map; | 
 |  |  |         } | 
 |  |  |         CardSimple card = (CardSimple) map_canReportLoss.get("content"); | 
 |  |  |         Long cardId = card.getCardId(); | 
 |  |  |         Long clientId = card.getClientId(); | 
 |  |  |  | 
 |  |  |         Float money = Optional.ofNullable(po.getMoney()).orElse(0f); | 
 |  |  |         Float refund = Optional.ofNullable(po.getRefund()).orElse(0f); | 
 |  |  |  | 
 |  |  |         SeClientCard seClientCard = new SeClientCard(); | 
 |  |  |         seClientCard.setId(cardId); | 
 |  |  |         seClientCard.setMoney(money); | 
 |  |  |         seClientCard.setLossdtdt(new Date()); | 
 |  |  |         seClientCard.setState(CardStateENUM.LOSS.getCode()); | 
 |  |  |         seClientCard.setLastoper(LastOperateENUM.LOSS.getCode()); | 
 |  |  |         Integer rec_updateClientCard = Optional.ofNullable(seClientCardMapper.updateByPrimaryKeySelective(seClientCard)).orElse(0); | 
 |  |  |         if (rec_updateClientCard == 0) { | 
 |  |  |             map.put("msg", "挂失失败-农户卡修改异常"); | 
 |  |  |             return map; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         SeCardOperate seCardOperate = new SeCardOperate(); | 
 |  |  |         seCardOperate.setCardId(cardId); | 
 |  |  |         seCardOperate.setClientId(clientId); | 
 |  |  |         seCardOperate.setMoney(money); | 
 |  |  |         seCardOperate.setTradeAmount(-refund); | 
 |  |  |         seCardOperate.setPaymentId(1L); | 
 |  |  |         seCardOperate.setOperateType(OperateTypeENUM.LOSS.getCode()); | 
 |  |  |         seCardOperate.setRemarks(po.getRemarks()); | 
 |  |  |         seCardOperate.setOperator(po.getOperator()); | 
 |  |  |         seCardOperate.setOperateDt(new Date()); | 
 |  |  |         seCardOperate.setOperateValid((byte) 2); | 
 |  |  |         seCardOperateMapper.insert(seCardOperate); | 
 |  |  |         if (seCardOperate.getId() == 0) { | 
 |  |  |             map.put("msg", "挂失失败-挂失记录写入异常"); | 
 |  |  |             return map; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         map.put("success", true); | 
 |  |  |         map.put("msg", "操作成功"); | 
 |  |  |         return map; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 操作回调 | 
 |  |  |      * @param po | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     @Transactional(rollbackFor = Exception.class) | 
 |  |  |     public Map callBack(DtoCallBack po) { | 
 |  |  |         Map map = new HashMap<>(); | 
 |  |  |         map.put("success", false); | 
 |  |  |         map.put("content", null); | 
 |  |  |  | 
 |  |  |         String cardAddr = po.getCardAddr(); | 
 |  |  |         Integer operateType = po.getOperateType(); | 
 |  |  |         String orderNumber = po.getOrderNumber(); | 
 |  |  |  | 
 |  |  |         Long cardId = seClientCardMapper.getCardIdByAddr(cardAddr); | 
 |  |  |         if (cardId == null || cardId.equals(0)) { | 
 |  |  |             map.put("msg", "您指定的水卡不存在"); | 
 |  |  |             return map; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         if(operateType == 1) { | 
 |  |  |             /** | 
 |  |  |              * 开卡操作执行通知 | 
 |  |  |              *  1.依据订单号将无效状态的操作记录改为有效 | 
 |  |  |              *  2.依据水卡ID将无效状态的水卡记录改为有效 | 
 |  |  |              *  3.如果开卡同步充值 | 
 |  |  |              *      修改充值操作记录为有效 | 
 |  |  |              *      修改充值历史记录为有效 | 
 |  |  |              *      修改水卡表的操作信息 | 
 |  |  |              */ | 
 |  |  |             Integer rec_ope = turnOperateValidByOrderNumber(orderNumber); | 
 |  |  |             Integer rec_card = turnCardValidByOrderNumber(orderNumber); | 
 |  |  |             if (rec_ope == 0 || rec_card == 0) { | 
 |  |  |                 map.put("msg", "不存在未生效的水卡"); | 
 |  |  |                 return map; | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             if(isMergeRecharge(cardId)) { | 
 |  |  |                 turnOperateValidByOrderNumber(orderNumber + "p"); | 
 |  |  |                 turnRechargeHistoryValidByOrderNumber(orderNumber); | 
 |  |  |                 updateCard(cardId, orderNumber+"p"); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         map.put("success", true); | 
 |  |  |         map.put("msg", "操作成功"); | 
 |  |  |         return map; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     // 根据订单号将操作记录改为有效 | 
 |  |  |     public Integer turnOperateValidByOrderNumber(String orderNumber) { | 
 |  |  |         return seCardOperateMapper.turnOperateValidByOrderNumber(orderNumber); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     // 根据订单号将水卡改为有效 | 
 |  |  |     public Integer turnCardValidByOrderNumber(String orderNumber) { | 
 |  |  |         return seClientCardMapper.turnCardValidByOrderNumber(orderNumber); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     // 根据订单号将充值历史改为有效 | 
 |  |  |     public Integer turnRechargeHistoryValidByOrderNumber(String orderNumber) { | 
 |  |  |         return seRechargeHistoryMapper.turnRechargeHistoryValidByOrderNumber(orderNumber); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     // 根据cardId判断是否是合并充值 | 
 |  |  |     public Boolean isMergeRecharge(Long cardId) { | 
 |  |  |         Integer plusRechargeCount = seCardOperateMapper.getPlusRechargeCount(cardId); | 
 |  |  |         if (plusRechargeCount == 0) { | 
 |  |  |             return false; | 
 |  |  |         } | 
 |  |  |         return true; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     // 修改水卡信息 | 
 |  |  |     public Boolean updateCard(Long cardId, String orderNumber) { | 
 |  |  |         VoAfterRecharge voAfterRecharge = seCardOperateMapper.getBalanceAfterRecharge(orderNumber); | 
 |  |  |  | 
 |  |  |         SeClientCard clientCard = new SeClientCard(); | 
 |  |  |         clientCard.setId(cardId); | 
 |  |  |         clientCard.setMoney(voAfterRecharge.getBalanceAfterRecharge()); | 
 |  |  |         clientCard.setRechargedt(voAfterRecharge.getOperateTime()); | 
 |  |  |         clientCard.setLastoper(LastOperateENUM.RECHARGE.getCode()); | 
 |  |  |         Integer rec_updateClientCard = seClientCardMapper.updateByPrimaryKeySelective(clientCard); | 
 |  |  |         if (rec_updateClientCard == null || rec_updateClientCard == 0) { | 
 |  |  |             return false; | 
 |  |  |         } | 
 |  |  |         return true; | 
 |  |  |     } | 
 |  |  | } |