From a0a9fc7a58a39626a395d2760194641726e1cd35 Mon Sep 17 00:00:00 2001 From: liurunyu <lry9898@163.com> Date: 星期五, 25 四月 2025 10:48:15 +0800 Subject: [PATCH] 1、微信小程序后端轮灌迟延时长改为可配置的; 2、微信小程序查询取水口接口实现修改,改为后端模糊查询; --- pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/virtualCard/VirtualCardCtrl.java | 372 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 372 insertions(+), 0 deletions(-) diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/virtualCard/VirtualCardCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/virtualCard/VirtualCardCtrl.java new file mode 100644 index 0000000..0005593 --- /dev/null +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/virtualCard/VirtualCardCtrl.java @@ -0,0 +1,372 @@ +package com.dy.pipIrrWechat.virtualCard; + +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.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.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.*; + +import java.util.*; + +/** + * @author ZhuBaoMin + * @date 2024-07-15 9:55 + * @LastEditTime 2024-07-15 9:55 + * @Description + */ + +@Slf4j +@Tag(name = "铏氭嫙鍗$鐞�", description = "铏氭嫙鍗$鐞�") +@RestController +@RequestMapping(path="virtual_card") +@RequiredArgsConstructor +@Validated +public class VirtualCardCtrl { + private final VirtualCardSv virtualCardSv; + private final PayHelper payHelper; + + /** + * 娉ㄥ唽铏氭嫙鍗� + * @param po + * @param bindingResult + * @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()); + } + + 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锛夊湪铏氭嫙鍗¤〃涓拡瀵硅櫄鎷熷崱缂栧彿锛坴cNum锛夎繘琛屾ā绯婃煡璇� + // * 濡傛灉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) ; + } + + /** + * 鏍规嵁铏氭嫙鍗D娉ㄩ攢铏氭嫙鍗� + * @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鍒ゆ柇鏄惁瀛樺湪姝e父鐘舵�侊紙鍙敞閿�锛夌殑铏氭嫙鍗� + 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 = "/get") + public BaseResponse<List<VoVirtualCard>> getVCs(Long clientId){ + try { + return BaseResponseUtils.buildSuccess(virtualCardSv.getVCs(clientId)); + } catch (Exception e) { + log.error("鑾峰彇鏀粯鏂瑰紡璁板綍寮傚父", e); + return BaseResponseUtils.buildException(e.getMessage()) ; + } + } + + /** + * 鏍规嵁铏氭嫙鍗D鑾峰彇铏氭嫙鍗″璞� + * @param vcId + * @return + */ + @GetMapping(path = "/getVcById") + public BaseResponse<VoVirtualCard> getVcById(@RequestParam Long vcId){ + try { + return BaseResponseUtils.buildSuccess(virtualCardSv.getVcById(vcId)); + } catch (Exception e) { + log.error("鑾峰彇鏀粯鏂瑰紡璁板綍寮傚父", e); + return BaseResponseUtils.buildException(e.getMessage()) ; + } + } + + /** + * 鐢ㄦ埛鐢宠閫�娆� + * @param po + * @param bindingResult + * @return + */ + //@Operation(summary = "铏氭嫙鍗$敵璇烽��娆�", description = "铏氭嫙鍗$敵璇烽��娆�") + //@ApiResponses(value = { + // @ApiResponse( + // responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, + // description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�", + // content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, + // schema = @Schema(implementation = Boolean.class))} + // ) + //}) + //@PostMapping(path = "add_refund", consumes = MediaType.APPLICATION_JSON_VALUE) + //@Transactional(rollbackFor = Exception.class) + //public BaseResponse<Boolean> addRefund(@RequestBody @Valid DtoRefund po, BindingResult bindingResult){ + // if(bindingResult != null && bindingResult.hasErrors()){ + // return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); + // } + // + // Long virtualId = po.getVirtualId(); + // Integer refundAmount = po.getRefundAmount(); + // + // // 鏍规嵁铏氭嫙鍗D鑾峰彇铏氭嫙鍗″璞� + // SeVirtualCard seVirtualCard = virtualCardSv.selectVirtuCardById(virtualId); + // if(seVirtualCard == null) { + // return BaseResponseUtils.buildFail(WechatResultCode.VIRTUAL_CARD_NOT_EXIST.getMessage()); + // } + // Long clientId = seVirtualCard.getClientId(); + // Double money = seVirtualCard.getMoney(); + // + // // 楠岃瘉閫�娆鹃噾棰濇槸鍚﹀ぇ浜庝綑棰� + // if(refundAmount > money) { + // return BaseResponseUtils.buildFail(WechatResultCode.REFUND_AMOUNT_CANNOT_GREATER_THAN_MONEY.getMessage()); + // } + // + // // 璁$畻娑堣垂鍚庝綑棰� + // Double afterRefund = money - refundAmount; + // + // SeVcRefund seVcRefund = new SeVcRefund(); + // seVcRefund.setVcId(virtualId); + // seVcRefund.setClientId(clientId); + // seVcRefund.setMoney(money); + // seVcRefund.setRefundAmount(refundAmount); + // seVcRefund.setAfterRefund(afterRefund); + // seVcRefund.setApplicationTime(new Date()); + // seVcRefund.setRefundStatus(RefundStateENUM.TO_AUDIT.getCode()); + // + // Long rec = virtualCardSv.addRefund(seVcRefund); + // if(rec == 0) { + // return BaseResponseUtils.buildFail(WechatResultCode.APPLICATION_REFUND_FAIL.getMessage()); + // } + // return BaseResponseUtils.buildSuccess(true) ; + //} + + /** + * 瀹℃牳閫�娆剧敵璇� + * @param po + * @param bindingResult + * @return + */ + //@Operation(summary = "瀹℃牳閫�娆剧敵璇�", description = "瀹℃牳閫�娆剧敵璇�") + //@ApiResponses(value = { + // @ApiResponse( + // responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, + // description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�", + // content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, + // schema = @Schema(implementation = Boolean.class))} + // ) + //}) + //@PostMapping(path = "audit_refund", consumes = MediaType.APPLICATION_JSON_VALUE) + //@Transactional(rollbackFor = Exception.class) + //public BaseResponse<Boolean> auditRefund(@RequestBody @Valid DtoAudit po, BindingResult bindingResult) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeySpecException, IOException, SignatureException, InvalidKeyException { + // if(bindingResult != null && bindingResult.hasErrors()){ + // return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); + // } + // + // // 鏍规嵁閫�娆綢D鑾峰彇閫�娆惧璞★紝骞舵洿鏂板鏍镐汉銆佸鏍告椂闂淬�佸鏍稿娉ㄣ�侀��娆剧姸鎬佸瓧娈� + // SeVcRefund seVcRefund = virtualCardSv.selectRefundByRefundId(po.getRefundId()); + // Long virtualId = seVcRefund.getVcId(); + // Integer refundAmount = seVcRefund.getRefundAmount(); + // seVcRefund.setAuditor(po.getAuditor()); + // seVcRefund.setAuditTime(new Date()); + // seVcRefund.setRemarks(po.getRemarks()); + // seVcRefund.setRefundStatus(RefundStateENUM.TO_REFUND.getCode()); + // Integer rec = virtualCardSv.updateRefund(seVcRefund); + // if(rec == 0) { + // return BaseResponseUtils.buildFail(WechatResultCode.AUDIT_REFUND_FAIL.getMessage()); + // } + // + // // 瀹屾垚瀹℃牳鍚庤幏鍙栧緟閫�娆捐鍗曞垪琛� + // List<ToRefund> list_ToRefund = payHelper.getToRefunds(virtualId, refundAmount); + // if(list_ToRefund == null || list_ToRefund.size() <=0) + // return BaseResponseUtils.buildFail(WechatResultCode.NOT_SUFFICIENT_FUNDS.getMessage()); + // + // //閬嶅巻寰呴��娆惧垪琛� + // JSONArray array_ToRefund = (JSONArray) JSON.toJSON(list_ToRefund); + // for(int i = 0; i < array_ToRefund.size(); i++) { + // JSONObject job_ToRefund = array_ToRefund.getJSONObject(i); + // String orderNumber_ToRefund = job_ToRefund.getString("orderNumber"); + // Integer refundAmount_ToRefund = job_ToRefund.getInteger("refundAmount"); + // + // // 鐢熸垚閫�娆惧垎椤硅褰� + // SeVcRefundItem seVcRefundItem = new SeVcRefundItem(); + // seVcRefundItem.setRefundId(po.getRefundId()); + // seVcRefundItem.setOrderNumber(orderNumber_ToRefund); + // String refundNumber = virtualCardSv.generateRefundNumber(orderNumber_ToRefund); + // seVcRefundItem.setRefundNumber(refundNumber); + // seVcRefundItem.setRefundAmount(refundAmount_ToRefund); + // seVcRefundItem.setCreateTime(new Date()); + // seVcRefundItem.setRefundStatus(RefundItemStateENUM.NO_REFUND.getCode()); + // Long refundItemId = virtualCardSv.addRefundItem(seVcRefundItem); + // + // // 璋冪敤寰俊閫�娆剧敵璇锋帴鍙� + // Refund refund = new Refund(); + // refund.setTradeNo(orderNumber_ToRefund); + // refund.setRefundNo(refundNumber); + // refund.setRefund(refundAmount_ToRefund); + // BaseResponse rep = payHelper.refunds(refund); + // } + // + // return BaseResponseUtils.buildSuccess(true) ; + //} + + /** + * 鑾峰彇铏氭嫙鍗″厖鍊艰褰� + * @return + */ + @GetMapping(path = "/getVcRechargeRecords") + 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) { + log.error("鑾峰彇铏氭嫙鍗″厖鍊艰褰曞紓甯�", 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() ; + } +} -- Gitblit v1.8.0