|
@@ -2,13 +2,13 @@ package com.rongwei.sfcommon.sys.service.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.rongwe.scentity.domian.*;
|
|
|
import com.rongwe.scentity.vo.CheckTemplateItemsVo;
|
|
|
import com.rongwe.scentity.vo.CheckTemplateVo;
|
|
|
import com.rongwei.commonservice.serial.service.CommonDictService;
|
|
|
import com.rongwei.commonservice.serial.service.SysSerialNumberService;
|
|
|
import com.rongwei.rwadmincommon.system.dao.SysUserDao;
|
|
|
-import com.rongwei.rwadmincommon.system.vo.SysUserVo;
|
|
|
import com.rongwei.rwcommon.utils.SecurityUtil;
|
|
|
import com.rongwei.rwcommon.utils.StringUtils;
|
|
|
import com.rongwei.rwcommon.vo.generalsql.GeneralApiParameter;
|
|
@@ -21,10 +21,11 @@ import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
+import static com.rongwei.sfcommon.utils.CommonUtil.streamCodeGeneration;
|
|
|
+
|
|
|
@Service("checkTemplateService")
|
|
|
public class CheckTemplateServiceImpl extends ServiceImpl<CheckTemplateDao, CheckTemplateDo> implements CheckTemplateService {
|
|
|
|
|
@@ -105,31 +106,49 @@ public class CheckTemplateServiceImpl extends ServiceImpl<CheckTemplateDao, Chec
|
|
|
/**
|
|
|
* 定时调度(每天)创建点检任务
|
|
|
*/
|
|
|
- public void pointCheckCreate(){
|
|
|
+ public void pointCheckCreate(Map<String, Object> map) {
|
|
|
logger.info("点检定时任务生成开始.....");
|
|
|
- Map<String,Object> map = new HashMap<>();
|
|
|
- map.put("TEMPLATETYPE",MlConstants.TEMPLATETYPE_POINT_CHECK);
|
|
|
- map.put("ENABLESTATUS",MlConstants.TEMPLATE_STATUS_OPEM);
|
|
|
+ if (map == null) {
|
|
|
+ map = new HashMap<>();
|
|
|
+ }
|
|
|
+ // 是否为定时任务
|
|
|
+ boolean runTask = false;
|
|
|
+ // 如果参数为空则为定时任务
|
|
|
+ if (map.isEmpty()) {
|
|
|
+ //map.put("TEMPLATETYPE",MlConstants.TEMPLATETYPE_POINT_CHECK);
|
|
|
+ // 模板状态
|
|
|
+ map.put("ENABLESTATUS", MlConstants.TEMPLATE_STATUS_OPEM);
|
|
|
+ // 任务生成类型
|
|
|
+ map.put("JOBSTARTTYPE", MlConstants.JOB_START_TYPE_AUTO);
|
|
|
+ runTask = true;
|
|
|
+ } else {
|
|
|
+ String checkTemplateId = map.getOrDefault("ID", "").toString();
|
|
|
+ if (StringUtils.isBlank(checkTemplateId)) {
|
|
|
+ log.error("参数异常");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
// 查询所有点检类型的检查模板
|
|
|
- List<CheckTemplateDo> list = (List<CheckTemplateDo>)this.listByMap(map);
|
|
|
- if(list != null && list.size()>0){
|
|
|
+ List<CheckTemplateDo> list = (List<CheckTemplateDo>) this.listByMap(map);
|
|
|
+ if (list.size() == 0) {
|
|
|
// 根据点检模板定时生成点检任务
|
|
|
- for(CheckTemplateDo checkTemplate:list){
|
|
|
- logger.info("点检模板编号:"+checkTemplate.getTemplatecode());
|
|
|
- // 检查模板的检查项
|
|
|
- Map<String,Object> itemMap = new HashMap<>();
|
|
|
- itemMap.put("CHECKTEMPLATEID",checkTemplate.getId());
|
|
|
- List<CheckTemplateItemsDo> items = (List<CheckTemplateItemsDo>)checkTemplateItemsService.listByMap(itemMap);
|
|
|
- // 根据检查模板和相应的检查项生成点检任务
|
|
|
- pointCheckCreateByItems(checkTemplate,items);
|
|
|
- }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (CheckTemplateDo checkTemplate : list) {
|
|
|
+ logger.info("点检模板编号:" + checkTemplate.getTemplatecode());
|
|
|
+ // 检查模板的检查项
|
|
|
+ Map<String, Object> itemMap = new HashMap<>();
|
|
|
+ itemMap.put("CHECKTEMPLATEID", checkTemplate.getId());
|
|
|
+ List<CheckTemplateItemsDo> items = (List<CheckTemplateItemsDo>) checkTemplateItemsService.listByMap(itemMap);
|
|
|
+ // 根据检查模板和相应的检查项生成点检任务
|
|
|
+ pointCheckCreateByItems(checkTemplate, items, runTask);
|
|
|
}
|
|
|
// 检查是否有延期点检任务,如有则发邮件提醒
|
|
|
- pointCheckService.pintCheckDelayReminder();
|
|
|
+ //pointCheckService.pintCheckDelayReminder();
|
|
|
}
|
|
|
|
|
|
// 根据检查模板和相应的检查项生成点检任务
|
|
|
- private void pointCheckCreateByItems(CheckTemplateDo checkTemplate,List<CheckTemplateItemsDo> items){
|
|
|
+ private void pointCheckCreateByItems(CheckTemplateDo checkTemplate, List<CheckTemplateItemsDo> items, boolean runTask) {
|
|
|
/**
|
|
|
* 根据检查模板所有检查项的频次决定最终生成多少点检任务
|
|
|
* 通过对需求分析总结模型如下:
|
|
@@ -142,57 +161,63 @@ public class CheckTemplateServiceImpl extends ServiceImpl<CheckTemplateDao, Chec
|
|
|
List<List<CheckTemplateItemsDo>> middleItems = new ArrayList<>();
|
|
|
// 夜班检查项
|
|
|
List<List<CheckTemplateItemsDo>> nightItems = new ArrayList<>();
|
|
|
-
|
|
|
- if(items != null && items.size()>0){
|
|
|
- // 循环处理检查内容到白、中、夜三班任务里
|
|
|
- for(CheckTemplateItemsDo checkTemplateItem:items){
|
|
|
- // 频次
|
|
|
- String frequency = checkTemplateItem.getFrequencyids();
|
|
|
- // 班次
|
|
|
- String shift = checkTemplateItem.getShift();
|
|
|
- // 次数
|
|
|
- Integer shiftcount = checkTemplateItem.getShiftcount();
|
|
|
- if(shiftcount == null){
|
|
|
- shiftcount = 1;
|
|
|
- }
|
|
|
- // 当前检查项是否生成任务
|
|
|
- if(StringUtils.isNotEmpty(frequency) && isNowCreateByFrequency(frequency)){
|
|
|
- // 白班
|
|
|
- if(MlConstants.CHECK_SHIFT_EVERY_SHIFT.equals(shift) || MlConstants.CHECK_SHIFT_EVERY_DAY_SHIFT.equals(shift)){
|
|
|
- addCheckItems(dayItems,shiftcount,checkTemplateItem);
|
|
|
- }
|
|
|
- // 夜班
|
|
|
- if(MlConstants.CHECK_SHIFT_EVERY_SHIFT.equals(shift) || MlConstants.CHECK_SHIFT_EVERY_NIGHT_SHIFT.equals(shift)){
|
|
|
- addCheckItems(nightItems,shiftcount,checkTemplateItem);
|
|
|
- }
|
|
|
- // 中班
|
|
|
- if(MlConstants.CHECK_SHIFT_EVERY_SHIFT.equals(shift) || MlConstants.CHECK_SHIFT_EVERY_MIDDLE_SHIFT.equals(shift)){
|
|
|
- addCheckItems(middleItems,shiftcount,checkTemplateItem);
|
|
|
- }
|
|
|
- }
|
|
|
+ if (items == null || items.size() == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 循环处理检查内容到白、中、夜三班任务里
|
|
|
+ for (CheckTemplateItemsDo checkTemplateItem : items) {
|
|
|
+ // 频次
|
|
|
+ String frequency = checkTemplateItem.getFrequencyids();
|
|
|
+ // 班次
|
|
|
+ String shift = checkTemplateItem.getShift();
|
|
|
+ // 次数
|
|
|
+ Integer shiftcount = checkTemplateItem.getShiftcount();
|
|
|
+ if (shiftcount == null) {
|
|
|
+ shiftcount = 1;
|
|
|
+ }
|
|
|
+ // 如果是定时任务 (频次为空或者根据频次判断不应该生产任务时 直接返回)
|
|
|
+ if (runTask && (StringUtils.isBlank(frequency) || !isNowCreateByFrequency(frequency))) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 白班
|
|
|
+ if (MlConstants.CHECK_SHIFT_EVERY_SHIFT.equals(shift) || MlConstants.CHECK_SHIFT_EVERY_DAY_SHIFT.equals(shift)) {
|
|
|
+ addCheckItems(dayItems, shiftcount, checkTemplateItem);
|
|
|
+ }
|
|
|
+ // 夜班
|
|
|
+ if (MlConstants.CHECK_SHIFT_EVERY_SHIFT.equals(shift) || MlConstants.CHECK_SHIFT_EVERY_NIGHT_SHIFT.equals(shift)) {
|
|
|
+ addCheckItems(nightItems, shiftcount, checkTemplateItem);
|
|
|
+ }
|
|
|
+ // 中班
|
|
|
+ if (MlConstants.CHECK_SHIFT_EVERY_SHIFT.equals(shift) || MlConstants.CHECK_SHIFT_EVERY_MIDDLE_SHIFT.equals(shift)) {
|
|
|
+ addCheckItems(middleItems, shiftcount, checkTemplateItem);
|
|
|
}
|
|
|
- // 生成点检任务
|
|
|
- System.out.println("dayItems:"+dayItems.size()+"***"+"middleItems:"+middleItems.size()+"***"+"nightItems:"+nightItems.size());
|
|
|
- // 白班任务
|
|
|
- createPointCheckByTemplate(checkTemplate,dayItems,MlConstants.CHECK_SHIFT_EVERY_DAY_SHIFT);
|
|
|
- // 中班任务
|
|
|
- createPointCheckByTemplate(checkTemplate,middleItems,MlConstants.CHECK_SHIFT_EVERY_MIDDLE_SHIFT);
|
|
|
- // 夜班任务
|
|
|
- createPointCheckByTemplate(checkTemplate,nightItems,MlConstants.CHECK_SHIFT_EVERY_NIGHT_SHIFT);
|
|
|
}
|
|
|
+ // 生成点检任务
|
|
|
+ System.out.println("dayItems:" + dayItems.size() + "***" + "middleItems:" + middleItems.size() + "***" + "nightItems:" + nightItems.size());
|
|
|
+ // 白班任务
|
|
|
+ createPointCheckByTemplate(checkTemplate, dayItems, MlConstants.CHECK_SHIFT_EVERY_DAY_SHIFT);
|
|
|
+ // 中班任务
|
|
|
+ createPointCheckByTemplate(checkTemplate, middleItems, MlConstants.CHECK_SHIFT_EVERY_MIDDLE_SHIFT);
|
|
|
+ // 夜班任务
|
|
|
+ createPointCheckByTemplate(checkTemplate, nightItems, MlConstants.CHECK_SHIFT_EVERY_NIGHT_SHIFT);
|
|
|
}
|
|
|
|
|
|
- // 根据频次判断当前检查项是否生成点检任务
|
|
|
- private boolean isNowCreateByFrequency(String frequency){
|
|
|
+ /**
|
|
|
+ * 根据频次判断当前检查项是否生成点检任务
|
|
|
+ *
|
|
|
+ * @param frequency
|
|
|
+ * @return 是否可以生成任务
|
|
|
+ */
|
|
|
+ private boolean isNowCreateByFrequency(String frequency) {
|
|
|
boolean isCreate = true;
|
|
|
String[] frequencys = frequency.split("/");
|
|
|
- if(frequencys != null && frequencys.length>0){
|
|
|
+ if (frequencys != null && frequencys.length > 0) {
|
|
|
// 每天
|
|
|
- if("day".equals(frequencys[0])){
|
|
|
+ if ("day".equals(frequencys[0])) {
|
|
|
isCreate = true;
|
|
|
}
|
|
|
// 每周
|
|
|
- else if("week".equals(frequencys[0])){
|
|
|
+ else if ("week".equals(frequencys[0])) {
|
|
|
String weekday = frequencys[1];
|
|
|
// 当前时间是星期几
|
|
|
String w = DateUtil.dayOfWeek(new Date())+"";
|
|
@@ -262,24 +287,25 @@ public class CheckTemplateServiceImpl extends ServiceImpl<CheckTemplateDao, Chec
|
|
|
String checkitemsids = checkTemplate.getCheckitemids();
|
|
|
if(StringUtils.isNotEmpty(checkitemsids)){
|
|
|
String[] checkitemsidArray = checkitemsids.split(",");
|
|
|
- for(String checkitemsid:checkitemsidArray){
|
|
|
+ for (String checkitemsid : checkitemsidArray) {
|
|
|
// 每个设备生成一条点检任务
|
|
|
CheckItemsDo checkItemsdo = checkItemsService.getById(checkitemsid);
|
|
|
// 如当前设备未禁用状态则不生成点检任务
|
|
|
- if(checkItemsdo != null && MlConstants.CHECKITEM_STATUS_DISABLE.equals(checkItemsdo.getEnabled())){
|
|
|
+ if (checkItemsdo != null && MlConstants.CHECKITEM_STATUS_DISABLE.equals(checkItemsdo.getEnabled())) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
// 点检编号
|
|
|
- SysSerialVo sysSerialVo = new SysSerialVo();
|
|
|
- sysSerialVo.setModulecode("asp_point_check_POINTCHECKCODE");
|
|
|
- sysSerialVo.setRuleTemplateStr("@{date:yyyyMMdd}@{serialNumber:#0000000}");
|
|
|
- String pointcheckcode = sysSerialNumberService.getCodeByTemplate(sysSerialVo);
|
|
|
+
|
|
|
+ String pointcheckcode = streamCodeGeneration("asp_point_check_POINTCHECKCODE",
|
|
|
+ "@{date:yyyyMMdd}@{serialNumber:#0000000}","date:yyyy", checkTemplate.getTenantid());
|
|
|
// 点检生成
|
|
|
PointCheckDo pointCheckDo = new PointCheckDo();
|
|
|
pointCheckDo.setId(SecurityUtil.getUUID());
|
|
|
pointCheckDo.setPointcheckname(poName);
|
|
|
pointCheckDo.setPointcheckcode(pointcheckcode);
|
|
|
+ pointCheckDo.setWorkshopid(checkTemplate.getYjorgid());
|
|
|
+ pointCheckDo.setWorkshopname(checkTemplate.getYjorgname());
|
|
|
//设备ID
|
|
|
pointCheckDo.setCheckitemid(checkItemsdo.getId());
|
|
|
//班次
|
|
@@ -288,23 +314,26 @@ public class CheckTemplateServiceImpl extends ServiceImpl<CheckTemplateDao, Chec
|
|
|
pointCheckDo.setCheckstatus(MlConstants.POINT_CHECK_STATUS_WAIT);
|
|
|
// 点检预警状态默认正常
|
|
|
pointCheckDo.setCheckwarnstatus(MlConstants.POINTCEHCK_WARNSTATUS_NORMAL);
|
|
|
+ pointCheckDo.setTenantid(checkTemplate.getTenantid());
|
|
|
+ pointCheckDo.setSource("1");
|
|
|
+ pointCheckDo.setTemplatetype(checkTemplate.getTemplatetype());
|
|
|
//设备负责人
|
|
|
- Map<String,Object> duMap = new HashMap<>();
|
|
|
- duMap.put("CHECKITEMID",checkItemsdo.getId());
|
|
|
- List<CheckItemsDutyuserDo> checkItemsDutyusers = (List<CheckItemsDutyuserDo>)checkItemsDutyuserService.listByMap(duMap);
|
|
|
+ Map<String, Object> duMap = new HashMap<>();
|
|
|
+ duMap.put("CHECKITEMID", checkItemsdo.getId());
|
|
|
+ List<CheckItemsDutyuserDo> checkItemsDutyusers = (List<CheckItemsDutyuserDo>) checkItemsDutyuserService.listByMap(duMap);
|
|
|
//设置点检人
|
|
|
String pcids = null;
|
|
|
String pcnames = null;
|
|
|
- if(checkItemsDutyusers != null && checkItemsDutyusers.size()>0){
|
|
|
- for(CheckItemsDutyuserDo checkItemsDutyuser:checkItemsDutyusers){
|
|
|
+ if (checkItemsDutyusers != null && checkItemsDutyusers.size() > 0) {
|
|
|
+ for (CheckItemsDutyuserDo checkItemsDutyuser : checkItemsDutyusers) {
|
|
|
// 生产属性的员工为点检人
|
|
|
- if(MlConstants.USER_ATTR_PRODUCTION.equals(checkItemsDutyuser.getDutyuserattribute())){
|
|
|
- if(pcids == null){
|
|
|
+ if (MlConstants.USER_ATTR_PRODUCTION.equals(checkItemsDutyuser.getDutyuserattribute())) {
|
|
|
+ if (pcids == null) {
|
|
|
pcids = checkItemsDutyuser.getDutyuserid();
|
|
|
pcnames = checkItemsDutyuser.getDutyusername();
|
|
|
- }else{
|
|
|
- pcids = pcids+","+checkItemsDutyuser.getDutyuserid();
|
|
|
- pcnames = pcnames+","+checkItemsDutyuser.getDutyusername();
|
|
|
+ } else {
|
|
|
+ pcids = pcids + "," + checkItemsDutyuser.getDutyuserid();
|
|
|
+ pcnames = pcnames + "," + checkItemsDutyuser.getDutyusername();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -347,6 +376,7 @@ public class CheckTemplateServiceImpl extends ServiceImpl<CheckTemplateDao, Chec
|
|
|
PointCheckItemDo pointCheckItemDo = new PointCheckItemDo();
|
|
|
pointCheckItemDo.setId(SecurityUtil.getUUID());
|
|
|
pointCheckItemDo.setPointcheckid(pointCheckDo.getId());
|
|
|
+ pointCheckItemDo.setTenantid(checkTemplate.getTenantid());
|
|
|
// 检查内容模板
|
|
|
CheckItemContentDo checkItemContent = checkItemContentService.getById(v.getCheckitemcontentid());
|
|
|
pointCheckItemDo.setCheckitemcontentid(v.getCheckitemcontentid());
|
|
@@ -363,6 +393,7 @@ public class CheckTemplateServiceImpl extends ServiceImpl<CheckTemplateDao, Chec
|
|
|
pointCheckItemDo.setShiftcount(v.getShiftcount());
|
|
|
// 排序字段
|
|
|
pointCheckItemDo.setItemsort(v.getItemsort());
|
|
|
+ pointCheckItemDo.setSource("1");
|
|
|
pointCheckItems.add(pointCheckItemDo);
|
|
|
});
|
|
|
}
|
|
@@ -391,17 +422,5 @@ public class CheckTemplateServiceImpl extends ServiceImpl<CheckTemplateDao, Chec
|
|
|
checkTemplate.setEnablestatus(MlConstants.TEMPLATE_STATUS_CLOSE);
|
|
|
this.updateById(checkTemplate);
|
|
|
}
|
|
|
- if(map.get("newId") != null){
|
|
|
- String newId = map.get("newId").toString();
|
|
|
- // 模板编号
|
|
|
- SysSerialVo sysSerialVo = new SysSerialVo();
|
|
|
- sysSerialVo.setModulecode("asp_check_template_TEMPLATECODE");
|
|
|
- sysSerialVo.setRuleTemplateStr("@{date:yyyyMMdd}@{serialNumber:#000000}");
|
|
|
- String code = sysSerialNumberService.getCodeByTemplate(sysSerialVo);
|
|
|
- CheckTemplateDo checkTemplate = new CheckTemplateDo();
|
|
|
- checkTemplate.setId(newId);
|
|
|
- checkTemplate.setTemplatecode(code);
|
|
|
- this.updateById(checkTemplate);
|
|
|
- }
|
|
|
}
|
|
|
}
|