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.auth.auth.vo.DataAuthAcceptVo; import com.dragoninfo.dcuc.auth.auth.vo.DataAuthTreeReactVo; import com.dragoninfo.dcuc.auth.sub.dto.LabelSearchDTO; import com.dragoninfo.dcuc.auth.sub.facade.IUserCenterApiFacade; import com.dragoninfo.dcuc.authweb.restcontroller.auth.vo.data.*; import com.dragoninfo.dcuc.auth.sub.vo.LabelTreeVO; import com.dragoninfo.dcuc.authweb.util.VersionUtils; 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.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 IUserCenterApiFacade userCenterApiFacade; @Autowired IDataResourceFacade dataResourceFacade; @ApiOperation(value = "获取属性列表,树形结构:警种1-业务域N") @ApiImplicitParam(name = "name", value = "查询条件") @GetMapping(value = "businessTreeList", produces = "application/json;charset=UTF-8") public Result> businessTreeList(){ LabelSearchDTO labelSearchDTO = new LabelSearchDTO(); labelSearchDTO.setShowAll(false); List labelTreeList = userCenterApiFacade.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> getAllDataResource(@RequestParam(value = "attrType", required = false) String attrType){ log.info("allDataTree >> attrType:{}", attrType); List 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 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 userDataAuth(@RequestBody UserDataAuthAcceptVo vo){ List 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("tree-react") public Result> treeReact(@RequestBody DataAuthTreeReactVo treeReactVo) { List classifyDTOS = dataAuthFacade.treeReact(treeReactVo); List vos = convertToVos(classifyDTOS); return Result.success(vos); } @ApiOperation(value = "机构数据授权接口") @PostMapping(value = "orgDataAuth", produces = "application/json;charset=UTF-8") public Result orgDataAuth(@RequestBody OrgDataAuthAcceptVo vo){ List 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 labelDataAuth(@RequestBody LabelDataAuthAcceptVo vo){ List 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 queryVoList) { List dtos = new ArrayList<>(); for (SubDataAuthQueryVo vo : queryVoList) { SubDataAuthQueryDTO dto = new SubDataAuthQueryDTO(); BeanUtils.copyProperties(vo,dto); } List classifyDTOS = dataAuthFacade.subDataAuthList(dtos); List vos = convertToVos(classifyDTOS); return Result.success(vos); } @ApiOperation(value = "查询单个主体数据权限") @PostMapping(value = "getSubDataAuth" , produces = "application/json;charset=UTF-8") public Result> getSubDataAuth(@RequestBody SubDataAuthQueryVo queryVo){ log.info("getSubDataAuth >> vo:{}",JSON.toJSONString(queryVo)); SubDataAuthQueryDTO queryDTO = new SubDataAuthQueryDTO(); BeanUtils.copyProperties(queryVo,queryDTO); List dtos = dataAuthFacade.getSubDataAuth(queryDTO); List 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> userDataAuthInfoById(@RequestParam("userId") String userId, @RequestParam(value = "authType", required = false) String authType){ log.info("dataAuthInfoByUserId >> userId:{},authType:{}", userId, authType); List dtos = dataAuthFacade.userDataAuthInfoByUserId(userId, authType); List 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> userDataAuthInfoByIdcard(@RequestParam("idcard") String idcard, @RequestParam(value = "authType",required = false) String authType){ List dtos = dataAuthFacade.userDataAuthInfoByIdcard(idcard, authType); List 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> userDataAuthTreeByIdcard(@RequestParam("idcard") String idcard, @RequestParam(value = "authType",required = false) String authType){ List dtos = dataAuthFacade.userDataTreeByIdcard(idcard, authType); //树节点dto转vo多层次拷贝,使用JSONString序列化 //字段key值要能对应上 String dtoStr = JSON.toJSONString(dtos); List vos = JSON.parseObject(dtoStr, new TypeReference>() {{ }}); 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 convertToVos(List classifyDTOS) { return classifyDTOS.stream().map(item -> { DataClassifyVo vo = new DataClassifyVo(); BeanUtils.copyProperties(item, vo,"tickedDatas"); List tickedDatas = item.getTickedDatas(); List 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 authVoList) { SubDataAuthDTO subDataAuthDTO = new SubDataAuthDTO(subId,subType,authType); List dataDTOList = new ArrayList<>(); for (DataAuthAcceptVo vo : authVoList) { SubDataDTO subDataDTO = new SubDataDTO(); String dataId = vo.getDataId(); //除去分级分类标签的code int index = dataId.indexOf(idJoin); //从dataId截取拼接各种参数 subDataDTO.setDataId(dataId); subDataDTO.setClassifyCode(vo.getClassifyCode()); dataDTOList.add(subDataDTO); } subDataAuthDTO.setDataAuthList(dataDTOList); return subDataAuthDTO; } }