liurunyu
2023-12-19 6eab5ecc0a1cf8bcf1ee999457104e2281e767d2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package com.dy.pipIrrSell.wallet;
 
import com.dy.common.aop.SsoAop;
import com.dy.common.webUtil.BaseResponse;
import com.dy.common.webUtil.BaseResponseUtils;
import com.dy.common.webUtil.ResultCodeMsg;
import com.dy.pipIrrGlobal.pojoSe.SeWallet;
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.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.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 java.util.Date;
import java.util.Optional;
 
/**
 * @author ZhuBaoMin
 * @date 2023/12/11 16:36
 * @LastEditTime 2023/12/11 16:36
 * @Description
 */
 
@Slf4j
@Tag(name = "电子钱包管理", description = "电子钱包管理")
@RestController
@RequestMapping(path="wallet")
@RequiredArgsConstructor
@Validated
public class WalletCtrl {
    private final WalletSv walletSv;
 
    @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")
    @Transactional(rollbackFor = Exception.class)
    @SsoAop("-1")//@SsoAop(power = "-1")
    //public BaseResponse<Boolean> add(@RequestBody Long clientId){
    public BaseResponse<Boolean> add(@RequestParam("clientId") @NotNull(message = "农户编号不能为空") Long clientId){
        if(clientId == null || clientId < 0) {
            return BaseResponseUtils.buildFail("农户编号不能为空");
        }
 
        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) ;
    }
 
    //@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 = "addRecharge")
    //@Transactional(rollbackFor = Exception.class)
    //@SsoAop("-1")//@SsoAop(power = "-1")
    //public BaseResponse<Boolean> addRecharge(@RequestBody @Parameter(description = "form表单json数据", required = true) @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) ;
    //}
}