自动化立体仓库 - WMS系统
skyouc
昨天 30bb734c3c5de070ab9513128980bfdbe1880857
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
package com.zy.api.service.impl;
 
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.DateUtils;
import com.core.common.R;
import com.core.exception.CoolException;
import com.zy.api.entity.OrderParams;
import com.zy.api.enums.OrderType;
import com.zy.api.enums.OrderWkType;
import com.zy.api.service.KopenApiService;
import com.zy.asrs.entity.Mat;
import com.zy.asrs.entity.Order;
import com.zy.asrs.entity.OrderDetl;
import com.zy.asrs.enums.CommonEnum;
import com.zy.asrs.enums.OrderSettle;
import com.zy.asrs.service.OrderDetlService;
import com.zy.asrs.service.OrderService;
 
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.Date;
import java.util.List;
import java.util.Objects;
 
@Service("kopenApiServiceImpl")
public class KopenApiServiceImpl implements KopenApiService {
 
    @Autowired
    private OrderService orderService;
    @Autowired
    private OrderDetlService orderDetlService;
 
    /**
     * 接收下发订单信息
     *
     * @author Ryan
     * @date 2025/11/24 14:49
     * @param params
     * @return com.core.common.R
     */
    @Override
    public R receiveOrders(OrderParams params) {
        if (params.getType().equals(OrderWkType.getTypeVal(params.getType()))) {
            return R.error("当前类型不是上架派工单!!");
        }
        addOrUpdateOrders(params, "add");
        return R.ok("单据下发成功!!");
    }
 
    /**
     * 基础零件变更
     *
     * @author Ryan
     * @date 2025/11/24 15:05
     * @param matnrs
     * @return com.core.common.R
     */
    @Override
    public R basMatupdate(List<Mat> matnrs) {
        return null;
    }
 
    /**
     * 新增或修改订单信息
     *
     * @author Ryan
     * @date 2025/11/24 15:32
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addOrUpdateOrders(OrderParams params, String type) {
        if (Objects.isNull(params)) {
            throw new CoolException("参数不能为空!!");
        }
        if (Objects.isNull(params.getType())) {
            throw new CoolException("订单类型不能为空!!");
        }
 
        OrderParams orderParams = JSONObject.parseObject(JSONObject.toJSONString(params), OrderParams.class);
        Order order = orderService.selectOne(new EntityWrapper<Order>().eq("order_no", orderParams.getInv_no()));
        if (type.equals("add") && !Objects.isNull(order)) {
            throw new CoolException("单据已存在, 不可重复添加!!");
        }
        // 判断订单是否存在
        if (Objects.isNull(order)) {
            /** 不存在,新增订单 */
            generateOrders(params);
        } else {
            /** 存在,删除老订单,更新插入新订单 */
            // 删除旧订单明细
            if (!orderDetlService.delete(new EntityWrapper<OrderDetl>().eq("order_id", order.getId()))) {
                throw new CoolException("订单明细删除失败!!");
            };
            if (!orderService.deleteById(order.getId())) {
                throw new CoolException("原单据删除失败!!");
            }
            generateOrders(params);
        }
    }
 
    public static String generateUUID(OrderParams params) {
        return java.util.UUID.randomUUID().toString();
    }
    
 
    /**
     * 生成订单信息
     * @param params
     */
    @Transactional(rollbackFor = Exception.class)
    public void generateOrders(OrderParams params) {
        // 将数据当新订单插入
        Order newOrder = new Order();
        if (OrderType.ORDER_IN.type.equals(OrderWkType.getTypeVal(params.getType()))) {
            // 入库
            newOrder.setPakinPakoutStatus(1);
        } else if (OrderType.ORDER_OUT.type.equals(OrderWkType.getTypeVal(params.getType()))) {
            // 出库
            newOrder.setPakinPakoutStatus(2);
        }
        newOrder.setDocType(Long.parseLong(params.getType()));
        newOrder.setOrderNo(params.getInv_no());
        newOrder.setUuid(generateUUID(params));
        // 流水号(唯一)
        newOrder.setDefNumber(params.getKopen_id());
        // 派工单号
        newOrder.setNumber(params.getDispatch_no());
        // 箱号
        newOrder.setItemName(params.getPm_tktid());
        newOrder.setSettle(OrderSettle.ORDER_SETTLE_INIT.type);
        newOrder.setStatus(CommonEnum.COMMON_ENUM_Y.type);
        // 订单时间
        newOrder.setOrderTime(DateUtils.convert(new Date(), "yyyy-MM-dd HH:mm:ss"));
        // 公司ID
        newOrder.setCstmrName(params.getCompany_id());
        newOrder.setCreateTime(new Date());
        newOrder.setUpdateTime(new Date());
        if (!orderService.insert(newOrder)) {
            throw new RuntimeException("新增订单失败!!");
        }
        if (!Objects.isNull(params.getDetails()) && !params.getDetails().isEmpty()) {
            params.getDetails().forEach(item -> {
                OrderDetl orderItem = new OrderDetl();
                BeanUtils.copyProperties(item, orderItem);
                orderItem.setOrderId(newOrder.getId());
                orderItem.setOrderNo(newOrder.getOrderNo());
                orderItem.setAnfme(Math.round(item.getInv_qty() * 10000) / 10000.0);
                orderItem.setMatnr(item.getPro_komcode());
                orderItem.setBatch(1 + "");
                orderItem.setStandby1(item.getPro_id());
                //关联上加派工单号+零件代码+供应商代码
                orderItem.setThreeCode(item.getTotal_serial());
                // 供应商代码
                orderItem.setSuppCode(item.getPro_id());
                orderItem.setCreateTime(new Date());
                orderItem.setUpdateTime(new Date());
                if (!orderDetlService.insert(orderItem)) {
                    throw new CoolException("订单明细新增失败!!");
                }
            });
        }
    }
 
}