自动化立体仓库 - WMS系统
zwl
2025-10-22 a9f7a73efb4fc132ad2c9a353d300b708430e961
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
package com.zy.asrs.task.handler;
 
import com.core.common.Cools;
import com.core.common.DateUtils;
import com.core.exception.CoolException;
import com.zy.asrs.entity.DocType;
import com.zy.asrs.entity.Order;
import com.zy.asrs.entity.OrderDetl;
import com.zy.asrs.service.ApiLogService;
import com.zy.asrs.service.DocTypeService;
import com.zy.asrs.service.OrderDetlService;
import com.zy.asrs.service.OrderService;
import com.zy.asrs.task.AbstractHandler;
import com.zy.asrs.task.core.ReturnT;
import com.zy.third.entity.ExdInstockTarget;
import com.zy.third.entity.ExdOutstockTarget;
import com.zy.third.service.ExdInstockTargetService;
import com.zy.third.service.ExdOutstockTargetService;
import lombok.extern.slf4j.Slf4j;
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;
 
/**
 * Created by vincent on 2020/7/7
 */
@Slf4j
@Service
public class OrderSyncHandler extends AbstractHandler<String> {
 
 
    @Autowired
    private OrderService orderService;
    @Autowired
    private OrderDetlService orderDetlService;
    @Autowired
    private ApiLogService apiLogService;
    @Autowired
    private DocTypeService docTypeService;
 
    @Autowired
    private ExdInstockTargetService exdInstockTargetService;
 
    @Autowired
    private ExdOutstockTargetService exdOutstockTargetService;
 
    @Transactional
    public ReturnT<String> start(Order order) {
        DocType docType = docTypeService.selectById(order.getDocType());
        if (null == docType) {
            return SUCCESS;
        }
        List<OrderDetl> orderDetls = orderDetlService.selectByOrderId(order.getId());
        if (orderDetls.isEmpty()) {
            return SUCCESS;
        }
        // 入库完成上报
        if (docType.getPakin() == 1) {
            ExdInstockTarget exdInstockTarge = null;
            for (OrderDetl orderDetl : orderDetls) {
                exdInstockTarge = new ExdInstockTarget();
                exdInstockTarge.setFinterid(orderDetl.getDeadWarn());
                exdInstockTarge.setFbillno(orderDetl.getOrderNo());
                exdInstockTarge.setFtrantype(order.getDocType().intValue());
                exdInstockTarge.setFdate(DateUtils.convert(order.getOrderTime()));
                exdInstockTarge.setFrob(orderDetl.getInspect());
                exdInstockTarge.setFuserid(Integer.getInteger(orderDetl.getColor()));
                exdInstockTarge.setWritetime(new Date());
                exdInstockTarge.setWritor("WMS");
                exdInstockTarge.setStatus(0);
                exdInstockTargetService.insert(exdInstockTarge);
            }
            if (!orderService.updateSettle(order.getId(), 6L, null)) {
                throw new CoolException("服务器内部错误,请联系管理员");
            }
        } else if (docType.getPakout() == 1) {
            // 出库完成上报
            ExdOutstockTarget exdOutstockTarget = null;
            for (OrderDetl orderDetl : orderDetls) {
                exdOutstockTarget = new ExdOutstockTarget();
                exdOutstockTarget.setFinterid(orderDetl.getDeadWarn());
                exdOutstockTarget.setFbillno(orderDetl.getOrderNo());
                if (order.getDocType() == 42) {
                    exdOutstockTarget.setFtrantype(41);
                } else {
                    exdOutstockTarget.setFtrantype(order.getDocType().intValue());
                }
                exdOutstockTarget.setFdate(DateUtils.convert(order.getOrderTime()));
                exdOutstockTarget.setFrob(orderDetl.getInspect());
                exdOutstockTarget.setFuserid(Integer.getInteger(orderDetl.getColor()));
                exdOutstockTarget.setWritetime(new Date());
                exdOutstockTarget.setWritor("WMS");
                exdOutstockTarget.setStatus(0);
                exdOutstockTargetService.insert(exdOutstockTarget);
 
            }
            if (!orderService.updateSettle(order.getId(), 6L, null)) {
                throw new CoolException("服务器内部错误,请联系管理员");
            }
        }
        return SUCCESS;
    }
 
    @Transactional
    public ReturnT<String> start1(Order order, OrderDetl orderDetl) {
        DocType docType = docTypeService.selectById(order.getDocType());
        if (null == docType) {
            return SUCCESS;
        }
        List<OrderDetl> orderDetls = orderDetlService.selectByOrderId(order.getId());
        if (orderDetls.isEmpty()) {
            return SUCCESS;
        }
 
        double count = orderDetl.getQty() - (Cools.isEmpty(orderDetl.getUnits()) ? 0.0 : orderDetl.getUnits());
        if (docType.getPakout() == 1) {
            // 出库完成上报
            ExdOutstockTarget exdOutstockTarget = null;
            exdOutstockTarget = new ExdOutstockTarget();
            //订单内码
            exdOutstockTarget.setFinterid(orderDetl.getDeadWarn());
            //单号 = erp订单号+物料编号+上报次数
            exdOutstockTarget.setFbillno(orderDetl.getOrderNo() + "--" + orderDetl.getMatnr() + "--" + orderDetl.getInspect());
 
            //部门ID
            exdOutstockTarget.setFdeptid(0);
            //供应商/客户ID
            exdOutstockTarget.setFsupplyid(0);
            //制单用户ID
            exdOutstockTarget.setFbillerid(0);
            //细表ID
            exdOutstockTarget.setFentryid(0);
            //物料ID
            exdOutstockTarget.setFitemid(0);
            //源单数量
            exdOutstockTarget.setFqtymust(0.0);
            //出库数量
            //单据类型
            exdOutstockTarget.setFtrantype(21);
 
            //单据日期
            exdOutstockTarget.setFdate(DateUtils.convert(order.getOrderTime()));
            //红蓝字
            exdOutstockTarget.setFrob(orderDetl.getBeBatch());
            //操作用户
            exdOutstockTarget.setFuserid(Integer.getInteger(orderDetl.getColor()));
            //写入时间
            exdOutstockTarget.setWritetime(new Date());
            //写入者
            exdOutstockTarget.setWritor("WMS");
            //状态
            exdOutstockTarget.setStatus(0);
            if (exdOutstockTargetService.insert(exdOutstockTarget)) {
                orderDetl.setInspect((Cools.isEmpty(orderDetl.getInspect()) ? 1 : (orderDetl.getInspect() + 1)));
                orderDetl.setUnits(count + (Cools.isEmpty(orderDetl.getUnits()) ? 0.0 : orderDetl.getUnits()));
                orderDetlService.updateById(orderDetl);
            }
        }
        return SUCCESS;
    }
 
}