1
zhang
2026-01-24 6f2e70d03c9dde5cdb26b8911d6c19e2993a38ab
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
package com.zy.core.operation.handler;
 
import com.zy.asrs.entity.Job;
import com.zy.asrs.service.CtuMainService;
import com.zy.asrs.service.JobService;
import com.zy.asrs.service.WrkLastnoService;
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.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.interceptor.TransactionAspectSupport;
 
/**
 * 模拟用户按按钮
 */
@Slf4j
@Component
public class FakeUserOperationHandler implements OperationHandler {
 
    @Autowired
    private SlaveProperties slaveProperties;
 
 
    @Autowired
    private WrkLastnoService wrkLastnoService;
 
    @Autowired
    private CtuMainService ctuMainService;
 
    @Autowired
    private JobService jobService;
 
 
    @Override
    public ConveyorStateType getType() {
        return ConveyorStateType.FAKEWMS;
    }
 
    @Override
    public void execute(CtuOperationConfig config) {
 
        try {
            // 根据输送线plc遍历
            SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, 1);
            StaProtocol staProtocol = devpThread.getStation().get(1004);
            if (staProtocol == null) {
                return;
            } else {
                staProtocol = staProtocol.clone();
            }
            // 判断是否满足条件
            if (!staProtocol.isLoading()) {
                return;
            }
            if (staProtocol.getWorkNo() > 0 && staProtocol.isAutoing()) {
                Job jobByWorkNo = jobService.getJobByJobNo(staProtocol.getWorkNo());
                if (jobByWorkNo != null && jobByWorkNo.getJobSts() == 1) {
                    staProtocol.setStaNo(1006);
                    boolean result = MessageQueue.offer(SlaveType.Devp, 1, new Task(2, staProtocol));
                    if (result) {
                        jobByWorkNo.setJobSts(3);
                        jobByWorkNo.setMemo("模拟按按钮");
                        jobService.updateById(jobByWorkNo);
                        log.info("入库输送线下发:{},{}", staProtocol.getWorkNo(), 1006);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
    }
}