Эх сурвалжийг харах

Merge branch 'mazq-0416-dataauth' into 'feature/v2.0.0-data-auth'

feature(数据授权开发): 数据授权开发

See merge request dcuc-tjdsj/auth-back!12
黄资权 4 жил өмнө
parent
commit
145d1bf768

+ 126 - 26
src/main/java/com/dragoninfo/dcuc/authweb/restcontroller/auth/DataAuthController.java

@@ -1,78 +1,178 @@
 package com.dragoninfo.dcuc.authweb.restcontroller.auth;
 
+import com.alibaba.fastjson.JSON;
+import com.dragoninfo.dcuc.auth.auth.dto.DataClassifyDTO;
+import com.dragoninfo.dcuc.auth.auth.dto.SubDataAuthDTO;
+import com.dragoninfo.dcuc.auth.auth.dto.SubDataAuthQueryDTO;
+import com.dragoninfo.dcuc.auth.auth.dto.SubDataDTO;
+import com.dragoninfo.dcuc.auth.auth.enumresources.SubDataAuthTypeEnum;
 import com.dragoninfo.dcuc.auth.auth.facade.IDataAuthFacade;
-import com.dragoninfo.dcuc.authweb.restcontroller.auth.vo.LabelDataAuthAcceptVo;
-import com.dragoninfo.dcuc.authweb.restcontroller.auth.vo.OrgDataAuthAcceptVo;
-import com.dragoninfo.dcuc.authweb.restcontroller.auth.vo.UserDataAuthAcceptVo;
+import com.dragoninfo.dcuc.authweb.restcontroller.auth.vo.data.*;
+import com.dragoninfo.dcuc.authweb.util.VersionUtils;
 import com.dragoninfo.duceap.core.response.Result;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
+import org.apache.commons.collections.CollectionUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
 /**
  * @author mazq
  * @date 2021/4/6
  */
-@Api("数据授权相关接口")
+@Api(tags ="数据授权API")
 @RestController
-@RequestMapping("authsvr/v2/dataauth")
+@RequestMapping("authsvr/"+ VersionUtils.VERSION_UID +"/dataauth")
 public class DataAuthController {
 
+    Logger logger = LoggerFactory.getLogger(DataAuthController.class);
+
     @Autowired
     IDataAuthFacade dataAuthFacade;
 
 
     @ApiOperation(value = "获取属性列表,树形结构:警种1-业务域N")
-    @GetMapping(value = "attrTreeList", produces = "application/json;charset=UTF-8")
-    public Result<?> getAttrTreeList(){
+    @ApiImplicitParam(name = "name", value = "查询条件")
+    @GetMapping(value = "businessTreeList", produces = "application/json;charset=UTF-8")
+    public Result<List<PropertyTreeVo>> businessTreeList(@RequestParam(value = "name",required = false) String name){
 
         return null;
     }
 
-//    @ApiOperation(value = "获取所有数据资源")
-
+    @ApiOperation(value = "获取所有数据资源,返回返回树结构")
+    @ApiImplicitParam(name = "attrType",value = "数据属性类型 TABLE:表 COLUMN:列")
+    @GetMapping(value = "allDataTree", produces = "application/json;charset=UTF-8")
+    public Result<List<DataClassifyVo>> getAllDataResource(@RequestParam("attrType") String attrType){
+        logger.info("allDataTree>>attrType:{}", attrType);
+        List<DataClassifyDTO> dtos = dataAuthFacade.getAllDataResourceTree(attrType);
+        List<DataClassifyVo> vos = dtos.stream().map(item -> {
+            DataClassifyVo vo = new DataClassifyVo();
+            BeanUtils.copyProperties(item, vo);
+            return vo;
+        }).collect(Collectors.toList());
+        return Result.success(vos);
+    }
 
     @ApiOperation(value = "人员数据授权接口")
     @PostMapping(value = "userDataAuth", produces = "application/json;charset=UTF-8")
-    public Result userDataAuth(@RequestBody UserDataAuthAcceptVo userDataAuthAcceptVo){
-
-
-
-        return Result.success();
+    public Result<Boolean> userDataAuth(@RequestBody UserDataAuthAcceptVo vo){
+        List<DataAuthAcceptVo> authVoList = vo.getAuthVoList();
+        if(CollectionUtils.isEmpty(authVoList)) {
+            return Result.failMessage("权限集合为空");
+        }
+        logger.info("userDataAuth>>userDataAuthAcceptVo",JSON.toJSONString(vo));
+        SubDataAuthDTO subDataAuthDTO = convertToSubAuthDTO(vo.getUserId(), SubDataAuthTypeEnum.SUB_DATA_AUTH_USER.getValue(), vo.getAuthType(), authVoList);
+        dataAuthFacade.subDataAuthAdd(subDataAuthDTO);
+        return Result.success(true);
     }
 
 
     @ApiOperation(value = "机构数据授权接口")
     @PostMapping(value = "orgDataAuth", produces = "application/json;charset=UTF-8")
-    public Result orgDataAuth(@RequestBody OrgDataAuthAcceptVo orgDataAuthAcceptVo){
-
-
-
-        return Result.success();
+    public Result<Boolean> orgDataAuth(@RequestBody OrgDataAuthAcceptVo vo){
+        List<DataAuthAcceptVo> authVoList = vo.getAuthVoList();
+        if(CollectionUtils.isEmpty(authVoList)){
+            return Result.failMessage("权限集合为空");
+        }
+        logger.info("orgDataAuth>>orgDataAuthAcceptVo",JSON.toJSONString(vo));
+        SubDataAuthDTO subDataAuthDTO = convertToSubAuthDTO(vo.getOrgId(), SubDataAuthTypeEnum.SUB_DATA_AUTH_ORG.getValue(), vo.getAuthType(), authVoList);
+        dataAuthFacade.subDataAuthAdd(subDataAuthDTO);
+        return Result.success(true);
     }
 
 
     @ApiOperation(value = "业务域标签数据授权接口")
     @PostMapping(value = "labelDataAuth", produces = "application/json;charset=UTF-8")
-    public Result labelDataAuth(@RequestBody LabelDataAuthAcceptVo labelDataAuthAcceptVo){
+    public Result<Boolean> labelDataAuth(@RequestBody LabelDataAuthAcceptVo vo){
+        List<DataAuthAcceptVo> authVoList = vo.getAuthVoList();
+        if(CollectionUtils.isEmpty(authVoList)){
+            return Result.failMessage("权限集合为空");
+        }
+        logger.info("labelDataAuth>>labelDataAuthAcceptVo",JSON.toJSONString(vo));
+        SubDataAuthDTO subDataAuthDTO = convertToSubAuthDTO(vo.getCode(), SubDataAuthTypeEnum.SUB_DATA_AUTH_BUSINESS.getValue(), vo.getAuthType(), authVoList);
+        dataAuthFacade.subDataAuthAdd(subDataAuthDTO);
+        return Result.success(true);
+    }
 
+    @ApiOperation(value = "查询多个主体相关数据权限")
+    @PostMapping(value = "subListDataAuth", produces = "application/json;charset=UTF-8")
+    public Result subDataAuthList(@RequestBody List<SubDataAuthQueryVo> queryVoList) {
 
 
         return Result.success();
     }
 
-    @ApiOperation(value = "人员视角数据权限查询")
-    @ApiImplicitParam(name = "userId",value = "人员id")
-    @GetMapping(value = "userDataAuthInfo")
-    public Result userDataAuthInfo(@RequestParam("userId") String userId){
+    @ApiOperation(value = "查询单个主体数据权限")
+    @PostMapping(value = "getSubDataAuth" , produces = "application/json;charset=UTF-8")
+    public Result<List<DataClassifyVo>> getSubDataAuth(@RequestBody SubDataAuthQueryVo queryVo){
+        logger.info("getSubDataAuth >> vo:{}",JSON.toJSONString(queryVo));
+        SubDataAuthQueryDTO queryDTO = new SubDataAuthQueryDTO();
+        BeanUtils.copyProperties(queryVo,queryDTO);
+        List<DataClassifyDTO> dtos = dataAuthFacade.getSubDataAuth(queryDTO);
+        List<DataClassifyVo> vos = dtos.stream().map(item -> {
+            DataClassifyVo vo = new DataClassifyVo();
+            BeanUtils.copyProperties(item, vo);
+            return vo;
+        }).collect(Collectors.toList());
+        return Result.success(vos);
+    }
 
 
-        return Result.success();
+    @ApiOperation(value = "人员视角数据权限查询-根据人员id查询")
+    @ApiImplicitParams(value = {
+            @ApiImplicitParam(name = "userId",value = "人员id"),
+            @ApiImplicitParam(name = "authType",value = "数据属性授权类型 TABLE:表授权 COLUMN:列授权")
+    })
+    @GetMapping(value = "dataAuthInfoByUserId" , produces = "application/json;charset=UTF-8")
+    public Result<List<DataClassifyVo>> userDataAuthInfoById(@RequestParam("userId") String userId,
+                                   @RequestParam(value = "authType") String authType){
+        logger.info("dataAuthInfoByUserId >> userId:{},authType:{}", userId, authType);
+        List<DataClassifyDTO> dtos = dataAuthFacade.userDataAuthInfoByUserId(userId, authType);
+        List<DataClassifyVo> vos = dtos.stream().map(item -> {
+            DataClassifyVo vo = new DataClassifyVo();
+            BeanUtils.copyProperties(item, vo);
+            return vo;
+        }).collect(Collectors.toList());
+        return Result.success(vos);
     }
 
+    @ApiOperation(value = "人员视角数据权限查询-根据人员身份证号查询")
+    @ApiImplicitParams(value = {
+            @ApiImplicitParam(name = "idcard",value = "身份证号"),
+            @ApiImplicitParam(name = "authType",value = "数据属性授权类型 TABLE:表授权 COLUMN:列授权")
+    })
+    @GetMapping(value = "dataAuthInfoByIdcard" , produces = "application/json;charset=UTF-8")
+    public Result<List<DataClassifyVo>> userDataAuthInfoByIdcard(@RequestParam("idcard") String idcard,
+                                   @RequestParam(value = "authType") String authType){
+        List<DataClassifyDTO> dtos = dataAuthFacade.userDataAuthInfoByIdcard(idcard, authType);
+        List<DataClassifyVo> vos = dtos.stream().map(item -> {
+            DataClassifyVo vo = new DataClassifyVo();
+            BeanUtils.copyProperties(item, vo);
+            return vo;
+        }).collect(Collectors.toList());
+        return Result.success(vos);
+    }
 
-
+    private SubDataAuthDTO convertToSubAuthDTO(String subId, String subType, String authType,List<DataAuthAcceptVo> authVoList) {
+        SubDataAuthDTO subDataAuthDTO = new SubDataAuthDTO(subId,subType,authType);
+        List<SubDataDTO> dataDTOList = new ArrayList<>();
+        for (DataAuthAcceptVo vo : authVoList) {
+            SubDataDTO subDataDTO = new SubDataDTO();
+            subDataDTO.setDataType(vo.getDataType());
+            subDataDTO.setDataCode(vo.getDataCode());
+            dataDTOList.add(subDataDTO);
+        }
+        subDataAuthDTO.setDataAuthList(dataDTOList);
+        return subDataAuthDTO;
+    }
 
 }

+ 5 - 7
src/main/java/com/dragoninfo/dcuc/authweb/restcontroller/auth/vo/DataAuthVo.java → src/main/java/com/dragoninfo/dcuc/authweb/restcontroller/auth/vo/data/DataAuthAcceptVo.java

@@ -1,28 +1,26 @@
-package com.dragoninfo.dcuc.authweb.restcontroller.auth.vo;
+package com.dragoninfo.dcuc.authweb.restcontroller.auth.vo.data;
 
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
-import java.util.List;
-
 /**
  * @author mazq
  * @date 2021/4/8
  */
 @ApiModel(value = "同一类别数据授权对象")
 @Data
-public class DataAuthVo {
+public class DataAuthAcceptVo {
 
-    @ApiModelProperty(value = "数据资源类型,对应类型码值" +
+    @ApiModelProperty(value = "数据资源类型,对应类型码值" +
             "DATA_SECURITY_LEVEL:数据安全级别;" +
             "LEVEL_1_COLUMN_CLASSIFY:字段一级分类;" +
             "LEVEL_2_COLUMN_CLASSIFY:字段二级分类;" +
             "DATA_CLASSIFY:数据分级", dataType = "string")
     private String dataType;
 
-    @ApiModelProperty(value = "该类型数据下需要授权的数据code集合",dataType = "string[]")
-    private List<String> dataCodes;
+    @ApiModelProperty(value = "数据资源code")
+    private String dataCode;
 
 
 }

+ 30 - 0
src/main/java/com/dragoninfo/dcuc/authweb/restcontroller/auth/vo/data/DataClassifyVo.java

@@ -0,0 +1,30 @@
+package com.dragoninfo.dcuc.authweb.restcontroller.auth.vo.data;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * @author mazq
+ * @date 2021/4/15
+ */
+@Data
+@ApiModel(value = "数据分级分类Vo")
+public class DataClassifyVo {
+    @ApiModelProperty(value = "id,分级分类唯一标识")
+    private String id;
+    @ApiModelProperty(value = "分级分类名称")
+    private String label;
+    @ApiModelProperty(value = "分级分类code值")
+    private String code;
+    @ApiModelProperty(value = "分级分类下数据资源-树结构")
+    private DataResourceTreeVo nodes;
+    @ApiModelProperty(value = "最后一级节点总数量")
+    private Integer total;
+    @ApiModelProperty(value = "数据属性类型 TABLE:表 COLUMN:列")
+    private String attrType;
+    @ApiModelProperty(value = "分级分下被勾选的叶子节点id集合")
+    private List<String> tickIds;
+}

+ 35 - 0
src/main/java/com/dragoninfo/dcuc/authweb/restcontroller/auth/vo/data/DataResourceTreeVo.java

@@ -0,0 +1,35 @@
+package com.dragoninfo.dcuc.authweb.restcontroller.auth.vo.data;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * @author mazq
+ * @date 2021/4/13
+ */
+@Data
+@ApiModel(value = "数据资源树对象")
+public class DataResourceTreeVo {
+
+    @ApiModelProperty(value = "节点id")
+    private String id;
+    @ApiModelProperty(value = "数据资源code")
+    private String code;
+    @ApiModelProperty(value = "节点名称")
+    private String label;
+    @ApiModelProperty(value = "节点详细说明")
+    private String desc;
+    @ApiModelProperty(value = "数据资源类型" +
+            "数据安全级别:DATA_SECURITY_LEVEL " +
+            "字段一级分类:LEVEL_1_COLUMN_CLASSIFY" +
+            "字段二级分类:LEVEL_2_COLUMN_CLASSIFY" +
+            "数据分级:DATA_CLASSIFY")
+    private String dataType;
+    @ApiModelProperty(value = "子节点集合")
+    private List<DataResourceTreeVo> child;
+    @ApiModelProperty(value = "是否是树节点 true:是树节点,child不为空。false:非树节点,child为空。")
+    private Boolean treeNode;
+}

+ 5 - 2
src/main/java/com/dragoninfo/dcuc/authweb/restcontroller/auth/vo/LabelDataAuthAcceptVo.java → src/main/java/com/dragoninfo/dcuc/authweb/restcontroller/auth/vo/data/LabelDataAuthAcceptVo.java

@@ -1,4 +1,4 @@
-package com.dragoninfo.dcuc.authweb.restcontroller.auth.vo;
+package com.dragoninfo.dcuc.authweb.restcontroller.auth.vo.data;
 
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
@@ -17,7 +17,10 @@ public class LabelDataAuthAcceptVo {
     @ApiModelProperty(value = "业务域表码code值")
     private String code;
 
+    @ApiModelProperty(value = "数据属性授权类型 TABLE:表授权 COLUMN:列授权")
+    private String authType;
+
     @ApiModelProperty(value = "需要授权的数据对象",dataType = "object[]")
-    private List<DataAuthVo> authDataList;
+    private List<DataAuthAcceptVo> authVoList;
 
 }

+ 5 - 2
src/main/java/com/dragoninfo/dcuc/authweb/restcontroller/auth/vo/OrgDataAuthAcceptVo.java → src/main/java/com/dragoninfo/dcuc/authweb/restcontroller/auth/vo/data/OrgDataAuthAcceptVo.java

@@ -1,4 +1,4 @@
-package com.dragoninfo.dcuc.authweb.restcontroller.auth.vo;
+package com.dragoninfo.dcuc.authweb.restcontroller.auth.vo.data;
 
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
@@ -17,7 +17,10 @@ public class OrgDataAuthAcceptVo {
     @ApiModelProperty(value = "机构id")
     private String orgId;
 
+    @ApiModelProperty(value = "数据属性授权类型 TABLE:表授权 COLUMN:列授权")
+    private String authType;
+
     @ApiModelProperty(value = "需要授权的数据对象",dataType = "object[]")
-    private List<DataAuthVo> authVoList;
+    private List<DataAuthAcceptVo> authVoList;
 
 }

+ 24 - 0
src/main/java/com/dragoninfo/dcuc/authweb/restcontroller/auth/vo/data/PropertyTreeVo.java

@@ -0,0 +1,24 @@
+package com.dragoninfo.dcuc.authweb.restcontroller.auth.vo.data;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * @author mazq
+ * @date 2021/4/15
+ */
+@Data
+@ApiModel("属性列表树结构对象:警种1-业务域N")
+public class PropertyTreeVo {
+    @ApiModelProperty(value = "节点名称")
+    private String label;
+    @ApiModelProperty(value = "节点code值")
+    private String code;
+    @ApiModelProperty(value = "子节点集合")
+    private List<PropertyTreeVo> child;
+    @ApiModelProperty(value = "是否是树节点 true:是树节点,child不为空。false:非树节点,child为空。")
+    private Boolean treeNode;
+}

+ 23 - 0
src/main/java/com/dragoninfo/dcuc/authweb/restcontroller/auth/vo/data/SubDataAuthQueryVo.java

@@ -0,0 +1,23 @@
+package com.dragoninfo.dcuc.authweb.restcontroller.auth.vo.data;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * @author mazq
+ * @date 2021/4/13
+ */
+@Data
+@ApiModel("主体数据权限查询参数封装对象")
+public class SubDataAuthQueryVo {
+
+    @ApiModelProperty(value = "主体id: 人员|机构id/业务域code")
+    private String subId;
+
+    @ApiModelProperty(value = "主体类型:机构:ORG|人员:USER|业务域:BUSINESS")
+    private String subType;
+
+    @ApiModelProperty(value = "数据属性授权类型 TABLE:表授权 COLUMN:列授权")
+    private String authType;
+}

+ 6 - 3
src/main/java/com/dragoninfo/dcuc/authweb/restcontroller/auth/vo/UserDataAuthAcceptVo.java → src/main/java/com/dragoninfo/dcuc/authweb/restcontroller/auth/vo/data/UserDataAuthAcceptVo.java

@@ -1,4 +1,4 @@
-package com.dragoninfo.dcuc.authweb.restcontroller.auth.vo;
+package com.dragoninfo.dcuc.authweb.restcontroller.auth.vo.data;
 
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
@@ -14,9 +14,12 @@ import java.util.List;
 @Data
 public class UserDataAuthAcceptVo {
 
-    @ApiModelProperty(value = "")
+    @ApiModelProperty(value = "人员id")
     private String userId;
 
+    @ApiModelProperty(value = "数据属性授权类型 TABLE:表授权 COLUMN:列授权")
+    private String authType;
+
     @ApiModelProperty(value = "需要授权的数据对象",dataType = "object[]")
-    private List<DataAuthVo> authVoList;
+    private List<DataAuthAcceptVo> authVoList;
 }