zhangback
2025-11-18 4636b03d801662db1b8712d7a9ae9105462eca37
tms/src/main/java/com/ruoyi/tms/service/impl/TmsQuoteDetailServiceImpl.java
@@ -2,8 +2,16 @@
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.enums.SystemDataNoEnum;
import com.ruoyi.common.utils.DateUtils;
import javax.annotation.Resource;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.service.ISystemDataNoService;
import com.ruoyi.tms.domain.TmsQuotePlan;
import com.ruoyi.tms.mapper.TmsQuotePlanMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;
import org.springframework.scheduling.annotation.Async;
@@ -34,7 +42,10 @@
    @Resource
    private TmsQuoteDetailMapper tmsQuoteDetailMapper;
    @Resource
    private TmsQuotePlanMapper tmsQuotePlanMapper;
    @Autowired
    ISystemDataNoService systemDataNoService;
    /**
     * 查询报价明细
     *
@@ -102,7 +113,47 @@
    @Override
    public int insertTmsQuoteDetail(TmsQuoteDetail tmsQuoteDetail)
    {
        Integer quotePlanId = tmsQuoteDetail.getQuotePlanId();
        if (quotePlanId == null){
            throw new RuntimeException("请先选择报价方案不能为空");
        }
        TmsQuotePlan tmsQuotePlan = tmsQuotePlanMapper.selectTmsQuotePlanById(quotePlanId);
        if (tmsQuotePlan == null){
            throw new RuntimeException("报价方案不存在");
        }
        // 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、不同报价方案,不能添加相同【客户-路线-车型】数据
        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("不同报价方案,不能添加相同【客户-路线-车型】数据");
        }
        tmsQuoteDetail.setQuotePlanCode(tmsQuotePlan.getSystemCode());
        tmsQuoteDetail.setCustomerId(tmsQuotePlan.getCustomerId());
        SystemDataNoEnum systemDataNoEnum = tmsQuotePlan.getPlanType() == 1 ? SystemDataNoEnum.YF : SystemDataNoEnum.YS;
        String noByKey = systemDataNoService.getNoByKey(systemDataNoEnum);
        tmsQuoteDetail.setSystemCode(noByKey);
        tmsQuoteDetail.setCreateBy(SecurityUtils.getUsername());
        tmsQuoteDetail.setCreateTime(DateUtils.getNowDate());
        tmsQuoteDetail.setPlanType(tmsQuotePlan.getPlanType());
        tmsQuoteDetail.setCustomerId(tmsQuotePlan.getCustomerId());
        return tmsQuoteDetailMapper.insertTmsQuoteDetail(tmsQuoteDetail);
    }
@@ -119,6 +170,7 @@
        return rows;
    }
    /**
     * 修改报价明细
     *
@@ -128,6 +180,38 @@
    @Override
    public int updateTmsQuoteDetail(TmsQuoteDetail tmsQuoteDetail)
    {
        Integer quotePlanId = tmsQuoteDetail.getQuotePlanId();
        if (quotePlanId == null){
            throw new RuntimeException("请先选择报价方案不能为空");
        }
        TmsQuotePlan tmsQuotePlan = tmsQuotePlanMapper.selectTmsQuotePlanById(quotePlanId);
        if (tmsQuotePlan == null){
            throw new RuntimeException("报价方案不存在");
        }
        // 1、同一报价清单,不能添加相同【路线-车型】数据
        Long l = tmsQuoteDetailMapper.selectCount(new LambdaQueryWrapper<TmsQuoteDetail>()
                .eq(TmsQuoteDetail::getQuotePlanId, quotePlanId)
                .eq(TmsQuoteDetail::getVehicleType, tmsQuoteDetail.getVehicleType())
                .eq(TmsQuoteDetail::getTransportRoute, tmsQuoteDetail.getTransportRoute())
                .ne(TmsQuoteDetail::getId, tmsQuoteDetail.getId())
        );
        if (l > 0){
            throw new RuntimeException("同一报价清单,不能添加相同【路线-车型】数据");
        }
        // 2、不同报价方案,不能添加相同【客户-路线-车型】数据
        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("不同报价方案,不能添加相同【客户-路线-车型】数据");
        }
        tmsQuoteDetail.setUpdateBy(SecurityUtils.getUsername());
        tmsQuoteDetail.setUpdateTime(DateUtils.getNowDate());
        return tmsQuoteDetailMapper.updateTmsQuoteDetail(tmsQuoteDetail);
    }