skyouc
2025-01-07 83b504d7a369baa08b15c741c3b6daf71f6fa1f9
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
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.*;
import com.zy.asrs.wms.asrs.entity.enums.OrderType;
import com.zy.asrs.wms.asrs.entity.param.BatchMergeOrdersParam;
import com.zy.asrs.wms.asrs.entity.param.GeneratePakInParam;
import com.zy.asrs.wms.asrs.entity.param.PakinOnShelvesParams;
import com.zy.asrs.wms.asrs.service.*;
import com.zy.asrs.wms.system.entity.Host;
import com.zy.asrs.wms.system.service.HostService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
 
@Service
public class MobileServiceImpl implements MobileService {
 
    @Autowired
    private WaitPakinService waitPakinService;
    @Autowired
    private WaitPakinLogService waitPakinLogService;
    @Autowired
    private WorkService workService;
    @Autowired
    private HostService hostService;
    @Autowired
    private OrderService orderService;
    @Autowired
    private OrderLogService orderLogService;
    @Autowired
    private LocService locService;
    @Autowired
    private LocDetlService locDetlService;
    @Autowired
    private LocAreaService locAreaService;
    @Autowired
    private LocAreaTypeService locAreaTypeService;
 
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean batchMergeOrders(BatchMergeOrdersParam ordersParam) {
        Order order = orderService.getOne(new LambdaQueryWrapper<Order>().eq(Order::getOrderNo, ordersParam.getOrderNo()));
        if (Objects.isNull(order)) {
            throw new CoolException("订单不存在!!");
        }
 
        ArrayList<WaitPakin> waitPakins = new ArrayList<>();
        ordersParam.getOrderDetls().forEach(orderdetl -> {
            WaitPakin waitPakin = new WaitPakin();
            waitPakin.setBatch(orderdetl.getBatch())
                    .setAnfme(orderdetl.getMergeNum())
                    .setBarcode(ordersParam.getMergeNo())
                    .setMatnr(orderdetl.getMatnr())
                    .setDetlId(orderdetl.getDetlId())
                    .setIoStatus(0)
                    .setOrderNo(orderdetl.getOrderNo()).setOrderId(orderdetl.getOrderId()).setStatus(1);
            waitPakins.add(waitPakin);
        });
 
        //组拖通知档
        waitPakins.forEach(pakin -> {
            waitPakinService.comb(pakin);
        });
 
        // UTC入库单据(非平库入库单据)
        if (order.getOrderType() != OrderType.PK_IN_ORDER.id) {
            /*** 项目下发流程 * 1. PDA组拖通知档* 2. 生成任务档* 3. 通过定时任务下发至ESS** */
            //生成任务档
            GeneratePakInParam generatePakInParam = new GeneratePakInParam();
            //当前没有起始站点,默认101, 高低位默认传低库位
            generatePakInParam.setBarcode(ordersParam.getMergeNo())
                    .setOriginSite("101")
                    .setTaskType(TaskStsType.GENERATE_IN.id).setLocTypeHeight(LocTypeHeightType.LOW.id);
            if (workService.generatePakIn(generatePakInParam)) {
                return true;
            }
        } else {
            //fixme 平库是否需要预约入库
        }
        return false;
    }
 
    @Override
    public List<Host> getHosts() {
        return hostService.list();
    }
 
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean pakinToStock(PakinOnShelvesParams shelvesParams) {
        Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, shelvesParams.getLoc()));
        if (Objects.isNull(loc)) {
            throw new CoolException("库位不存在!!");
        }
        if (loc.getLocStsId() != LocStsType.O.val()) {
            throw new CoolException("当前库位状态不是空库状态." + LocStsType.O.val());
        }
 
        //判断当前仓库是否为平库位
        List<LocArea> locAreas = locAreaService.list(new LambdaQueryWrapper<LocArea>().eq(LocArea::getLocId, loc.getId()));
        if (locAreas.isEmpty()) {
            throw new CoolException("库位没有分配所属仓库区域!!");
        }
        locAreas.forEach(locArea -> {
            LocAreaType typeServiceOne = locAreaTypeService.getOne(new LambdaQueryWrapper<LocAreaType>().eq(LocAreaType::getId, locArea.getTypeId()), false);
            if (typeServiceOne.getParentId() != LocAreaTypeSts.LOC_AREA_TYPE_FLAT.id && typeServiceOne.getId() != LocAreaTypeSts.LOC_AREA_TYPE_FLAT.id) {
                throw new CoolException("请选择平库区库位,再操作!!");
            }
        });
 
        loc.setBarcode(shelvesParams.getBarcode());
        loc.setUpdateTime(new Date());
        //库存状态修改为在库状态
        loc.setLocStsId(LocStsType.F.val());
        if (!locService.updateById(loc)) {
            throw new CoolException("库位更新失败!!");
        }
 
        List<WaitPakin> waitPakins = waitPakinService.list(new LambdaQueryWrapper<WaitPakin>().eq(WaitPakin::getBarcode, shelvesParams.getBarcode()));
        waitPakins.forEach(pakin -> {
            LocDetl locDetl = new LocDetl();
            locDetl.setAnfme(pakin.getAnfme());
            locDetl.setBatch(pakin.getBatch());
            locDetl.setMatId(pakin.getMatnrId$());;
            locDetl.setCreateTime(new Date());
            locDetl.setOrderNo(pakin.getOrderNo());
            locDetl.setLocNo(loc.getLocNo());
            locDetl.setLocId(loc.getId());
            locDetl.setMatnr(pakin.getMatnr());
            locDetl.setMemo(pakin.getMemo());
            locDetl.setUpdateTime(new Date());
            if (!locDetlService.saveOrUpdate(locDetl)) {
                throw new CoolException("库存明细更新失败!!");
            }
            //修改状态为入库中
            pakin.setIoStatus(1);
        });
 
        //删除组拖档,加入历史组拖档
        waitPakins.forEach(waitPakin -> {
            WaitPakinLog pakinLog = new WaitPakinLog();
            BeanUtils.copyProperties(waitPakin, pakinLog);
            if (!waitPakinLogService.saveOrUpdate(pakinLog)) {
                throw new CoolException("组拖历史档更新失败");
            }
        });
 
        if (!waitPakinService.removeBatchByIds(waitPakins)) {
            throw new CoolException("组拖档删除失败!!");
        }
        //通过组拖订单ID获取订单,并删除原单据,加入单据历史档
        List<Long> list = waitPakins.stream().map(WaitPakin::getOrderId).collect(Collectors.toList());
        List<Order> orders = orderService.list(new LambdaQueryWrapper<Order>().in(Order::getId, list));
        orders.forEach(order -> {
            OrderLog orderLog = new OrderLog();
            BeanUtils.copyProperties(order, orderLog);
            if (!orderLogService.save(orderLog)) {
                throw new CoolException("历史单据更新失败!!");
            }
        });
 
        if (!orderService.removeBatchByIds(orders)) {
            throw new CoolException("订单删除失败!!");
        }
 
        return true;
    }
 
//    /**
//     * 获取当前库位是否存在
//     * @param shelvesParams
//     * @return
//     */
//    @Override
//    public Loc selectPakinLocs(PakinOnShelvesParams shelvesParams) {
//        return locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, shelvesParams.getLoc()));
//    }
 
 
}