package com.yuanchu.mom.controller;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.yuanchu.mom.annotation.ValueAuth;
|
import com.yuanchu.mom.annotation.ValueClassify;
|
import com.yuanchu.mom.pojo.Custom;
|
import com.yuanchu.mom.dto.UserPageDto;
|
import com.yuanchu.mom.pojo.User;
|
import com.yuanchu.mom.service.CustomService;
|
import com.yuanchu.mom.service.PowerService;
|
import com.yuanchu.mom.service.UserService;
|
import com.yuanchu.mom.utils.JackSonUtil;
|
import com.yuanchu.mom.utils.Jwt;
|
import com.yuanchu.mom.utils.RedisUtil;
|
import com.yuanchu.mom.vo.Result;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import lombok.AllArgsConstructor;
|
import org.springframework.util.DigestUtils;
|
import org.springframework.web.bind.annotation.*;
|
|
import java.util.HashMap;
|
import java.util.Map;
|
|
@RequestMapping("/user")
|
@RestController
|
@Api(tags = "用户模块")
|
@AllArgsConstructor
|
public class UserController {
|
|
private UserService userService;
|
|
private PowerService powerService;
|
|
private Jwt jwt;
|
|
private CustomService customService;
|
|
@ApiOperation(value = "登录")
|
@PostMapping("/enter")
|
@ValueAuth
|
public Result login(String account, String password) {
|
User user = userService.selectUserByPwd(account, password);
|
if (user == null) return Result.fail("账号密码错误或者账号已被停用");
|
String jwtToken;
|
String jwtReToken;
|
if(RedisUtil.hasKey("" + user.getId())){
|
jwtToken = RedisUtil.get("" + user.getId()) + "";
|
}else{
|
jwtToken = jwt.createJwt(user.getName(), user.getId(), 24 * 60);
|
RedisUtil.set("" + user.getId(), jwtToken, 24 * 60);
|
}
|
if(RedisUtil.hasKey(user.getId() + "Re")){
|
jwtReToken = RedisUtil.get(user.getId() + "Re") + "";
|
}else{
|
jwtReToken = jwt.createJwt(user.getName(), user.getId(), 48 * 60);
|
RedisUtil.set(user.getId() + "Re", jwtReToken, 48 * 60);
|
}
|
Map<String, Object> map = new HashMap<>();
|
map.put("token", jwtToken);
|
map.put("reToken", jwtReToken);
|
map.put("name", user.getName());
|
map.put("userId", user.getId());
|
map.put("power", powerService.selectPowerByRoleId(user.getRoleId()));
|
return Result.success("登录成功", map);
|
}
|
|
@ApiOperation(value = "token刷新")
|
@PostMapping("/refresh")
|
@ValueAuth
|
public Result refresh(String reToken) throws Exception {
|
Map<String, String> map = new Jwt().readJWT(reToken);
|
Map<String, String> maps = JackSonUtil.unmarshal(map.get("data"), Map.class);
|
if (map.get("state").equals("0")) {
|
String redisToken = String.valueOf(RedisUtil.get(maps.get("id") + "Re"));
|
if (!redisToken.equals(reToken)) {
|
return Result.success("不存在的token", "1");
|
} else if (redisToken.equals(reToken)) {
|
int id = Integer.parseInt(maps.get("id").replaceAll("\"", ""));
|
String name = maps.get("name").replaceAll("\"", "");
|
String jwtToken = jwt.createJwt(name, id, 24 * 60);
|
String jwtReToken = jwt.createJwt(name, id, 48 * 60);
|
RedisUtil.set("" + id, jwtToken, 24 * 60);
|
RedisUtil.set(id + "Re", jwtReToken, 48 * 60);
|
Map<String, String> map1 = new HashMap<>();
|
map1.put("token", jwtToken);
|
map1.put("reToken", jwtReToken);
|
return Result.success("刷新成功", map1);
|
}
|
}
|
return Result.fail(map.get("info"));
|
}
|
|
@ValueClassify("用户管理")
|
@ApiOperation(value = "获取用户列表")
|
@PostMapping("/selectUserList2")
|
public Result selectUserList2(@RequestBody Map<String, Object> data) throws Exception {
|
Page page = JackSonUtil.unmarshal(JackSonUtil.marshal(data.get("page")), Page.class);
|
UserPageDto user = JackSonUtil.unmarshal(JackSonUtil.marshal(data.get("entity")), UserPageDto.class);
|
return Result.success(userService.selectUserList(page, user));
|
}
|
|
@ValueAuth
|
@ApiOperation(value = "获取用户列表(用于其他页面获取用户数据)")
|
@PostMapping("/selectUserList")
|
public Result selectUserList(@RequestBody Map<String, Object> data) throws Exception {
|
Page page = JackSonUtil.unmarshal(JackSonUtil.marshal(data.get("page")), Page.class);
|
UserPageDto user = JackSonUtil.unmarshal(JackSonUtil.marshal(data.get("entity")), UserPageDto.class);
|
return Result.success(userService.selectUserList(page, user));
|
}
|
|
@ValueClassify("人员总览")
|
@ApiOperation(value = "查询人员总览")
|
@PostMapping("/selectPersonnelOverview")
|
public Result selectPersonnelOverview(@RequestBody Map<String, Object> data) throws Exception {
|
Page page = JackSonUtil.unmarshal(JackSonUtil.marshal(data.get("page")), Page.class);
|
UserPageDto user = JackSonUtil.unmarshal(JackSonUtil.marshal(data.get("entity")), UserPageDto.class);
|
return Result.success(userService.selectPersonnelOverview(page, user));
|
}
|
|
@ValueClassify("用户管理")
|
@ApiOperation(value = "修改用户信息")
|
@PostMapping("/updateUser")
|
public Result<?> updateUser(@RequestBody User user) {
|
if ("".equals(user.getPassword())) user.setPassword(null);
|
else user.setPassword(DigestUtils.md5DigestAsHex(user.getPassword().getBytes()));
|
return Result.success(userService.updateUser(user));
|
}
|
@ValueClassify("用户管理")
|
@ApiOperation(value = "添加用户信息")
|
@PostMapping("/addUser")
|
public Result<?> addUser(@RequestBody User user) {
|
if ("".equals(user.getPassword())) user.setPassword(null);
|
else user.setPassword(DigestUtils.md5DigestAsHex(user.getPassword().getBytes()));
|
return Result.success(userService.addUser(user));
|
}
|
|
@ApiOperation(value = "获取用户信息枚举")
|
@GetMapping("/getUserMenu")
|
@ValueAuth
|
public Result<?> getUserMenu() {
|
return Result.success(userService.getUserMenu());
|
}
|
|
@ValueClassify("客户管理")
|
@ApiOperation(value = "获取客户列表")
|
@PostMapping("/selectCustomPageList")
|
public Result selectCustomPageList(@RequestBody Map<String, Object> data) throws Exception {
|
Page page = JackSonUtil.unmarshal(JackSonUtil.marshal(data.get("page")), Page.class);
|
Custom custom = JackSonUtil.unmarshal(JackSonUtil.marshal(data.get("entity")), Custom.class);
|
return Result.success(customService.selectCustomPageList(page, custom));
|
}
|
@ValueClassify("客户管理")
|
@ApiOperation(value = "删除客户信息")
|
@PostMapping("/delCustomById")
|
public Result<?> delCustomById(Long id) {
|
return Result.success(customService.removeById(id));
|
}
|
@ValueClassify("客户管理")
|
@ApiOperation(value = "新增客户信息")
|
@PostMapping("/addCustom")
|
public Result<?> addCustom(@RequestBody Custom custom) {
|
return Result.success(customService.addCustom(custom));
|
}
|
|
@ValueClassify("客户管理")
|
@ApiOperation(value = "修改客户信息")
|
@PostMapping("/upCustom")
|
public Result<?> upCustom(@RequestBody Custom custom) {
|
return Result.success(customService.upCustom(custom));
|
}
|
|
//获取设备负责人
|
@ValueAuth
|
@ApiOperation(value = "获取设备负责人")
|
@GetMapping("/getDeviceManager")
|
public Result<?> getDeviceManager() {
|
return Result.success(userService.getDeviceManager());
|
}
|
|
@ValueAuth
|
@GetMapping("/getUserNow")
|
@ApiOperation(value = "获取当前登录的客户信息")
|
public Result<?> getUserNow(){
|
return Result.success(userService.getUserNow());
|
}
|
|
@ValueAuth
|
@GetMapping("/getUserInfo")
|
@ApiOperation(value = "获取当前登录的用户信息")
|
public Result<?> getUserInfo(){
|
return Result.success(userService.getUserInfo());
|
}
|
|
@PostMapping("/upUserPassword")
|
@ApiOperation(value = "修改用户密码")
|
@ValueAuth
|
public Result<?> upUserPassword(String oldPassword, String newPassWord){
|
return Result.success(userService.upUserPassword(oldPassword, newPassWord));
|
}
|
|
@ValueClassify("人员明细")
|
@PostMapping("/upUserDepardLimsId")
|
@ApiOperation(value = "修改人员明细所在组织架构")
|
public Result<?> upUserDepardLimsId(String ids, String id){
|
return Result.success(userService.upUserDepardLimsId(ids, id));
|
}
|
|
@ValueClassify("人员明细")
|
@PostMapping("/delUserDepardLimsId")
|
@ApiOperation(value = "删除人员明细所在组织架构")
|
public Result<?> delUserDepardLimsId(Integer id){
|
return Result.success(userService.delUserDepardLimsId(id));
|
}
|
|
@ValueAuth
|
@GetMapping ("/selectCustomEnum")
|
@ApiOperation(value = "获取客户枚举")
|
public Result<?> selectCustomEnum(){
|
return Result.success(customService.selectCustomEnum());
|
}
|
|
}
|