|
|
@@ -0,0 +1,682 @@
|
|
|
+package com.fs.crm.service.impl;
|
|
|
+
|
|
|
+import cn.jiguang.common.resp.APIConnectionException;
|
|
|
+import cn.jiguang.common.resp.APIRequestException;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.fs.aiSipCall.utils.DateUtils;
|
|
|
+import com.fs.common.OrderUtils;
|
|
|
+import com.fs.common.core.domain.R;
|
|
|
+import com.fs.common.core.domain.entity.SysDictData;
|
|
|
+import com.fs.common.exception.CustomException;
|
|
|
+import com.fs.common.utils.*;
|
|
|
+import com.fs.company.domain.Company;
|
|
|
+import com.fs.company.domain.CompanyUser;
|
|
|
+import com.fs.company.mapper.CompanyMapper;
|
|
|
+import com.fs.company.mapper.CompanyUserMapper;
|
|
|
+import com.fs.company.service.impl.CompanyServiceImpl;
|
|
|
+import com.fs.crm.domain.*;
|
|
|
+import com.fs.crm.enums.CustomerLogEnum;
|
|
|
+import com.fs.crm.mapper.*;
|
|
|
+import com.fs.crm.param.*;
|
|
|
+import com.fs.crm.service.ICrmBusinessService;
|
|
|
+import com.fs.crm.service.ICrmCustomerContactsService;
|
|
|
+import com.fs.crm.service.ICrmCustomerService;
|
|
|
+import com.fs.crm.vo.CrmBusinessListVO;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 商机Service业务层处理
|
|
|
+ *
|
|
|
+ * @author fs
|
|
|
+ * @date 2025-01-16
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class CrmBusinessServiceImpl implements ICrmBusinessService {
|
|
|
+ @Autowired
|
|
|
+ private CrmBusinessMapper crmBusinessMapper;
|
|
|
+ @Autowired
|
|
|
+ private CrmCustomerLogsMapper logsMapper;
|
|
|
+ @Autowired
|
|
|
+ private CrmCustomerMapper customerMapper;
|
|
|
+ @Autowired
|
|
|
+ private ICrmCustomerContactsService contactsService;
|
|
|
+ @Autowired
|
|
|
+ private CrmCustomerMapper crmCustomerMapper;
|
|
|
+ @Autowired
|
|
|
+ private CrmCustomerLogsMapper customerLogsMapper;
|
|
|
+ @Autowired
|
|
|
+ private CrmCustomerVisitMapper customerVisitMapper;
|
|
|
+ @Autowired
|
|
|
+ private ICrmCustomerService crmCustomerService;
|
|
|
+ @Autowired
|
|
|
+ private CrmCustomerUserMapper crmCustomerUserMapper;
|
|
|
+ @Autowired
|
|
|
+ private CompanyMapper companyMapper;
|
|
|
+ @Autowired
|
|
|
+ private CompanyUserMapper companyUserMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询商机
|
|
|
+ *
|
|
|
+ * @param businessId 商机ID
|
|
|
+ * @return 商机
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public CrmBusiness selectCrmBusinessById(Long businessId) {
|
|
|
+ return crmBusinessMapper.selectCrmBusinessById(businessId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询商机列表
|
|
|
+ *
|
|
|
+ * @param param 商机
|
|
|
+ * @return 商机
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<CrmBusinessListVO> selectCrmBusinessList(CrmBusinessQueryParam param) {
|
|
|
+ List<CrmBusinessListVO> list = crmBusinessMapper.selectCrmBusinessList(param);
|
|
|
+ if (list != null) {
|
|
|
+ for (CrmBusinessListVO vo : list) {
|
|
|
+ Long customerId = vo.getCustomerId();
|
|
|
+ CrmCustomerContacts contacts = new CrmCustomerContacts();
|
|
|
+ if (customerId != null) {
|
|
|
+ contacts.setCustomerId(customerId);
|
|
|
+ //客户联系电话
|
|
|
+ CrmCustomer crmCustomer = customerMapper.selectCrmCustomerById(customerId);
|
|
|
+ if (crmCustomer != null) {
|
|
|
+ vo.setMobile(crmCustomer.getMobile());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ contacts.setBusinessId(vo.getBusinessId());
|
|
|
+ }
|
|
|
+ if (vo.getCustomerId() == null){
|
|
|
+ //查询最新跟进内容
|
|
|
+ CrmCustomerVisit visit = customerVisitMapper.selectNewByBusinessId(vo.getBusinessId());
|
|
|
+ if (visit != null) {
|
|
|
+ vo.setNextTime(visit.getNextTime());
|
|
|
+ vo.setContent(visit.getContent());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<CrmCustomerContacts> mobileList = contactsService.selectCrmCustomerContactsList(contacts);
|
|
|
+ vo.setMobileList(mobileList);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增商机
|
|
|
+ *
|
|
|
+ * @param param 商机
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public int insertCrmBusiness(CrmBusinessAddAndUpdateParam param) {
|
|
|
+ Date nowDate = DateUtils.getNowDate();
|
|
|
+ //新增商机
|
|
|
+ CrmBusiness business = new CrmBusiness();
|
|
|
+ BeanUtils.copyProperties(param, business);
|
|
|
+ business.setCreateTime(nowDate);
|
|
|
+ if (business.getNextTime() == null){
|
|
|
+ business.setNextTime(DateUtils.addDays(nowDate,20));
|
|
|
+ }
|
|
|
+ int i = crmBusinessMapper.insertCrmBusiness(business);
|
|
|
+ Long businessId = business.getBusinessId();
|
|
|
+ if (i > 0) {
|
|
|
+ param.setBusinessId(businessId);
|
|
|
+ Long customerId = param.getCustomerId();
|
|
|
+ //其他联系人
|
|
|
+ List<CrmCustomerContacts> mobileList = param.getMobileList();
|
|
|
+ //客户新建商机 不用添加mobile
|
|
|
+ if (customerId == null) {
|
|
|
+ //直接新建商机
|
|
|
+ if (mobileList != null) {
|
|
|
+ if (StringUtils.isNotBlank(param.getMobile())) {
|
|
|
+ CrmCustomerContacts contact = new CrmCustomerContacts();
|
|
|
+ contact.setName(param.getCompanyName());
|
|
|
+ contact.setMobile(param.getMobile());
|
|
|
+ mobileList.add(contact);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (mobileList != null && !mobileList.isEmpty()) {
|
|
|
+ //添加联系人
|
|
|
+ contactsService.addByBusiness(customerId, businessId, mobileList);
|
|
|
+ }
|
|
|
+ checkPoolRule(param,customerId);
|
|
|
+ checkInsertLog(param,business);
|
|
|
+ //2025.9.2 规则 有商机的客户归属管理员
|
|
|
+ CrmCustomer customer = crmCustomerMapper.selectCrmCustomerById(param.getCustomerId());
|
|
|
+ if (customer != null) {
|
|
|
+ //查询管理员
|
|
|
+ assignAdmin(param, customer, customerId,nowDate);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return i;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void assignAdmin(CrmBusinessAddAndUpdateParam param, CrmCustomer customer, Long customerId,Date nowDate) {
|
|
|
+ Company company = companyMapper.selectCompanyById(customer.getCompanyId());
|
|
|
+ Long userId = company.getUserId();
|
|
|
+ CompanyUser user = companyUserMapper.selectCompanyUserById(userId);
|
|
|
+ //写入认领记录
|
|
|
+ CrmCustomerUser crmCustomerUser = new CrmCustomerUser();
|
|
|
+
|
|
|
+ crmCustomerUser.setCustomerId(customerId);
|
|
|
+ crmCustomerUser.setCompanyId(user.getCompanyId());
|
|
|
+ crmCustomerUser.setCompanyUserId(user.getUserId());
|
|
|
+ crmCustomerUser.setStatus(1);
|
|
|
+ crmCustomerUser.setCreateTime(nowDate);
|
|
|
+ crmCustomerUser.setStartTime(nowDate);
|
|
|
+ crmCustomerUser.setIsPool(0);
|
|
|
+ //结束时间按规则配置
|
|
|
+ crmCustomerUserMapper.insertCrmCustomerUser(crmCustomerUser);
|
|
|
+ customer.setReceiveUserId(user.getUserId());
|
|
|
+ customer.setIsReceive(1);
|
|
|
+ customer.setReceiveTime(nowDate);
|
|
|
+ customer.setCustomerUserId(crmCustomerUser.getCustomerUserId());
|
|
|
+ customer.setDeptId(user.getDeptId());
|
|
|
+ customer.setIsPool(0);
|
|
|
+ customer.setPoolTime(null);
|
|
|
+ customer.setIsPoolRule(0); // 2025.9.2 所有商机客户 不流转公海
|
|
|
+ //2025.04.09 如果没有下次跟进时间 建立20天后的跟进时间
|
|
|
+ if (customer.getNextTime() == null){
|
|
|
+ CrmCustomerVisit crmCustomerVisit = new CrmCustomerVisit();
|
|
|
+ crmCustomerVisit.setCustomerId(param.getCustomerId());
|
|
|
+ crmCustomerVisit.setCompanyId(crmCustomerUser.getCompanyId());
|
|
|
+ crmCustomerVisit.setCompanyUserId(crmCustomerUser.getCompanyUserId());
|
|
|
+ crmCustomerVisit.setVisitType(-1L);
|
|
|
+ crmCustomerVisit.setContent("创建商机客户,自动添加下次联系时间");
|
|
|
+ crmCustomerVisit.setType(1);
|
|
|
+ crmCustomerVisit.setIsShow(1);
|
|
|
+ crmCustomerVisit.setCreateTime(nowDate);
|
|
|
+ crmCustomerVisit.setNextTime(DateUtils.addDays(nowDate, 20));
|
|
|
+ customer.setNextTime(crmCustomerVisit.getNextTime());
|
|
|
+ customerVisitMapper.insertCrmCustomerVisit(crmCustomerVisit);
|
|
|
+ }
|
|
|
+ crmCustomerMapper.updateCrmCustomer(customer);
|
|
|
+ //写日志
|
|
|
+ CrmCustomerLogs logs = new CrmCustomerLogs();
|
|
|
+ logs.setCustomerId(customer.getCustomerId());
|
|
|
+ logs.setCreateTime(new Date());
|
|
|
+ logs.setLogsType(CustomerLogEnum.RECEIVE.getValue());
|
|
|
+ logs.setTitle(CustomerLogEnum.RECEIVE.getDesc());
|
|
|
+ logs.setRemark(param.getOpeName() + "创建商机,系统自动分配该客户给管理员,客户名称为:" + customer.getCustomerName());
|
|
|
+ logs.setCompanyUserId(param.getCreateId());
|
|
|
+ logsMapper.insertCrmCustomerLogs(logs);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void checkInsertLog(CrmBusinessAddAndUpdateParam param, CrmBusiness business) {
|
|
|
+ //添加客户日志
|
|
|
+ if (param.getCustomerId() != null) {
|
|
|
+ CrmCustomerLogs log=new CrmCustomerLogs();
|
|
|
+ log.setCustomerId(param.getCustomerId());
|
|
|
+ log.setCreateTime(business.getCreateTime());
|
|
|
+ log.setLogsType(CustomerLogEnum.BUSINESS.getValue());
|
|
|
+ log.setTitle(CustomerLogEnum.BUSINESS.getDesc());
|
|
|
+ log.setRemark(param.getOpeName()+"创建商机,商机id:" + business.getBusinessId());
|
|
|
+ logsMapper.insertCrmCustomerLogs(log);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增商机
|
|
|
+ *
|
|
|
+ * @param crmBusiness 商机
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int insert(CrmBusiness crmBusiness) {
|
|
|
+ //新增商机
|
|
|
+ crmBusiness.setCreateTime(DateUtils.getNowDate());
|
|
|
+ return crmBusinessMapper.insertCrmBusiness(crmBusiness);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改商机
|
|
|
+ *
|
|
|
+ * @param param 商机
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public int updateCrmBusiness(CrmBusinessAddAndUpdateParam param) {
|
|
|
+ CrmBusiness crmBusiness = new CrmBusiness();
|
|
|
+ BeanUtils.copyProperties(param, crmBusiness);
|
|
|
+ crmBusiness.setUpdateTime(DateUtils.getNowDate());
|
|
|
+ Long customerId = param.getCustomerId();
|
|
|
+ //其他联系人
|
|
|
+ List<CrmCustomerContacts> mobileList = param.getMobileList();
|
|
|
+ if (mobileList != null && !mobileList.isEmpty()) {
|
|
|
+ //添加联系人
|
|
|
+ contactsService.addByBusiness(customerId, param.getBusinessId(), mobileList);
|
|
|
+ }
|
|
|
+ checkPoolRule(param, customerId); //处理商机规则
|
|
|
+ return crmBusinessMapper.updateCrmBusiness(crmBusiness);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void checkPoolRule(CrmBusinessAddAndUpdateParam param, Long customerId) {
|
|
|
+ //判断是否100商机 是 相关客户取消公海回收规则
|
|
|
+ String projectPhase = param.getProjectPhase();
|
|
|
+ Integer businessStatus = param.getBusinessStatus();
|
|
|
+ if (StringUtils.isNotBlank(projectPhase) || businessStatus != null) {
|
|
|
+ //同步跟进状态和项目阶段
|
|
|
+ if ("A".equals(projectPhase)){
|
|
|
+ businessStatus = 2;
|
|
|
+ } else if ("L".equals(projectPhase)){
|
|
|
+ businessStatus = 1;
|
|
|
+ }
|
|
|
+ if (businessStatus == 1) {
|
|
|
+ projectPhase = "A";
|
|
|
+ } else if (businessStatus == 2) {
|
|
|
+ projectPhase = "L";
|
|
|
+ }
|
|
|
+ param.setProjectPhase(projectPhase);
|
|
|
+ param.setBusinessStatus(businessStatus);
|
|
|
+ }
|
|
|
+
|
|
|
+ CrmCustomer crmCustomer = null;
|
|
|
+ if (customerId != null) {
|
|
|
+ crmCustomer = customerMapper.selectCrmCustomerById(customerId);
|
|
|
+ if (crmCustomer != null) {
|
|
|
+ if (StringUtils.isNotBlank(projectPhase)) {
|
|
|
+ //100%转商机
|
|
|
+ if ("A".equals(projectPhase)) {
|
|
|
+ //相关客户取消公海回收规则
|
|
|
+ crmCustomer.setIsPoolRule(0);
|
|
|
+ customerMapper.updateCrmCustomer(crmCustomer);
|
|
|
+ } else {
|
|
|
+ //查询是否有成交商机
|
|
|
+ CrmBusinessQueryParam queryParam = new CrmBusinessQueryParam();
|
|
|
+ queryParam.setCustomerId(customerId);
|
|
|
+ queryParam.setProjectPhase("A");
|
|
|
+ List<CrmBusinessListVO> list = crmBusinessMapper.selectCrmBusinessList(queryParam);
|
|
|
+ if (list == null || list.isEmpty()) {
|
|
|
+ crmCustomer.setIsPoolRule(1);
|
|
|
+ customerMapper.updateCrmCustomer(crmCustomer);
|
|
|
+ } else if (list.size() == 1) {
|
|
|
+ if (Objects.equals(list.get(0).getBusinessId(), param.getBusinessId())) {
|
|
|
+ crmCustomer.setIsPoolRule(1);
|
|
|
+ customerMapper.updateCrmCustomer(crmCustomer);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ createLogByUpdateBusiness(param, crmCustomer);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加客户日志 (修改商机)
|
|
|
+ * @param param
|
|
|
+ * @param crmCustomer
|
|
|
+ */
|
|
|
+ private void createLogByUpdateBusiness(CrmBusinessAddAndUpdateParam param,CrmCustomer crmCustomer) {
|
|
|
+ if (crmCustomer != null) {
|
|
|
+ CrmCustomerLogs logTemp = new CrmCustomerLogs();
|
|
|
+ logTemp.setCustomerId(crmCustomer.getCustomerId());
|
|
|
+ logTemp.setCompanyUserId(param.getUpdateId());
|
|
|
+ logTemp.setTitle(CustomerLogEnum.UPDATE_BUSINESS.getDesc());
|
|
|
+ logTemp.setLogsType(CustomerLogEnum.UPDATE_BUSINESS.getValue());
|
|
|
+ //查询原记录
|
|
|
+ StringBuilder remark = getBusinessChange(param);
|
|
|
+ logTemp.setRemark("跟进商机:" +"\n" + remark);
|
|
|
+ logTemp.setCreateTime(new Date());
|
|
|
+ customerLogsMapper.insertCrmCustomerLogs(logTemp);
|
|
|
+ }
|
|
|
+ //判断是否早于最新跟进
|
|
|
+// if (param.getNextTime() != null && param.getNextTime().after(new Date())) {
|
|
|
+ if (param.getNextTime() != null) {
|
|
|
+ CrmCustomerVisit visitTemp = new CrmCustomerVisit();
|
|
|
+ visitTemp.setCustomerId(crmCustomer == null ?null:crmCustomer.getCustomerId());
|
|
|
+ visitTemp.setBusinessId(param.getBusinessId());
|
|
|
+ visitTemp.setType(2);
|
|
|
+ visitTemp.setVisitType(-1L); //系统自建 修改商机创建的跟进
|
|
|
+ visitTemp.setContent("商机跟进:" + (StringUtils.isNotBlank(param.getContent())?param.getContent():""));
|
|
|
+ visitTemp.setNextTime(param.getNextTime());
|
|
|
+ visitTemp.setCompanyUserId(param.getUpdateId()==null?param.getCreateId():param.getUpdateId());
|
|
|
+ visitTemp.setCompanyId(param.getCompanyId());
|
|
|
+ visitTemp.setIsShow(1);
|
|
|
+ visitTemp.setCreateTime(new Date());
|
|
|
+ customerVisitMapper.insertCrmCustomerVisit(visitTemp);
|
|
|
+ boolean isUpdate = false;
|
|
|
+ if (crmCustomer != null) {
|
|
|
+ if (crmCustomer.getNextTime() != null){
|
|
|
+ if (param.getNextTime().before(crmCustomer.getNextTime())){
|
|
|
+ isUpdate = true;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ isUpdate = true;
|
|
|
+ }
|
|
|
+ //是,则需要更新crm_customer表
|
|
|
+ if (isUpdate) {
|
|
|
+ crmCustomer.setNextTime(param.getNextTime());
|
|
|
+ crmCustomerMapper.updateCrmCustomer(crmCustomer);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询修改了商机的哪些东西
|
|
|
+ * @param param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private StringBuilder getBusinessChange(CrmBusinessAddAndUpdateParam param) {
|
|
|
+ StringBuilder remark = new StringBuilder();
|
|
|
+ CrmBusiness crmBusiness = crmBusinessMapper.selectCrmBusinessById(param.getBusinessId());
|
|
|
+ if (crmBusiness != null) {
|
|
|
+ Integer source = crmBusiness.getSource();
|
|
|
+ if (param.getSource() != null && !param.getSource().equals(source)) {
|
|
|
+ remark.append("将 ").append("线索来源 ").append(source).append(" 改为 ").append(param.getSource()).append("\n");
|
|
|
+ }
|
|
|
+ String manager = crmBusiness.getManager();
|
|
|
+ if (param.getManager() != null && !param.getManager().equals(manager)) {
|
|
|
+ remark.append("将 ").append("客户经理 ").append(manager).append(" 改为 ").append(param.getManager()).append("\n");
|
|
|
+ }
|
|
|
+ String companyName = crmBusiness.getCompanyName();
|
|
|
+ if (param.getCompanyName() != null && !param.getCompanyName().equals(companyName)) {
|
|
|
+ remark.append("将 ").append("公司名称 ").append(companyName).append(" 改为 ").append(param.getCompanyName()).append("\n");
|
|
|
+ }
|
|
|
+ Integer contactRole = crmBusiness.getContactRole();
|
|
|
+ if (param.getContactRole() != null && !param.getContactRole().equals(contactRole)) {
|
|
|
+ remark.append("将 ").append("接口人角色 ").append(contactRole).append(" 改为 ").append(param.getContactRole()).append("\n");
|
|
|
+ }
|
|
|
+ String businessScenario = crmBusiness.getBusinessScenario();
|
|
|
+ if (param.getBusinessScenario() != null && !param.getBusinessScenario().equals(businessScenario)) {
|
|
|
+ remark.append("将 ").append("业务场景 ").append(businessScenario).append(" 改为 ").append(param.getBusinessScenario()).append("\n");
|
|
|
+ }
|
|
|
+ String product = crmBusiness.getProduct();
|
|
|
+ if (param.getProduct() != null && !param.getProduct().equals(product)) {
|
|
|
+ remark.append("将 ").append("意向产品 ").append(product).append(" 改为 ").append(param.getProduct()).append("\n");
|
|
|
+ }
|
|
|
+ Long purchaseCycle = crmBusiness.getPurchaseCycle();
|
|
|
+ if (param.getPurchaseCycle() != null && !param.getPurchaseCycle().equals(purchaseCycle)) {
|
|
|
+ remark.append("将 ").append("采购周期 ").append(purchaseCycle).append(" 改为 ").append(param.getPurchaseCycle()).append("\n");
|
|
|
+ }
|
|
|
+ Integer businessStatus = crmBusiness.getBusinessStatus();
|
|
|
+ if (param.getBusinessStatus() != null && !param.getBusinessStatus().equals(businessStatus)) {
|
|
|
+ remark.append("将 ").append("跟进状态 ").append(businessStatus).append(" 改为 ").append(param.getBusinessStatus()).append("\n");
|
|
|
+ }
|
|
|
+ String businessRemark = crmBusiness.getRemark();
|
|
|
+ if (param.getRemark() != null && !param.getRemark().equals(businessRemark)) {
|
|
|
+ remark.append("将 ").append("备注 ").append(businessRemark).append(" 改为 ").append(param.getRemark()).append("\n");
|
|
|
+ }
|
|
|
+ String projectPhase = crmBusiness.getProjectPhase();
|
|
|
+ if (param.getProjectPhase() != null && !param.getProjectPhase().equals(projectPhase)) {
|
|
|
+ remark.append("将 ").append("项目阶段 ").append(projectPhase).append(" 改为 ").append(param.getProjectPhase()).append("\n");
|
|
|
+ }
|
|
|
+ Integer level = crmBusiness.getLevel();
|
|
|
+ if (param.getLevel() != null && !param.getLevel().equals(level)) {
|
|
|
+ remark.append("将 ").append("意向等级 ").append(level).append(" 改为 ").append(param.getLevel()).append("\n");
|
|
|
+ }
|
|
|
+ Integer isBp = crmBusiness.getIsBp();
|
|
|
+ if (param.getIsBp() != null && !param.getIsBp().equals(isBp)) {
|
|
|
+ remark.append("将 ").append("是否绑定BP ").append(isBp).append(" 改为 ").append(param.getIsBp()).append("\n");
|
|
|
+ }
|
|
|
+ String bpAccount = crmBusiness.getBpAccount();
|
|
|
+ if (param.getBpAccount() != null && !param.getBpAccount().equals(bpAccount)) {
|
|
|
+ remark.append("将 ").append("bp账号 ").append(bpAccount).append(" 改为 ").append(param.getBpAccount()).append("\n");
|
|
|
+ }
|
|
|
+ Date preTime = crmBusiness.getPreTime();
|
|
|
+ if (param.getPreTime() != null && !param.getPreTime().equals(preTime)) {
|
|
|
+ remark.append("将 ").append("预计成单时间 ").append(preTime).append(" 改为 ").append(param.getPreTime()).append("\n");
|
|
|
+ }
|
|
|
+ Float preMoney = crmBusiness.getPreMoney();
|
|
|
+ if (param.getPreMoney() != null && !param.getPreMoney().equals(preMoney)) {
|
|
|
+ remark.append("将 ").append("预计成交金额 ").append(preMoney).append(" 改为 ").append(param.getPreMoney()).append("\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return remark;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量删除商机
|
|
|
+ *
|
|
|
+ * @param businessIds 需要删除的商机ID
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public int deleteCrmBusinessByIds(Long[] businessIds,String opeName) {
|
|
|
+ for (Long businessId : businessIds) {
|
|
|
+ delCheckPoolRule(businessId,opeName);
|
|
|
+ }
|
|
|
+ return crmBusinessMapper.deleteCrmBusinessByIds(businessIds);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void delCheckPoolRule(Long businessId,String opeName) {
|
|
|
+ //查询 商机
|
|
|
+ CrmBusiness crmBusiness = selectCrmBusinessById(businessId);
|
|
|
+ if (crmBusiness != null) {
|
|
|
+ Long customerId = crmBusiness.getCustomerId();
|
|
|
+ if (customerId != null) {
|
|
|
+ CrmCustomer crmCustomer = crmCustomerMapper.selectCrmCustomerById(customerId);
|
|
|
+ if (crmCustomer != null) {
|
|
|
+ //查询是否有成交商机
|
|
|
+ CrmBusinessQueryParam queryParam = new CrmBusinessQueryParam();
|
|
|
+ queryParam.setCustomerId(customerId);
|
|
|
+ queryParam.setProjectPhase("A");
|
|
|
+ List<CrmBusinessListVO> list = crmBusinessMapper.selectCrmBusinessList(queryParam);
|
|
|
+ if (list!=null && list.size() == 1) {
|
|
|
+ if (Objects.equals(list.get(0).getBusinessId(), businessId)) {
|
|
|
+ crmCustomer.setIsPoolRule(1);
|
|
|
+ customerMapper.updateCrmCustomer(crmCustomer);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ CrmCustomerLogs log=new CrmCustomerLogs();
|
|
|
+ log.setCustomerId(customerId);
|
|
|
+ log.setCreateTime(new Date());
|
|
|
+ log.setLogsType(CustomerLogEnum.DEL_BUSINESS.getValue());
|
|
|
+ log.setTitle(CustomerLogEnum.DEL_BUSINESS.getDesc());
|
|
|
+ log.setRemark(opeName+"删除商机,商机id:" + businessId);
|
|
|
+ logsMapper.insertCrmCustomerLogs(log);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除商机信息
|
|
|
+ *
|
|
|
+ * @param businessId 商机ID
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public int deleteCrmBusinessById(Long businessId,String opeName) {
|
|
|
+ delCheckPoolRule(businessId,opeName);
|
|
|
+ return crmBusinessMapper.deleteCrmBusinessById(businessId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int updateCrmBusinessByCustomerId(CrmBusiness crmBusiness) {
|
|
|
+ crmBusiness.setUpdateTime(DateUtils.getNowDate());
|
|
|
+ return crmBusinessMapper.updateCrmBusinessByCustomerId(crmBusiness);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CrmBusiness getLastByCustomerId(Long customerId) {
|
|
|
+ return crmBusinessMapper.getLastByCustomerId(customerId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String importBusinessData(List<CrmBusinessImportParam> list, CompanyUser user) {
|
|
|
+ if (StringUtils.isNull(list) || list.size() == 0) {
|
|
|
+ throw new CustomException("导入数据不能为空!");
|
|
|
+ }
|
|
|
+ int successNum = 0;
|
|
|
+ int failureNum = 0;
|
|
|
+ StringBuilder successMsg = new StringBuilder();
|
|
|
+ StringBuilder failureMsg = new StringBuilder();
|
|
|
+ StringBuilder importMsg = new StringBuilder();
|
|
|
+ for (CrmBusinessImportParam param : list) {
|
|
|
+ try {
|
|
|
+ //1.1校验必填字段
|
|
|
+ ExcelUtils.validateRequiredFields(param, list.indexOf(param) + 1); // 传入行号
|
|
|
+ CrmBusinessAddAndUpdateParam addParam = new CrmBusinessAddAndUpdateParam();
|
|
|
+ BeanUtils.copyProperties(param, addParam);
|
|
|
+ //没有相关客户,则新建客户
|
|
|
+ if (param.getCustomerId() == null || param.getCustomerId() <= 0) {
|
|
|
+ if (StringUtils.isBlank(param.getMobile())){
|
|
|
+ failureNum++;
|
|
|
+ String msg = "<br/>" + failureNum + "、第 " + list.indexOf(param) + 1 + "行 客户id为空的情况 客户电话不能为空!";
|
|
|
+ failureMsg.append(msg);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(param.getCompanyName())){
|
|
|
+ failureNum++;
|
|
|
+ String msg = "<br/>" + failureNum + "、第 " + list.indexOf(param) + 1 + "行 客户id为空的情况 公司名称不能为空!";
|
|
|
+ failureMsg.append(msg);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(param.getSource())){
|
|
|
+ failureNum++;
|
|
|
+ String msg = "<br/>" + failureNum + "、第 " + list.indexOf(param) + 1 + "行 客户id为空的情况 客户来源不能为空!";
|
|
|
+ failureMsg.append(msg);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ CrmCustomerUpdateOrAddParam crmCustomer = new CrmCustomerUpdateOrAddParam();
|
|
|
+ crmCustomer.setCustomerCode(OrderUtils.getOrderNo());
|
|
|
+ crmCustomer.setMobile(param.getMobile());
|
|
|
+ crmCustomer.setCustomerCompanyName(param.getCompanyName());
|
|
|
+ crmCustomer.setCustomerName(param.getCompanyName());
|
|
|
+ crmCustomer.setSource(param.getSource());
|
|
|
+ crmCustomer.setIsLine(0);
|
|
|
+ crmCustomer.setIsDel(0);
|
|
|
+ crmCustomer.setIsReceive(0);
|
|
|
+ crmCustomer.setStatus(1);
|
|
|
+ crmCustomer.setDeptId(user.getDeptId());
|
|
|
+ crmCustomer.setCreateUserId(user.getUserId());
|
|
|
+ crmCustomer.setCompanyId(user.getCompanyId());
|
|
|
+ crmCustomer.setOpeName(user.getNickName());
|
|
|
+ if(crmCustomerService.insertCrmCustomer(crmCustomer)>0){
|
|
|
+ CrmCustomeReceiveParam receiveParam=new CrmCustomeReceiveParam();
|
|
|
+ receiveParam.setCompanyId(user.getCompanyId());
|
|
|
+ receiveParam.setCompanyUserId(user.getUserId());
|
|
|
+ receiveParam.setCustomerId(crmCustomer.getCustomerId());
|
|
|
+ R receiveResult = crmCustomerService.receive(receiveParam, user.getNickName());
|
|
|
+ if (!"200".equals(receiveResult.get("code").toString())){
|
|
|
+ failureNum++;
|
|
|
+ String msg = "<br/>" + failureNum + "、第 " + list.indexOf(param) + 1 + "行 客户创建成功,但认领失败,商机导入失败:" + receiveResult.get("msg");
|
|
|
+ failureMsg.append(msg);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ failureNum++;
|
|
|
+ String msg = "<br/>" + failureNum + "、第 " + list.indexOf(param) + 1 + "行 客户创建失败:电话或者公司名字已存在 请查找相关客户导入商机时填写相关客户id";
|
|
|
+ failureMsg.append(msg);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ param.setCustomerId(crmCustomer.getCustomerId());
|
|
|
+ addParam.setCustomerId(crmCustomer.getCustomerId());
|
|
|
+ addParam.setMobile(null);
|
|
|
+ }else {
|
|
|
+ addParam.setMobile(null);
|
|
|
+ if (StringUtils.isNotBlank((param.getMobile()))){
|
|
|
+ CrmCustomerContacts crmCustomerContact = new CrmCustomerContacts();
|
|
|
+ crmCustomerContact.setCustomerId(param.getCustomerId());
|
|
|
+ crmCustomerContact.setMobile(param.getMobile());
|
|
|
+ List<CrmCustomerContacts> contacts = new ArrayList<>();
|
|
|
+ contacts.add(crmCustomerContact);
|
|
|
+ addParam.setMobileList(contacts);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ CrmCustomer crmCustomer = customerMapper.selectCrmCustomerById(param.getCustomerId());
|
|
|
+ if (crmCustomer == null) {
|
|
|
+ failureNum++;
|
|
|
+ String msg = "<br/>" + failureNum + "、客户ID " + param.getCustomerId() + "不存在该客户 导入失败:";
|
|
|
+ failureMsg.append(msg);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ addParam.setSource(Integer.valueOf(crmCustomer.getSource()));
|
|
|
+ addParam.setContactRole(StringUtils.isNotBlank(param.getContactRole())?Integer.valueOf(param.getContactRole()):null);
|
|
|
+ addParam.setBusinessStatus(StringUtils.isNotBlank(param.getBusinessStatus())?Integer.valueOf(param.getBusinessStatus()):null);
|
|
|
+ addParam.setLevel(StringUtils.isNotBlank(param.getLevel())?Integer.valueOf(param.getLevel()):null);
|
|
|
+ addParam.setCreateId(user.getUserId());
|
|
|
+ addParam.setOpeName(user.getNickName());
|
|
|
+ addParam.setCompanyId(user.getCompanyId());
|
|
|
+ if (insertCrmBusiness(addParam) > 0) {
|
|
|
+ successNum++;
|
|
|
+ successMsg.append("<br/>").append(successNum).append("、第"+list.indexOf(param) + 1 +"行 客户ID ").append(param.getCustomerId()).append(" 导入成功");
|
|
|
+ } else {
|
|
|
+ failureNum++;
|
|
|
+ failureMsg.append("<br/>").append(successNum).append("、客户ID ").append(param.getCustomerId()).append(" 导入失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ failureNum++;
|
|
|
+ String msg = "<br/>" + failureNum + "、客户ID " +param.getCustomerId() + " 导入失败:";
|
|
|
+ failureMsg.append(msg).append(e.getMessage());
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (failureNum > 0) {
|
|
|
+ failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
|
|
|
+ //throw new CustomException(failureMsg.toString());
|
|
|
+ } else {
|
|
|
+ successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
|
|
|
+ }
|
|
|
+ importMsg.append(failureMsg.toString());
|
|
|
+ importMsg.append(successMsg.toString());
|
|
|
+ return importMsg.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+// @Override
|
|
|
+// @Transactional
|
|
|
+// public String gain(AssignmentBusinessVo vo, Long userId, String userName) {
|
|
|
+// List<Long> businessIds = vo.getBusinessIds();
|
|
|
+// List<Long> customerIds = vo.getCustomerIds();
|
|
|
+// if (businessIds.size() != customerIds.size()) {
|
|
|
+// return "参数错误!";
|
|
|
+// }
|
|
|
+// if (businessIds.size() == 0) {
|
|
|
+// return "无商机捞取!";
|
|
|
+// }
|
|
|
+// //修改商机表
|
|
|
+// CrmBusiness crmBusiness = new CrmBusiness();
|
|
|
+//// crmBusiness.setBusinessId(businessIds[i]);
|
|
|
+// crmBusiness.setStatus(2); //或1
|
|
|
+// crmBusiness.setUpdateTime(DateUtils.getNowDate());
|
|
|
+// crmBusinessMapper.updateBatchCrmBusiness(businessIds, crmBusiness);
|
|
|
+// //修改客户表
|
|
|
+// CrmCustomer crmCustomer = new CrmCustomer();
|
|
|
+// crmCustomer.setIsPool(0);
|
|
|
+//// customer.setReceiveUserId(0L);
|
|
|
+//// customer.setIsReceive(0);
|
|
|
+// crmCustomer.setPoolTime(new Date());
|
|
|
+//// customer.setCustomerUserId(0L);
|
|
|
+// crmCustomer.setUpdateTime(DateUtils.getNowDate());
|
|
|
+// customerMapper.updateBatchCrmCustomer(customerIds, crmCustomer);
|
|
|
+// //写日志
|
|
|
+// customerIds.forEach(customerId -> {
|
|
|
+// CrmCustomerLogs logs = new CrmCustomerLogs();
|
|
|
+// logs.setCustomerId(customerId);
|
|
|
+// logs.setCreateTime(new Date());
|
|
|
+// logs.setLogsType(CustomerLogEnum.GAIN_BUSINESS.getValue());
|
|
|
+// logs.setTitle(CustomerLogEnum.GAIN_BUSINESS.getDesc());
|
|
|
+// logs.setRemark(userName + "捞取客户客户id为" +customerId + "的客户");
|
|
|
+// logs.setCompanyUserId(userId);
|
|
|
+// logsMapper.insertCrmCustomerLogs(logs);
|
|
|
+// });
|
|
|
+//
|
|
|
+// return "捞取成功";
|
|
|
+// }
|
|
|
+}
|