|
@@ -1,18 +1,30 @@
|
|
|
package com.fjhx.customer.service.xiaoman.impl;
|
|
|
|
|
|
+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.entity.customer.po.Customer;
|
|
|
+import com.fjhx.customer.entity.customer.po.CustomerUser;
|
|
|
import com.fjhx.customer.entity.xiaoman.po.XiaomanCustomer;
|
|
|
import com.fjhx.customer.entity.xiaoman.po.XiaomanCustomerInfoJson;
|
|
|
import com.fjhx.customer.entity.xiaoman.vo.CustomerApiVo;
|
|
|
import com.fjhx.customer.entity.xiaoman.vo.CustomerInfoVo;
|
|
|
-import com.fjhx.customer.entity.xiaoman.vo.CustomerListApiVo;
|
|
|
import com.fjhx.customer.handle.HandleXiaomanData;
|
|
|
import com.fjhx.customer.handle.R;
|
|
|
import com.fjhx.customer.mapper.xiaoman.XiaomanCustomerMapper;
|
|
|
-import com.fjhx.customer.service.xiaoman.XiaomanCustomerInfoJsonService;
|
|
|
+import com.fjhx.customer.service.customer.CustomerService;
|
|
|
+import com.fjhx.customer.service.customer.CustomerUserService;
|
|
|
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.ruoyi.common.core.domain.entity.SysUser;
|
|
|
+import com.ruoyi.common.utils.SecurityUtils;
|
|
|
+import com.ruoyi.common.utils.StringUtils;
|
|
|
+import com.ruoyi.system.service.impl.SysUserServiceImpl;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.fjhx.customer.entity.xiaoman.vo.XiaomanCustomerVo;
|
|
@@ -23,9 +35,9 @@ import cn.hutool.core.bean.BeanUtil;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.*;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import static com.ruoyi.common.utils.wrapper.IWrapper.getWrapper;
|
|
|
|
|
@@ -43,6 +55,15 @@ public class XiaomanCustomerServiceImpl extends ServiceImpl<XiaomanCustomerMappe
|
|
|
@Resource
|
|
|
private XiaomanCustomerInfoJsonServiceImpl xiaomanCustomerInfoJsonService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private CustomerService customerService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private CustomerUserService customerUserService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private SysUserServiceImpl sysUserService;
|
|
|
+
|
|
|
@Override
|
|
|
public List<XiaomanCustomerVo> getList(XiaomanCustomerSelectDto dto) {
|
|
|
IWrapper<XiaomanCustomer> wrapper = getWrapper();
|
|
@@ -87,7 +108,7 @@ public class XiaomanCustomerServiceImpl extends ServiceImpl<XiaomanCustomerMappe
|
|
|
for (XiaomanCustomer customer : xiaomanCustomerList){
|
|
|
try {
|
|
|
if (allCustomer.contains(customer.getCompanyId())){
|
|
|
- updateById(customer);
|
|
|
+
|
|
|
//TODO 获取详情
|
|
|
String customerDetailJson = HandleXiaomanData.getCustomerDetail(customer.getCompanyId());
|
|
|
XiaomanCustomerInfoJson xiaomanCustomerInfoJson = new XiaomanCustomerInfoJson();
|
|
@@ -97,9 +118,11 @@ public class XiaomanCustomerServiceImpl extends ServiceImpl<XiaomanCustomerMappe
|
|
|
//TODO 更新数据
|
|
|
CustomerInfoVo infoVo = HandleXiaomanData.handleDate(customerDetailJson, new TypeReference<R<CustomerInfoVo>>() {
|
|
|
});
|
|
|
- System.out.println("1");
|
|
|
+ Long s = customerConversion(infoVo);
|
|
|
+ customer.setCustomerId(s);
|
|
|
+ updateById(customer);
|
|
|
}else {
|
|
|
- save(customer);
|
|
|
+
|
|
|
//TODO 获取详情
|
|
|
String customerDetailJson = HandleXiaomanData.getCustomerDetail(customer.getCompanyId());
|
|
|
XiaomanCustomerInfoJson xiaomanCustomerInfoJson = new XiaomanCustomerInfoJson();
|
|
@@ -110,6 +133,10 @@ public class XiaomanCustomerServiceImpl extends ServiceImpl<XiaomanCustomerMappe
|
|
|
//TODO 更新数据
|
|
|
CustomerInfoVo infoVo = HandleXiaomanData.handleDate(customerDetailJson, new TypeReference<R<CustomerInfoVo>>() {
|
|
|
});
|
|
|
+ //小满客户 =》 客户
|
|
|
+ Long s = customerConversion(infoVo);
|
|
|
+ customer.setCustomerId(s);
|
|
|
+ save(customer);
|
|
|
System.out.println("2");
|
|
|
}
|
|
|
}catch (Exception e){
|
|
@@ -119,4 +146,142 @@ public class XiaomanCustomerServiceImpl extends ServiceImpl<XiaomanCustomerMappe
|
|
|
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 小满客户 =》 客户
|
|
|
+ * @param vo
|
|
|
+ */
|
|
|
+ public Long customerConversion(CustomerInfoVo vo) {
|
|
|
+ SecurityUtils.setTenantId(HandleXiaomanData.TENANT_ID);
|
|
|
+ List<Customer> list = customerService.lambdaQuery()
|
|
|
+ .eq(StringUtils.isNotEmpty(vo.getName()), Customer::getName, vo.getName())
|
|
|
+ .or()
|
|
|
+ .eq(StringUtils.isNotEmpty(vo.getShortName()), Customer::getName, vo.getShortName())
|
|
|
+ .list();
|
|
|
+
|
|
|
+ if (!list.isEmpty()){
|
|
|
+ for (Customer customer :list){
|
|
|
+ //小满公司ID
|
|
|
+ customer.setCompanyId(vo.getCompanyId());
|
|
|
+ //公司编号
|
|
|
+ customer.setCustomerCode(vo.getSerialId());
|
|
|
+ //业务员ID
|
|
|
+ if (!vo.getOwner().isEmpty()){
|
|
|
+ DynamicDataSourceContextHolder.push(SourceConstant.BASE);
|
|
|
+ SysUser sysUser = sysUserService.lambdaQuery().eq(SysUser::getNickNameEn, vo.getOwner().get(0).getName()).one();
|
|
|
+ if (Objects.nonNull(sysUser)){
|
|
|
+ customer.setUserId(sysUser.getUserId());
|
|
|
+ }
|
|
|
+ DynamicDataSourceContextHolder.poll();
|
|
|
+ }
|
|
|
+ //TODO 标签tag customer_tag
|
|
|
+ vo.getTag().stream().map(CustomerInfoVo.Tag::getTagName).collect(Collectors.joining(","));
|
|
|
+
|
|
|
+ //客户名称
|
|
|
+ customer.setName(vo.getName());
|
|
|
+ //客户简称
|
|
|
+ customer.setShortName(vo.getShortName());
|
|
|
+
|
|
|
+ //TODO 客户来源source customer_source
|
|
|
+ String.join(",",vo.getOriginList());
|
|
|
+
|
|
|
+ //客户规模
|
|
|
+ customer.setScaleId(vo.getScaleId());
|
|
|
+ //TODO 客户来源status customer_status
|
|
|
+ vo.getTrailStatus();
|
|
|
+
|
|
|
+ //公司网址
|
|
|
+ customer.setHomepage(vo.getHomepage());
|
|
|
+ //小满传真
|
|
|
+ customer.setFax(vo.getFax());
|
|
|
+ //小满电话区号
|
|
|
+ customer.setTelAreaCode(vo.getTelAreaCode());
|
|
|
+ //小满电话
|
|
|
+ customer.setTel(vo.getTel());
|
|
|
+ //小满备注
|
|
|
+ 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()));
|
|
|
+
|
|
|
+
|
|
|
+ for (CustomerInfoVo.Customer cus :vo.getCustomers()){
|
|
|
+ //如果email匹配成功新增 ,否则修改
|
|
|
+ if (collect.containsKey(cus.getEmail())){
|
|
|
+ List<Map> maps = new ArrayList<>();
|
|
|
+ CustomerUser customerUser = collect.get(cus.getEmail());
|
|
|
+ for (CustomerInfoVo.Contact contact: cus.getContact()){
|
|
|
+ if (StringUtils.isNotEmpty(customerUser.getContactJson())){
|
|
|
+ maps = JSON.parseArray(customerUser.getContactJson(), Map.class);
|
|
|
+ for (Map map:maps){
|
|
|
+ if (!contact.getValue().equals(map.get("contactNo"))){
|
|
|
+ Map map1 = new HashMap();
|
|
|
+ map1.put("type",contact.getType());
|
|
|
+ map1.put("contactNo",contact.getValue());
|
|
|
+ maps.add(map1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }else {
|
|
|
+ Map map1 = new HashMap();
|
|
|
+ map1.put("type",contact.getType());
|
|
|
+ map1.put("contactNo",contact.getValue());
|
|
|
+ maps.add(map1);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ customerUser.setContactJson(JSON.toJSONString(maps));
|
|
|
+ customerUserService.updateById(customerUser);
|
|
|
+ }else {
|
|
|
+
|
|
|
+ CustomerUser customerUser = new CustomerUser();
|
|
|
+ customerUser.setCustomerId(customer.getId());
|
|
|
+ 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());
|
|
|
+ maps.add(map1);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ Map map1 = new HashMap();
|
|
|
+ map1.put("type", "");
|
|
|
+ map1.put("contactNo", "");
|
|
|
+ maps.add(map1);
|
|
|
+ }
|
|
|
+// customerUser.setPhone(cus.getTel());
|
|
|
+ customerUser.setContactJson(JSON.toJSONString(maps));
|
|
|
+ customerUserService.save(customerUser);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ customerService.updateById(customer);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ SecurityUtils.clearTenantId();
|
|
|
+ if (!list.isEmpty()) {
|
|
|
+ Long collect = list.stream().map(Customer::getId).collect(Collectors.toList()).get(0);
|
|
|
+ return collect;
|
|
|
+ }else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|