1
zhang
3 天以前 38ce5bc7cd58a218f89d8f9ca6aacd7e14d6d93e
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
package com.zy.core.operation.handler;
 
import com.core.exception.CoolException;
import com.zy.asrs.entity.Job;
import com.zy.asrs.enums.WorkNoTypeType;
import com.zy.asrs.service.CtuMainService;
import com.zy.asrs.service.JobService;
import com.zy.asrs.service.WrkLastnoService;
import com.zy.common.utils.News;
import com.zy.core.cache.MessageQueue;
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.Task;
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.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
 
@Slf4j
@Component
public class OutOperationHandler implements OperationHandler {
 
    @Autowired
    private SlaveProperties slaveProperties;
 
 
    @Autowired
    private WrkLastnoService wrkLastnoService;
 
    @Autowired
    private CtuMainService ctuMainService;
 
    @Autowired
    private JobService jobService;
 
 
    @Override
    public ConveyorStateType getType() {
        return ConveyorStateType.OUTBOUND;
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public synchronized void execute(CtuOperationConfig config) {
        try {
            // 根据输送线plc遍历
            for (DevpSlave devp : slaveProperties.getDevp()) {
                // 遍历出库口
                for (DevpSlave.Sta releaseSta : devp.getReleaseSta()) {
                    // 获取入库站信息
                    SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
                    StaProtocol staProtocol = devpThread.getStation().get(releaseSta.getStaNo());
                    if (staProtocol == null) {
                        continue;
                    } else {
                        staProtocol = staProtocol.clone();
                    }
                    // 判断是否满足条件
                    if (!staProtocol.isLoading()) {
                        continue;
                    }
                    //&& staProtocol.isOutEnable()
                    if (staProtocol.isAutoing() && staProtocol.getWorkNo() == 0) {
                        String seqNum = ctuMainService.checkStationStatus(releaseSta.getStaNo());
                        if (seqNum != null) {
                            Job jobBySeqNum = jobService.getJobBySeqNum(seqNum);
                            if (jobBySeqNum == null) {
                                int workNo = wrkLastnoService.nextWorkNo(WorkNoTypeType.WORK_NO_TYPE.type);
                                // 下发移动 且 下发plc命令
                                staProtocol.setWorkNo(workNo);
                                staProtocol.setStaNo(releaseSta.getTargetSta());
                                Job job = new Job();
                                job.setTaskNo(seqNum);
                                job.setJobNo(workNo);
                                job.setJobSts(2);
                                if (!jobService.insert(job)) {
                                    throw new CoolException("插入输送线任务失败," + jobBySeqNum + " - " + workNo);
                                }
                                devpThread.setPakMk(staProtocol.getSiteId(), false);
                                boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                                if (result) {
                                    log.info("输送线下发:{},{}", staProtocol.getWorkNo(), releaseSta.getTargetSta());
                                } else {
                                    News.error("" + config.getMark() + " - 发布命令至输送线队列失败!!! [plc编号:{}]", devp.getId());
                                }
                            }
                        } else {
                            News.errorNoLog("" + config.getMark() + " - 站点信息不符合入库条件!!!" + " 调用RCS检验未通过,站点:" + staProtocol.getSiteId());
                        }
                    } else {
                        News.errorNoLog("" + config.getMark() + " - 站点信息不符合入库条件!!!" + " 自动信号:" + staProtocol.isLoading() + "、可入信号:" + staProtocol.isInEnable() + "、空板信号:" + staProtocol.isEmptyMk() + "、工作号:" + staProtocol.getWorkNo() + "、锁定标记" + staProtocol.isPakMk());
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
    }
}