|
@@ -0,0 +1,311 @@
|
|
|
+package com.fjhx.sale.service.ext.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fjhx.area.utils.CustomizeAreaUtil;
|
|
|
+import com.fjhx.common.enums.FlowStatusEnum1;
|
|
|
+import com.fjhx.common.utils.Utils;
|
|
|
+import com.fjhx.customer.entity.customer.po.Customer;
|
|
|
+import com.fjhx.customer.service.customer.CustomerService;
|
|
|
+import com.fjhx.item.service.product.ProductInfoService;
|
|
|
+import com.fjhx.sale.entity.ext.dto.ExtQuotationDto;
|
|
|
+import com.fjhx.sale.entity.ext.dto.ExtQuotationProductBomDto;
|
|
|
+import com.fjhx.sale.entity.ext.dto.ExtQuotationProductDto;
|
|
|
+import com.fjhx.sale.entity.ext.dto.ExtQuotationSelectDto;
|
|
|
+import com.fjhx.sale.entity.ext.po.ExtQuotation;
|
|
|
+import com.fjhx.sale.entity.ext.po.ExtQuotationFollow;
|
|
|
+import com.fjhx.sale.entity.ext.po.ExtQuotationProduct;
|
|
|
+import com.fjhx.sale.entity.ext.po.ExtQuotationProductBom;
|
|
|
+import com.fjhx.sale.entity.ext.vo.ExtQuotationProductBomVo;
|
|
|
+import com.fjhx.sale.entity.ext.vo.ExtQuotationProductVo;
|
|
|
+import com.fjhx.sale.entity.ext.vo.ExtQuotationVo;
|
|
|
+import com.fjhx.sale.entity.sale.po.SaleQuotation;
|
|
|
+import com.fjhx.sale.mapper.ext.ExtQuotationMapper;
|
|
|
+import com.fjhx.sale.service.ext.ExtQuotationFollowService;
|
|
|
+import com.fjhx.sale.service.ext.ExtQuotationProductBomService;
|
|
|
+import com.fjhx.sale.service.ext.ExtQuotationProductService;
|
|
|
+import com.fjhx.sale.service.ext.ExtQuotationService;
|
|
|
+import com.ruoyi.common.core.domain.entity.SysDept;
|
|
|
+import com.ruoyi.common.exception.ServiceException;
|
|
|
+import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
+import com.ruoyi.system.service.ISysDeptService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 对外报价单 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author
|
|
|
+ * @since 2024-01-14
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class ExtQuotationServiceImpl extends ServiceImpl<ExtQuotationMapper, ExtQuotation> implements ExtQuotationService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CustomerService customerService;
|
|
|
+ @Autowired
|
|
|
+ private ProductInfoService productInfoService;
|
|
|
+ @Autowired
|
|
|
+ private ISysDeptService sysDeptService;
|
|
|
+ @Autowired
|
|
|
+ private ExtQuotationProductService extQuotationProductService;
|
|
|
+ @Autowired
|
|
|
+ private ExtQuotationProductBomService extQuotationProductBomService;
|
|
|
+ @Autowired
|
|
|
+ private ExtQuotationFollowService extQuotationFollowService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<ExtQuotationVo> getPage(ExtQuotationSelectDto dto) {
|
|
|
+ IWrapper<ExtQuotation> wrapper = getWrapper();
|
|
|
+ wrapper.orderByDesc("eq", ExtQuotation::getId);
|
|
|
+
|
|
|
+ //报价状态
|
|
|
+ wrapper.eq(SaleQuotation::getQuotationStatus, dto.getQuotationStatus());
|
|
|
+ //报价公司
|
|
|
+ wrapper.eq(SaleQuotation::getCompanyId, dto.getCompanyId());
|
|
|
+ //报价单类型
|
|
|
+ wrapper.eq(SaleQuotation::getType, dto.getType());
|
|
|
+
|
|
|
+ //报价时间-时间范围过滤
|
|
|
+ wrapper.ge("eq", ExtQuotation::getQuotationTime, dto.getQuotationTimeSta());
|
|
|
+ wrapper.le("eq", ExtQuotation::getQuotationTime, dto.getQuotationTimeEnd());
|
|
|
+ //创建时间-时间范围过滤
|
|
|
+ wrapper.ge("eq", ExtQuotation::getCreateTime, dto.getBeginTime());
|
|
|
+ wrapper.le("eq", ExtQuotation::getCreateTime, dto.getEndTime());
|
|
|
+
|
|
|
+ wrapper.ne("eq", ExtQuotation::getStatus, FlowStatusEnum1.UPDATE);
|
|
|
+ wrapper.ne("eq", ExtQuotation::getStatus, dto.getStatus());
|
|
|
+
|
|
|
+ Page<ExtQuotationVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
|
|
|
+ List<ExtQuotationVo> records = page.getRecords();
|
|
|
+
|
|
|
+ if (ObjectUtil.isEmpty(records)) {
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 赋值买方公司名称(客户)
|
|
|
+ customerService.attributeAssign(records, ExtQuotationVo::getBuyCorporationId, (item, customer) -> {
|
|
|
+ item.setBuyCorporationName(customer.getName());
|
|
|
+ });
|
|
|
+
|
|
|
+ List<Long> companyIds = records.stream().map(ExtQuotation::getCompanyId).collect(Collectors.toList());
|
|
|
+ List<SysDept> companyList = sysDeptService.list(Wrappers.<SysDept>query().in("dept_id", companyIds));
|
|
|
+ Map<Long, String> companyMap = companyList.stream().collect(Collectors.toMap(SysDept::getDeptId, SysDept::getDeptName));
|
|
|
+
|
|
|
+ List<Long> ids = records.stream().map(ExtQuotationVo::getId).collect(Collectors.toList());
|
|
|
+ List<ExtQuotationProduct> pList = extQuotationProductService.list(q -> q.in(ExtQuotationProduct::getSaleQuotationId, ids));
|
|
|
+ List<ExtQuotationProductVo> quotationProductVos = BeanUtil.copyToList(pList, ExtQuotationProductVo.class);
|
|
|
+ //赋值产品信息
|
|
|
+ productInfoService.attributeAssign(quotationProductVos, ExtQuotationProductVo::getProductId, (item, productInfo) -> {
|
|
|
+ item.setProductCode(productInfo.getCustomCode());
|
|
|
+ item.setProductName(productInfo.getName());
|
|
|
+ });
|
|
|
+ Map<Long, List<ExtQuotationProductVo>> pMap = quotationProductVos.stream().collect(Collectors.groupingBy(ExtQuotationProduct::getSaleQuotationId));
|
|
|
+
|
|
|
+ //获取跟进记录Map
|
|
|
+ Map<Long, List<ExtQuotationFollow>> followMap = extQuotationFollowService.mapKGroup(ExtQuotationFollow::getQuotationId, q -> q
|
|
|
+ .in(ExtQuotationFollow::getQuotationId, ids)
|
|
|
+ .orderByDesc(ExtQuotationFollow::getFollowTime)
|
|
|
+ );
|
|
|
+
|
|
|
+ for (ExtQuotationVo saleQuotationVo : records) {
|
|
|
+ //赋值报价公司名称
|
|
|
+ saleQuotationVo.setCompanyName(companyMap.get(saleQuotationVo.getCompanyId()));
|
|
|
+
|
|
|
+ //赋值产品列表
|
|
|
+ saleQuotationVo.setQuotationProductList(pMap.get(saleQuotationVo.getId()));
|
|
|
+
|
|
|
+ //赋值跟进信息
|
|
|
+ List<ExtQuotationFollow> extQuotationFollows = followMap.get(saleQuotationVo.getId());
|
|
|
+ saleQuotationVo.setExtQuotationFollowList(extQuotationFollows);
|
|
|
+ }
|
|
|
+
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ExtQuotationVo detail(Long id) {
|
|
|
+ //查询报价表详情
|
|
|
+ ExtQuotation extQuotation = this.getById(id);
|
|
|
+ ExtQuotationVo result = BeanUtil.toBean(extQuotation, ExtQuotationVo.class);
|
|
|
+ if (ObjectUtil.isEmpty(result)) {
|
|
|
+ throw new ServiceException("查询不到明细信息请检查");
|
|
|
+ }
|
|
|
+ //赋值买方公司名称(客户)
|
|
|
+ Customer customer = customerService.getById(result.getBuyCorporationId());
|
|
|
+ if (ObjectUtil.isNotEmpty(customer)) {
|
|
|
+ result.setBuyCorporationName(customer.getName());
|
|
|
+ }
|
|
|
+
|
|
|
+ //赋值买方公司地址
|
|
|
+ setArea(result);
|
|
|
+ //查询报价-商品表的详情
|
|
|
+ List<ExtQuotationProduct> quotationProductList = extQuotationProductService.list(Wrappers.<ExtQuotationProduct>lambdaQuery()
|
|
|
+ .eq(ExtQuotationProduct::getSaleQuotationId, result.getId()));
|
|
|
+
|
|
|
+ List<ExtQuotationProductVo> quotationProductVos = BeanUtil.copyToList(quotationProductList, ExtQuotationProductVo.class);
|
|
|
+ //赋值产品信息
|
|
|
+ productInfoService.attributeAssign(quotationProductVos, ExtQuotationProductVo::getProductId, (item, productInfo) -> {
|
|
|
+ item.setProductCode(productInfo.getCustomCode());
|
|
|
+ item.setProductName(productInfo.getName());
|
|
|
+ item.setProductLength(productInfo.getLength());
|
|
|
+ item.setProductWidth(productInfo.getWidth());
|
|
|
+ item.setProductHeight(productInfo.getHeight());
|
|
|
+ item.setProductProdImgPath(productInfo.getProdImgPath());
|
|
|
+ });
|
|
|
+
|
|
|
+ //获取配件列表
|
|
|
+ List<Long> ids = quotationProductVos.stream().map(ExtQuotationProduct::getId).collect(Collectors.toList());
|
|
|
+ List<ExtQuotationProductBom> list = extQuotationProductBomService.list(q -> q.in(ExtQuotationProductBom::getQuotationProductId, ids));
|
|
|
+ List<ExtQuotationProductBomVo> quotationProductBomVos = BeanUtil.copyToList(list, ExtQuotationProductBomVo.class);
|
|
|
+ //赋值产品信息
|
|
|
+ productInfoService.attributeAssign(quotationProductBomVos, ExtQuotationProductBom::getProductId, (item, productInfo) -> {
|
|
|
+ item.setProductCode(productInfo.getCustomCode());
|
|
|
+ item.setProductName(productInfo.getName());
|
|
|
+ item.setProductLength(productInfo.getLength());
|
|
|
+ item.setProductWidth(productInfo.getWidth());
|
|
|
+ item.setProductHeight(productInfo.getHeight());
|
|
|
+ });
|
|
|
+
|
|
|
+ Map<Long, List<ExtQuotationProductBomVo>> qpbMap = quotationProductBomVos.stream().collect(Collectors.groupingBy(ExtQuotationProductBom::getQuotationProductId));
|
|
|
+
|
|
|
+ for (ExtQuotationProductVo quotationProductVo : quotationProductVos) {
|
|
|
+ quotationProductVo.setQuotationProductBomList(qpbMap.get(quotationProductVo.getId()));
|
|
|
+ }
|
|
|
+ result.setQuotationProductList(quotationProductVos);
|
|
|
+
|
|
|
+ //赋值报价金额趋势
|
|
|
+ List<ExtQuotation> quotationTrendList = this.list(q -> q
|
|
|
+ .eq(ExtQuotation::getGroupId, result.getGroupId())
|
|
|
+ .ne(ExtQuotation::getStatus, FlowStatusEnum1.CANCELLATION.getKey())
|
|
|
+ .orderByAsc(ExtQuotation::getCreateTime)
|
|
|
+ );
|
|
|
+ result.setQuotationTrendList(quotationTrendList);
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @DSTransactional
|
|
|
+ public void add(ExtQuotationDto saleQuotationDto) {
|
|
|
+ long id = IdWorker.getId();
|
|
|
+ saleQuotationDto.setId(id);
|
|
|
+ saleQuotationDto.setGroupId(id);//赋值数据分组id
|
|
|
+ saleQuotationDto.setStatus(30);
|
|
|
+ saveOrEdit(saleQuotationDto);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @DSTransactional
|
|
|
+ public void edit(ExtQuotationDto saleQuotationDto) {
|
|
|
+ if (Objects.equals(saleQuotationDto.getQuotationStatus(), 2)) {
|
|
|
+ saleQuotationDto.setQuotationTime(new Date());
|
|
|
+ }
|
|
|
+ saveOrEdit(saleQuotationDto);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void delete(Long id) {
|
|
|
+ this.removeById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 变更
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void changeSaleQuotation(ExtQuotationDto saleQuotationDto) {
|
|
|
+ ExtQuotation saleQuotation = this.getById(saleQuotationDto.getId());
|
|
|
+ if (ObjectUtil.isEmpty(saleQuotation)) {
|
|
|
+ throw new ServiceException("查询不到原报价单信息");
|
|
|
+ }
|
|
|
+ saleQuotation.setStatus(FlowStatusEnum1.UPDATE.getKey());
|
|
|
+ this.updateById(saleQuotation);
|
|
|
+
|
|
|
+ saleQuotationDto.setOldQuotationId(saleQuotation.getId());
|
|
|
+
|
|
|
+ //变更清除id信息
|
|
|
+ saleQuotationDto.setId(null);
|
|
|
+ saleQuotationDto.setStatus(30);
|
|
|
+ saleQuotationDto.setQuotationStatus(0);
|
|
|
+ saleQuotationDto.setCode(Utils.getNewCode(saleQuotation.getCode()));//赋值新合同号
|
|
|
+ List<ExtQuotationProductDto> quotationProductList = saleQuotationDto.getQuotationProductList();
|
|
|
+ for (ExtQuotationProductDto quotationProductDto : quotationProductList) {
|
|
|
+ quotationProductDto.setId(null);
|
|
|
+ List<ExtQuotationProductBomDto> quotationProductBomList = quotationProductDto.getQuotationProductBomList();
|
|
|
+ for (ExtQuotationProductBomDto quotationProductBomDto : quotationProductBomList) {
|
|
|
+ quotationProductBomDto.setId(null);
|
|
|
+ }
|
|
|
+ quotationProductDto.setQuotationProductBomList(quotationProductBomList);
|
|
|
+ }
|
|
|
+ saleQuotationDto.setQuotationProductList(quotationProductList);
|
|
|
+ //调用创建方法
|
|
|
+ saveOrEdit(saleQuotationDto);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 作废
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void cancellation(Long id) {
|
|
|
+ ExtQuotation saleQuotation = this.getById(id);
|
|
|
+ saleQuotation.setStatus(FlowStatusEnum1.CANCELLATION.getKey());
|
|
|
+ this.updateById(saleQuotation);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 赋值买卖公司地址
|
|
|
+ */
|
|
|
+ private void setArea(ExtQuotationVo saleQuotationVo) {
|
|
|
+
|
|
|
+ List<Long> areaIdList = Arrays.asList(
|
|
|
+ saleQuotationVo.getBuyCountryId(),
|
|
|
+ saleQuotationVo.getBuyProvinceId(),
|
|
|
+ saleQuotationVo.getBuyCityId()
|
|
|
+ );
|
|
|
+ Map<Long, String> areaMap = CustomizeAreaUtil.getAreaMapByIds(areaIdList);
|
|
|
+ saleQuotationVo.setBuyCountryName(areaMap.get(saleQuotationVo.getBuyCountryId()));
|
|
|
+ saleQuotationVo.setBuyProvinceName(areaMap.get(saleQuotationVo.getBuyProvinceId()));
|
|
|
+ saleQuotationVo.setBuyCityName(areaMap.get(saleQuotationVo.getBuyCityId()));
|
|
|
+ saleQuotationVo.setBuyDetailedAddress(saleQuotationVo.getBuyAddress());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加修改公共方法
|
|
|
+ */
|
|
|
+ private void saveOrEdit(ExtQuotationDto saleQuotationDto) {
|
|
|
+ this.saveOrUpdate(saleQuotationDto);
|
|
|
+
|
|
|
+ List<ExtQuotationProductDto> quotationProductList = saleQuotationDto.getQuotationProductList();
|
|
|
+ for (ExtQuotationProductDto quotationProductDto : quotationProductList) {
|
|
|
+ //手动创建id
|
|
|
+ if (ObjectUtil.isEmpty(quotationProductDto.getId())) {
|
|
|
+ quotationProductDto.setId(IdWorker.getId());
|
|
|
+ }
|
|
|
+ quotationProductDto.setSaleQuotationId(saleQuotationDto.getId());
|
|
|
+
|
|
|
+ //保存配件
|
|
|
+ List<ExtQuotationProductBom> quotationProductBomList = BeanUtil.copyToList(quotationProductDto.getQuotationProductBomList(), ExtQuotationProductBom.class);
|
|
|
+ for (ExtQuotationProductBom quotationProductBom : quotationProductBomList) {
|
|
|
+ quotationProductBom.setProductId(quotationProductDto.getProductId());
|
|
|
+ quotationProductBom.setQuotationProductId(quotationProductDto.getId());
|
|
|
+ }
|
|
|
+ extQuotationProductBomService.editLinked(quotationProductBomList, ExtQuotationProductBom::getQuotationProductId, quotationProductDto.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ List<ExtQuotationProduct> quotationProducts = BeanUtil.copyToList(quotationProductList, ExtQuotationProduct.class);
|
|
|
+ extQuotationProductService.editLinked(quotationProducts, ExtQuotationProduct::getSaleQuotationId, saleQuotationDto.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+}
|