cp
2024-12-17 01ed85818b7062ba9a7f396df8122c8e1d168b64
zy-asrs-common/src/main/java/com/zy/asrs/common/openapi/service/impl/ApiServiceImpl.java
@@ -2,12 +2,11 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zy.asrs.common.domain.dto.DetlDto;
import com.zy.asrs.common.openapi.entity.param.CombParam;
import com.zy.asrs.common.openapi.entity.param.GenerateOrderPakInParam;
import com.zy.asrs.common.openapi.entity.dto.OrderListDto;
import com.zy.asrs.common.openapi.entity.param.*;
import com.zy.asrs.common.openapi.service.ApiService;
import com.zy.asrs.common.wms.entity.*;
import com.zy.asrs.common.wms.service.*;
import com.zy.asrs.framework.common.BaseRes;
import com.zy.asrs.framework.common.Cools;
import com.zy.asrs.framework.common.DateUtils;
import com.zy.asrs.framework.common.SnowflakeIdWorker;
@@ -26,15 +25,17 @@
    @Autowired
    private OrderService orderService;
    @Autowired
    private OrderDetlService orderDetlService;
    @Autowired
    private DocTypeService docTypeService;
    @Autowired
    private SnowflakeIdWorker snowflakeIdWorker;
    @Autowired
    private MatService matService;
    @Autowired
    private OrderDetlService orderDetlService;
    private OrderSettleService orderSettleService;
    @Autowired
    private WaitPakinService waitPakinService;
    private TagService tagService;
    @Override
    public void generateOrderPakIn(GenerateOrderPakInParam param) {
@@ -88,28 +89,22 @@
        if (!orderService.save(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.getOne(new LambdaQueryWrapper<Mat>().eq(Mat::getMatnr, detlDto.getMatnr()).eq(Mat::getHostId, param.getHostId()));
        List<GenerateOrderMatParam> mats = param.getMats();
        orderDetlService.remove(new LambdaQueryWrapper<OrderDetl>().eq(OrderDetl::getOrderNo, order.getOrderNo()));
        for (GenerateOrderMatParam matParam : mats) {
            Mat mat = matService.getOne(new LambdaQueryWrapper<Mat>().eq(Mat::getMatnr, matParam.getMatnr()).eq(Mat::getHostId, param.getHostId()));
            if (Cools.isEmpty(mat)) {
                throw new CoolException(detlDto.getMatnr() + "编号商品检索失败,请先添加商品");
                orderService.remove(new LambdaQueryWrapper<Order>().eq(Order::getOrderNo, order.getOrderNo()));
                throw new CoolException(matParam.getMatnr() + "编号商品检索失败,请先添加商品");
            }
            OrderDetl orderDetl = new OrderDetl();
            orderDetl.sync(mat);
            orderDetl.setBatch(detlDto.getBatch());
            orderDetl.setAnfme(detlDto.getAnfme());
            orderDetl.setBatch(matParam.getBatch());
            orderDetl.setAnfme(matParam.getAnfme());
            orderDetl.setUnit(matParam.getUnit());
            orderDetl.setThreeCode(matParam.getWarehouse());//仓库号
            orderDetl.setSupp(matParam.getOrigin());//来源单号
            orderDetl.setSuppCode(matParam.getOriginNo());//来源序号
            orderDetl.setOrderId(order.getId());
            orderDetl.setOrderNo(order.getOrderNo());
            orderDetl.setCreateBy(9527L);
@@ -121,6 +116,195 @@
            if (!orderDetlService.save(orderDetl)) {
                throw new CoolException("生成单据明细失败,请联系管理员");
            }
        }
    }
    @Override
    public void generateOrderPakOut(GenerateOrderPakOutParam param) {
        Order order = orderService.selectByNo(param.getOrderNo(), param.getHostId());
        // 如果单据不存在则添加;如果单据存在,作业中无法修改,反之则修改单据
        boolean boo = false;
        boolean b = false;
        if (!Cools.isEmpty(order)) {
            List<OrderDetl> orderDetls = orderDetlService.list(new LambdaQueryWrapper<OrderDetl>()
                    .eq(OrderDetl::getOrderId, order.getId()).eq(OrderDetl::getHostId, param.getHostId()));
            if (orderDetls.size() == param.getMats().size()) {
                for (OrderDetl o : orderDetls
                ) {
                    for (GenerateOrderMatParam matParam : param.getMats()
                    ) {
                        if (o.getMatnr().equals(matParam.getMatnr()) && !o.getAnfme().equals(matParam.getAnfme())) {
                            boo = true;
                            break;
                        }
                        if (o.getMatnr().equals(matParam.getMatnr())) {
                            b = true;
                        }
                    }
                    if (boo || !b) {
                        break;
                    }
                }
            } else {
                boo = true;
            }
        }
        if (boo || (!b && !Cools.isEmpty(order))) {
            if (order.getSettle() > 1L) {
                throw new CoolException(param.getOrderNo() + "正在出库,无法修改单据");
            }
            orderService.removeById(order.getId());
            DocType docType = docTypeService.getOne(new LambdaQueryWrapper<DocType>().eq(DocType::getDocId, param.getOrderType()));
            if (docType == null) {
                throw new CoolException("订单类型不存在");
            }
            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,    // 备注
                    param.getHostId() //仓库ID
            );
            if (!orderService.save(order)) {
                throw new CoolException("生成单据主档失败,请联系管理员");
            }
            List<GenerateOrderMatParam> mats = param.getMats();
            orderDetlService.remove(new LambdaQueryWrapper<OrderDetl>().eq(OrderDetl::getOrderNo, order.getOrderNo()));
            for (GenerateOrderMatParam matParam : mats) {
                Mat mat = matService.getOne(new LambdaQueryWrapper<Mat>().eq(Mat::getMatnr, matParam.getMatnr()).eq(Mat::getHostId, param.getHostId()));
                if (Cools.isEmpty(mat)) {
                    throw new CoolException(matParam.getMatnr() + "编号商品检索失败,请先添加商品");
                }
                OrderDetl orderDetl = new OrderDetl();
                orderDetl.sync(mat);
                orderDetl.setBatch(matParam.getBatch());
                orderDetl.setAnfme(matParam.getAnfme());
                orderDetl.setOrderId(order.getId());
                orderDetl.setOrderNo(order.getOrderNo());
                orderDetl.setThreeCode(matParam.getWarehouse());//仓库号
                orderDetl.setSupp(matParam.getOrigin());//来源单号
                orderDetl.setSuppCode(matParam.getOriginNo());//来源序号
                orderDetl.setCreateBy(9527L);
                orderDetl.setCreateTime(now);
                orderDetl.setUpdateBy(9527L);
                orderDetl.setUpdateTime(now);
                orderDetl.setStatus(1);
                orderDetl.setQty(0.0D);
                orderDetl.setHostId(param.getHostId());
                if (!orderDetlService.save(orderDetl)) {
                    throw new CoolException("生成单据明细失败,请联系管理员");
                }
            }
        }
        if (!boo && Cools.isEmpty(order)) {
            DocType docType = docTypeService.getOne(new LambdaQueryWrapper<DocType>().eq(DocType::getDocId, param.getOrderType()));
            if (docType == null) {
                throw new CoolException("订单类型不存在");
            }
            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,    // 备注
                    param.getHostId() //仓库ID
            );
            if (!orderService.save(order)) {
                throw new CoolException("生成单据主档失败,请联系管理员");
            }
            List<GenerateOrderMatParam> mats = param.getMats();
            orderDetlService.remove(new LambdaQueryWrapper<OrderDetl>().eq(OrderDetl::getOrderNo, order.getOrderNo()));
            for (GenerateOrderMatParam matParam : mats) {
                Mat mat = matService.getOne(new LambdaQueryWrapper<Mat>().eq(Mat::getMatnr, matParam.getMatnr()).eq(Mat::getHostId, param.getHostId()));
                if (Cools.isEmpty(mat)) {
                    throw new CoolException(matParam.getMatnr() + "编号商品检索失败,请先添加商品");
                }
                OrderDetl orderDetl = new OrderDetl();
                orderDetl.sync(mat);
                orderDetl.setBatch(matParam.getBatch());
                orderDetl.setAnfme(matParam.getAnfme());
                orderDetl.setOrderId(order.getId());
                orderDetl.setOrderNo(order.getOrderNo());
                orderDetl.setThreeCode(matParam.getWarehouse());//仓库号
                orderDetl.setSupp(matParam.getOrigin());//来源单号
                orderDetl.setSuppCode(matParam.getOriginNo());//来源序号
                orderDetl.setCreateBy(9527L);
                orderDetl.setCreateTime(now);
                orderDetl.setUpdateBy(9527L);
                orderDetl.setUpdateTime(now);
                orderDetl.setStatus(1);
                orderDetl.setQty(0.0D);
                orderDetl.setHostId(param.getHostId());
                if (!orderDetlService.save(orderDetl)) {
                    throw new CoolException("生成单据明细失败,请联系管理员");
                }
            }
        }
    }
@@ -129,4 +313,185 @@
        List<DocType> list = docTypeService.list();
        return list;
    }
    @Override
    public List<OrderSettle> getOrderStatus() {
        return orderSettleService.list();
    }
    @Override
    public List<OrderListDto> getOrderList(OrderListParam param, Long hostId) {
        ArrayList<OrderListDto> listDtos = new ArrayList<>();
        LambdaQueryWrapper<Order> wrapper = new LambdaQueryWrapper<Order>().eq(Order::getHostId, hostId);
        if (!Cools.isEmpty(param)) {
            if (!Cools.isEmpty(param.getOrderType())) {
                wrapper.eq(Order::getDocType, param.getOrderType());
            }
            if (!Cools.isEmpty(param.getOrderNo())) {
                wrapper.eq(Order::getOrderNo, param.getOrderNo());
            }
            if (!Cools.isEmpty(param.getStatus())) {
                wrapper.eq(Order::getStatus, param.getStatus());
            }
        }
        List<Order> list = orderService.list(wrapper);
        for (Order order : list) {
            List<OrderDetl> orderDetls = orderDetlService.list(new LambdaQueryWrapper<OrderDetl>().eq(OrderDetl::getHostId, hostId).eq(OrderDetl::getOrderId, order.getId()));
            OrderListDto dto = new OrderListDto();
            dto.setOrder(order);
            dto.setOrderDetls(orderDetls);
            listDtos.add(dto);
        }
        return listDtos;
    }
    @Override
    @Transactional
    public int createMat(CreateMatParam param) {
        int count = 0;
        Long hostId = param.getHostId();
        for (MatParam matParam : param.getMats()) {
            //获取分类
            Tag tag = tagService.getTag(matParam.getFirstTag(), matParam.getSecondTag(), hostId);
            matService.remove(new LambdaQueryWrapper<Mat>()
                    .eq(Mat::getMatnr, matParam.getMatnr())
                    .eq(Mat::getHostId, hostId));
            Mat mat = new Mat();
            mat.setMatnr(matParam.getMatnr());//物料号
            mat.setHostId(hostId);//仓库ID
            mat.setTagId(tag.getId());//分类ID
            if (!Cools.isEmpty(matParam.getShopCategory())) {
                Tag shopTag = tagService.getOne(new LambdaQueryWrapper<Tag>()
                        .eq(Tag::getName, matParam.getShopCategory())
                        .eq(Tag::getHostId, hostId));
                if (shopTag == null) {
                    //商品分类为空,创建商品分类
                    shopTag = new Tag();
                    shopTag.setName(matParam.getShopCategory());
                    shopTag.setParentId(tag.getId());
                    shopTag.setStatus(1);
                    shopTag.setHostId(hostId);
                    shopTag.setCreateTime(new Date());
                    shopTag.setUpdateTime(new Date());
                    tagService.save(shopTag);
                }
                mat.setTagId(shopTag.getId());//分类ID
            }
            if (!Cools.isEmpty(matParam.getMaktx())) {
                mat.setMaktx(matParam.getMaktx());
            }
            if (!Cools.isEmpty(matParam.getMaktx())) {
                mat.setMaktx(matParam.getMaktx());
            }
            if (!Cools.isEmpty(matParam.getName())) {
                mat.setName(matParam.getName());
            }
            if (!Cools.isEmpty(matParam.getSpecs())) {
                mat.setSpecs(matParam.getSpecs());
            }
            if (!Cools.isEmpty(matParam.getMemo())) {
                mat.setMemo(matParam.getMemo());
            }
            if (!Cools.isEmpty(matParam.getStatus())) {
                mat.setStatus(matParam.getStatus());
            } else {
                mat.setStatus(1);
            }
            if (!Cools.isEmpty(matParam.getMainHost())) {
                mat.setMainHost(matParam.getMainHost());
            }
            if (!Cools.isEmpty(matParam.getMainSource())) {
                mat.setMainSource(matParam.getMainSource());
            }
            if (!Cools.isEmpty(matParam.getBarcode())) {
                mat.setBarcode(matParam.getBarcode());
            }
            if (!Cools.isEmpty(matParam.getCyclePickCode())) {
                mat.setCyclePickCode(matParam.getCyclePickCode());
            }
            if (!Cools.isEmpty(matParam.getLocationStock())) {
                mat.setLocationStock(matParam.getLocationStock());
            }
            if (!Cools.isEmpty(matParam.getMaterial())) {
                mat.setMaterial(matParam.getMaterial());
            }
            if (!Cools.isEmpty(matParam.getModel())) {
                mat.setModel(matParam.getModel());
            }
            if (!Cools.isEmpty(matParam.getDecrees())) {
                mat.setDecrees(matParam.getDecrees());
            }
            if (!Cools.isEmpty(matParam.getWeight())) {
                mat.setWeight(matParam.getWeight());
            }
            if (!Cools.isEmpty(matParam.getImgNum())) {
                mat.setImgNum(matParam.getImgNum());
            }
            if (!Cools.isEmpty(matParam.getPurchasingUnits())) {
                mat.setPurchasingUnits(matParam.getPurchasingUnits());
            }
            if (!Cools.isEmpty(matParam.getProcessNumber())) {
                mat.setProcessNumber(matParam.getProcessNumber());
            }
            if (!Cools.isEmpty(matParam.getBom())) {
                mat.setBom(matParam.getBom());
            }
            if (!Cools.isEmpty(matParam.getSafeNum())) {
                mat.setSafeNum(matParam.getSafeNum());
            }
            if (!Cools.isEmpty(matParam.getMiniCount())) {
                mat.setMiniCount(matParam.getMiniCount());
            }
            if (!Cools.isEmpty(matParam.getReplenishmentNum())) {
                mat.setReplenishmentNum(matParam.getReplenishmentNum());
            }
            if (!Cools.isEmpty(matParam.getTmp1())) {
                mat.setTmp1(matParam.getTmp1());
            }
            if (!Cools.isEmpty(matParam.getTmp2())) {
                mat.setTmp2(matParam.getTmp2());
            }
            if (!Cools.isEmpty(matParam.getTmp3())) {
                mat.setTmp3(matParam.getTmp3());
            }
            if (!Cools.isEmpty(matParam.getRestockDemand())) {
                mat.setRestockDemand(matParam.getRestockDemand());
            }
            if (!Cools.isEmpty(matParam.getLapse())) {
                mat.setLapse(matParam.getLapse());
            }
            if (!Cools.isEmpty(matParam.getShortcuts())) {
                mat.setShortcuts(matParam.getShortcuts());
            }
            if (!Cools.isEmpty(matParam.getUnits())) {
                mat.setUnits(matParam.getUnits());
            }
            if (!Cools.isEmpty(matParam.getLength())) {
                mat.setLength(matParam.getLength());
            }
            if (!Cools.isEmpty(matParam.getWidth())) {
                mat.setWidth(matParam.getWidth());
            }
            if (!Cools.isEmpty(matParam.getHeight())) {
                mat.setHeight(matParam.getHeight());
            }
            if (!Cools.isEmpty(matParam.getAccountingClass())) {
                mat.setAccountingClass(matParam.getAccountingClass());
            }
            if (!Cools.isEmpty(matParam.getBatch())) {
                mat.setBatch(matParam.getBatch());
            }
            if (!Cools.isEmpty(matParam.getInventoryAccount())) {
                mat.setInventoryAccount(matParam.getInventoryAccount());
            }
            if (matService.save(mat)) {
                count++;
            }
        }
        return count;
    }
}