zhangback
7 天以前 ca412ade3b178fbc8ba0a4b6215a040acdede954
tms/src/main/java/com/ruoyi/tms/service/impl/TmsQuoteDetailServiceImpl.java
@@ -2,6 +2,7 @@
import java.util.List;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.enums.SystemDataNoEnum;
import com.ruoyi.common.utils.DateUtils;
@@ -10,6 +11,7 @@
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.service.ISystemDataNoService;
import com.ruoyi.tms.domain.TmsQuotePlan;
import com.ruoyi.tms.domain.vo.QuoteDetailItem;
import com.ruoyi.tms.mapper.TmsQuotePlanMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
@@ -111,32 +113,66 @@
     * @return 结果
     */
    @Override
    public int insertTmsQuoteDetail(TmsQuoteDetail tmsQuoteDetail)
    {
    public int insertTmsQuoteDetail(TmsQuoteDetail tmsQuoteDetail) {
        Integer quotePlanId = tmsQuoteDetail.getQuotePlanId();
        if (quotePlanId == null){
        if (quotePlanId == null) {
            throw new RuntimeException("请先选择报价方案不能为空");
        }
        TmsQuotePlan tmsQuotePlan = tmsQuotePlanMapper.selectTmsQuotePlanById(quotePlanId);
        if (tmsQuotePlan == null){
        if (tmsQuotePlan == null) {
            throw new RuntimeException("报价方案不存在");
        }
        // 车型报价类型
        //if (tmsQuotePlan.getPlanType() == 0) {
            List<QuoteDetailItem> quoteItems = tmsQuoteDetail.getQuoteItems();
            if (quoteItems == null || quoteItems.isEmpty()) {
                throw new RuntimeException("请填写车型报价");
            }
            int count = 0;
            for (QuoteDetailItem item : quoteItems) {
                // 拷贝主对象固定属性
                TmsQuoteDetail newDetail = BeanUtil.copyProperties(tmsQuoteDetail, TmsQuoteDetail.class);
                // 拷贝 item 属性
                BeanUtil.copyProperties(item ,newDetail);
                // 插入
                addDetail(quotePlanId, tmsQuotePlan, newDetail);
                count++;
            }
            return count;
        //}
        // 普通类型
        //return addDetail(quotePlanId, tmsQuotePlan, tmsQuoteDetail);
    }
    public int addDetail(Integer quotePlanId, TmsQuotePlan tmsQuotePlan, TmsQuoteDetail tmsQuoteDetail){
        // 1、同一报价清单,不能添加相同【路线-车型】数据
        Long l = tmsQuoteDetailMapper.selectCount(new LambdaQueryWrapper<TmsQuoteDetail>()
                .eq(TmsQuoteDetail::getQuotePlanId, quotePlanId)
                .eq(TmsQuoteDetail::getVehicleType, tmsQuoteDetail.getVehicleType())
                .eq(TmsQuoteDetail::getTransportRoute, tmsQuoteDetail.getTransportRoute())
                .eq(TmsQuoteDetail::getPlanType, tmsQuotePlan.getPlanType())
        );
        if (l > 0){
            throw new RuntimeException("同一报价清单,不能添加相同【路线-车型】数据");
        }
        // 2、不同报价方案,不能添加相同【客户-路线-车型】数据
        int l1 = tmsQuoteDetailMapper.countSameCustomerRouteVehicle(new TmsQuoteDetail(){{
            setQuotePlanId(quotePlanId);
            setCustomerId(tmsQuotePlan.getCustomerId());
            setTransportRoute(tmsQuoteDetail.getTransportRoute());
            setVehicleType(tmsQuoteDetail.getVehicleType());
        }});
        Long l1 = tmsQuoteDetailMapper.selectCount(new LambdaQueryWrapper<TmsQuoteDetail>()
                .ne(TmsQuoteDetail::getQuotePlanId, quotePlanId)
                .eq(TmsQuoteDetail::getCustomerId, tmsQuotePlan.getCustomerId())
                .eq(TmsQuoteDetail::getTransportRoute, tmsQuoteDetail.getTransportRoute())
                .eq(TmsQuoteDetail::getPlanType, tmsQuotePlan.getPlanType())
                .eq(TmsQuoteDetail::getVehicleType, tmsQuoteDetail.getVehicleType())
        );
        if (l1 > 0){
            throw new RuntimeException("不同报价方案,不能添加相同【客户-路线-车型】数据");
@@ -148,8 +184,13 @@
        tmsQuoteDetail.setSystemCode(noByKey);
        tmsQuoteDetail.setCreateBy(SecurityUtils.getUsername());
        tmsQuoteDetail.setCreateTime(DateUtils.getNowDate());
        tmsQuoteDetail.setPlanType(tmsQuotePlan.getPlanType());
        tmsQuoteDetail.setCustomerId(tmsQuotePlan.getCustomerId());
        return tmsQuoteDetailMapper.insertTmsQuoteDetail(tmsQuoteDetail);
    }
    /**
     * 新增报价明细[批量]
@@ -193,13 +234,14 @@
            throw new RuntimeException("同一报价清单,不能添加相同【路线-车型】数据");
        }
        // 2、不同报价方案,不能添加相同【客户-路线-车型】数据
        int l1 = tmsQuoteDetailMapper.countSameCustomerRouteVehicle(new TmsQuoteDetail(){{
            setQuotePlanId(quotePlanId);
            setCustomerId(tmsQuotePlan.getCustomerId());
            setTransportRoute(tmsQuoteDetail.getTransportRoute());
            setVehicleType(tmsQuoteDetail.getVehicleType());
            setId(tmsQuoteDetail.getId());
        }});
        Long l1 = tmsQuoteDetailMapper.selectCount(new LambdaQueryWrapper<TmsQuoteDetail>()
                .ne(TmsQuoteDetail::getQuotePlanId, quotePlanId)
                .ne(TmsQuoteDetail::getId, tmsQuoteDetail.getId())
                .eq(TmsQuoteDetail::getCustomerId, tmsQuotePlan.getCustomerId())
                .eq(TmsQuoteDetail::getTransportRoute, tmsQuoteDetail.getTransportRoute())
                .eq(TmsQuoteDetail::getPlanType, tmsQuotePlan.getPlanType())
                .eq(TmsQuoteDetail::getVehicleType, tmsQuoteDetail.getVehicleType())
        );
        if (l1 > 0){
            throw new RuntimeException("不同报价方案,不能添加相同【客户-路线-车型】数据");