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.
udi-spms-java/src/main/java/com/glxp/api/controller/auth/AuthAdminController.java

430 lines
19 KiB
Java

2 years ago
package com.glxp.api.controller.auth;
import com.github.pagehelper.PageInfo;
import com.glxp.api.annotation.AuthRuleAnnotation;
import com.glxp.api.common.res.BaseResponse;
import com.glxp.api.common.util.ResultVOUtils;
import com.glxp.api.entity.auth.AuthRole;
import com.glxp.api.res.PageSimpleResponse;
import com.glxp.api.res.auth.AuthAdminRoleResponse;
import com.glxp.api.service.auth.AuthAdminService;
import com.glxp.api.service.auth.AuthRoleAdminService;
import com.glxp.api.service.auth.AuthRoleService;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
/**
*
*/
@RestController
public class AuthAdminController {
@Resource
private AuthAdminService authAdminService;
@Resource
private AuthRoleService authRoleService;
@Resource
private AuthRoleAdminService authRoleAdminService;
// @Resource
// private CustomerInfoService customerInfoService;
//
// @Resource
// private WarehouseUserService warehouseUserService;
//
// @Resource
// private InvBusUserService invBusUserService;
//
// @Resource
// private InvSubWarehouseService invSubWarehouseService;
// @Resource
// private AuthPermissionRuleService authPermissionRuleService;
// @Resource
// private AuthPermissionService authPermissionService;
/**
*
*/
// @AuthRuleAnnotation("admin/auth/admin/index")
// @GetMapping("/admin/auth/admin/index")
// public BaseResponse index(@Valid FilterAuthUserRequest 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);
// }
// List<AuthAdmin> authAdminList = authAdminService.listAdminPage(authAdminQueryRequest);
// // 查询所有的权限
// List<Long> adminIds = authAdminList.stream().map(AuthAdmin::getId).collect(Collectors.toList());
// List<AuthRoleAdmin> authRoleAdminList = authRoleAdminService.listByAdminIdIn(adminIds);
//
// // 视图列表
// List<AuthAdminResponse> authAdminResponseList = authAdminList.stream().map(item -> {
// 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());
//
// PageInfo<AuthAdmin> authAdminPageInfo = new PageInfo<>(authAdminList);
// 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);
// }
//
// @AuthRuleAnnotation("admin/auth/admin/roleCustomers")
// @GetMapping("/admin/auth/admin/roleCustomers")
// public BaseResponse roleCustomers(@RequestParam(value = "page", defaultValue = "1") Integer page,
// @RequestParam(value = "limit", defaultValue = "100") Integer limit) {
// AuthAdmin authAdmin = getCustomerId();
// List<AuthRole> authRoles = authRoleAdminService.listAdminRole(authAdmin.getId());
// List<AuthRole> authRoleList = null;
// if (authRoles != null && authRoles.size() > 0) {
// int status = authRoles.get(0).getIsCustomer();
// authRoleList = authRoleService.listCustomerRoles(page, limit, status);
// } else {
// 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);
// }
@AuthRuleAnnotation("admin/auth/admin/customerRoles")
@GetMapping("/admin/auth/admin/customerRoles")
public BaseResponse customerRoles(@RequestParam(value = "page", defaultValue = "1") Integer page,
@RequestParam(value = "limit", defaultValue = "100") Integer limit) {
List<AuthRole> authRoleList = authRoleService.listCustomerRoles(page, limit, 1);
// List<AuthRole> authRoleList = authRoleService.listAuthRoles2(page, limit);
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);
}
@AuthRuleAnnotation("admin/auth/admin/customerRoles")
@GetMapping("/admin/auth/admin/customerRolesList")
public BaseResponse customerRolesList(@RequestParam(value = "page", defaultValue = "1") Integer page,
@RequestParam(value = "limit", defaultValue = "100") Integer limit) {
2 years ago
List<AuthRole> authRoleList = authRoleService.getlistCustomerRoles(page, limit, 1);
// List<AuthRole> authRoleList = authRoleService.listAuthRoles2(page, limit);
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);
}
2 years ago
/**
*
*
* @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 curUser = getCustomerId();
// if (!curUser.getCustomerId().equals("110")) {
// CustomerInfoEntity customerInfoEntity = customerInfoService.selectById(curUser.getCustomerId());
// int max = customerInfoEntity.getUserMax();
// int count = authAdminService.findCountByCustomerId(authAdminSaveRequest.getCustomerId());
// if (count >= max) {
// return ResultVOUtils.error(ResultEnum.DATA_REPEAT, "已超过最大用户数");
// }
// }
//
// // 检查是否存在相同名称的管理员
// 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()));
// }
// authAdmin.setCustomerId(curUser.getCustomerId());
// authAdmin.setLastModifyTime(new Date());
// 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());
// } else {
// List<AuthRoleAdmin> authRoleAdmins = authRoleAdminService.listByAdminId(curUser.getId());
// List<Long> roles = new ArrayList<>();
// if (!authRoleAdmins.isEmpty()) {
// for (AuthRoleAdmin authRoleAdmin : authRoleAdmins) {
// roles.add(authRoleAdmin.getRole_id());
// }
// authRoleAdminService.insertRolesAdminIdAll(roles, 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()));
// }
// authAdmin.setLastModifyTime(new Date());
// boolean b = authAdminService.updateAuthAdmin(authAdmin);
//
// if (!b) {
// return ResultVOUtils.error(ResultEnum.NOT_NETWORK);
// }
//
// // 修改角色
// if (authAdminSaveRequest.getRoles() != null && authAdminSaveRequest.getRoles().size() > 0) {
// // 先删除之前的
// authRoleAdminService.deleteByAdminId(authAdmin.getId());
// authRoleAdminService.insertRolesAdminIdAll(authAdminSaveRequest.getRoles(), authAdmin.getId());
// }
//
// return ResultVOUtils.success();
// }
//
//
// @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, "参数错误!");
// }
// InvSubWarehouseEntity invSubWarehouseEntity = invSubWarehouseService.filterGroupInvSubAndcode(authAdminSaveRequest.getLocSubInvCode());
// if (invSubWarehouseEntity != null) {
// authAdminSaveRequest.setLocInvCode(invSubWarehouseEntity.getParentId());
// }
// 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();
// }
//
// /**
// * 删除
// *
// * @return
// */
// @AuthRuleAnnotation("admin/auth/admin/delete")
// @PostMapping("/admin/auth/admin/delete")
// public BaseResponse delete(@RequestBody AuthAdminSaveRequest authAdminSaveRequest) {
//
//
// FilterInvUserRequest warehouseUser = new FilterInvUserRequest();
// warehouseUser.setUserid(authAdminSaveRequest.getId());
// List<WarehouseUserEntity> warehouseUserEntityList = warehouseUserService.filterWarehouseUsers(warehouseUser);
// if (warehouseUserEntityList.size() == 0) {
// FilterInvBusUserRequest invBusUserEntity = new FilterInvBusUserRequest();
// invBusUserEntity.setUserId(authAdminSaveRequest.getId() + "");
// List<InvBusUserEntity> invBusUserList = invBusUserService.filterInvBusUser(invBusUserEntity);
// if (invBusUserList.size() > 0) {
// return ResultVOUtils.error(999, "该用户存在关联单据信息,请先解除再删除");
// }
// } else {
// return ResultVOUtils.error(999, "该用户存在关联仓库信息,请先解除再删除");
// }
//
//
// if (authAdminSaveRequest.getId() == null) {
// return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "参数错误!");
// }
//
// boolean b = authAdminService.deleteById(authAdminSaveRequest.getId());
// if (!b) {
// return ResultVOUtils.error(ResultEnum.NOT_NETWORK);
// }
// // 先删除之前的角色
// authRoleAdminService.deleteByAdminId(authAdminSaveRequest.getId());
//
// return ResultVOUtils.success();
// }
//
//
// @GetMapping("/spms/getRouters")
// public BaseResponse getRouters() {
//
// List<Long> roleIds;
// AuthAdmin authAdmin = getCustomerId();
// if (!authAdmin.getCustomerId().equals("110")) {
// CustomerInfoEntity customerInfoEntity = customerInfoService.selectById(authAdmin.getCustomerId());
// roleIds = new ArrayList<>();
// roleIds.add(Long.parseLong(customerInfoEntity.getRoleId()));
// } else {
// List<AuthRoleAdmin> authRoleAdmins = authRoleAdminService.listByAdminId(authAdmin.getId());
// roleIds = authRoleAdmins.stream().map(AuthRoleAdmin::getRole_id).collect(Collectors.toList());
// }
//
//
// // 角色授权列表
// List<AuthPermission> authPermissions = authPermissionService.listByRoleIdIn(roleIds);
// List<Long> permissionRuleIds = authPermissions.stream().map(AuthPermission::getPermissionRuleId).collect(Collectors.toList());
//
// // 获取授权的规则
// List<AuthPermissionRule> authPermissionRules = authPermissionRuleService.listByIdIn(permissionRuleIds);
//
//
// if (authAdmin.getId() == 1) {//admin 用户获取所有菜单项
// authPermissionRules = authPermissionRuleService.listAll();
// } else {
//
// }
//
//
// List<AuthPermissionRule> menus = authPermissionRuleService.selectMenuTreeByUserId(authPermissionRules);
// List<RouterEntity> routerEntities = authPermissionRuleService.buildMenus(menus);
//
// return ResultVOUtils.success(routerEntities);
// }
//
//
// public AuthAdmin getCustomerId() {
// ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//
// if (attributes == null) {
// throw new JsonException(ResultEnum.NOT_NETWORK);
// }
// HttpServletRequest request = attributes.getRequest();
// String userId = request.getHeader("ADMIN_ID");
// AuthAdmin authAdmin = authAdminService.findById(Long.parseLong(userId));
// return authAdmin;
// }
//
// /**
// * 获取医院用户列表
// *
// * @return
// */
// @AuthRuleAnnotation("")
// @PostMapping("/admin/auth/admin/hospitalUserList")
// public BaseResponse getHospitalUserList() {
// List<AuthAdmin> hospitalUserList = authAdminService.getHospitalUserList();
// return ResultVOUtils.success(hospitalUserList);
// }
}