puzhibing
2023-07-07 0be58dbf7774fef98ddac83c3f454b49c6d5a6c1
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
package com.dsh.account.controller;
 
 
import com.dsh.account.entity.TAppUser;
import com.dsh.account.feignclient.other.SysLogClient;
import com.dsh.account.model.vo.userBenefitDetail.AppUserDetailsVo;
import com.dsh.account.model.vo.userBenefitDetail.BillingDetailsVo;
import com.dsh.account.model.vo.userBenefitDetail.IndexOfUserBenefirVo;
import com.dsh.account.service.TAppUserService;
import com.dsh.account.util.ResultUtil;
import com.dsh.account.util.TokenUtil;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.text.SimpleDateFormat;
 
/**
 * 使用福利 控制器
 */
 
@RestController
@RequestMapping("")
public class UseBenefitsController {
 
 
    @Autowired
    private TAppUserService tauService;
 
    @Autowired
    private TokenUtil tokenUtil;
 
    @Autowired
    private SysLogClient slClient;
 
    private final SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
 
 
    @ResponseBody
    @PostMapping("/api/useBenefit/indexOfAppUser")
    @ApiOperation(value = "福利主页", tags = {"APP-使用福利"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    public ResultUtil<IndexOfUserBenefirVo> queryAppUserUser(){
        try {
            Integer appUserId = tokenUtil.getUserIdFormRedis();
            if(null == appUserId){
                return ResultUtil.tokenErr();
            }
            return ResultUtil.success(tauService.queryBenefitDetails(appUserId));
        }catch (Exception e){
            return ResultUtil.runErr();
        }
    }
 
 
    @ResponseBody
    @PostMapping("/api/useBenefit/userDetails")
    @ApiOperation(value = "用户个人信息", tags = {"APP-使用福利"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    public ResultUtil<AppUserDetailsVo> queryAppUserDetails(){
        try {
            AppUserDetailsVo detailsVo = new AppUserDetailsVo();
            Integer appUserId = tokenUtil.getUserIdFormRedis();
            if(null == appUserId){
                return ResultUtil.tokenErr();
            }
            TAppUser tAppUser = tauService.getBaseMapper().selectById(appUserId);
            if (null != tAppUser){
                detailsVo.setUserImage(tAppUser.getHeadImg());
                detailsVo.setUserName(tAppUser.getName());
                detailsVo.setUserPhone(tAppUser.getPhone());
                detailsVo.setSex(tAppUser.getGender() == 1 ? "男" : "女");
                detailsVo.setBirthday(format1.format(tAppUser.getBirthday()));
                detailsVo.setAddress(tAppUser.getProvince()+tAppUser.getCity());
                detailsVo.setMemberLifespan(format1.format(tAppUser.getVipEndTime()));
            }
            return ResultUtil.success(detailsVo);
        }catch (Exception e){
            return ResultUtil.runErr();
        }
    }
 
 
 
    @ResponseBody
    @PostMapping("/api/useBenefit/cancellation")
    @ApiOperation(value = "个人信息-注销账号", tags = {"APP-使用福利"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    public ResultUtil cancellationAccount(){
        try {
            Integer appUserId = tokenUtil.getUserIdFormRedis();
            if(null == appUserId){
                return ResultUtil.tokenErr();
            }
//            变更账号的状态为删除
            tauService.cancellation(appUserId);
//            增加一条注销账号的日志
            slClient.cancellation(appUserId);
//            删除redis中用户key
            tokenUtil.logout();
            return ResultUtil.success();
        }catch (Exception e){
            return ResultUtil.runErr();
        }
    }
 
 
 
    @ResponseBody
    @PostMapping("/api/useBenefit/logOut")
    @ApiOperation(value = "个人信息-退出登录", tags = {"APP-使用福利"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    public ResultUtil logOutAccount(){
        try {
            Integer appUserId = tokenUtil.getUserIdFormRedis();
            if(null == appUserId){
                return ResultUtil.tokenErr();
            }
            //            增加一条退出账号的日志
            slClient.logOut(appUserId);
            //            删除redis中用户key
            tokenUtil.logout();
            return ResultUtil.success();
        }catch (Exception e){
            return ResultUtil.runErr();
        }
    }
 
 
 
    @ResponseBody
    @PostMapping("/api/useBenefit/userBilling")
    @ApiOperation(value = "账单", tags = {"APP-使用福利"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(value = "年月", name = "yearMonth", required = true, dataType = "string"),
            @ApiImplicitParam(value = "记录id", name = "recordId", required = true, dataType = "int"),
    })
    public ResultUtil<BillingDetailsVo> getUserBillingDetails(String yearMonth,Integer recordId){
        try {
            Integer appUserId = tokenUtil.getUserIdFormRedis();
            if(null == appUserId){
                return ResultUtil.tokenErr();
            }
            return ResultUtil.success(tauService.queryUserBillingDetails(yearMonth,recordId));
        }catch (Exception e){
            return ResultUtil.runErr();
        }
    }
 
 
 
 
}