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;
|
import javax.annotation.Resource;
|
|
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;
|
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.TmsQuotePlanMapper;
|
import com.ruoyi.tms.domain.TmsQuotePlan;
|
import com.ruoyi.tms.service.ITmsQuotePlanService;
|
import com.ruoyi.common.core.text.Convert;
|
|
/**
|
* 报价方案管理Service业务层处理
|
*
|
* @author ruoyi
|
* @date 2025-11-11
|
*/
|
@Service
|
@Transactional(rollbackFor = Exception.class)
|
public class TmsQuotePlanServiceImpl extends BaseService<TmsQuotePlanMapper, TmsQuotePlan> implements ITmsQuotePlanService
|
{
|
protected final Logger logger = LoggerFactory.getLogger(getClass());
|
@Resource
|
private TmsQuotePlanMapper tmsQuotePlanMapper;
|
@Autowired
|
private ITmsQuoteItemService tmsQuoteItemService;
|
|
@Autowired
|
ISystemDataNoService systemDataNoService;
|
/**
|
* 查询报价方案管理
|
*
|
* @param id 报价方案管理ID
|
* @return 报价方案管理
|
*/
|
@DataSource(DataSourceType.SLAVE)
|
@Override
|
public TmsQuotePlan selectTmsQuotePlanById(Integer id)
|
{
|
TmsQuotePlan tmsQuotePlan = tmsQuotePlanMapper.selectTmsQuotePlanById(id);
|
tmsQuotePlan.setQuoteItems(tmsQuoteItemService.selectTmsQuoteItemList(new TmsQuoteItem(){{setQuotePlanId(id);}}));
|
return tmsQuotePlan;
|
}
|
|
/**
|
* 查询报价方案管理 记录数
|
*
|
* @param tmsQuotePlan 报价方案管理
|
* @return 报价方案管理集合
|
*/
|
@DataSource(DataSourceType.SLAVE)
|
@Override
|
public int selectTmsQuotePlanCount(TmsQuotePlan tmsQuotePlan)
|
{
|
return tmsQuotePlanMapper.selectTmsQuotePlanCount(tmsQuotePlan);
|
}
|
|
/**
|
* 查询报价方案管理列表
|
*
|
* @param tmsQuotePlan 报价方案管理
|
* @return 报价方案管理
|
*/
|
@DataSource(DataSourceType.SLAVE)
|
@Override
|
public List<TmsQuotePlan> selectTmsQuotePlanList(TmsQuotePlan tmsQuotePlan)
|
{
|
return tmsQuotePlanMapper.selectTmsQuotePlanList(tmsQuotePlan);
|
}
|
|
/**
|
* 查询报价方案管理列表 异步 导出
|
*
|
* @param tmsQuotePlan 报价方案管理
|
* @param exportKey 导出功能的唯一标识
|
* @return 报价方案管理集合
|
*/
|
@DataSource(DataSourceType.SLAVE)
|
@Async
|
@Override
|
public void export(TmsQuotePlan tmsQuotePlan,String exportKey) {
|
|
super.export(TmsQuotePlan.class,exportKey,"tmsQuotePlanData",(pageNum)->{
|
PageUtils.startPage(pageNum, Constants.EXPORT_PATE_SIZE);
|
return selectTmsQuotePlanList(tmsQuotePlan);
|
});
|
}
|
|
|
/**
|
* 新增报价方案管理
|
*
|
* @param tmsQuotePlan 报价方案管理
|
* @return 结果
|
*/
|
@Override
|
public int insertTmsQuotePlan(TmsQuotePlan tmsQuotePlan)
|
{
|
SystemDataNoEnum systemDataNoEnum = tmsQuotePlan.getPlanType() == 1 ? SystemDataNoEnum.YF : SystemDataNoEnum.YS;
|
String noByKey = systemDataNoService.getNoByKey(systemDataNoEnum);
|
tmsQuotePlan.setSystemCode(noByKey);
|
tmsQuotePlan.setCreateBy(SecurityUtils.getUsername());
|
tmsQuotePlan.setCreateTime(DateUtils.getNowDate());
|
tmsQuotePlanMapper.insertTmsQuotePlan(tmsQuotePlan);
|
|
List<TmsQuoteItem> quoteItems = tmsQuotePlan.getQuoteItems();
|
if (quoteItems != null && !quoteItems.isEmpty()){
|
quoteItems.forEach(tmsQuoteItem -> {
|
tmsQuoteItem.setQuotePlanId(tmsQuotePlan.getId());
|
});
|
tmsQuoteItemService.insertTmsQuoteItemBatch(quoteItems);
|
}else{
|
throw new RuntimeException("请至少选择一个报价方案");
|
}
|
return 1;
|
}
|
|
/**
|
* 新增报价方案管理[批量]
|
*
|
* @param tmsQuotePlans 报价方案管理
|
* @return 结果
|
*/
|
@Override
|
public int insertTmsQuotePlanBatch(List<TmsQuotePlan> tmsQuotePlans)
|
{
|
int rows = tmsQuotePlanMapper.insertTmsQuotePlanBatch(tmsQuotePlans);
|
return rows;
|
}
|
|
/**
|
* 修改报价方案管理
|
*
|
* @param tmsQuotePlan 报价方案管理
|
* @return 结果
|
*/
|
@Override
|
public int updateTmsQuotePlan(TmsQuotePlan tmsQuotePlan)
|
{
|
tmsQuotePlan.setUpdateBy(SecurityUtils.getUsername());
|
tmsQuotePlan.setUpdateTime(DateUtils.getNowDate());
|
int i = tmsQuotePlanMapper.updateTmsQuotePlan(tmsQuotePlan);
|
|
|
if (tmsQuotePlan.getPlanType() == 0){
|
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);
|
}
|
|
|
}else{
|
throw new RuntimeException("请至少选择一个报价方案");
|
}
|
}
|
return i;
|
}
|
|
/**
|
* 修改报价方案管理[批量]
|
*
|
* @param tmsQuotePlans 报价方案管理
|
* @return 结果
|
*/
|
@Override
|
public int updateTmsQuotePlanBatch(List<TmsQuotePlan> tmsQuotePlans){
|
return tmsQuotePlanMapper.updateTmsQuotePlanBatch(tmsQuotePlans);
|
}
|
|
/**
|
* 删除报价方案管理对象
|
*
|
* @param ids 需要删除的数据ID
|
* @return 结果
|
*/
|
@Override
|
public int deleteTmsQuotePlanByIds(String ids)
|
{
|
return deleteTmsQuotePlanByIds(Convert.toIntArray(ids));
|
}
|
|
/**
|
* 删除报价方案管理对象
|
*
|
*
|
* @param ids 需要删除的数据ID
|
* @return 结果
|
*/
|
@Override
|
public int deleteTmsQuotePlanByIds(Integer[] ids)
|
{
|
return tmsQuotePlanMapper.deleteTmsQuotePlanByIds(ids);
|
}
|
|
/**
|
* 删除报价方案管理信息
|
*
|
* @param id 报价方案管理ID
|
* @return 结果
|
*/
|
@Override
|
public int deleteTmsQuotePlanById(Integer id)
|
{
|
return tmsQuotePlanMapper.deleteTmsQuotePlanById(id);
|
}
|
}
|