完善部门与用户信息关联

newFrame
anthonywj 3 years ago
parent 9f1fb1553d
commit 4a780bd9a5

@ -10,13 +10,16 @@ import com.glxp.api.constant.BusinessType;
import com.glxp.api.controller.BaseController; import com.glxp.api.controller.BaseController;
import com.glxp.api.entity.auth.AuthAdmin; import com.glxp.api.entity.auth.AuthAdmin;
import com.glxp.api.entity.auth.AuthRoleAdmin; import com.glxp.api.entity.auth.AuthRoleAdmin;
import com.glxp.api.entity.auth.DeptUserEntity;
import com.glxp.api.entity.auth.SysRole; import com.glxp.api.entity.auth.SysRole;
import com.glxp.api.req.auth.AuthAdminQueryRequest; import com.glxp.api.req.auth.AuthAdminQueryRequest;
import com.glxp.api.req.auth.AuthAdminSaveRequest; import com.glxp.api.req.auth.AuthAdminSaveRequest;
import com.glxp.api.res.PageSimpleResponse; import com.glxp.api.res.PageSimpleResponse;
import com.glxp.api.res.auth.AuthAdminResponse; import com.glxp.api.res.auth.AuthAdminResponse;
import com.glxp.api.res.auth.DeptUserResponse;
import com.glxp.api.service.auth.AuthAdminService; import com.glxp.api.service.auth.AuthAdminService;
import com.glxp.api.service.auth.AuthRoleAdminService; import com.glxp.api.service.auth.AuthRoleAdminService;
import com.glxp.api.service.auth.DeptUserService;
import com.glxp.api.service.auth.ISysRoleService; import com.glxp.api.service.auth.ISysRoleService;
import com.glxp.api.util.PasswordUtils; import com.glxp.api.util.PasswordUtils;
import com.glxp.api.util.StreamUtils; import com.glxp.api.util.StreamUtils;
@ -68,23 +71,28 @@ public class SysUserController extends BaseController {
authAdminQueryRequest.setIds(ids); authAdminQueryRequest.setIds(ids);
} }
List<AuthAdmin> authAdminList = userService.listAdminPage(authAdminQueryRequest); List<AuthAdmin> authAdminList = userService.listAdminPage(authAdminQueryRequest);
// 查询所有的权限
List<Long> adminIds = authAdminList.stream().map(AuthAdmin::getId).collect(Collectors.toList());
//查询对应角色和部门
// 视图列表
List<AuthAdminResponse> authAdminResponseList = authAdminList.stream().map(item -> { List<AuthAdminResponse> authAdminResponseList = authAdminList.stream().map(item -> {
AuthAdminResponse authAdminResponse = new AuthAdminResponse(); AuthAdminResponse authAdminResponse = new AuthAdminResponse();
BeanUtils.copyProperties(item, authAdminResponse); BeanUtils.copyProperties(item, authAdminResponse);
// List<Long> roles = authRoleAdminList.stream()
// .filter(authRoleAdmin -> authAdminResponse.getId().equals(authRoleAdmin.getAdmin_id()))
// .map(AuthRoleAdmin::getRole_id)
// .collect(Collectors.toList());
List<Long> roles = sysRoleService.selectRoleListByUserId(authAdminResponse.getId()); List<Long> roles = sysRoleService.selectRoleListByUserId(authAdminResponse.getId());
List<DeptUserResponse> deptUserResponses = deptUserService.selectByUserId(authAdminResponse.getId());
if (CollUtil.isNotEmpty(deptUserResponses)) {
List<Long> depts = new ArrayList<>();
String deptName = "";
for (DeptUserResponse deptUserResponse : deptUserResponses) {
depts.add(deptUserResponse.getDeptId());
deptName = deptName + "," + deptUserResponse.getDeptName();
}
authAdminResponse.setDeptName(deptName.substring(1));
authAdminResponse.setDepts(depts);
}
authAdminResponse.setRoles(roles); authAdminResponse.setRoles(roles);
return authAdminResponse; return authAdminResponse;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
PageInfo<AuthAdmin> authAdminPageInfo = new PageInfo<>(authAdminList); PageInfo<AuthAdmin> authAdminPageInfo = new PageInfo<>(authAdminList);
PageSimpleResponse<AuthAdminResponse> authAdminPageSimpleResponse = new PageSimpleResponse<>(); PageSimpleResponse<AuthAdminResponse> authAdminPageSimpleResponse = new PageSimpleResponse<>();
authAdminPageSimpleResponse.setTotal(authAdminPageInfo.getTotal()); authAdminPageSimpleResponse.setTotal(authAdminPageInfo.getTotal());
@ -94,7 +102,6 @@ public class SysUserController extends BaseController {
} }
/** /**
* *
* *
@ -153,24 +160,13 @@ public class SysUserController extends BaseController {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
} }
AuthAdmin curUser = getUser(); AuthAdmin curUser = getUser();
// if (!curUser.getCustomerId().equals("110")) {
// CustomerInfoEntity customerInfoEntity = customerInfoService.selectById(curUser.getCustomerId());
// int max = customerInfoEntity.getUserMax();
// int count = userService.findCountByCustomerId(authAdminSaveRequest.getCustomerId());
// if (count >= max) {
// return ResultVOUtils.error(ResultEnum.DATA_REPEAT, "已超过最大用户数");
// }
// }
// 检查是否存在相同名称的管理员 // 检查是否存在相同名称的管理员
AuthAdmin byUserName = userService.findByUserName(authAdminSaveRequest.getUserName()); AuthAdmin byUserName = userService.findByUserName(authAdminSaveRequest.getUserName());
if (byUserName != null) { if (byUserName != null) {
return ResultVOUtils.error(ResultEnum.DATA_REPEAT, "当前管理员已存在"); return ResultVOUtils.error(ResultEnum.DATA_REPEAT, "当前管理员已存在");
} }
AuthAdmin authAdmin = new AuthAdmin(); AuthAdmin authAdmin = new AuthAdmin();
BeanUtils.copyProperties(authAdminSaveRequest, authAdmin); BeanUtils.copyProperties(authAdminSaveRequest, authAdmin);
if (authAdmin.getPassWord() != null) { if (authAdmin.getPassWord() != null) {
authAdmin.setPassWord(PasswordUtils.authAdminPwd(authAdmin.getPassWord())); authAdmin.setPassWord(PasswordUtils.authAdminPwd(authAdmin.getPassWord()));
} }
@ -187,12 +183,27 @@ public class SysUserController extends BaseController {
userService.insertUserAuth(authAdmin.getId(), authAdminSaveRequest.getRoles()); userService.insertUserAuth(authAdmin.getId(), authAdminSaveRequest.getRoles());
} }
//插入部门
if (CollUtil.isNotEmpty(authAdminSaveRequest.getDepts())) {
List<DeptUserEntity> list = new ArrayList<>();
for (int i = 0; i < authAdminSaveRequest.getDepts().size(); i++) {
DeptUserEntity deptUserEntity = new DeptUserEntity();
deptUserEntity.setUserId(authAdmin.getId());
deptUserEntity.setDeptId(authAdminSaveRequest.getDepts().get(i));
list.add(deptUserEntity);
}
deptUserService.insertBatch(list);
}
Map<String, Long> res = new HashMap<>(); Map<String, Long> res = new HashMap<>();
res.put("id", authAdmin.getId()); res.put("id", authAdmin.getId());
return ResultVOUtils.success(res); return ResultVOUtils.success(res);
} }
@Resource
DeptUserService deptUserService;
/** /**
* *
*/ */
@ -228,6 +239,18 @@ public class SysUserController extends BaseController {
userService.insertUserAuth(authAdmin.getId(), authAdminSaveRequest.getRoles()); userService.insertUserAuth(authAdmin.getId(), authAdminSaveRequest.getRoles());
} }
//修改所属部门
if (CollUtil.isNotEmpty(authAdminSaveRequest.getDepts())) {
deptUserService.deleteByUser(authAdminSaveRequest.getId());
List<DeptUserEntity> list = new ArrayList<>();
for (int i = 0; i < authAdminSaveRequest.getDepts().size(); i++) {
DeptUserEntity deptUserEntity = new DeptUserEntity();
deptUserEntity.setUserId(authAdminSaveRequest.getId());
deptUserEntity.setDeptId(authAdminSaveRequest.getDepts().get(i));
list.add(deptUserEntity);
}
deptUserService.insertBatch(list);
}
return ResultVOUtils.success(); return ResultVOUtils.success();
} }

@ -18,6 +18,9 @@ public interface DeptUserDao {
int deleteById(Integer id); int deleteById(Integer id);
boolean deleteByUser(@Param("userId") Long userId);
int deleteByList(@Param("ids") List<Integer> ids); int deleteByList(@Param("ids") List<Integer> ids);
int insertBatch(List<DeptUserEntity> list); int insertBatch(List<DeptUserEntity> list);

@ -4,7 +4,7 @@ import lombok.Data;
@Data @Data
public class DeptUserEntity { public class DeptUserEntity {
private Integer deptId; private Long deptId;
private Integer userId; private Long userId;
} }

@ -36,4 +36,6 @@ public class AuthAdminSaveRequest {
private String locInvCode; private String locInvCode;
private String locSubInvCode; private String locSubInvCode;
private String dept; private String dept;
private List<Long> depts;
} }

@ -5,6 +5,6 @@ import lombok.Data;
@Data @Data
public class DeptUserReqeust extends ListPageRequest { public class DeptUserReqeust extends ListPageRequest {
private Integer deptId; private Long deptId;
private Integer userId; private Long userId;
} }

@ -40,4 +40,6 @@ public class AuthAdminResponse {
private String dept; private String dept;
private String deptName; private String deptName;
private List<Long> depts;
} }

@ -5,8 +5,9 @@ import lombok.Data;
@Data @Data
public class DeptUserResponse { public class DeptUserResponse {
private Integer deptId; private Long deptId;
private Integer userId; private Long userId;
private String userName; private String userName;
private String employeeName; private String employeeName;
private String deptName;
} }

@ -3,6 +3,7 @@ package com.glxp.api.service.auth;
import com.glxp.api.entity.auth.DeptUserEntity; import com.glxp.api.entity.auth.DeptUserEntity;
import com.glxp.api.req.auth.DeptUserReqeust; import com.glxp.api.req.auth.DeptUserReqeust;
import com.glxp.api.res.auth.DeptUserResponse; import com.glxp.api.res.auth.DeptUserResponse;
import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
@ -11,8 +12,12 @@ public interface DeptUserService {
List<DeptUserEntity> selectDeptUser(DeptUserReqeust deptUserReqeust); List<DeptUserEntity> selectDeptUser(DeptUserReqeust deptUserReqeust);
List<DeptUserResponse> selectByUserId(Long userId);
List<DeptUserResponse> selectJoinDeptUser(DeptUserReqeust deptUserReqeust); List<DeptUserResponse> selectJoinDeptUser(DeptUserReqeust deptUserReqeust);
boolean deleteByUser(Long userId);
int deleteById(Integer id); int deleteById(Integer id);
int deleteByList(List<Integer> ids); int deleteByList(List<Integer> ids);

@ -28,6 +28,13 @@ public class DeptUserServiceImpl implements DeptUserService {
return deptUserDao.selectDeptUser(deptUserReqeust); return deptUserDao.selectDeptUser(deptUserReqeust);
} }
@Override
public List<DeptUserResponse> selectByUserId(Long userId) {
DeptUserReqeust deptUserReqeust = new DeptUserReqeust();
deptUserReqeust.setUserId(userId);
return deptUserDao.selectJoinDeptUser(deptUserReqeust);
}
@Override @Override
public List<DeptUserResponse> selectJoinDeptUser(DeptUserReqeust deptUserReqeust) { public List<DeptUserResponse> selectJoinDeptUser(DeptUserReqeust deptUserReqeust) {
if (deptUserReqeust.getPage() != null) { if (deptUserReqeust.getPage() != null) {
@ -37,6 +44,11 @@ public class DeptUserServiceImpl implements DeptUserService {
return deptUserDao.selectJoinDeptUser(deptUserReqeust); return deptUserDao.selectJoinDeptUser(deptUserReqeust);
} }
@Override
public boolean deleteByUser(Long userId) {
return deptUserDao.deleteByUser(userId);
}
@Override @Override
public int deleteById(Integer id) { public int deleteById(Integer id) {
return deptUserDao.deleteById(id); return deptUserDao.deleteById(id);

@ -21,10 +21,11 @@
<select id="selectJoinDeptUser" parameterType="com.glxp.api.req.auth.DeptUserReqeust" <select id="selectJoinDeptUser" parameterType="com.glxp.api.req.auth.DeptUserReqeust"
resultType="com.glxp.api.entity.auth.DeptUserEntity">> resultType="com.glxp.api.res.auth.DeptUserResponse">
SELECT auth_dept_user.*,auth_user.userName,auth_user.employeeName SELECT auth_dept_user.*,auth_user.userName,auth_user.employeeName,inv_warehouse.`name` deptName
FROM auth_dept_user INNER JOIN auth_user FROM auth_dept_user INNER JOIN auth_user
on auth_dept_user.userId = auth_user.id on auth_dept_user.userId = auth_user.id
INNER JOIN inv_warehouse on auth_dept_user.deptId = inv_warehouse.id
<where> <where>
<if test="deptId != null "> <if test="deptId != null ">
and deptId = #{deptId} and deptId = #{deptId}
@ -42,6 +43,12 @@
where deptId = #{id} where deptId = #{id}
</delete> </delete>
<delete id="deleteByUser" parameterType="java.lang.Long">
delete
from auth_dept_user
where userId = #{userId}
</delete>
<delete id="deleteByList" parameterType="java.util.List" <delete id="deleteByList" parameterType="java.util.List"
> >
delete delete

Loading…
Cancel
Save