liulin
2025-07-03 fb2f11d7d502ceacbe7fbed176bea4ab0f152f69
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
package com.lunhan.water.host.controller.api;
 
import com.lunhan.water.common.ExecutedResult;
import com.lunhan.water.common.PagerResult;
import com.lunhan.water.common.jwt.LoginUserDTO;
import com.lunhan.water.common.util.ParameterUtil;
import com.lunhan.water.common.validator.ParameterValidateResult;
import com.lunhan.water.common.validator.ParameterValidator;
import com.lunhan.water.entity.request.paymentrecords.ReqBuyWater;
import com.lunhan.water.entity.request.userlogin.ReqModifyUserLogin;
import com.lunhan.water.entity.search.SearchPaymentRecords;
import com.lunhan.water.entity.search.SearchRechargeRecords;
import com.lunhan.water.entity.search.SearchWaterFacility;
import com.lunhan.water.host.BasicController;
import com.lunhan.water.repository.po.UserLoginPO;
import com.lunhan.water.repository.vo.PaymentRecordsVO;
import com.lunhan.water.repository.vo.RechargeRecordsVO;
import com.lunhan.water.repository.vo.UserLoginVO;
import com.lunhan.water.repository.vo.WaterFacilityVO;
import com.lunhan.water.service.PaymentRecordsService;
import com.lunhan.water.service.RechargeRecordsService;
import com.lunhan.water.service.UserLoginService;
import com.lunhan.water.service.WaterFacilityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.math.BigDecimal;
import java.util.Objects;
 
@RestController
@RequestMapping(value = "api/user")
public class UserController extends BasicController {
    @Autowired
    private PaymentRecordsService paymentRecordsService;
    @Autowired
    private RechargeRecordsService rechargeRecordsService;
    @Autowired
    private UserLoginService userLoginService;
    @Autowired
    private WaterFacilityService waterFacilityService;
    /**
     * 查询用户信息
     * @author lin.liu
     */
    @GetMapping(value = "getUser")
    public ExecutedResult<UserLoginVO> getUser() {
        return userLoginService.getUser(this.getTokenUser());
    }
    /**
     * 编辑用户头像信息
     * @author lin.liu
     */
    @PostMapping(value = "editUser")
    public ExecutedResult<String> editUser(@RequestBody ReqModifyUserLogin request ) {
        return userLoginService.modify(request);
    }
    /**
     * 用户取水
     * @author lin.liu
     */
    @PostMapping(value = "userWaterInTaking")
    public ExecutedResult<String> userWaterInTaking(@RequestBody ReqBuyWater request) {
        return paymentRecordsService.userWaterInTaking(this.getTokenUser(),request);
    }
    /**
     * 查询取水设备列表
     * @author lin.liu
     */
    @PostMapping(value = "searchFacility")
    public ExecutedResult<PagerResult<WaterFacilityVO>> searchFacility(@RequestBody SearchWaterFacility request) {
        //#region 参数验证
        ParameterValidator validator = new ParameterValidator()
                // 必须大于0
                .addGreater(ParameterUtil.named("纬度"), request.getLatitude(), 0L)
                .addGreater(ParameterUtil.named("经度"), request.getLongitude(), 0L)
                ;
        ParameterValidateResult result = validator.validate();
        if (result.getIsFiled()) {
            return failed(result.getErrorMsg());
        }
        return waterFacilityService.search(request);
    }
 
    /**
     * 查询[消费记录]
     * @author lin.liu
     */
    @PostMapping(value = "searchPaymentRecords")
    public ExecutedResult<PagerResult<PaymentRecordsVO>> searchPaymentRecords(@RequestBody SearchPaymentRecords request) {
        //#region 参数验证
        LoginUserDTO tokenUser = this.getTokenUser();
        UserLoginPO user = userLoginService.get4Openid(tokenUser.getUserId());
        if(Objects.isNull(user)){
            return ExecutedResult.failed("用户信息不存在!");
        }
        request.setUserId(user.getId());
        return paymentRecordsService.search(request);
    }
    /**
     * 查询[充值记录]
     * @author lin.liu
     */
    @PostMapping(value = "searchRechargeRecords")
    public ExecutedResult<PagerResult<RechargeRecordsVO>> searchRechargeRecords(@RequestBody SearchRechargeRecords request) {
        LoginUserDTO tokenUser = this.getTokenUser();
        UserLoginPO user = userLoginService.get4Openid(tokenUser.getUserId());
        if(Objects.isNull(user)){
            return ExecutedResult.failed("用户信息不存在!");
        }
        request.setUserId(user.getId());
        return rechargeRecordsService.search(request);
    }
}