package com.ruoyi.tms.service.impl; 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; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.ruoyi.common.utils.PageUtils; import com.ruoyi.common.constant.Constants; import com.ruoyi.common.annotation.DataSource; import com.ruoyi.common.enums.DataSourceType; import com.ruoyi.common.core.service.BaseService; import com.ruoyi.tms.mapper.TmsQuoteDetailMapper; import com.ruoyi.tms.domain.TmsQuoteDetail; import com.ruoyi.tms.service.ITmsQuoteDetailService; import com.ruoyi.common.core.text.Convert; /** * 报价明细Service业务层处理 * * @author ruoyi * @date 2025-11-12 */ @Service @Transactional(rollbackFor = Exception.class) public class TmsQuoteDetailServiceImpl extends BaseService implements ITmsQuoteDetailService { protected final Logger logger = LoggerFactory.getLogger(getClass()); @Resource private TmsQuoteDetailMapper tmsQuoteDetailMapper; @Resource private TmsQuotePlanMapper tmsQuotePlanMapper; @Autowired ISystemDataNoService systemDataNoService; /** * 查询报价明细 * * @param id 报价明细ID * @return 报价明细 */ @DataSource(DataSourceType.SLAVE) @Override public TmsQuoteDetail selectTmsQuoteDetailById(Integer id) { return tmsQuoteDetailMapper.selectTmsQuoteDetailById(id); } /** * 查询报价明细 记录数 * * @param tmsQuoteDetail 报价明细 * @return 报价明细集合 */ @DataSource(DataSourceType.SLAVE) @Override public int selectTmsQuoteDetailCount(TmsQuoteDetail tmsQuoteDetail) { return tmsQuoteDetailMapper.selectTmsQuoteDetailCount(tmsQuoteDetail); } /** * 查询报价明细列表 * * @param tmsQuoteDetail 报价明细 * @return 报价明细 */ @DataSource(DataSourceType.SLAVE) @Override public List selectTmsQuoteDetailList(TmsQuoteDetail tmsQuoteDetail) { return tmsQuoteDetailMapper.selectTmsQuoteDetailList(tmsQuoteDetail); } /** * 查询报价明细列表 异步 导出 * * @param tmsQuoteDetail 报价明细 * @param exportKey 导出功能的唯一标识 * @return 报价明细集合 */ @DataSource(DataSourceType.SLAVE) @Async @Override public void export(TmsQuoteDetail tmsQuoteDetail,String exportKey) { super.export(TmsQuoteDetail.class,exportKey,"tmsQuoteDetailData",(pageNum)->{ PageUtils.startPage(pageNum, Constants.EXPORT_PATE_SIZE); return selectTmsQuoteDetailList(tmsQuoteDetail); }); } /** * 新增报价明细 * * @param tmsQuoteDetail 报价明细 * @return 结果 */ @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() .eq(TmsQuoteDetail::getQuotePlanId, quotePlanId) .eq(TmsQuoteDetail::getVehicleType, tmsQuoteDetail.getVehicleType()) .eq(TmsQuoteDetail::getTransportRoute, tmsQuoteDetail.getTransportRoute()) ); if (l > 0){ throw new RuntimeException("同一报价清单,不能添加相同【路线-车型】数据"); } // 2、不同报价方案,不能添加相同【客户-路线-车型】数据 int l1 = tmsQuoteDetailMapper.countSameCustomerRouteVehicle(new TmsQuoteDetail(){{ setQuotePlanId(quotePlanId); setCustomerId(tmsQuotePlan.getCustomerId()); setTransportRoute(tmsQuoteDetail.getTransportRoute()); setVehicleType(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()); return tmsQuoteDetailMapper.insertTmsQuoteDetail(tmsQuoteDetail); } /** * 新增报价明细[批量] * * @param tmsQuoteDetails 报价明细 * @return 结果 */ @Override public int insertTmsQuoteDetailBatch(List tmsQuoteDetails) { int rows = tmsQuoteDetailMapper.insertTmsQuoteDetailBatch(tmsQuoteDetails); return rows; } /** * 修改报价明细 * * @param tmsQuoteDetail 报价明细 * @return 结果 */ @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() .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、不同报价方案,不能添加相同【客户-路线-车型】数据 int l1 = tmsQuoteDetailMapper.countSameCustomerRouteVehicle(new TmsQuoteDetail(){{ setQuotePlanId(quotePlanId); setCustomerId(tmsQuotePlan.getCustomerId()); setTransportRoute(tmsQuoteDetail.getTransportRoute()); setVehicleType(tmsQuoteDetail.getVehicleType()); setId(tmsQuoteDetail.getId()); }}); if (l1 > 0){ throw new RuntimeException("不同报价方案,不能添加相同【客户-路线-车型】数据"); } tmsQuoteDetail.setUpdateBy(SecurityUtils.getUsername()); tmsQuoteDetail.setUpdateTime(DateUtils.getNowDate()); return tmsQuoteDetailMapper.updateTmsQuoteDetail(tmsQuoteDetail); } /** * 修改报价明细[批量] * * @param tmsQuoteDetails 报价明细 * @return 结果 */ @Override public int updateTmsQuoteDetailBatch(List tmsQuoteDetails){ return tmsQuoteDetailMapper.updateTmsQuoteDetailBatch(tmsQuoteDetails); } /** * 删除报价明细对象 * * @param ids 需要删除的数据ID * @return 结果 */ @Override public int deleteTmsQuoteDetailByIds(String ids) { return deleteTmsQuoteDetailByIds(Convert.toIntArray(ids)); } /** * 删除报价明细对象 * * * @param ids 需要删除的数据ID * @return 结果 */ @Override public int deleteTmsQuoteDetailByIds(Integer[] ids) { return tmsQuoteDetailMapper.deleteTmsQuoteDetailByIds(ids); } /** * 删除报价明细信息 * * @param id 报价明细ID * @return 结果 */ @Override public int deleteTmsQuoteDetailById(Integer id) { return tmsQuoteDetailMapper.deleteTmsQuoteDetailById(id); } }