zuoxiao
2 天以前 44030fd43d3b8009a6ba0591dc60fa7720b20e0a
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
package com.dy.pipIrrTerminal.card;
 
import com.dy.common.aop.SsoAop;
import com.dy.common.webUtil.BaseResponse;
import com.dy.common.webUtil.BaseResponseUtils;
import com.dy.common.webUtil.QueryResultVo;
import com.dy.common.webUtil.ResultCodeMsg;
import com.dy.pipIrrGlobal.voSe.*;
import com.dy.pipIrrTerminal.card.dto.*;
import com.dy.pipIrrTerminal.card.qo.QoCards;
import com.dy.pipIrrTerminal.card.qo.QoLostCards;
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 jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
import java.util.Map;
import java.util.Objects;
 
/**
 * @author ZhuBaoMin
 * @date 2025-05-08 10:15
 * @LastEditTime 2025-05-08 10:15
 * @Description
 */
 
@Slf4j
@RestController
@RequestMapping(path = "card")
@RequiredArgsConstructor
public class CardCtrl {
    private final CardSv cardSv;
 
    /**
     * 开卡(含充值)
     *
     * @param po
     * @param bindingResult
     * @return
     */
    @PostMapping(path = "termActiveCard", consumes = MediaType.APPLICATION_JSON_VALUE)
    @SsoAop()
    public BaseResponse<VoTermActiveCard> termActiveCard(@RequestBody @Valid ActiveCard po, BindingResult bindingResult) {
        if (bindingResult != null && bindingResult.hasErrors()) {
            return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
 
        Map map_result = cardSv.activeOrReissueTermCard(po);
        if (map_result.get("success").equals(false)) {
            return BaseResponseUtils.buildErrorMsg(map_result.get("msg").toString());
        }
        return BaseResponseUtils.buildSuccess(map_result.get("content"));
 
    }
 
    /**
     * 充值
     *
     * @param po
     * @param bindingResult
     * @return
     */
    @PostMapping(path = "termRecharge", consumes = MediaType.APPLICATION_JSON_VALUE)
    @SsoAop()
    public BaseResponse<VoTermCommon> termRecharge(@RequestBody @Valid DtoRecharge po, BindingResult bindingResult) {
        if (bindingResult != null && bindingResult.hasErrors()) {
            return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
 
        Map map_result = cardSv.addRecharge(po, null);
        if (map_result.get("success").equals(false)) {
            return BaseResponseUtils.buildErrorMsg(map_result.get("msg").toString());
        }
        return BaseResponseUtils.buildSuccess(map_result.get("content"));
 
    }
 
    /**
     * 挂失
     *
     * @param po
     * @param bindingResult
     * @return
     */
    @PostMapping(path = "termReportLoss", consumes = MediaType.APPLICATION_JSON_VALUE)
    @SsoAop()
    public BaseResponse<Boolean> termReportLoss(@RequestBody @Valid DtoLoss po, BindingResult bindingResult) {
        if (bindingResult != null && bindingResult.hasErrors()) {
            return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
 
        Map map_result = cardSv.reportLoss(po);
        if (map_result.get("success").equals(false)) {
            return BaseResponseUtils.buildErrorMsg(map_result.get("msg").toString());
        }
        return BaseResponseUtils.buildSuccess(map_result.get("content"));
 
    }
 
    /**
     * 解锁
     *
     * @param po
     * @param bindingResult
     * @return
     */
    @PostMapping(path = "termUnlock", consumes = MediaType.APPLICATION_JSON_VALUE)
    @SsoAop()
    public BaseResponse<Boolean> termUnlock(@RequestBody @Valid DtoUnlock po, BindingResult bindingResult) {
        if (bindingResult != null && bindingResult.hasErrors()) {
            return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
 
        Map map_result = cardSv.unlock(po);
        if (map_result.get("success").equals(false)) {
            return BaseResponseUtils.buildErrorMsg(map_result.get("msg").toString());
        }
        return BaseResponseUtils.buildSuccess(map_result.get("content"));
 
    }
 
    /**
     * 补卡
     *
     * @param po
     * @param bindingResult
     * @return
     */
    @PostMapping(path = "termReissue", consumes = MediaType.APPLICATION_JSON_VALUE)
    @SsoAop()
    public BaseResponse<VoTermCommon> termReissue(@RequestBody @Valid DtoReissue po, BindingResult bindingResult) {
        if (bindingResult != null && bindingResult.hasErrors()) {
            return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
 
        Map map_result = cardSv.reissue(po);
        if (map_result.get("success").equals(false)) {
            return BaseResponseUtils.buildErrorMsg(map_result.get("msg").toString());
        }
        return BaseResponseUtils.buildSuccess(map_result.get("content"));
 
    }
 
    /**
     * 销卡
     *
     * @param po
     * @param bindingResult
     * @return
     */
    @PostMapping(path = "termCancel", consumes = MediaType.APPLICATION_JSON_VALUE)
    @SsoAop()
    public BaseResponse<VoTermCommon> termCancel(@RequestBody @Valid DtoCancel po, BindingResult bindingResult) {
        if (bindingResult != null && bindingResult.hasErrors()) {
            return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
 
        Map map_result = cardSv.cancel(po);
        if (map_result.get("success").equals(false)) {
            return BaseResponseUtils.buildErrorMsg(map_result.get("msg").toString());
        }
        return BaseResponseUtils.buildSuccess(map_result.get("content"));
 
    }
 
    /**
     * 补扣
     * @param po
     * @param bindingResult
     * @return
     */
    @PostMapping(path = "termRepay", consumes = MediaType.APPLICATION_JSON_VALUE)
    @SsoAop()
    public BaseResponse<VoRepaySupplement> termRepay(@RequestBody @Valid DtoRepaySupplement po, BindingResult bindingResult) {
        if (bindingResult != null && bindingResult.hasErrors()) {
            return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
 
        if(po.getRepayMorny()  == null || po.getRepayMorny() <= 0) {
            return BaseResponseUtils.buildErrorMsg("补扣金额不能为空且需大于0");
        }
 
        if(po.getRepayMorny() > po.getBalance()) {
            return BaseResponseUtils.buildErrorMsg("补扣金额不能大于补扣前余额");
        }
 
        Map map_result = cardSv.repay(po);
        if (map_result.get("success").equals(false)) {
            return BaseResponseUtils.buildErrorMsg(map_result.get("msg").toString());
        }
        return BaseResponseUtils.buildSuccess(map_result.get("content"));
    }
 
    /**
     * 返还
     * @param po
     * @param bindingResult
     * @return
     */
    @PostMapping(path = "supplement", consumes = MediaType.APPLICATION_JSON_VALUE)
    @SsoAop()
    public BaseResponse<VoRepaySupplement> supplement(@RequestBody @Valid DtoRepaySupplement po, BindingResult bindingResult) {
        if (bindingResult != null && bindingResult.hasErrors()) {
            return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
 
        if(po.getSupplementMoney() == null || po.getSupplementMoney() <= 0) {
            return BaseResponseUtils.buildErrorMsg("返还金额不能为空且需大于0");
        }
 
        Map map_result = cardSv.supplement(po);
        if (map_result.get("success").equals(false)) {
            return BaseResponseUtils.buildErrorMsg(map_result.get("msg").toString());
        }
        return BaseResponseUtils.buildSuccess(map_result.get("content"));
    }
 
    /**
     * 操作执行回调
     *
     * @param po
     * @param bindingResult
     * @return
     */
    @PostMapping(path = "termCallBack", consumes = MediaType.APPLICATION_JSON_VALUE)
    @SsoAop()
    public BaseResponse<Boolean> termCallBack(@RequestBody @Valid DtoCallBack po, BindingResult bindingResult) {
        if (bindingResult != null && bindingResult.hasErrors()) {
            return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
 
        Map map_result = cardSv.callBack(po);
        if (map_result.get("success").equals(false)) {
            return BaseResponseUtils.buildErrorMsg(map_result.get("msg").toString());
        }
        return BaseResponseUtils.buildSuccess(map_result.get("content"));
    }
 
    /**
     * 读取卡信息
     * @param cardAddr
     * @return
     */
    @GetMapping(path = "readCard")
    @SsoAop()
    public BaseResponse<VoTermCard> readCard(@RequestParam String cardAddr){
        try {
            VoTermCard voTermCard = cardSv.readCard(cardAddr);
            if(voTermCard == null) {
                return BaseResponseUtils.buildNonExist();
            }
            return BaseResponseUtils.buildSuccess(voTermCard);
        } catch (Exception e) {
            log.error("查询农户异常", e);
            return BaseResponseUtils.buildException(e.getMessage()) ;
        }
    }
 
    /**
     * 根据指定条件获取水卡列表,终端应用程序使用
     * @param vo
     * @return
     */
    @Operation(summary = "获得一页水卡记录", description = "返回一页水卡数据")
    @ApiResponses(value = {
            @ApiResponse(
                    responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
                    description = "返回一页水卡数据(BaseResponse.content:QueryResultVo[{}])",
                    content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
                            schema = @Schema(implementation = VoCards.class))}
            )
    })
    @GetMapping(path = "getcards")
    @SsoAop()
    public BaseResponse<QueryResultVo<List<VoCards>>> getcards(QoCards vo){
        try {
            QueryResultVo<List<VoCards>> res = cardSv.getCards(vo);
            return BaseResponseUtils.buildSuccess(res);
        } catch (Exception e) {
            log.error("查询水卡异常", e);
            return BaseResponseUtils.buildException(e.getMessage()) ;
        }
    }
 
    /**
     * 获取已挂失的水卡列表,终端应用程序使用
     * @param vo
     * @return
     */
    @Operation(summary = "获得一页已挂失水卡记录", description = "返回一页已挂失水卡数据")
    @ApiResponses(value = {
            @ApiResponse(
                    responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
                    description = "返回一页已挂失水卡数据(BaseResponse.content:QueryResultVo[{}])",
                    content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
                            schema = @Schema(implementation = VoCards.class))}
            )
    })
    @GetMapping(path = "getlostcards")
    @SsoAop()
    public BaseResponse<QueryResultVo<List<VoCards>>> getLostCards(QoLostCards vo){
        try {
            QueryResultVo<List<VoCards>> res = cardSv.getLostCards(vo);
            return BaseResponseUtils.buildSuccess(res);
        } catch (Exception e) {
            log.error("查询已挂失水卡异常", e);
            return BaseResponseUtils.buildException(e.getMessage()) ;
        }
    }
 
    /**
     * 根据农户编号获取卡信息
     * @param clientNum 农户编号
     * @return
     */
    @Operation(summary = "根据农户编号获取卡信息", description = "根据农户编号获取对应的卡信息")
    @ApiResponses(value = {
            @ApiResponse(
                    responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
                    description = "返回卡信息(BaseResponse.content:VoCardByClientNum)",
                    content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
                            schema = @Schema(implementation = VoCardByClientNum.class))}
            )
    })
    @GetMapping(path = "getcardbyclientnum")
    @SsoAop()
    public BaseResponse<VoCardByClientNum> getCardByClientNum(@RequestParam String clientNum){
        try {
            VoCardByClientNum res = cardSv.getCardByClientNum(clientNum);
            if (res == null) {
                return BaseResponseUtils.buildFail("未找到对应的卡信息");
            }
            return BaseResponseUtils.buildSuccess(res);
        } catch (Exception e) {
            log.error("根据农户编号查询卡信息异常", e);
            return BaseResponseUtils.buildException(e.getMessage()) ;
        }
    }
}