You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
328 lines
13 KiB
Java
328 lines
13 KiB
Java
3 years ago
|
package com.glxp.api.controller.auth;
|
||
4 years ago
|
|
||
3 years ago
|
import cn.hutool.core.util.StrUtil;
|
||
4 years ago
|
import com.github.pagehelper.PageInfo;
|
||
3 years ago
|
import com.glxp.api.annotation.AuthRuleAnnotation;
|
||
|
import com.glxp.api.annotation.Log;
|
||
|
import com.glxp.api.constant.BusinessType;
|
||
|
import com.glxp.api.entity.auth.AuthAdmin;
|
||
|
import com.glxp.api.entity.auth.AuthRole;
|
||
|
import com.glxp.api.entity.auth.AuthRoleAdmin;
|
||
|
import com.glxp.api.entity.auth.DeptEntity;
|
||
|
import com.glxp.api.entity.inout.WarehouseUserEntity;
|
||
|
import com.glxp.api.entity.inventory.InvSubWarehouseEntity;
|
||
|
import com.glxp.api.req.auth.AuthAdminQueryRequest;
|
||
|
import com.glxp.api.req.auth.AuthAdminSaveRequest;
|
||
|
import com.glxp.api.req.auth.FilterNoSelectUserRequest;
|
||
|
import com.glxp.api.req.inventory.FilterInvLinkDataRequest;
|
||
|
import com.glxp.api.res.PageSimpleResponse;
|
||
|
import com.glxp.api.res.auth.AuthAdminResponse;
|
||
|
import com.glxp.api.res.auth.AuthAdminRoleResponse;
|
||
|
import com.glxp.api.service.inout.WarehouseUserService;
|
||
|
import com.glxp.api.service.inventory.InvSubWarehouseService;
|
||
|
import com.glxp.api.util.GennerOrderUtils;
|
||
|
import com.glxp.api.util.PasswordUtils;
|
||
3 years ago
|
import com.glxp.api.common.enums.ResultEnum;
|
||
|
import com.glxp.api.common.res.BaseResponse;
|
||
|
import com.glxp.api.common.util.ResultVOUtils;
|
||
3 years ago
|
import com.glxp.api.service.auth.*;
|
||
4 years ago
|
import org.springframework.beans.BeanUtils;
|
||
|
import org.springframework.validation.BindingResult;
|
||
|
import org.springframework.web.bind.annotation.*;
|
||
|
|
||
|
import javax.annotation.Resource;
|
||
|
import javax.validation.Valid;
|
||
|
import java.util.*;
|
||
|
import java.util.stream.Collectors;
|
||
|
|
||
|
/**
|
||
|
* 管理员相关
|
||
|
*/
|
||
|
@RestController
|
||
|
public class AuthAdminController {
|
||
|
|
||
|
@Resource
|
||
|
private AuthAdminService authAdminService;
|
||
|
|
||
|
@Resource
|
||
|
private AuthRoleService authRoleService;
|
||
|
|
||
|
@Resource
|
||
|
private AuthRoleAdminService authRoleAdminService;
|
||
3 years ago
|
@Resource
|
||
|
GennerOrderUtils gennerOrderUtils;
|
||
3 years ago
|
@Resource
|
||
|
private InvSubWarehouseService invSubWarehouseService;
|
||
3 years ago
|
@Resource
|
||
|
private DeptService deptService;
|
||
3 years ago
|
@Resource
|
||
|
private CustomerService customerService;
|
||
4 years ago
|
|
||
3 years ago
|
@Resource
|
||
|
private WarehouseUserService warehouseUserService;
|
||
|
|
||
|
|
||
4 years ago
|
/**
|
||
|
* 获取管理员列表
|
||
|
*/
|
||
|
@AuthRuleAnnotation("admin/auth/admin/index")
|
||
|
@GetMapping("/admin/auth/admin/index")
|
||
|
public BaseResponse index(@Valid AuthAdminQueryRequest authAdminQueryRequest,
|
||
|
BindingResult bindingResult) {
|
||
|
|
||
|
if (bindingResult.hasErrors()) {
|
||
|
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
|
||
|
}
|
||
|
|
||
|
if (authAdminQueryRequest.getRoleId() != null) {
|
||
|
List<AuthRoleAdmin> authRoleAdmins = authRoleAdminService.listByRoleId(authAdminQueryRequest.getRoleId());
|
||
|
List<Long> ids = new ArrayList<>();
|
||
|
if (authRoleAdmins != null && !authRoleAdmins.isEmpty()) {
|
||
|
ids = authRoleAdmins.stream().map(AuthRoleAdmin::getAdmin_id).collect(Collectors.toList());
|
||
|
}
|
||
|
authAdminQueryRequest.setIds(ids);
|
||
|
}
|
||
3 years ago
|
authAdminQueryRequest.setNeUserName("admin");
|
||
4 years ago
|
List<AuthAdmin> authAdmins = authAdminService.listAdminPage(authAdminQueryRequest);
|
||
|
// 查询所有的权限
|
||
3 years ago
|
List<Long> adminIds = authAdmins.stream().map(AuthAdmin::getId).collect(Collectors.toList());
|
||
4 years ago
|
List<AuthRoleAdmin> authRoleAdminList = authRoleAdminService.listByAdminIdIn(adminIds);
|
||
|
|
||
|
// 视图列表
|
||
3 years ago
|
List<AuthAdminResponse> authAdminResponseList = authAdmins.stream().map(item -> {
|
||
4 years ago
|
AuthAdminResponse authAdminResponse = new 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());
|
||
|
authAdminResponse.setRoles(roles);
|
||
|
return authAdminResponse;
|
||
|
}).collect(Collectors.toList());
|
||
|
|
||
3 years ago
|
PageInfo<AuthAdmin> authAdminPageInfo = new PageInfo<>(authAdmins);
|
||
4 years ago
|
PageSimpleResponse<AuthAdminResponse> authAdminPageSimpleResponse = new PageSimpleResponse<>();
|
||
|
authAdminPageSimpleResponse.setTotal(authAdminPageInfo.getTotal());
|
||
|
authAdminPageSimpleResponse.setList(authAdminResponseList);
|
||
|
return ResultVOUtils.success(authAdminPageSimpleResponse);
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* 获取角色列表
|
||
|
*/
|
||
|
@AuthRuleAnnotation("admin/auth/admin/roleList")
|
||
|
@GetMapping("/admin/auth/admin/roleList")
|
||
|
public BaseResponse roleList(@RequestParam(value = "page", defaultValue = "1") Integer page,
|
||
|
@RequestParam(value = "limit", defaultValue = "100") Integer limit) {
|
||
|
|
||
|
List<AuthRole> authRoleList = authRoleService.listAuthAdminRolePage(page, limit, null);
|
||
|
PageInfo<AuthRole> pageInfo = new PageInfo<>(authRoleList);
|
||
|
PageSimpleResponse<AuthAdminRoleResponse> pageSimpleResponse = new PageSimpleResponse<>();
|
||
|
pageSimpleResponse.setTotal(pageInfo.getTotal());
|
||
|
List<AuthAdminRoleResponse> authAdminRoleResponses = authRoleList.stream().map(e -> {
|
||
|
AuthAdminRoleResponse authAdminRoleResponse = new AuthAdminRoleResponse();
|
||
|
BeanUtils.copyProperties(e, authAdminRoleResponse);
|
||
|
return authAdminRoleResponse;
|
||
|
}).collect(Collectors.toList());
|
||
|
pageSimpleResponse.setList(authAdminRoleResponses);
|
||
|
|
||
|
return ResultVOUtils.success(pageSimpleResponse);
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* 新增
|
||
|
*
|
||
|
* @return
|
||
|
*/
|
||
|
@AuthRuleAnnotation("admin/auth/admin/save")
|
||
|
@PostMapping("/admin/auth/admin/save")
|
||
|
public BaseResponse save(@RequestBody @Valid AuthAdminSaveRequest authAdminSaveRequest,
|
||
|
BindingResult bindingResult) {
|
||
|
|
||
|
if (bindingResult.hasErrors()) {
|
||
|
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
|
||
|
}
|
||
|
|
||
|
// 检查是否存在相同名称的管理员
|
||
|
AuthAdmin byUserName = authAdminService.findByUserName(authAdminSaveRequest.getUserName());
|
||
|
if (byUserName != null) {
|
||
|
return ResultVOUtils.error(ResultEnum.DATA_REPEAT, "当前管理员已存在");
|
||
|
}
|
||
|
|
||
|
AuthAdmin authAdmin = new AuthAdmin();
|
||
|
BeanUtils.copyProperties(authAdminSaveRequest, authAdmin);
|
||
|
|
||
|
if (authAdmin.getPassWord() != null) {
|
||
|
authAdmin.setPassWord(PasswordUtils.authAdminPwd(authAdmin.getPassWord()));
|
||
|
}
|
||
3 years ago
|
|
||
|
//设置部门信息
|
||
|
if (StrUtil.isNotBlank(authAdminSaveRequest.getDept())) {
|
||
|
authAdmin.setDept(authAdminSaveRequest.getDept());
|
||
|
DeptEntity deptEntity = deptService.findByDeptCode(authAdminSaveRequest.getDept());
|
||
|
authAdmin.setDeptName(deptEntity.getName());
|
||
|
}
|
||
|
|
||
3 years ago
|
authAdmin.setLastModifyTime(new Date());
|
||
3 years ago
|
authAdmin.setCustomerId(customerService.getUserBean().getCustomerId());
|
||
3 years ago
|
|
||
3 years ago
|
authAdmin.setId(gennerOrderUtils.getRelId());
|
||
4 years ago
|
boolean b = authAdminService.insertAuthAdmin(authAdmin);
|
||
|
authAdmin = authAdminService.findByUserName(authAdmin.getUserName());
|
||
|
if (!b) {
|
||
|
return ResultVOUtils.error(ResultEnum.NOT_NETWORK);
|
||
|
}
|
||
|
|
||
|
// 插入角色
|
||
|
if (authAdminSaveRequest.getRoles() != null) {
|
||
|
authRoleAdminService.insertRolesAdminIdAll(authAdminSaveRequest.getRoles(), authAdmin.getId());
|
||
|
}
|
||
|
|
||
|
Map<String, Long> res = new HashMap<>();
|
||
|
res.put("id", authAdmin.getId());
|
||
|
return ResultVOUtils.success(res);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 修改
|
||
|
*
|
||
|
* @return
|
||
|
*/
|
||
|
@AuthRuleAnnotation("admin/auth/admin/edit")
|
||
|
@PostMapping("/admin/auth/admin/edit")
|
||
|
public BaseResponse edit(@RequestBody @Valid AuthAdminSaveRequest authAdminSaveRequest,
|
||
|
BindingResult bindingResult) {
|
||
|
|
||
|
if (bindingResult.hasErrors()) {
|
||
|
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
|
||
|
}
|
||
|
|
||
|
if (authAdminSaveRequest.getId() == null) {
|
||
|
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "参数错误!");
|
||
|
}
|
||
|
|
||
|
// 检查是否存在除了当前管理员的其它名称的管理员
|
||
|
AuthAdmin byUserName = authAdminService.findByUserName(authAdminSaveRequest.getUserName());
|
||
|
if (byUserName != null && !authAdminSaveRequest.getId().equals(byUserName.getId())) {
|
||
|
return ResultVOUtils.error(ResultEnum.DATA_REPEAT, "当前管理员已存在");
|
||
|
}
|
||
|
|
||
|
AuthAdmin authAdmin = new AuthAdmin();
|
||
|
BeanUtils.copyProperties(authAdminSaveRequest, authAdmin);
|
||
|
if (authAdmin.getPassWord() != null) {
|
||
|
authAdmin.setPassWord(PasswordUtils.authAdminPwd(authAdmin.getPassWord()));
|
||
|
}
|
||
3 years ago
|
authAdmin.setLastModifyTime(new Date());
|
||
3 years ago
|
|
||
|
if (StrUtil.isNotBlank(authAdminSaveRequest.getDept())) {
|
||
|
authAdmin.setDept(authAdmin.getDept());
|
||
|
DeptEntity deptEntity = deptService.findByDeptCode(authAdmin.getDept());
|
||
|
authAdmin.setDeptName(deptEntity.getName());
|
||
|
}
|
||
|
|
||
4 years ago
|
boolean b = authAdminService.updateAuthAdmin(authAdmin);
|
||
|
|
||
|
if (!b) {
|
||
|
return ResultVOUtils.error(ResultEnum.NOT_NETWORK);
|
||
|
}
|
||
|
|
||
|
// 修改角色
|
||
|
if (authAdminSaveRequest.getRoles() != null) {
|
||
|
// 先删除之前的
|
||
|
authRoleAdminService.deleteByAdminId(authAdmin.getId());
|
||
|
authRoleAdminService.insertRolesAdminIdAll(authAdminSaveRequest.getRoles(), authAdmin.getId());
|
||
|
}
|
||
|
|
||
|
return ResultVOUtils.success();
|
||
3 years ago
|
}
|
||
|
|
||
|
@AuthRuleAnnotation("admin/auth/admin/updateInv")
|
||
|
@PostMapping("/admin/auth/admin/updateInv")
|
||
|
public BaseResponse updateInv(@RequestBody @Valid AuthAdminSaveRequest authAdminSaveRequest,
|
||
|
BindingResult bindingResult) {
|
||
|
|
||
|
if (bindingResult.hasErrors()) {
|
||
|
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
|
||
|
}
|
||
|
|
||
|
if (authAdminSaveRequest.getId() == null) {
|
||
|
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "参数错误!");
|
||
|
}
|
||
3 years ago
|
InvSubWarehouseEntity invSubWarehouseEntity = invSubWarehouseService.filterGroupInvSubAndcode(authAdminSaveRequest.getLocSubInvCode());
|
||
|
if (invSubWarehouseEntity != null) {
|
||
3 years ago
|
authAdminSaveRequest.setLocInvCode(invSubWarehouseEntity.getParentId());
|
||
|
}
|
||
3 years ago
|
AuthAdmin authAdmin = new AuthAdmin();
|
||
|
BeanUtils.copyProperties(authAdminSaveRequest, authAdmin);
|
||
|
authAdmin.setLastModifyTime(new Date());
|
||
|
boolean b = authAdminService.updateAuthAdmin(authAdmin);
|
||
|
if (!b) {
|
||
|
return ResultVOUtils.error(ResultEnum.NOT_NETWORK);
|
||
|
}
|
||
|
return ResultVOUtils.success();
|
||
4 years ago
|
}
|
||
|
|
||
|
/**
|
||
|
* 删除
|
||
|
*
|
||
|
* @return
|
||
|
*/
|
||
3 years ago
|
@Log(title = "用户管理", businessType = BusinessType.DELETE)
|
||
4 years ago
|
@AuthRuleAnnotation("admin/auth/admin/delete")
|
||
|
@PostMapping("/admin/auth/admin/delete")
|
||
|
public BaseResponse delete(@RequestBody AuthAdminSaveRequest authAdminSaveRequest) {
|
||
|
|
||
|
if (authAdminSaveRequest.getId() == null) {
|
||
|
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "参数错误!");
|
||
|
}
|
||
3 years ago
|
// 先得到要删除角色的 getLocSubInvCode
|
||
|
AuthAdmin byId = authAdminService.findById(authAdminSaveRequest.getId());
|
||
4 years ago
|
boolean b = authAdminService.deleteById(authAdminSaveRequest.getId());
|
||
|
if (!b) {
|
||
|
return ResultVOUtils.error(ResultEnum.NOT_NETWORK);
|
||
|
}
|
||
3 years ago
|
|
||
4 years ago
|
// 先删除之前的角色
|
||
|
authRoleAdminService.deleteByAdminId(authAdminSaveRequest.getId());
|
||
3 years ago
|
warehouseUserService.deleteByCodeAndId(authAdminSaveRequest.getId(), byId.getLocSubInvCode());
|
||
4 years ago
|
return ResultVOUtils.success();
|
||
|
}
|
||
|
|
||
3 years ago
|
/**
|
||
|
* 获取医院用户列表
|
||
|
*
|
||
|
* @return
|
||
|
*/
|
||
|
@AuthRuleAnnotation("")
|
||
3 years ago
|
@GetMapping("/admin/auth/admin/selectNotSelectUser")
|
||
|
public BaseResponse selectNotSelectUser(FilterInvLinkDataRequest filterInvLinkDataRequest) {
|
||
|
List<WarehouseUserEntity> warehouseUserEntities = warehouseUserService.getWarehouseUserList(filterInvLinkDataRequest);
|
||
|
List<Long> userIds = new ArrayList<>();
|
||
|
warehouseUserEntities.forEach(user -> {
|
||
|
userIds.add(user.getUserid());
|
||
|
});
|
||
|
FilterNoSelectUserRequest filterNoSelectUserRequest = new FilterNoSelectUserRequest();
|
||
|
BeanUtils.copyProperties(filterInvLinkDataRequest, filterNoSelectUserRequest);
|
||
|
filterNoSelectUserRequest.setUserIds(userIds);
|
||
|
List<AuthAdmin> hospitalUserList = authAdminService.selectNotSelectUser(filterNoSelectUserRequest);
|
||
|
PageInfo<AuthAdmin> authAdminPageInfo = new PageInfo<>(hospitalUserList);
|
||
|
PageSimpleResponse<AuthAdmin> authAdminPageSimpleResponse = new PageSimpleResponse<>();
|
||
|
authAdminPageSimpleResponse.setTotal(authAdminPageInfo.getTotal());
|
||
|
authAdminPageSimpleResponse.setList(hospitalUserList);
|
||
|
return ResultVOUtils.success(authAdminPageSimpleResponse);
|
||
|
|
||
|
}
|
||
|
|
||
|
//仓库未关联用户列表
|
||
|
@AuthRuleAnnotation("")
|
||
3 years ago
|
@GetMapping("/admin/auth/admin/hospitalUserList")
|
||
3 years ago
|
public BaseResponse getHospitalUserList() {
|
||
|
List<AuthAdmin> hospitalUserList = authAdminService.getHospitalUserList();
|
||
3 years ago
|
return ResultVOUtils.success(hospitalUserList);
|
||
3 years ago
|
}
|
||
|
|
||
4 years ago
|
}
|