|  |  | 
 |  |  | import com.dy.common.aop.SsoAop; | 
 |  |  | import com.dy.common.webUtil.BaseResponse; | 
 |  |  | import com.dy.common.webUtil.BaseResponseUtils; | 
 |  |  | import com.dy.common.webUtil.QueryResultVo; | 
 |  |  | import com.dy.pipIrrGlobal.pojoSe.SeVirtualCard; | 
 |  |  | import com.dy.pipIrrGlobal.voSe.VoVcRecharge; | 
 |  |  | import com.dy.pipIrrGlobal.voSe.VoVirtualCard; | 
 |  |  | import com.dy.pipIrrSell.result.SellResultCode; | 
 |  |  | import com.dy.pipIrrSell.util.PayHelper; | 
 |  |  | import com.dy.pipIrrSell.virtualCard.dto.DtoRegist; | 
 |  |  | import com.dy.pipIrrSell.virtualCard.dto.DtoVcRecharge; | 
 |  |  | import com.dy.pipIrrSell.virtualCard.enums.LastOperateENUM; | 
 |  |  | import io.swagger.v3.oas.annotations.tags.Tag; | 
 |  |  | import jakarta.validation.Valid; | 
 |  |  | import lombok.RequiredArgsConstructor; | 
 |  |  | import lombok.extern.slf4j.Slf4j; | 
 |  |  | import org.springframework.validation.BindingResult; | 
 |  |  | import org.springframework.validation.annotation.Validated; | 
 |  |  | import org.springframework.web.bind.annotation.*; | 
 |  |  |  | 
 |  |  | import java.util.Date; | 
 |  |  | import java.util.List; | 
 |  |  | import java.util.Objects; | 
 |  |  | import java.util.Optional; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  |  * @author ZhuBaoMin | 
 |  |  | 
 |  |  |     private final PayHelper payHelper; | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 获取全部虚拟卡 | 
 |  |  |      * 获取农户全部虚拟卡 | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     @GetMapping(path = "/get") | 
 |  |  |     @SsoAop() | 
 |  |  |     public BaseResponse<List<VoVirtualCard>> getVCs(){ | 
 |  |  |     public BaseResponse<List<VoVirtualCard>> getVCs(Long clientId){ | 
 |  |  |         try { | 
 |  |  |             List<VoVirtualCard> res = virtualCardSv.getVCs(); | 
 |  |  |             List<VoVirtualCard> res = virtualCardSv.getVCs(clientId); | 
 |  |  |             return BaseResponseUtils.buildSuccess(res); | 
 |  |  |         } catch (Exception e) { | 
 |  |  |             log.error("获取支付方式记录异常", e); | 
 |  |  | 
 |  |  |      * @param bindingResult | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     //@Operation(summary = "注册虚拟卡", description = "注册虚拟卡") | 
 |  |  |     //@ApiResponses(value = { | 
 |  |  |     //        @ApiResponse( | 
 |  |  |     //                responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, | 
 |  |  |     //                description = "操作结果:true:成功,false:失败(BaseResponse.content)", | 
 |  |  |     //                content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, | 
 |  |  |     //                        schema = @Schema(implementation = Boolean.class))} | 
 |  |  |     //        ) | 
 |  |  |     //}) | 
 |  |  |     //@PostMapping(path = "add_vc") | 
 |  |  |     //@SsoAop() | 
 |  |  |     //public BaseResponse<Boolean> addVC(@RequestBody @Valid DtoRegist po, BindingResult bindingResult){ | 
 |  |  |     //    if(bindingResult != null && bindingResult.hasErrors()){ | 
 |  |  |     //        return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
 |  |  |     //    } | 
 |  |  |     //    Long clientId = po.getClientId(); | 
 |  |  |     //    String vcName = po.getVcName(); | 
 |  |  |     // | 
 |  |  |     //    // 名称验重 | 
 |  |  |     //    Integer rc = virtualCardSv.getRecordCountByName(po); | 
 |  |  |     //    if(rc != null && rc > 0) { | 
 |  |  |     //        return BaseResponseUtils.buildFail(SellResultCode.CARD_NAME_ESIST.getMessage()); | 
 |  |  |     //    } | 
 |  |  |     // | 
 |  |  |     //    SeVirtualCard seVirtualCard = new SeVirtualCard(); | 
 |  |  |     //    seVirtualCard.setVcName(vcName); | 
 |  |  |     //    seVirtualCard.setClientId(clientId); | 
 |  |  |     //    seVirtualCard.setMoney(0d); | 
 |  |  |     //    seVirtualCard.setLastOperate(LastOperateENUM.OPEN_ACCOUNT.getCode()); | 
 |  |  |     //    seVirtualCard.setLastOperateTime(new Date()); | 
 |  |  |     //    seVirtualCard.setInUse((byte) 0); | 
 |  |  |     //    seVirtualCard.setCreateTime(new Date()); | 
 |  |  |     //    Long rec = virtualCardSv.insertVirtualCard(seVirtualCard); | 
 |  |  |     //    if(rec == null) { | 
 |  |  |     //        return BaseResponseUtils.buildFail(SellResultCode.WALLET_OPEN_ACCOUNT_FAIL.getMessage()); | 
 |  |  |     //    } | 
 |  |  |     //    return BaseResponseUtils.buildSuccess(true) ; | 
 |  |  |     //} | 
 |  |  |     @PostMapping(path = "add_vc") | 
 |  |  |     @SsoAop() | 
 |  |  |     public BaseResponse<Boolean> addVC(@RequestBody @Valid DtoRegist po, BindingResult bindingResult){ | 
 |  |  |         if(bindingResult != null && bindingResult.hasErrors()){ | 
 |  |  |             return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
 |  |  |         } | 
 |  |  |         Long clientId = po.getClientId(); | 
 |  |  |  | 
 |  |  |         // 获取5级行政区划串areaCode | 
 |  |  |         String areaCode = String.valueOf(virtualCardSv.getAreaCodeById(clientId)); | 
 |  |  |         /** | 
 |  |  |          * 根据行政区划串(areaCode)在虚拟卡表中针对虚拟卡编号(vcNum)进行模糊查询 | 
 |  |  |          * 如果5位顺序号已经达到最大值,提示用户联系系统管理员 | 
 |  |  |          * 如果5位顺序号未达到最大值,则加1 | 
 |  |  |          * cardNum为新的卡号 | 
 |  |  |          */ | 
 |  |  |         String vcNum = Optional.ofNullable(virtualCardSv.getVcCardNumOfMax(areaCode)).orElse(""); | 
 |  |  |         if(vcNum != null && vcNum.trim().length() > 0) { | 
 |  |  |             Integer number = Integer.parseInt(vcNum.substring(12)); | 
 |  |  |             number = number + 1; | 
 |  |  |             if(number > 65535) { | 
 |  |  |                 return BaseResponseUtils.buildFail(SellResultCode.CARD_NUMBER_OVERRUN.getMessage()); | 
 |  |  |             } | 
 |  |  |             vcNum = vcNum.substring(0, 12) + String.format("%05d", number); | 
 |  |  |         } else { | 
 |  |  |             vcNum = areaCode + "00001"; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         SeVirtualCard seVirtualCard = new SeVirtualCard(); | 
 |  |  |         seVirtualCard.setVcNum(Long.parseLong(vcNum)); | 
 |  |  |         seVirtualCard.setClientId(clientId); | 
 |  |  |         seVirtualCard.setMoney(0d); | 
 |  |  |         seVirtualCard.setLastOperate(LastOperateENUM.OPEN_ACCOUNT.getCode()); | 
 |  |  |         seVirtualCard.setLastOperateTime(new Date()); | 
 |  |  |         seVirtualCard.setInUse((byte) 0); | 
 |  |  |         seVirtualCard.setCreateTime(new Date()); | 
 |  |  |         Long rec = virtualCardSv.insertVirtualCard(seVirtualCard); | 
 |  |  |         if(rec == null) { | 
 |  |  |             return BaseResponseUtils.buildFail(SellResultCode.VC_OPEN_ACCOUNT_FAIL.getMessage()); | 
 |  |  |         } | 
 |  |  |         return BaseResponseUtils.buildSuccess(true) ; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 用户申请退款 | 
 |  |  | 
 |  |  |     //    return BaseResponseUtils.buildSuccess(true) ; | 
 |  |  |     //} | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 获取虚拟卡充值记录 | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     @GetMapping(path = "/getVcRechargeRecords") | 
 |  |  |     @SsoAop() | 
 |  |  |     public BaseResponse<QueryResultVo<List<VoVcRecharge>>> getVcRechargeRecords(DtoVcRecharge dtoVcRecharge){ | 
 |  |  |         try { | 
 |  |  |             QueryResultVo<List<VoVcRecharge>> res = virtualCardSv.getVcRechargeRecords(dtoVcRecharge); | 
 |  |  |             return BaseResponseUtils.buildSuccess(res); | 
 |  |  |         } catch (Exception e) { | 
 |  |  |             log.error("获取虚拟卡充值记录异常", e); | 
 |  |  |             return BaseResponseUtils.buildException(e.getMessage()) ; | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  | } |