Lius
2025-05-21 d0b97b5655a6cac1efbda08dad1d3019ed973923
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
118
119
120
121
122
123
124
125
126
127
128
129
130
package org.jeecg.modules.mdc.job;
 
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.util.DateUtils;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.modules.mdc.entity.MdcEquipment;
import org.jeecg.modules.mdc.entity.MdcEquipmentDaySchedule;
import org.jeecg.modules.mdc.service.IEquipmentWorkLineService;
import org.jeecg.modules.mdc.service.IMdcEquipmentService;
import org.jeecg.modules.mdc.util.CxfClientUtil;
import org.jeecg.modules.mdc.util.ThrowableUtil;
import org.jeecg.modules.mdc.vo.WsEquipmentEndWork;
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.quartz.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
 
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;
 
/**
 * @Author: Lius
 * @CreateTime: 2025-04-29
 * @Description: 完工任务
 */
@PersistJobDataAfterExecution
@DisallowConcurrentExecution
@Slf4j
public class WebServiceCompletedJob implements Job {
 
    /**
     * url
     */
    @Value("${webservice2.url}")
    private String url;
 
    /**
     * namespace
     */
    @Value("${webservice2.namespace}")
    private String namespace;
 
    /**
     * method
     */
    @Value("${webservice2.endWorkMethod}")
    private String method;
 
    @Resource
    private IQuartzJobService quartzJobService;
 
    @Resource
    private ISysQuartzLogService sysQuartzLogService;
 
    @Resource
    @Lazy
    private RedisUtil redisUtil;
 
    @Resource
    private IMdcEquipmentService mdcEquipmentService;
 
    @Resource
    private IEquipmentWorkLineService equipmentWorkLineService;
 
    @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("WebService上报完工任务 WebServiceCompletedJob start!  时间:" + DateUtils.now());
        long startTime = System.currentTimeMillis();
        try {
            List<MdcEquipment> mdcEquipmentList = mdcEquipmentService.list(new LambdaQueryWrapper<MdcEquipment>().eq(MdcEquipment::getDriveType, "FANUC"));
            if (mdcEquipmentList != null && !mdcEquipmentList.isEmpty()) {
                for (MdcEquipment mdcEquipment : mdcEquipmentList) {
                    if (redisUtil.hasKey("work:" + mdcEquipment.getEquipmentId())) {
                        MdcEquipmentDaySchedule mdcEquipmentDaySchedule = (MdcEquipmentDaySchedule) redisUtil.get("work:" + mdcEquipment.getEquipmentId());
                        String productName = mdcEquipmentDaySchedule.getProductName();
                        Map<String, Object> dataProductName = equipmentWorkLineService.getDataProductName(mdcEquipment.getSaveTableName());
                        if (dataProductName != null && !dataProductName.isEmpty()) {
                            if (dataProductName.containsKey("productname")) {
                                String proName = dataProductName.get("productname") == null ? "" : dataProductName.get("productname").toString();
                                if (!productName.equals(proName)) {
                                    //完工
                                    WsEquipmentEndWork wsEquipmentEndWork = new WsEquipmentEndWork();
                                    wsEquipmentEndWork.setMesId(mdcEquipmentDaySchedule.getMesId());
                                    wsEquipmentEndWork.setWorkshop(mdcEquipmentDaySchedule.getWorkshop());
                                    wsEquipmentEndWork.setProcessProgress("100");
                                    wsEquipmentEndWork.setTaskCode(mdcEquipmentDaySchedule.getTaskCode());
                                    wsEquipmentEndWork.setOpreationSeqNo(mdcEquipmentDaySchedule.getOpreationSeqNo());
                                    wsEquipmentEndWork.setMdsItemCode(mdcEquipmentDaySchedule.getMdsItemCode());
                                    wsEquipmentEndWork.setEquipmentId(mdcEquipment.getEquipmentId());
                                    wsEquipmentEndWork.setProcessNumber(mdcEquipmentDaySchedule.getBatchNum());
                                    Date date = dataProductName.get("collecttime") == null ? null : (Date) dataProductName.get("collecttime");
                                    wsEquipmentEndWork.setEndProcessTime(date);
                                    String s = JSONObject.toJSONString(wsEquipmentEndWork);
                                    log.info("上报完工数据 ===== " + s);
                                    String result = CxfClientUtil.invokeService(url, s, namespace, method);
                                    log.info("上报完工结果 ===== " + result);
                                    if (result.contains("成功")) {
//                                        mdcEquipmentDaySchedule.setProductName(productName);
                                        //开工设备删除redis
                                        redisUtil.del("work:" + mdcEquipment.getEquipmentId());
                                    }
                                }
                            }
                        }
                    }
                }
            }
            quartzLog.setIsSuccess(0);
        } catch (Exception e) {
            quartzLog.setIsSuccess(-1);
            quartzLog.setExceptionDetail(ThrowableUtil.getStackTrace(e));
        }
        long endTime = System.currentTimeMillis();
        quartzLog.setExecutionTime(Integer.parseInt(String.valueOf(endTime - startTime)));
        sysQuartzLogService.save(quartzLog);
    }
}