自动化立体仓库 - WMS系统
#
luxiaotao1123
2022-04-08 032a882c857145fca3b1cd80f61b339663b897c3
#
4个文件已修改
145 ■■■■ 已修改文件
src/main/java/com/zy/asrs/controller/OpenController.java 100 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/entity/param/OpenOrderPakinParam.java 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/service/DocTypeService.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/service/impl/DocTypeServiceImpl.java 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/controller/OpenController.java
@@ -1,17 +1,27 @@
package com.zy.asrs.controller;
import com.core.common.BaseRes;
import com.core.common.Cools;
import com.core.common.R;
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.DocTypeService;
import com.zy.asrs.service.MatService;
import com.zy.asrs.service.OrderDetlService;
import com.zy.asrs.service.OrderService;
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
@@ -24,11 +34,18 @@
    private OrderService orderService;
    @Autowired
    private OrderDetlService orderDetlService;
    @Autowired
    private SnowflakeIdWorker snowflakeIdWorker;
    @Autowired
    private DocTypeService docTypeService;
    @Autowired
    private MatService matService;
    /**
     * 添加入库单
     */
    @PostMapping("order/pakin/default/v1")
    @Transactional
    public synchronized R orderCreate(@RequestBody OpenOrderPakinParam param) {
        if (Cools.isEmpty(param)) {
            return R.parse(BaseRes.PARAM);
@@ -37,7 +54,7 @@
            return R.error("单据编号[orderNo]不能为空");
        }
        if (Cools.isEmpty(param.getOrderType())) {
            return R.error("单据类型[orderType]错误");
            return R.error("单据类型[orderType]不能为空");
        }
        if (Cools.isEmpty(param.getOrderDetails())) {
            return R.error("单据明细[orderDetails]不能为空");
@@ -46,7 +63,80 @@
        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();
    }
src/main/java/com/zy/asrs/entity/param/OpenOrderPakinParam.java
@@ -1,5 +1,6 @@
package com.zy.asrs.entity.param;
import com.zy.common.model.DetlDto;
import lombok.Data;
import java.util.List;
@@ -14,17 +15,8 @@
    private String orderType;
    private List<Detl> orderDetails;
    private String orderTime;
    @Data
    public static class Detl {
        private String matnr;
        private String batch;
        private Double anfme;
    }
    private List<DetlDto> orderDetails;
}
src/main/java/com/zy/asrs/service/DocTypeService.java
@@ -5,4 +5,6 @@
public interface DocTypeService extends IService<DocType> {
    DocType selectOrAdd(String docName);
}
src/main/java/com/zy/asrs/service/impl/DocTypeServiceImpl.java
@@ -1,12 +1,41 @@
package com.zy.asrs.service.impl;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.Cools;
import com.core.exception.CoolException;
import com.zy.asrs.mapper.DocTypeMapper;
import com.zy.asrs.entity.DocType;
import com.zy.asrs.service.DocTypeService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import java.util.Date;
@Service("docTypeService")
public class DocTypeServiceImpl extends ServiceImpl<DocTypeMapper, DocType> implements DocTypeService {
    @Override
    public DocType selectOrAdd(String docName) {
        if (Cools.isEmpty(docName)) {
            return null;
        }
        DocType docType = this.selectOne(new EntityWrapper<DocType>().eq("doc_name", docName));
        if (docType == null) {
            long docId = 1L;
            DocType last = this.selectOne(new EntityWrapper<DocType>().orderBy("doc_id", false));
            if (last != null) {
                docId = last.getDocId() + 1;
            }
            docType = new DocType();
            docType.setDocId(docId);
            docType.setDocName(docName);
            docType.setStatus(1);
            docType.setCreateTime(new Date());
            docType.setUpdateTime(new Date());
            if (!this.insert(docType)) {
                throw new CoolException("单据类型错误");
            }
        }
        return docType;
    }
}