123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312 |
- 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<List<AuthUserDTO>> roleStaffList(SearchDTO searchDTO) {
- //职位状态只查询在职、挂职、借调
- Searchable searchable = getUserQuerySearchable(searchDTO);
- Page<AuthUserDTO> page = authUserInfoFacade.roleAuthRoleViewPage(searchable.toSearchDTO());
- //表码翻译
- Map<String, String> 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<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 = "查询条件")
- @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<AuthUserDTO> 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<List<RoleInfoVO>> getRoleList(SearchDTO searchDTO) {
- Page<RoleInfoVO> page = roleInfoFacade.roleAuthRoleViewPage(searchDTO);
- Map<String, String> 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<List<RoleInfoVO>> 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<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);
- }
- roleSearchable.addSearchFilter("orgId", SearchOperator.eq, orgId);
- //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);
- Map<String, String> 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<String, String> 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<String, String> getUserLabel() {
- List<LabelVO> 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<Object> 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<Object> result = getResult(responseStatus);
- return result;
- }
- private Result<Object> 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<StaffAssignAuthInfo> list = iRoleAuthInfoFacade.getStaff(roleId, orgId);
- List<UserRoleAuthInfoVo> 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<Object> roleAuthApply(@RequestBody RoleAuthApplySaveVo saveVo) {
- ResponseStatus responseStatus = iRoleAuthInfoFacade.roleAuthApply(saveVo);
- return getResult(responseStatus);
- }
- @ApiOperation(value = "角色授权申请角色列表")
- @PostMapping(value = "apply-role-list")
- public Result<List<ApplyRoleInVo>> applyRoleList(SearchDTO searchDTO) {
- List<ApplyRoleInVo> roleList = iRoleAuthInfoFacade.applyRoleList(searchDTO);
- return Result.success(roleList);
- }
- }
|