|
@@ -1,13 +1,19 @@
|
|
|
package com.rongwei.bscommon.sys.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.io.resource.ClassPathResource;
|
|
|
import com.rongwei.bscommon.sys.dao.CommonDao;
|
|
|
import com.rongwei.bscommon.sys.service.AspCheckItemsService;
|
|
|
import com.rongwei.bscommon.sys.service.EquLubricationTaskManagementService;
|
|
|
+import com.rongwei.bscommon.sys.service.EquMaintenanceOrderService;
|
|
|
import com.rongwei.bscommon.sys.service.EquMaintenanceTaskService;
|
|
|
import com.rongwei.bscommon.sys.service.EquipmentSendNotifyService;
|
|
|
+import com.rongwei.bscommon.sys.utils.ExcelUtils;
|
|
|
import com.rongwei.bsentity.domain.AspCheckItems;
|
|
|
import com.rongwei.bsentity.domain.EquLubricationTaskManagementDo;
|
|
|
+import com.rongwei.bsentity.domain.EquMaintenanceOrderDo;
|
|
|
import com.rongwei.bsentity.domain.EquMaintenanceTaskDo;
|
|
|
+import com.rongwei.bsentity.dto.EquMaintenanceOrderSumDTO;
|
|
|
+import com.rongwei.bsentity.enums.PlantEnum;
|
|
|
import com.rongwei.bsentity.dto.EquipmentDisposeDTO;
|
|
|
import com.rongwei.rwadmincommon.system.domain.SysDictDo;
|
|
|
import com.rongwei.rwadmincommon.system.service.SysDictService;
|
|
@@ -16,17 +22,24 @@ import com.rongwei.safecommon.fegin.CXCommonFeginClient;
|
|
|
import com.rongwei.safecommon.utils.CXCommonUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFRow;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFSheet;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.io.*;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
+import static com.rongwei.safecommon.utils.SaveConstans.FileName.DEVICE_REPEATEDLY_FAILS_FILE_NAME;
|
|
|
import static com.rongwei.safecommon.utils.SaveConstans.NotifyContent.*;
|
|
|
import static com.rongwei.safecommon.utils.SaveConstans.NotifyTitle.*;
|
|
|
import static com.rongwei.safecommon.utils.SaveConstans.NotifyType.*;
|
|
|
+import static com.rongwei.safecommon.utils.SaveConstans.TemplatePath.DEVICE_REPEATEDLY_FAILS_TEMPLATE_NAME;
|
|
|
|
|
|
/**
|
|
|
* @author shangmi
|
|
@@ -50,6 +63,9 @@ public class EquipmentSendNotifyServiceImpl implements EquipmentSendNotifyServic
|
|
|
@Autowired
|
|
|
private EquLubricationTaskManagementService equLubricationTaskManagementService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private EquMaintenanceOrderService equMaintenanceOrderService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private AspCheckItemsService aspCheckItemsService;
|
|
|
|
|
@@ -224,5 +240,151 @@ public class EquipmentSendNotifyServiceImpl implements EquipmentSendNotifyServic
|
|
|
CXCommonUtils.sendNotify(EQU_SCRAP_TITLE, context, null, userId.stream().distinct().collect(Collectors.toList()),
|
|
|
equipmentDisposeDTO.getId(), EQU_SCRAP_TASK, true);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设备部位重复故障问题提醒
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public R deviceRepeatedlyFailsNotify() {
|
|
|
+ //查询3月前的时间
|
|
|
+ Date startDate = getBeforeThreeMonthDate();
|
|
|
+ //查询维修单汇总数据:根据故障发生时间自动查询每个工厂近3个月内 (以本月在往前倒推三个月至当前时间)所有 除去 无需维修、已关闭 且 维修对象分类 为 档案设备、工装 的 维修任务记录中,
|
|
|
+ // 然后根据所属工厂、设备类型、发生部位 分组查询对应分组类型的 数量记录 中 > 1的记录
|
|
|
+ List<EquMaintenanceOrderSumDTO> list= equMaintenanceOrderService.selectOrderSummaryData(startDate,new Date());
|
|
|
+ if (list.isEmpty()) {
|
|
|
+ log.info("记录为空,则不生成附件,也不生成提醒信息");
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+ //2.生成excel 文件
|
|
|
+ String id= generateDeviceRepeatedlyFailsExcel(list);
|
|
|
+ //3.消息提醒
|
|
|
+ generateDeviceRepeatedlyFailsNotify(id);
|
|
|
+
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成设备部位重复故障问题提醒
|
|
|
+ * @param id
|
|
|
+ */
|
|
|
+ private void generateDeviceRepeatedlyFailsNotify(String id) {
|
|
|
+ // 发送人 取车间维修主管、设备部部长、设备部维修主管 角色中所有人员
|
|
|
+ List<String> userId = equMaintenanceOrderService.selectRoleList();
|
|
|
+ if (userId.isEmpty()) {
|
|
|
+ log.info("车间维修主管、设备部部长、设备部维修主管角色无提醒人");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ CXCommonUtils.sendNotify(DEVICE_REPEATEDLY_FAILS_TITLE, DEVICE_REPEATEDLY_FAILS_CONTEXT, null, userId.stream().distinct().collect(Collectors.toList()),
|
|
|
+ id, DEVICE_REPEATEDLY_FAILS_NOTICETYPE, true);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成 备部位重复故障问题 excel 记录
|
|
|
+ * @param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String generateDeviceRepeatedlyFailsExcel(List<EquMaintenanceOrderSumDTO> list) {
|
|
|
+
|
|
|
+ try {
|
|
|
+ //1.获取模板
|
|
|
+ ClassPathResource classPathResource = new ClassPathResource(DEVICE_REPEATEDLY_FAILS_TEMPLATE_NAME);
|
|
|
+ InputStream inputStream = classPathResource.getStream();
|
|
|
+ HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
|
|
|
+ HSSFSheet sheet0 = workbook.getSheetAt(0);
|
|
|
+ HSSFSheet sheet1 = workbook.getSheetAt(1);
|
|
|
+ HSSFSheet sheet2 = workbook.getSheetAt(2);
|
|
|
+ HSSFSheet sheet3 = workbook.getSheetAt(3);
|
|
|
+ //2.填充数据
|
|
|
+ //2.1 给第一页数据填充数据
|
|
|
+ for (int i=0;i<list.size()-1;i++){
|
|
|
+ // 创建行
|
|
|
+ HSSFRow row = sheet0.createRow(i+1);
|
|
|
+ row.createCell(0).setCellValue(list.get(i).getPlant()); // 所属工厂
|
|
|
+ row.createCell(1).setCellValue(list.get(i).getDevicetype()); //设备类型
|
|
|
+ row.createCell(2).setCellValue(list.get(i).getProblemlocation()); //发生部位
|
|
|
+ row.createCell(3).setCellValue(list.get(i).getCount()); //数量
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取后面3页工厂的数据,通过ids 获取所有数据
|
|
|
+ String ids = list.stream()
|
|
|
+ .map(obj -> String.valueOf(obj.getIds()))
|
|
|
+ .collect(Collectors.joining(","));
|
|
|
+ List<EquMaintenanceOrderDo> dos = equMaintenanceOrderService.selectOrderDataByIds(ids);
|
|
|
+ //根据工厂进行分组
|
|
|
+ Map<String, List<EquMaintenanceOrderDo>> listMap = dos.stream()
|
|
|
+ .collect(Collectors.groupingBy(EquMaintenanceOrderDo::getTenantid));
|
|
|
+ //2.2板材
|
|
|
+ fillPlantData(listMap.get( PlantEnum.CXBC.getId()),sheet1);
|
|
|
+ //2.3精铝
|
|
|
+ fillPlantData(listMap.get( PlantEnum.CXJL.getId()),sheet2);
|
|
|
+ //2.4箔材
|
|
|
+ fillPlantData(listMap.get( PlantEnum.CXLB.getId()),sheet3);
|
|
|
+ //3数据填充生成文件
|
|
|
+ String id = ExcelUtils.feginCommonUpload(workbook, DEVICE_REPEATEDLY_FAILS_FILE_NAME.split("\\.")[0], "."+ DEVICE_REPEATEDLY_FAILS_FILE_NAME.split("\\.")[1]);
|
|
|
+ log.info("返回文件id:{}",id);
|
|
|
+ return id ;
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("生成设备部位重复故障excel 失败:{}",e.getMessage());
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 填充后3页工厂数据
|
|
|
+ * @param list
|
|
|
+ * @param sheet
|
|
|
+ */
|
|
|
+ private void fillPlantData(List<EquMaintenanceOrderDo> list, HSSFSheet sheet) {
|
|
|
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ for (int i=0;i<list.size()-1;i++){
|
|
|
+ // 创建行
|
|
|
+ HSSFRow row = sheet.createRow(i+1);
|
|
|
+ row.createCell(0).setCellValue(list.get(i).getJobnumber()); //工单编号
|
|
|
+ row.createCell(1).setCellValue(list.get(i).getPlant()); //所属工厂
|
|
|
+ row.createCell(2).setCellValue(list.get(i).getWorkshop()); //使用车间
|
|
|
+ row.createCell(3).setCellValue(list.get(i).getEquipmentname()); //设备名称
|
|
|
+ row.createCell(4).setCellValue(list.get(i).getEquipmentnumber()); //设备编号
|
|
|
+ row.createCell(5).setCellValue(list.get(i).getIncidenttime()==null?"":dateFormat.format(list.get(i).getIncidenttime())); //故障发生时间
|
|
|
+ row.createCell(6).setCellValue(list.get(i).getProblemlocation()); //问题发生部位
|
|
|
+ row.createCell(7).setCellValue(list.get(i).getFaultcondition()); //设备故障情况
|
|
|
+ row.createCell(8).setCellValue(list.get(i).getIshalt()==null?"":sysDictService.getDictNameByValue("YORN",list.get(i).getIshalt())); //是否停机
|
|
|
+ row.createCell(9).setCellValue(list.get(i).getHalttime()==null?"":dateFormat.format(list.get(i).getHalttime())); //停机时间
|
|
|
+ row.createCell(10).setCellValue(list.get(i).getCreateusername()); //报修申请人
|
|
|
+ row.createCell(11).setCellValue(list.get(i).getServiceperson()); //维修人
|
|
|
+ row.createCell(12).setCellValue(list.get(i).getCausefailure()); //故障发生原因
|
|
|
+ row.createCell(13).setCellValue(list.get(i).getResult()); //维修结果
|
|
|
+ row.createCell(14).setCellValue(list.get(i).getRepairstatus()==null?"":sysDictService.getDictNameByValue("maintenance_state",list.get(i).getRepairstatus())); //维修状态
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取3月前的时间
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Date getBeforeThreeMonthDate(){
|
|
|
+ // 创建一个Calendar实例
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ // 将Calendar实例设置为当前时间
|
|
|
+ calendar.setTimeInMillis(System.currentTimeMillis());
|
|
|
+ // 减去3个月的时间
|
|
|
+ calendar.add(Calendar.MONTH, -3);
|
|
|
+ // 将日期设置为1号
|
|
|
+ calendar.set(Calendar.DAY_OF_MONTH, 1);
|
|
|
+ // 将时分秒设置为00:00:00
|
|
|
+ calendar.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
+ calendar.set(Calendar.MINUTE, 0);
|
|
|
+ calendar.set(Calendar.SECOND, 0);
|
|
|
+ calendar.set(Calendar.MILLISECOND, 0);
|
|
|
+ log.info("开始时间{}",calendar.getTime());
|
|
|
+ return calendar.getTime();
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+
|