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
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.OrderSettleType;
import com.zy.asrs.wms.asrs.entity.param.PlatformShippedParam;
import com.zy.asrs.wms.asrs.mapper.PlatformMapper;
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.ArrayList;
import java.util.Date;
import java.util.List;
 
@Service("platformService")
public class PlatformServiceImpl extends ServiceImpl<PlatformMapper, Platform> implements PlatformService {
 
    @Autowired
    private PlatformDetlService platformDetlService;
    @Autowired
    private PlatformDetlLogService platformDetlLogService;
    @Autowired
    private OrderService orderService;
    @Autowired
    private OrderDetlService orderDetlService;
    @Autowired
    private TaskService taskService;
    @Autowired
    private CacheSiteService cacheSiteService;
    @Autowired
    private WaveService waveService;
    @Autowired
    private WaveDetlService waveDetlService;
    @Autowired
    private WaveLogService waveLogService;
    @Autowired
    private WaveDetlLogService waveDetlLogService;
 
    @Override
    public void shipped(PlatformShippedParam param) {
        if (param == null) {
            throw new CoolException("参数不能为空");
        }
 
        if (param.getPlatformId() == null) {
            throw new CoolException("集货区域参数不能为空");
        }
 
        Platform platform = this.getById(param.getPlatformId());
        if(platform == null) {
            throw new CoolException("集货区域数据不存在");
        }
 
        List<PlatformDetl> detls = platformDetlService.list(new LambdaQueryWrapper<PlatformDetl>().eq(PlatformDetl::getPlatformId, platform.getId()));
        if (detls.isEmpty()) {
            throw new CoolException("集货区域库存为空");
        }
 
        ArrayList<Long> orderIds = new ArrayList<>();
        for (PlatformDetl detl : detls) {
            if (!orderIds.contains(detl.getOrderId())) {
                orderIds.add(detl.getOrderId());
            }
        }
 
        List<Order> orderList = orderService.listByIds(orderIds);
        if(orderList.isEmpty()) {
            throw new CoolException("订单数据不存在");
        }
 
        ArrayList<Long> waveIds = new ArrayList<>();
        for (Order order : orderList) {
            waveIds.add(order.getWaveId());
        }
 
        if (waveIds.isEmpty()) {
            throw new CoolException("波次不存在");
        }
 
        List<Task> waitTasks = taskService.selectWaitWaveOut(waveIds);
        if (!waitTasks.isEmpty()) {
            throw new CoolException("波次存在未完成任务");
        }
 
        for (PlatformDetl detl : detls) {
            OrderDetl orderDetl = orderDetlService.getById(detl.getOrderDetlId());
            orderDetl.setQty(orderDetl.getQty() + detl.getQty());
            orderDetl.setWorkQty(orderDetl.getWorkQty() - detl.getAnfme());
            orderDetl.setUpdateTime(new Date());
            if (!orderDetlService.updateById(orderDetl)) {
                throw new CoolException("订单明细更新失败");
            }
        }
 
        List<Wave> waves = waveService.listByIds(waveIds);
        for (Wave wave : waves) {
            WaveLog waveLog = new WaveLog();
            waveLog.sync(wave);
            waveLog.setId(null);
            if (!waveLogService.save(waveLog)) {
                throw new CoolException("波次转历史失败");
            }
 
            List<WaveDetl> waveDetls = waveDetlService.list(new LambdaQueryWrapper<WaveDetl>().eq(WaveDetl::getWaveId, wave.getId()));
            for (WaveDetl waveDetl : waveDetls) {
                WaveDetlLog waveDetlLog = new WaveDetlLog();
                waveDetlLog.sync(waveDetl);
                waveDetlLog.setId(null);
                waveDetlLog.setWaveId(waveLog.getId());
                if (!waveDetlLogService.save(waveDetlLog)) {
                    throw new CoolException("波次明细转历史失败");
                }
 
                if (!waveDetlService.removeById(waveDetl.getId())) {
                    throw new CoolException("波次明细删除失败");
                }
            }
 
            if (!waveService.removeById(wave.getId())) {
                throw new CoolException("波次删除失败");
            }
        }
 
        List<Order> orders = orderService.list(new LambdaQueryWrapper<Order>().in(Order::getWaveId, waveIds));
        for (Order order : orders) {
            order.setOrderSettle(OrderSettleType.COMPLETE.val());
            order.setUpdateTime(new Date());
            if (!orderService.updateById(order)) {
                throw new CoolException("订单更新失败");
            }
        }
 
        List<CacheSite> cacheSites = cacheSiteService.list(new LambdaQueryWrapper<CacheSite>().eq(CacheSite::getPlatformId, platform.getId()));
        for (CacheSite cacheSite : cacheSites) {
            if (!cacheSite.getSiteStatus().equals(CacheSiteStatusType.O.id)) {
                cacheSite.setSiteStatus(CacheSiteStatusType.O.id);
                cacheSite.setOrderId(null);
                cacheSite.setOrderNo(null);
                cacheSite.setPlatformId(null);
                cacheSite.setPlatformNo(null);
                cacheSite.setUpdateTime(new Date());
                if (!cacheSiteService.updateById(cacheSite)) {
                    throw new CoolException("播种站点更新失败");
                }
            }
        }
 
        for (PlatformDetl detl : detls) {
            PlatformDetlLog platformDetlLog = new PlatformDetlLog();
            platformDetlLog.sync(detl);
            platformDetlLog.setId(null);
            if (!platformDetlLogService.save(platformDetlLog)) {
                throw new CoolException("集货区域库存转历史失败");
            }
 
            if (!platformDetlService.removeById(detl.getId())) {
                throw new CoolException("集货区域删除失败");
            }
        }
 
    }
}