|
@@ -3,18 +3,25 @@ package com.platform.controller;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.platform.annotation.SysLog;
|
|
|
-import com.platform.entity.*;
|
|
|
+import com.platform.entity.Result;
|
|
|
+import com.platform.entity.SysRoleEntity;
|
|
|
+import com.platform.entity.SysUserEntity;
|
|
|
import com.platform.enums.SysRoleEnum;
|
|
|
-import com.platform.service.*;
|
|
|
+import com.platform.service.SysRoleService;
|
|
|
+import com.platform.service.SysUserRoleService;
|
|
|
+import com.platform.service.SysUserService;
|
|
|
import com.platform.service.custom.MySysUserBrandService;
|
|
|
-import com.platform.service.impl.SysDeptServiceImpl;
|
|
|
-import com.platform.service.impl.ZhiHouseService;
|
|
|
-import com.platform.utils.*;
|
|
|
-import com.platform.validator.Assert;
|
|
|
+import com.platform.utils.Constant;
|
|
|
+import com.platform.utils.PageUtilsPlus;
|
|
|
+import com.platform.utils.Query;
|
|
|
+import com.platform.utils.StringUtils;
|
|
|
import com.platform.validator.ValidatorUtils;
|
|
|
import com.platform.validator.group.AddGroup;
|
|
|
import com.platform.validator.group.UpdateGroup;
|
|
|
-import io.swagger.annotations.*;
|
|
|
+import io.swagger.annotations.ApiImplicitParam;
|
|
|
+import io.swagger.annotations.ApiImplicitParams;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import io.swagger.annotations.ApiParam;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -52,8 +59,6 @@ public class SysUserController extends AbstractController {
|
|
|
@Autowired
|
|
|
private MySysUserBrandService mySysUserBrandService;
|
|
|
|
|
|
- @Autowired
|
|
|
- private SysDeptServiceImpl sysDeptService;
|
|
|
|
|
|
@Autowired
|
|
|
private RestTemplate restTemplate;
|
|
@@ -74,7 +79,7 @@ public class SysUserController extends AbstractController {
|
|
|
@RequestParam(name = "pageNum") long pageNum,
|
|
|
@RequestParam(name = "pageSize") long pageSize) {
|
|
|
|
|
|
- IPage<SysUserEntity> resultPage = sysUserService.getSysUserList(sysDeptService.getSubDeptIdLongList(deptId), key,
|
|
|
+ IPage<SysUserEntity> resultPage = sysUserService.getSysUserList(Arrays.asList(getDeptId()), key,
|
|
|
brandId , pageNum, pageSize);
|
|
|
if (null == resultPage) {
|
|
|
return Result.failure("获取用户列表失败");
|
|
@@ -95,7 +100,7 @@ public class SysUserController extends AbstractController {
|
|
|
public Result list(@RequestBody Map<String, Object> params) {
|
|
|
//只有超级管理员,才能查看所有管理员列表
|
|
|
if (getUserId() != Constant.SUPER_ADMIN) {
|
|
|
- params.put("deptIdList", sysDeptService.getSubDeptIdList(getDeptId()));
|
|
|
+ params.put("deptIdList", getDeptId());
|
|
|
}
|
|
|
//查询列表数据
|
|
|
Query query = new Query(params);
|
|
@@ -239,54 +244,6 @@ public class SysUserController extends AbstractController {
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- @ApiOperation(value = "新增员工接口")
|
|
|
- @SysLog("新增员工接口")
|
|
|
- @PostMapping("/staffSave")
|
|
|
- @RequiresPermissions("sys:user:save")
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public Result staffSave(@ApiParam(name = "SysUserEntity对象", value = "传入json格式", required = true) @RequestBody SysUserEntity user) {
|
|
|
- ValidatorUtils.validateEntity(user, AddGroup.class);
|
|
|
- if(null == user.getDeptId()){
|
|
|
- return Result.failure("缺失公司数据!");
|
|
|
- }
|
|
|
- if(ObjectUtils.isEmpty(user.getRoleId())){
|
|
|
- return Result.failure("角色为空!");
|
|
|
- }
|
|
|
-
|
|
|
- //TODO:这里需要改成select for update
|
|
|
- SysDeptEntity sysDeptEntity = sysDeptService.queryObject(user.getDeptId());
|
|
|
- if(null == sysDeptEntity){
|
|
|
- return Result.failure("公司不存在!");
|
|
|
- }
|
|
|
- int curStaffNum = null != sysDeptEntity.getCurStaffNum() ? sysDeptEntity.getCurStaffNum() : 0;
|
|
|
- int maxStaffNum = null != sysDeptEntity.getStaffNum() ? sysDeptEntity.getStaffNum() : 0;
|
|
|
- if((curStaffNum + 1) > maxStaffNum){
|
|
|
- return Result.failure("公司员工已经达到上限!");
|
|
|
- }
|
|
|
-
|
|
|
- user.setCreateUserId(getUserId());
|
|
|
-
|
|
|
- SysUserEntity sysUserEntity = sysUserService.queryByUserMobile(user.getMobile());
|
|
|
- if(null != sysUserEntity){
|
|
|
- return Result.failure("员工已经存在,请勿重复添加!");
|
|
|
- }
|
|
|
- //创建用户,并且创建用户和角色的关联关系
|
|
|
- sysUserService.save(user);
|
|
|
-
|
|
|
- //给相应的部门增加相应的员工数
|
|
|
- if(null == sysDeptEntity.getCurStaffNum()){
|
|
|
- sysDeptEntity.setCurStaffNum(1);
|
|
|
- }else{
|
|
|
- sysDeptEntity.setCurStaffNum(curStaffNum + 1);
|
|
|
- }
|
|
|
-
|
|
|
- sysDeptService.update(sysDeptEntity);
|
|
|
-
|
|
|
- return Result.success();
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 修改用户
|
|
|
*/
|
|
@@ -348,70 +305,4 @@ public class SysUserController extends AbstractController {
|
|
|
}
|
|
|
return Result.success();
|
|
|
}
|
|
|
-
|
|
|
- @ApiOperation(value = "删除员工")
|
|
|
- @SysLog("删除员工")
|
|
|
- @PostMapping("/deleteStaff")
|
|
|
- @RequiresPermissions("sys:user:delete")
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public Result deleteStaff(@RequestBody Map<String,String> params) {
|
|
|
- Long userId = Long.parseLong(params.get("userId"));
|
|
|
- String toUser = params.get("toUser");
|
|
|
- if(ObjectUtils.isEmpty(userId)){
|
|
|
- return Result.failure("参数有误!");
|
|
|
- }
|
|
|
- if (userId.equals(-1L)) {
|
|
|
- return Result.failure("不能删除平台管理员");
|
|
|
- }
|
|
|
- if (getUserId().equals(userId)) {
|
|
|
- return Result.failure("当前用户不能删除");
|
|
|
- }
|
|
|
-
|
|
|
- SysUserEntity sysUserEntity = sysUserService.queryObject(userId);
|
|
|
- if(ObjectUtils.isEmpty(sysUserEntity)){
|
|
|
- return Result.failure("获取用户信息失败!");
|
|
|
- }
|
|
|
-
|
|
|
- List<Long> roleList = sysUserRoleService.queryRoleIdList(userId);
|
|
|
- if (!CollectionUtils.isEmpty(roleList) && roleList.contains(5)) {
|
|
|
- return Result.failure("不能删除平台管理员");
|
|
|
- }
|
|
|
-
|
|
|
- // 获取情景信息
|
|
|
- List<Long> bindUsers = mySysUserBrandService.queryBrandIdList(userId);
|
|
|
- SysUserEntity toUserEntity = null;
|
|
|
-
|
|
|
- if (!ObjectUtils.isEmpty(bindUsers)) {
|
|
|
- if (ObjectUtils.isEmpty(toUser)) {
|
|
|
- return Result.failure("没有配置分配用户信息!");
|
|
|
- }
|
|
|
- toUserEntity = sysUserService.queryByUserMobile(toUser);
|
|
|
- if (ObjectUtils.isEmpty(toUserEntity)) {
|
|
|
- return Result.failure("分配用户有误!");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 更新企业员工信息
|
|
|
- Long deptId = sysUserEntity.getDeptId();
|
|
|
- if(!ObjectUtils.isEmpty(deptId)){
|
|
|
- long num = sysUserService.getUserNumOfDept(deptId);
|
|
|
- if(num <= 1){
|
|
|
- return Result.failure("删除失败,公司仅剩一名员工,不可进行删除");
|
|
|
- }
|
|
|
- SysDeptEntity sysDeptEntity = sysDeptService.queryObject(deptId);
|
|
|
- if(!ObjectUtils.isEmpty(sysDeptEntity)){
|
|
|
- sysDeptEntity.setCurStaffNum(Long.valueOf(num - 1).intValue());
|
|
|
- sysDeptService.update(sysDeptEntity);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 重新绑定直播间
|
|
|
- if(!ObjectUtils.isEmpty(toUserEntity)){
|
|
|
- mySysUserBrandService.reBindUser(userId,toUserEntity);
|
|
|
- }
|
|
|
-
|
|
|
- // 删除用户信息
|
|
|
- sysUserService.deleteBatch(new Long[]{userId});
|
|
|
- return Result.success();
|
|
|
- }
|
|
|
}
|