From 742e0a8ec019ccb76f03fcc58859ed15e9264c4c Mon Sep 17 00:00:00 2001
From: Administrator <zhubaomin>
Date: 星期三, 31 一月 2024 08:26:30 +0800
Subject: [PATCH] 2024-01-31 朱宝民 电子钱包账户注册接口、充值接口
---
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wallet/WalletCtrl.java | 129 +++++++++++++++++++++++++++---------------
1 files changed, 83 insertions(+), 46 deletions(-)
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wallet/WalletCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wallet/WalletCtrl.java
index 8eecd2c..7383dc8 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wallet/WalletCtrl.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wallet/WalletCtrl.java
@@ -5,22 +5,24 @@
import com.dy.common.webUtil.BaseResponseUtils;
import com.dy.common.webUtil.ResultCodeMsg;
import com.dy.pipIrrGlobal.pojoSe.SeWallet;
+import com.dy.pipIrrGlobal.pojoSe.SeWalletRecharge;
+import com.dy.pipIrrSell.result.SellResultCode;
+import com.dy.pipIrrSell.wallet.dto.DtoRecharge;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
+import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.transaction.annotation.Transactional;
+import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.Optional;
@@ -41,6 +43,12 @@
public class WalletCtrl {
private final WalletSv walletSv;
+ /**
+ * 娉ㄥ唽鐢靛瓙閽卞寘璐︽埛
+ * 娉ㄥ唽閽卞厛楠岃瘉璇ュ啘鎴锋槸鍚﹀凡缁忔敞鍐岀數瀛愰挶鍖�
+ * @param clientId
+ * @return
+ */
@Operation(summary = "娉ㄥ唽鐢靛瓙閽卞寘", description = "娉ㄥ唽鐢靛瓙閽卞寘")
@ApiResponses(value = {
@ApiResponse(
@@ -50,56 +58,85 @@
schema = @Schema(implementation = Boolean.class))}
)
})
- @PostMapping(path = "add")
- @Transactional(rollbackFor = Exception.class)
+ @PostMapping(path = "add_wallet")
@SsoAop()
- //public BaseResponse<Boolean> add(@RequestBody Long clientId){
- public BaseResponse<Boolean> add(@RequestParam("clientId") @NotNull(message = "鍐滄埛缂栧彿涓嶈兘涓虹┖") Long clientId){
+ public BaseResponse<Boolean> addWallet(@RequestParam("clientId") @NotNull(message = "鍐滄埛缂栧彿涓嶈兘涓虹┖") Long clientId){
if(clientId == null || clientId < 0) {
- return BaseResponseUtils.buildFail("鍐滄埛缂栧彿涓嶈兘涓虹┖");
+ return BaseResponseUtils.buildFail(SellResultCode.CLIENT_ID_CANNOT_BE_NULL.getMessage());
+ }
+
+ if(walletSv.getWalletByClientId(clientId) != null) {
+ return BaseResponseUtils.buildFail(SellResultCode.WALLET_ACCOUNT_EXIST.getMessage());
}
SeWallet seWallet = new SeWallet();
- seWallet.setClientid(clientId);
- seWallet.setMoney(0f);
- seWallet.setCreatedt(new Date());
- Integer rec = Optional.ofNullable(walletSv.add(seWallet)).orElse(0);
+ seWallet.setClientId(clientId);
+ seWallet.setMoney(0d);
+ seWallet.setLastOperate(LastOperateENUM.OPEN_ACCOUNT.getCode());
+ seWallet.setLastOperateTime(new Date());
+ seWallet.setCreateTime(new Date());
+ Long rec = Optional.ofNullable(walletSv.addWallet(seWallet)).orElse(0L);
if(rec == 0) {
- return BaseResponseUtils.buildFail("娉ㄥ唽鐢靛瓙閽卞寘-鐢靛瓙閽卞寘璁板綍鍐欏叆寮傚父");
+ return BaseResponseUtils.buildFail(SellResultCode.WALLET_OPEN_ACCOUNT_FAIL.getMessage());
}
-
return BaseResponseUtils.buildSuccess(true) ;
}
- //@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 = "addRecharge")
- //@Transactional(rollbackFor = Exception.class)
- //@SsoAop()
- //public BaseResponse<Boolean> addRecharge(@RequestBody @Valid DtoWalletRecharge po, @Parameter(hidden = true) BindingResult bindingResult){
- // DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
- // if(bindingResult != null && bindingResult.hasErrors()){
- // return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
- // }
- //
- //
- //
- // SeWallet seWallet = new SeWallet();
- // seWallet.setClientid(clientId);
- // seWallet.setMoney(0f);
- // seWallet.setCreatedt(new Date());
- // Integer rec = Optional.ofNullable(walletSv.add(seWallet)).orElse(0);
- // if(rec == 0) {
- // return BaseResponseUtils.buildFail("娉ㄥ唽鐢靛瓙閽卞寘-鐢靛瓙閽卞寘璁板綍鍐欏叆寮傚父");
- // }
- //
- // 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 = "add_recharge", consumes = MediaType.APPLICATION_JSON_VALUE)
+ @Transactional(rollbackFor = Exception.class)
+ @SsoAop()
+ public BaseResponse<Boolean> addRecharge(@RequestBody @Valid DtoRecharge po, BindingResult bindingResult){
+ Long clientId = Optional.ofNullable(po .getClientId()).orElse(0L);
+ Double amount = Optional.ofNullable(po.getAmount()).orElse(0.0);
+
+ // 楠岃瘉璇ュ啘鎴锋槸鍚﹀凡缁忔敞鍐岀數瀛愰挶鍖呰处鎴峰苟鍙栧嚭ID鍙婂綋鍓嶈处鎴蜂綑棰�
+ SeWallet seWallet = walletSv.getWalletByClientId(clientId);
+ if(seWallet == null) {
+ return BaseResponseUtils.buildFail(SellResultCode.NO_ACCOUNT.getMessage());
+ }
+ Long wallerId = Optional.ofNullable(seWallet.getId()).orElse(0L);
+ Double money = Optional.ofNullable(seWallet.getMoney()).orElse(0.0);
+
+ // 璁$畻鍏呭�煎悗浣欓
+ Double afterRrecharge = money + amount;
+
+ // 淇敼鐢靛瓙閽卞寘浣欓銆佹渶鍚庢搷浣滅被鍨嬨�佹渶鍚庢搷浣滄椂闂�
+ seWallet.setMoney(afterRrecharge);
+ seWallet.setLastOperate(LastOperateENUM.RECHARGE.getCode());
+ seWallet.setLastOperateTime(new Date());
+ Integer rec_updateWaller = Optional.ofNullable(walletSv.updateWallet(seWallet)).orElse(0);
+ if(rec_updateWaller == 0) {
+ return BaseResponseUtils.buildFail(SellResultCode.UPDATE_ACCOUNT_FAIL.getMessage());
+ }
+
+ // 娣诲姞鍏呭�艰褰�
+ SeWalletRecharge seWalletRecharge = new SeWalletRecharge();
+ seWalletRecharge.setWalletId(wallerId);
+ seWalletRecharge.setClientId(clientId);
+ seWalletRecharge.setMoney(money);
+ seWalletRecharge.setAmount(amount);
+ seWalletRecharge.setAfterRecharge(afterRrecharge);
+ seWalletRecharge.setRechargeTime(new Date());
+ Long rec = Optional.ofNullable(walletSv.addRecharge(seWalletRecharge)).orElse(0L);
+ if(rec == 0) {
+ return BaseResponseUtils.buildFail(SellResultCode.WALLET_OPEN_ACCOUNT_FAIL.getMessage());
+ }
+ return BaseResponseUtils.buildSuccess(true) ;
+ }
+
}
--
Gitblit v1.8.0