1
zhang
20 小时以前 27b048e77b68752c7c3060b9e31ad46efb4101a5
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package com.zy.acs.conveyor.core.operation.handler;
 
import com.alibaba.fastjson.JSON;
import com.zy.acs.common.utils.News;
import com.zy.acs.common.utils.RedisSupport;
import com.zy.acs.conveyor.controller.vo.ApplyInDto;
import com.zy.acs.conveyor.controller.vo.ApplyInRepsonseDto;
import com.zy.acs.conveyor.core.constant.RedisConveyorConstant;
import com.zy.acs.conveyor.core.enums.ConveyorStateType;
import com.zy.acs.conveyor.core.model.StaProtocol;
import com.zy.acs.conveyor.core.operation.OperationHandler;
import com.zy.acs.conveyor.core.properties.CtuOperationConfig;
import com.zy.acs.conveyor.core.properties.DevpSlave;
import com.zy.acs.conveyor.core.properties.SlaveProperties;
import com.zy.acs.conveyor.core.service.StationService;
import com.zy.acs.conveyor.entity.Job;
import com.zy.acs.conveyor.enums.WorkNoTypeType;
import com.zy.acs.conveyor.service.JobService;
import com.zy.acs.conveyor.service.WmsMainService;
import com.zy.acs.conveyor.service.WrkLastnoService;
import com.zy.acs.framework.common.Cools;
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;
import java.util.Map;
 
/**
 * 入库
 */
@Slf4j
@Component
public class AppleLocOperationHandler implements OperationHandler {
 
    @Autowired
    private SlaveProperties slaveProperties;
 
 
    @Autowired
    private WrkLastnoService wrkLastnoService;
 
    @Autowired
    private WmsMainService wmsMainService;
 
    @Autowired
    private JobService jobService;
 
 
    @Autowired
    private StationService stationService;
 
 
    private final RedisSupport redis = RedisSupport.defaultRedisSupport;
 
 
    @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遍历
                    Map<Integer, StaProtocol> stationMap = stationService.getStationMap(devp.getId());
                    StaProtocol staProtocol = stationMap.get(inSta.getStaNo());
                    if (staProtocol == null) {
                        continue;
                    } else {
                        staProtocol = staProtocol.clone();
                    }
                    // 判断是否满足条件
                    if (staProtocol.getWorkNo() == 0) {
                        continue;
                    }
                    if (!staProtocol.isAutoing()) {
                        //News.error("{}:站点:{},非自动", config.getMark(), staProtocol.getSiteId());
                        continue;
                    }
                    if (!staProtocol.isLoading()) {
                        News.error("{}:站点:{},无物", config.getMark(), staProtocol.getSiteId());
                        continue;
                    }
                    if (staProtocol.isWeightErr()){
                        News.error("{}:站点:{},重量异常:{}", config.getMark(), staProtocol.getSiteId(), staProtocol.getWeight());
                        continue;
                    }
                    if (staProtocol.isBarcodeErr()){
                        News.error("{}:站点:{},条码异常:{}",  config.getMark(),staProtocol.getSiteId(), staProtocol.getBarcode());
                        continue;
                    }
                    if (staProtocol.isLoadErr()){
                        News.error("{}:站点:{},入库时检测托盘上有无货物",  config.getMark(),staProtocol.getSiteId());
                        continue;
                    }
                    String barcode = staProtocol.getBarcode();
                    if (Cools.isEmpty(barcode)) {
                        News.error("站点:{},未扫到码值:{}", staProtocol.getSiteId(), barcode);
                        continue;
                    }
                    Job job = jobService.getJobByJobNo(staProtocol.getWorkNo());
                    //Job job = jobService.getJobByBarcode(barcode);
                    if (job == null) {
                        News.error("{}:站点:{},找不到任务", config.getMark(), staProtocol.getSiteId());
                        continue;
                    }
                    if (job.getJobSts() != ConveyorStateType.STARTUP.getStatus()) {
                        if (job.getJobSts() == ConveyorStateType.INBOUND.getStatus()) {
                            continue;
                        }
                        News.error("{}:站点:{},任务状态不对,{}", config.getMark(), staProtocol.getSiteId(), JSON.toJSON(job));
                        continue;
                    }
 
                    ApplyInRepsonseDto locOfWms = wmsMainService.getLocOfWms(applyIn(barcode, inSta.getStaNo() + "", staProtocol));
                    if (locOfWms != null) {
                        staProtocol.setWorkNo(staProtocol.getWorkNo());
                        staProtocol.setStaNo(inSta.getTargetSta());
                        redis.push(RedisConveyorConstant.CONVEYOR_TASK_FLAG, staProtocol);
                        job.setLoc(locOfWms.getLocNo());
                        job.setStaNo(String.valueOf(inSta.getTargetSta() + 1));
                        job.setTaskNo(locOfWms.getTaskNo());
                        job.setBatchNo(locOfWms.getBatchNo());
                        job.setBarcode(barcode);
                        job.setWmsTime(new Date());
                        job.setJobSts(ConveyorStateType.INBOUND.getStatus());
                        //if (jobService.insert(initJob(locOfWms, barcode, workNo, inSta.getTargetSta() + ""))) {
                        if (jobService.updateById(job)) {
                            News.info("申请入库成功,条码:{},站点:{}", barcode, inSta.getStaNo());
 
                        }
                    } else {
                        News.error("WMS未返回库位信息,条码:{},站点:{}", barcode, inSta.getStaNo());
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
    }
 
 
    private Job initJob(ApplyInRepsonseDto locOfWms, String barcode, Integer workNo, String staNo) {
        Job job = new Job();
        job.setLoc(locOfWms.getLocNo());
        job.setTaskNo(locOfWms.getTaskNo());
        job.setBatchNo(locOfWms.getBatchNo());
        job.setBarcode(barcode);
        job.setStaNo(staNo);
        job.setJobNo(workNo);
        job.setJobSts(ConveyorStateType.INBOUND.getStatus());
        job.setWmsTime(new Date());
        return job;
    }
 
 
 
    private ApplyInDto applyIn(String barcode, String staNo, StaProtocol staProtocol) {
        ApplyInDto applyInDto = new ApplyInDto();
        applyInDto.setStaNo(staNo);
        applyInDto.setBarcode(barcode);
        applyInDto.setFull(staProtocol.isFullPlt());
        applyInDto.setWeight(staProtocol.getWeight());
        return applyInDto;
    }
}