|
@@ -9,6 +9,7 @@ import com.rongwe.scentity.vo.CheckTemplateItemsVo;
|
|
|
import com.rongwe.scentity.vo.CheckTemplateVo;
|
|
|
import com.rongwei.commonservice.serial.service.CommonDictService;
|
|
|
import com.rongwei.rwadmincommon.system.domain.SysDictDo;
|
|
|
+import com.rongwei.rwadmincommon.system.service.impl.WidgetInstServiceImpl;
|
|
|
import com.rongwei.rwadmincommon.system.vo.SysUserVo;
|
|
|
import com.rongwei.rwcommon.base.BaseDo;
|
|
|
import com.rongwei.rwcommon.base.R;
|
|
@@ -27,6 +28,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.*;
|
|
|
+import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import static com.rongwei.safecommon.utils.JSCommonUtils.parameterCheck;
|
|
@@ -77,6 +79,8 @@ public class CheckTemplateServiceImpl extends ServiceImpl<CheckTemplateDao, Chec
|
|
|
private ThemeCheckItemService themeCheckItemService;
|
|
|
@Autowired
|
|
|
private ThemeCheckContentService themeCheckContentService;
|
|
|
+ @Autowired
|
|
|
+ private WidgetInstServiceImpl widgetInstService;
|
|
|
|
|
|
/**
|
|
|
* 通用Map转自定义业务实体类
|
|
@@ -501,54 +505,60 @@ public class CheckTemplateServiceImpl extends ServiceImpl<CheckTemplateDao, Chec
|
|
|
* 根据模板ID创建计划
|
|
|
*
|
|
|
* @param id
|
|
|
+ * @param mode 是否忽略检查项的频次 0:不忽略 1:忽略
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public R createCheckPlanByTempId(String id) {
|
|
|
+ public R createCheckPlanByTempId(String id,Boolean mode) {
|
|
|
CheckTemplateDo checkTemplateDo = this.getById(id);
|
|
|
parameterCheck(() -> checkTemplateDo == null, "检查模板不存在", "检查模板不存在");
|
|
|
// 生产检查任务
|
|
|
- assembleCheckPlan(Collections.singletonList(checkTemplateDo), true);
|
|
|
+ assembleCheckTask(checkTemplateDo, mode);
|
|
|
return R.ok();
|
|
|
}
|
|
|
|
|
|
|
|
|
- public void assembleCheckPlan(List<CheckTemplateDo> checkTemplateDos, boolean singleExecution) {
|
|
|
+ public void assembleCheckTask(CheckTemplateDo checkTemplateDo, Boolean mode) {
|
|
|
// 各班次需要生产任务的模板信息
|
|
|
- Map<String, List<CheckTemplateDo>> shiftTypeAndTempMap = new HashMap<>();
|
|
|
- if (!singleExecution) {
|
|
|
- // 获取本次可以生成计划的模板信息
|
|
|
- checkTemplateDos = checkTemplateDos.stream().filter(data -> isNowCreateByFrequency(data.getFrequency())).collect(Collectors.toList());
|
|
|
- }
|
|
|
+ Map<String, List<CheckTemplateItemsDo>> shiftTypeAndTempMap = new HashMap<>();
|
|
|
// 获取工作时间信息
|
|
|
List<AspShiftTimeDo> aspShiftTimeDos = aspShiftTimeDao.selectByMap(SHIFT_TIME_QUERY);
|
|
|
-
|
|
|
- log.debug("本次需要生成");
|
|
|
- checkTemplateDos.forEach(tempDao -> {
|
|
|
+ // 获取模板对应的检查项
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+ logger.debug("本次需要生成检查计划的模板数据有:{}",templateItemsDos.size());
|
|
|
+ templateItemsDos.forEach(tempDao -> {
|
|
|
+ if (tempDao.getShift().contains(CHECK_SHIFT_EVERY_SHIFT)) {
|
|
|
+ // 每班
|
|
|
+ shiftTypeAndTempMap.computeIfAbsent(CHECK_SHIFT_EVERY_DAY_SHIFT, k -> new ArrayList<>()).add(tempDao);
|
|
|
+ shiftTypeAndTempMap.computeIfAbsent(CHECK_SHIFT_EVERY_MIDDLE_SHIFT, k -> new ArrayList<>()).add(tempDao);
|
|
|
+ shiftTypeAndTempMap.computeIfAbsent(CHECK_SHIFT_EVERY_NIGHT_SHIFT, k -> new ArrayList<>()).add(tempDao);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 白班
|
|
|
if (tempDao.getShift().contains(CHECK_SHIFT_EVERY_DAY_SHIFT)) {
|
|
|
shiftTypeAndTempMap.computeIfAbsent(CHECK_SHIFT_EVERY_DAY_SHIFT, k -> new ArrayList<>()).add(tempDao);
|
|
|
- } else if (tempDao.getShift().contains(CHECK_SHIFT_EVERY_MIDDLE_SHIFT)) {
|
|
|
+ }
|
|
|
+ if (tempDao.getShift().contains(CHECK_SHIFT_EVERY_MIDDLE_SHIFT)) {
|
|
|
// 中班
|
|
|
shiftTypeAndTempMap.computeIfAbsent(CHECK_SHIFT_EVERY_MIDDLE_SHIFT, k -> new ArrayList<>()).add(tempDao);
|
|
|
- } else if (tempDao.getShift().contains(CHECK_SHIFT_EVERY_NIGHT_SHIFT)) {
|
|
|
+ }
|
|
|
+ if (tempDao.getShift().contains(CHECK_SHIFT_EVERY_NIGHT_SHIFT)) {
|
|
|
// 夜班
|
|
|
shiftTypeAndTempMap.computeIfAbsent(CHECK_SHIFT_EVERY_NIGHT_SHIFT, k -> new ArrayList<>()).add(tempDao);
|
|
|
- } else if (tempDao.getShift().contains(CHECK_SHIFT_EVERY_CHANGBAI_CLASS_SHIFT)) {
|
|
|
+ }
|
|
|
+ if (tempDao.getShift().contains(CHECK_SHIFT_EVERY_CHANGBAI_CLASS_SHIFT)) {
|
|
|
// 长白班
|
|
|
shiftTypeAndTempMap.computeIfAbsent(CHECK_SHIFT_EVERY_CHANGBAI_CLASS_SHIFT, k -> new ArrayList<>()).add(tempDao);
|
|
|
- } else if (tempDao.getShift().contains(CHECK_SHIFT_EVERY_SHIFT)) {
|
|
|
- // 每班
|
|
|
- shiftTypeAndTempMap.computeIfAbsent(CHECK_SHIFT_EVERY_DAY_SHIFT, k -> new ArrayList<>()).add(tempDao);
|
|
|
- shiftTypeAndTempMap.computeIfAbsent(CHECK_SHIFT_EVERY_MIDDLE_SHIFT, k -> new ArrayList<>()).add(tempDao);
|
|
|
- shiftTypeAndTempMap.computeIfAbsent(CHECK_SHIFT_EVERY_NIGHT_SHIFT, k -> new ArrayList<>()).add(tempDao);
|
|
|
}
|
|
|
+
|
|
|
});
|
|
|
- // 获取检查模板ID
|
|
|
- List<String> tempId = checkTemplateDos.stream().map(CheckTemplateDo::getId).collect(Collectors.toList());
|
|
|
- // 获取模板对应的检查项
|
|
|
- List<CheckTemplateItemsDo> templateItemsDos = checkTemplateItemsService.list(new LambdaQueryWrapper<CheckTemplateItemsDo>()
|
|
|
- .in(CheckTemplateItemsDo::getChecktemplateid, tempId)
|
|
|
- .eq(BaseDo::getDeleted, "0"));
|
|
|
+
|
|
|
+
|
|
|
SysUserVo currentUser = JSCommonUtils.getCurrentUser();
|
|
|
// 获取当前时间的0点0分0秒
|
|
|
Calendar startCalendar = Calendar.getInstance();
|
|
@@ -573,11 +583,14 @@ public class CheckTemplateServiceImpl extends ServiceImpl<CheckTemplateDao, Chec
|
|
|
Date endTime = endCalendar.getTime();
|
|
|
// 模板对应的检查项
|
|
|
List<CheckTemplateItemsDo> items;
|
|
|
- for (Map.Entry<String, List<CheckTemplateDo>> entry : shiftTypeAndTempMap.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);
|
|
|
- basedOnShiftGenerateTime(aspShiftTimeDo, startTime, endTime);
|
|
|
- for (CheckTemplateDo checkTemplateDo : entry.getValue()) {
|
|
|
+
|
|
|
+ //当前班次最大的任务数量
|
|
|
+ int maxFrequency = entry.getValue().stream().mapToInt(CheckTemplateItemsDo::getShiftcount).max().orElse(1);
|
|
|
+ for (int i = 1; i <= maxFrequency; i++) {
|
|
|
checkItemDo = new ThemeCheckItemDo();
|
|
|
checkItemDo.setId(SecurityUtil.getUUID());
|
|
|
JSCommonUtils.setBaseDetail(checkItemDo, currentUser);
|
|
@@ -585,31 +598,32 @@ public class CheckTemplateServiceImpl extends ServiceImpl<CheckTemplateDao, Chec
|
|
|
"SC@{date:yyyyMM}@{serialNumber:#000000}", "date:yyyyMM", ""));
|
|
|
checkItemDo.setThemecheckid(checkTemplateDo.getId());
|
|
|
checkItemDo.setThemecheckname(checkTemplateDo.getTemplatename());
|
|
|
- checkItemDo.setPlanstarttime(startTime);
|
|
|
- checkItemDo.setPlanendtime(endTime);
|
|
|
+ checkItemDo.setPlanstarttime(basedOnShiftGenerateTime(aspShiftTimeDo, AspShiftTimeDo::getStarttime));
|
|
|
+ checkItemDo.setPlanendtime(basedOnShiftGenerateTime(aspShiftTimeDo, AspShiftTimeDo::getEndtime));
|
|
|
checkItemDo.setChecktype(checkTemplateDo.getTemplatetype());
|
|
|
checkItemDo.setTenantid(checkTemplateDo.getTenantid());
|
|
|
// TODO:XH add 2024/8/16 暂不止如何处理
|
|
|
// checkItemDo.setChecker();
|
|
|
// checkItemDo.setCheckerid();
|
|
|
// TODO:XH add 2024/8/16 检查区域暂不处理
|
|
|
-// checkItemDo.setThemecheckworkspartid();
|
|
|
+// checkItemDo.setThemecheckworkspartid();a
|
|
|
// checkItemDo.setCheckworkspart();
|
|
|
checkItemDo.setCheckresult("20");
|
|
|
checkItemDo.setCheckstatus(THEME_CHECK_STATUS_WAIT);
|
|
|
themeCheckItemSaveDos.add(checkItemDo);
|
|
|
- items = templateItemsDos.stream().filter(data -> checkTemplateDo.getId().equals(data.getChecktemplateid())).collect(Collectors.toList());
|
|
|
- for (int i = 0; i < items.size(); i++) {
|
|
|
+ int finalI = i;
|
|
|
+ items = entry.getValue().stream().filter(info -> info.getShiftcount()>= finalI ).collect(Collectors.toList());
|
|
|
+ for (int j = 0; j < items.size(); j++) {
|
|
|
themeCheckContentDo = new ThemeCheckContentDo();
|
|
|
- themeCheckContentDo.setItemsort(i+1);
|
|
|
+ themeCheckContentDo.setItemsort(j+1);
|
|
|
themeCheckContentDo.setTenantid(checkTemplateDo.getTenantid());
|
|
|
themeCheckContentDo.setId(SecurityUtil.getUUID());
|
|
|
themeCheckContentDo.setThemecheckitemid(checkItemDo.getId());
|
|
|
JSCommonUtils.setBaseDetail(themeCheckContentDo, currentUser);
|
|
|
- themeCheckContentDo.setCheckposition(items.get(i).getCheckposition());
|
|
|
- themeCheckContentDo.setCheckmethod(items.get(i).getChecktype());
|
|
|
- themeCheckContentDo.setCheckcontent(items.get(i).getCheckcontent());
|
|
|
- themeCheckContentDo.setManagement(items.get(i).getManagement());
|
|
|
+ themeCheckContentDo.setCheckposition(items.get(j).getCheckposition());
|
|
|
+ themeCheckContentDo.setCheckmethod(items.get(j).getChecktype());
|
|
|
+ themeCheckContentDo.setCheckcontent(items.get(j).getCheckcontent());
|
|
|
+ themeCheckContentDo.setManagement(items.get(j).getManagement());
|
|
|
themeCheckContentDos.add(themeCheckContentDo);
|
|
|
}
|
|
|
}
|
|
@@ -619,24 +633,21 @@ public class CheckTemplateServiceImpl extends ServiceImpl<CheckTemplateDao, Chec
|
|
|
JSCommonUtils.batchChunk(themeCheckContentDos, themeCheckContentService::saveBatch, 20);
|
|
|
}
|
|
|
|
|
|
- public void basedOnShiftGenerateTime(AspShiftTimeDo aspShiftTimeDo,
|
|
|
- Date startTime, Date endTime) {
|
|
|
+ public Date basedOnShiftGenerateTime(AspShiftTimeDo aspShiftTimeDo,
|
|
|
+ Function<AspShiftTimeDo, String> getTimeFunction) {
|
|
|
if (aspShiftTimeDo == null) {
|
|
|
- return;
|
|
|
+ return new Date();
|
|
|
}
|
|
|
- String starttime = aspShiftTimeDo.getStarttime();
|
|
|
- String endtime = aspShiftTimeDo.getEndtime();
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
calendar.setTime(new Date());
|
|
|
- calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(starttime.split(":")[0]));
|
|
|
- calendar.set(Calendar.MINUTE, Integer.parseInt(starttime.split(":")[1]));
|
|
|
- calendar.set(Calendar.SECOND, Integer.parseInt(starttime.split(":")[2]));
|
|
|
- startTime = calendar.getTime();
|
|
|
- calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(endtime.split(":")[0]));
|
|
|
- calendar.set(Calendar.MINUTE, Integer.parseInt(endtime.split(":")[1]));
|
|
|
- calendar.set(Calendar.SECOND, Integer.parseInt(endtime.split(":")[2]));
|
|
|
- endTime = calendar.getTime();
|
|
|
-
|
|
|
+ String timeStr = getTimeFunction.apply(aspShiftTimeDo);
|
|
|
+ if(CHECK_SHIFT_EVERY_NIGHT_SHIFT.equals(aspShiftTimeDo.getShift())){
|
|
|
+ calendar.add(Calendar.DATE, 1);
|
|
|
+ }
|
|
|
+ calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(timeStr.split(":")[0]));
|
|
|
+ calendar.set(Calendar.MINUTE, Integer.parseInt(timeStr.split(":")[1]));
|
|
|
+ calendar.set(Calendar.SECOND, Integer.parseInt(timeStr.split(":")[2]));
|
|
|
+ return calendar.getTime();
|
|
|
}
|
|
|
|
|
|
|