| | |
| | | import com.dy.common.webUtil.BaseResponse; |
| | | import com.dy.common.webUtil.BaseResponseUtils; |
| | | import com.dy.common.webUtil.QueryResultVo; |
| | | import com.dy.pipIrrGlobal.pojoSe.SeVcOperate; |
| | | import com.dy.pipIrrGlobal.pojoSe.SeVirtualCard; |
| | | 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.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 lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.validation.BindingResult; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | |
| | | * @return |
| | | */ |
| | | @PostMapping(path = "add_vc") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public BaseResponse<Boolean> addVC(@RequestBody @Valid DtoRegist po, BindingResult bindingResult) { |
| | | if(bindingResult != null && bindingResult.hasErrors()){ |
| | | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); |
| | |
| | | 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 rec = virtualCardSv.insertVirtualCard(seVirtualCard); |
| | | if(rec == null) { |
| | | 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(); |
| | | |
| | | // 根据农户ID及虚拟卡Id判断是否存在正常状态(可注销)的虚拟卡 |
| | | SeVirtualCard seVirtualCard = virtualCardSv.getVcByClientIdAndVcId(clientId, vcId); |
| | | if(seVirtualCard == null) { |
| | | return BaseResponseUtils.buildErrorMsg(WechatResultCode.NO_VC_FIT_THE_BILL.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.CLOSING_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) ; |
| | | } |
| | | |
| | |
| | | * @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()) ; |
| | | } |
| | | } |
| | | } |