ZY
2024-08-22 0c79b5072495ad34c3a408e4b5a9e39de4e1a741
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
package com.zy.asrs.wms.asrs.manage;
 
import com.zy.asrs.framework.exception.CoolException;
import com.zy.asrs.wms.asrs.controller.req.OutReq;
import com.zy.asrs.wms.asrs.entity.*;
import com.zy.asrs.wms.asrs.entity.param.FieldParam;
import com.zy.asrs.wms.asrs.service.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
/**
 * 出库管理
 */
@Service
public class OutManage {
 
    private static Logger logger = LoggerFactory.getLogger(LocManage.class);
 
    @Autowired
    private TaskService taskService;
 
 
    @Autowired
    private TaskDetlService taskDetlService;
 
    @Autowired
    private LocService locService;
 
 
    @Autowired
    private LocDetlService locDetlService;
 
 
    @Autowired
    private WorkService workService;
 
 
    @Autowired
    private OrderService orderService;
 
    @Autowired
    private OrderDetlService orderDetlService;
 
 
    /**
     * 获取库存
     *
     * @param map
     */
    public List<LocDetl> listSuitableMat(Map<String, Object> map) {
        List<FieldParam> param = new ArrayList<>();
        map.entrySet().stream().filter(entry -> entry.getValue() != null).forEach(entry -> {
            FieldParam fieldParam = new FieldParam();
            fieldParam.setName(entry.getKey());
            fieldParam.setValue(entry.getValue());
            param.add(fieldParam);
        });
        //TODO 这里加上出库规则
 
        List<LocDetl> stock = locDetlService.listSuitableMat(param, null);
        return stock;
    }
 
    /**
     * 根据订单id获取库存
     *
     * @param orderId 订单ID
     */
    public List<LocDetl> listSuitableMatByOrder(Long orderId) {
        Order order = orderService.getById(orderId);
        List<OrderDetl> orderDetls = orderDetlService.getOrderDetlByOrderId(orderId);
        //TODO 这里加上出库规则
        for (OrderDetl orderDetl : orderDetls) {
 
        }
        List<FieldParam> param = new ArrayList<>();
 
 
        List<LocDetl> stock = locDetlService.listSuitableMat(param, null);
        return stock;
    }
 
    /**
     * 根据订单id获取库存
     *
     * @param waveId 订单ID
     */
    public List<LocDetl> listSuitableMatByWave(Long waveId) {
 
        List<FieldParam> param = new ArrayList<>();
 
 
        List<LocDetl> stock = locDetlService.listSuitableMat(param, null);
        return stock;
    }
 
    /**
     * 出库
     *
     * @param outReq
     */
    public void out(OutReq outReq) {
        Map<Long, List<OutReq.Detl>> map = outReq.getDetls().stream().collect(Collectors.groupingBy(OutReq.Detl::getLocDetlId));
        map.forEach((k, v) -> {
            Loc loc = locService.getById(k);
            processTask(loc, v, outReq.getTargetSite());
        });
    }
 
 
    private void processTask(Loc loc, List<OutReq.Detl> detls, String targetSite) {
        // 保存工作档
        Task task = new Task();
        task.setTaskNo(workService.generateTaskNo(1L));
        // 任务状态
        task.setTaskSts(101L);
        // 任务类型
        task.setTaskType(101L);
        // 优先级
        task.setIoPri(1);
        // 源库位
        task.setOriginLoc(loc.getLocNo());
        // 目标站点
        task.setTargetSite(targetSite);
        // 托盘码
        task.setBarcode(loc.getBarcode());
        boolean res = taskService.save(task);
        if (!res) {
            throw new CoolException("保存工作档失败");
        }
        // 工作档明细保存
        for (OutReq.Detl detl : detls) {
            LocDetl locDetl = locDetlService.getById(detl.getLocDetlId());
            TaskDetl taskDetl = new TaskDetl();
            taskDetl.sync(locDetl);
            taskDetl.setTaskId(task.getId());
            if (!taskDetlService.save(taskDetl)) {
                throw new CoolException("保存工作档明细失败");
            }
        }
    }
}