zhangback
7 天以前 ca412ade3b178fbc8ba0a4b6215a040acdede954
tms/src/main/java/com/ruoyi/tms/service/impl/TmsQuotePlanServiceImpl.java
@@ -1,6 +1,7 @@
package com.ruoyi.tms.service.impl;
import java.util.List;
import java.util.stream.Collectors;
import com.ruoyi.common.enums.SystemDataNoEnum;
import com.ruoyi.common.utils.DateUtils;
@@ -8,6 +9,8 @@
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.service.ISystemDataNoService;
import com.ruoyi.tms.domain.TmsQuoteItem;
import com.ruoyi.tms.service.ITmsQuoteItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;
@@ -38,6 +41,8 @@
    protected final Logger logger = LoggerFactory.getLogger(getClass());
    @Resource
    private TmsQuotePlanMapper tmsQuotePlanMapper;
    @Autowired
    private ITmsQuoteItemService tmsQuoteItemService;
    @Autowired
    ISystemDataNoService systemDataNoService;
@@ -51,7 +56,9 @@
    @Override
    public TmsQuotePlan selectTmsQuotePlanById(Integer id)
    {
        return tmsQuotePlanMapper.selectTmsQuotePlanById(id);
        TmsQuotePlan tmsQuotePlan = tmsQuotePlanMapper.selectTmsQuotePlanById(id);
        tmsQuotePlan.setQuoteItems(tmsQuoteItemService.selectTmsQuoteItemList(new TmsQuoteItem(){{setQuotePlanId(id);}}));
        return tmsQuotePlan;
    }
    /**
@@ -113,7 +120,16 @@
        tmsQuotePlan.setSystemCode(noByKey);
        tmsQuotePlan.setCreateBy(SecurityUtils.getUsername());
        tmsQuotePlan.setCreateTime(DateUtils.getNowDate());
        return tmsQuotePlanMapper.insertTmsQuotePlan(tmsQuotePlan);
        tmsQuotePlanMapper.insertTmsQuotePlan(tmsQuotePlan);
        List<TmsQuoteItem> quoteItems = tmsQuotePlan.getQuoteItems();
        if (quoteItems != null && !quoteItems.isEmpty()){
            quoteItems.forEach(tmsQuoteItem -> {
                tmsQuoteItem.setQuotePlanId(tmsQuotePlan.getId());
            });
            tmsQuoteItemService.insertTmsQuoteItemBatch(quoteItems);
        }
        return 1;
    }
    /**
@@ -140,7 +156,41 @@
    {
        tmsQuotePlan.setUpdateBy(SecurityUtils.getUsername());
        tmsQuotePlan.setUpdateTime(DateUtils.getNowDate());
        return tmsQuotePlanMapper.updateTmsQuotePlan(tmsQuotePlan);
        int i = tmsQuotePlanMapper.updateTmsQuotePlan(tmsQuotePlan);
            List<TmsQuoteItem> quoteItems = tmsQuotePlan.getQuoteItems();
            if (quoteItems != null && !quoteItems.isEmpty()){
                List<TmsQuoteItem> tmsQuoteItems = tmsQuoteItemService.selectTmsQuoteItemList(new TmsQuoteItem() {{
                    setQuotePlanId(tmsQuotePlan.getId());
                }});
                // 1、删除本次提交没有的数据
                List<Integer> collect = quoteItems.stream().map(TmsQuoteItem::getId).collect(Collectors.toList());
                tmsQuoteItems.removeIf(tmsQuoteItem -> collect.contains(tmsQuoteItem.getId()));
                List<Integer> collect1 = tmsQuoteItems.stream().map(TmsQuoteItem::getId).collect(Collectors.toList());
                if (!collect1.isEmpty()){
                    tmsQuoteItemService.getBaseMapper().deleteBatchIds(collect1);
                }
                // 2、更新本次提交有的数据
                List<TmsQuoteItem> collect2 = quoteItems.stream().filter(tmsQuoteItem -> tmsQuoteItem.getId() != null).collect(Collectors.toList());
                if (!collect2.isEmpty()){
                    tmsQuoteItemService.updateTmsQuoteItemBatch(collect2);
                }
                // 3、新增本次提交没有的数据
                List<TmsQuoteItem> collect3 = quoteItems.stream().
                        filter(tmsQuoteItem -> tmsQuoteItem.getId() == null).collect(Collectors.toList());
                if (!collect3.isEmpty()){
                    collect3.forEach(tmsQuoteItem -> tmsQuoteItem.setQuotePlanId(tmsQuotePlan.getId()));
                    tmsQuoteItemService.insertTmsQuoteItemBatch(collect3);
                }
            }
        return i;
    }
    /**