Lius
2025-04-25 4e8a8c130b7af3f8cab4a852265840f1e70bfa01
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package org.jeecg.modules.mdc.job;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.jeecg.modules.mdc.entity.MdcEquipment;
import org.jeecg.modules.mdc.service.IMdcEquipmentService;
import org.jeecg.modules.mdc.util.DateUtils;
import org.jeecg.modules.mdc.util.ThrowableUtil;
import org.jeecg.modules.mdcJc.dto.MesRcJobreport;
import org.jeecg.modules.mdcJc.entity.MdcJcRcJobreport;
import org.jeecg.modules.mdcJc.service.IMdcJcRcJobreportService;
import org.jeecg.modules.mdcJc.service.MesRcJobreportService;
import org.jeecg.modules.quartz.entity.QuartzJob;
import org.jeecg.modules.quartz.entity.SysQuartzLog;
import org.jeecg.modules.quartz.service.IQuartzJobService;
import org.jeecg.modules.quartz.service.ISysQuartzLogService;
import org.jeecg.modules.system.service.ISysAnnouncementService;
import org.quartz.*;
 
import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * @Author: Lius
 * @CreateTime: 2025-04-14
 * @Description: 同步MES加工信息(合格率)
 */
@PersistJobDataAfterExecution
@DisallowConcurrentExecution
@Slf4j
public class MesPartProcessInfoJob implements Job {
 
    /**
     * 若参数变量名修改 QuartzJobController中也需对应修改  时间: yyyyMMdd 例: 20230414
     */
    private String parameter;
 
    public void setParameter(String parameter) {
        this.parameter = parameter;
    }
 
    @Resource
    private IQuartzJobService quartzJobService;
 
    @Resource
    private ISysAnnouncementService sysAnnouncementService;
 
    @Resource
    private ISysQuartzLogService sysQuartzLogService;
 
    @Resource
    private IMdcJcRcJobreportService mdcJcRcJobreportService;
 
    @Resource
    private MesRcJobreportService mesRcJobreportService;
 
    @Resource
    private IMdcEquipmentService mdcEquipmentService;
 
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        SysQuartzLog quartzLog = new SysQuartzLog();
        quartzLog.setCreateTime(new Date());
        List<QuartzJob> byJobClassName = this.quartzJobService.findByJobClassName(this.getClass().getName());
        if (byJobClassName != null && !byJobClassName.isEmpty()) {
            quartzLog.setJobId(byJobClassName.get(0).getId());
        }
        log.info("定时获取MES系统加工个数任务 MesPartProcessInfoJob start!  时间:" + DateUtils.getNow());
        long startTime = System.currentTimeMillis();
        try {
            String date = "";
            if (StringUtils.isNotBlank(this.parameter)) {
                date = DateUtils.format(DateUtils.toDate(this.parameter, DateUtils.STRDATE), DateUtils.STR_DATE);
            } else {
                date = LocalDate.now().plusDays(-1).toString();
            }
 
            mdcJcRcJobreportService.remove(new LambdaQueryWrapper<MdcJcRcJobreport>().eq(MdcJcRcJobreport::getTheDate, date));
 
            //获取设备列表
            List<MdcEquipment> mdcEquipmentList = mdcEquipmentService.list();
            if (mdcEquipmentList != null && !mdcEquipmentList.isEmpty()) {
                List<String> equipmentIdList = mdcEquipmentList.stream().map(MdcEquipment::getEquipmentId).collect(Collectors.toList());
                List<MesRcJobreport> mesRcJobreportList = mesRcJobreportService.findPartProcessInfo(date, equipmentIdList);
                if (mesRcJobreportList != null && !mesRcJobreportList.isEmpty()) {
                    List<MdcJcRcJobreport> mdcJcRcJobreportList = new ArrayList<>();
                    for (MesRcJobreport mesRcJobreport : mesRcJobreportList) {
                        MdcJcRcJobreport mdcJcRcJobreport = new MdcJcRcJobreport();
                        mdcJcRcJobreport.setEquipmentId(mesRcJobreport.getDeviceNumber());
                        mdcJcRcJobreport.setOkuqty(mesRcJobreport.getOkuqty().intValue());
                        mdcJcRcJobreport.setProcessCount(mesRcJobreport.getQty().intValue());
                        mdcJcRcJobreport.setTheDate(date);
                        mdcJcRcJobreportList.add(mdcJcRcJobreport);
                    }
                    if (!mdcEquipmentList.isEmpty()) {
                        mdcJcRcJobreportService.saveBatch(mdcJcRcJobreportList);
                    }
                }
            }
 
            quartzLog.setIsSuccess(0);
        } catch (Exception e) {
            quartzLog.setIsSuccess(-1);
            quartzLog.setExceptionDetail(ThrowableUtil.getStackTrace(e));
            // 发送消息通知
            sysAnnouncementService.jobSendMessage("定时获取MES系统加工个数任务", quartzLog.getExceptionDetail());
        }
        long endTime = System.currentTimeMillis();
        quartzLog.setExecutionTime(Integer.parseInt(String.valueOf(endTime - startTime)));
        sysQuartzLogService.save(quartzLog);
    }
}