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
131
132
133
134
135
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.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.IMdcEquipmentDayScheduleService;
import org.jeecg.modules.mdc.service.IMdcEquipmentService;
import org.jeecg.modules.mdc.util.CxfClientUtil;
import org.jeecg.modules.mdc.util.DateUtils;
import org.jeecg.modules.mdc.util.ThrowableUtil;
import org.jeecg.modules.mdc.vo.WsEquipmentStartWork;
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 WebServiceStartWorkJob implements Job {
 
    /**
     * url
     */
    @Value("${webservice2.url}")
    private String url;
 
    /**
     * namespace
     */
    @Value("${webservice2.namespace}")
    private String namespace;
 
    /**
     * method
     */
    @Value("${webservice2.startWorkMethod}")
    private String method;
 
    @Resource
    private IQuartzJobService quartzJobService;
 
    @Resource
    private ISysQuartzLogService sysQuartzLogService;
 
    @Resource
    private IMdcEquipmentDayScheduleService mdcEquipmentDayScheduleService;
 
    @Resource
    private IMdcEquipmentService mdcEquipmentService;
 
    @Resource
    @Lazy
    private RedisUtil redisUtil;
 
    @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上报开工任务 WebServiceStartWorkJob start!  时间:" + DateUtils.getNow());
        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 = mdcEquipmentDayScheduleService.selectLast(mdcEquipment.getEquipmentId());
                        if (mdcEquipmentDaySchedule != null) {
                            //查询设备单表零件号
                            Map<String, Object> dataList = equipmentWorkLineService.getDataProductName(mdcEquipment.getSaveTableName());
                            if (dataList != null) {
                                if (dataList.containsKey("productname")) {
                                    String productName = dataList.get("productname") == null ? "" : dataList.get("productname").toString();
                                    if (productName.contains(mdcEquipmentDaySchedule.getMdsItemCode())) {
                                        log.info("验证自动开工开始,设备编号为 ====== " + mdcEquipment.getEquipmentId());
                                        WsEquipmentStartWork wsEquipmentStartWork = new WsEquipmentStartWork();
                                        wsEquipmentStartWork.setMesId(mdcEquipmentDaySchedule.getMesId());
                                        wsEquipmentStartWork.setEquipmentId(mdcEquipmentDaySchedule.getEquipmentId());
                                        wsEquipmentStartWork.setWorkshop(mdcEquipmentDaySchedule.getWorkshop());
                                        wsEquipmentStartWork.setTaskCode(mdcEquipmentDaySchedule.getTaskCode());
                                        wsEquipmentStartWork.setOpreationSeqNo(mdcEquipmentDaySchedule.getOpreationSeqNo());
                                        //获取开工时间
                                        Date date = dataList.get("collecttime") == null ? null : (Date) dataList.get("collecttime");
                                        wsEquipmentStartWork.setStartProcessTime(date);
                                        String s = JSONObject.toJSONString(wsEquipmentStartWork);
                                        log.info("上报开工数据 ===== " + s);
                                        String result = CxfClientUtil.invokeService(url, s, namespace, method);
                                        log.info("上报开工结果 ===== " + result);
                                        if (result.contains("成功")) {
                                            mdcEquipmentDaySchedule.setProductName(productName);
                                            //开工设备存入redis
                                            redisUtil.set("work:" + mdcEquipment.getEquipmentId(), mdcEquipmentDaySchedule);
                                        }
                                        return;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            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);
    }
}