|
@@ -4,15 +4,19 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.lantone.common.dto.DataAuthDetailDTO;
|
|
|
-import com.lantone.common.dto.DeptDTO;
|
|
|
import com.lantone.common.dto.GetDataAuthByIdDTO;
|
|
|
+import com.lantone.common.dto.GetDataAuthDeptDTO;
|
|
|
+import com.lantone.common.dto.GetDataAuthDetailDTO;
|
|
|
+import com.lantone.common.dto.GetDataAuthDoctorDTO;
|
|
|
+import com.lantone.common.dto.GetDataAuthHospitalDTO;
|
|
|
import com.lantone.common.dto.GetDataAuthPageDTO;
|
|
|
import com.lantone.common.dto.GetDataAuthRoleDTO;
|
|
|
import com.lantone.common.dto.GetDataAuthSoftwareDTO;
|
|
|
import com.lantone.common.dto.GetDoctorPageDTO;
|
|
|
-import com.lantone.common.dto.HospitalDTO;
|
|
|
import com.lantone.common.dto.SoftwareDataAuthDetail;
|
|
|
+import com.lantone.common.enums.StatusEnum;
|
|
|
import com.lantone.common.exception.Asserts;
|
|
|
+import com.lantone.common.service.RedisService;
|
|
|
import com.lantone.common.util.DateUtil;
|
|
|
import com.lantone.common.util.EntityUtil;
|
|
|
import com.lantone.common.util.ListUtil;
|
|
@@ -25,28 +29,36 @@ import com.lantone.common.vo.UpdateAuthVO;
|
|
|
import com.lantone.dblayermbg.entity.DataAuth;
|
|
|
import com.lantone.dblayermbg.entity.DataAuthDetail;
|
|
|
import com.lantone.dblayermbg.entity.Dept;
|
|
|
-import com.lantone.dblayermbg.entity.Hospital;
|
|
|
+import com.lantone.dblayermbg.entity.DeptUser;
|
|
|
import com.lantone.dblayermbg.entity.RoleSoftwareDataAuth;
|
|
|
import com.lantone.dblayermbg.entity.SoftwareDataAuth;
|
|
|
+import com.lantone.dblayermbg.entity.User;
|
|
|
import com.lantone.dblayermbg.facade.DataAuthDetailFacade;
|
|
|
import com.lantone.dblayermbg.facade.DataAuthFacade;
|
|
|
import com.lantone.dblayermbg.facade.DeptFacade;
|
|
|
+import com.lantone.dblayermbg.facade.DeptUserFacade;
|
|
|
import com.lantone.dblayermbg.facade.DoctorFacade;
|
|
|
import com.lantone.dblayermbg.facade.HospitalFacade;
|
|
|
import com.lantone.dblayermbg.facade.HospitalUserFacade;
|
|
|
+import com.lantone.dblayermbg.facade.MedoupDoctorFacade;
|
|
|
import com.lantone.dblayermbg.facade.RoleSoftwareDataAuthFacade;
|
|
|
import com.lantone.dblayermbg.facade.SoftwareDataAuthFacade;
|
|
|
+import com.lantone.dblayermbg.facade.UserFacade;
|
|
|
import com.lantone.dblayermbg.service.impl.DataAuthDetailServiceImpl;
|
|
|
import com.lantone.dblayermbg.service.impl.RoleSoftwareDataAuthServiceImpl;
|
|
|
+import com.lantone.security.annotation.DataAuthFilter;
|
|
|
import com.lantone.security.enums.DataAuthDataTypeEnum;
|
|
|
import com.lantone.security.enums.DataAuthDetailTypeEnum;
|
|
|
import com.lantone.common.enums.IsDeleteEnum;
|
|
|
import com.lantone.security.enums.ServiceEnum;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
@@ -76,6 +88,14 @@ public class DataAuthManagementFacade {
|
|
|
private DoctorFacade doctorFacade;
|
|
|
@Autowired
|
|
|
private HospitalUserFacade hospitalUserFacade;
|
|
|
+ @Autowired
|
|
|
+ private RedisService redisService;
|
|
|
+ @Autowired
|
|
|
+ private DeptUserFacade deptUserFacade;
|
|
|
+ @Autowired
|
|
|
+ private UserFacade userFacade;
|
|
|
+ @Autowired
|
|
|
+ private MedoupDoctorFacade medoupDoctorFacade;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -307,7 +327,7 @@ public class DataAuthManagementFacade {
|
|
|
dataAuthDetail.setDepts(deptFacade.getBaseMapper().getDepts(ids));
|
|
|
}
|
|
|
//医生
|
|
|
- if(DataAuthDetailTypeEnum.DOCTOR.getKey() == detailType){
|
|
|
+ if (DataAuthDetailTypeEnum.DOCTOR.getKey() == detailType) {
|
|
|
dataAuthDetail.setDoctors(deptFacade.getBaseMapper().getDoctors(ids));
|
|
|
}
|
|
|
});
|
|
@@ -339,4 +359,102 @@ public class DataAuthManagementFacade {
|
|
|
getDataAuthPageVO.setCreator(SysUserUtils.getCurrentPrincipleId());
|
|
|
return dataAuthFacade.getBaseMapper().getDataAuthPage(getDataAuthPageVO);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param
|
|
|
+ * @Description获取用户数据权限
|
|
|
+ * @Return void
|
|
|
+ */
|
|
|
+ @Async
|
|
|
+ public void initUserDataAuth(Long userId, Long hospitalId,String softwareId) {
|
|
|
+ //获取当前用户的数据权限
|
|
|
+ List<GetDataAuthDetailDTO> dataAuthDetails = dataAuthFacade.getBaseMapper()
|
|
|
+ .getDataAuth(userId, softwareId);
|
|
|
+ Map<String, List<Long>> localDataAuthMap = new HashMap<>();
|
|
|
+ List<Long> users = new ArrayList<>();
|
|
|
+ List<Long> notUsers = new ArrayList<>();
|
|
|
+
|
|
|
+ List<Long> doctors = new ArrayList<>();
|
|
|
+
|
|
|
+ List<Long> depts = new ArrayList<>();
|
|
|
+ List<Long> notDepts = new ArrayList<>();
|
|
|
+
|
|
|
+ List<Long> hospitals = new ArrayList<>();
|
|
|
+ List<Long> notHospitals = new ArrayList<>();
|
|
|
+
|
|
|
+ if (ListUtil.isNotEmpty(dataAuthDetails)) {
|
|
|
+ Map<Integer, List<GetDataAuthDetailDTO>> dataAuthDetailMap = dataAuthDetails.stream()
|
|
|
+ .collect(Collectors.groupingBy(GetDataAuthDetailDTO::getDataType));
|
|
|
+ dataAuthDetailMap.keySet().stream().forEach(dataType -> {
|
|
|
+ //1:全部组织,2:全部科室,3:全部科室除本科室外,4:本科室,5:本医疗组,6:本人,7:自定义
|
|
|
+ //全部组织
|
|
|
+ if (DataAuthDataTypeEnum.ALL_HOSPITAL.getKey() == dataType) {
|
|
|
+ //获取当前登录用户的医院id
|
|
|
+ hospitals.add(hospitalId);
|
|
|
+ }
|
|
|
+ //全部科室
|
|
|
+ if (DataAuthDataTypeEnum.ALL_DEPT.getKey() == dataType) {
|
|
|
+ hospitals.add(hospitalId);
|
|
|
+ //获取所有科室
|
|
|
+// depts.addAll(deptFacade.list(new QueryWrapper<Dept>()
|
|
|
+// .in("hospital_id",hospitalId)
|
|
|
+// .eq("is_deleted",IsDeleteEnum.N.getKey())).stream().map(Dept::getId).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+ //除了本科室外
|
|
|
+ if (DataAuthDataTypeEnum.ALL_DEPT_NOT_SELF.getKey() == dataType) {
|
|
|
+ notDepts.addAll(deptUserFacade.list(new QueryWrapper<DeptUser>()
|
|
|
+ .eq("user_id", userId)
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())).stream()
|
|
|
+ .map(DeptUser::getDeptId).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+ //本科室
|
|
|
+ if (DataAuthDataTypeEnum.ALL_SELF_DEPT.getKey() == dataType) {
|
|
|
+ depts.addAll(deptUserFacade.list(new QueryWrapper<DeptUser>()
|
|
|
+ .eq("user_id", userId)
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())).stream()
|
|
|
+ .map(DeptUser::getDeptId).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+ //本医疗组
|
|
|
+ if (DataAuthDataTypeEnum.SELF_MEDOUP.getKey() == dataType) {
|
|
|
+ doctors.addAll(medoupDoctorFacade.getBaseMapper().getDoctorIdByMedoup(userId));
|
|
|
+ }
|
|
|
+ //本人
|
|
|
+ if (DataAuthDataTypeEnum.SELF_MEDOUP.getKey() == dataType) {
|
|
|
+ users.add(userId);
|
|
|
+ }
|
|
|
+ //自定义
|
|
|
+ if (DataAuthDataTypeEnum.CUSTOMIZE.getKey() == dataType) {
|
|
|
+ Map<Integer, List<GetDataAuthDetailDTO>> dataAuthDetailTypeMap = dataAuthDetailMap.get(dataType).stream()
|
|
|
+ .collect(Collectors.groupingBy(GetDataAuthDetailDTO::getDetailType));
|
|
|
+ dataAuthDetailTypeMap.keySet().stream().forEach(detailType -> {
|
|
|
+ List<Long> ids = dataAuthDetailTypeMap
|
|
|
+ .get(detailType).stream().map(GetDataAuthDetailDTO::getDetailId).collect(Collectors.toList());
|
|
|
+ //医院
|
|
|
+ if (DataAuthDetailTypeEnum.HOSPITAL.getKey() == detailType) {
|
|
|
+ hospitals.addAll(hospitalFacade.getBaseMapper().getHospitals(ids).stream()
|
|
|
+ .map(GetDataAuthHospitalDTO::getId).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+ //科室
|
|
|
+ if (DataAuthDetailTypeEnum.DEPT.getKey() == detailType) {
|
|
|
+ depts.addAll(deptFacade.getBaseMapper().getDepts(ids).stream()
|
|
|
+ .map(GetDataAuthDeptDTO::getId).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+ //医生
|
|
|
+ if (DataAuthDetailTypeEnum.DOCTOR.getKey() == detailType) {
|
|
|
+ doctors.addAll(deptFacade.getBaseMapper().getDoctors(ids).stream()
|
|
|
+ .map(GetDataAuthDoctorDTO::getId).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ localDataAuthMap.put("users", users);
|
|
|
+ localDataAuthMap.put("notUsers", notUsers);
|
|
|
+ localDataAuthMap.put("doctors", doctors);
|
|
|
+ localDataAuthMap.put("depts", depts);
|
|
|
+ localDataAuthMap.put("notDepts", notDepts);
|
|
|
+ localDataAuthMap.put("hospitals", hospitals);
|
|
|
+ localDataAuthMap.put("notHospitals", notHospitals);
|
|
|
+ redisService.hSetAll(hospitalId + "_" + userId + "_" + softwareId, localDataAuthMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|