liujie
2023-06-12 c8638bb17163cc95e9063c358eb92cada1474102
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
package com.stylefeng.guns.modular.system.controller;
 
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.base.tips.ErrorTip;
import com.stylefeng.guns.core.util.MD5Util;
import com.stylefeng.guns.modular.system.enums.UserFeeSettingEnum;
import com.stylefeng.guns.modular.system.model.*;
import com.stylefeng.guns.modular.system.model.dto.UpdatePwdDto;
import com.stylefeng.guns.modular.system.service.ITUserAddressService;
import com.stylefeng.guns.modular.system.service.ITUserFeeSettingService;
import com.stylefeng.guns.modular.system.service.ITUserFileService;
import com.stylefeng.guns.modular.system.utils.EmailUtil;
import com.stylefeng.guns.modular.system.utils.RedisUtil;
import com.stylefeng.guns.modular.system.utils.tips.SuccessTip;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.ui.Model;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.system.service.ITUserService;
 
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
 
/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2023-01-09 09:51:51
 */
@Controller
@Api(tags = "客户端--个人信息")
@RequestMapping("/api/tUser")
public class TUserController extends BaseController {
 
    @Autowired
    private ITUserService tUserService;
 
 
 
 
    @ApiOperation(value = "客户端-根据客户id获取基本信息",notes="客户端-根据客户id获取基本信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "tUserId", value = "客户id", required = true, dataType = "int"),
    })
    @PostMapping(value = "/getBasicInfo")
    @ResponseBody
    public Object getBasicInfo(Integer tUserId) {
        TUserBasicInfo tUser = tUserService.getBasicInfo(tUserId);
        return new SuccessTip(tUser);
    }
 
 
 
    @ApiOperation(value = "客户端-根据客户id获取子账号列表",notes="客户端-根据客户id获取子账号列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "tUserId", value = "客户id", required = true, dataType = "int"),
            @ApiImplicitParam(name = "pageNumber", value = "pageNumber", required = true, dataType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "pageSize", required = true, dataType = "int"),
    })
    @PostMapping(value = "/getUserList")
    @ResponseBody
    public Object getUserList(Integer tUserId,int pageNumber,int pageSize) {
        Page<TUser> tUserPage = tUserService.selectPage(new Page<>(pageNumber, pageSize), new EntityWrapper<TUser>().eq("parent_id", tUserId).eq("remove", 0).eq("status", 1));
        List<TUser> records = tUserPage.getRecords();
        Page<UserChildVo> userChildVoPage = new Page<>();
        BeanUtil.copyProperties(tUserPage,userChildVoPage);
        ArrayList<UserChildVo> userChildVos = new ArrayList<>();
        for (TUser record : records) {
            UserChildVo userChildVo = new UserChildVo();
            userChildVo.setName(record.getCompanyName());
            userChildVo.setPhone(record.getPhone());
            userChildVo.setAccount(record.getAccount());
            userChildVo.setId(record.getId());
            userChildVos.add(userChildVo);
        }
        userChildVoPage.setRecords(userChildVos);
        return new SuccessTip(userChildVoPage);
    }
 
 
    @ApiOperation(value = "客户端-根据id获取详情",notes="客户端-根据客户id获取子账号列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "tUserId", value = "客户id", required = true, dataType = "int"),
    })
    @GetMapping(value = "/getUserInfo")
    @ResponseBody
    public Object getUserInfo(Integer tUserId) {
        TUser tUser = tUserService.selectById(tUserId);
        return new SuccessTip(tUser);
    }
 
 
 
    @ApiOperation(value = "客户端-设置权限",notes="客户端-设置权限")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    @PostMapping(value = "/setUserInfo")
    @ResponseBody
    public Object setUserInfo(@RequestBody TUser tUser) {
         tUserService.updateById(tUser);
        return new SuccessTip();
    }
@Autowired
private RedisUtil redisUtil;
 
    @ApiOperation(value = "客户端-修改登录密码",notes="客户端-修改登录密码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    @PostMapping(value = "/updatePwd")
    @ResponseBody
    public Object updatePwd(@RequestBody UpdatePwdDto  dto) {
        TUser tUser = tUserService.selectById(dto.getId());
        String account = tUser.getAccount();
        String value = redisUtil.getValue(account);
        if(!value.equals(dto.getCode())){
            return new ErrorTip(5001, "Verification code error!");
        }
        tUser.setPassword(SecureUtil.md5(dto.getPwd()));
        tUserService.updateById(tUser);
        return new SuccessTip();
    }
 
 
    @ApiOperation(value = "客户端-修改account",notes="客户端-修改account")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    @PostMapping(value = "/updateAccount")
    @ResponseBody
    public Object setUserInfo(@RequestBody UpdatePwdDto  dto) {
        TUser tUser = tUserService.selectById(dto.getId());
        String account = tUser.getAccount();
        String value = redisUtil.getValue(account);
        if(!value.equals(dto.getCode())){
            return new ErrorTip(5001, "Verification code error!");
        }
        String value1 = redisUtil.getValue(dto.getEmail());
        if(!value1.equals(dto.getCodeOne())){
            return new ErrorTip(5001, "Verification code error!");
        }
        tUser.setAccount(dto.getEmail());
        tUserService.updateById(tUser);
        return new SuccessTip();
    }
 
 
 
}