|
@@ -21,6 +21,7 @@ import com.rongwei.sfcommon.sys.dao.AspShiftTimeDao;
|
|
|
import com.rongwei.sfcommon.sys.dao.CheckTemplateDao;
|
|
|
import com.rongwei.sfcommon.sys.service.*;
|
|
|
import com.rongwei.sfcommon.utils.MlConstants;
|
|
|
+import org.apache.logging.log4j.util.Strings;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -29,7 +30,6 @@ import org.springframework.stereotype.Service;
|
|
|
import java.util.*;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
-import java.util.stream.Stream;
|
|
|
|
|
|
import static com.rongwei.safecommon.utils.JSCommonUtils.parameterCheck;
|
|
|
import static com.rongwei.safecommon.utils.JSCommonUtils.streamCodeGeneration;
|
|
@@ -81,6 +81,8 @@ public class CheckTemplateServiceImpl extends ServiceImpl<CheckTemplateDao, Chec
|
|
|
private ThemeCheckContentService themeCheckContentService;
|
|
|
@Autowired
|
|
|
private AspRiskUnitServiceImpl aspRiskUnitService;
|
|
|
+ @Autowired
|
|
|
+ private AspPersonnelCheckConfigService aspPersonnelCheckConfigService;
|
|
|
|
|
|
/**
|
|
|
* 通用Map转自定义业务实体类
|
|
@@ -475,7 +477,9 @@ public class CheckTemplateServiceImpl extends ServiceImpl<CheckTemplateDao, Chec
|
|
|
//发送消息提醒添加设备名称和设备编号拼接
|
|
|
String checkitemname = k.getCheckitemname();
|
|
|
String checkitemcode = k.getCheckitemcode();
|
|
|
- SysDictDo sysDictDo = dictsByType.stream().filter(info -> info.getValue().equals(templatetype)).findFirst().orElse(null);
|
|
|
+ SysDictDo sysDictDo = dictsByType.stream().filter(info -> info.getValue().equals(templatetype))
|
|
|
+ .findFirst()
|
|
|
+ .orElse(null);
|
|
|
JSCommonUtils.sendNotify(INSPECTION_TITLE, String.format(INSPECTION_CONTENT, pointcheckname, checkitemname, checkitemcode, sysDictDo == null ? "" : sysDictDo.getName()),
|
|
|
null, v, k.getId(), INSPECTION + "-" + shift, false);
|
|
|
});
|
|
@@ -523,10 +527,7 @@ public class CheckTemplateServiceImpl extends ServiceImpl<CheckTemplateDao, Chec
|
|
|
Map<String, List<CheckTemplateItemsDo>> shiftTypeAndTempMap = new HashMap<>();
|
|
|
// 获取工作时间信息
|
|
|
List<AspShiftTimeDo> aspShiftTimeDos = aspShiftTimeDao.selectByMap(SHIFT_TIME_QUERY);
|
|
|
- // 风险单元ID
|
|
|
- String riskunitid = checkTemplateDo.getRiskunitid();
|
|
|
- JSCommonUtils.parameterCheck(() -> StringUtils.isBlank(riskunitid), "风险单元为空", "风险单元为空");
|
|
|
- List<AspRiskUnitDo> aspRiskUnitDos = aspRiskUnitService.getBaseMapper().selectBatchIds(Arrays.asList(riskunitid.split(",")));
|
|
|
+
|
|
|
Map<String, String> checkUserMap = new HashMap<>();
|
|
|
if (StringUtils.isNotBlank(checkTemplateDo.getInspectorsid())) {
|
|
|
String[] ids = checkTemplateDo.getInspectorsid().split(",");
|
|
@@ -535,12 +536,49 @@ public class CheckTemplateServiceImpl extends ServiceImpl<CheckTemplateDao, Chec
|
|
|
checkUserMap.put(ids[i], names[i]);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // 风险分析单元
|
|
|
+ List<AspRiskUnitDo> aspRiskUnitDos = Collections.emptyList();
|
|
|
+ // 设备
|
|
|
+ List<CheckItemsDo> checkitemList = Collections.emptyList();
|
|
|
+ List<String> checkAreaIds = new ArrayList<>();
|
|
|
+ String checkAttr;
|
|
|
+ String checkType;
|
|
|
+ if ("1".equals(checkTemplateDo.getObjclass())) {
|
|
|
+ // 设备 ID
|
|
|
+ String checkitemids = checkTemplateDo.getCheckitemids();
|
|
|
+ parameterCheck(() -> StringUtils.isBlank(checkitemids), "设备为空", "设备为空");
|
|
|
+ checkitemList = checkItemsService.getBaseMapper().selectBatchIds(Arrays.asList(checkitemids.split(",")));
|
|
|
+ checkAreaIds = checkitemList.stream().map(CheckItemsDo::getId).collect(Collectors.toList());
|
|
|
+ checkAttr = CheckType.EQU;
|
|
|
+ checkType = ResponsiblePositionAttribute.EQU_CHECK;
|
|
|
+ } else {
|
|
|
+ // 风险单元 ID
|
|
|
+ String riskunitid = checkTemplateDo.getRiskunitid();
|
|
|
+ parameterCheck(() -> StringUtils.isBlank(riskunitid), "风险单元为空", "风险单元为空");
|
|
|
+ aspRiskUnitDos = aspRiskUnitService.getBaseMapper().selectBatchIds(Arrays.asList(riskunitid.split(",")));
|
|
|
+ checkAreaIds = aspRiskUnitDos.stream().map(AspRiskUnitDo::getId).collect(Collectors.toList());
|
|
|
+ checkAttr = CheckType.RISK;
|
|
|
+ checkType = ResponsiblePositionAttribute.RISK_CHECK;
|
|
|
+ }
|
|
|
+ // 检查人员为空的时,从人员检查配置中获取人员,设置为检察人员
|
|
|
+ if (checkUserMap.isEmpty()) {
|
|
|
+ // 从设备中获取检查人
|
|
|
+ List<AspPersonnelCheckConfigDo> aspPersonnelCheckConfigDos = aspPersonnelCheckConfigService
|
|
|
+ .batchSelectCheckUserInfo(checkType, checkAreaIds, checkAttr);
|
|
|
+ aspPersonnelCheckConfigDos.forEach(data -> {
|
|
|
+ checkUserMap.put(data.getDutyofficerid(), data.getDutyofficername());
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
// 获取模板对应的检查项
|
|
|
List<CheckTemplateItemsDo> templateItemsDos = checkTemplateItemsService.list(new LambdaQueryWrapper<CheckTemplateItemsDo>()
|
|
|
.in(CheckTemplateItemsDo::getChecktemplateid, checkTemplateDo.getId())
|
|
|
.eq(BaseDo::getDeleted, "0"));
|
|
|
if (!mode) {
|
|
|
- templateItemsDos = templateItemsDos.stream().filter(data -> isNowCreateByFrequency(data.getFrequency())).collect(Collectors.toList());
|
|
|
+ templateItemsDos = templateItemsDos.stream()
|
|
|
+ .filter(data -> isNowCreateByFrequency(data.getFrequency()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
}
|
|
|
logger.debug("本次需要生成检查计划的模板数据有:{}", templateItemsDos.size());
|
|
|
|
|
@@ -562,8 +600,6 @@ public class CheckTemplateServiceImpl extends ServiceImpl<CheckTemplateDao, Chec
|
|
|
List<ThemeCheckItemDo> themeCheckItemSaveDos = new ArrayList<>();
|
|
|
// 检查任务对应的检查项
|
|
|
List<ThemeCheckContentDo> themeCheckContentDos = new ArrayList<>();
|
|
|
- ThemeCheckItemDo checkItemDo;
|
|
|
- ThemeCheckContentDo themeCheckContentDo;
|
|
|
Date startTime = startCalendar.getTime();
|
|
|
Date endTime = endCalendar.getTime();
|
|
|
templateItemsDos.forEach(tempDao -> {
|
|
@@ -594,79 +630,110 @@ public class CheckTemplateServiceImpl extends ServiceImpl<CheckTemplateDao, Chec
|
|
|
// 长白班
|
|
|
shiftTypeAndTempMap.computeIfAbsent(CHECK_SHIFT_EVERY_CHANGBAI_CLASS_SHIFT, k -> new ArrayList<>()).add(tempDao);
|
|
|
}
|
|
|
-
|
|
|
});
|
|
|
|
|
|
-
|
|
|
- // 模板对应的检查项
|
|
|
- List<CheckTemplateItemsDo> items;
|
|
|
- for (AspRiskUnitDo aspRiskUnitDo : aspRiskUnitDos) {
|
|
|
- checkUserMap.put(aspRiskUnitDo.getDutyofficerid(), aspRiskUnitDo.getDutyofficername());
|
|
|
- for (Map.Entry<String, String> nameAndId : checkUserMap.entrySet()) {
|
|
|
- for (Map.Entry<String, List<CheckTemplateItemsDo>> entry : shiftTypeAndTempMap.entrySet()) {
|
|
|
- String k = entry.getKey();
|
|
|
- AspShiftTimeDo aspShiftTimeDo = aspShiftTimeDos.stream().filter(info -> k.equals(info.getShift())).findFirst().orElse(null);
|
|
|
- int maxFrequency = entry.getValue().stream()
|
|
|
- .mapToInt(item -> Optional.ofNullable(item.getShiftcount()).orElse(1))
|
|
|
- .max()
|
|
|
- .orElse(1);
|
|
|
- for (int i = 1; i <= maxFrequency; i++) {
|
|
|
- checkItemDo = new ThemeCheckItemDo();
|
|
|
- checkItemDo.setId(SecurityUtil.getUUID());
|
|
|
- JSCommonUtils.setBaseDetail(checkItemDo, currentUser);
|
|
|
- checkItemDo.setThemechecknum(JSCommonUtils.streamCodeGeneration("asp_theme_check_item_number",
|
|
|
- "SC@{date:yyyyMM}@{serialNumber:#000000}", "date:yyyyMM", ""));
|
|
|
- checkItemDo.setThemecheckid(checkTemplateDo.getId());
|
|
|
- checkItemDo.setThemecheckname(checkTemplateDo.getTemplatename());
|
|
|
- if (aspShiftTimeDo != null) {
|
|
|
- checkItemDo.setPlanstarttime(basedOnShiftGenerateTime(aspShiftTimeDo, AspShiftTimeDo::getStarttime));
|
|
|
- checkItemDo.setPlanendtime(basedOnShiftGenerateTime(aspShiftTimeDo, AspShiftTimeDo::getEndtime));
|
|
|
- } else {
|
|
|
- checkItemDo.setPlanstarttime(startTime);
|
|
|
- checkItemDo.setPlanendtime(endTime);
|
|
|
- }
|
|
|
- checkItemDo.setChecktype(checkTemplateDo.getTemplatetype());
|
|
|
- checkItemDo.setTenantid(checkTemplateDo.getTenantid());
|
|
|
- checkItemDo.setChecker(nameAndId.getValue());
|
|
|
- checkItemDo.setCheckerid(nameAndId.getKey());
|
|
|
- checkItemDo.setThemecheckworkspartid(aspRiskUnitDo.getResponsibledeptid());
|
|
|
- checkItemDo.setCheckworkspart(aspRiskUnitDo.getResponsibledept());
|
|
|
- checkItemDo.setCheckresult("20");
|
|
|
- checkItemDo.setCheckstatus(THEME_CHECK_STATUS_WAIT);
|
|
|
- checkItemDo.setTenantid(checkTemplateDo.getTenantid());
|
|
|
- themeCheckItemSaveDos.add(checkItemDo);
|
|
|
- int finalI = i;
|
|
|
- items = entry.getValue().stream()
|
|
|
- .peek(info -> {
|
|
|
- Integer shiftcount = Optional.ofNullable(info.getShiftcount()).orElse(1);
|
|
|
- info.setShiftcount(shiftcount);
|
|
|
- })
|
|
|
- .filter(info -> info.getShiftcount() >= finalI)
|
|
|
- .collect(Collectors.toList());
|
|
|
- for (int j = 0; j < items.size(); j++) {
|
|
|
- themeCheckContentDo = new ThemeCheckContentDo();
|
|
|
- themeCheckContentDo.setItemsort(j + 1);
|
|
|
- themeCheckContentDo.setTenantid(checkTemplateDo.getTenantid());
|
|
|
- themeCheckContentDo.setId(SecurityUtil.getUUID());
|
|
|
- themeCheckContentDo.setThemecheckitemid(checkItemDo.getId());
|
|
|
- JSCommonUtils.setBaseDetail(themeCheckContentDo, currentUser);
|
|
|
- themeCheckContentDo.setCheckposition(items.get(j).getCheckposition());
|
|
|
- themeCheckContentDo.setCheckmethod(items.get(j).getChecktype());
|
|
|
- themeCheckContentDo.setCheckcontent(items.get(j).getCheckcontent());
|
|
|
- themeCheckContentDo.setManagement(items.get(j).getCheckstandard());
|
|
|
- themeCheckContentDo.setTenantid(checkTemplateDo.getTenantid());
|
|
|
- themeCheckContentDos.add(themeCheckContentDo);
|
|
|
- }
|
|
|
- }
|
|
|
+ if ("1".equals(checkTemplateDo.getObjclass())) {
|
|
|
+ if (checkUserMap.isEmpty()) {
|
|
|
+ checkUserMap.put(Strings.EMPTY, Strings.EMPTY);
|
|
|
+ }
|
|
|
+ for (CheckItemsDo checkItemsDo : checkitemList) {
|
|
|
+ createThemeCheck(checkTemplateDo, checkUserMap, shiftTypeAndTempMap, aspShiftTimeDos,
|
|
|
+ currentUser, startTime, endTime, themeCheckItemSaveDos, themeCheckContentDos,
|
|
|
+ checkItemsDo.getUsedeptid(),
|
|
|
+ checkItemsDo.getUsedeptname(), CheckType.EQU);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ for (AspRiskUnitDo aspRiskUnitDo : aspRiskUnitDos) {
|
|
|
+ if (checkUserMap.isEmpty()) {
|
|
|
+ checkUserMap.put(aspRiskUnitDo.getDutyofficerid(), aspRiskUnitDo.getDutyofficername());
|
|
|
}
|
|
|
+ createThemeCheck(checkTemplateDo, checkUserMap, shiftTypeAndTempMap, aspShiftTimeDos,
|
|
|
+ currentUser, startTime, endTime, themeCheckItemSaveDos, themeCheckContentDos,
|
|
|
+ aspRiskUnitDo.getResponsibledeptid(),
|
|
|
+ aspRiskUnitDo.getResponsibledept(), CheckType.RISK);
|
|
|
+ checkUserMap.remove(aspRiskUnitDo.getDutyofficerid());
|
|
|
}
|
|
|
- checkUserMap.remove(aspRiskUnitDo.getDutyofficerid());
|
|
|
}
|
|
|
+
|
|
|
// 数据存表
|
|
|
JSCommonUtils.batchChunk(themeCheckItemSaveDos, themeCheckItemService::saveBatch, 20);
|
|
|
JSCommonUtils.batchChunk(themeCheckContentDos, themeCheckContentService::saveBatch, 20);
|
|
|
}
|
|
|
|
|
|
+ private void createThemeCheck(CheckTemplateDo checkTemplateDo,
|
|
|
+ Map<String, String> checkUserMap,
|
|
|
+ Map<String, List<CheckTemplateItemsDo>> shiftTypeAndTempMap,
|
|
|
+ List<AspShiftTimeDo> aspShiftTimeDos, SysUserVo currentUser,
|
|
|
+ Date startTime, Date endTime, List<ThemeCheckItemDo> themeCheckItemSaveDos,
|
|
|
+ List<ThemeCheckContentDo> themeCheckContentDos,
|
|
|
+ String themecheckworkspartid,
|
|
|
+ String checkworkspart,
|
|
|
+ String type) {
|
|
|
+
|
|
|
+ ThemeCheckContentDo themeCheckContentDo;
|
|
|
+ List<CheckTemplateItemsDo> items;
|
|
|
+ ThemeCheckItemDo checkItemDo;
|
|
|
+ for (Map.Entry<String, String> nameAndId : checkUserMap.entrySet()) {
|
|
|
+ for (Map.Entry<String, List<CheckTemplateItemsDo>> entry : shiftTypeAndTempMap.entrySet()) {
|
|
|
+ String k = entry.getKey();
|
|
|
+ AspShiftTimeDo aspShiftTimeDo = aspShiftTimeDos.stream().filter(info -> k.equals(info.getShift())).findFirst().orElse(null);
|
|
|
+ int maxFrequency = entry.getValue().stream()
|
|
|
+ .mapToInt(item -> Optional.ofNullable(item.getShiftcount()).orElse(1))
|
|
|
+ .max()
|
|
|
+ .orElse(1);
|
|
|
+ for (int i = 1; i <= maxFrequency; i++) {
|
|
|
+ checkItemDo = new ThemeCheckItemDo();
|
|
|
+ checkItemDo.setId(SecurityUtil.getUUID());
|
|
|
+ JSCommonUtils.setBaseDetail(checkItemDo, currentUser);
|
|
|
+ checkItemDo.setThemechecknum(streamCodeGeneration("asp_theme_check_item_number",
|
|
|
+ "SC@{date:yyyyMM}@{serialNumber:#000000}", "date:yyyyMM", ""));
|
|
|
+ checkItemDo.setThemecheckid(checkTemplateDo.getId());
|
|
|
+ checkItemDo.setThemecheckname(checkTemplateDo.getTemplatename());
|
|
|
+ if (aspShiftTimeDo != null) {
|
|
|
+ checkItemDo.setPlanstarttime(basedOnShiftGenerateTime(aspShiftTimeDo, AspShiftTimeDo::getStarttime));
|
|
|
+ checkItemDo.setPlanendtime(basedOnShiftGenerateTime(aspShiftTimeDo, AspShiftTimeDo::getEndtime));
|
|
|
+ } else {
|
|
|
+ checkItemDo.setPlanstarttime(startTime);
|
|
|
+ checkItemDo.setPlanendtime(endTime);
|
|
|
+ }
|
|
|
+ checkItemDo.setChecktype(checkTemplateDo.getTemplatetype());
|
|
|
+ checkItemDo.setTenantid(checkTemplateDo.getTenantid());
|
|
|
+ checkItemDo.setChecker(nameAndId.getValue());
|
|
|
+ checkItemDo.setCheckerid(nameAndId.getKey());
|
|
|
+ checkItemDo.setThemecheckworkspartid(themecheckworkspartid);
|
|
|
+ checkItemDo.setCheckworkspart(checkworkspart);
|
|
|
+ checkItemDo.setCheckresult("20");
|
|
|
+ checkItemDo.setCheckstatus(THEME_CHECK_STATUS_WAIT);
|
|
|
+ checkItemDo.setTenantid(checkTemplateDo.getTenantid());
|
|
|
+ checkItemDo.setType(type);
|
|
|
+ themeCheckItemSaveDos.add(checkItemDo);
|
|
|
+ int finalI = i;
|
|
|
+ items = entry.getValue().stream()
|
|
|
+ .peek(info -> {
|
|
|
+ Integer shiftcount = Optional.ofNullable(info.getShiftcount()).orElse(1);
|
|
|
+ info.setShiftcount(shiftcount);
|
|
|
+ })
|
|
|
+ .filter(info -> info.getShiftcount() >= finalI)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ for (int j = 0; j < items.size(); j++) {
|
|
|
+ themeCheckContentDo = new ThemeCheckContentDo();
|
|
|
+ themeCheckContentDo.setItemsort(j + 1);
|
|
|
+ themeCheckContentDo.setTenantid(checkTemplateDo.getTenantid());
|
|
|
+ themeCheckContentDo.setId(SecurityUtil.getUUID());
|
|
|
+ themeCheckContentDo.setThemecheckitemid(checkItemDo.getId());
|
|
|
+ JSCommonUtils.setBaseDetail(themeCheckContentDo, currentUser);
|
|
|
+ themeCheckContentDo.setCheckposition(items.get(j).getCheckposition());
|
|
|
+ themeCheckContentDo.setCheckmethod(items.get(j).getChecktype());
|
|
|
+ themeCheckContentDo.setCheckcontent(items.get(j).getCheckcontent());
|
|
|
+ themeCheckContentDo.setManagement(items.get(j).getCheckstandard());
|
|
|
+ themeCheckContentDo.setTenantid(checkTemplateDo.getTenantid());
|
|
|
+ themeCheckContentDos.add(themeCheckContentDo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public Date basedOnShiftGenerateTime(AspShiftTimeDo aspShiftTimeDo,
|
|
|
Function<AspShiftTimeDo, String> getTimeFunction) {
|
|
|
if (aspShiftTimeDo == null) {
|