|  |  |  | 
|---|
|  |  |  | import com.dy.common.webUtil.QueryResultVo; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.pojoSe.SeVcOperate; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.pojoSe.SeVirtualCard; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.voIr.VoPlanDetails; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.voSe.VoRechargeProfile; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.voSe.VoVcRecharge; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.voSe.VoVirtualCard; | 
|---|
|  |  |  | import com.dy.pipIrrWechat.result.WechatResultCode; | 
|---|
|  |  |  | import com.dy.pipIrrWechat.util.PayHelper; | 
|---|
|  |  |  | import com.dy.pipIrrWechat.virtualCard.dto.Client; | 
|---|
|  |  |  | import com.dy.pipIrrWechat.virtualCard.dto.DtoCancel; | 
|---|
|  |  |  | import com.dy.pipIrrWechat.virtualCard.dto.DtoRegist; | 
|---|
|  |  |  | import com.dy.pipIrrWechat.virtualCard.dto.DtoVcRecharge; | 
|---|
|  |  |  | import com.dy.pipIrrWechat.virtualCard.enums.LastOperateENUM; | 
|---|
|  |  |  | import com.dy.pipIrrWechat.virtualCard.qo.QoVcRecharge; | 
|---|
|  |  |  | import io.swagger.v3.oas.annotations.tags.Tag; | 
|---|
|  |  |  | import jakarta.validation.Valid; | 
|---|
|  |  |  | import lombok.RequiredArgsConstructor; | 
|---|
|  |  |  | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author ZhuBaoMin | 
|---|
|  |  |  | 
|---|
|  |  |  | if(bindingResult != null && bindingResult.hasErrors()){ | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map map_result = virtualCardSv.addVC(po.getClientId(), 0D); | 
|---|
|  |  |  | if(map_result.get("success").equals(false)) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(map_result.get("msg").toString()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess() ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //Long clientId = po.getClientId(); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //// 获取5级行政区划串areaCode | 
|---|
|  |  |  | //Long areaCodeL = virtualCardSv.getAreaCodeById(clientId); | 
|---|
|  |  |  | //if(areaCodeL == null) { | 
|---|
|  |  |  | //    return BaseResponseUtils.buildErrorMsg(WechatResultCode.AREA_CODE_MISTAKE.getMessage()); | 
|---|
|  |  |  | //} | 
|---|
|  |  |  | //String areaCode = String.valueOf(areaCodeL); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | ///** | 
|---|
|  |  |  | // * 根据行政区划串(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.buildErrorMsg(WechatResultCode.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.setState((byte)1); | 
|---|
|  |  |  | //seVirtualCard.setLastOperate(LastOperateENUM.OPEN_ACCOUNT.getCode()); | 
|---|
|  |  |  | //seVirtualCard.setLastOperateTime(new Date()); | 
|---|
|  |  |  | //seVirtualCard.setInUse((byte) 0); | 
|---|
|  |  |  | //seVirtualCard.setCreateTime(new Date()); | 
|---|
|  |  |  | //Long vcId = virtualCardSv.insertVirtualCard(seVirtualCard); | 
|---|
|  |  |  | //if(vcId == null) { | 
|---|
|  |  |  | //    return BaseResponseUtils.buildErrorMsg(WechatResultCode.VC_OPEN_ACCOUNT_FAIL.getMessage()); | 
|---|
|  |  |  | //} | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //// 生成虚拟卡操作记录,注册虚拟卡操作人为农户 | 
|---|
|  |  |  | //SeVcOperate seVcOperate = new SeVcOperate(); | 
|---|
|  |  |  | //seVcOperate.setVcId(vcId); | 
|---|
|  |  |  | //seVcOperate.setClientId(clientId); | 
|---|
|  |  |  | //seVcOperate.setOperateType(LastOperateENUM.OPEN_ACCOUNT.getCode()); | 
|---|
|  |  |  | //seVcOperate.setOperator(clientId); | 
|---|
|  |  |  | //seVcOperate.setOperateTime(new Date()); | 
|---|
|  |  |  | //Long vcOperateId = virtualCardSv.insertVcOperate(seVcOperate); | 
|---|
|  |  |  | //if(vcOperateId == null) { | 
|---|
|  |  |  | //    return BaseResponseUtils.buildErrorMsg(WechatResultCode.VC_OPEN_ACCOUNT_FAIL.getMessage()); | 
|---|
|  |  |  | //} | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //return BaseResponseUtils.buildSuccess(true) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据虚拟卡ID注销虚拟卡 | 
|---|
|  |  |  | * @param po | 
|---|
|  |  |  | * @param bindingResult | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @PostMapping(path = "cancel") | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | public BaseResponse<Boolean> cancelVC(@RequestBody @Valid DtoCancel po, BindingResult bindingResult) { | 
|---|
|  |  |  | if(bindingResult != null && bindingResult.hasErrors()){ | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Long clientId = po.getClientId(); | 
|---|
|  |  |  | Long vcId = po.getVcId(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 获取5级行政区划串areaCode | 
|---|
|  |  |  | Long areaCodeL = virtualCardSv.getAreaCodeById(clientId); | 
|---|
|  |  |  | if(areaCodeL == null) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(WechatResultCode.AREA_CODE_MISTAKE.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String areaCode = String.valueOf(areaCodeL); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据行政区划串(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.buildErrorMsg(WechatResultCode.CARD_NUMBER_OVERRUN.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | vcNum = vcNum.substring(0, 12) + String.format("%05d", number); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | vcNum = areaCode + "00001"; | 
|---|
|  |  |  | // 根据农户ID及虚拟卡Id判断是否存在正常状态(可注销)的虚拟卡 | 
|---|
|  |  |  | SeVirtualCard seVirtualCard = virtualCardSv.getVcByClientIdAndVcId(clientId, vcId); | 
|---|
|  |  |  | if(seVirtualCard == null) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(WechatResultCode.NO_VC_FIT_THE_BILL.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 生成虚拟卡记录 | 
|---|
|  |  |  | 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 vcId = virtualCardSv.insertVirtualCard(seVirtualCard); | 
|---|
|  |  |  | if(vcId == null) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(WechatResultCode.VC_OPEN_ACCOUNT_FAIL.getMessage()); | 
|---|
|  |  |  | // 注销虚拟卡 | 
|---|
|  |  |  | Integer rec = virtualCardSv.cancelVc(clientId, vcId); | 
|---|
|  |  |  | if(rec == null || rec == 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(WechatResultCode.VC_CANCEL_FAIL.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 生成虚拟卡操作记录,注册虚拟卡操作人为农户 | 
|---|
|  |  |  | SeVcOperate seVcOperate = new SeVcOperate(); | 
|---|
|  |  |  | seVcOperate.setVcId(vcId); | 
|---|
|  |  |  | seVcOperate.setClientId(clientId); | 
|---|
|  |  |  | seVcOperate.setOperateType(LastOperateENUM.OPEN_ACCOUNT.getCode()); | 
|---|
|  |  |  | seVcOperate.setOperateType(LastOperateENUM.CLOSING_ACCOUNT.getCode()); | 
|---|
|  |  |  | seVcOperate.setOperator(clientId); | 
|---|
|  |  |  | seVcOperate.setOperateTime(new Date()); | 
|---|
|  |  |  | Long vcOperateId = virtualCardSv.insertVcOperate(seVcOperate); | 
|---|
|  |  |  | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @GetMapping(path = "/getVcRechargeRecords") | 
|---|
|  |  |  | public BaseResponse<QueryResultVo<List<VoVcRecharge>>> getVcRechargeRecords(DtoVcRecharge dtoVcRecharge){ | 
|---|
|  |  |  | public BaseResponse<QueryResultVo<List<VoVcRecharge>>> getVcRechargeRecords(QoVcRecharge dtoVcRecharge){ | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | if(dtoVcRecharge.getVcId() == null) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg("虚拟卡不能为空"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | QueryResultVo<List<VoVcRecharge>> res = virtualCardSv.getVcRechargeRecords(dtoVcRecharge); | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(res); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取虚拟卡常用充值金额配置 | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @GetMapping(path = "/gerRechargeProfiles") | 
|---|
|  |  |  | public BaseResponse<List<VoRechargeProfile>> gerRechargeProfiles(){ | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(virtualCardSv.gerRechargeProfiles()); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("获取虚拟卡常用充值金额配置异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 绑定虚拟卡到取水口 | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @PostMapping(path = "linkVcToIntake") | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | public BaseResponse<Boolean> linkVcToIntake(@RequestBody @Valid Client client, BindingResult bindingResult) { | 
|---|
|  |  |  | if(bindingResult != null && bindingResult.hasErrors()){ | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Long clientId = client.getClientId(); | 
|---|
|  |  |  | Map map_result = virtualCardSv.linkVcToIntake(clientId); | 
|---|
|  |  |  | if(map_result.get("success").equals(false)) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(map_result.get("msg").toString()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess() ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|