自动化立体仓库 - WMS系统
zwl
2025-04-16 b4b2da143af53a7422135abffd5306b282be6a39
src/main/java/com/zy/asrs/controller/OrderController.java
@@ -1,5 +1,7 @@
package com.zy.asrs.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
@@ -12,12 +14,17 @@
import com.zy.asrs.service.*;
import com.zy.common.model.DetlDto;
import com.zy.common.web.BaseController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
@Slf4j
@RestController
public class OrderController extends BaseController {
@@ -33,6 +40,25 @@
    private WrkDetlService wrkDetlService;
    @Autowired
    private WaitPakinService waitPakinService;
    @Autowired
    private LocDetlService locDetlService;
    @Value("${erp.address.URL}")
    //端口
    private String URL;
    @Value("${erp.address.inaddress}")
    //单据,商品档案地址
    private String inaddress;
    @Autowired
    private ApiLogService apiLogService;
    @Autowired
    private MatService matService;
    @Autowired
    private TagService tagService;
    @RequestMapping(value = "/order/nav/list/auth")
    @ManagerAuth
@@ -334,4 +360,93 @@
        return R.ok();
    }
    @RequestMapping(value = "/order/form/add/authtest")
    @ManagerAuth(memo = "手动添加订单")
    @Transactional
    public R formAddTest(@RequestBody OrderDomainParam param){
        if(Cools.isEmpty(param.getOrderNo())){
            String prefix = "";
            DocType docType = docTypeService.selectById(param.getDocType());
            if(!Cools.isEmpty(docType)){
                prefix = docType.getPakin() == 1 ? "RK" : "CK";
            }
            param.setOrderNo(prefix + snowflakeIdWorker.nextId());
        }
        Order order = orderService.selectByNo(param.getOrderNo());
        if (order != null) {
            return R.error("单据编号已存在");
        }
        Date now = new Date();
        order = new Order(
                String.valueOf(snowflakeIdWorker.nextId()),    // 编号[非空]
                param.getOrderNo(),    // 订单编号
                DateUtils.convert(now),    // 单据日期
                param.getDocType(),    // 单据类型
                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,    // 状态
                getUserId(),    // 添加人员
                now,    // 添加时间
                getUserId(),    // 修改人员
                now,    // 修改时间
                null    // 备注
        );
        if (!orderService.insert(order)) {
            throw new CoolException("保存订单主档失败");
        }
        List<DetlDto> list = new ArrayList<>();
        for (OrderDetl orderDetl : param.getOrderDetlList()) {
            DetlDto dto = new DetlDto(orderDetl.getMatnr(), orderDetl.getBatch());
            if (DetlDto.has(list, dto)) {
                OrderDetl item = orderDetlService.selectItem(order.getId(), orderDetl.getMatnr(), orderDetl.getBatch());
                item.setAnfme(item.getAnfme() + orderDetl.getAnfme());
                if (!orderDetlService.updateById(item)) {
                    throw new CoolException("保存订单明细档失败");
                }
            } else {
                list.add(dto);
                orderDetl.setOrderId(order.getId());
                orderDetl.setOrderNo(order.getOrderNo());
                orderDetl.setCreateBy(getUserId());
                orderDetl.setCreateTime(now);
                orderDetl.setUpdateBy(getUserId());
                orderDetl.setUpdateTime(now);
                orderDetl.setStatus(1);
                orderDetl.setQty(0.0D);
                //给添加子订单
                Set<String> exist = new HashSet<>();
                List<LocDetl> locDetls = locDetlService.queryStock(orderDetl.getMatnr(), orderDetl.getBatch(), null, exist);
                if (!orderDetlService.insert(orderDetl)) {
                    throw new CoolException("保存订单明细档失败");
                }
            }
        }
        return R.ok("订单添加成功");
    }
}