|
@@ -0,0 +1,226 @@
|
|
|
+package com.dragoninfo.dcuc.authweb.restcontroller.auth;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.TypeReference;
|
|
|
+import com.dragoninfo.dcuc.app.facade.IDataResourceFacade;
|
|
|
+import com.dragoninfo.dcuc.app.vo.DataResourceClassifyVo;
|
|
|
+import com.dragoninfo.dcuc.auth.auth.dto.data.*;
|
|
|
+import com.dragoninfo.dcuc.auth.auth.enumresources.SubDataAuthTypeEnum;
|
|
|
+import com.dragoninfo.dcuc.auth.auth.facade.IDataAuthFacade;
|
|
|
+import com.dragoninfo.dcuc.auth.auth.vo.BusResultVO;
|
|
|
+import com.dragoninfo.dcuc.authweb.restcontroller.auth.vo.data.*;
|
|
|
+import com.dragoninfo.dcuc.authweb.util.VersionUtils;
|
|
|
+import com.dragoninfo.dcuc.user.label.ILabelFacade;
|
|
|
+import com.dragoninfo.dcuc.user.label.dto.LabelSearchDto;
|
|
|
+import com.dragoninfo.dcuc.user.label.vo.LabelTreeVO;
|
|
|
+import com.dragoninfo.duceap.core.response.Result;
|
|
|
+import com.dragonsoft.duceap.base.entity.search.SearchDTO;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiImplicitParam;
|
|
|
+import io.swagger.annotations.ApiImplicitParams;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
+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
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Api(tags ="数据授权API")
|
|
|
+@RestController
|
|
|
+@RequestMapping("authsvr/"+ VersionUtils.VERSION_UID +"/dataauth")
|
|
|
+public class DataAuthController {
|
|
|
+
|
|
|
+ public static final String idJoin = "|";
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ IDataAuthFacade dataAuthFacade;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ILabelFacade labelFacade;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ IDataResourceFacade dataResourceFacade;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation(value = "获取属性列表,树形结构:警种1-业务域N")
|
|
|
+ @ApiImplicitParam(name = "name", value = "查询条件")
|
|
|
+ @RequestMapping(value = "businessTreeList", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
|
|
|
+ public Result<List<LabelTreeVO>> businessTreeList(@RequestBody LabelSearchDto labelSearchDto){
|
|
|
+ List<LabelTreeVO> labelTreeList = labelFacade.labelTreeList(labelSearchDto);
|
|
|
+ return Result.success(labelTreeList);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation(value = "获取所有数据资源,返回树结构")
|
|
|
+ @ApiImplicitParam(name = "attrType",value = "数据属性类型 TABLE:表 COLUMN:列")
|
|
|
+ @GetMapping(value = "allDataTree", produces = "application/json;charset=UTF-8")
|
|
|
+ public Result<List<DataResourceClassifyVo>> getAllDataResource(@RequestParam("attrType") String attrType){
|
|
|
+ log.info("allDataTree >> attrType:{}", attrType);
|
|
|
+ List<DataResourceClassifyVo> dataResourceTree = dataResourceFacade.getAllDataResourceTree(attrType);
|
|
|
+ return Result.success(dataResourceTree);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "获取数据资源,返回树结构")
|
|
|
+ @ApiImplicitParam(name = "typeCode",value = "typeCode类型(数据分级:DATA_CLASSIFY;数据资源分类:DATA_RESOURCE_CLASSIFY;数据安全级别:DATA_SECURITY_LEVEL;字段分类:COLUMN_CLASSIFY)")
|
|
|
+ @GetMapping(value = "getDataResourceTree")
|
|
|
+ public Result<DataResourceClassifyVo> getDataResource(@RequestParam("typeCode") String typeCode){
|
|
|
+ log.info("dataTree >> typeCode:{}", typeCode);
|
|
|
+ DataResourceClassifyVo dataResourceTree = dataResourceFacade.getDataResourceTree(typeCode);
|
|
|
+ return Result.success(dataResourceTree);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "人员数据授权接口")
|
|
|
+ @PostMapping(value = "userDataAuth", produces = "application/json;charset=UTF-8")
|
|
|
+ public Result<Boolean> userDataAuth(@RequestBody UserDataAuthAcceptVo vo){
|
|
|
+ List<DataAuthAcceptVo> authVoList = vo.getAuthVoList();
|
|
|
+ log.info("userDataAuth >> userDataAuthAcceptVo:{}",JSON.toJSONString(vo));
|
|
|
+ SubDataAuthDTO subDataAuthDTO = convertToSubAuthDTO(vo.getIdcard(), 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<Boolean> orgDataAuth(@RequestBody OrgDataAuthAcceptVo vo){
|
|
|
+ List<DataAuthAcceptVo> authVoList = vo.getAuthVoList();
|
|
|
+ log.info("orgDataAuth>>orgDataAuthAcceptVo:{}",JSON.toJSONString(vo));
|
|
|
+ SubDataAuthDTO subDataAuthDTO = convertToSubAuthDTO(vo.getOrgCode(), 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<Boolean> labelDataAuth(@RequestBody LabelDataAuthAcceptVo vo){
|
|
|
+ List<DataAuthAcceptVo> authVoList = vo.getAuthVoList();
|
|
|
+ log.info("labelDataAuth >> labelDataAuthAcceptVo:{}",JSON.toJSONString(vo));
|
|
|
+ SubDataAuthDTO subDataAuthDTO = convertToSubAuthDTO(vo.getBusinessCode(), 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) {
|
|
|
+ List<SubDataAuthQueryDTO> dtos = new ArrayList<>();
|
|
|
+ for (SubDataAuthQueryVo vo : queryVoList) {
|
|
|
+ SubDataAuthQueryDTO dto = new SubDataAuthQueryDTO();
|
|
|
+ BeanUtils.copyProperties(vo,dto);
|
|
|
+ }
|
|
|
+ List<DataClassifyDTO> classifyDTOS = dataAuthFacade.subDataAuthList(dtos);
|
|
|
+ List<DataClassifyVo> vos = convertToVos(classifyDTOS);
|
|
|
+ return Result.success(vos);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "查询单个主体数据权限")
|
|
|
+ @PostMapping(value = "getSubDataAuth" , produces = "application/json;charset=UTF-8")
|
|
|
+ public Result<List<DataClassifyVo>> getSubDataAuth(@RequestBody SubDataAuthQueryVo queryVo){
|
|
|
+ log.info("getSubDataAuth >> vo:{}",JSON.toJSONString(queryVo));
|
|
|
+ SubDataAuthQueryDTO queryDTO = new SubDataAuthQueryDTO();
|
|
|
+ BeanUtils.copyProperties(queryVo,queryDTO);
|
|
|
+ List<DataClassifyDTO> dtos = dataAuthFacade.getSubDataAuth(queryDTO);
|
|
|
+ List<DataClassifyVo> vos = convertToVos(dtos);
|
|
|
+ return Result.success(vos);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @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", required = false) String authType){
|
|
|
+ log.info("dataAuthInfoByUserId >> userId:{},authType:{}", userId, authType);
|
|
|
+ List<DataClassifyDTO> dtos = dataAuthFacade.userDataAuthInfoByUserId(userId, authType);
|
|
|
+ List<DataClassifyVo> vos = convertToVos(dtos);
|
|
|
+ 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",required = false) String authType){
|
|
|
+ List<DataClassifyDTO> dtos = dataAuthFacade.userDataAuthInfoByIdcard(idcard, authType);
|
|
|
+ List<DataClassifyVo> vos = convertToVos(dtos);
|
|
|
+ return Result.success(vos);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "人员视角-有权限的数据资源查询(树结构)-根据身份证号查询")
|
|
|
+ @ApiImplicitParams(value = {
|
|
|
+ @ApiImplicitParam(name = "idcard",value = "身份证号"),
|
|
|
+ @ApiImplicitParam(name = "authType",value = "数据属性授权类型 TABLE:表授权 COLUMN:列授权")
|
|
|
+ })
|
|
|
+ @GetMapping(value = "userDataTreeByIdcard" , produces = "application/json;charset=UTF-8")
|
|
|
+ public Result<List<DataResourceClassifyVo>> userDataAuthTreeByIdcard(@RequestParam("idcard") String idcard, @RequestParam(value = "authType",required = false) String authType){
|
|
|
+ List<DataResourceDTO> dtos = dataAuthFacade.userDataTreeByIdcard(idcard, authType);
|
|
|
+ //树节点dto转vo多层次拷贝,使用JSONString序列化
|
|
|
+ //字段key值要能对应上
|
|
|
+ String dtoStr = JSON.toJSONString(dtos);
|
|
|
+ List<DataResourceClassifyVo> vos = JSON.parseObject(dtoStr, new TypeReference<List<DataResourceClassifyVo>>() {{
|
|
|
+ }});
|
|
|
+ return Result.success(vos);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "分级分类清单数据")
|
|
|
+ @PostMapping(value = "dataDetailList")
|
|
|
+ public Result dataDetailList(SearchDTO searchDTO){
|
|
|
+ BusResultVO busResultVO = dataAuthFacade.dataDetailList(searchDTO);
|
|
|
+ return Result.success((long) busResultVO.getResultData().getTotalCount(),busResultVO.getResultData().getDataList());
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<DataClassifyVo> convertToVos(List<DataClassifyDTO> classifyDTOS) {
|
|
|
+ return classifyDTOS.stream().map(item -> {
|
|
|
+ DataClassifyVo vo = new DataClassifyVo();
|
|
|
+ BeanUtils.copyProperties(item, vo,"tickedDatas");
|
|
|
+ List<SubDataDTO> tickedDatas = item.getTickedDatas();
|
|
|
+ List<SubDataVo> dataVoList = tickedDatas.stream()
|
|
|
+ .map(dto->{
|
|
|
+ //拼接dataId给前端使用,保证dataId是唯一值
|
|
|
+ dto.setDataId(dto.getClassifyCode()+ idJoin + dto.getDataId());
|
|
|
+ SubDataVo subDataVo = new SubDataVo();
|
|
|
+ BeanUtils.copyProperties(dto,subDataVo);
|
|
|
+ return subDataVo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ vo.setTickedDatas(dataVoList);
|
|
|
+ return vo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ 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());
|
|
|
+ String dataId = vo.getDataId();
|
|
|
+ //除去分级分类标签的code
|
|
|
+ int index = dataId.indexOf(idJoin);
|
|
|
+ //从dataId截取拼接各种参数
|
|
|
+ int lastIndex = dataId.lastIndexOf(idJoin);
|
|
|
+ subDataDTO.setDataId(dataId.substring(index+1));
|
|
|
+ subDataDTO.setClassifyCode(dataId.substring(0,index));
|
|
|
+ subDataDTO.setDataCode(dataId.substring(lastIndex+1));
|
|
|
+ dataDTOList.add(subDataDTO);
|
|
|
+ }
|
|
|
+ subDataAuthDTO.setDataAuthList(dataDTOList);
|
|
|
+ return subDataAuthDTO;
|
|
|
+ }
|
|
|
+}
|