skyouc
2024-12-21 c635d78b479510ebe2556a420948effcd30a0731
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
package com.zy.asrs.wms.asrs.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zy.asrs.framework.exception.CoolException;
import com.zy.asrs.wms.asrs.entity.*;
import com.zy.asrs.wms.asrs.entity.enums.CacheSiteStatusType;
import com.zy.asrs.wms.asrs.entity.enums.TaskStsType;
import com.zy.asrs.wms.asrs.entity.param.SeedCompleteParam;
import com.zy.asrs.wms.asrs.mapper.CacheSiteMapper;
import com.zy.asrs.wms.asrs.service.*;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.*;
 
@Service("cacheSiteService")
public class CacheSiteServiceImpl extends ServiceImpl<CacheSiteMapper, CacheSite> implements CacheSiteService {
 
    @Autowired
    private OrderService orderService;
    @Autowired
    private OrderDetlService orderDetlService;
    @Autowired
    private WaveSeedService waveSeedService;
    @Autowired
    private WaveSeedLogService waveSeedLogService;
    @Autowired
    private TaskService taskService;
    @Autowired
    private TaskDetlService taskDetlService;
    @Autowired
    private PlatformService platformService;
    @Autowired
    private PlatformDetlService platformDetlService;
 
 
    @Override
    public List<String> getChannelList() {
        return this.baseMapper.getChannelList();
    }
 
    @Override
    public boolean seedCompletePreview(SeedCompleteParam param) {
        if (param == null) {
            throw new CoolException("参数不能为空");
        }
 
        String siteNo = param.getSiteNo();
        if (siteNo == null) {
            throw new CoolException("播种站点编号不能为空");
        }
 
        CacheSite cacheSite = this.getOne(new LambdaQueryWrapper<CacheSite>().eq(CacheSite::getSiteNo, siteNo));
        if(cacheSite == null){
            throw new CoolException("播种站点不存在");
        }
 
        if (cacheSite.getSiteStatus().equals(CacheSiteStatusType.O.id)) {
            throw new CoolException("站点状态异常");
        }
 
        Long orderId = cacheSite.getOrderId();
        Order order = orderService.getById(orderId);
        if (order == null) {
            throw new CoolException("订单不存在");
        }
 
        HashMap<Long, Double> stockMap = new HashMap<>();
        List<WaveSeed> waveSeeds = waveSeedService.list(new LambdaQueryWrapper<WaveSeed>().eq(WaveSeed::getOrderId, orderId));
        for (WaveSeed waveSeed : waveSeeds) {
            Double anfme = stockMap.get(waveSeed.getOrderDetlId());
            if (anfme == null) {
                anfme = 0.0D;
            }
            anfme += waveSeed.getWorkQty();
            stockMap.put(waveSeed.getOrderDetlId(), anfme);
        }
 
        List<OrderDetl> orderDetls = orderDetlService.getOrderDetlByOrderId(orderId);
        boolean check = true;
        for (OrderDetl orderDetl : orderDetls) {
            Double anfme = Optional.of(orderDetl.getAnfme() - orderDetl.getQty()).orElse(0.0D);
            Double workQty = stockMap.get(orderDetl.getId());
            if (!anfme.equals(workQty)) {
                check = false;
                break;
            }
        }
 
        return check;
    }
 
    @Override
    public void seedComplete(SeedCompleteParam param) {
        if (param == null) {
            throw new CoolException("参数不能为空");
        }
 
        String siteNo = param.getSiteNo();
        if (siteNo == null) {
            throw new CoolException("播种站点编号不能为空");
        }
 
        CacheSite cacheSite = this.getOne(new LambdaQueryWrapper<CacheSite>().eq(CacheSite::getSiteNo, siteNo));
        if(cacheSite == null){
            throw new CoolException("播种站点不存在");
        }
 
        if (cacheSite.getSiteStatus().equals(CacheSiteStatusType.O.id)) {
            throw new CoolException("站点状态异常");
        }
 
        if (cacheSite.getPlatformId() == null) {
            throw new CoolException("集货区域未绑定");
        }
 
        Long orderId = cacheSite.getOrderId();
        Order order = orderService.getById(orderId);
        if (order == null) {
            throw new CoolException("订单不存在");
        }
        Long waveId = order.getWaveId();
 
        boolean check = this.seedCompletePreview(param);
        if (!check) {//订单未处理完成
            List<Long> taskIds = new ArrayList<>();
            List<TaskDetl> taskDetls = taskDetlService.list(new LambdaQueryWrapper<TaskDetl>().eq(TaskDetl::getWaveId, waveId));
            for (TaskDetl taskDetl : taskDetls) {
                if(!taskIds.contains(taskDetl.getTaskId())){
                    taskIds.add(taskDetl.getTaskId());
                }
            }
 
            if (!taskIds.isEmpty()) {
                List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>().in(Task::getId, taskIds).notIn(Task::getTaskSts, TaskStsType.COMPLETE_OUT.id, TaskStsType.UPDATED_OUT.id));
                if (!tasks.isEmpty()) {
                    throw new CoolException("存在未完成任务");
                }
            }
        }
 
        Platform platform = platformService.getById(cacheSite.getPlatformId());
        if(platform == null){
            throw new CoolException("集货区域不存在");
        }
 
        List<WaveSeed> waveSeeds = waveSeedService.list(new LambdaQueryWrapper<WaveSeed>().eq(WaveSeed::getOrderId, orderId));
        if (waveSeeds.isEmpty()) {
            throw new CoolException("播种数据不存在");
        }
 
        for (WaveSeed waveSeed : waveSeeds) {
            PlatformDetl platformDetl = new PlatformDetl();
            platformDetl.setPlatformId(platform.getId());
            platformDetl.setPlatformNo(platform.getPlatformNo());
            platformDetl.setOrderId(orderId);
            platformDetl.setOrderDetlId(waveSeed.getOrderDetlId());
            platformDetl.setTaskDetlId(waveSeed.getTaskDetlId());
            platformDetl.setMatnr(waveSeed.getMatnr());
            platformDetl.setBatch(waveSeed.getBatch());
            platformDetl.setFieldParams(waveSeed.getFieldParams());
            platformDetl.setAnfme(waveSeed.getAnfme());
            platformDetl.setQty(waveSeed.getWorkQty());
 
            if (!platformDetlService.save(platformDetl)) {
                throw new CoolException("集货区域库存插入失败");
            }
 
 
            WaveSeedLog waveSeedLog = new WaveSeedLog();
            waveSeedLog.sync(waveSeed);
            waveSeedLog.setId(null);
            if (!waveSeedLogService.save(waveSeedLog)) {
                throw new CoolException("播种数据转历史失败");
            }
 
            if (!waveSeedService.removeById(waveSeed.getId())) {
                throw new CoolException("播种数据删除失败");
            }
        }
 
        cacheSite.setSiteStatus(CacheSiteStatusType.O.id);
        cacheSite.setOrderId(null);
        cacheSite.setOrderNo(null);
        cacheSite.setPlatformId(null);
        cacheSite.setPlatformNo(null);
        cacheSite.setUpdateTime(new Date());
        if (!this.updateById(cacheSite)) {
            throw new CoolException("更新播种站点数据失败");
        }
 
    }
}