liujie
2023-05-22 9f2315d92cc93f8f431805a10ea9ce3f79fa7eb2
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
package com.stylefeng.guns.modular.system.controller;
 
import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.util.MD5Util;
import com.stylefeng.guns.modular.system.model.RoleVo;
import com.stylefeng.guns.modular.system.model.UserDto;
import com.stylefeng.guns.modular.system.model.UserVo;
import com.stylefeng.guns.modular.system.service.IRoleService;
import com.stylefeng.guns.modular.system.utils.tips.ErrorTip;
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.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.modular.system.model.User;
import com.stylefeng.guns.modular.system.service.IUserService;
 
import java.util.Date;
import java.util.List;
 
/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2023-01-06 14:22:05
 */
@Controller
@Api(tags = "销售")
@RequestMapping("/api/user")
public class UserController extends BaseController {
 
 
    @Autowired
    private IUserService userService;
 
    @Autowired
    private IRoleService roleService;
 
 
 
    /**
     * 获取列表
     */
    @ApiOperation(value = "获取销售列表",notes="获取销售列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "pageNumber", value = "pageNumber", required = true, dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "pageSize", required = true, dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "account", value = "account", required = false, dataType = "String"),
            @ApiImplicitParam(name = "name", value = "name", required = false, dataType = "String"),
            @ApiImplicitParam(name = "roleName", value = "roleName", required = false, dataType = "String"),
            @ApiImplicitParam(name = "departmentName", value = "departmentName", required = false, dataType = "String"),
    })
    @GetMapping(value = "/list")
    @ResponseBody
    public Object list(String account,String name ,String roleName,String departmentName,int pageNumber,int pageSize) {
        Page<UserVo> userVoPage = new Page<>(pageNumber, pageSize);
        List<UserVo> list =  userService.getList(userVoPage,account,name,roleName,departmentName);
        userVoPage.setRecords(list);
        return new SuccessTip(userVoPage);
    }
 
 
 
    @ApiOperation(value = "设置提成",notes="设置提成")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "userId", value = "销售id", required = true, dataType = "int"),
            @ApiImplicitParam(name = "commission", value = "提成", required = true, dataType = "Double"),
    })
    @PostMapping(value = "/setCommission")
    @ResponseBody
    public Object setCommission(int userId,Double commission) {
        try {
            User user = userService.selectById(userId);
            user.setCommission(commission);
            userService.updateById(user);
            return SUCCESS_TIP;
        }catch (Exception e){
            e.printStackTrace();
            return ERROR;
        }
    }
 
    @ApiOperation(value = "根据销售id获取所在部门角色",notes="根据销售id获取所在部门角色")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "userId", value = "销售id", required = true, dataType = "int"),
    })
    @PostMapping(value = "/getDept")
    @ResponseBody
    public Object getDept(int userId) {
        try {
            User user = userService.selectById(userId);
            Integer deptid = user.getDeptid();
            List<RoleVo> roles = roleService.getDept(deptid);
            for (RoleVo role : roles) {
                if(user.getRoleid().equals(role.getId().toString())){
                    role.setIsRole(2);
                }else {
                    role.setIsRole(1);
                }
            }
            return roles;
        }catch (Exception e){
            e.printStackTrace();
            return ERROR;
        }
    }
 
 
 
    @ApiOperation(value = "设置销售角色",notes="设置销售角色")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "userId", value = "销售id", required = true, dataType = "int"),
            @ApiImplicitParam(name = "roleId", value = "角色id", required = true, dataType = "int"),
    })
    @PostMapping(value = "/setRoleFromId")
    @ResponseBody
    public Object setRoleFromId(int userId,Integer roleId) {
        try {
            User user = userService.selectById(userId);
            user.setRoleid(roleId.toString());
            return userService.updateById(user);
        }catch (Exception e){
            e.printStackTrace();
            return ERROR;
        }
    }
    /**
     * 新增
     */
    @ApiOperation(value = "添加销售",notes="添加销售")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    @PostMapping(value = "/add")
    @ResponseBody
    public Object add(UserDto user) {
        String encrypt = MD5Util.encrypt(user.getPassword());
        user.setPassword(encrypt);
        User user1 = new User();
        BeanUtils.copyProperties(user,user1);
        user1.setStatus(1);
        user1.setCreatetime(new Date());
        userService.insert(user1);
        return SUCCESS_TIP;
    }
 
    /**
     * 删除
     */
    @ApiOperation(value = "删除销售",notes="删除销售")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "userId", value = "销售id", required = true, dataType = "int"),
    })
    @DeleteMapping(value = "/delete")
    @ResponseBody
    public Object delete( Integer userId) {
        User user = userService.selectById(userId);
        if(user.getStatus()!=2){
            return new ErrorTip(500, "只能删除被冻结状态的账号!");
        }
        user.setStatus(3);
        userService.updateById(user);
        return SUCCESS_TIP;
    }
 
 
    @ApiOperation(value = "冻结/解冻用户",notes="冻结/解冻用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "userId", value = "销售id", required = true, dataType = "int"),
            @ApiImplicitParam(name = "type", value = "2冻结 1解冻", required = true, dataType = "int"),
    })
    @PostMapping(value = "/freezeUser")
    @ResponseBody
    public Object freezeUser( Integer userId,Integer type) {
        User user = userService.selectById(userId);
        user.setStatus(type);
        userService.updateById(user);
        return SUCCESS_TIP;
    }
 
    /**
     * 修改
     */
    @ApiOperation(value = "修改销售",notes="修改销售")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    @PostMapping(value = "/update")
    @ResponseBody
    public Object update(UserDto user) {
        if(user.getPassword()!=null && user.getPassword()!=""){
            user.setPassword(MD5Util.encrypt(user.getPassword()));
        }
        User user1 = new User();
        BeanUtils.copyProperties(user,user1);
        userService.updateById(user1);
        return SUCCESS_TIP;
    }
 
    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{userId}")
    @ResponseBody
    public Object detail(@PathVariable("userId") Integer userId) {
        return userService.selectById(userId);
    }
 
 
}