|
@@ -4,28 +4,46 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.diagbot.enums.IsDeleteEnum;
|
|
import com.diagbot.enums.IsDeleteEnum;
|
|
import com.diagbot.exception.CommonErrorCode;
|
|
import com.diagbot.exception.CommonErrorCode;
|
|
import com.diagbot.exception.CommonException;
|
|
import com.diagbot.exception.CommonException;
|
|
|
|
+import com.lantone.common.dto.DataAuthDTO;
|
|
|
|
+import com.lantone.common.dto.DataAuthDetailDTO;
|
|
|
|
+import com.lantone.common.dto.HospitalDTO;
|
|
|
|
+import com.lantone.common.dto.RoleDTO;
|
|
|
|
+import com.lantone.common.dto.ServiceRoleDataAuthDetailDTO;
|
|
|
|
+import com.lantone.common.dto.SysServiceDTO;
|
|
import com.lantone.common.util.DateUtil;
|
|
import com.lantone.common.util.DateUtil;
|
|
import com.lantone.common.util.ListUtil;
|
|
import com.lantone.common.util.ListUtil;
|
|
import com.lantone.common.util.StringUtil;
|
|
import com.lantone.common.util.StringUtil;
|
|
|
|
+import com.lantone.common.vo.DataAuthDetailVO;
|
|
|
|
+import com.lantone.common.vo.RoleVO;
|
|
|
|
+import com.lantone.common.vo.ServiceDataAuthVO;
|
|
|
|
+import com.lantone.common.vo.SysServiceVO;
|
|
import com.lantone.dblayermbg.entity.DataAuth;
|
|
import com.lantone.dblayermbg.entity.DataAuth;
|
|
import com.lantone.dblayermbg.entity.DataAuthDetail;
|
|
import com.lantone.dblayermbg.entity.DataAuthDetail;
|
|
-import com.lantone.dblayermbg.entity.Role;
|
|
|
|
|
|
+import com.lantone.dblayermbg.entity.Hospital;
|
|
import com.lantone.dblayermbg.entity.RoleServiceDataAuth;
|
|
import com.lantone.dblayermbg.entity.RoleServiceDataAuth;
|
|
import com.lantone.dblayermbg.entity.ServiceDataAuth;
|
|
import com.lantone.dblayermbg.entity.ServiceDataAuth;
|
|
import com.lantone.dblayermbg.facade.DataAuthDetailFacade;
|
|
import com.lantone.dblayermbg.facade.DataAuthDetailFacade;
|
|
import com.lantone.dblayermbg.facade.DataAuthFacade;
|
|
import com.lantone.dblayermbg.facade.DataAuthFacade;
|
|
|
|
+import com.lantone.dblayermbg.facade.DeptFacade;
|
|
|
|
+import com.lantone.dblayermbg.facade.HospitalFacade;
|
|
import com.lantone.dblayermbg.facade.RoleServiceDataAuthFacade;
|
|
import com.lantone.dblayermbg.facade.RoleServiceDataAuthFacade;
|
|
import com.lantone.dblayermbg.facade.ServiceDataAuthFacade;
|
|
import com.lantone.dblayermbg.facade.ServiceDataAuthFacade;
|
|
import com.lantone.dblayermbg.service.impl.DataAuthServiceImpl;
|
|
import com.lantone.dblayermbg.service.impl.DataAuthServiceImpl;
|
|
import com.lantone.security.enums.CRUDEnum;
|
|
import com.lantone.security.enums.CRUDEnum;
|
|
-import com.lantone.security.util.SysUserUtils;
|
|
|
|
-import com.lantone.security.vo.ServiceDataAuthVO;
|
|
|
|
-import com.lantone.security.vo.SysServiceVO;
|
|
|
|
|
|
+import com.lantone.security.enums.DataAuthDataTypeEnum;
|
|
|
|
+import com.lantone.security.enums.HospitalTypeEnum;
|
|
|
|
+import com.lantone.security.enums.ServiceEnum;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Set;
|
|
|
|
+import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
|
|
/**
|
|
/**
|
|
* @ClassName: DataAuthHandleFacade
|
|
* @ClassName: DataAuthHandleFacade
|
|
@@ -44,6 +62,10 @@ public class DataAuthHandleFacade extends DataAuthServiceImpl {
|
|
private RoleServiceDataAuthFacade roleServiceDataAuthFacade;
|
|
private RoleServiceDataAuthFacade roleServiceDataAuthFacade;
|
|
@Autowired
|
|
@Autowired
|
|
private DataAuthDetailFacade dataAuthDetailFacade;
|
|
private DataAuthDetailFacade dataAuthDetailFacade;
|
|
|
|
+ @Autowired
|
|
|
|
+ private HospitalFacade hospitalFacade;
|
|
|
|
+ @Autowired
|
|
|
|
+ private DeptFacade deptFacade;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @Author songxl
|
|
* @Author songxl
|
|
@@ -54,23 +76,23 @@ public class DataAuthHandleFacade extends DataAuthServiceImpl {
|
|
* @MethodName addOrUpdate
|
|
* @MethodName addOrUpdate
|
|
*/
|
|
*/
|
|
@Transactional
|
|
@Transactional
|
|
- public void addOrUpdate(ServiceDataAuthVO serviceDataAuthVO) {
|
|
|
|
|
|
+ public boolean addOrUpdate(ServiceDataAuthVO serviceDataAuthVO) {
|
|
//1.入参校验
|
|
//1.入参校验
|
|
inputParamCheck(serviceDataAuthVO);
|
|
inputParamCheck(serviceDataAuthVO);
|
|
//2.执行增加、修改操作
|
|
//2.执行增加、修改操作
|
|
if (CRUDEnum.ADD.getKey() == serviceDataAuthVO.getType()) {
|
|
if (CRUDEnum.ADD.getKey() == serviceDataAuthVO.getType()) {
|
|
try {
|
|
try {
|
|
- addDataAuth(serviceDataAuthVO);
|
|
|
|
- }catch (Exception e)
|
|
|
|
- {
|
|
|
|
|
|
+ return addDataAuth(serviceDataAuthVO);
|
|
|
|
+ } catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, e.toString());
|
|
}
|
|
}
|
|
} else if (CRUDEnum.UPDATE.getKey() == serviceDataAuthVO.getType()) {
|
|
} else if (CRUDEnum.UPDATE.getKey() == serviceDataAuthVO.getType()) {
|
|
|
|
|
|
} else {
|
|
} else {
|
|
throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "操作码错误");
|
|
throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "操作码错误");
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -81,12 +103,13 @@ public class DataAuthHandleFacade extends DataAuthServiceImpl {
|
|
* @Return void
|
|
* @Return void
|
|
* @MethodName addDataAuth
|
|
* @MethodName addDataAuth
|
|
*/
|
|
*/
|
|
- private void addDataAuth(ServiceDataAuthVO serviceDataAuthVO) {
|
|
|
|
|
|
+ private boolean addDataAuth(ServiceDataAuthVO serviceDataAuthVO) {
|
|
//1.插入新建数据权限
|
|
//1.插入新建数据权限
|
|
DataAuth dataAuth = new DataAuth();
|
|
DataAuth dataAuth = new DataAuth();
|
|
|
|
+ // dataAuth.setCreator(Long.parseLong(SysUserUtils.getCurrentPrincipleID()));
|
|
|
|
+ BeanUtils.copyProperties(serviceDataAuthVO.getDataAuthVO(), dataAuth);
|
|
dataAuth.setCreateTime(DateUtil.now());
|
|
dataAuth.setCreateTime(DateUtil.now());
|
|
- dataAuth.setCreator(Long.parseLong(SysUserUtils.getCurrentPrincipleID()));
|
|
|
|
- BeanUtils.copyProperties(dataAuth, serviceDataAuthVO.getDataAuthVO());
|
|
|
|
|
|
+ dataAuth.setCreator(1l);
|
|
boolean dataAuthInsert = dataAuthFacade.save(dataAuth);
|
|
boolean dataAuthInsert = dataAuthFacade.save(dataAuth);
|
|
if (dataAuthInsert) {
|
|
if (dataAuthInsert) {
|
|
//2.插入成功获取新生成的数据权限名称编号data_auth_id
|
|
//2.插入成功获取新生成的数据权限名称编号data_auth_id
|
|
@@ -100,7 +123,8 @@ public class DataAuthHandleFacade extends DataAuthServiceImpl {
|
|
serviceDataAuth.setServiceId(sysServiceVO.getId());
|
|
serviceDataAuth.setServiceId(sysServiceVO.getId());
|
|
serviceDataAuth.setDataAuthId(dataAuthId);
|
|
serviceDataAuth.setDataAuthId(dataAuthId);
|
|
serviceDataAuth.setCreateTime(DateUtil.now());
|
|
serviceDataAuth.setCreateTime(DateUtil.now());
|
|
- serviceDataAuth.setCreator(Long.parseLong(SysUserUtils.getCurrentPrincipleID()));
|
|
|
|
|
|
+ serviceDataAuth.setCreator(1l);
|
|
|
|
+ // serviceDataAuth.setCreator(Long.parseLong(SysUserUtils.getCurrentPrincipleID()));
|
|
boolean serviceDataAuthInsert = serviceDataAuthFacade.save(serviceDataAuth);
|
|
boolean serviceDataAuthInsert = serviceDataAuthFacade.save(serviceDataAuth);
|
|
if (serviceDataAuthInsert) {
|
|
if (serviceDataAuthInsert) {
|
|
//4.获取上一步插入时新生成的数据权限名称与系统关联编号service_data_auth _id
|
|
//4.获取上一步插入时新生成的数据权限名称与系统关联编号service_data_auth _id
|
|
@@ -110,23 +134,27 @@ public class DataAuthHandleFacade extends DataAuthServiceImpl {
|
|
.eq("is_deleted", IsDeleteEnum.N.getKey())).get(0).getId();
|
|
.eq("is_deleted", IsDeleteEnum.N.getKey())).get(0).getId();
|
|
|
|
|
|
//5.插入数据权限系统关联表与角色管理sys_role_service_data_auth
|
|
//5.插入数据权限系统关联表与角色管理sys_role_service_data_auth
|
|
- for(Role role:serviceDataAuthVO.getRoles()){
|
|
|
|
|
|
+ for (RoleVO role : serviceDataAuthVO.getRoles()) {
|
|
RoleServiceDataAuth roleServiceDataAuth = new RoleServiceDataAuth();
|
|
RoleServiceDataAuth roleServiceDataAuth = new RoleServiceDataAuth();
|
|
roleServiceDataAuth.setRoleId(role.getId());
|
|
roleServiceDataAuth.setRoleId(role.getId());
|
|
roleServiceDataAuth.setServiceDataAuthId(serviceDataAuthId);
|
|
roleServiceDataAuth.setServiceDataAuthId(serviceDataAuthId);
|
|
roleServiceDataAuth.setCreateTime(DateUtil.now());
|
|
roleServiceDataAuth.setCreateTime(DateUtil.now());
|
|
- roleServiceDataAuth.setCreator(Long.parseLong(SysUserUtils.getCurrentPrincipleID()));
|
|
|
|
- if(!roleServiceDataAuthFacade.save(roleServiceDataAuth)){
|
|
|
|
|
|
+ roleServiceDataAuth.setCreator(1l);
|
|
|
|
+ // roleServiceDataAuth.setCreator(Long.parseLong(SysUserUtils.getCurrentPrincipleID()));
|
|
|
|
+ if (!roleServiceDataAuthFacade.save(roleServiceDataAuth)) {
|
|
throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "角色对应服务数据权限关系插入失败");
|
|
throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "角色对应服务数据权限关系插入失败");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
//6.插入数据权限详细信息。sys_data_auth_detail
|
|
//6.插入数据权限详细信息。sys_data_auth_detail
|
|
- for(DataAuthDetail dataAuthDetail:sysServiceVO.getDataAuthDetailVOS()){
|
|
|
|
- dataAuthDetail.setCreator(Long.parseLong(SysUserUtils.getCurrentPrincipleID()));
|
|
|
|
|
|
+ for (DataAuthDetailVO dataAuthDetailVO : sysServiceVO.getDataAuthDetailVOS()) {
|
|
|
|
+ DataAuthDetail dataAuthDetail = new DataAuthDetail();
|
|
|
|
+ BeanUtils.copyProperties(dataAuthDetailVO, dataAuthDetail);
|
|
|
|
+ // dataAuthDetail.setCreator(Long.parseLong(SysUserUtils.getCurrentPrincipleID()));
|
|
|
|
+ dataAuthDetail.setCreator(1l);
|
|
dataAuthDetail.setCreateTime(DateUtil.now());
|
|
dataAuthDetail.setCreateTime(DateUtil.now());
|
|
dataAuthDetail.setServiceDataAuthId(serviceDataAuthId);
|
|
dataAuthDetail.setServiceDataAuthId(serviceDataAuthId);
|
|
- if(!dataAuthDetailFacade.save(dataAuthDetail)){
|
|
|
|
|
|
+ if (!dataAuthDetailFacade.save(dataAuthDetail)) {
|
|
throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "数据权限明细插入失败");
|
|
throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "数据权限明细插入失败");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -139,6 +167,7 @@ public class DataAuthHandleFacade extends DataAuthServiceImpl {
|
|
} else {
|
|
} else {
|
|
throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "数据权限插入失败");
|
|
throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "数据权限插入失败");
|
|
}
|
|
}
|
|
|
|
+ return true;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -167,4 +196,124 @@ public class DataAuthHandleFacade extends DataAuthServiceImpl {
|
|
throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "系统对应数据权限明细未选择");
|
|
throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "系统对应数据权限明细未选择");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @Author songxl
|
|
|
|
+ * @Description通过数据权限id和角色id获取数据权限详情
|
|
|
|
+ * @Date 2021/7/22
|
|
|
|
+ * @Param [serviceDataAuthVO]
|
|
|
|
+ * @Return com.lantone.security.dto.DataAuthDTO
|
|
|
|
+ * @MethodName getDataAuthById
|
|
|
|
+ */
|
|
|
|
+ public DataAuthDTO getDataAuthById(ServiceDataAuthVO serviceDataAuthVO) {
|
|
|
|
+ DataAuthDTO dataAuthDTO = new DataAuthDTO();
|
|
|
|
+ List<ServiceRoleDataAuthDetailDTO> serviceRoleDataAuthDetailDTOS = this.baseMapper.getDataAuthById(serviceDataAuthVO);
|
|
|
|
+ if (ListUtil.isNotEmpty(serviceRoleDataAuthDetailDTOS)) {
|
|
|
|
+ //1.添加数据权限信息
|
|
|
|
+ dataAuthDTO.setId(serviceRoleDataAuthDetailDTOS.get(0).getDataAuthId());
|
|
|
|
+ dataAuthDTO.setAuthName(serviceRoleDataAuthDetailDTOS.get(0).getDataAuthName());
|
|
|
|
+ dataAuthDTO.setStatus(serviceRoleDataAuthDetailDTOS.get(0).getStatus());
|
|
|
|
+ //2.获取系统信息
|
|
|
|
+ Set<Long> serviceSet = serviceRoleDataAuthDetailDTOS.stream().map(ServiceRoleDataAuthDetailDTO::getServiceId).collect(Collectors.toSet());
|
|
|
|
+ List<SysServiceDTO> sysServiceDTOS = new ArrayList<>();
|
|
|
|
+ serviceSet.stream().forEach(id -> {
|
|
|
|
+ //3.添加服务信息
|
|
|
|
+ SysServiceDTO sysServiceDTO = new SysServiceDTO();
|
|
|
|
+ sysServiceDTO.setId(id);
|
|
|
|
+ sysServiceDTO.setName(ServiceEnum.getName(id.intValue()));
|
|
|
|
+ //4.1添加数据权限详情列表
|
|
|
|
+ List<ServiceRoleDataAuthDetailDTO> oneServiceRoleDataAuthDetailDTOS = serviceRoleDataAuthDetailDTOS.stream()
|
|
|
|
+ .filter(serviceRoleDataAuthDetailDTO -> serviceRoleDataAuthDetailDTO.getServiceId() == id).collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ List<DataAuthDetailDTO> dataAuthDetailDTOS = new ArrayList<>();
|
|
|
|
+ //4.2.1是否获取当前组织-科室信息
|
|
|
|
+ AtomicBoolean selectFalg = new AtomicBoolean(false);
|
|
|
|
+ oneServiceRoleDataAuthDetailDTOS.stream().forEach(serviceRoleDataAuthDetailDTO -> {
|
|
|
|
+ DataAuthDetailDTO dataAuthDetailDTO = new DataAuthDetailDTO();
|
|
|
|
+ dataAuthDetailDTO.setId(serviceRoleDataAuthDetailDTO.getDetail());
|
|
|
|
+ dataAuthDetailDTO.setDataType(serviceRoleDataAuthDetailDTO.getDataType());
|
|
|
|
+ dataAuthDetailDTO.setDetailType(serviceRoleDataAuthDetailDTO.getDetailType());
|
|
|
|
+ dataAuthDetailDTO.setDetailId(serviceRoleDataAuthDetailDTO.getDetailId());
|
|
|
|
+ if (DataAuthDataTypeEnum.CUSTOMIZE.getKey() == serviceRoleDataAuthDetailDTO.getDataType()) {
|
|
|
|
+ selectFalg.set(true);
|
|
|
|
+ }
|
|
|
|
+ dataAuthDetailDTOS.add(dataAuthDetailDTO);
|
|
|
|
+ });
|
|
|
|
+ //4.2.3selectFalg为true时查询组织-科室信息
|
|
|
|
+ getDeptDetial(dataAuthDetailDTOS);
|
|
|
|
+ sysServiceDTO.setDataAuthDetailDTOS(dataAuthDetailDTOS);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //5.添加角色列表
|
|
|
|
+ List<RoleDTO> roleDTOS = new ArrayList<>();
|
|
|
|
+ RoleDTO role = new RoleDTO();
|
|
|
|
+ role.setId(serviceRoleDataAuthDetailDTOS.get(0).getRoleId());
|
|
|
|
+ role.setName(serviceRoleDataAuthDetailDTOS.get(0).getRoleName());
|
|
|
|
+ roleDTOS.add(role);
|
|
|
|
+ sysServiceDTO.setRoles(roleDTOS);
|
|
|
|
+ sysServiceDTOS.add(sysServiceDTO);
|
|
|
|
+ });
|
|
|
|
+ dataAuthDTO.setSysServiceDTOS(sysServiceDTOS);
|
|
|
|
+ } else {
|
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "请检查角色id或数据权限id");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return dataAuthDTO;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @Author songxl
|
|
|
|
+ * @Description 获取组织-科室信息以及自定义科室
|
|
|
|
+ * @Date 2021/7/22
|
|
|
|
+ * @Param [dataAuthDetailDTO]
|
|
|
|
+ * @Return void
|
|
|
|
+ * @MethodName getDeptDetial
|
|
|
|
+ */
|
|
|
|
+ public void getDeptDetial(List<DataAuthDetailDTO> dataAuthDetailDTOS) {
|
|
|
|
+ //1.获取医院信息
|
|
|
|
+ HospitalDTO hospitalDTO = new HospitalDTO();
|
|
|
|
+ Hospital hospital = hospitalFacade.list(new QueryWrapper<Hospital>()
|
|
|
|
+ .eq("id", 2l)//###
|
|
|
|
+ .eq("type", "1")//###
|
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())).get(0);
|
|
|
|
+ BeanUtils.copyProperties(hospital,hospitalDTO);
|
|
|
|
+ //获取当前登录用户的组织信息
|
|
|
|
+ List<HospitalDTO> hospitalDTOS = getHospitalInfo(hospitalDTO);
|
|
|
|
+ getAllHospitalDTO(hospitalDTOS);
|
|
|
|
+ //2.获取科室信息
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void getAllHospitalDTO(List<HospitalDTO> hospitalDTOS) {
|
|
|
|
+ if(ListUtil.isNotEmpty(hospitalDTOS)){
|
|
|
|
+ for(HospitalDTO tempHospitalDTO:hospitalDTOS){
|
|
|
|
+ getAllHospitalDTO(getHospitalInfo(tempHospitalDTO));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @Author songxl
|
|
|
|
+ * @Description获取医院信息
|
|
|
|
+ * @Date 2021/7/22
|
|
|
|
+ * @Param [parentId]
|
|
|
|
+ * @Return java.util.List<com.lantone.common.dto.HospitalDTO>
|
|
|
|
+ * @MethodName getHospitalInfo
|
|
|
|
+ */
|
|
|
|
+ private List<HospitalDTO> getHospitalInfo(HospitalDTO hospitalDTO) {
|
|
|
|
+ List<HospitalDTO> hospitalDTOS = new ArrayList<>();
|
|
|
|
+ if(hospitalDTO.getId()!=null){
|
|
|
|
+ List<Hospital> hospitals = hospitalFacade.list(new QueryWrapper<Hospital>()
|
|
|
|
+ .eq("parent_id",hospitalDTO.getId())
|
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey()));
|
|
|
|
+ hospitals.stream().forEach(hospital -> {
|
|
|
|
+ HospitalDTO tempHospitalDTO = new HospitalDTO();
|
|
|
|
+ BeanUtils.copyProperties(hospital,tempHospitalDTO);
|
|
|
|
+ hospitalDTOS.add(tempHospitalDTO);
|
|
|
|
+ });
|
|
|
|
+ hospitalDTO.setHospitalDTOS(hospitalDTOS);
|
|
|
|
+ }
|
|
|
|
+ return hospitalDTOS;
|
|
|
|
+ }
|
|
}
|
|
}
|