Browse Source

设备重复部位故障提醒

huangpeng 1 year ago
parent
commit
81f0c0a928

+ 7 - 4
bs-common/src/main/java/com/rongwei/safecommon/fegin/CXCommonFeginClient.java

@@ -4,11 +4,10 @@ import com.rongwei.rwcommon.base.R;
 import com.rongwei.rwcommon.vo.MailDo;
 import com.rongwei.rwcommonentity.commonservers.vo.SysNotifyAnnounceVo;
 import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.http.MediaType;
 import org.springframework.scheduling.annotation.Async;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
 import java.util.List;
 import java.util.Map;
@@ -30,4 +29,8 @@ public interface CXCommonFeginClient {
 
     @PostMapping("sys/sysnotifyannounce/delete")
     R delete(@RequestBody List<String> ids);
+
+    @PostMapping(value = "sys/sysfile/upload?platform=ic-pc&foldercode=file_system&relationid=0"
+            ,consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
+    R upload(@RequestPart(value = "file",required = true) MultipartFile file);
 }

+ 8 - 0
bs-common/src/main/java/com/rongwei/safecommon/fegin/CXHysitx.java

@@ -6,6 +6,7 @@ import com.rongwei.rwcommonentity.commonservers.vo.SysNotifyAnnounceVo;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Component;
+import org.springframework.web.multipart.MultipartFile;
 
 import java.util.List;
 import java.util.Map;
@@ -48,4 +49,11 @@ public class CXHysitx implements CXCommonFeginClient {
         log.error("删除提醒失败,数据为{}",ids);
         return R.error();
     }
+
+    @Override
+    public R upload(MultipartFile file) {
+        return null;
+    }
+
+
 }

+ 8 - 0
bs-common/src/main/java/com/rongwei/safecommon/utils/CXCommonUtils.java

@@ -7,6 +7,7 @@ import com.google.common.collect.Lists;
 import com.rongwei.commonservice.serial.service.SysSerialNumberService;
 import com.rongwei.commonservice.service.RedisService;
 import com.rongwei.rwadmincommon.system.vo.SysUserVo;
+import com.rongwei.rwcommon.base.R;
 import com.rongwei.rwcommon.utils.SecurityUtil;
 import com.rongwei.rwcommon.utils.StringUtils;
 import com.rongwei.rwcommonentity.commonservers.vo.SysNotifyAnnounceVo;
@@ -18,6 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 import org.springframework.web.context.request.RequestContextHolder;
 import org.springframework.web.context.request.ServletRequestAttributes;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.PostConstruct;
 import javax.servlet.http.HttpServletRequest;
@@ -54,6 +56,8 @@ public class CXCommonUtils {
     private static CXCommonFeginClient commonFeginClient;
     public static final String DEFAULT_NOTIFY_STATUS = "3";
 
+
+
     @PostConstruct
     public void info() {
         redisService = autoRedisService;
@@ -225,4 +229,8 @@ public class CXCommonUtils {
         }
     }
 
+    public static R upload(MultipartFile file) {
+       return   commonFeginClient.upload(file);
+    }
+
 }

+ 45 - 0
bs-common/src/main/java/com/rongwei/safecommon/utils/SaveConstans.java

@@ -143,6 +143,11 @@ public class SaveConstans {
          */
         public static final String MOBILE_PLANNING_TASK = "mobilePlanningTask";
 
+        /**
+         * 设备部位重复故障问题提醒类型
+         */
+        public static final String DEVICE_REPEATEDLY_FAILS_NOTICETYPE = "device_repeatedly_fails";
+
         /**
          * 设备报废申请审批通过通知
          */
@@ -222,6 +227,12 @@ public class SaveConstans {
          * 大修任务超期提醒标题
          */
         public static final String PLANNING_TASK_TITLE = "大修任务超期提醒";
+        /**
+         * 设备部位重复故障问题提醒标题
+         */
+        public static final String DEVICE_REPEATEDLY_FAILS_TITLE = "设备部位重复故障问题提醒";
+
+
 
         /**
          * 设备报废申请审批通过通知
@@ -304,5 +315,39 @@ public class SaveConstans {
          * 设备报废申请审批通过提醒内容
          */
         public static final String EQU_SCRAP_CONTENT = "【%s】于【%s】申请【%s】【%s】【%s】使用的设备进行报废处置申请已审批通过,系统已将该设备进行标记报废标记处理,此设备的相关保养、润滑相关计划请及时进行停用处理,请大家注意。";
+
+         /**
+         * 设备部位重复故障问题提醒内容
+         */
+        public static final String DEVICE_REPEATEDLY_FAILS_CONTEXT = "近三个月内设备部位重复故障问题提醒说明(含三个厂,各自独立),单个工厂对相同问题重复发生请大家互相学习解决方案并加以改进,具体信息详见提醒内容中附件表格。";
+
+    }
+
+    /**
+     * 模板路径
+     */
+    public static class TemplatePath {
+
+        /**
+         * 设备部位重复故障问题excel 模板名称
+         */
+        public static final String DEVICE_REPEATEDLY_FAILS_TEMPLATE_NAME = "template/设备部位重复故障问题.xls";
+
+
     }
+
+    /**
+     * 模板路径
+     */
+    public static class FileName {
+
+
+        /**
+         * 设备部位重复故障问题 生成excel名称
+         */
+        public static final String DEVICE_REPEATEDLY_FAILS_FILE_NAME = "设备部位重复故障问题.xls";
+
+    }
+
+
 }

+ 8 - 0
cx-equipment/cx-equipment-common/src/main/java/com/rongwei/bscommon/sys/service/EquipmentSendNotifyService.java

@@ -60,4 +60,12 @@ public interface EquipmentSendNotifyService {
     void sendPlanningTasksNotify(String planyear, String belongfactory, Integer taskquantity, String fileItemId);
 
     void equScrapAuditNotify(EquipmentDisposeDTO equipmentDisposeDTO);
+
+
+    /**
+     * 设备部位重复故障问题提醒
+     * @return
+     */
+    R deviceRepeatedlyFailsNotify();
+
 }

+ 162 - 0
cx-equipment/cx-equipment-common/src/main/java/com/rongwei/bscommon/sys/service/impl/EquipmentSendNotifyServiceImpl.java

@@ -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();
+
+    }
 }
 
+

+ 47 - 0
cx-equipment/cx-equipment-common/src/main/java/com/rongwei/bscommon/sys/utils/ExcelUtils.java

@@ -1,8 +1,17 @@
 package com.rongwei.bscommon.sys.utils;
 
+import com.alibaba.fastjson.JSON;
+import com.rongwei.rwcommon.base.R;
+import com.rongwei.safecommon.utils.CXCommonUtils;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.CellType;
 import org.apache.poi.ss.usermodel.Row;
+import org.springframework.mock.web.MockMultipartFile;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.*;
+import java.util.Map;
 
 /**
  * @author zhou
@@ -28,4 +37,42 @@ public class ExcelUtils {
         return true;
     }
 
+
+    /**
+     * 调用接口生成文件
+     * @param workbook
+     * @param fileName
+     * @return
+     */
+    public static  String feginCommonUpload(HSSFWorkbook workbook, String fileName, String suffix){
+        String id="";
+        try {
+            // 创建临时文件
+            File tempFile = File.createTempFile(fileName, suffix);
+            tempFile.deleteOnExit();
+            //数据写入临时文件中
+            FileOutputStream outputStream = new FileOutputStream(tempFile);
+            workbook.write(outputStream);
+            outputStream.close();
+            // 获取临时文件的InputStream
+            InputStream inputStream = new FileInputStream(tempFile);
+            // 使用临时文件创建一个 MultipartFile 实例
+            MultipartFile multipartFile = new MockMultipartFile("file", tempFile.getName() , "application/vnd.ms-excel", inputStream);
+            //文件上传只需将参数中的键指定(默认file),值设为文件对象即可,对于使用者来说,文件上传与普通表单提交并无区别
+            R upload = CXCommonUtils.upload(multipartFile);
+            if (upload.getCode().equals("200")){
+                Map<String,String> map = (Map<String, String>) JSON.parse(upload.getData().toString());
+                id =map.get("id");
+            }
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+
+        return id;
+    }
+
+
+
+
+
 }

BIN
cx-equipment/cx-equipment-common/src/main/resources/template/设备部位重复故障问题.xls


+ 29 - 0
cx-equipment/cx-equipment-entity/src/main/java/com/rongwei/bsentity/domain/EquMaintenanceOrderVo.java

@@ -0,0 +1,29 @@
+package com.rongwei.bsentity.domain;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * @author  cyn 
+ * @create 2024-01-19 14:52 
+ */
+
+@Data
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class EquMaintenanceOrderVo  extends EquMaintenanceOrderDo implements Serializable {
+
+	/**
+	 * table name:ID
+	 * table type:varchar(36)
+	 * table comment:主键
+	 */
+	private String devicetypename;
+
+
+}

+ 44 - 0
cx-equipment/cx-equipment-entity/src/main/java/com/rongwei/bsentity/dto/EquMaintenanceOrderSumDTO.java

@@ -0,0 +1,44 @@
+package com.rongwei.bsentity.dto;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.io.Serializable;
+
+/**
+ * 提醒导出excel 汇总数据接收
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class EquMaintenanceOrderSumDTO implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+
+    /**
+     * 所属工厂名称
+     */
+    private String plant;
+
+    /**
+     * 设备类型名称
+     */
+    private String devicetype;
+
+
+    /**
+     * 问题发生部位
+     */
+    private String problemlocation;
+
+    /**
+     * ids
+     */
+    private String ids;
+
+    /**
+     * 数量
+     */
+    private Integer count;
+}

+ 1 - 0
cx-equipment/cx-equipment-entity/src/main/java/com/rongwei/bsentity/enums/PlantEnum.java

@@ -2,6 +2,7 @@ package com.rongwei.bsentity.enums;
 
 import lombok.Getter;
 
+import java.util.Arrays;
 import java.util.stream.Stream;
 
 /**

+ 17 - 0
cx-equipment/cx-equipment-server/src/main/java/com/rongwei/bsserver/sys/controller/EquipmentSendNotifyController.java

@@ -96,4 +96,21 @@ public class EquipmentSendNotifyController {
         }
     };
 
+
+    /**
+     * 设备部位重复故障问题提醒 repeatEquipmentFaultNotify
+     * @return
+     */
+    @PostMapping("/deviceRepeatedlyFailsNotify")
+    public R repeatEquipmentFaultNotify(){
+        try {
+            log.info("进入接口:/send-notify/deviceRepeatedlyFailsNotify;");
+            return sendNotifyService.deviceRepeatedlyFailsNotify();
+        }catch (Exception e){
+            ExceptionUtils.printExceptionDetail(e,"发送消息提醒失败,异常为:");
+            log.info(e.getMessage());
+            return R.error(e.getMessage());
+        }
+    };
+
 }