SaleClueInfoServiceImpl.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. package com.ruixuan.salesLeads.service.impl;
  2. import com.alibaba.excel.EasyExcel;
  3. import com.github.pagehelper.PageInfo;
  4. import com.ruixuan.common.core.domain.ResultResponse;
  5. import com.ruixuan.common.core.page.TableDataInfo;
  6. import com.ruixuan.common.utils.DateUtils;
  7. import com.ruixuan.common.utils.PageUtils;
  8. import com.ruixuan.common.utils.StringUtils;
  9. import com.ruixuan.common.utils.file.FileTypeUtils;
  10. import com.ruixuan.salesLeads.listener.ImportExcelListener;
  11. import com.ruixuan.salesLeads.mapper.SaleClueDistributionInfoMapper;
  12. import com.ruixuan.salesLeads.mapper.SaleClueInfoMapper;
  13. import com.ruixuan.salesLeads.mapper.SaleClueRecordInfoMapper;
  14. import com.ruixuan.salesLeads.mapper.SaleQuotaInfoMapper;
  15. import com.ruixuan.salesLeads.pojo.SaleClueDistributionInfoPojo;
  16. import com.ruixuan.salesLeads.pojo.SaleClueInfoPojo;
  17. import com.ruixuan.salesLeads.pojo.SaleClueRecordInfoPojo;
  18. import com.ruixuan.salesLeads.pojo.SaleQuotaInfoPojo;
  19. import com.ruixuan.salesLeads.pojo.vo.SaleRecordVo;
  20. import com.ruixuan.salesLeads.pojo.vo.SaleTaskInfoVo;
  21. import com.ruixuan.salesLeads.service.ISaleClueInfoService;
  22. import com.ruixuan.salesLeads.utils.CsvImportUtil;
  23. import com.ruixuan.system.domain.SysAreaInfo;
  24. import com.ruixuan.system.domain.SysIndustryInfo;
  25. import com.ruixuan.system.mapper.SysAreaInfoMapper;
  26. import com.ruixuan.system.mapper.SysIndustryInfoMapper;
  27. import lombok.extern.slf4j.Slf4j;
  28. import org.springframework.beans.factory.annotation.Autowired;
  29. import org.springframework.stereotype.Service;
  30. import org.springframework.web.multipart.MultipartFile;
  31. import java.util.ArrayList;
  32. import java.util.HashMap;
  33. import java.util.List;
  34. import java.util.Map;
  35. /**
  36. * ***************************************************
  37. *
  38. * @Auther: zianY
  39. * @Descipion: demo测试
  40. * @CreateDate: 2022-05-19
  41. * ****************************************************
  42. */
  43. @Service
  44. @Slf4j
  45. public class SaleClueInfoServiceImpl implements ISaleClueInfoService {
  46. @Autowired
  47. private SaleClueInfoMapper saleClueInfoMapper;
  48. @Autowired
  49. private SaleQuotaInfoMapper saleQuotaInfoMapper;
  50. @Autowired
  51. private SysIndustryInfoMapper sysIndustryInfoMapper;
  52. @Autowired
  53. private SysAreaInfoMapper sysAreaInfoMapper;
  54. @Autowired
  55. private SaleClueRecordInfoMapper saleClueRecordInfoMapper;
  56. @Autowired
  57. private SaleClueDistributionInfoMapper saleClueDistributionInfoMapper;
  58. /**
  59. * Author: zianY
  60. * Description: 销售线索添加
  61. * 支持excel 和 csv 文件上传
  62. *------------
  63. * @param file
  64. * @param salesLeadsType 销售线索类型1:50W低潜;2:50W中高潜;3:200W高潜;4:200W-500w;5:500W
  65. * @param uploadDate 时间 格式为202205
  66. * @param createUserId
  67. *------------
  68. * Return com.ruixuan.common.core.domain.ResultResponse
  69. */
  70. @Override
  71. public ResultResponse importSaleExcelOrCsv(MultipartFile file, int salesLeadsType, Long uploadDate, Long createUserId){
  72. List<Map<String,String>> dataList = new ArrayList<>();
  73. //文件类型
  74. String fileType = FileTypeUtils.gerFileTypeXlsOrCsv(file);
  75. try {
  76. if (StringUtils.equals("excel",fileType)){
  77. //读取Excel
  78. EasyExcel.read(file.getInputStream(),null,
  79. new ImportExcelListener()).sheet().headRowNumber(1).doRead();
  80. //头 信息
  81. //Map<Integer, String> headList = ImportExcelListener.importHeadList;
  82. //结果集
  83. dataList = ImportExcelListener.importDataList;
  84. }
  85. if (StringUtils.equals("csv",fileType)){
  86. dataList = CsvImportUtil.readCSV(file);
  87. }
  88. //处理数据结果
  89. resultData(dataList,salesLeadsType,uploadDate,createUserId);
  90. //excel 清除监听数据
  91. ImportExcelListener.importDataList.clear();
  92. ImportExcelListener.importHeadList.clear();
  93. }catch (Exception e){
  94. //excel 清除监听数据
  95. ImportExcelListener.importDataList.clear();
  96. ImportExcelListener.importHeadList.clear();
  97. log.error("上传文件出现了问题。{}",e.toString());
  98. e.printStackTrace();
  99. return ResultResponse.error("上传文件失败。");
  100. }
  101. return ResultResponse.successMsg("保存成功",null);
  102. }
  103. /**
  104. * 处理销售线索 数据结果
  105. * @param dataList
  106. * @param salesLeadsType
  107. * @param uploadDate
  108. * @param createUserId
  109. */
  110. public void resultData(List<Map<String,String>> dataList,int salesLeadsType,Long uploadDate,Long createUserId){
  111. List<SaleClueInfoPojo> clueList = new ArrayList<>();
  112. List<SaleQuotaInfoPojo> quotaList = new ArrayList<>();
  113. for (Map<String, String> dataMap : dataList) {
  114. SaleClueInfoPojo clue = new SaleClueInfoPojo();
  115. SaleQuotaInfoPojo quota = new SaleQuotaInfoPojo();
  116. clue.setSalesLeadsType(salesLeadsType);
  117. if (dataMap.get("sellerId").isEmpty()){
  118. continue;
  119. }
  120. clue.setSellerId(Long.valueOf(dataMap.get("sellerId")));
  121. clue.setSellerName(dataMap.get("sellerName"));
  122. clue.setFans(Long.valueOf(dataMap.get("fans")));
  123. clue.setTelephone(StringUtils.isEmpty(dataMap.get("telephone")) ? 0 : Long.valueOf(dataMap.get("telephone")));
  124. clue.setProviderFlag(dataMap.get("providerFlag"));
  125. clue.setTransitionFlag(dataMap.get("transitionFlag"));
  126. clue.setCreateUserId(createUserId);
  127. clue.setUploadDate(uploadDate);
  128. //查询行业
  129. SysIndustryInfo industryInfo = sysIndustryInfoMapper.getIndustryInfoByName(dataMap.get("industryId"));
  130. clue.setIndustryId(StringUtils.isNull(industryInfo) ? 0 : industryInfo.getId());
  131. //根据城市查询 省市id
  132. SysAreaInfo areaInfo = sysAreaInfoMapper.getAreaInfoByName(dataMap.get("cityId"));
  133. clue.setProvinceId(areaInfo == null ? 0 : areaInfo.getParentCode());
  134. clue.setCityId(areaInfo == null ? 0 : areaInfo.getCode());
  135. if (StringUtils.isNotEmpty(dataMap.get("NearlyThirtyDays"))){
  136. quota.setNearlyThirtyDays(dataMap.get("NearlyThirtyDays"));
  137. }
  138. if (StringUtils.isNotEmpty(dataMap.get("gmv"))){
  139. quota.setGmvMonth(Long.valueOf(dataMap.get("gmvMonth")));
  140. quota.setGmv(dataMap.get("gmv"));
  141. }
  142. if (StringUtils.isNotEmpty(dataMap.get("mtd"))){
  143. quota.setMtdDate(Long.valueOf(dataMap.get("mtdDate")));
  144. quota.setMtd(dataMap.get("mtd"));
  145. }
  146. if (StringUtils.isNotEmpty(dataMap.get("NearlyThirtyDays")) ||
  147. StringUtils.isNotEmpty(dataMap.get("gmv")) ||
  148. StringUtils.isNotEmpty(dataMap.get("mtd"))){
  149. quota.setCreateUserId(createUserId);
  150. quota.setSellerId(Long.valueOf(dataMap.get("sellerId")));
  151. }
  152. if (StringUtils.isNotNull(clue)){
  153. clueList.add(clue);
  154. }
  155. if (StringUtils.isNotNull(quota.getSellerId())){
  156. quotaList.add(quota);
  157. }
  158. }
  159. if (clueList.size() > 0){
  160. //销售线索
  161. saleClueInfoMapper.replaceSaleClueInfoBatch(clueList);
  162. }
  163. if (quotaList.size() > 0){
  164. //线索-额度
  165. saleQuotaInfoMapper.replaceSaleQuotaInfoBatch(quotaList);
  166. }
  167. }
  168. /**
  169. *
  170. * @description: 销售线索列表查询
  171. *
  172. * @param sellerName 卖家昵称
  173. * @param uploadDate 年月
  174. * @param distributionSaleFlag 是否分配销售 0-否 1-是
  175. * @param industryId 行业id
  176. * @param fansType 粉丝量级 1:0~50w 2:50W~200W 3:200W~500W 4:500W以上
  177. * @param userId
  178. * @return: com.ruixuan.common.core.domain.ResultResponse<java.util.List<com.ruixuan.salesLeads.pojo.SaleClueInfoPojo>>
  179. * @author: zianY
  180. */
  181. @Override
  182. public ResultResponse selectSaleClueInfoList(String sellerName, Long uploadDate, String distributionSaleFlag, String industryId, String fansType, String state,String salesLeadsType,Long userId) throws Exception {
  183. PageUtils.startPage();
  184. List<SaleClueInfoPojo> saleList = saleClueInfoMapper.selectSaleClueInfoList(sellerName,uploadDate,distributionSaleFlag,industryId,fansType,state,salesLeadsType, userId);
  185. saleList.forEach(clue ->{
  186. clue.setFirstRecord(saleClueRecordInfoMapper.getSaleClueRecordNumber(clue.getSellerId(),1));
  187. clue.setSecondRecord(saleClueRecordInfoMapper.getSaleClueRecordNumber(clue.getSellerId(),2));
  188. //近30天 gmv mtd
  189. SaleQuotaInfoPojo quotaInfoPojo = saleQuotaInfoMapper.getSaleQuotaInfoBySellerId(clue.getSellerId());
  190. if (StringUtils.isNotNull(quotaInfoPojo)){
  191. clue.setNearlyThirtyDays(quotaInfoPojo.getNearlyThirtyDays());
  192. clue.setGmvMonth(quotaInfoPojo.getGmvMonth());
  193. clue.setGmv(quotaInfoPojo.getGmv());
  194. clue.setMtdDate(quotaInfoPojo.getMtdDate());
  195. clue.setMtd(quotaInfoPojo.getMtd());
  196. }
  197. });
  198. return ResultResponse.successMsg("查询成功。",new TableDataInfo(saleList,new Long(new PageInfo(saleList).getTotal()).intValue()));
  199. }
  200. /**
  201. *
  202. * @description: 销售线索任务列表查询
  203. *
  204. * @param sellerName 模糊查询
  205. * @param state 状态 1-未开始 2-进行中 3-已结束
  206. * @param userId 当前用户id
  207. * @return: com.ruixuan.common.core.domain.ResultResponse<java.util.List<com.ruixuan.salesLeads.pojo.SaleClueInfoPojo>>
  208. * @author: zianY
  209. */
  210. @Override
  211. public ResultResponse selectSaleClueTaskList(String sellerName,Integer state, Long userId) {
  212. PageUtils.startPage();
  213. List<SaleClueInfoPojo> saleList = saleClueInfoMapper.selectSaleClueTaskList(sellerName,state, userId);
  214. saleList.forEach(cluePojo -> {
  215. //获取最新一条记录信息
  216. List<SaleClueRecordInfoPojo> list = saleClueRecordInfoMapper.selectDistributionList(cluePojo.getSellerId());
  217. cluePojo.setRecordTask(StringUtils.isEmpty(list) ? null : list.get(list.size()-1));
  218. });
  219. return ResultResponse.successMsg("查询成功。",new TableDataInfo(saleList,new Long(new PageInfo(saleList).getTotal()).intValue()));
  220. }
  221. /**
  222. *
  223. * @description: 销售线索-分配-显示数据信息
  224. *
  225. * @param sellerIds 卖家id
  226. * @return: com.ruixuan.common.core.domain.ResultResponse<java.util.List<com.ruixuan.salesLeads.pojo.SaleClueInfoPojo>>
  227. * @author: zianY
  228. */
  229. @Override
  230. public ResultResponse<List<SaleClueInfoPojo>> selectSaleClueInfoBySellers(List<Long> sellerIds){
  231. List<SaleClueInfoPojo> saleList = saleClueInfoMapper.selectSaleClueInfoBySellers(sellerIds);
  232. return ResultResponse.successMsg("查询成功。",saleList);
  233. }
  234. /**
  235. *
  236. * @description: 销售线索-分配
  237. *
  238. * @param sellerIds 卖家ids
  239. * @param saleId 销售id
  240. * @param createUserId
  241. * @return: com.ruixuan.common.core.domain.ResultResponse
  242. * @author: zianY
  243. */
  244. @Override
  245. public ResultResponse saleClueDistribution(List<String> sellerIds, Long saleId,Long createUserId){
  246. sellerIds.forEach(sellerId -> {
  247. //修改销售线索 销售
  248. saleClueInfoMapper.updateSaleClueSale(Long.valueOf(sellerId),saleId,1);
  249. // 修改线索 状态
  250. saleClueInfoMapper.updateSaleClueState(Long.valueOf(sellerId),2);
  251. //添加 分配记录
  252. saleClueDistributionInfoMapper.insertSaleClueDistribution(new SaleClueDistributionInfoPojo(Long.valueOf(sellerId),saleId,createUserId));
  253. });
  254. return ResultResponse.successMsg("分配销售成功。",null);
  255. }
  256. /**
  257. *
  258. * @description:销售线索任务-查询用户代办以及本周完成的数量汇总
  259. *
  260. * @param userId
  261. * @return: com.ruixuan.common.core.domain.ResultResponse
  262. * @author: zianY
  263. */
  264. @Override
  265. public ResultResponse getTaskNumber(Long userId){
  266. Map<String,Integer> resultMap = new HashMap<>();
  267. //获取当前周的开始和截至时间
  268. Map<String,String> map = DateUtils.getWeekBeginAndEnd();
  269. //本周有意向合作
  270. int complete = saleClueRecordInfoMapper.selectSaleClueIntention(userId,map.get("begin"),map.get("end"));
  271. //用户代办-包括未开始与进行中
  272. int noStarted = saleClueInfoMapper.selectSaleClueComplete(userId);
  273. resultMap.put("complete",complete);
  274. resultMap.put("noStarted",noStarted);
  275. return ResultResponse.successMsg("销售汇总查询成功。",resultMap);
  276. }
  277. /**
  278. * 销售线索任务-回显线索详情
  279. * @param sellerId
  280. * @return
  281. */
  282. @Override
  283. public ResultResponse getSaleTaskInfoBySellerId(Long sellerId){
  284. SaleTaskInfoVo saleTaskInfoVo = new SaleTaskInfoVo();
  285. //线索详情
  286. SaleRecordVo saleInfo = saleClueInfoMapper.selectSaleClueInfoBySellerId(sellerId);
  287. //记录信息
  288. List<SaleClueRecordInfoPojo> recordList = saleClueRecordInfoMapper.selectDistributionList(sellerId);
  289. saleTaskInfoVo.setSaleRecordVo(saleInfo);
  290. saleTaskInfoVo.setRecordList(recordList);
  291. saleTaskInfoVo.setNextNum(StringUtils.isEmpty(recordList) ? 1 : recordList.size()+1);
  292. return ResultResponse.successMsg("查询成功。",saleTaskInfoVo);
  293. }
  294. /**
  295. * 销售线索任务-新增跟进记录
  296. * @param recordInfoPojo
  297. * @return
  298. */
  299. @Override
  300. public ResultResponse insertSaleTaskRecord(SaleClueRecordInfoPojo recordInfoPojo){
  301. //新增跟进记录
  302. saleClueRecordInfoMapper.insertSaleRedord(recordInfoPojo);
  303. //修改线索状态
  304. //是否继续跟进 1-继续跟进 2-意向合作 3-跟进完成无合作
  305. if (recordInfoPojo.getContinueFlag() == 1){
  306. //线索状态 1-未开始 2-进行中 3-已结束
  307. saleClueInfoMapper.updateSaleClueState(recordInfoPojo.getSellerId(),2);
  308. }
  309. if (recordInfoPojo.getContinueFlag() == 2){
  310. //意向合作 1-不合作可跟进 2-添加微信 3-操盘合作 4-服务商合作 5-金牛合作 6-无法添加微信
  311. if (StringUtils.equals(recordInfoPojo.getIntendedCooperation(),"1")){
  312. saleClueInfoMapper.updateSaleClueState(recordInfoPojo.getSellerId(),2);
  313. }
  314. saleClueInfoMapper.updateSaleClueState(recordInfoPojo.getSellerId(),3);
  315. }
  316. if (recordInfoPojo.getContinueFlag() == 3){
  317. saleClueInfoMapper.updateSaleClueState(recordInfoPojo.getSellerId(),3);
  318. }
  319. return ResultResponse.successMsg("新增跟进记录成功。",null);
  320. }
  321. /**
  322. *
  323. * @description: 销售线索-转面销/电销
  324. *
  325. * @param sellerId 卖家id
  326. * @param offlineSaleFlag 类型1-电销 2-面销
  327. * @param saleId 销售人员
  328. * @param createUserId
  329. * @return: com.ruixuan.common.core.domain.ResultResponse
  330. */
  331. @Override
  332. public ResultResponse saleClueToOffline(Long sellerId,int offlineSaleFlag,Long saleId,Long createUserId){
  333. saleClueInfoMapper.updateSaleClueOfflineFlag(sellerId,offlineSaleFlag,saleId);
  334. return ResultResponse.successMsg("成功。",null);
  335. }
  336. }