1
zhang
昨天 d35e2accdca4b3762359231f4fe479c9538b6f6f
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
package com.zy.core.operation.handler;
 
import com.core.common.Cools;
import com.core.common.DateUtils;
import com.zy.asrs.controller.vo.OpenBusSubmitParam;
import com.zy.asrs.controller.vo.TaskDto;
import com.zy.asrs.entity.Job;
import com.zy.asrs.service.CtuMainService;
import com.zy.asrs.service.JobService;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.ConveyorStateType;
import com.zy.core.enums.SlaveType;
import com.zy.core.model.DevpSlave;
import com.zy.core.model.protocol.StaProtocol;
import com.zy.core.operation.OperationHandler;
import com.zy.core.properties.CtuOperationConfig;
import com.zy.core.properties.SlaveProperties;
import com.zy.core.thread.SiemensDevpThread;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
/**
 * 发送任务给RCS
 */
@Slf4j
@Component
public class SendTaskOperationHandler implements OperationHandler {
 
    @Autowired
    private SlaveProperties slaveProperties;
 
 
    @Autowired
    private JobService jobService;
 
 
    @Autowired
    private CtuMainService ctuMainService;
 
    @Override
    public ConveyorStateType getType() {
        return ConveyorStateType.SENDTASK;
    }
 
    @Override
    public synchronized void execute(CtuOperationConfig config) {
        try {
            // 根据输送线plc遍历
            for (DevpSlave devp : slaveProperties.getDevp()) {
                // 遍历入库口
                for (DevpSlave.Sta inSta : devp.getInSta()) {
                    // 根据输送线plc遍历
                    SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
                    StaProtocol staProtocol = devpThread.getStation().get(inSta.getTargetSta());
                    if (staProtocol == null) {
                        return;
                    } else {
                        staProtocol = staProtocol.clone();
                    }
                    // 判断是否满足条件
                    if (!staProtocol.isLoading()) {
                        return;
                    }
                    if (staProtocol.getWorkNo() > 0 && staProtocol.isAutoing()) {
                        Job job = jobService.getJobByJobNo(staProtocol.getWorkNo());
                        if (job != null && job.getJobSts() == 5) {
                            OpenBusSubmitParam openBusSubmitParam = new OpenBusSubmitParam();
                            openBusSubmitParam.setBatchNo(DateUtils.convert(new Date()));
                            List<TaskDto> taskList = new ArrayList<>();
                            TaskDto taskDto = new TaskDto();
                            taskDto.setTaskNo(job.getTaskNo());
                            taskDto.setBatchNo(job.getBatchNo());
                            taskDto.setOriSta(job.getStaNo());
                            taskDto.setDestLoc(job.getLoc());
                            //TODO
                            taskDto.setPriority(9527);
                            taskList.add(taskDto);
                            openBusSubmitParam.setTasks(taskList);
                            if (ctuMainService.sendTask(openBusSubmitParam)) {
                                job.setJobSts(7);
                                job.setRcsTime(new Date());
                                jobService.updateById(job);
                                log.info("任务发送给RCS成功," + job.getTaskNo() + " - " + job.getJobNo());
                            } else {
                                log.info("任务发送给RCS失败," + job.getTaskNo() + " - " + job.getJobNo());
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
    }
}