自动化立体仓库 - WMS系统
skyouc
2 天以前 4304744cfb33afe68934cd63029f4f01a6b34b18
src/main/java/com/zy/api/service/impl/KopenApiServiceImpl.java
@@ -1,5 +1,6 @@
package com.zy.api.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
@@ -14,6 +15,7 @@
import com.zy.api.entity.StockAdjustParams;
import com.zy.api.entity.StockUpOrderParams;
import com.zy.api.entity.SyncMatParmas;
import com.zy.api.entity.dto.LocDetlDto;
import com.zy.api.entity.dto.XSR;
import com.zy.api.enums.MatLocType;
import com.zy.api.enums.OrderType;
@@ -46,6 +48,7 @@
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
@Service("kopenApiServiceImpl")
@@ -83,6 +86,7 @@
     */
    @Override
    public XSR receiveOrders(List<PubOrderParams> orderParams, String type) {
        log.info("接收下发订单信息参数:{}", JSONObject.toJSONString(orderParams));
        orderParams.forEach(params -> {
            if (params.getType().equals(OrderWkType.getTypeVal(params.getType()))) {
                throw new CoolException("当前类型不是上架派工单!!");
@@ -102,6 +106,7 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public XSR getInDispatchResult(List<ReportOrderParam> params, Order order) {
        log.info("上架派工单反馈请求参数:{}", JSONObject.toJSONString(params));
        if (Objects.isNull(params)) {
            return XSR.error("参数不能为空!!");
        }
@@ -119,6 +124,7 @@
            }
            JSONObject jsonObject = JSONObject.parseObject(response);
            Integer code = jsonObject.getInteger("code");
            log.info("上架派工单返回结果:{}", JSONObject.toJSONString(response));
            if (!Objects.isNull(code) && code.equals(200)) {
                if (!Objects.isNull(order)) {
                    order.setReportOnce(5);
@@ -128,7 +134,7 @@
            } else {
                if (!Objects.isNull(order)) {
                    int reportOnce = order.getReportOnce();
                    reportOnce ++;
                    reportOnce++;
                    order.setReportOnce(reportOnce);
                    orderService.updateById(order);
                }
@@ -138,7 +144,7 @@
        } catch (Exception e) {
            if (!Objects.isNull(order)) {
                int reportOnce = order.getReportOnce();
                reportOnce ++;
                reportOnce++;
                order.setReportOnce(reportOnce);
                orderService.updateById(order);
            }
@@ -149,9 +155,10 @@
    /**
     * 获取自定义请求头
     *
     * @return java.util.Map<java.lang.String, java.lang.Object>
     * @author Ryan
     * @date 2025/12/29 9:11
     * @return java.util.Map<java.lang.String,java.lang.Object>
     */
    private Map<String, Object> getHeaderParam() {
        Map<String, Object> headerParam = new HashMap<>();
@@ -180,6 +187,8 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public XSR sendOutDispatch(List<PubOrderParams> pubOrderParams, String type) {
        log.info("备货指示派工单下发参数:{}", JSONObject.toJSONString(pubOrderParams));
        if (Objects.isNull(pubOrderParams) || pubOrderParams.isEmpty()) {
            return XSR.error("参数不能为空!!");
        }
@@ -254,6 +263,8 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public synchronized XSR basMatupdate(List<SyncMatParmas> params) {
        log.info("基础零件变更:{}", JSONArray.toJSONString(params));
        if (Objects.isNull(params) || params.isEmpty()) {
            return XSR.error("参数不能为空!!");
        }
@@ -264,7 +275,12 @@
            if (Objects.isNull(mats.getPro_type())) {
                throw new CoolException("零件类型不能为空!!");
            }
            Mat matnr = matService.selectOne(new EntityWrapper<Mat>().eq("matnr", mats.getPro_komcode()));
            if (Objects.isNull(mats.getPro_id())) {
                throw new CoolException("供应商不能为空!!");
            }
            Mat matnr = matService.selectOne(new EntityWrapper<Mat>()
                    .eq("supp_code", mats.getPro_id())
                    .eq("matnr", mats.getPro_komcode()));
            if (!Objects.isNull(matnr)) {
                // 订单时间
                if (Utils.isValidFormat(mats.getUpdate_time(), "yyyy-MM-dd HH:mm:ss")) {
@@ -492,6 +508,8 @@
     */
    @Override
    public XSR getOutDetails(List<StockUpOrderParams> stockUpParams) {
        log.info("备货单下发参数:{}", JSONArray.toJSONString(stockUpParams));
        if (Objects.isNull(stockUpParams)) {
            return XSR.error("参数不能为空!!");
        }
@@ -541,31 +559,61 @@
     * @return com.core.common.R
     */
    @Override
    public XSR getStockInfo(PageRequestParams params) {
    public XSR getStockInfo(List<PageRequestParams> params) {
        if (Objects.isNull(params) || params.isEmpty()) {
            throw new CoolException("参数不能为空!!");
        }
        Set<String> collect = params.stream().map(PageRequestParams::getPro_id).collect(Collectors.toSet());
        Set<String> komccodes = params.stream().map(PageRequestParams::getPro_komcode).collect(Collectors.toSet());
        EntityWrapper<LocDetl> wrapper = new EntityWrapper<>();
        if (!Objects.isNull(params.getPro_id())) {
            wrapper.eq("supp_code", params.getPro_id());
        }
        if (!Objects.isNull(params.getPro_komcode())) {
            wrapper.eq("matnr", params.getPro_komcode());
        }
        wrapper.in(collect.isEmpty(), "pro_id", collect);
        wrapper.in(komccodes.isEmpty(), "komccode", komccodes);
        Page<LocDetl> locDetls = locDetlService.selectPage(new Page<>(params.getCurr(), params.getLimit()),  wrapper);
        List<LocDetl> detls = locDetlService.selectList(wrapper);
        return XSR.ok(locDetls.getRecords());
        if (detls == null || detls.isEmpty()) {
            return XSR.ok();
        }
        List<LocDetlDto> dtos = new ArrayList<>();
        detls.forEach(item -> {
            LocDetlDto locDetlDto = new LocDetlDto();
            if (item.getDiffQty().compareTo(BigDecimal.ZERO) == 0) {
                locDetlDto.setLock_qty(0);
            } else {
                locDetlDto.setLock_qty(Integer.parseInt(item.getDiffQty().toString()));
            }
            if (item.getBookQty().compareTo(BigDecimal.ZERO) == 0) {
                locDetlDto.setStock_qty(0);
            } else {
                locDetlDto.setStock_qty(Integer.parseInt(item.getBookQty().toString()));
            }
            locDetlDto
                    .setPro_komcode(item.getMatnr())
                    .setPro_id(item.getStandby1())
                    .setLocation_no(item.getZpallet())
                    .setTarget_location("");
            dtos.add(locDetlDto);
        });
        return XSR.ok(dtos);
    }
    /**
     * 零件损溢单下发
     *
     * @author Ryan
     * @date 2025/11/24 15:22
     *
     * @param params
     * @return com.core.common.R
     * @author Ryan
     * @date 2025/11/24 15:22
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public XSR sendStockAdjust(List<StockAdjustParams> params, Long userId) {
        log.info("零件损溢单下发参数:{}", JSONArray.toJSONString(params));
        if (Objects.isNull(params)) {
            return XSR.error("参数不能为空!!");
        }
@@ -578,11 +626,12 @@
    /**
     * 损溢单完结上报
     * @author Ryan
     * @date 2025/12/30 16:57
     *
     * @param params
     * @param order
     * @return com.zy.api.entity.dto.XSR
     * @author Ryan
     * @date 2025/12/30 16:57
     */
    @Override
    public XSR reportCheckOrder(List<StockAdjustParams> params, CheckOrder order) {
@@ -612,7 +661,7 @@
            } else {
                if (!Objects.isNull(order)) {
                    int reportOnce = order.getReportOnce();
                    reportOnce ++;
                    reportOnce++;
                    order.setReportOnce(reportOnce);
                    checkOrderService.updateById(order);
                }
@@ -634,6 +683,7 @@
    /**
     * 备货单反馈
     *
     * @param params
     * @param order
     * @return
@@ -666,7 +716,7 @@
            } else {
                if (!Objects.isNull(order)) {
                    int reportOnce = order.getReportOnce();
                    reportOnce ++;
                    reportOnce++;
                    order.setReportOnce(reportOnce);
                    orderService.updateById(order);
                }
@@ -676,7 +726,7 @@
        } catch (Exception e) {
            if (!Objects.isNull(order)) {
                int reportOnce = order.getReportOnce();
                reportOnce ++;
                reportOnce++;
                order.setReportOnce(reportOnce);
                orderService.updateById(order);
            }
@@ -685,9 +735,66 @@
        }
    }
    /** 生成新的零件损溢单
     * @param userId */
    @Transactional(rollbackFor = Exception.class)
    /**
     * 备货指示派工单反馈
     * @author Ryan
     * @date 2026/1/15 15:20
     * @param orderParams
     * @param order
     * @return com.zy.api.entity.dto.XSR
     */
    @Override
    public XSR reportOutDetailsResult(List<ReportOrderParam> orderParams, Order order) {
        if (Objects.isNull(orderParams)) {
            return XSR.error("参数不能为空!!");
        }
        String response = null;
        try {
            response = new HttpHandler.Builder()
                    .setUri(url + ":" + port)
                    .setPath(prefix + "/getOutDetailsResult")
                    .setJson(JSONObject.toJSONString(orderParams))
                    .build()
                    .doPost();
             if (Objects.isNull(response) || response.trim().isEmpty()) {
                return XSR.error("外网接口无响应!!");
            }
            JSONObject jsonObject = JSONObject.parseObject(response);
            Integer code = jsonObject.getInteger("code");
            if (!Objects.isNull(code) && code.equals(200)) {
                if (!Objects.isNull(order)) {
                    order.setReportOnce(5);
                    orderService.updateById(order);
                }
                return XSR.ok("入库单上报完成!!");
            } else {
                if (!Objects.isNull(order)) {
                    int reportOnce = order.getReportOnce();
                    reportOnce++;
                    order.setReportOnce(reportOnce);
                    orderService.updateById(order);
                }
                String msg = jsonObject.getString("message");
                return XSR.error(Objects.isNull(msg) ? "上报失败!!" : msg);
            }
        } catch (Exception e) {
            if (!Objects.isNull(order)) {
                int reportOnce = order.getReportOnce();
                reportOnce++;
                order.setReportOnce(reportOnce);
                orderService.updateById(order);
            }
            log.error(e.getMessage(), e);
            return XSR.error(e.getMessage());
        }
    }
    /**
     * 生成新的零件损溢单
     *
     * @param userId
     */
    @Transactional(rollbackFor = Exception.class)
    public void gentCheckOrders(StockAdjustParams params, Long userId) {
        if (Objects.isNull(params.getDetails()) || params.getDetails().isEmpty()) {
            throw new CoolException("订单明细不能为空!!");