package com.dragoninfo.dcuc.authweb.restcontroller.auth; import com.alibaba.fastjson.JSON; import com.dragoninfo.dcuc.auth.auth.dto.RoleAuthDto; import com.dragoninfo.dcuc.auth.auth.dto.StaffAssignDTO; import com.dragoninfo.dcuc.auth.auth.entity.RoleInfo; 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.RoleAuthParamVo; import com.dragoninfo.dcuc.auth.auth.vo.RoleInfoVO; import com.dragoninfo.dcuc.authweb.business.MtAuthBusiness; import com.dragoninfo.dcuc.authweb.common.SysConstants; import com.dragoninfo.dcuc.authweb.restcontroller.auth.vo.RoleAuthUserVo; import com.dragoninfo.dcuc.authweb.restcontroller.auth.vo.StaffAssignAuthInfoVo; import com.dragoninfo.dcuc.authweb.restcontroller.auth.vo.StaffOperateVo; import com.dragoninfo.dcuc.authweb.restcontroller.auth.vo.StaffRoleOperateVo; import com.dragoninfo.dcuc.duceap.facade.ICodeListResourceFacade; import com.dragoninfo.dcuc.duceap.facade.IDuceapCodeFacade; import com.dragoninfo.dcuc.org.entity.OrgInfo; import com.dragoninfo.dcuc.org.facade.IOrgInfoFacade; import com.dragoninfo.dcuc.user.user.entity.UserInfo; import com.dragoninfo.dcuc.user.user.entity.UserInfoView; import com.dragoninfo.dcuc.user.user.enumresources.JobTypeEnum; import com.dragoninfo.dcuc.user.user.enumresources.YesNotEnum; import com.dragoninfo.dcuc.user.user.facade.IUserInfoFacade; import com.dragoninfo.duceap.core.enums.RoleLevelEnum; 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.commons.util.string.StringUtils; import com.dragonsoft.duceap.core.context.ContextUtils; import com.dragonsoft.duceap.core.entity.page.PageImpl; import com.dragonsoft.duceap.core.search.Searchable; import com.dragonsoft.duceap.core.search.enums.SearchOperator; import com.dragonsoft.duceap.core.search.filter.Condition; import com.dragonsoft.duceap.web.annotation.Permission; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.hibernate.validator.internal.IgnoreForbiddenApisErrors; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; import java.util.*; @Api(tags = {"授权模块-角色授权管理接口"}) @RestController @RequestMapping(value = "authsvr/v2/roleauthinfo") public class RoleAuthInfoController { @Autowired private IRoleAuthInfoFacade iRoleAuthInfoFacade; @Autowired private IUserInfoFacade iUserInfoFacade; @Autowired private IOrgInfoFacade iOrgInfoFacade; @Autowired private IRoleInfoFacade roleInfoFacade; @Autowired private IStaffAssignAuthInfoFacade staffAssignAuthInfoFacade; @Autowired private MtAuthBusiness mtAuthBusiness; @Autowired private ICodeListResourceFacade iCodeListResourceFacade; @Autowired private IDuceapCodeFacade iDuceapCodeFacade; /** * 角色视图 人员列表 * @param * @return */ @ApiOperation(value = "角色视图 人员列表") @ApiImplicitParams({@ApiImplicitParam(name = "RoleAuthUserVo", value = "角色视图-人员列表参数") }) @PostMapping(value = "/roleStaffList/_search") public Result> roleStaffList( RoleAuthUserVo vo) { if (StringUtils.isEmpty(vo.getOrgId())) { return Result.success(new ArrayList()); } OrgInfo orgInfo = iOrgInfoFacade.detail(vo.getOrgId()); //找到角色id RoleInfo roleInfo = roleInfoFacade.get(vo.getRoleId()); String orgLevel = null; if (StringUtils.isNotEmpty(orgInfo.getOrgLevel())) { orgLevel = orgInfo.getOrgLevel(); } if (roleInfo.getRoleLevel() != null && !RoleLevelEnum.TY.getValue().equals(roleInfo.getRoleLevel()) && !roleInfo.getRoleLevel().equals(orgLevel)) { return Result.success(new ArrayList()); } List list = new ArrayList(); Searchable searchable = Searchable.newSearchable(); searchable.addSearchFilter("deleted", SearchOperator.eq,YesNotEnum.NO.getValue()); searchable.addSearchFilter("name", SearchOperator.ne,iUserInfoFacade.getRootUser()); searchable.addSearchFilter("org_id", SearchOperator.eq,vo.getOrgId()); List jobType = new ArrayList(); jobType.add(JobTypeEnum.LZ.getValue()); jobType.add(JobTypeEnum.SW.getValue()); jobType.add(JobTypeEnum.TX.getValue()); searchable.addSearchFilter("jobType", SearchOperator.notIn, jobType); if(StringUtils.isNotEmpty(vo.getName())){ searchable.addSearchFilter("name", SearchOperator.like,vo.getName()); } //当角色有警种时候过滤警种 if (StringUtils.isNotEmpty(roleInfo.getPoliceCategory())) { searchable.addSearchFilter("police_category", SearchOperator.eq, roleInfo.getPoliceCategory()); } //当有业务域时候 if (StringUtils.isNotEmpty(roleInfo.getRoleBusiness())) { for (String business : roleInfo.getRoleBusiness().split(",")) { searchable.addSearchFilter("police_business", SearchOperator.like,business); list.addAll(iUserInfoFacade.roleInfoList(searchable.toSearchDTO())); } //去重 HashSet userInfoViewSet = new HashSet(list); list.clear(); list.addAll(userInfoViewSet); } else { list.addAll(iUserInfoFacade.expList(searchable.toSearchDTO())); } Map> listCodes = iCodeListResourceFacade.listCodes("code", "DM_POLICE_BUSINESS,T_MD_ORG_LEVEL,DM_USER_TYPE"); HashMap> map = getConvertMap(listCodes); //标码翻译 for (UserInfoView userInfo : list) { if (StringUtils.isNotEmpty(userInfo.getPoliceBusiness())){ String[] policeBusinessOld = userInfo.getPoliceBusiness().split(","); String policeBusinesssNew=""; for (String businesss : policeBusinessOld) { policeBusinesssNew+= StringUtils.isEmpty(policeBusinesssNew)?map.get("DM_POLICE_BUSINESS").get(businesss):","+map.get("DM_POLICE_BUSINESS").get(businesss); } userInfo.setPoliceBusiness(policeBusinesssNew); } // String policeBusinessLable = map.get("DM_POLICE_BUSINESS").get(userInfo.getPoliceBusiness()); String orgLevelLable = map.get("T_MD_ORG_LEVEL").get(userInfo.getOrgLevel()); userInfo.setOrgLevel(orgLevelLable); String userTypeLable = map.get("DM_USER_TYPE").get(userInfo.getUserType()); userInfo.setUserType(userTypeLable); } return Result.success(list); } 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 = "查询条件(orgId必须)",required = true) @PostMapping(value = "/staffRolePage/_search") public Result> staffRolePage(SearchDTO searchDTO) { SecurityUser curUser = (SecurityUser) ContextUtils.getUserInfo(); Searchable searchable = Searchable.toSearchable(searchDTO); searchable.addSearchFilter("deleted",SearchOperator.eq,YesNotEnum.NO.getValue()); searchable.addSearchFilter("name",SearchOperator.ne,iUserInfoFacade.getRootUser()); Page page = iUserInfoFacade.userList(searchDTO); if (!iUserInfoFacade.getRootUser().equals(curUser.getName())) { String mtIds = mtAuthBusiness.getMtAuth(curUser.getId(), SysConstants.MT_APP); if (StringUtils.isEmpty(mtIds)) { return Result.success(0L,null); } } return Result.success(page.getTotalElements(),page.getContent()); } /** * 人员视图 人员列表 * @param * @return */ @ApiOperation(value = "人员视图 人员列表") @ApiImplicitParam(name = "searchDTO", value = "查询条件(orgId必须)",required = true) @PostMapping(value = "/staffUserPage/_search") public Result> staffUserPage(SearchDTO searchDTO) { SecurityUser curUser = (SecurityUser) ContextUtils.getUserInfo(); Searchable searchable = Searchable.toSearchable(searchDTO); searchable.addSearchFilter("deleted",SearchOperator.eq,YesNotEnum.NO.getValue()); searchable.addSearchFilter("name",SearchOperator.ne,iUserInfoFacade.getRootUser()); // Set jobType = new HashSet(); // jobType.add(JobTypeEnum.LZ.getValue()); // jobType.add(JobTypeEnum.SW.getValue()); // jobType.add(JobTypeEnum.TX.getValue()); // jobType.add(JobTypeEnum.FP.getValue()); // searchable.addSearchFilter("jobType",SearchOperator.notIn,jobType); Page page = iUserInfoFacade.userList(searchable.toSearchDTO()); if (!iUserInfoFacade.getRootUser().equals(curUser.getName())) { String mtIds = mtAuthBusiness.getMtAuth(curUser.getId(), SysConstants.MT_APP); if (StringUtils.isEmpty(mtIds)) { return Result.success(0L,null); } } return Result.success(page.getTotalElements(),page.getContent()); } /** * 人员视图-角色已勾选 * @param userId 用户Id * @return */ @ApiOperation(value = "人员视图-角色已勾选") @ApiImplicitParam(name = "userId", value = "用户id(orgId必须)",required = true) @GetMapping(value = "/roleChecked") public Result> getRoleChecked(@RequestParam(value = "userId", required = false) String userId) { if (StringUtils.isEmpty(userId)) { return Result.success(new ArrayList()); } Searchable searchable = Searchable.newSearchable(); searchable.addSearchFilter("staffId",SearchOperator.eq,userId); List staffAssignAuthInfoList = staffAssignAuthInfoFacade.findForList(searchable.toSearchDTO()); List vos = new ArrayList<>(); for (StaffAssignAuthInfo source : staffAssignAuthInfoList) { StaffAssignAuthInfoVo vo = new StaffAssignAuthInfoVo(); BeanUtils.copyProperties(source,vo); vos.add(vo); } return Result.success(vos); } /** * 分页查询机构拥有的应用角色配额情况 * @param * @return */ @ApiOperation(value = "分页查询机构拥有的应用角色配额情况") @ApiImplicitParam(name = "searchDTO", value = "查询条件(appId必须)",required = true) @PostMapping(value = "roleRoleList/_search") public Result> getRoleList(SearchDTO searchDTO) { String appId = null; String orgId = null; Page page = new PageImpl(); Searchable searchable = Searchable.toSearchable(searchDTO); Condition appIdCondition = searchable.getSearchFilterByKey("appId_eq"); searchable.removeSearchFilter("appId_eq"); Condition orgIdCondition = searchable.getSearchFilterByKey("orgId_eq"); if(null == appIdCondition || StringUtils.isBlank((String) appIdCondition.getValue())){ return Result.success(page.getTotalElements(),page.getContent()); } if(orgIdCondition!=null && StringUtils.isNotBlank((String) orgIdCondition.getValue())){ orgId = (String) orgIdCondition.getValue(); } appId = (String) appIdCondition.getValue(); SecurityUser curUser = (SecurityUser) ContextUtils.getUserInfo(); if (!iUserInfoFacade.getRootUser().equals(curUser.getName())) { String mtIds = mtAuthBusiness.getMtAuth(curUser.getId(), SysConstants.MT_APP); if (StringUtils.isEmpty(mtIds)) { return Result.success(0L,null); } } RoleAuthParamVo vo=new RoleAuthParamVo(); vo.setAppId(appId); vo.setOrgId(orgId); vo.setSearchDTO(searchable.toSearchDTO()); page = roleInfoFacade.getOrgRoleQuota(vo); for (RoleInfoVO roleInfoVO : page.getContent()) { roleInfoVO.setRoleBusiness(getLavleValue(roleInfoVO.getRoleBusiness())); } 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 = "应用名称") }) @GetMapping(value = "/staffRoleList") public Result> staffRoleList(@RequestParam(value = "roleName",required = false) String roleName,@RequestParam("userId") String userId, @RequestParam(value = "appName",required = false) String appName) { 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); } //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); for (RoleInfoVO roleInfoVO : roleInfoVOList) { if (roleMap.containsKey(roleInfoVO.getId())) { roleInfoVO.setCause(1); roleInfoVO.setActiveTime(roleMap.get(roleInfoVO.getId())); } else { roleInfoVO.setActiveTime("长期"); } String policeBusinessLable = getLavleValue(roleInfoVO.getRoleBusiness()); roleInfoVO.setRoleBusiness(policeBusinessLable); 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 getLavleValue(String value) { HashMap codeMap = getCodeVLMap("T_USER_LABEL"); String codeValue = ""; if(StringUtils.isNotEmpty(value)){ String[] codeLable = value.split(","); for (String s : codeLable) { codeValue += codeMap.get(s)+","; } } return codeValue; } private HashMap getCodeVLMap(String name) { HashMap map = new HashMap(); List> codeResource = iDuceapCodeFacade.getCodeResource(name); codeResource.forEach(item->{ String lable = item.get("NAME").toString(); String value = item.get("CODE").toString(); map.put(value,lable); }); return map; } /** * 角色视图保存 * * @param * @return */ @ApiOperation(value = "角色视图保存") @Permission(value = "auth_mge_config") @PostMapping(value = "/role", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public Result saveRole(@RequestBody StaffRoleOperateVo staffRoleOperateVo) { //SecurityUser user = (SecurityUser) ContextUtils.getUserInfo(); // String staffJson = staffRoleOperateVo.getStaffJson(); // String delStaffJson = staffRoleOperateVo.getDelStaffJson(); // String appId = staffRoleOperateVo.getAppId(); // String roleId = staffRoleOperateVo.getRoleId(); // String orgId = staffRoleOperateVo.getOrgId(); // String appOrgId = staffRoleOperateVo.getAppOrgId(); RoleAuthDto dto=new RoleAuthDto(); 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 = "人员视图保存") @Permission(value = "auth_mge_config") @PostMapping (value = "/staff", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public Result saveStaff(@RequestBody StaffOperateVo staffOperateVo) { String userId = staffOperateVo.getUserId(); String saveIds = JSON.toJSONString(staffOperateVo.getSaveIds()); String deleteIds = JSON.toJSONString(staffOperateVo.getDeleteIds()); StaffAssignDTO staffAssignDTO=new StaffAssignDTO(userId, saveIds, deleteIds); ResponseStatus responseStatus = staffAssignAuthInfoFacade.saveStaff(staffAssignDTO); Result result = new Result(responseStatus.getStatusCode(),responseStatus.getMessage(),null,null); return result; } /** * 获取角色视图勾选人员 * 获取人员视图勾选角色 * * @param * @return */ @ApiOperation(value = "获取角色视图勾选人员,获取人员视图勾选角色", notes = "type表示获取类型,获取类型:role获取勾选人员 其他:获取勾选角色。type=role时appId, roleId, orgId") @ApiImplicitParams({ @ApiImplicitParam(name = "type", value = "获取类型:role获取勾选人员 其他:获取勾选角色"), @ApiImplicitParam(name = "appId", value = "应用id",required = true), @ApiImplicitParam(name = "orgId", value = "机构id", required = true), @ApiImplicitParam(name = "roleId", value = "角色id"), @ApiImplicitParam(name = "staffId", value = "人员id") }) @GetMapping(value = "/checked") @ResponseBody public Result> getCheckedStaff(@RequestParam(value = "type", required = true) String type, @RequestParam(value = "appId", required = true) String appId, @RequestParam(value = "orgId", required = false) String orgId, @RequestParam(value = "roleId", required = false) String roleId, @RequestParam(value = "staffId", required = false) String staffId) { List staffAssignAuthInfoList; if (type.equals("role")) { //获取勾选人员 staffAssignAuthInfoList = iRoleAuthInfoFacade.getStaff(appId, roleId, orgId); } else { //获取勾选角色 staffAssignAuthInfoList = iRoleAuthInfoFacade.getRole(appId, staffId); } List vos = new ArrayList<>(); for (StaffAssignAuthInfo source : staffAssignAuthInfoList) { StaffAssignAuthInfoVo vo = new StaffAssignAuthInfoVo(); BeanUtils.copyProperties(source,vo); vos.add(vo); } return Result.success(vos); } }