|
|
@@ -1,30 +1,34 @@
|
|
|
package com.zd.laboratory.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.convert.Convert;
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import com.zd.model.domain.DTO.UserPhoneInfo;
|
|
|
import com.zd.common.core.annotation.DataScope;
|
|
|
import com.zd.common.core.exception.ServiceException;
|
|
|
import com.zd.common.core.utils.*;
|
|
|
+import com.zd.laboratory.api.dto.CheckSubjectDto;
|
|
|
+import com.zd.laboratory.api.dto.QuerySubListParam;
|
|
|
+import com.zd.laboratory.api.vo.CollegeInfoVo;
|
|
|
import com.zd.laboratory.api.vo.LabSubClassVO;
|
|
|
import com.zd.laboratory.domain.*;
|
|
|
-import com.zd.laboratory.domain.vo.LabClassifiedVo;
|
|
|
-import com.zd.laboratory.domain.vo.LabClasstypeVo;
|
|
|
-import com.zd.laboratory.domain.vo.LabSubjectVO;
|
|
|
-import com.zd.laboratory.domain.vo.XxpClassifyDetailVO;
|
|
|
-import com.zd.laboratory.interfaces.SysProperties;
|
|
|
+import com.zd.laboratory.domain.vo.*;
|
|
|
import com.zd.laboratory.mapper.LabHazardSubjectRelationMapper;
|
|
|
import com.zd.laboratory.mapper.LabQpSubjectRelationMapper;
|
|
|
import com.zd.laboratory.mapper.LabSubjectMapper;
|
|
|
-import com.zd.laboratory.service.ILabHazardSubjectRelationService;
|
|
|
-import com.zd.laboratory.service.ILabSubjectService;
|
|
|
-import com.zd.laboratory.service.IXxpClassifySubjectService;
|
|
|
+import com.zd.laboratory.service.*;
|
|
|
+import com.zd.model.constant.HttpStatus;
|
|
|
import com.zd.model.constant.SecurityConstants;
|
|
|
import com.zd.model.constant.UserConstants;
|
|
|
import com.zd.model.domain.R;
|
|
|
+import com.zd.model.domain.ResultData;
|
|
|
import com.zd.model.domain.per.PerPrefix;
|
|
|
+import com.zd.model.entity.SysDept;
|
|
|
import com.zd.model.entity.SysUser;
|
|
|
import com.zd.model.entity.TotalByID;
|
|
|
import com.zd.model.enums.HazardTypeEnum;
|
|
|
import com.zd.system.api.entity.SysDictData;
|
|
|
+import com.zd.system.api.feign.RemoteDeptService;
|
|
|
import com.zd.system.api.feign.RemoteUserService;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.jsoup.Jsoup;
|
|
|
@@ -35,7 +39,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import java.io.File;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -63,6 +66,25 @@ public class LabSubjectServiceImpl implements ILabSubjectService {
|
|
|
private IXxpClassifySubjectService classifySubjectService;
|
|
|
@Autowired
|
|
|
private FileConfigUtils fileConfigUtils;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RemoteDeptService remoteDeptService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ILabMoldService labMoldService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ILabSafeClasstypeService labSafeClasstypeService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ILabSafeClassifiedService labSafeClassifiedService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ILabBuildingService labBuildingService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ILabMoldService labmoldService;
|
|
|
+
|
|
|
/**
|
|
|
* 查询实验室
|
|
|
*
|
|
|
@@ -689,4 +711,303 @@ public class LabSubjectServiceImpl implements ILabSubjectService {
|
|
|
public Integer isAdminOrSafeUser(Long subjectId, Long userId) {
|
|
|
return labSubjectMapper.isAdminOrSafeUser(subjectId,userId);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<CheckSubjectDto> findSubjectInfoList(String subIds) {
|
|
|
+ Long[] longs = cn.hutool.core.convert.Convert.toLongArray(subIds);
|
|
|
+ return labSubjectMapper.findSubjectInfoList(longs);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<CheckSubjectDto> conditionSubjectInfo(SubejctInfoBo subejctInfoBo) {
|
|
|
+ List<CheckSubjectDto> checkSubjectDtos = labSubjectMapper.conditionSubjectInfo(subejctInfoBo);
|
|
|
+ return checkSubjectDtos;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<CollegeInfoVo> conditionCollegeInfo(String searchValue) {
|
|
|
+ List<CollegeInfoVo> collegeInfoVos = labSubjectMapper.conditionCollegeInfo(searchValue);
|
|
|
+ Optional.ofNullable(collegeInfoVos).orElseGet(Collections::emptyList).stream().forEach(i->{
|
|
|
+ int subNum = labSubjectMapper.getCollegeSubCount(i.getDeptId());
|
|
|
+ i.setSubNum(subNum);
|
|
|
+ });
|
|
|
+ List<CollegeInfoVo> collect = collegeInfoVos.stream().filter(collegeInfoVo -> collegeInfoVo.getSubNum() != 0).collect(Collectors.toList());
|
|
|
+ return collect;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<CheckSubjectDto> findSubInfoByDeptIds(QuerySubListParam querySubListParam) {
|
|
|
+ if (Objects.isNull(querySubListParam.getDeptIds()) || querySubListParam.getDeptIds().length == 0) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ if(querySubListParam.getDeptId() != null){
|
|
|
+ List<Long> subjectIds = Arrays.stream(querySubListParam.getDeptIds()).filter(deptId -> deptId.equals(querySubListParam.getDeptId())).collect(Collectors.toList());
|
|
|
+ Long[] longs = Convert.toLongArray(subjectIds);
|
|
|
+ querySubListParam.setDeptIds(longs);
|
|
|
+ }
|
|
|
+ return labSubjectMapper.findSubInfoByDeptIds(querySubListParam);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<Long, Map<String, Object>> getPositionBySubId(String subIds) {
|
|
|
+ Long[] longs = Convert.toLongArray(subIds.split(","));
|
|
|
+ List<Map<String, Object>> positionBySubId = labSubjectMapper.getPositionBySubId(longs);
|
|
|
+ if (positionBySubId.isEmpty()){
|
|
|
+ return new HashMap<>();
|
|
|
+ }
|
|
|
+ Map<Long,Map<String,Object>> map = new HashMap<>();
|
|
|
+ for (Map<String, Object> stringStringMap : positionBySubId) {
|
|
|
+ Long subId = (Long) stringStringMap.get("subId");
|
|
|
+ map.put(subId,stringStringMap);
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Integer getAllSubNum() {
|
|
|
+ return labSubjectMapper.getAllSubNum();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Integer hasSubCollegeNum() {
|
|
|
+ return labSubjectMapper.hasSubCollegeNum();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Long> getSubIds() {
|
|
|
+ return labSubjectMapper.getSubIds();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Long> getCollegeSubIds(Long[] deptIds) {
|
|
|
+ return labSubjectMapper.getCollegeSubIds(deptIds);
|
|
|
+ }
|
|
|
+
|
|
|
+// @DataScope(deptAlias = "s", permi = PerPrefix.LABORATORY_SUBJECT)
|
|
|
+ @Override
|
|
|
+ public List <LabSubject> buildBySub(LabSubject labSubject) {
|
|
|
+ return labSubjectMapper.buildBySub(labSubject);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public List<SubjectUploadTemplateFail> importSubjectData(List<SubjectUploadTemplate> subjectData) {
|
|
|
+ if (StringUtils.isNull(subjectData) || subjectData.size() == 0) {
|
|
|
+ throw new ServiceException("导入实验室数据不能为空!");
|
|
|
+ }
|
|
|
+ List<SubjectUploadTemplateFail> subjectUploadTemplateFail = checkData(subjectData);
|
|
|
+ return subjectUploadTemplateFail;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询安全信息
|
|
|
+ *
|
|
|
+ * @param ids
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<LabSubjectVO> selectLabSubSafeInfoByIds(Long... ids) {
|
|
|
+ return labSubjectMapper.selectLabSubSafeInfoByIds(ids);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private List<SubjectUploadTemplateFail> checkData(List<SubjectUploadTemplate> subjectData) {
|
|
|
+ List<SubjectUploadTemplateFail> failList = new ArrayList<>();
|
|
|
+ //查询所有实验室、学院、楼栋、楼层、安全分类、安全分级信息
|
|
|
+ List<LabSubjectVO> labSubjectVOS = labSubjectMapper.selectLabSubjectVOList(new LabSubject());
|
|
|
+ List<String> subNameList = Optional.ofNullable(labSubjectVOS).orElseGet(Collections::emptyList).stream().map(LabSubjectVO::getName).collect(Collectors.toList());
|
|
|
+
|
|
|
+ //学院
|
|
|
+ R<List<SysDept>> deptList = remoteDeptService.getDeptList(new SysDept());
|
|
|
+ LinkedHashMap<String, List<SysDept>> collegeMap = new LinkedHashMap<>();
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+ if (HttpStatus.SUCCESS == deptList.getCode() && !deptList.getData().isEmpty()) {
|
|
|
+ for (SysDept dept : deptList.getData()) {
|
|
|
+ sb.append(dept.getDeptId()).append(",");
|
|
|
+ }
|
|
|
+ collegeMap = Optional.ofNullable(deptList.getData()).orElseGet(Collections::emptyList).stream().filter(sysDept -> sysDept.getDeptName() != null).collect(Collectors.groupingBy(SysDept::getDeptName, LinkedHashMap::new, Collectors.toList()));
|
|
|
+ }
|
|
|
+
|
|
|
+ //楼栋
|
|
|
+ String deptIds = sb.substring(0, sb.length() - 1);
|
|
|
+ ResultData<List<SysDept>> resultData = remoteDeptService.getDeptListByDeptIds(deptIds);
|
|
|
+ LinkedHashMap<String, List<SysDept>> buildMap = new LinkedHashMap<>();
|
|
|
+ if (HttpStatus.SUCCESS == resultData.getCode() && !resultData.getData().isEmpty()) {
|
|
|
+ buildMap = Optional.ofNullable(resultData.getData()).orElseGet(Collections::emptyList).stream().filter(sysDept -> sysDept.getDeptName() != null).collect(Collectors.groupingBy(SysDept::getDeptName, LinkedHashMap::new, Collectors.toList()));
|
|
|
+ }
|
|
|
+
|
|
|
+ //楼层
|
|
|
+ List<LabBuildingInfoVO> buildLlist = labBuildingService.labInfoLayout(new LabBuildingVO());
|
|
|
+ LinkedHashMap<String, List<LabBuilding>> floorMap = Optional.ofNullable(buildLlist).orElseGet(Collections::emptyList).stream().filter(labBuilding -> labBuilding.getName() != null).collect(Collectors.groupingBy(LabBuilding::getName, LinkedHashMap::new, Collectors.toList()));
|
|
|
+
|
|
|
+ //分类
|
|
|
+ List<LabSafeClasstype> labSafeClasstypes = labSafeClasstypeService.selectLabSafeClasstypeList(new LabSafeClasstype());
|
|
|
+ LinkedHashMap<String, List<LabSafeClasstype>> typeNameMap = Optional.ofNullable(labSafeClasstypes).orElseGet(Collections::emptyList).stream().filter(labSafeClasstype -> labSafeClasstype.getTypeName() != null).collect(Collectors.groupingBy(LabSafeClasstype::getTypeName, LinkedHashMap::new, Collectors.toList()));
|
|
|
+
|
|
|
+ //分级
|
|
|
+ List<LabSafeClassified> labSafeClassifieds = labSafeClassifiedService.selectLabSafeClassifiedList(new LabSafeClassified());
|
|
|
+ LinkedHashMap<String, List<LabSafeClassified>> levelMap = Optional.ofNullable(labSafeClassifieds).orElseGet(Collections::emptyList).stream().filter(labSafeClassified -> labSafeClassified.getClassifiedName() != null).collect(Collectors.groupingBy(LabSafeClassified::getClassifiedName, LinkedHashMap::new, Collectors.toList()));
|
|
|
+
|
|
|
+ //实验室类型
|
|
|
+ List<LabMold> labMolds = labmoldService.selectLabMoldList(new LabMold());
|
|
|
+ LinkedHashMap<String, List<LabMold>> moldMap = Optional.ofNullable(labMolds).orElseGet(Collections::emptyList).stream().filter(labMold -> labMold.getMoldName() != null).collect(Collectors.groupingBy(LabMold::getMoldName, LinkedHashMap::new, Collectors.toList()));
|
|
|
+
|
|
|
+ for (SubjectUploadTemplate subjectUploadTemplate : subjectData) {
|
|
|
+ SubjectUploadTemplateFail subjectUploadTemplateFail = new SubjectUploadTemplateFail();
|
|
|
+ StringBuffer failStr = new StringBuffer();
|
|
|
+ LabSubject labSubject = new LabSubject();
|
|
|
+ // 校验是否装入错误数据
|
|
|
+ boolean flag = Boolean.TRUE;
|
|
|
+ //验证实验室名称
|
|
|
+ if (StringUtils.isBlank(subjectUploadTemplate.getName())) {
|
|
|
+ failStr.append("实验室名称不能为空、");
|
|
|
+ flag = false;
|
|
|
+ } else {
|
|
|
+ if (!subNameList.isEmpty() && subNameList.contains(subjectUploadTemplate.getName())) {
|
|
|
+ failStr.append("实验室名称重复、");
|
|
|
+ flag = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //验证房间号
|
|
|
+ if (StringUtils.isBlank(subjectUploadTemplate.getRoom())) {
|
|
|
+ failStr.append("房间号不能为空、");
|
|
|
+ flag = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ //验证学院
|
|
|
+ if (StringUtils.isBlank(subjectUploadTemplate.getDeptName())) {
|
|
|
+ failStr.append("学院不能为空、");
|
|
|
+ flag = false;
|
|
|
+ } else {
|
|
|
+ if (!collegeMap.isEmpty() && collegeMap.containsKey(subjectUploadTemplate.getDeptName())) {
|
|
|
+ List<SysDept> sysDepts = collegeMap.get(subjectUploadTemplate.getDeptName());
|
|
|
+ labSubject.setDeptId(sysDepts.get(0).getDeptId());
|
|
|
+ } else {
|
|
|
+ failStr.append("学院信息不存在、");
|
|
|
+ flag = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //验证楼栋
|
|
|
+ if (StringUtils.isBlank(subjectUploadTemplate.getBuildName())) {
|
|
|
+ failStr.append("楼栋信息不能为空、");
|
|
|
+ flag = false;
|
|
|
+ } else {
|
|
|
+ if (!buildMap.isEmpty() && buildMap.containsKey(subjectUploadTemplate.getBuildName())) {
|
|
|
+ List<SysDept> sysDepts = buildMap.get(subjectUploadTemplate.getBuildName());
|
|
|
+ labSubject.setBuildId(sysDepts.get(0).getDeptId());
|
|
|
+ } else {
|
|
|
+ failStr.append("楼栋信息不存在、");
|
|
|
+ flag = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //验证楼层
|
|
|
+ if (StringUtils.isBlank(subjectUploadTemplate.getFloorName())) {
|
|
|
+ failStr.append("楼层信息不能为空、");
|
|
|
+ flag = false;
|
|
|
+ } else {
|
|
|
+ if (!floorMap.isEmpty() && floorMap.containsKey(subjectUploadTemplate.getFloorName())) {
|
|
|
+ List<LabBuilding> labBuildings = floorMap.get(subjectUploadTemplate.getFloorName());
|
|
|
+ List<LabBuilding> buildings = labBuildings.stream().filter(i -> i.getDeptId().equals(labSubject.getBuildId())).collect(Collectors.toList());
|
|
|
+ if (!buildings.isEmpty()) {
|
|
|
+ labSubject.setFloorId(buildings.get(0).getId());
|
|
|
+ }else {
|
|
|
+ failStr.append("楼层信息与学院楼栋楼层不匹配、");
|
|
|
+ flag = false;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ failStr.append("楼层信息不存在、");
|
|
|
+ flag = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //验证分类
|
|
|
+ if (StringUtils.isBlank(subjectUploadTemplate.getTypeName())) {
|
|
|
+ failStr.append("安全分类信息不能为空、");
|
|
|
+ flag = false;
|
|
|
+ } else {
|
|
|
+ if (!typeNameMap.isEmpty() && typeNameMap.containsKey(subjectUploadTemplate.getTypeName())) {
|
|
|
+ List<LabSafeClasstype> labSafeClasstypes1 = typeNameMap.get(subjectUploadTemplate.getTypeName());
|
|
|
+ labSubject.setTypeId(labSafeClasstypes1.get(0).getId());
|
|
|
+ } else {
|
|
|
+ failStr.append("安全分类信息不存在、");
|
|
|
+ flag = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //验证分级
|
|
|
+ if (StringUtils.isBlank(subjectUploadTemplate.getClassifiedName())) {
|
|
|
+ failStr.append("安全分级信息不能为空、");
|
|
|
+ flag = false;
|
|
|
+ } else {
|
|
|
+ if (!levelMap.isEmpty() && levelMap.containsKey(subjectUploadTemplate.getClassifiedName())) {
|
|
|
+ List<LabSafeClassified> labSafeClassifieds1 = levelMap.get(subjectUploadTemplate.getClassifiedName());
|
|
|
+ labSubject.setLevel(labSafeClassifieds1.get(0).getId());
|
|
|
+ } else {
|
|
|
+ failStr.append("安全分级信息不存在、");
|
|
|
+ flag = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //实验室类型
|
|
|
+ if (StringUtils.isBlank(subjectUploadTemplate.getMoldName())) {
|
|
|
+ failStr.append("实验室类型不能为空、");
|
|
|
+ flag = false;
|
|
|
+ } else {
|
|
|
+ if (!moldMap.isEmpty() && moldMap.containsKey(subjectUploadTemplate.getMoldName())) {
|
|
|
+ List<LabMold> labMoldlist = moldMap.get(subjectUploadTemplate.getMoldName());
|
|
|
+ labSubject.setMoldId(labMoldlist.get(0).getId());
|
|
|
+ } else {
|
|
|
+ failStr.append("实验室类型不存在、");
|
|
|
+ flag = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (flag) {
|
|
|
+ BeanUtils.copyProperties(subjectUploadTemplate, labSubject);
|
|
|
+ labSubject.setCreateTime(DateTime.now());
|
|
|
+ labSubject.setUserId(SecurityUtils.getUserId());
|
|
|
+ labSubject.setCreateBy(SecurityUtils.getUsername());
|
|
|
+ labSubjectMapper.insertLabSubject(labSubject);
|
|
|
+ }else {
|
|
|
+ BeanUtils.copyProperties(subjectUploadTemplate, subjectUploadTemplateFail);
|
|
|
+ subjectUploadTemplateFail.setFailCause(failStr);
|
|
|
+ failList.add(subjectUploadTemplateFail);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return failList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<UserPhoneInfo> selectAdminAndSafeAdminById(Long subId) {
|
|
|
+ LabSubject labSubject = selectLabSubjectById(subId);
|
|
|
+ List<UserPhoneInfo> userPhoneInfoList = new ArrayList<>();
|
|
|
+ R<SysUser> sysUserR = userService.getUserInfoByUserId(labSubject.getAdminId(),SecurityConstants.INNER);
|
|
|
+ if (HttpStatus.SUCCESS == sysUserR.getCode()) {
|
|
|
+ SysUser sysUser = sysUserR.getData();
|
|
|
+ UserPhoneInfo userPhoneInfo = new UserPhoneInfo();
|
|
|
+ userPhoneInfo.setPhone(sysUser.getPhonenumber());
|
|
|
+ userPhoneInfo.setNickName(sysUser.getNickName());
|
|
|
+ userPhoneInfo.setRole("实验室负责人");
|
|
|
+ userPhoneInfoList.add(userPhoneInfo);
|
|
|
+ }
|
|
|
+ String[] split = labSubject.getSafeUserId().split(",");
|
|
|
+ if(split != null && split.length >0){
|
|
|
+ for (String userId : split) {
|
|
|
+ R<SysUser> userR = userService.getUserInfoByUserId(Long.valueOf(userId), SecurityConstants.INNER);
|
|
|
+ if (HttpStatus.SUCCESS == userR.getCode()) {
|
|
|
+ SysUser user = userR.getData();
|
|
|
+ UserPhoneInfo userPhoneInfo1 = new UserPhoneInfo();
|
|
|
+ userPhoneInfo1.setPhone(user.getPhonenumber());
|
|
|
+ userPhoneInfo1.setNickName(user.getNickName());
|
|
|
+ userPhoneInfo1.setRole("安全责任人");
|
|
|
+ userPhoneInfoList.add(userPhoneInfo1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return userPhoneInfoList;
|
|
|
+ }
|
|
|
}
|