自动化立体仓库 - WMS系统
#
luxiaotao1123
2022-04-09 65ad59fc53b0fee72bb06da3b89bcc4867848ee8
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
package com.zy.asrs.controller;
 
import com.core.common.*;
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.entity.param.OpenOrderPakinParam;
import com.zy.asrs.service.*;
import com.zy.common.model.DetlDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
/**
 * Created by vincent on 2022/4/8
 */
@RestController
@RequestMapping("open/asrs")
public class OpenController {
 
    @Autowired
    private OrderService orderService;
    @Autowired
    private OrderDetlService orderDetlService;
    @Autowired
    private SnowflakeIdWorker snowflakeIdWorker;
    @Autowired
    private DocTypeService docTypeService;
    @Autowired
    private MatService matService;
    @Autowired
    private LocDetlService locDetlService;
 
    /**
     * 添加入库单
     */
    @PostMapping("/order/pakin/default/v1")
    @Transactional
    public synchronized R orderCreate(@RequestBody OpenOrderPakinParam param) {
        if (Cools.isEmpty(param)) {
            return R.parse(BaseRes.PARAM);
        }
        if (Cools.isEmpty(param.getOrderNo())) {
            return R.error("单据编号[orderNo]不能为空");
        }
        if (Cools.isEmpty(param.getOrderType())) {
            return R.error("单据类型[orderType]不能为空");
        }
        if (Cools.isEmpty(param.getOrderDetails())) {
            return R.error("单据明细[orderDetails]不能为空");
        }
        Order order = orderService.selectByNo(param.getOrderNo());
        if (!Cools.isEmpty(order)) {
            return R.error(param.getOrderNo() + "单据已存在,请勿重复提交");
        }
        DocType docType = docTypeService.selectOrAdd(param.getOrderType());
        Date now = new Date();
        // 单据主档
        order = new Order(
                String.valueOf(snowflakeIdWorker.nextId()),    // 编号[非空]
                param.getOrderNo(),    // 订单编号
                DateUtils.convert(now),    // 单据日期
                docType.getDocId(),    // 单据类型
                null,    // 项目编号
                null,    //
                null,    // 调拨项目编号
                null,    // 初始票据号
                null,    // 票据号
                null,    // 客户编号
                null,    // 客户
                null,    // 联系方式
                null,    // 操作人员
                null,    // 合计金额
                null,    // 优惠率
                null,    // 优惠金额
                null,    // 销售或采购费用合计
                null,    // 实付金额
                null,    // 付款类型
                null,    // 业务员
                null,    // 结算天数
                null,    // 邮费支付类型
                null,    // 邮费
                null,    // 付款时间
                null,    // 发货时间
                null,    // 物流名称
                null,    // 物流单号
                1L,    // 订单状态
                1,    // 状态
                9527L,    // 添加人员
                now,    // 添加时间
                9527L,    // 修改人员
                now,    // 修改时间
                null    // 备注
        );
        if (!orderService.insert(order)) {
            throw new CoolException("生成单据主档失败,请联系管理员");
        }
        // 单据明细档
        List<DetlDto> list = new ArrayList<>();
        List<DetlDto> orderDetails = param.getOrderDetails();
        for (DetlDto detail : orderDetails) {
            DetlDto dto = new DetlDto(detail.getMatnr(), detail.getBatch(), detail.getAnfme());
            if (DetlDto.has(list, dto)) {
                DetlDto detlDto = DetlDto.find(list, dto.getMatnr(), dto.getBatch());
                assert detlDto != null;
                detlDto.setAnfme(detlDto.getAnfme() + detail.getAnfme());
            } else {
                list.add(dto);
            }
        }
        for (DetlDto detlDto : list) {
            Mat mat = matService.selectByMatnr(detlDto.getMatnr());
            if (Cools.isEmpty(mat)) {
                throw new CoolException(detlDto.getMatnr() + "编号商品检索失败,请先添加商品");
            }
            OrderDetl orderDetl = new OrderDetl();
            orderDetl.sync(mat);
            orderDetl.setOrderId(order.getId());
            orderDetl.setOrderNo(order.getOrderNo());
            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 R.ok();
    }
 
 
    /**
     * 库存统计
     */
    @RequestMapping("/stock/default/v1")
    public R queryStock() {
        return R.ok(locDetlService.queryStockTotal());
    }
 
}