123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456 |
- 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<List<UserInfoView>> roleStaffList( RoleAuthUserVo vo) {
- if (StringUtils.isEmpty(vo.getOrgId())) {
- return Result.success(new ArrayList<UserInfoView>());
- }
- 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<UserInfoView>());
- }
- List<UserInfoView> list = new ArrayList<UserInfoView>();
- 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<String> jobType = new ArrayList<String>();
- 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<String, ArrayList<CodeRecord>> listCodes = iCodeListResourceFacade.listCodes("code", "DM_POLICE_BUSINESS,T_MD_ORG_LEVEL,DM_USER_TYPE");
- HashMap<String, Map<String, String>> 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<String, Map<String, String>> getConvertMap(Map<String, ArrayList<CodeRecord>> listCodes) {
- HashMap<String, Map<String, String>> allConvertMap = new HashMap<>();
- for (Map.Entry<String, ArrayList<CodeRecord>> entry : listCodes.entrySet()) {
- String codeName = entry.getKey();
- ArrayList<CodeRecord> valueList = entry.getValue();
- HashMap<String, String> 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<List<UserInfo>> 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<UserInfo> 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<List<UserInfo>> 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<UserInfo> 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<List<StaffAssignAuthInfoVo>> 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<StaffAssignAuthInfo> staffAssignAuthInfoList = staffAssignAuthInfoFacade.findForList(searchable.toSearchDTO());
- List<StaffAssignAuthInfoVo> 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<List<RoleInfoVO>> getRoleList(SearchDTO searchDTO) {
- String appId = null;
- String orgId = null;
- Page<RoleInfoVO> 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<List<RoleInfoVO>> 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<RoleInfoVO>());
- }
- 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<RoleInfoVO> roleInfoVOList = roleInfoFacade.staffRoleList(roleSearchable.toSearchDTO());
- Searchable staffSearchable = Searchable.newSearchable();
- staffSearchable.addSearchFilter("staffId",SearchOperator.eq,userId);
- List<StaffAssignAuthInfo> staffAssignAuthInfoList = staffAssignAuthInfoFacade.findForList(staffSearchable.toSearchDTO());
- Map<String, String> roleMap = new HashMap<String, String>();
- for (StaffAssignAuthInfo assignAuthInfo : staffAssignAuthInfoList) {
- roleMap.put(assignAuthInfo.getRoleId(), assignAuthInfo.getActiveTime());
- }
- Map<String, ArrayList<CodeRecord>> listCodes = iCodeListResourceFacade.listCodes("code", "DM_ROLE_LEVEL,T_MD_POLICE_TYPE");
- HashMap<String, Map<String, String>> 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<String, String> 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<String, String> getCodeVLMap(String name) {
- HashMap<String, String> map = new HashMap<String, String>();
- List<Map<String, Object>> 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<List<StaffAssignAuthInfoVo>> 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<StaffAssignAuthInfo> staffAssignAuthInfoList;
- if (type.equals("role")) {
- //获取勾选人员
- staffAssignAuthInfoList = iRoleAuthInfoFacade.getStaff(appId, roleId, orgId);
- } else {
- //获取勾选角色
- staffAssignAuthInfoList = iRoleAuthInfoFacade.getRole(appId, staffId);
- }
- List<StaffAssignAuthInfoVo> vos = new ArrayList<>();
- for (StaffAssignAuthInfo source : staffAssignAuthInfoList) {
- StaffAssignAuthInfoVo vo = new StaffAssignAuthInfoVo();
- BeanUtils.copyProperties(source,vo);
- vos.add(vo);
- }
- return Result.success(vos);
- }
- }
|