package com.zy.asrs.common.sys.controller;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.zy.asrs.common.sys.entity.Role;
|
import com.zy.asrs.common.sys.entity.User;
|
import com.zy.asrs.common.sys.service.RoleService;
|
import com.zy.asrs.common.sys.service.UserService;
|
import com.zy.asrs.common.web.BaseController;
|
import com.zy.asrs.framework.annotations.ManagerAuth;
|
import com.zy.asrs.framework.common.Cools;
|
import com.zy.asrs.framework.common.R;
|
import com.zy.asrs.framework.domain.KeyValueVo;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import java.util.*;
|
|
@RestController
|
public class UserController extends BaseController {
|
|
@Autowired
|
private UserService userService;
|
@Autowired
|
private RoleService roleService;
|
|
@RequestMapping(value = "/user/{id}/auth")
|
@ManagerAuth
|
public R get(@PathVariable("id") Long id) {
|
return R.ok(userService.getById(String.valueOf(id)));
|
}
|
|
@RequestMapping(value = "/user/list/auth")
|
@ManagerAuth
|
public R list(@RequestParam(defaultValue = "1")Integer curr,
|
@RequestParam(defaultValue = "10")Integer limit,
|
@RequestParam(required = false)String orderByField,
|
@RequestParam(required = false)String orderByType,
|
@RequestParam Map<String, Object> param){
|
excludeTrash(param);
|
LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
|
wrapper.eq(User::getHostId, param.get("host_id"));
|
wrapper.orderByDesc(User::getId);
|
if (9527 == getUserId()) {
|
return R.ok(userService.page(new Page<>(curr, limit), wrapper));
|
}
|
|
Long roleId = getUser().getRoleId();
|
Role role = roleService.getById(roleId);
|
Long leaderId = role.getLeader();
|
if (null != leaderId) {
|
List<Long> leaderIds = new ArrayList<>();
|
leaderIds.add(role.getId());
|
while (leaderId != null) {
|
Role leader = roleService.getById(leaderId);
|
leaderIds.add(leader.getId());
|
leaderId = leader.getLeader();
|
}
|
wrapper.notIn(User::getRoleId, leaderIds);
|
}
|
|
return R.ok(userService.page(new Page<>(curr, limit), wrapper));
|
}
|
|
|
@RequestMapping(value = "/user/edit/auth")
|
@ManagerAuth(memo = "系统用户编辑")
|
public R edit(User user) {
|
if (Cools.isEmpty(user)){
|
return R.error();
|
}
|
if (null == user.getId()){
|
user.setStatus(1);
|
user.setCreateTime(new Date());
|
userService.save(user);
|
} else {
|
userService.updateById(user);
|
}
|
return R.ok();
|
}
|
|
@RequestMapping(value = "/user/add/auth")
|
@ManagerAuth(memo = "系统用户添加")
|
public R add(User user) {
|
User one = userService.getOne(new LambdaQueryWrapper<User>().eq(User::getUsername, user.getUsername()));
|
if (one != null) {
|
return R.error("账号已存在");
|
}
|
user.setStatus(1);
|
user.setCreateTime(new Date());
|
userService.save(user);
|
return R.ok();
|
}
|
|
@RequestMapping(value = "/user/update/auth")
|
@ManagerAuth(memo = "系统用户修改")
|
public R update(User user){
|
if (Cools.isEmpty(user) || null==user.getId()){
|
return R.error();
|
}
|
User entity = userService.getById(user.getId());
|
if (user.getPassword()!=null) {
|
entity.setPassword(user.getPassword());
|
}
|
if (user.getUsername()!=null) {
|
entity.setUsername(user.getUsername());
|
}
|
if (user.getMobile()!=null) {
|
entity.setMobile(user.getMobile());
|
}
|
userService.updateById(entity);
|
return R.ok();
|
}
|
|
@RequestMapping(value = "/user/delete/auth")
|
@ManagerAuth(memo = "系统用户删除")
|
public R delete(@RequestParam(value="ids[]") Long[] ids){
|
for (Long id : ids){
|
userService.removeById(id);
|
}
|
return R.ok();
|
}
|
|
|
@RequestMapping(value = "/userQuery/auth")
|
@ManagerAuth
|
public R query(String condition) {
|
LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
|
wrapper.like(User::getUsername, condition);
|
Page<User> page = userService.page(new Page<>(0, 10), wrapper);
|
List<Map<String, Object>> result = new ArrayList<>();
|
for (User user : page.getRecords()){
|
Map<String, Object> map = new HashMap<>();
|
map.put("id", user.getId());
|
map.put("value", user.getUsername());
|
result.add(map);
|
}
|
return R.ok(result);
|
}
|
|
/*************************************** xm-select ***********************************************/
|
|
// xm-select 搜索商品列表
|
@RequestMapping("/user/all/get/kv")
|
@ManagerAuth
|
public R getUserDataKV(@RequestParam(required = false) String condition) {
|
List<KeyValueVo> vos = new ArrayList<>();
|
LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
|
if (!Cools.isEmpty(condition)) {
|
wrapper.like(User::getUsername, condition);
|
}
|
userService.page(new Page<>(1, 30), wrapper).getRecords().forEach(item -> vos.add(new KeyValueVo(String.valueOf(item.getUsername()), item.getId())));
|
return R.ok().add(vos);
|
}
|
|
}
|