| | |
| | | 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 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(); |
| | | |
| | | VoTermRecharge voTermRecharge = new VoTermRecharge(); |
| | | voTermRecharge.setProjectNo(projectNo); |
| | | voTermRecharge.setCardNum(cardNum); |
| | | voTermRecharge.setBalance(balance); |
| | | voTermRecharge.setWaterPrice(waterPrice); |
| | | voTermRecharge.setTime(new Date()); |
| | | voTermRecharge.setOrderNo(orderNo); |
| | | 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", voTermRecharge); |
| | | map.put("content", voTermActiveCard); |
| | | return map; |
| | | } |
| | | |
| | | public Map canRecharge(DtoRecharge po) { |
| | | /** |
| | | * 充值 |
| | | * @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); |
| | | |
| | | 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)) { |
| | |
| | | } |
| | | 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.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) { |
| | | //return BaseResponseUtils.buildErrorMsg("充值失败-充值记录写入异常"); |
| | | map.put("msg", "充值失败-充值记录写入异常"); |
| | | return map; |
| | | } |
| | | |
| | | /** |
| | |
| | | seRechargeHistory.setOperator(po.getOperator()); |
| | | seRechargeHistory.setOperatedt(new Date()); |
| | | seRechargeHistory.setOperateValid((byte) 1); |
| | | //seRechargeHistoryMapper.insert(seRechargeHistory); |
| | | seRechargeHistory.setOrderNo(orderNo); |
| | | seRechargeHistoryMapper.insert(seRechargeHistory); |
| | | Long rec_seRechargeHistory = Optional.ofNullable(seRechargeHistory.getId()).orElse(0L); |
| | | //if (rec_seRechargeHistory == 0) { |
| | | // return BaseResponseUtils.buildErrorMsg("充值失败-充值历史记录写入异常"); |
| | | //} |
| | | if (rec_seRechargeHistory == 0) { |
| | | map.put("msg", "充值失败-充值历史记录写入异常"); |
| | | return map; |
| | | } |
| | | |
| | | //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); |
| | | VoTermRecharge voTermRecharge = new VoTermRecharge(); |
| | | voTermRecharge.setProjectNo(projectNo); |
| | | voTermRecharge.setCardNum(po.getCardNum()); |
| | | voTermRecharge.setOrderNo(orderNo); |
| | | |
| | | map.put("success", true); |
| | | map.put("msg", "操作成功"); |
| | | map.put("content", voTermRecharge); |
| | | 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; |
| | | } |
| | | } |