浏览代码

feature(运营平台接口开发): 运营平台接口开发

运营平台接口开发
mazq 3 年之前
父节点
当前提交
631a1d546d

+ 9 - 0
dcuc-auth-api/src/main/java/com/dragoninfo/dcuc/auth/auth/facade/IStaffAssignAuthInfoFacade.java

@@ -4,6 +4,7 @@ import com.dragoninfo.dcuc.auth.auth.dto.AppDataSensitiveLevelDTO;
 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.vo.StaffRoleAuthApiVo;
 import com.dragonsoft.duceap.base.entity.http.ResponseStatus;
 import com.dragonsoft.duceap.base.entity.search.SearchDTO;
 import org.springframework.cloud.openfeign.FeignClient;
@@ -211,4 +212,12 @@ public interface IStaffAssignAuthInfoFacade {
     @GetMapping("getAppLitByUserId")
     List<AppDataSensitiveLevelDTO> getAppLitByUserId(@RequestParam("userId") String userId);
 
+    /**
+     * 应用下的角色授权列表
+     * API对外接口使用
+     * @param searchDTO
+     * @return
+     */
+    @PostMapping("apiStaffRoleAuthResult")
+    Page<StaffRoleAuthApiVo> apiStaffRoleAuthResult(@RequestBody SearchDTO searchDTO);
 }

+ 16 - 0
dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/dto/StaffRoleAuthApiDTO.java

@@ -0,0 +1,16 @@
+package com.dragoninfo.dcuc.auth.auth.dto;
+
+import lombok.Data;
+
+/**
+ * @author mazq
+ * @date 2022/2/18
+ */
+@Data
+public class StaffRoleAuthApiDTO {
+    private String staffOrgId;
+    private String staffId;
+    private String roleId;
+    private String relName;
+    private String relStatus;
+}

+ 27 - 0
dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/vo/RoleInfoApiVo.java

@@ -0,0 +1,27 @@
+package com.dragoninfo.dcuc.auth.auth.vo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * @author mazq
+ * @date 2022/2/17
+ */
+@Data
+@ApiModel(value = "角色信息api接口Vo")
+public class RoleInfoApiVo {
+
+    @ApiModelProperty(name = "角色名称")
+    private String roleName;
+
+    @ApiModelProperty(name = "角色Code")
+    private String roleCode;
+
+    @ApiModelProperty(name = "应用名称")
+    private String appName;
+
+    @ApiModelProperty(name = "应用Code")
+    private String appCode;
+
+}

+ 41 - 0
dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/vo/StaffRoleAuthApiVo.java

@@ -0,0 +1,41 @@
+package com.dragoninfo.dcuc.auth.auth.vo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * @author mazq
+ * @date 2022/2/17
+ */
+@Data
+@ApiModel(value = "人员角色授权信息api接口Vo")
+public class StaffRoleAuthApiVo {
+
+    @ApiModelProperty(name = "人员姓名")
+    private String name;
+
+    @ApiModelProperty(name = "人员身份证号")
+    private String idcard;
+
+    @ApiModelProperty(name = "人员类型 10:警员 20:辅警 30:施工人员")
+    private String userType;
+
+    @ApiModelProperty(name = "职务任职状态 ")
+    private String postStatus;
+
+    @ApiModelProperty(name = "该机构下的职务名称")
+    private String postName;
+
+    @ApiModelProperty(name = "机构Code")
+    private String orgCode;
+
+    @ApiModelProperty(name = "机构名称")
+    private String orgName;
+
+    @ApiModelProperty(name = "角色名称")
+    private String roleName;
+
+    @ApiModelProperty(name = "角色code")
+    private String roleCode;
+}

+ 13 - 0
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/bpo/StaffAssignAuthInfoBPO.java

@@ -2,13 +2,18 @@
 package com.dragoninfo.dcuc.auth.auth.bpo;
 
 import com.dragoninfo.dcuc.auth.auth.dto.AppDataSensitiveLevelDTO;
+import com.dragoninfo.dcuc.auth.auth.dto.StaffRoleAuthApiDTO;
 import com.dragoninfo.dcuc.auth.auth.entity.StaffAssignAuthInfo;
 import com.dragoninfo.dcuc.auth.auth.enumresources.YesNotEnum;
 import com.dragoninfo.dcuc.auth.auth.vo.StaffAllotVO;
+import com.dragoninfo.dcuc.auth.auth.vo.StaffRoleAuthApiVo;
 import com.dragoninfo.duceap.core.persistent.BaseBPO;
 import com.dragonsoft.duceap.commons.util.date.DateConst;
 import com.dragonsoft.duceap.commons.util.date.DateUtils;
 import com.dragonsoft.duceap.core.persistent.factory.PersistentFactory;
+import com.dragonsoft.duceap.core.search.Searchable;
+import com.dragonsoft.duceap.core.search.enums.SearchOperator;
+import org.springframework.data.domain.Page;
 import org.springframework.stereotype.Repository;
 
 import java.util.List;
@@ -176,4 +181,12 @@ public class StaffAssignAuthInfoBPO extends BaseBPO<StaffAssignAuthInfo, String>
         String sql = "SELECT ROLE_ID from T_STAFF_ASSIGN_AUTH_INFO where STAFF_ID = ?";
         return PersistentFactory.getJdbcDao().queryForList(sql, String.class, userId);
     }
+
+    public Page<StaffRoleAuthApiDTO> apiStaffRoleAuthResult(Searchable pageSearch) {
+        String appId = pageSearch.getSearchFilter("appId", SearchOperator.eq).toString();
+        String sql = "SELECT s.ROLE_ID, s.STAFF_ID, s.STAFF_ORG_ID, r.REL_NAME, r.REL_STATUS," +
+                " s.ROLE_ID as roleId, s.STAFF_ID as staffId, s.STAFF_ORG_ID as staffOrgId, s.APP_ID as appId, r.REL_STATUS as postStatus" +
+                " FROM T_STAFF_ASSIGN_AUTH_INFO s INNER JOIN T_AUTH_USER_ORG_REL r ON s.STAFF_ID = r.USER_ID AND s.STAFF_ORG_ID = r.ORG_ID WHERE s.APP_ID = ?";
+        return PersistentFactory.getJdbcDao().paging(sql, pageSearch, StaffRoleAuthApiDTO.class, appId);
+    }
 }

+ 6 - 0
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/facade/StaffAssignAuthInfoFacade.java

@@ -7,6 +7,7 @@ import com.dragoninfo.dcuc.auth.auth.dto.StaffRoleOperateDTO;
 import com.dragoninfo.dcuc.auth.auth.entity.StaffAssignAuthInfo;
 import com.dragoninfo.dcuc.auth.auth.enumresources.PermissionEventTypeEnum;
 import com.dragoninfo.dcuc.auth.auth.service.IStaffAssignAuthInfoService;
+import com.dragoninfo.dcuc.auth.auth.vo.StaffRoleAuthApiVo;
 import com.dragonsoft.duceap.base.entity.http.ResponseStatus;
 import com.dragonsoft.duceap.base.entity.search.SearchDTO;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -114,4 +115,9 @@ public class StaffAssignAuthInfoFacade implements IStaffAssignAuthInfoFacade {
         return staffAssignAuthInfoService.getAppLitByUserId(userId);
     }
 
+    @Override
+    public Page<StaffRoleAuthApiVo> apiStaffRoleAuthResult(SearchDTO searchDTO) {
+        return staffAssignAuthInfoService.apiStaffRoleAuthResult(searchDTO);
+    }
+
 }

+ 7 - 0
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/service/IRoleInfoService.java

@@ -187,4 +187,11 @@ public interface IRoleInfoService {
      * @return
      */
     Page<RoleInfoVO> roleAuthRoleViewPage(SearchDTO searchDTO);
+
+    /**
+     * 根据appId获取
+     * @param appId
+     * @return
+     */
+    List<RoleInfo> getRolesByAppId(String appId);
 }

+ 9 - 0
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/service/IStaffAssignAuthInfoService.java

@@ -5,6 +5,7 @@ import com.dragoninfo.dcuc.auth.auth.dto.AppDataSensitiveLevelDTO;
 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.vo.StaffRoleAuthApiVo;
 import com.dragonsoft.duceap.base.entity.http.ResponseStatus;
 import com.dragonsoft.duceap.base.entity.search.SearchDTO;
 import com.dragonsoft.duceap.base.entity.security.SecurityUser;
@@ -197,4 +198,12 @@ public interface IStaffAssignAuthInfoService  {
      * @return
      */
     List<String> getAllRoleIds(String userId);
+
+    /**
+     * 应用下的角色授权列表
+     * API对外接口使用
+     * @param searchDTO
+     * @return
+     */
+    Page<StaffRoleAuthApiVo> apiStaffRoleAuthResult(SearchDTO searchDTO);
 }

+ 5 - 0
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/service/impl/RoleInfoService.java

@@ -612,4 +612,9 @@ public class RoleInfoService implements IRoleInfoService {
         }
         return page;
     }
+
+    @Override
+    public List<RoleInfo> getRolesByAppId(String appId) {
+        return roleInfoBPO.getRolesByAppId(appId);
+    }
 }

+ 105 - 4
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/service/impl/StaffAssignAuthInfoService.java

@@ -11,10 +11,7 @@ import com.dragoninfo.dcuc.auth.audit.enums.AuthResultEnum;
 import com.dragoninfo.dcuc.auth.audit.service.log.LogInfoFillService;
 import com.dragoninfo.dcuc.auth.auth.async.StaffAssignAuthEventCenterBus;
 import com.dragoninfo.dcuc.auth.auth.bpo.StaffAssignAuthInfoBPO;
-import com.dragoninfo.dcuc.auth.auth.dto.AppDataSensitiveLevelDTO;
-import com.dragoninfo.dcuc.auth.auth.dto.StaffAssignDTO;
-import com.dragoninfo.dcuc.auth.auth.dto.StaffRoleOperateDTO;
-import com.dragoninfo.dcuc.auth.auth.dto.UserRoleAuthInfoDTO;
+import com.dragoninfo.dcuc.auth.auth.dto.*;
 import com.dragoninfo.dcuc.auth.auth.entity.OrgQuotaAuthInfo;
 import com.dragoninfo.dcuc.auth.auth.entity.RoleInfo;
 import com.dragoninfo.dcuc.auth.auth.entity.StaffAssignAuthInfo;
@@ -23,6 +20,7 @@ import com.dragoninfo.dcuc.auth.auth.service.IOrgQuotaAuthService;
 import com.dragoninfo.dcuc.auth.auth.service.IRoleInfoService;
 import com.dragoninfo.dcuc.auth.auth.service.IStaffAssignAuthInfoService;
 import com.dragoninfo.dcuc.auth.auth.service.IStaffAssignAuthLogService;
+import com.dragoninfo.dcuc.auth.auth.vo.StaffRoleAuthApiVo;
 import com.dragoninfo.dcuc.auth.sub.entity.AuthOrgInfo;
 import com.dragoninfo.dcuc.auth.sub.entity.AuthUserInfo;
 import com.dragoninfo.dcuc.auth.sub.service.IAuthOrgInfoService;
@@ -40,6 +38,7 @@ import com.dragonsoft.duceap.core.context.ContextUtils;
 import com.dragonsoft.duceap.core.persistent.factory.PersistentFactory;
 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.utils.RequestUtils;
 import org.hibernate.criterion.DetachedCriteria;
 import org.hibernate.criterion.Projections;
@@ -48,13 +47,17 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageImpl;
+import org.springframework.data.domain.Pageable;
 import org.springframework.data.domain.Sort;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import sun.security.krb5.internal.PAData;
 
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 @Service
 @Transactional
@@ -698,4 +701,102 @@ public class StaffAssignAuthInfoService implements IStaffAssignAuthInfoService {
         return staffAssignAuthInfoBPO.getAllRoleIds(userId);
     }
 
+    @Override
+    public Page<StaffRoleAuthApiVo> apiStaffRoleAuthResult(SearchDTO searchDTO) {
+        Searchable searchable = Searchable.toSearchable(searchDTO);
+        Pageable page = searchable.getPage();
+        String appId = searchable.getSearchFilter("appId", SearchOperator.eq).getValue().toString();
+        List<RoleInfo> roleInfos = roleInfoService.getRolesByAppId(appId);
+        Stream<RoleInfo> stream = roleInfos.stream();
+        Condition roleCodeEq = searchable.getSearchFilter("roleCode", SearchOperator.eq);
+        if(null != roleCodeEq) {
+            String roleCode = roleCodeEq.getValue().toString();
+            stream = stream.filter(e -> e.getCode().equals(roleCode));
+        }
+        Condition roleCodeIn = searchable.getSearchFilter("roleCode", SearchOperator.in);
+        if(null != roleCodeIn) {
+            String[] value = (String[]) roleCodeIn.getValue();
+            Set<String> set = Stream.of(value).collect(Collectors.toSet());
+            stream = stream.filter(e->set.contains(e.getCode()));
+        }
+        if(stream.count() == 0) {
+            return Page.empty();
+        }
+        Searchable pageSearch = Searchable.newSearchable();
+        pageSearch.setPage(page);
+        List<String> roleIds = stream.map(RoleInfo::getId).collect(Collectors.toList());
+        pageSearch.addSearchFilter("roleId", SearchOperator.in, roleIds);
+        Condition orgCodeEq = searchable.getSearchFilter("orgCode", SearchOperator.eq);
+        List<AuthOrgInfo> orgInfos = null;
+        if(null != orgCodeEq) {
+            String orgCode = orgCodeEq.getValue().toString();
+            AuthOrgInfo orgInfo = authOrgInfoService.getByOrgCode(orgCode);
+            if(null == orgInfo) {
+                return Page.empty();
+            }
+            orgInfos = new ArrayList<>();
+            orgInfos.add(orgInfo);
+            String orgId = orgInfo.getId();
+            pageSearch.addSearchFilter("staffOrgId", SearchOperator.eq, orgId);
+        }
+        List<AuthUserInfo> userInfos = null;
+        Condition userNameLike = searchable.getSearchFilter("userName", SearchOperator.like);
+        if(null != userNameLike) {
+            String userName = userNameLike.getValue().toString();
+            userInfos = authUserInfoService.findByNameLike(userName);
+            if(CollectionUtils.isEmpty(userInfos)) {
+                return Page.empty();
+            }
+            List<String> userIds = userInfos.stream().map(AuthUserInfo::getId).collect(Collectors.toList());
+            pageSearch.addSearchFilter("staffId", SearchOperator.in ,userIds);
+        }
+
+        pageSearch.addSearchFilter("appId", SearchOperator.eq, appId);
+        Condition postStatusEq = searchable.getSearchFilter("postStatus", SearchOperator.eq);
+        if(null != postStatusEq) {
+            pageSearch.addSearchFilter("postStatus", SearchOperator.eq, postStatusEq.getValue());
+        }
+        Condition postStatusIn = searchable.getSearchFilter("postStatus", SearchOperator.in);
+        if(null != postStatusIn) {
+            pageSearch.addSearchFilter("postStatus", SearchOperator.in, postStatusIn.getValue());
+        }
+
+        Page<StaffRoleAuthApiDTO> dtoPage = staffAssignAuthInfoBPO.apiStaffRoleAuthResult(pageSearch);
+        if(null == userInfos) {
+            List<String> userIds = dtoPage.getContent().stream().map(StaffRoleAuthApiDTO::getStaffId).distinct().collect(Collectors.toList());
+            userInfos = authUserInfoService.findByIds(userIds);
+        }
+        if(null == orgInfos) {
+            List<String> orgIds = dtoPage.getContent().stream().map(StaffRoleAuthApiDTO::getStaffOrgId).distinct().collect(Collectors.toList());
+            orgInfos = authOrgInfoService.getByIds(orgIds);
+        }
+        Map<String, RoleInfo> roleInfoMap = stream.collect(Collectors.toMap(RoleInfo::getId, e -> e, (old, last) -> last));
+        Map<String, AuthUserInfo> userInfoMap = userInfos.stream().collect(Collectors.toMap(AuthUserInfo::getId, e -> e, (old, last) -> last));
+        Map<String, AuthOrgInfo> orgInfoMap = orgInfos.stream().collect(Collectors.toMap(AuthOrgInfo::getId, e -> e, (old, last) -> last));
+        List<StaffRoleAuthApiVo> vos = dtoPage.stream()
+                .map(e -> getStaffRoleAuthApiVo(roleInfoMap, userInfoMap, orgInfoMap, e))
+                .collect(Collectors.toList());
+        return new PageImpl<>(vos,page, dtoPage.getTotalElements());
+    }
+
+    private StaffRoleAuthApiVo getStaffRoleAuthApiVo(Map<String, RoleInfo> roleInfoMap, Map<String, AuthUserInfo> userInfoMap, Map<String, AuthOrgInfo> orgInfoMap, StaffRoleAuthApiDTO e) {
+        StaffRoleAuthApiVo apiVo = new StaffRoleAuthApiVo();
+        String staffId = e.getStaffId();
+        String staffOrgId = e.getStaffOrgId();
+        String roleId = e.getRoleId();
+        AuthUserInfo userInfo = userInfoMap.get(staffId);
+        AuthOrgInfo authOrgInfo = orgInfoMap.get(staffOrgId);
+        RoleInfo roleInfo = roleInfoMap.get(roleId);
+        apiVo.setName(userInfo.getName());
+        apiVo.setIdcard(userInfo.getIdcard());
+        apiVo.setOrgName(authOrgInfo.getFullName());
+        apiVo.setUserType(userInfo.getUserType());
+        apiVo.setOrgCode(authOrgInfo.getCode());
+        apiVo.setPostStatus(e.getRelStatus());
+        apiVo.setPostName(e.getRelName());
+        apiVo.setRoleCode(roleInfo.getCode());
+        apiVo.setRoleName(roleInfo.getName());
+        return apiVo;
+    }
+
 }

+ 6 - 0
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/sub/service/IAuthUserInfoService.java

@@ -167,4 +167,10 @@ public interface IAuthUserInfoService {
      */
     void updateOrgInfoInUser();
 
+    /**
+     * 根据名称模糊查询
+     * @param userName
+     * @return
+     */
+    List<AuthUserInfo> findByNameLike(String userName);
 }

+ 6 - 0
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/sub/service/impl/AuthUserInfoService.java

@@ -222,6 +222,12 @@ public class AuthUserInfoService implements IAuthUserInfoService {
         userInfoRepository.updateOrgInfoInUser();
     }
 
+    @Override
+    public List<AuthUserInfo> findByNameLike(String userName) {
+        Specification<AuthUserInfo> specification = (root, query, cb)-> cb.like(root.get("name"), userName);
+        return userInfoRepository.findAll(specification);
+    }
+
     private List<AuthUserInfo> getPageContent(int pageSize, int pageNumber, List<AuthUserInfo> list) {
         return list.stream().skip(pageNumber * pageSize).limit(pageSize).collect(Collectors.toList());
     }