自动化立体仓库 - WMS系统
skyouc
昨天 3aed7236f2db67dd90115a39bc8f1465e4cc8b73
src/main/java/com/zy/api/service/impl/KopenApiServiceImpl.java
@@ -2,16 +2,13 @@
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.DateUtils;
import com.core.common.R;
import com.core.exception.CoolException;
import com.zy.api.entity.OrderParams;
import com.zy.api.entity.ReportOrderParam;
import com.zy.api.entity.PubOrderParams;
import com.zy.api.entity.ReportOrderParam;
import com.zy.api.entity.SyncMatParmas;
import com.zy.api.enums.MatLocType;
import com.zy.api.enums.MatType;
import com.zy.api.enums.OrderType;
import com.zy.api.enums.OrderWkType;
import com.zy.api.service.KopenApiService;
@@ -31,9 +28,6 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;
@@ -66,6 +60,7 @@
    /**
     * 上架派工单反馈
     *
     * @author Ryan
     * @date 2025/11/24 15:33
     */
@@ -97,6 +92,76 @@
        } catch (Exception e) {
            return R.error(e.getMessage());
        }
    }
    /* */
    /**
     * 备货指示派工单下发
     *
     * @author Ryan
     * @date 2025/11/24 15:21
     * @param params
     * @return com.core.common.R
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R sendOutDispatch(PubOrderParams params) {
        if (Objects.isNull(params)) {
            return R.error("参数不能为空!!");
        }
        // 校验参数
        if (Objects.isNull(params.getDispatch_no())) {
            return R.error("派工单编号不能为空!!");
        }
        if (Objects.isNull(params.getKopen_id())) {
            return R.error("流水号不能为空!!");
        }
        if (Objects.isNull(params.getCompany_id())) {
            return R.error("公司ID不能为空!!");
        }
        addOrUpdateOrders(params, "add");
        return R.ok("备货指示派工单下发成功!!");
    }
    /**
     * 备货指示派工单
     *
     * @author Ryan
     * @date 2025/12/16 9:15
     * @param params
     */
    private void outOrderAddAndUpdate(PubOrderParams params, String type) {
        if (Objects.isNull(params)) {
            throw new CoolException("参数不能为空!!");
        }
        if (Objects.isNull(params.getType())) {
            throw new CoolException("订单类型不能为空!!");
        }
        OrderParams orderParams = JSONObject.parseObject(JSONObject.toJSONString(params), OrderParams.class);
        Order order = orderService.selectOne(new EntityWrapper<Order>().eq("order_no", orderParams.getInv_no()));
        if (type.equals("add") && !Objects.isNull(order)) {
            throw new CoolException("单据已存在, 不可重复添加!!");
        }
        // 判断订单是否存在
        if (Objects.isNull(order)) {
            /** 不存在,新增订单 */
            generateOrders(params);
        } else {
            /** 存在,删除老订单,更新插入新订单 */
            // 删除旧订单明细
            if (!orderDetlService.delete(new EntityWrapper<OrderDetl>().eq("order_id", order.getId()))) {
                throw new CoolException("订单明细删除失败!!");
            }
            ;
            if (!orderService.deleteById(order.getId())) {
                throw new CoolException("原单据删除失败!!");
            }
            generateOrders(params);
        }
    }
    /**
@@ -167,9 +232,15 @@
        if (Objects.isNull(params.getType())) {
            throw new CoolException("订单类型不能为空!!");
        }
        OrderParams orderParams = JSONObject.parseObject(JSONObject.toJSONString(params), OrderParams.class);
        Order order = orderService.selectOne(new EntityWrapper<Order>().eq("order_no", orderParams.getInv_no()));
        Order order = new Order();
        if (OrderType.ORDER_IN.type.equals(OrderWkType.getTypeVal(params.getType()))) {
            // 入库
          order = orderService.selectOne(new EntityWrapper<Order>().eq("order_no", orderParams.getInv_no()));
        } else if (OrderType.ORDER_OUT.type.equals(OrderWkType.getTypeVal(params.getType()))) {
            // 出库
           order = orderService.selectOne(new EntityWrapper<Order>().eq("order_no", orderParams.getDispatch_no()));
        }
        if (type.equals("add") && !Objects.isNull(order)) {
            throw new CoolException("单据已存在, 不可重复添加!!");
        }
@@ -182,7 +253,8 @@
            // 删除旧订单明细
            if (!orderDetlService.delete(new EntityWrapper<OrderDetl>().eq("order_id", order.getId()))) {
                throw new CoolException("订单明细删除失败!!");
            };
            }
            if (!orderService.deleteById(order.getId())) {
                throw new CoolException("原单据删除失败!!");
            }
@@ -193,10 +265,10 @@
    public static String generateUUID(OrderParams params) {
        return java.util.UUID.randomUUID().toString();
    }
    /**
     * 生成订单信息
     *
     * @param params
     */
    @Transactional(rollbackFor = Exception.class)
@@ -206,12 +278,14 @@
        if (OrderType.ORDER_IN.type.equals(OrderWkType.getTypeVal(params.getType()))) {
            // 入库
            newOrder.setPakinPakoutStatus(1);
            newOrder.setDocType(Long.parseLong(params.getType()));
            newOrder.setOrderNo(params.getInv_no());
        } else if (OrderType.ORDER_OUT.type.equals(OrderWkType.getTypeVal(params.getType()))) {
            // 出库
            newOrder.setPakinPakoutStatus(2);
            newOrder.setDocType(5L);
            newOrder.setOrderNo(params.getDispatch_no());
        }
        newOrder.setDocType(Long.parseLong(params.getType()));
        newOrder.setOrderNo(params.getInv_no());
        newOrder.setUuid(generateUUID(params));
        // 流水号(唯一)
        newOrder.setDefNumber(params.getKopen_id());
@@ -242,13 +316,21 @@
                BeanUtils.copyProperties(matnr, orderItem);
                orderItem.setOrderId(newOrder.getId());
                orderItem.setOrderNo(newOrder.getOrderNo());
                orderItem.setAnfme(Math.round(item.getInv_qty() * 10000) / 10000.0);
                if (OrderType.ORDER_IN.type.equals(OrderWkType.getTypeVal(params.getType()))) {
                    // 入库
                    orderItem.setAnfme(Math.round(item.getInv_qty() * 10000) / 10000.0);
                } else if (OrderType.ORDER_OUT.type.equals(OrderWkType.getTypeVal(params.getType()))) {
                    // 出库
                    newOrder.setPakinPakoutStatus(2);
                    orderItem.setAnfme(Math.round(item.getOrder_qty() * 10000) / 10000.0);
                }
                orderItem.setMatnr(matnr.getMatnr());
                orderItem.setMaktx(matnr.getMaktx());
                orderItem.setBrand(matnr.getBrand());
                orderItem.setBatch(1 + "");
                orderItem.setStandby1(item.getPro_id());
                //关联上加派工单号+零件代码+供应商代码
                // 关联上加派工单号+零件代码+供应商代码
                orderItem.setThreeCode(item.getTotal_serial());
                // 供应商代码
                orderItem.setSuppCode(item.getPro_id());