|  |  | 
 |  |  | import com.dy.pipIrrGlobal.pojoBa.BaClient; | 
 |  |  | import com.dy.pipIrrGlobal.pojoSe.SeCardOperate; | 
 |  |  | import com.dy.pipIrrGlobal.pojoSe.SeClientCard; | 
 |  |  | import com.dy.pipIrrGlobal.pojoSe.SeManagerCard; | 
 |  |  | import com.dy.pipIrrGlobal.util.AmountToChinese; | 
 |  |  | import com.dy.pipIrrGlobal.voSe.VoActiveCard; | 
 |  |  | import com.dy.pipIrrGlobal.voSe.VoOperate; | 
 |  |  | 
 |  |  | import jakarta.validation.Valid; | 
 |  |  | import lombok.RequiredArgsConstructor; | 
 |  |  | import lombok.extern.slf4j.Slf4j; | 
 |  |  | import org.springframework.beans.factory.annotation.Value; | 
 |  |  | import org.springframework.http.MediaType; | 
 |  |  | import org.springframework.transaction.annotation.Transactional; | 
 |  |  | import org.springframework.validation.BindingResult; | 
 |  |  | 
 |  |  |     private final CardOperateSv cardOperateSv; | 
 |  |  |     private final ClientCardSv clientCardSv; | 
 |  |  |  | 
 |  |  |     @Value("${project.divisionCode}") | 
 |  |  |     private String divisionCode; | 
 |  |  |     /** | 
 |  |  |      * 开卡 | 
 |  |  |      * @param po 开卡传入对象 | 
 |  |  | 
 |  |  |     @SsoAop() | 
 |  |  |     public BaseResponse<Boolean> add_active(@RequestBody @Valid ActiveCard po, BindingResult bindingResult){ | 
 |  |  |         if(bindingResult != null && bindingResult.hasErrors()){ | 
 |  |  |             return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
 |  |  |             return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         Long clientId = po.getClientId(); | 
 |  |  | 
 |  |  |          * operator         操作人编号 | 
 |  |  |          * activeTime       开卡时间 | 
 |  |  |          */ | 
 |  |  |         String protocol = po.getProtocol(); | 
 |  |  |         String cardAddr = po.getCardAddr(); | 
 |  |  |         Integer cardCost = po.getCardCost(); | 
 |  |  |         Long originalCardId = po.getOriginalCardId(); | 
 |  |  | 
 |  |  |          * 添加农户卡记录,退还金额作为当前余额 | 
 |  |  |          */ | 
 |  |  |         SeClientCard seClientCard = new SeClientCard(); | 
 |  |  |         seClientCard.setProtocol(protocol); | 
 |  |  |         seClientCard.setCardaddr(cardAddr); | 
 |  |  |         seClientCard.setCardnum(cardNum); | 
 |  |  |         seClientCard.setClientid(clientId); | 
 |  |  | 
 |  |  |     @SsoAop() | 
 |  |  |     public BaseResponse<Boolean> add_reissue(@RequestBody @Valid DtoReissue po, BindingResult bindingResult){ | 
 |  |  |         if(bindingResult != null && bindingResult.hasErrors()){ | 
 |  |  |             return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
 |  |  |             return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         /** | 
 |  |  | 
 |  |  |          * operator         操作人编号 | 
 |  |  |          */ | 
 |  |  |  | 
 |  |  |         String protocol; | 
 |  |  |         String cardAddr = po.getCardAddr(); | 
 |  |  |         String clientNum = ""; | 
 |  |  |         Long clientId = 0L; | 
 |  |  | 
 |  |  |         // 如果传入了退还金额,需要判断老卡(被挂失的水卡)挂失时是否已经退款,无论退款多少都提示用户挂失时已退款 | 
 |  |  |         if(reissueAmount != null && reissueAmount > 0) { | 
 |  |  |             Double tradeAmount = cardOperateSv.getTradeAmountByCardNo(cardNum); | 
 |  |  |             if(tradeAmount != null) { | 
 |  |  |             if(tradeAmount != null && tradeAmount > 0) { | 
 |  |  |                 return BaseResponseUtils.buildErrorMsg(SellResultCode.THE_FEE_CANNOT_BE_REFUNDED.getMessage()); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  | 
 |  |  |         clientNum = map.get("clientNum").toString(); | 
 |  |  |         cardId = Long.parseLong(map.get("cardId").toString()); | 
 |  |  |         clientId = Long.parseLong(map.get("clientId").toString()); | 
 |  |  |         protocol = map.get("protocol").toString(); | 
 |  |  |  | 
 |  |  |         /** | 
 |  |  |          * 如果是补卡调用的开卡且转移了退还金额,需修改挂失卡余额为0 | 
 |  |  | 
 |  |  |          * 添加开卡记录,退还金额冲到新卡中 | 
 |  |  |          */ | 
 |  |  |         ActiveCard activeCard = new ActiveCard(); | 
 |  |  |         activeCard.setProtocol(protocol); | 
 |  |  |         activeCard.setCardAddr(cardAddr); | 
 |  |  |         activeCard.setClientId(clientId); | 
 |  |  |         activeCard.setOriginalCardId(cardId); | 
 |  |  | 
 |  |  |         map_response.put("projectNo", projectNo); | 
 |  |  |         map_response.put("orderNumber", orderNumber); | 
 |  |  |         map_response.put("cardNum", cardNum); | 
 |  |  |         map_response.put("protocol", protocol); | 
 |  |  |         return BaseResponseUtils.buildSuccess(map_response) ; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | 
 |  |  |     @SsoAop() | 
 |  |  |     public BaseResponse<Boolean> add_recharge(@RequestBody @Valid DtoRecharge po, BindingResult bindingResult){ | 
 |  |  |         if(bindingResult != null && bindingResult.hasErrors()){ | 
 |  |  |             return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
 |  |  |             return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
 |  |  |         } | 
 |  |  |         return cardOperateSv.addRecharge(po); | 
 |  |  |     } | 
 |  |  | 
 |  |  |     @SsoAop() | 
 |  |  |     public BaseResponse<Boolean> add_cancel(@RequestBody @Valid DtoCancel po, BindingResult bindingResult){ | 
 |  |  |         if(bindingResult != null && bindingResult.hasErrors()){ | 
 |  |  |             return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
 |  |  |             return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         /** | 
 |  |  | 
 |  |  |     @SsoAop() | 
 |  |  |     public BaseResponse<Boolean> add_loss(@RequestBody @Valid DtoLoss po, BindingResult bindingResult){ | 
 |  |  |         if(bindingResult != null && bindingResult.hasErrors()){ | 
 |  |  |             return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
 |  |  |             return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         /** | 
 |  |  | 
 |  |  |     @SsoAop() | 
 |  |  |     public BaseResponse<Boolean> add_reversal(@RequestBody @Valid DtoReversal po, BindingResult bindingResult){ | 
 |  |  |         if(bindingResult != null && bindingResult.hasErrors()){ | 
 |  |  |             return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
 |  |  |             return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         /** | 
 |  |  | 
 |  |  |     @SsoAop() | 
 |  |  |     public BaseResponse<Boolean> add_refund(@RequestBody @Valid DtoRefund po, BindingResult bindingResult){ | 
 |  |  |         if(bindingResult != null && bindingResult.hasErrors()){ | 
 |  |  |             return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
 |  |  |             return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         /** | 
 |  |  | 
 |  |  |     @SsoAop() | 
 |  |  |     public BaseResponse<Boolean> add_unlock(@RequestBody @Valid DtoUnlock po, BindingResult bindingResult){ | 
 |  |  |         if(bindingResult != null && bindingResult.hasErrors()){ | 
 |  |  |             return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
 |  |  |             return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         /** | 
 |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 创建管理卡 | 
 |  |  |      * @param po | 
 |  |  |      * @param bindingResult | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     @PostMapping(path = "create_manager_card", consumes = MediaType.APPLICATION_JSON_VALUE) | 
 |  |  |     @Transactional(rollbackFor = Exception.class) | 
 |  |  |     @SsoAop() | 
 |  |  |     public BaseResponse<Boolean> createManagerCard(@RequestBody @Valid ManagerCard po, BindingResult bindingResult){ | 
 |  |  |         if(bindingResult != null && bindingResult.hasErrors()){ | 
 |  |  |             return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         /** | 
 |  |  |          * 根据行政区划串(divisionCode)在管理卡表中针对卡片编号(cardNum)进行模糊查询 | 
 |  |  |          * 如果顺序号已经达到最大值,提示用户联系系统管理员 | 
 |  |  |          * 如果顺序号未达到最大值,则加1 | 
 |  |  |          * cardNum为新的卡号 | 
 |  |  |          */ | 
 |  |  |         String cardNum = Optional.ofNullable(cardOperateSv.getManagerCardNumOfMax(divisionCode)).orElse(""); | 
 |  |  |         if(cardNum != null && cardNum.trim().length() > 0) { | 
 |  |  |             Integer number = Integer.parseInt(cardNum.substring(12)); | 
 |  |  |             number = number + 1; | 
 |  |  |             if(number > 65535) { | 
 |  |  |                 return BaseResponseUtils.buildErrorMsg(SellResultCode.CARD_NUMBER_OVERRUN.getMessage()); | 
 |  |  |             } | 
 |  |  |             cardNum = cardNum.substring(0, 12) + String.format("%05d", number); | 
 |  |  |         } else { | 
 |  |  |             cardNum = divisionCode + "00001"; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         SeManagerCard seManagerCard = new SeManagerCard(); | 
 |  |  |         seManagerCard.setCardAddr(po.getCardAddr()); | 
 |  |  |         seManagerCard.setCardNum(cardNum); | 
 |  |  |         seManagerCard.setCardType(po.getCardType()); | 
 |  |  |         seManagerCard.setCreateTime(new Date()); | 
 |  |  |         seManagerCard.setRemarks(po.getRemarks()); | 
 |  |  |         Long managerCardId = cardOperateSv.addManagerCard(seManagerCard); | 
 |  |  |         if(managerCardId == 0) { | 
 |  |  |             return BaseResponseUtils.buildErrorMsg(SellResultCode.CREATE_MANAGER_CARD_ERROR.getMessage()); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         return BaseResponseUtils.buildSuccess(cardNum); | 
 |  |  |  | 
 |  |  |         //Map map = new HashMap(); | 
 |  |  |         //map.put("cardNum", cardNum); | 
 |  |  |         //return BaseResponseUtils.buildSuccess(map) ; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 获取充值记录 | 
 |  |  |      * @param vo | 
 |  |  |      * @return | 
 |  |  | 
 |  |  |         try { | 
 |  |  |             QueryResultVo<List<VoActiveCard>> res = cardOperateSv.getActiveCards(vo); | 
 |  |  |             if(res.itemTotal == 0) { | 
 |  |  |                 return BaseResponseUtils.buildFail(SellResultCode.No_ActiveCards.getMessage()); | 
 |  |  |                 return BaseResponseUtils.buildErrorMsg(SellResultCode.No_ActiveCards.getMessage()); | 
 |  |  |             } | 
 |  |  |             return BaseResponseUtils.buildSuccess(res); | 
 |  |  |         } catch (Exception e) { | 
 |  |  | 
 |  |  |         try { | 
 |  |  |             QueryResultVo<List<VoReissueCard>> res = cardOperateSv.getReissueCards(vo); | 
 |  |  |             if(res.itemTotal == 0) { | 
 |  |  |                 return BaseResponseUtils.buildFail(SellResultCode.No_ReissueCards.getMessage()); | 
 |  |  |                 return BaseResponseUtils.buildErrorMsg(SellResultCode.No_ReissueCards.getMessage()); | 
 |  |  |             } | 
 |  |  |             return BaseResponseUtils.buildSuccess(res); | 
 |  |  |         } catch (Exception e) { | 
 |  |  | 
 |  |  |         // 验证操作类型是否正确 | 
 |  |  |         Integer operateType = Optional.ofNullable(vo.getOperateType()).orElse(0); | 
 |  |  |         if(operateType != 3 && operateType != 6 && operateType != 7 && operateType != 8) { | 
 |  |  |             return BaseResponseUtils.buildFail(SellResultCode.PARAMS_ERROR.getMessage()); | 
 |  |  |             return BaseResponseUtils.buildErrorMsg(SellResultCode.PARAMS_ERROR.getMessage()); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         try { | 
 |  |  |             QueryResultVo<List<VoOperate>> res = cardOperateSv.getCommonOperations(vo); | 
 |  |  |             if(res.itemTotal == 0) { | 
 |  |  |                 return BaseResponseUtils.buildFail(SellResultCode.No_CANCELS.getMessage()); | 
 |  |  |                 return BaseResponseUtils.buildErrorMsg(SellResultCode.No_CANCELS.getMessage()); | 
 |  |  |             } | 
 |  |  |             return BaseResponseUtils.buildSuccess(res); | 
 |  |  |         } catch (Exception e) { | 
 |  |  | 
 |  |  |         try { | 
 |  |  |             Map res = Optional.ofNullable(cardOperateSv.getReceipts(vo)).orElse(new HashMap()); | 
 |  |  |             if(res.size() == 0) { | 
 |  |  |                 return BaseResponseUtils.buildFail(SellResultCode.No_RECEIPTS.getMessage()); | 
 |  |  |                 return BaseResponseUtils.buildErrorMsg(SellResultCode.No_RECEIPTS.getMessage()); | 
 |  |  |             } | 
 |  |  |             return BaseResponseUtils.buildSuccess(res); | 
 |  |  |         } catch (Exception e) { |