|
@@ -1,12 +1,19 @@
|
|
package com.fjhx.sale.service.sale.impl;
|
|
package com.fjhx.sale.service.sale.impl;
|
|
|
|
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
+import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
+import com.fjhx.account.controller.utils.DateUtils;
|
|
|
|
+import com.fjhx.common.constant.SourceConstant;
|
|
|
|
+import com.fjhx.customer.entity.customer.dto.CustomerDto;
|
|
|
|
+import com.fjhx.sale.entity.contract.vo.ContractVo;
|
|
import com.fjhx.sale.entity.quotation.po.QuotationPay;
|
|
import com.fjhx.sale.entity.quotation.po.QuotationPay;
|
|
import com.fjhx.sale.entity.quotation.po.QuotationProduct;
|
|
import com.fjhx.sale.entity.quotation.po.QuotationProduct;
|
|
import com.fjhx.sale.entity.sale.po.SaleQuotation;
|
|
import com.fjhx.sale.entity.sale.po.SaleQuotation;
|
|
import com.fjhx.sale.mapper.sale.SaleQuotationMapper;
|
|
import com.fjhx.sale.mapper.sale.SaleQuotationMapper;
|
|
|
|
+import com.fjhx.sale.service.contract.ContractService;
|
|
import com.fjhx.sale.service.quotation.QuotationPayService;
|
|
import com.fjhx.sale.service.quotation.QuotationPayService;
|
|
import com.fjhx.sale.service.quotation.QuotationProductService;
|
|
import com.fjhx.sale.service.quotation.QuotationProductService;
|
|
import com.fjhx.sale.service.sale.SaleQuotationService;
|
|
import com.fjhx.sale.service.sale.SaleQuotationService;
|
|
@@ -24,7 +31,9 @@ import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
import com.fjhx.sale.entity.sale.dto.SaleQuotationDto;
|
|
import com.fjhx.sale.entity.sale.dto.SaleQuotationDto;
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -43,6 +52,10 @@ public class SaleQuotationServiceImpl extends ServiceImpl<SaleQuotationMapper, S
|
|
@Autowired
|
|
@Autowired
|
|
private QuotationPayService quotationPayService;
|
|
private QuotationPayService quotationPayService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private ContractService contractService;
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 报价表分页
|
|
* 报价表分页
|
|
*/
|
|
*/
|
|
@@ -137,4 +150,117 @@ public class SaleQuotationServiceImpl extends ServiceImpl<SaleQuotationMapper, S
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 查询这个客户的报价次数
|
|
|
|
+ * @param id (客户ID)
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public Integer getCount(Long id) {
|
|
|
|
+ return baseMapper.getCount(id);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 查询指定客户的每月报价总额
|
|
|
|
+ * @param dto
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public List<SaleQuotationVo> getAmount(CustomerDto dto) {
|
|
|
|
+ return baseMapper.getAmount(dto);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 最新跟进(客户画像)
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public List<Map<String,Object>> latestFollowUp(CustomerDto dto) {
|
|
|
|
+
|
|
|
|
+// //切换数据源
|
|
|
|
+// DynamicDataSourceContextHolder.push(SourceConstant.SALE);
|
|
|
|
+// //查询这个客户的报价列表
|
|
|
|
+// saleQuotationService.page(,Wrappers.<SaleQuotation>lambdaQuery()
|
|
|
|
+// .eq(SaleQuotation::getBuyCorporationId,dto.getId()).orderByDesc(SaleQuotation::getCreateTime));
|
|
|
|
+//
|
|
|
|
+// //查询客户的合同列表
|
|
|
|
+// contractService.list();
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 销售统计(客户画像)
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public Map<String, Object> salesStatistics(CustomerDto dto) {
|
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
|
+ //切换数据源
|
|
|
|
+ DynamicDataSourceContextHolder.push(SourceConstant.SALE);
|
|
|
|
+ //查询这个客户的销售额(合同总金额)及成交合同数量
|
|
|
|
+ ContractVo contractVo = contractService.getSalesTotal(dto.getId());
|
|
|
|
+ map.put("contractVo",contractVo);
|
|
|
|
+
|
|
|
|
+ //查询这个客户的报价次数
|
|
|
|
+ Integer count = this.getCount(dto.getId());
|
|
|
|
+ DynamicDataSourceContextHolder.poll();
|
|
|
|
+ map.put("count",count);
|
|
|
|
+ return map;
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * 报价销售走势(客户画像)
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public Map<String, Object> salesTrend(CustomerDto dto) {
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
+
|
|
|
|
+ List<String> monthBetweenDate = DateUtils.getMonthBetweenDate(DateUtil.offsetMonth(new Date(), -12), new Date());
|
|
|
|
+
|
|
|
|
+ //存放报价的数据;
|
|
|
|
+ List<Map<String,Object>> saleQuotationList = new ArrayList<>();
|
|
|
|
+ //存放报价的数据;
|
|
|
|
+ List<Map<String,Object>> contractList = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ dto.setBeginTime(DateUtil.format(DateUtil.offsetMonth(new Date(), -12),"yy-MM"));
|
|
|
|
+ dto.setEndTime(DateUtil.format(new Date(),"yy-MM"));
|
|
|
|
+ //查询指定客户的每月报价总额
|
|
|
|
+ List<SaleQuotationVo> saleQuotationVoList = this.getAmount(dto);
|
|
|
|
+
|
|
|
|
+ Map<String, List<SaleQuotationVo>> saleQuotationVoMap = saleQuotationVoList.stream()
|
|
|
|
+ .collect(Collectors.groupingBy(item->DateUtil.format(item.getCreateTime(),"yyyy-MM")));
|
|
|
|
+
|
|
|
|
+ //查询指定客户的每月合同总额
|
|
|
|
+ List<ContractVo> contractVoList = contractService.getAmount(dto);
|
|
|
|
+ Map<String, List<ContractVo>> contractVoMap = contractVoList.stream()
|
|
|
|
+ .collect(Collectors.groupingBy(item->DateUtil.format(item.getCreateTime(),"yyyy-MM")));
|
|
|
|
+
|
|
|
|
+ //赋值每个月的值
|
|
|
|
+ for (String month : monthBetweenDate) {
|
|
|
|
+ //存放每月的报价总额
|
|
|
|
+ Map<String,Object> saleQuotationMap = new HashMap<>();
|
|
|
|
+ //每月的金额初始化的值为0
|
|
|
|
+ saleQuotationMap.put("month",month);
|
|
|
|
+ saleQuotationMap.put("saleAmount",new BigDecimal(0));
|
|
|
|
+ List<SaleQuotationVo> saleQuotationVos = saleQuotationVoMap.get(month);
|
|
|
|
+ //给每月的报价金额赋值
|
|
|
|
+ if (ObjectUtil.isNotEmpty(saleQuotationVos)){
|
|
|
|
+ saleQuotationMap.put("saleAmount",saleQuotationVos.get(0).getAmount());
|
|
|
|
+ }
|
|
|
|
+ saleQuotationList.add(saleQuotationMap);
|
|
|
|
+
|
|
|
|
+ //存放每月的合同总额
|
|
|
|
+ Map<String,Object> contractMap = new HashMap<>();
|
|
|
|
+ //每月的金额初始化的值为0
|
|
|
|
+ contractMap.put("month",month);
|
|
|
|
+ contractMap.put("contractAmount",new BigDecimal(0));
|
|
|
|
+ List<ContractVo> contractVoList1 = contractVoMap.get(month);
|
|
|
|
+ if (ObjectUtil.isNotEmpty(contractVoList1)){
|
|
|
|
+ contractMap.put("contractAmount",contractVoList1.get(0).getAmount());
|
|
|
|
+ }
|
|
|
|
+ contractList.add(contractMap);
|
|
|
|
+ }
|
|
|
|
+ map.put("contractList",contractList);
|
|
|
|
+ map.put("saleQuotationList",saleQuotationList);
|
|
|
|
+ return map;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|