package com.dragoninfo.dcuc.authweb.restcontroller.auth; import com.alibaba.fastjson.JSON; import com.dragoninfo.dcuc.auth.admin.dto.ManageInfoDTO; import com.dragoninfo.dcuc.auth.admin.facade.IManageInfoFacade; import com.dragoninfo.dcuc.auth.auth.dto.StaffAssignDTO; import com.dragoninfo.dcuc.auth.auth.dto.StaffRoleOperateDTO; import com.dragoninfo.dcuc.auth.auth.entity.StaffAssignAuthInfo; import com.dragoninfo.dcuc.auth.auth.facade.IRoleAuthInfoFacade; import com.dragoninfo.dcuc.auth.auth.facade.IRoleInfoFacade; import com.dragoninfo.dcuc.auth.auth.facade.IStaffAssignAuthInfoFacade; import com.dragoninfo.dcuc.auth.auth.vo.RoleInfoVO; import com.dragoninfo.dcuc.auth.auth.vo.zerotrust.roleauthapply.ApplyRoleInVo; import com.dragoninfo.dcuc.auth.auth.vo.zerotrust.roleauthapply.RoleAuthApplySaveVo; import com.dragoninfo.dcuc.auth.sub.dto.AuthUserDTO; import com.dragoninfo.dcuc.auth.sub.enumresource.JobTypeEnum; import com.dragoninfo.dcuc.auth.sub.facade.IAuthUserInfoFacade; import com.dragoninfo.dcuc.auth.sub.facade.IUserCenterApiFacade; import com.dragoninfo.dcuc.auth.sub.vo.LabelVO; import com.dragoninfo.dcuc.authweb.restcontroller.auth.vo.StaffOperateVo; import com.dragoninfo.dcuc.authweb.restcontroller.auth.vo.StaffRoleOperateVo; import com.dragoninfo.dcuc.authweb.restcontroller.auth.vo.UserRoleAuthInfoVo; import com.dragoninfo.dcuc.duceap.facade.ICodeListResourceFacade; import com.dragoninfo.duceap.core.response.Result; import com.dragonsoft.duceap.base.entity.http.ResponseStatus; import com.dragonsoft.duceap.base.entity.metadata.CodeRecord; import com.dragonsoft.duceap.base.entity.search.SearchDTO; import com.dragonsoft.duceap.base.entity.security.SecurityUser; import com.dragonsoft.duceap.base.utils.UserContextUtils; import com.dragonsoft.duceap.commons.util.string.StringUtils; import com.dragonsoft.duceap.core.search.Searchable; import com.dragonsoft.duceap.core.search.enums.SearchOperator; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.web.bind.annotation.*; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @Api(tags = {"授权模块-角色授权管理接口"}) @RestController @RequestMapping(value = "authsvr/v2/roleauthinfo") public class RoleAuthInfoController { @Autowired private IRoleAuthInfoFacade iRoleAuthInfoFacade; @Autowired private IAuthUserInfoFacade authUserInfoFacade; @Autowired private IRoleInfoFacade roleInfoFacade; @Autowired private IStaffAssignAuthInfoFacade staffAssignAuthInfoFacade; @Autowired private IManageInfoFacade manageInfoFacade; @Autowired private ICodeListResourceFacade iCodeListResourceFacade; @Autowired private IUserCenterApiFacade userCenterApiFacade; /** * 角色视图 人员列表 * @param * @return */ @ApiOperation(value = "角色视图 人员列表") @ApiImplicitParam(name = "searchDTO", value = "角色视图 人员列表 查询条件 orgId eq 必填, roleId eq 必填") @PostMapping(value = "/roleStaffList/_search") public Result> roleStaffList(SearchDTO searchDTO) { //职位状态只查询在职、挂职、借调 Searchable searchable = getUserQuerySearchable(searchDTO); Page page = authUserInfoFacade.roleAuthRoleViewPage(searchable.toSearchDTO()); //表码翻译 Map codeMap = getUserLabel(); for (AuthUserDTO userInfo : page.getContent()) { String labelValue = this.getLabelValue(userInfo.getPoliceBusiness(), codeMap); userInfo.setPoliceBusiness(labelValue); } return Result.success(page.getTotalElements(), page.getContent()); } private Searchable getUserQuerySearchable(SearchDTO searchDTO) { Searchable searchable = Searchable.toSearchable(searchDTO); String[] jobTypes = new String[]{JobTypeEnum.ZZ.getValue(), JobTypeEnum.GZ.getValue(), JobTypeEnum.JD.getValue()}; searchable.addSearchFilter("relStatus", SearchOperator.in, jobTypes); return searchable; } private HashMap> getConvertMap(Map> listCodes) { HashMap> allConvertMap = new HashMap<>(); for (Map.Entry> entry : listCodes.entrySet()) { String codeName = entry.getKey(); ArrayList valueList = entry.getValue(); HashMap codeConvertMap = new HashMap<>(); valueList.forEach(item->codeConvertMap.put(item.getValue(),item.getLabel())); allConvertMap.put(codeName,codeConvertMap); } return allConvertMap; } /** * 人员视图 人员列表 * @param * @return */ @ApiOperation(value = "人员视图 人员列表") @ApiImplicitParam(name = "searchDTO", value = "查询条件") @PostMapping(value = "/staffUserPage/_search") public Result staffUserPage(SearchDTO searchDTO) { SecurityUser curUser = UserContextUtils.getCurrentUser(); String userId = curUser.getId(); ManageInfoDTO manageInfo = manageInfoFacade.getManageInfoByUserId(userId); //判断是否是管理员 if (null == manageInfo) { return Result.success(0L,null); } //职位状态只查询在职、挂职、借调 Searchable searchable = getUserQuerySearchable(searchDTO); Page page = authUserInfoFacade.roleAuthUserViewPage(searchable.toSearchDTO()); return Result.success(page.getTotalElements(),page.getContent()); } /** * 角色视图 角色列表 * @param * @return */ @ApiOperation(value = "角色视图 角色列表") @ApiImplicitParam(name = "searchDTO", value = "查询条件") @PostMapping(value = "roleRoleList/_search") public Result> getRoleList(SearchDTO searchDTO) { Page page = roleInfoFacade.roleAuthRoleViewPage(searchDTO); Map codeMap = getUserLabel(); for (RoleInfoVO roleInfoVO : page.getContent()) { roleInfoVO.setRoleBusiness(getLabelValue(roleInfoVO.getRoleBusiness(), codeMap)); } return Result.success(page.getTotalElements(),page.getContent()); } /** * 人员视图 应用角色列表 * @param * @return */ @ApiOperation(value = "人员视图 应用角色列表") @ApiImplicitParams({ @ApiImplicitParam(name = "roleName", value = "角色名称"), @ApiImplicitParam(name = "userId", value = "用户id",required = true), @ApiImplicitParam(name = "appName", value = "应用名称"), @ApiImplicitParam(name = "orgId", value = "机构id",required = true) }) @GetMapping(value = "/staffRoleList") public Result> staffRoleList(@RequestParam(value = "roleName",required = false) String roleName, @RequestParam("userId") String userId, @RequestParam(value = "appName",required = false) String appName, @RequestParam(value = "orgId",required = false) String orgId) { if (StringUtils.isBlank(userId)) { return Result.success(new ArrayList()); } Searchable roleSearchable = Searchable.newSearchable(); roleSearchable.addSearchFilter("userId",SearchOperator.eq,userId); if (StringUtils.isNotEmpty(roleName)) { roleSearchable.addSearchFilter("name",SearchOperator.like,roleName); } if (StringUtils.isNotEmpty(appName)) { roleSearchable.addSearchFilter("appName",SearchOperator.like,appName); } roleSearchable.addSearchFilter("orgId", SearchOperator.eq, orgId); //TODO //DTO待设计 List roleInfoVOList = roleInfoFacade.staffRoleList(roleSearchable.toSearchDTO()); Searchable staffSearchable = Searchable.newSearchable(); staffSearchable.addSearchFilter("staffId",SearchOperator.eq,userId); List staffAssignAuthInfoList = staffAssignAuthInfoFacade.findForList(staffSearchable.toSearchDTO()); Map roleMap = new HashMap(); for (StaffAssignAuthInfo assignAuthInfo : staffAssignAuthInfoList) { roleMap.put(assignAuthInfo.getRoleId(), assignAuthInfo.getActiveTime()); } Map> listCodes = iCodeListResourceFacade.listCodes("code", "DM_ROLE_LEVEL,T_MD_POLICE_TYPE"); HashMap> map = getConvertMap(listCodes); Map codeMap = getUserLabel(); for (RoleInfoVO roleInfoVO : roleInfoVOList) { if (roleMap.containsKey(roleInfoVO.getId())) { roleInfoVO.setCause(1); roleInfoVO.setActiveTime(roleMap.get(roleInfoVO.getId())); } else { roleInfoVO.setActiveTime("长期"); } String policeBusinessLabel = getLabelValue(roleInfoVO.getRoleBusiness(), codeMap); roleInfoVO.setRoleBusiness(policeBusinessLabel); String roleLevelLable = map.get("DM_ROLE_LEVEL").get(roleInfoVO.getRoleLevel()); roleInfoVO.setRoleLevel(roleLevelLable); String policeCategory = map.get("T_MD_POLICE_TYPE").get(roleInfoVO.getPoliceCategory()); roleInfoVO.setPoliceCategory(policeCategory); } return Result.success(roleInfoVOList); } private String getLabelValue(String value, Map codeMap) { String codeValue = ""; if(StringUtils.isNotEmpty(value)) { String[] codes = value.split(","); for (int i = 0; i < codes.length; i++) { String code = codes[i]; String label = codeMap.get(code); label = StringUtils.isBlank(label)? "": label; codes[i] = label; } codeValue = String.join(",",codes); } return codeValue; } private Map getUserLabel() { List all = userCenterApiFacade.findAllLabels(); return all.stream().collect(Collectors.toMap(LabelVO::getCode, LabelVO::getName)); } /** * 角色视图保存 * * @param * @return */ @ApiOperation(value = "角色视图保存") @PostMapping(value = "/role") public Result saveRole(@RequestBody StaffRoleOperateVo staffRoleOperateVo) { StaffRoleOperateDTO dto = new StaffRoleOperateDTO(); BeanUtils.copyProperties(staffRoleOperateVo, dto); //TODO //dto待设计 ResponseStatus responseStatus = staffAssignAuthInfoFacade.saveStaffRoleAuth(dto); String statusCode = responseStatus.getStatusCode(); if(ResponseStatus.FAIL_CODE.equals(statusCode)){ return Result.fail(responseStatus.getMessage()); }else { return Result.success(responseStatus.getMessage()); } } /** * 人员视图保存 * @return */ @ApiOperation(value = "人员视图保存") @PostMapping (value = "/staff") public Result saveStaff(@RequestBody StaffOperateVo staffOperateVo) { String userId = staffOperateVo.getUserId(); String orgId = staffOperateVo.getOrgId(); String saveIds = JSON.toJSONString(staffOperateVo.getSaveIds()); String deleteIds = JSON.toJSONString(staffOperateVo.getDeleteIds()); StaffAssignDTO staffAssignDTO=new StaffAssignDTO(userId, orgId, saveIds, deleteIds); ResponseStatus responseStatus = staffAssignAuthInfoFacade.saveStaff(staffAssignDTO); Result result = getResult(responseStatus); return result; } private Result getResult(ResponseStatus responseStatus) { return new Result<>(responseStatus.getStatusCode(), responseStatus.getMessage(),null,null); } /** * 获取角色视图勾选人员 * 获取人员视图勾选角色 * * @param * @return */ @ApiOperation(value = "获取角色视图勾选人员id") @ApiImplicitParams({ @ApiImplicitParam(name = "orgId", value = "机构id", required = true), @ApiImplicitParam(name = "roleId", value = "角色id") }) @GetMapping(value = "/checked") public Result getCheckedStaff(@RequestParam(value = "orgId", required = false) String orgId, @RequestParam(value = "roleId", required = false) String roleId) { List list = iRoleAuthInfoFacade.getStaff(roleId, orgId); List collect = list.stream().map(e -> { UserRoleAuthInfoVo authInfoVo = new UserRoleAuthInfoVo(); authInfoVo.setId(e.getStaffId()); authInfoVo.setActiveTime(e.getActiveTime()); return authInfoVo; }).collect(Collectors.toList()); return Result.success(collect); } @ApiOperation(value = "角色授权申请") @PostMapping(value = "role-auth-apply") public Result roleAuthApply(@RequestBody RoleAuthApplySaveVo saveVo) { ResponseStatus responseStatus = iRoleAuthInfoFacade.roleAuthApply(saveVo); return getResult(responseStatus); } @ApiOperation(value = "角色授权申请角色列表") @PostMapping(value = "apply-role-list") public Result> applyRoleList(SearchDTO searchDTO) { List roleList = iRoleAuthInfoFacade.applyRoleList(searchDTO); return Result.success(roleList); } }