From ce1985a0fc44cb2a8ca5f70cb2361556712804d0 Mon Sep 17 00:00:00 2001 From: liurunyu <lry9898@163.com> Date: 星期三, 25 六月 2025 15:28:35 +0800 Subject: [PATCH] Merge branch 'master' of http://8.140.179.55:20000/r/pipIrr-SV --- pipIrr-platform/pipIrr-web/pipIrr-web-terminal/src/main/java/com/dy/pipIrrTerminal/card/CardSv.java | 570 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 528 insertions(+), 42 deletions(-) diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-terminal/src/main/java/com/dy/pipIrrTerminal/card/CardSv.java b/pipIrr-platform/pipIrr-web/pipIrr-web-terminal/src/main/java/com/dy/pipIrrTerminal/card/CardSv.java index 6c762ce..31520d5 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-terminal/src/main/java/com/dy/pipIrrTerminal/card/CardSv.java +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-terminal/src/main/java/com/dy/pipIrrTerminal/card/CardSv.java @@ -1,27 +1,29 @@ package com.dy.pipIrrTerminal.card; import com.dy.common.webUtil.BaseResponseUtils; +import com.dy.common.webUtil.QueryResultVo; 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.daoSe.*; import com.dy.pipIrrGlobal.pojoSe.SeCardOperate; import com.dy.pipIrrGlobal.pojoSe.SeClientCard; +import com.dy.pipIrrGlobal.pojoSe.SeManagementCard; import com.dy.pipIrrGlobal.pojoSe.SeRechargeHistory; -import com.dy.pipIrrGlobal.voSe.VoAfterRecharge; -import com.dy.pipIrrGlobal.voSe.VoTermActiveCard; -import com.dy.pipIrrGlobal.voSe.VoTermCommon; +import com.dy.pipIrrGlobal.voSe.*; import com.dy.pipIrrTerminal.card.dto.*; +import com.dy.pipIrrTerminal.card.qo.QoCards; +import com.dy.pipIrrTerminal.card.qo.QoLostCards; import com.dy.pipIrrTerminal.card.enums.CardStateENUM; import com.dy.pipIrrTerminal.card.enums.LastOperateENUM; +import com.dy.pipIrrTerminal.card.enums.ManagementCardStateENUM; import com.dy.pipIrrTerminal.card.enums.OperateTypeENUM; import com.dy.pipIrrTerminal.card.enums.RechargeTypeENUM; import lombok.extern.slf4j.Slf4j; +import org.apache.dubbo.common.utils.PojoUtils; 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 com.dy.common.util.IDLongGenerator; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; @@ -52,11 +54,21 @@ @Autowired private SeRechargeHistoryMapper seRechargeHistoryMapper; + @Autowired + private SeManagerCardMapper seManagerCardMapper; + + @Autowired + private SeManagementCardMapper seManagementCardMapper; + + @Autowired + private IDLongGenerator idLongGenerator; + @Value("${project.projectNo}") private Integer projectNo; /** * 鏍规嵁姘村崱鍦板潃鍒ゆ柇璇ュ崱鏄惁鍙互寮�鍗� + * * @param cardAddr * @return true:鍙互寮�鍗� */ @@ -78,6 +90,7 @@ /** * 鏍规嵁姘村崱缂栧彿鍒ゆ柇璇ュ崱鏄惁鍙互鍏呭�� + * * @param po * @return true:鍙互鍏呭�� */ @@ -88,7 +101,7 @@ String stateName = Optional.ofNullable(seClientCardMapper.getCardStateByCardNum(po.getCardNum())).orElse(""); // 鍗曠嫭鍏呭�兼椂鍗$墖蹇呴』涓烘甯� - if((po.getRechargeType() == RechargeTypeENUM.RECHARGE.getCode()) && !stateName.equals("姝e父")) { + if ((po.getRechargeType() == RechargeTypeENUM.RECHARGE.getCode()) && !stateName.equals("姝e父")) { map.put("msg", stateName + ", " + "姘村崱鐘舵�佷笉鏀寔褰撳墠鎿嶄綔"); return map; } @@ -99,6 +112,7 @@ /** * 鏍规嵁姘村崱缂栧彿鍒ゆ柇璇ュ崱鏄惁鍙互鎸傚け + * * @param po * @return true:鍙互鎶ュけ */ @@ -109,7 +123,7 @@ Long cardNum = po.getCardNum(); String stateName = seClientCardMapper.getCardStateByCardNum(cardNum); - if(stateName == null || stateName.equals("") || !stateName.equals("姝e父")) { + if (stateName == null || stateName.equals("") || !stateName.equals("姝e父")) { map.put("msg", stateName + ", " + "姘村崱鐘舵�佷笉鏀寔褰撳墠鎿嶄綔"); return map; } @@ -125,7 +139,7 @@ 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()); + // card.setProtocol(map_card.get("protocol").toString()); map.put("success", true); map.put("content", card); @@ -134,6 +148,7 @@ /** * 鏍规嵁姘村崱缂栧彿鍒ゆ柇璇ュ崱鏄惁鍙互瑙i攣 + * * @param po * @return */ @@ -165,8 +180,10 @@ map.put("content", card); return map; } + /** * 鏍规嵁姘村崱缂栧彿鍒ゆ柇璇ュ崱鏄惁鍙互琛ュ崱 + * * @param po * @return true:鍙互琛ュ崱 */ @@ -178,7 +195,7 @@ Long cardNum = po.getCardNum(); Integer lostCount = seClientCardMapper.getLostCount(cardNum); Integer replacedCount = seClientCardMapper.getReplacedCount(cardNum); - if(lostCount == 0 || replacedCount > 0) { + if (lostCount == 0 || replacedCount > 0) { map.put("msg", "姘村崱鏈寕澶辨垨宸茶ˉ鍗★紝涓嶈兘琛ュ崱"); return map; } @@ -210,6 +227,7 @@ /** * 鏍规嵁姘村崱缂栧彿鍒ゆ柇璇ュ崱鏄惁鍙互娉ㄩ攢 + * * @param po * @return */ @@ -220,7 +238,77 @@ Long cardNum = po.getCardNum(); String stateName = seClientCardMapper.getCardStateByCardNum(cardNum); - if(stateName == null || stateName.equals("") || !stateName.equals("姝e父")) { + if (stateName == null || stateName.equals("") || !stateName.equals("姝e父")) { + 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())); + + map.put("success", true); + map.put("content", card); + return map; + } + + /** + * 鏍规嵁姘村崱缂栧彿鍒ゆ柇璇ュ崱鏄惁鍙互琛ユ墸 + * + * @param po + * @return + */ + public Map canRepay(DtoRepaySupplement 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("姝e父")) { + 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())); + + map.put("success", true); + map.put("content", card); + return map; + } + + /** + * 鏍规嵁姘村崱缂栧彿鍒ゆ柇璇ュ崱鏄惁鍙互杩旇繕 + * + * @param po + * @return + */ + public Map canSupplement(DtoRepaySupplement 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("姝e父")) { map.put("msg", stateName + ", " + "姘村崱鐘舵�佷笉鏀寔褰撳墠鎿嶄綔"); return map; } @@ -244,6 +332,7 @@ /** * 鏍规嵁鍐滄埛缂栧彿鑾峰彇5绾ц鏀垮尯鍒掍覆areaCode锛岃ˉ鍗¤繃绋嬩腑寮�鏂板崱浣跨敤 + * * @param clientId * @return */ @@ -365,6 +454,7 @@ /** * 寮�鍗¢檮鍔犲厖鍊� + * * @param po * @param cardNum * @return @@ -398,6 +488,7 @@ /** * 婵�娲绘垨琛ュ崱 + * * @param po * @return */ @@ -415,7 +506,7 @@ } Map map_cardNum = generateCardNum(po.getClientId()); - if(map_cardNum.get("success").equals(false)) { + if (map_cardNum.get("success").equals(false)) { map.put("msg", map_cardNum.get("msg").toString()); return map; } @@ -423,14 +514,14 @@ String orderNo = generateOrderNo(); Map map_addCardAndOperate = addCardAndOperate(po, cardNum, orderNo); - if(map_addCardAndOperate.get("success").equals(false)) { + if (map_addCardAndOperate.get("success").equals(false)) { map.put("msg", map_addCardAndOperate.get("msg").toString()); return map; } if (amount != null && amount > 0 && originalCardId == null) { Map map_plusRecharge = plusRecharge(po, cardNum, orderNo); - if(map_plusRecharge.get("success").equals(false)) { + if (map_plusRecharge.get("success").equals(false)) { map.put("msg", map_plusRecharge.get("msg").toString()); return map; } @@ -455,6 +546,7 @@ /** * 鍏呭�� + * * @param po * @return */ @@ -465,7 +557,7 @@ map.put("content", null); Map map_canRecharge = canRecharge(po); - if(map_canRecharge.get("success").equals(false)) { + if (map_canRecharge.get("success").equals(false)) { map.put("msg", map_canRecharge.get("msg").toString()); return map; } @@ -480,7 +572,7 @@ } Long cardId = Long.parseLong(map_cardAndClient.get("cardId").toString()); Long clientId = Long.parseLong(map_cardAndClient.get("clientId").toString()); - if(orderNo == null || orderNo.length() <= 0) { + if (orderNo == null || orderNo.length() <= 0) { orderNo = generateOrderNo(); } @@ -537,6 +629,7 @@ voTermRecharge.setProjectNo(projectNo); voTermRecharge.setCardNum(po.getCardNum()); voTermRecharge.setOrderNo(orderNo); + voTermRecharge.setBalance(afterRecharge); map.put("success", true); map.put("msg", "鎿嶄綔鎴愬姛"); @@ -546,6 +639,7 @@ /** * 琛ュ崱 + * * @param po * @return */ @@ -556,7 +650,7 @@ map.put("content", null); Map map_canReissue = canReissue(po); - if(map_canReissue.get("success").equals(false)) { + if (map_canReissue.get("success").equals(false)) { map.put("msg", map_canReissue.get("msg").toString()); return map; } @@ -590,6 +684,7 @@ /** * 鎸傚け + * * @param po * @return */ @@ -600,7 +695,7 @@ map.put("content", null); Map map_canReportLoss = canReportLoss(po); - if(map_canReportLoss.get("success").equals(false)) { + if (map_canReportLoss.get("success").equals(false)) { map.put("msg", map_canReportLoss.get("msg").toString()); return map; } @@ -617,7 +712,8 @@ seClientCard.setLossdtdt(new Date()); seClientCard.setState(CardStateENUM.LOSS.getCode()); seClientCard.setLastoper(LastOperateENUM.LOSS.getCode()); - Integer rec_updateClientCard = Optional.ofNullable(seClientCardMapper.updateByPrimaryKeySelective(seClientCard)).orElse(0); + Integer rec_updateClientCard = Optional.ofNullable(seClientCardMapper.updateByPrimaryKeySelective(seClientCard)) + .orElse(0); if (rec_updateClientCard == 0) { map.put("msg", "鎸傚け澶辫触-鍐滄埛鍗′慨鏀瑰紓甯�"); return map; @@ -647,6 +743,7 @@ /** * 瑙i攣 + * * @param po * @return */ @@ -657,7 +754,7 @@ map.put("content", null); Map map_canUnlock = canUnlock(po); - if(map_canUnlock.get("success").equals(false)) { + if (map_canUnlock.get("success").equals(false)) { map.put("msg", map_canUnlock.get("msg").toString()); return map; } @@ -667,8 +764,8 @@ /** * 淇敼鍐滄埛鍗′俊鎭細 - * 鎸傚け鏃堕棿 - * 鏈�鍚庢搷浣滅被鍨�-4 + * 鎸傚け鏃堕棿 + * 鏈�鍚庢搷浣滅被鍨�-4 */ SeClientCard seClientCard = new SeClientCard(); seClientCard.setId(cardId); @@ -676,7 +773,8 @@ seClientCard.setMoney(po.getMoney()); seClientCard.setState(CardStateENUM.NORMAL.getCode()); seClientCard.setLastoper(LastOperateENUM.UNLOCK.getCode()); - Integer rec_updateClientCard = Optional.ofNullable(seClientCardMapper.updateByPrimaryKeySelective(seClientCard)).orElse(0); + Integer rec_updateClientCard = Optional.ofNullable(seClientCardMapper.updateByPrimaryKeySelective(seClientCard)) + .orElse(0); if (rec_updateClientCard == 0) { map.put("msg", "瑙i攣澶辫触-鍐滄埛鍗′慨鏀瑰紓甯�"); return map; @@ -708,6 +806,7 @@ /** * 閿�鍗� + * * @param po * @return */ @@ -718,8 +817,8 @@ map.put("content", null); String orderNo = generateOrderNo(); - Map map_canCancel = canCancel(po); - if(map_canCancel.get("success").equals(false)) { + Map map_canCancel = canCancel(po); + if (map_canCancel.get("success").equals(false)) { map.put("msg", map_canCancel.get("msg").toString()); return map; } @@ -756,7 +855,113 @@ } /** + * 琛ユ墸 + * + * @param po + * @return + */ + @Transactional(rollbackFor = Exception.class) + public Map repay(DtoRepaySupplement po) { + Map map = new HashMap<>(); + map.put("success", false); + map.put("content", null); + String orderNo = generateOrderNo(); + Date operateTime = new Date(); + Double waterPrice = Optional.ofNullable(prWaterPriceMapper.getPrice()).orElse(0.0); + + Map map_canRepay = canRepay(po); + if (map_canRepay.get("success").equals(false)) { + map.put("msg", map_canRepay.get("msg").toString()); + return map; + } + CardSimple card = (CardSimple) map_canRepay.get("content"); + Long cardId = card.getCardId(); + Long clientId = card.getClientId(); + + SeCardOperate seCardOperate = new SeCardOperate(); + seCardOperate.setCardId(cardId); + seCardOperate.setClientId(clientId); + seCardOperate.setMoney(po.getBalance()); + seCardOperate.setRefundAmount(po.getRepayMorny()); + seCardOperate.setOperateType(OperateTypeENUM.REFUND.getCode()); + seCardOperate.setRemarks(po.getRemarks()); + seCardOperate.setOperator(po.getOperator()); + seCardOperate.setOperateDt(operateTime); + seCardOperate.setOrderNo(orderNo); + seCardOperate.setOperateValid((byte) 1); + seCardOperateMapper.insert(seCardOperate); + if (seCardOperate.getId() == 0) { + map.put("msg", "琛ユ墸澶辫触-琛ユ墸璁板綍鍐欏叆寮傚父"); + return map; + } + + VoRepaySupplement voRepaySupplement = new VoRepaySupplement(); + voRepaySupplement.setBalance(po.getBalance() - po.getRepayMorny()); + voRepaySupplement.setWaterPrice(waterPrice); + voRepaySupplement.setTime(operateTime); + voRepaySupplement.setOrderNo(orderNo); + + map.put("success", true); + map.put("msg", "鎿嶄綔鎴愬姛"); + map.put("content", voRepaySupplement); + return map; + } + + /** + * 杩旇繕 + * + * @param po + * @return + */ + @Transactional(rollbackFor = Exception.class) + public Map supplement(DtoRepaySupplement po) { + Map map = new HashMap<>(); + map.put("success", false); + map.put("content", null); + String orderNo = generateOrderNo(); + Date operateTime = new Date(); + Double waterPrice = Optional.ofNullable(prWaterPriceMapper.getPrice()).orElse(0.0); + + Map map_canSupplement = canSupplement(po); + if (map_canSupplement.get("success").equals(false)) { + map.put("msg", map_canSupplement.get("msg").toString()); + return map; + } + CardSimple card = (CardSimple) map_canSupplement.get("content"); + Long cardId = card.getCardId(); + Long clientId = card.getClientId(); + + SeCardOperate seCardOperate = new SeCardOperate(); + seCardOperate.setCardId(cardId); + seCardOperate.setClientId(clientId); + seCardOperate.setMoney(po.getBalance()); + seCardOperate.setRefundAmount(po.getSupplementMoney()); + seCardOperate.setOperateType(OperateTypeENUM.SUPPLEMENT.getCode()); + seCardOperate.setRemarks(po.getRemarks()); + seCardOperate.setOperator(po.getOperator()); + seCardOperate.setOperateDt(operateTime); + seCardOperate.setOrderNo(orderNo); + seCardOperate.setOperateValid((byte) 1); + seCardOperateMapper.insert(seCardOperate); + if (seCardOperate.getId() == 0) { + map.put("msg", "杩旇繕澶辫触-杩旇繕璁板綍鍐欏叆寮傚父"); + return map; + } + VoRepaySupplement voRepaySupplement = new VoRepaySupplement(); + voRepaySupplement.setBalance(po.getBalance() + po.getSupplementMoney()); + voRepaySupplement.setWaterPrice(waterPrice); + voRepaySupplement.setTime(operateTime); + voRepaySupplement.setOrderNo(orderNo); + + map.put("success", true); + map.put("msg", "鎿嶄綔鎴愬姛"); + map.put("content", voRepaySupplement); + return map; + } + + /** * 鎿嶄綔鍥炶皟 + * * @param po * @return */ @@ -770,21 +975,28 @@ Integer operateType = po.getOperateType(); String orderNumber = po.getOrderNumber(); + // 鍏堟鏌ユ槸鍚︿负绠$悊鍗� + if (operateType.equals(OperateTypeENUM.MANAGEMENT_CARD_WRITE.getCode().intValue())) { + // 绠$悊绫诲瀷鍗″啓鍗¢�昏緫 + return handleManagementCardWrite(cardAddr, orderNumber); + } + + // 澶勭悊鍐滄埛鍗¢�昏緫 Long cardId = seClientCardMapper.getCardIdByAddr(cardAddr); if (cardId == null || cardId.equals(0)) { map.put("msg", "鎮ㄦ寚瀹氱殑姘村崱涓嶅瓨鍦�"); return map; } - if(operateType == 1) { + if (operateType.equals(OperateTypeENUM.ACTIVE.getCode().intValue())) { /** * 寮�鍗℃搷浣滄墽琛岄�氱煡 - * 1.渚濇嵁璁㈠崟鍙峰皢鏃犳晥鐘舵�佺殑鎿嶄綔璁板綍鏀逛负鏈夋晥 - * 2.渚濇嵁姘村崱ID灏嗘棤鏁堢姸鎬佺殑姘村崱璁板綍鏀逛负鏈夋晥 - * 3.濡傛灉寮�鍗″悓姝ュ厖鍊� - * 淇敼鍏呭�兼搷浣滆褰曚负鏈夋晥 - * 淇敼鍏呭�煎巻鍙茶褰曚负鏈夋晥 - * 淇敼姘村崱琛ㄧ殑鎿嶄綔淇℃伅 + * 1.渚濇嵁璁㈠崟鍙峰皢鏃犳晥鐘舵�佺殑鎿嶄綔璁板綍鏀逛负鏈夋晥 + * 2.渚濇嵁姘村崱ID灏嗘棤鏁堢姸鎬佺殑姘村崱璁板綍鏀逛负鏈夋晥 + * 3.濡傛灉寮�鍗″悓姝ュ厖鍊� + * 淇敼鍏呭�兼搷浣滆褰曚负鏈夋晥 + * 淇敼鍏呭�煎巻鍙茶褰曚负鏈夋晥 + * 淇敼姘村崱琛ㄧ殑鎿嶄綔淇℃伅 */ Integer rec_ope = turnOperateValidByOrderNumber(orderNumber); Integer rec_card = turnCardValidByOrderNumber(orderNumber); @@ -793,12 +1005,12 @@ return map; } - if(isMergeRecharge(cardId)) { + if (isMergeRecharge(cardId)) { turnOperateValidByOrderNumber(orderNumber + "p"); turnRechargeHistoryValidByOrderNumber(orderNumber); - updateCard(cardId, orderNumber+"p"); + updateCard(cardId, orderNumber + "p"); } - } else if (operateType == 2) { + } else if (operateType.equals(OperateTypeENUM.RECHARGE.getCode().intValue())) { /** * 鍏呭�兼搷浣滄墽琛岄�氱煡 * 1. 鎿嶄綔璁板綍鏀逛负鏈夋晥 @@ -807,8 +1019,8 @@ */ turnOperateValidByOrderNumber(orderNumber + "p"); turnRechargeHistoryValidByOrderNumber(orderNumber); - updateCard(cardId, orderNumber+"p"); - }else if (operateType == 3) { + updateCard(cardId, orderNumber + "p"); + } else if (operateType.equals(OperateTypeENUM.CANCEL.getCode().intValue())) { /** * 閿�鍗℃搷浣滄墽琛岄�氱煡 * 1. 鎿嶄綔璁板綍鏀逛负鏈夋晥 @@ -822,13 +1034,13 @@ return map; } - } else if (operateType == 4) { + } else if (operateType.equals(OperateTypeENUM.REISSUE.getCode().intValue())) { /** * 琛ュ崱鎿嶄綔鎵ц閫氱煡 * 1. 鏂版按鍗¤褰曟敼涓烘湁鏁� * 2. 寮�鍗℃搷浣滆褰曟敼涓烘湁鏁� * 3. 濡傛灉瀛樺湪閫�杩橀噾棰� - * 娓呯┖鍘熷崱浣欓 + * 娓呯┖鍘熷崱浣欓 */ Integer rec_card = turnCardValidByOrderNumber(orderNumber); Integer rec_ope = turnOperateValidByOrderNumber(orderNumber); @@ -837,11 +1049,76 @@ map.put("msg", "琛ュ崱鍥炶皟澶辫触"); return map; } - + } else if (operateType.equals(OperateTypeENUM.REFUND.getCode().intValue())) { + /** + * 琛ユ墸鎿嶄綔鎵ц閫氱煡 + * 1. 鎿嶄綔璁板綍鏀逛负鏈夋晥 + * 2. 淇敼姘村崱琛ㄦ搷浣滀俊鎭強浣欓 + */ + Integer rec_ope = turnOperateValidByOrderNumber(orderNumber); + Integer rec_card = updateCardInfo_repay(cardId, orderNumber); + if (rec_ope == 0 || rec_card == 0) { + map.put("msg", "琛ユ墸鍥炶皟澶辫触"); + return map; + } + } else if (operateType.equals(OperateTypeENUM.SUPPLEMENT.getCode().intValue())) { + /** + * 杩旇繕鎿嶄綔鎵ц閫氱煡 + * 1. 鎿嶄綔璁板綍鏀逛负鏈夋晥 + * 2. 淇敼姘村崱琛ㄦ搷浣滀俊鎭強浣欓 + */ + Integer rec_ope = turnOperateValidByOrderNumber(orderNumber); + Integer rec_card = updateCardInfo_supplement(cardId, orderNumber); + if (rec_ope == 0 || rec_card == 0) { + map.put("msg", "杩旇繕鍥炶皟澶辫触"); + return map; + } } map.put("success", true); map.put("msg", "鎿嶄綔鎴愬姛"); + return map; + } + + /** + * 澶勭悊绠$悊绫诲瀷鍗″啓鍗″洖璋� + * + * @param cardAddr 鍗″湴鍧� + * @param orderNumber 璁㈠崟鍙� + * @return 澶勭悊缁撴灉 + */ + private Map<String, Object> handleManagementCardWrite(String cardAddr, String orderNumber) { + Map<String, Object> map = new HashMap<>(); + map.put("success", false); + map.put("content", null); + + try { + // 鏍规嵁鍗″湴鍧�鍜岃鍗曞彿鏌ユ壘绠$悊鍗� + SeManagementCard managementCard = seManagementCardMapper.selectOne( + com.baomidou.mybatisplus.core.toolkit.Wrappers.<SeManagementCard>lambdaQuery() + .eq(SeManagementCard::getCardAddr, cardAddr) + .eq(SeManagementCard::getOrderNo, orderNumber)); + + if (managementCard == null) { + map.put("msg", "鏈壘鍒板搴旂殑绠$悊鍗¤褰�"); + return map; + } + + // 鏇存柊绠$悊鍗$姸鎬佷负姝e父 + managementCard.setState(ManagementCardStateENUM.NORMAL.getCode()); + + int updateResult = seManagementCardMapper.updateByPrimaryKeySelective(managementCard); + if (updateResult > 0) { + map.put("success", true); + map.put("msg", "绠$悊鍗″啓鍗″畬鎴愶紝鐘舵�佸凡鏇存柊涓烘甯�"); + } else { + map.put("msg", "绠$悊鍗$姸鎬佹洿鏂板け璐�"); + } + } catch (Exception e) { + log.error("澶勭悊绠$悊鍗″啓鍗″洖璋冨紓甯�", e); + map.put("msg", "澶勭悊绠$悊鍗″啓鍗″洖璋冩椂鍙戠敓寮傚父锛�" + e.getMessage()); + } + return map; } @@ -887,12 +1164,13 @@ /** * 濡傛灉琛ュ崱鏃堕��杩樹簡閲戦锛屾竻绌烘寕澶卞崱浣欓 + * * @param orderNumber */ public Integer emptyCardBalance(String orderNumber) { Integer rec_empty = 0; Float noTradeAmount = seCardOperateMapper.getNoTradeAmount(orderNumber); - if(noTradeAmount != null && noTradeAmount > 0) { + if (noTradeAmount != null && noTradeAmount > 0) { rec_empty = seClientCardMapper.emptyCardBalance(orderNumber); } return rec_empty; @@ -900,6 +1178,7 @@ /** * 淇敼娉ㄩ攢姘村崱琛ㄧ殑璁板綍鍙婁綑棰濓紙0锛� + * * @param orderNumber * @return */ @@ -916,7 +1195,52 @@ } /** + * 淇敼琛ユ墸姘村崱琛ㄨ褰曞強浣欓 + * + * @param cardId + * @param orderNumber + * @return + */ + public Integer updateCardInfo_repay(Long cardId, String orderNumber) { + VoRepaySupplementSimple po = seCardOperateMapper.getCardOperateByOrderNumber(orderNumber); + Float money = Optional.ofNullable(po.getMoney()).orElse(0f); + Float refundAmount = Optional.ofNullable(po.getRefundAmount()).orElse(0f); + Date operateTime = po.getOperateTime(); + + SeClientCard clientCard = new SeClientCard(); + clientCard.setId(cardId); + clientCard.setRefunddt(operateTime); + clientCard.setMoney(money - refundAmount); + clientCard.setState(CardStateENUM.NORMAL.getCode()); + clientCard.setLastoper(LastOperateENUM.REFUND.getCode()); + return seClientCardMapper.updateByPrimaryKeySelective(clientCard); + } + + /** + * 淇敼杩旇繕姘村崱琛ㄨ褰曞強浣欓 + * + * @param cardId + * @param orderNumber + * @return + */ + public Integer updateCardInfo_supplement(Long cardId, String orderNumber) { + VoRepaySupplementSimple po = seCardOperateMapper.getCardOperateByOrderNumber(orderNumber); + Float money = Optional.ofNullable(po.getMoney()).orElse(0f); + Float refundAmount = Optional.ofNullable(po.getRefundAmount()).orElse(0f); + Date operateTime = po.getOperateTime(); + + SeClientCard clientCard = new SeClientCard(); + clientCard.setId(cardId); + clientCard.setRefunddt(operateTime); + clientCard.setMoney(money + refundAmount); + clientCard.setState(CardStateENUM.NORMAL.getCode()); + clientCard.setLastoper(LastOperateENUM.WRITE_BACK.getCode()); + return seClientCardMapper.updateByPrimaryKeySelective(clientCard); + } + + /** * 鍒ゆ柇鎸囧畾姘村崱鏄惁涓烘寕澶辩姸鎬佷笖鏃犺ˉ鍗¤褰� + * * @param cardNum * @return */ @@ -928,4 +1252,166 @@ } return false; } + + /** + * 璇诲彇姘村崱淇℃伅 + * + * @param cardAddr + * @return + */ + public VoTermCard readCard(String cardAddr) { + VoTermCard voTermCard = seClientCardMapper.getTermCardInfo(cardAddr); + if (voTermCard != null) { + return voTermCard; + } + + VoTermCard voTermManagerCard = seManagerCardMapper.getTermManagerCardInfo(cardAddr); + if (voTermManagerCard != null) { + return voTermManagerCard; + } + + return null; + } + + /** + * 鏍规嵁鎸囧畾鏉′欢鑾峰彇姘村崱鍒楄〃 + * + * @param vo 鏌ヨ鏉′欢 + * @return 姘村崱鍒楄〃 + */ + public QueryResultVo<List<VoCards>> getCards(QoCards vo) { + Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(vo); + Long itemTotal = seClientCardMapper.getCardsCount(params); + + QueryResultVo<List<VoCards>> rsVo = new QueryResultVo<>(); + rsVo.pageSize = vo.pageSize; + rsVo.pageCurr = vo.pageCurr; + + if (itemTotal > 0) { + rsVo.calculateAndSet(itemTotal, params); + List<VoCards> list = seClientCardMapper.getCards(params); + rsVo.obj = list; + } else { + rsVo.obj = new ArrayList<>(); + rsVo.itemTotal = 0L; + } + + return rsVo; + } + + /** + * 鑾峰彇宸叉寕澶辩殑姘村崱鍒楄〃 + * + * @param vo 鏌ヨ鏉′欢 + * @return 宸叉寕澶辩殑姘村崱鍒楄〃 + */ + public QueryResultVo<List<VoCards>> getLostCards(QoLostCards vo) { + Map<String, Object> params = new HashMap<>(); + params.put("pageCurr", vo.pageCurr); + params.put("pageSize", vo.pageSize); + params.put("state", 2); // 鎸傚け鐘舵�� + + Long itemTotal = seClientCardMapper.getLostCardsCount(params); + + QueryResultVo<List<VoCards>> rsVo = new QueryResultVo<>(); + rsVo.pageSize = vo.pageSize; + rsVo.pageCurr = vo.pageCurr; + + if (itemTotal > 0) { + rsVo.calculateAndSet(itemTotal, params); + List<VoCards> list = seClientCardMapper.getLostCards(params); + rsVo.obj = list; + } else { + rsVo.obj = new ArrayList<>(); + rsVo.itemTotal = 0L; + } + + return rsVo; + } + + /** + * 鏍规嵁姘村崱缂栧彿鑾峰彇鍗′俊鎭� + * + * @param cardNum 姘村崱缂栧彿 + * @return 鍗′俊鎭� + */ + public VoCardByClientNum getCardByCardNum(String cardNum) { + return seClientCardMapper.getCardByCardNum(cardNum); + } + + /** + * 鍒涘缓绠$悊鍗� + * + * @param dto 鍒涘缓绠$悊鍗TO + * @return 鍒涘缓缁撴灉 + */ + @Transactional(rollbackFor = Exception.class) + public Map<String, Object> createManagementCard(CreateManagementCardDto dto) { + Map<String, Object> result = new HashMap<>(); + result.put("success", false); + + try { + // 妫�鏌ュ崱鍦板潃鏄惁宸插瓨鍦� + if (isCardAddrExists(dto.getCardAddr())) { + result.put("msg", "鍒涘缓澶辫触-姝ゅ崱鍦板潃宸插瓨鍦�"); + return result; + } + + // 鍙傝�僼ermActiveCard閫昏緫锛氱敓鎴愯鍗曞彿 + String orderNo = generateOrderNo(); + + // 浣跨敤IDLongGenerator鐢熸垚鍞竴ID + Long id = idLongGenerator.generate(); + Date createTime = new Date(); + + // 鏋勫缓绠$悊鍗″璞� + SeManagementCard managementCard = SeManagementCard.builder() + .id(id) + .protocol(dto.getProtocol()) + .cardAddr(dto.getCardAddr()) + .securityCode(dto.getSecurityCode()) + .cardType(dto.getCardType()) + .createTime(createTime) + .orderNo(orderNo) + .districtCode(dto.getDistrictCode()) + .projectNo(dto.getProjectNo() != null ? dto.getProjectNo() : this.projectNo) + .ip(dto.getIp()) + .domain(dto.getDomain()) + .openClostTime(dto.getOpenClostTime()) + .remarks(dto.getRemarks()) + .state(ManagementCardStateENUM.UNWRITTEN.getCode()) // 榛樿鐘舵�佷负鏈啓鍗� + .build(); + + // 鎻掑叆鏁版嵁搴� + int insertResult = seManagementCardMapper.insertSelective(managementCard); + + if (insertResult > 0) { + result.put("success", true); + result.put("content", orderNo); // 杩斿洖璁㈠崟鍙� + result.put("msg", "璇锋眰鎴愬姛"); + } else { + result.put("msg", "绠$悊鍗″垱寤哄け璐�-鏁版嵁搴撴彃鍏ュ紓甯�"); + } + + } catch (Exception e) { + log.error("鍒涘缓绠$悊鍗″紓甯�: {}", e.getMessage(), e); + result.put("msg", "绠$悊鍗″垱寤哄け璐�: " + e.getMessage()); + } + + return result; + } + + /** + * 妫�鏌ュ崱鐗囧湴鍧�鏄惁宸插瓨鍦� + * + * @param cardAddr 鍗$墖鍦板潃 + * @return true-宸插瓨鍦紝false-涓嶅瓨鍦� + */ + public boolean isCardAddrExists(String cardAddr) { + // 浣跨敤涓�娆℃煡璇㈡鏌ヤ袱涓〃涓槸鍚﹀瓨鍦ㄨ鍗″湴鍧� + // 1. 绠$悊鍗¤〃锛氭墍鏈夎褰曢兘妫�鏌� + // 2. 鍐滄埛姘村崱琛細鍙鏌ユ甯�(1)鍜屾寕澶�(3)鐘舵�佺殑璁板綍 + Long totalCount = seClientCardMapper.checkCardAddrExists(cardAddr); + return totalCount != null && totalCount > 0; + } } -- Gitblit v1.8.0