自动化立体仓库 - WMS系统
zc
2024-07-27 cef8161169e99e299eefb7c67eeb4cb6e41d99f2
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
package com.zy.third.erp.task;
 
import com.core.common.Cools;
import com.core.common.DateUtils;
import com.core.common.SnowflakeIdWorker;
import com.core.exception.CoolException;
import com.zy.asrs.entity.DocType;
import com.zy.asrs.entity.Mat;
import com.zy.asrs.entity.Order;
import com.zy.asrs.entity.OrderDetl;
import com.zy.asrs.service.DocTypeService;
import com.zy.asrs.service.MatService;
import com.zy.asrs.service.OrderDetlService;
import com.zy.asrs.service.OrderService;
import com.zy.third.erp.entity.InDetTB;
import com.zy.third.erp.entity.InHedTB;
import com.zy.third.erp.entity.OutDetTB;
import com.zy.third.erp.entity.OutHedTB;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.Date;
import java.util.List;
 
@Slf4j
@Component
public class ERPInOrOutService {
 
 
    @Autowired
    private OrderService orderService;
 
    @Autowired
    private OrderDetlService orderDetlService;
 
 
    @Autowired
    private SnowflakeIdWorker snowflakeIdWorker;
 
 
    @Autowired
    private DocTypeService docTypeService;
 
 
    @Autowired
    private MatService matService;
 
 
    /**
     * @return
     */
    @Transactional(rollbackFor = Throwable.class)
    public boolean createInOrder(InHedTB inHedTB, List<InDetTB> inDetTBs) {
        Order order = orderService.selectByNo(inHedTB.getBillNo());
        // 如果单据不存在则添加;如果单据存在,作业中无法修改,反之则修改单据
        if (!Cools.isEmpty(order)) {
            if (order.getSettle() > 1L) {
                throw new CoolException(inHedTB.getBillNo() + "正在出库,无法修改单据");
            }
            orderService.remove(order.getId());
        }
        DocType docType = docTypeService.selectOrAdd(inHedTB.getIoKindName(), inHedTB.getIoKindID(), Boolean.TRUE);
        Date now = new Date();
        // 单据主档
        order = new Order(
                String.valueOf(snowflakeIdWorker.nextId()),    // 编号[非空]
                inHedTB.getBillNo(),    // 订单编号
                DateUtils.convert(inHedTB.getBillDate()),    // 单据日期
                docType.getDocId(),    // 单据类型
                null,    // 项目编号
                null,    //
                null,    // 调拨项目编号
                null,    // 初始票据号
                null,    // 票据号
                inHedTB.getObjectId(),    // 客户编号
                inHedTB.getObjectName(),    // 客户
                null,    // 联系方式
                null,    // 操作人员
                null,    // 合计金额
                null,    // 优惠率
                null,    // 优惠金额
                null,    // 销售或采购费用合计
                null,    // 实付金额
                null,    // 付款类型
                null,    // 业务员
                null,    // 结算天数
                null,    // 邮费支付类型
                null,    // 邮费
                null,    // 付款时间
                null,    // 发货时间
                null,    // 物流名称
                null,    // 物流单号
                1L,    // 订单状态
                1,    // 状态
                9527L,    // 添加人员
                now,    // 添加时间
                9527L,    // 修改人员
                inHedTB.getMakeDate(),    // 修改时间
                inHedTB.getRemark()    // 备注
        );
        order.setTemp1(inHedTB.getTemp1());
        order.setTemp2(inHedTB.getTemp2());
        order.setTemp3(inHedTB.getTemp3());
        order.setWareId(inHedTB.getWareId());
        order.setWareName(inHedTB.getWareName());
        if (!orderService.insert(order)) {
            throw new CoolException("生成单据主档失败,请联系管理员");
        }
        for (InDetTB outDetTB : inDetTBs) {
            Mat mat = matService.selectByMatnr(outDetTB.getItemId());
            if (Cools.isEmpty(mat)) {
                throw new CoolException(outDetTB.getItemCode() + "编号商品检索失败,请先添加商品");
            }
            OrderDetl orderDetl = new OrderDetl();
            orderDetl.sync(mat);
            orderDetl.setOrderNo(outDetTB.getBillNo());
            orderDetl.setOutOrderNo(outDetTB.getOrderNo());
            orderDetl.setAutoId(outDetTB.getAutoId());
            orderDetl.setLuHao(outDetTB.getLuHao());
            orderDetl.setSpecs(outDetTB.getSPgNO());
            orderDetl.setPacking(outDetTB.getPacking());
            orderDetl.setWareId(outDetTB.getWareId());
            orderDetl.setWareName(outDetTB.getWareName());
            orderDetl.setBatch(outDetTB.getItemBatch());
            orderDetl.setAnfme(outDetTB.getMainNum());
            orderDetl.setINO(outDetTB.getINO());
            orderDetl.setOrderId(order.getId());
            orderDetl.setTemp1(outDetTB.getTemp1());
            orderDetl.setTemp2(outDetTB.getTemp2());
            orderDetl.setTemp3(outDetTB.getTemp3());
            orderDetl.setOrderNo(order.getOrderNo());
            orderDetl.setThreeCode(outDetTB.getDetId() + "");
            orderDetl.setCreateBy(9527L);
            orderDetl.setCreateTime(now);
            orderDetl.setUpdateBy(9527L);
            orderDetl.setUpdateTime(now);
            orderDetl.setStatus(1);
            orderDetl.setQty(0.0D);
            if (!orderDetlService.insert(orderDetl)) {
                throw new CoolException("生成单据明细失败,请联系管理员");
            }
        }
        return true;
    }
 
 
    /**
     * @return
     */
    @Transactional(rollbackFor = Throwable.class)
    public boolean createOutOrder(OutHedTB inHedTB, List<OutDetTB> inDetTBs) {
        Order order = orderService.selectByNo(inHedTB.getBillNo());
        // 如果单据不存在则添加;如果单据存在,作业中无法修改,反之则修改单据
        if (!Cools.isEmpty(order)) {
            if (order.getSettle() > 1L) {
                throw new CoolException(inHedTB.getBillNo() + "正在出库,无法修改单据");
            }
            orderService.remove(order.getId());
        }
        DocType docType = docTypeService.selectOrAdd(inHedTB.getIoKindName(),inHedTB.getIoKindID(), Boolean.FALSE);
        Date now = new Date();
        // 单据主档
        order = new Order(
                String.valueOf(snowflakeIdWorker.nextId()),    // 编号[非空]
                inHedTB.getBillNo(),    // 订单编号
                DateUtils.convert(inHedTB.getBillDate()),    // 单据日期
                docType.getDocId(),    // 单据类型
                null,    // 项目编号
                null,    //
                null,    // 调拨项目编号
                null,    // 初始票据号
                null,    // 票据号
                inHedTB.getObjectId(),    // 客户编号
                inHedTB.getObjectName(),    // 客户
                null,    // 联系方式
                null,    // 操作人员
                null,    // 合计金额
                null,    // 优惠率
                null,    // 优惠金额
                null,    // 销售或采购费用合计
                null,    // 实付金额
                null,    // 付款类型
                null,    // 业务员
                null,    // 结算天数
                null,    // 邮费支付类型
                null,    // 邮费
                null,    // 付款时间
                null,    // 发货时间
                null,    // 物流名称
                null,    // 物流单号
                1L,    // 订单状态
                1,    // 状态
                9527L,    // 添加人员
                now,    // 添加时间
                9527L,    // 修改人员
                inHedTB.getMakeDate(),    // 修改时间
                inHedTB.getRemark()    // 备注
        );
        order.setTemp1(inHedTB.getTemp1());
        order.setTemp2(inHedTB.getTemp2());
        order.setTemp3(inHedTB.getTemp3());
        order.setWareId(inHedTB.getWareId());
        order.setWareName(inHedTB.getWareName());
 
        if (!orderService.insert(order)) {
            throw new CoolException("生成单据主档失败,请联系管理员");
        }
        for (OutDetTB outDetTB : inDetTBs) {
            Mat mat = matService.selectByMatnr(outDetTB.getItemId());
            if (Cools.isEmpty(mat)) {
                throw new CoolException(outDetTB.getItemCode() + "编号商品检索失败,请先添加商品");
            }
            OrderDetl orderDetl = new OrderDetl();
            orderDetl.sync(mat);
            orderDetl.setOrderNo(outDetTB.getBillNo());
            orderDetl.setOutOrderNo(outDetTB.getOrderNo());
            orderDetl.setAutoId(outDetTB.getAutoId());
            orderDetl.setLuHao(outDetTB.getLuHao());
            orderDetl.setSpecs(outDetTB.getSPgNO());
            orderDetl.setPacking(outDetTB.getPacking());
            orderDetl.setWareId(outDetTB.getWareId());
            orderDetl.setWareName(outDetTB.getWareName());
            orderDetl.setBatch(outDetTB.getItemBatch());
            orderDetl.setAnfme(outDetTB.getMainNum());
            orderDetl.setINO(outDetTB.getINO());
            orderDetl.setOrderId(order.getId());
            orderDetl.setTemp1(outDetTB.getTemp1());
            orderDetl.setTemp2(outDetTB.getTemp2());
            orderDetl.setTemp3(outDetTB.getTemp3());
            orderDetl.setOrderNo(order.getOrderNo());
            orderDetl.setThreeCode(outDetTB.getDetId() + "");
            orderDetl.setCreateBy(9527L);
            orderDetl.setCreateTime(now);
            orderDetl.setUpdateBy(9527L);
            orderDetl.setUpdateTime(now);
            orderDetl.setStatus(1);
            orderDetl.setQty(0.0D);
            if (!orderDetlService.insert(orderDetl)) {
                throw new CoolException("生成单据明细失败,请联系管理员");
            }
        }
        return true;
    }
}