skyouc
2025-03-31 1719035b389120ed30a15bf3d62202a87bfa0ea3
rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/AsnOrderServiceImpl.java
@@ -1,11 +1,13 @@
package com.vincent.rsf.server.manager.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.vincent.rsf.framework.common.R;
import com.vincent.rsf.framework.exception.CoolException;
import com.vincent.rsf.server.api.entity.dto.PoItemsDto;
import com.vincent.rsf.server.api.service.ReceiveMsgService;
import com.vincent.rsf.server.api.service.ReportMsgService;
import com.vincent.rsf.server.manager.controller.params.AsnOrderAndItemsParams;
import com.vincent.rsf.server.manager.entity.AsnOrderItem;
import com.vincent.rsf.server.manager.mapper.AsnOrderItemMapper;
import com.vincent.rsf.server.manager.mapper.AsnOrderMapper;
@@ -20,6 +22,7 @@
import com.vincent.rsf.server.system.utils.SerialRuleUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.*;
@@ -41,10 +44,8 @@
    private ReportMsgService reportMsgService;
    @Resource
    private PurchaseMapper purchaseMapper;
    @Autowired
    private AsnOrderItemService asnOrderItemService;
    @Resource
    private SerialRuleMapper serialRuleMapper;
@@ -66,23 +67,6 @@
    }
    @Override
    public R generateBarcode(List<AsnOrder> orders) {
        orders.forEach(order -> {
            List<AsnOrderItem> items = asnOrderItemService.list(new LambdaQueryWrapper<AsnOrderItem>().eq(AsnOrderItem::getAsnId, order.getId()));
            if (!items.isEmpty()) {
                items.forEach(item -> {
                    String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_LABEL_CODE, item);
                    item.setTrackCode(ruleCode);
                });
                if (!asnOrderItemService.saveOrUpdateBatch(items)) {
                    throw new CoolException("生成条码失败!!");
                }
            }
        });
        return R.ok();
    }
    @Override
    public List<AsnOrder> getListByMatnr(Map<String, String> params) {
        if (Objects.isNull(params)) {
            throw new CoolException("查询条件不能为空!!");
@@ -98,4 +82,63 @@
        return this.listByIds(longList);
    }
    @Override
    public R saveOrderAndItems(AsnOrderAndItemsParams params) {
        if (Objects.isNull(params.getOrders())) {
            throw new CoolException("主单信息不能为空");
        }
        AsnOrder orders = params.getOrders();
        if (Objects.isNull(orders)) {
            throw new CoolException("单据不能为空!!");
        }
        String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_ASN_ORDER, orders);
        if (Objects.isNull(ruleCode)) {
            throw new CoolException("收货通知单编码生成失败!!");
        }
        orders.setCode(ruleCode);
        if (!this.save(orders)) {
            throw new CoolException("主单保存失败!!");
        }
        if (params.getItems().isEmpty()) {
            throw new CoolException("收货通知单明细不能为寒食节!!");
        }
        params.getItems().forEach(item -> {
            item.put("asnId", orders.getId());
            item.put("asnCode", orders.getCode());
            item.put("poCode", orders.getPoCode());
            if (!asnOrderItemService.fieldsSave(item)) {
                throw new CoolException("明细保存失败!!");
            }
        });
        return R.ok("保存成功!!");
    }
    /**
     * 表单明细修改
     * @param params
     * @return
     */
    @Override
    @Transactional
    public R updateOrderItem(AsnOrderAndItemsParams params) {
        if (Objects.isNull(params.getOrders())) {
            throw new CoolException("主单信息不能为空!!");
        }
        if (Objects.isNull(params.getOrders().getId())) {
            throw new CoolException("数据错误:单据ID不能为空!!");
        }
        if (!this.updateById(params.getOrders())) {
            throw new CoolException("主单修改失败!!");
        }
        if (Objects.isNull(params.getItems()) || params.getItems().isEmpty()) {
            return R.ok("修改完成!!");
        }
        List<Map<String, Object>> items = params.getItems();
        List<AsnOrderItem> asnOrderItems = JSONArray.parseArray(JSONArray.toJSONString(items), AsnOrderItem.class);
        if (!asnOrderItemService.saveOrUpdateBatch(asnOrderItems)) {
            throw new CoolException("明细修改失败!!");
        }
        return R.ok("修改完成!!");
    }
}