|
@@ -1,16 +1,15 @@
|
|
|
package com.rongwei.bscommon.sys.service.impl;
|
|
|
-
|
|
|
import cn.hutool.core.io.resource.ClassPathResource;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.excel.EasyExcel;
|
|
|
import com.alibaba.excel.ExcelWriter;
|
|
|
import com.alibaba.excel.write.metadata.WriteSheet;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.rongwei.bscommon.sys.dao.CommonDao;
|
|
|
import com.rongwei.bscommon.sys.excel.EquLubricationTaskManagementTemplate;
|
|
|
import com.rongwei.bscommon.sys.excel.EquMaintenanceTaskTemplate;
|
|
|
import com.rongwei.bscommon.sys.service.*;
|
|
|
-import com.rongwei.bscommon.sys.utils.ExcelUtils;
|
|
|
import com.rongwei.bsentity.domain.*;
|
|
|
import com.rongwei.bsentity.dto.EquMaintenanceOrderSumDTO;
|
|
|
import com.rongwei.bsentity.dto.EquipmentDisposeDTO;
|
|
@@ -21,13 +20,14 @@ import com.rongwei.bsentity.enums.TaskStatusEnum;
|
|
|
import com.rongwei.rwadmincommon.system.domain.SysDictDo;
|
|
|
import com.rongwei.rwadmincommon.system.service.SysDictService;
|
|
|
import com.rongwei.rwcommon.base.R;
|
|
|
+import com.rongwei.rwcommon.utils.SecurityUtil;
|
|
|
+import com.rongwei.rwcommoncomponent.file.service.SysFileItemService;
|
|
|
+import com.rongwei.rwcommonentity.commonservers.domain.SysFileItemDo;
|
|
|
import com.rongwei.safecommon.fegin.CXCommonFeginClient;
|
|
|
import com.rongwei.safecommon.utils.CXCommonUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.fileupload.FileItem;
|
|
|
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.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.mock.web.MockMultipartFile;
|
|
@@ -45,7 +45,6 @@ import static com.rongwei.safecommon.utils.SaveConstans.FileName.DEVICE_REPEATED
|
|
|
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
|
|
@@ -81,6 +80,9 @@ public class EquipmentSendNotifyServiceImpl implements EquipmentSendNotifyServic
|
|
|
@Autowired
|
|
|
private CommonDao commonDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private SysFileItemService sysFileItemService;
|
|
|
+
|
|
|
/**
|
|
|
* 根据任务ID发送 提醒
|
|
|
*
|
|
@@ -256,29 +258,6 @@ public class EquipmentSendNotifyServiceImpl implements EquipmentSendNotifyServic
|
|
|
}
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * 设备部位重复故障问题提醒
|
|
|
- *
|
|
|
- * @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();
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 故障停机提醒
|
|
@@ -319,6 +298,49 @@ public class EquipmentSendNotifyServiceImpl implements EquipmentSendNotifyServic
|
|
|
CXCommonUtils.sendNotify(FAUL_STOP_TITLE, context, null, userId.stream().distinct().collect(Collectors.toList()), dataId, FAUL_STOP_REMIND, true);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 设备部位重复故障问题提醒
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public R deviceRepeatedlyFailsNotify() {
|
|
|
+ //查询维修单汇总数据:根据故障发生时间自动查询每个工厂近3个月内 (以本月在往前倒推三个月至当前时间)所有
|
|
|
+ // 除去 无需维修、已关闭 且 维修对象分类 为 档案设备、工装 的 维修任务记录中,
|
|
|
+ // 然后根据所属工厂、设备类型、发生部位 分组查询对应分组类型的 数量记录 中 > 1的记录
|
|
|
+ List<EquMaintenanceOrderSumDTO> list = equMaintenanceOrderService.selectOrderSummaryData();
|
|
|
+ if (list.isEmpty()) {
|
|
|
+ log.info("记录为空,则不生成附件,也不生成提醒信息");
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+ //2.生成excel 文件,返回文件信息
|
|
|
+ SysFileItemDo fileItem = equMaintenanceOrderService.generateDeviceRepeatedlyFailsExcel(list);
|
|
|
+
|
|
|
+ //3.消息提醒
|
|
|
+ // 3.1发送人 取车间维修主管、设备部部长、设备部维修主管 角色中所有人员
|
|
|
+ List<String> userId = equMaintenanceOrderService.selectRoleList();
|
|
|
+ if (userId.isEmpty()) {
|
|
|
+ log.info("车间维修主管、设备部部长、设备部维修主管角色无提醒人");
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+ //3.2发送消息
|
|
|
+ String id = SecurityUtil.getUUID();
|
|
|
+ //附件关联业务字段存入消息主键
|
|
|
+ fileItem.setRelationid(id);
|
|
|
+ fileItem.setFilename(DEVICE_REPEATEDLY_FAILS_FILE_NAME);
|
|
|
+
|
|
|
+ //消息提醒的remark 存放附件的名称+id
|
|
|
+ String remark = fileItem.getFilename()+"-;-"+fileItem.getId();
|
|
|
+ CXCommonUtils.sendNotify(id,DEVICE_REPEATEDLY_FAILS_TITLE, DEVICE_REPEATEDLY_FAILS_CONTEXT, remark, userId.stream().distinct().collect(Collectors.toList()),
|
|
|
+ null, DEVICE_REPEATEDLY_FAILS_NOTICETYPE, true);
|
|
|
+
|
|
|
+ //4.修改附件
|
|
|
+ sysFileItemService.updateById(fileItem);
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 保养/润滑跨月未完成提醒
|
|
|
*
|
|
@@ -472,130 +494,8 @@ public class EquipmentSendNotifyServiceImpl implements EquipmentSendNotifyServic
|
|
|
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();
|
|
|
-
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 润滑任务导出数据迁移
|
|
@@ -724,7 +624,7 @@ public class EquipmentSendNotifyServiceImpl implements EquipmentSendNotifyServic
|
|
|
*
|
|
|
*/
|
|
|
|
|
|
- public List<EquMaintenanceTaskTemplate> maintainDeriveDate(PlantEnum plantEnum,List<EquMaintenanceTaskDo> maintenanceTaskList){
|
|
|
+ public List<EquMaintenanceTaskTemplate> maintainDeriveDate(PlantEnum plantEnum, List<EquMaintenanceTaskDo> maintenanceTaskList){
|
|
|
return maintenanceTaskList.stream().map(info ->{
|
|
|
EquMaintenanceTaskTemplate equMaintenanceTaskTemplate = new EquMaintenanceTaskTemplate();
|
|
|
BeanUtils.copyProperties(info,equMaintenanceTaskTemplate);
|