|
@@ -1,10 +1,9 @@
|
|
|
package com.fjhx.customer.service.xiaoman.impl;
|
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
-import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
-import com.fasterxml.jackson.databind.json.JsonMapper;
|
|
|
import com.fjhx.common.constant.SourceConstant;
|
|
|
import com.fjhx.customer.contants.XiaomanContant;
|
|
|
import com.fjhx.customer.entity.customer.po.Customer;
|
|
@@ -21,8 +20,8 @@ import com.fjhx.customer.service.customer.CustomerUserService;
|
|
|
import com.fjhx.customer.service.xiaoman.XiaomanApiService;
|
|
|
import com.fjhx.customer.service.xiaoman.XiaomanCustomerService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.fjhx.tenant.entity.dict.dto.DictTenantDataSelectDto;
|
|
|
import com.fjhx.tenant.entity.dict.vo.DictTenantDataVo;
|
|
|
+import com.fjhx.tenant.utils.DictUtils;
|
|
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
@@ -34,10 +33,10 @@ import com.fjhx.customer.entity.xiaoman.dto.XiaomanCustomerSelectDto;
|
|
|
import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
import com.fjhx.customer.entity.xiaoman.dto.XiaomanCustomerDto;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.atomic.AtomicReference;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -71,6 +70,13 @@ public class XiaomanCustomerServiceImpl extends ServiceImpl<XiaomanCustomerMappe
|
|
|
@Override
|
|
|
public List<XiaomanCustomerVo> getList(XiaomanCustomerSelectDto dto) {
|
|
|
IWrapper<XiaomanCustomer> wrapper = getWrapper();
|
|
|
+ if(ObjectUtil.isNotEmpty(dto.getKeyword())){
|
|
|
+ wrapper.and(q->q.like("xc",XiaomanCustomer::getCompanyId,dto.getKeyword()))
|
|
|
+ .or().like("xc",XiaomanCustomer::getCustomerId,dto.getKeyword())
|
|
|
+ .or().like("xc",XiaomanCustomer::getName,dto.getKeyword())
|
|
|
+ .or().like("xc",XiaomanCustomer::getShortName,dto.getKeyword())
|
|
|
+ ;
|
|
|
+ }
|
|
|
wrapper.orderByDesc("xc", XiaomanCustomer::getCompanyId);
|
|
|
List<XiaomanCustomerVo> list = this.baseMapper.getList(wrapper);
|
|
|
return list;
|
|
@@ -113,13 +119,11 @@ public class XiaomanCustomerServiceImpl extends ServiceImpl<XiaomanCustomerMappe
|
|
|
try {
|
|
|
if (allCustomer.contains(customer.getCompanyId())){
|
|
|
|
|
|
- //TODO 获取详情
|
|
|
String customerDetailJson = xiaomanApiService.getCustomerDetail(customer.getCompanyId());
|
|
|
XiaomanCustomerInfoJson xiaomanCustomerInfoJson = new XiaomanCustomerInfoJson();
|
|
|
xiaomanCustomerInfoJson.setCompanyId(customer.getCompanyId());
|
|
|
xiaomanCustomerInfoJson.setJson(customerDetailJson);
|
|
|
xiaomanCustomerInfoJsonService.updateById(xiaomanCustomerInfoJson);
|
|
|
- //TODO 更新数据
|
|
|
CustomerInfoVo infoVo = HandleXiaomanData.handleDate(customerDetailJson, new TypeReference<R<CustomerInfoVo>>() {
|
|
|
});
|
|
|
Long s = customerConversion(infoVo);
|
|
@@ -127,14 +131,12 @@ public class XiaomanCustomerServiceImpl extends ServiceImpl<XiaomanCustomerMappe
|
|
|
updateById(customer);
|
|
|
}else {
|
|
|
|
|
|
- //TODO 获取详情
|
|
|
String customerDetailJson = xiaomanApiService.getCustomerDetail(customer.getCompanyId());
|
|
|
XiaomanCustomerInfoJson xiaomanCustomerInfoJson = new XiaomanCustomerInfoJson();
|
|
|
xiaomanCustomerInfoJson.setCompanyId(customer.getCompanyId());
|
|
|
xiaomanCustomerInfoJson.setJson(customerDetailJson);
|
|
|
xiaomanCustomerInfoJsonService.save(xiaomanCustomerInfoJson);
|
|
|
|
|
|
- //TODO 更新数据
|
|
|
CustomerInfoVo infoVo = HandleXiaomanData.handleDate(customerDetailJson, new TypeReference<R<CustomerInfoVo>>() {
|
|
|
});
|
|
|
//小满客户 =》 客户
|
|
@@ -181,20 +183,61 @@ public class XiaomanCustomerServiceImpl extends ServiceImpl<XiaomanCustomerMappe
|
|
|
DynamicDataSourceContextHolder.poll();
|
|
|
}
|
|
|
//TODO 标签tag customer_tag
|
|
|
- vo.getTag().stream().map(CustomerInfoVo.Tag::getTagName).collect(Collectors.joining(","));
|
|
|
+ if (!vo.getTag().isEmpty()){
|
|
|
+ Set<String> tags = new HashSet<>();
|
|
|
+ vo.getTag().forEach(x->{
|
|
|
+ List<DictTenantDataVo> customerTag = DictUtils.getDictList("customer_tag");
|
|
|
+ AtomicReference<String> key = new AtomicReference<>("");
|
|
|
+ customerTag.forEach(tag ->{
|
|
|
+ if (tag.getDictValue().equals(x.getTagName())){
|
|
|
+ key.set(tag.getDictKey());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (StringUtils.isNull(key)){
|
|
|
+ xiaomanApiService.dealCustomerTagDict(x.getTagName(),x.getTagId());
|
|
|
+ tags.add(x.getTagId());
|
|
|
+ }else {
|
|
|
+ tags.add(String.valueOf(key));
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ customer.setTag(String.join(",",tags));
|
|
|
+ }
|
|
|
|
|
|
//客户名称
|
|
|
customer.setName(vo.getName());
|
|
|
//客户简称
|
|
|
customer.setShortName(vo.getShortName());
|
|
|
|
|
|
- //TODO 客户来源source customer_source
|
|
|
- String.join(",",vo.getOriginList());
|
|
|
+ if (!vo.getOriginList().isEmpty()){
|
|
|
+ List<DictTenantDataVo> customerSource = DictUtils.getDictList("customer_source");
|
|
|
+ Set<String> sources = new HashSet<>();
|
|
|
+ vo.getOriginList().forEach(x->{
|
|
|
+ customerSource.forEach(tag ->{
|
|
|
+ if (tag.getDictValue().equals(x)){
|
|
|
+ sources.add(tag.getDictKey());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ customer.setSource(String.join(",",sources));
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
//客户规模
|
|
|
customer.setScaleId(vo.getScaleId());
|
|
|
- //TODO 客户来源status customer_status
|
|
|
- vo.getTrailStatus();
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(vo.getTrailStatus())){
|
|
|
+ AtomicReference<String> status = new AtomicReference<>("");
|
|
|
+ List<DictTenantDataVo> customerSource = DictUtils.getDictList("customer_status");
|
|
|
+ customerSource.forEach(tag ->{
|
|
|
+ if (tag.getDictValue().equals(vo.getTrailStatus())){
|
|
|
+ status.set(tag.getDictKey());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ customer.setStatus(String.valueOf(status));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
//公司网址
|
|
|
customer.setHomepage(vo.getHomepage());
|
|
@@ -208,49 +251,39 @@ public class XiaomanCustomerServiceImpl extends ServiceImpl<XiaomanCustomerMappe
|
|
|
customer.setRemark(vo.getRemark());
|
|
|
|
|
|
|
|
|
- //业务员ID
|
|
|
+ //联系人
|
|
|
if (!vo.getCustomers().isEmpty()){
|
|
|
Map<String, CustomerUser> collect = customerUserService.lambdaQuery()
|
|
|
.eq(CustomerUser::getCustomerId, customer.getId())
|
|
|
.list().stream().collect(Collectors.toMap(CustomerUser::getEmail, Function.identity()));
|
|
|
-
|
|
|
- Set<String > str = new HashSet<>();
|
|
|
+ //1、小满客户的联系人email为空,不做同步
|
|
|
+ //2、小满客户的联系人email与客户表联系人相匹配,以小满为主修改联系人信息
|
|
|
+ //3、小满客户的联系人email与客户表联系人不匹配,以小满为主新增联系人信息
|
|
|
for (CustomerInfoVo.Customer cus :vo.getCustomers()){
|
|
|
- if ( !str.contains(customer.getId()+"_"+ cus.getEmail())){
|
|
|
- //如果email匹配成功新增 ,否则修改
|
|
|
+ if (StringUtils.isNotEmpty(cus.getEmail())){
|
|
|
+ //如果email匹配成功新增 ,以小满为主修改客户信息
|
|
|
if (collect.containsKey(cus.getEmail()) ){
|
|
|
- List<Map> maps = new ArrayList<>();
|
|
|
CustomerUser customerUser = collect.get(cus.getEmail());
|
|
|
- if (StringUtils.isNotEmpty(customerUser.getContactJson())) {
|
|
|
- maps = JSON.parseArray(customerUser.getContactJson(), Map.class);
|
|
|
- }
|
|
|
- for (CustomerInfoVo.Contact contact: cus.getContact()){
|
|
|
- if (StringUtils.isNotEmpty(customerUser.getContactJson())){
|
|
|
- for (Map map:maps){
|
|
|
- if (!contact.getValue().equals(map.get("contactNo")) && !contact.getType().equals(map.get("type"))){
|
|
|
- Map map1 = new HashMap();
|
|
|
- map1.put("type",contact.getType());
|
|
|
- map1.put("contactNo",contact.getValue());
|
|
|
- maps.add(map1);
|
|
|
- }else {
|
|
|
- System.out.println();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }else {
|
|
|
+ customerUser.setName(cus.getName());
|
|
|
+ customerUser.setEmail(cus.getEmail());
|
|
|
+ List<Map> maps = new ArrayList<>();
|
|
|
+ if (! cus.getContact().isEmpty()) {
|
|
|
+ for (CustomerInfoVo.Contact contact : cus.getContact()) {
|
|
|
Map map1 = new HashMap();
|
|
|
- map1.put("type",contact.getType());
|
|
|
- map1.put("contactNo",contact.getValue());
|
|
|
+ map1.put("type", contact.getType());
|
|
|
+ map1.put("contactNo", contact.getValue());
|
|
|
maps.add(map1);
|
|
|
}
|
|
|
-
|
|
|
+ }else {
|
|
|
+ Map map1 = new HashMap();
|
|
|
+ map1.put("type", "");
|
|
|
+ map1.put("contactNo", "");
|
|
|
+ maps.add(map1);
|
|
|
}
|
|
|
- customerUser.setEmail(cus.getEmail());
|
|
|
+ customerUser.setPhone(cus.getTel());
|
|
|
customerUser.setContactJson(JSON.toJSONString(maps));
|
|
|
- str.add(customer.getId()+"_"+ cus.getEmail());
|
|
|
customerUserService.updateById(customerUser);
|
|
|
}else {
|
|
|
-
|
|
|
CustomerUser customerUser = new CustomerUser();
|
|
|
customerUser.setCustomerId(customer.getId());
|
|
|
customerUser.setName(cus.getName());
|
|
@@ -269,18 +302,20 @@ public class XiaomanCustomerServiceImpl extends ServiceImpl<XiaomanCustomerMappe
|
|
|
map1.put("contactNo", "");
|
|
|
maps.add(map1);
|
|
|
}
|
|
|
-// customerUser.setPhone(cus.getTel());
|
|
|
+ customerUser.setPhone(cus.getTel());
|
|
|
customerUser.setContactJson(JSON.toJSONString(maps));
|
|
|
-
|
|
|
- str.add(customer.getId()+"_"+ cus.getEmail());
|
|
|
customerUserService.save(customerUser);
|
|
|
|
|
|
+ //新增后添加至map中
|
|
|
+ collect.put(customerUser.getEmail(),customerUser);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
+ customer.setCountryName(vo.getCountryName());
|
|
|
customerService.updateById(customer);
|
|
|
}
|
|
|
|
|
@@ -296,5 +331,12 @@ public class XiaomanCustomerServiceImpl extends ServiceImpl<XiaomanCustomerMappe
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ @Override
|
|
|
+ public void initAllList() {
|
|
|
+ xiaomanApiService.initAllList();
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public void updateList() {
|
|
|
+ xiaomanApiService.updateList();
|
|
|
+ }
|
|
|
}
|