1
zhang
9 小时以前 286eadc0913fe9974ab2f2fd188fb707dc16ad40
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
package com.zy.core.operation.handler;
 
import com.core.common.Cools;
import com.zy.asrs.controller.vo.ApplyInDto;
import com.zy.asrs.controller.vo.ApplyInRepsonseDto;
import com.zy.asrs.entity.Job;
import com.zy.asrs.enums.WorkNoTypeType;
import com.zy.asrs.service.JobService;
import com.zy.asrs.service.WmsMainService;
import com.zy.asrs.service.WrkLastnoService;
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.BarcodeThread;
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;
 
import java.util.Date;
 
/**
 * 入库
 */
@Slf4j
@Component
public class AppleLocOperationHandler implements OperationHandler {
 
    @Autowired
    private SlaveProperties slaveProperties;
 
 
    @Autowired
    private WrkLastnoService wrkLastnoService;
 
    @Autowired
    private WmsMainService wmsMainService;
 
    @Autowired
    private JobService jobService;
 
 
    @Override
    public ConveyorStateType getType() {
        return ConveyorStateType.APPLYLOC;
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    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.getStaNo());
                    BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, devp.getId());
                    if (staProtocol == null) {
                        continue;
                    } else {
                        staProtocol = staProtocol.clone();
                    }
                    // 判断是否满足条件
                    if (!staProtocol.isLoading()) {
                        continue;
                    }
                    if (staProtocol.getWorkNo() > 0 && staProtocol.isAutoing()) {
                        String barcode = barcodeThread.getBarcode();
                        if (barcodeThread == null || Cools.isEmpty(barcode)) {
                            log.error("站点:{},未扫到码值:{}", staProtocol.getSiteId(), barcode);
                            return;
                        }
                        // 9991是空板,9992是满板
                        if (staProtocol.getWorkNo() >= 9991 && staProtocol.getWorkNo() <= 9992) {
                            Job job = jobService.getJobByBarcode(barcode);
                            // 申请入库
                            if (job == null || (job != null && job.getJobSts() == 8)) {
                                ApplyInRepsonseDto locOfWms = wmsMainService.getLocOfWms(applyIn(barcode, inSta.getStaNo() + "", staProtocol));
                                if (locOfWms != null) {
                                    job = new Job();
                                    job.setLoc(locOfWms.getLocNo());
                                    job.setTaskNo(locOfWms.getTaskNo());
                                    job.setBatchNo(locOfWms.getBatchNo());
                                    job.setBarcode(barcode);
                                    job.setStaNo(inSta.getTargetSta() + "");
                                    job.setJobNo(wrkLastnoService.nextWorkNo(WorkNoTypeType.WORK_NO_TYPE.type));
                                    job.setJobSts(ConveyorStateType.APPLYLOC.getStatus());
                                    job.setWmsTime(new Date());
                                    jobService.insert(job);
                                } else {
                                    log.info("WMS未返回库位信息,条码:{},站点:{}", barcode, inSta.getStaNo());
                                }
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
    }
 
    private ApplyInDto applyIn(String barcode, String staNo, StaProtocol staProtocol) {
        ApplyInDto applyInDto = new ApplyInDto();
        applyInDto.setStaNo(staNo);
        applyInDto.setBarcode(barcode);
        applyInDto.setFull(staProtocol.getWorkNo() == 9992);
        return applyInDto;
    }
}