lqh 1 年之前
父节点
当前提交
289d811275

+ 1 - 1
hx-customer/src/main/java/com/fjhx/customer/contants/XiaomanContant.java

@@ -24,7 +24,7 @@ public class XiaomanContant {
     public static final int DELAY_DELETE_KEY_TIME = 300;
 
 
-    public static final int PAGE_SIZE = 20;
+    public static final int PAGE_SIZE = 500;
     public static final String TENANT_ID = "ehsd";
 
 }

+ 22 - 21
hx-customer/src/main/java/com/fjhx/customer/controller/xiaoman/XiaomanCustomerController.java

@@ -1,5 +1,7 @@
 package com.fjhx.customer.controller.xiaoman;
 
+import com.fjhx.customer.service.xiaoman.XiaomanApiService;
+import com.ruoyi.common.core.domain.AjaxResult;
 import org.springframework.web.bind.annotation.*;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.fjhx.customer.entity.xiaoman.vo.XiaomanCustomerVo;
@@ -9,6 +11,7 @@ import com.ruoyi.common.core.domain.BaseSelectDto;
 import com.fjhx.customer.service.xiaoman.XiaomanCustomerService;
 import org.springframework.beans.factory.annotation.Autowired;
 
+import javax.annotation.Resource;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicBoolean;
 
@@ -25,8 +28,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
 public class XiaomanCustomerController {
 
 
-
-
     @Autowired
     private XiaomanCustomerService xiaomanCustomerService;
 
@@ -77,26 +78,26 @@ public class XiaomanCustomerController {
     public void delete(@RequestBody BaseSelectDto dto) {
         xiaomanCustomerService.delete(dto.getId());
     }
+    /**
+     * 小满客户表删除
+     */
+    @PostMapping("/initAllList")
+    public AjaxResult initAllList() {
+        try {
+            xiaomanCustomerService.initAllList();
+            return AjaxResult.success();
+        }catch (Exception e){
+            return AjaxResult.error(e.getMessage());
+        }
+    }
 
 
+    /**
+     * 小满客户表删除
+     */
+    @PostMapping("/updateList")
+    public void updateList() {
+        xiaomanCustomerService.updateList();
+    }
 
-//    private static final AtomicBoolean isRunning = new AtomicBoolean(false);
-//    /**
-//     * 匹配小满客户数据
-//     * @param xiaomanCustomerDto
-//     */
-//    @PostMapping("/aatchingData")
-//    public synchronized void aatchingData(@RequestBody XiaomanCustomerDto xiaomanCustomerDto) {
-//        // 检查是否已有线程在执行此方法
-//        if (isRunning.compareAndSet(false, true)) {
-//            try {
-//                xiaomanCustomerService.add(xiaomanCustomerDto);
-//            } finally {
-//                // 在方法执行完毕后设置 isRunning 为 false
-//                isRunning.set(false);
-//            }
-//        } else {
-//            throw new IllegalStateException("Another request is currently being processed. Please try again later.");
-//        }
-//    }
 }

+ 5 - 1
hx-customer/src/main/java/com/fjhx/customer/entity/customer/po/Customer.java

@@ -151,7 +151,7 @@ public class Customer extends BasePo {
     private Long companyId;
 
     /**
-     * 客户简称
+     * 小满客户简称
      */
     private String shortName;
 
@@ -181,5 +181,9 @@ public class Customer extends BasePo {
      * 小满备注
      */
     private String remark;
+    /**
+     * 小满国家
+     */
+    private String countryName;
 
 }

+ 0 - 1
hx-customer/src/main/java/com/fjhx/customer/entity/xiaoman/po/XiaomanCustomer.java

@@ -46,7 +46,6 @@ public class XiaomanCustomer {
     /**
      * 公司简称
      */
-
     @JsonProperty("short_name")
     private String shortName;
 

+ 3 - 0
hx-customer/src/main/java/com/fjhx/customer/service/xiaoman/XiaomanApiService.java

@@ -17,10 +17,13 @@ public interface XiaomanApiService {
 
     String getCustomerDetail(Long companyId);
 
+
     void updateList();
 
     @DSTransactional
     void getSelectorData();
 
     void updateXiaomanData(XiaomanUpdateInfoVO xiaomanUpdateInfoVO);
+
+    void dealCustomerTagDict(String label,String key);
 }

+ 3 - 0
hx-customer/src/main/java/com/fjhx/customer/service/xiaoman/XiaomanCustomerService.java

@@ -52,4 +52,7 @@ public interface XiaomanCustomerService  {
     void delete(Long id);
 
     void handleSaveOrUpdate(List<CustomerApiVo> customerApiVoList, Set<Long> allCustomer);
+
+    void initAllList();
+    void updateList();
 }

+ 16 - 3
hx-customer/src/main/java/com/fjhx/customer/service/xiaoman/impl/XiaomanApiServiceImpl.java

@@ -50,12 +50,10 @@ public class XiaomanApiServiceImpl implements XiaomanApiService {
     @Resource
     DictTenantDataService dictTenantDataService;
 
+//    @DSTransactional
     @Override
-    @DSTransactional
     @Async
     public void initAllList() {
-        stringRedisTemplate.delete(XiaomanContant.TASK_STATUS_KEY);
-        stringRedisTemplate.opsForValue().set(XiaomanContant.TASK_STATUS_DESC_KEY, "全量更新出现异常,已停止");
         boolean result = setNxWithExpiration(XiaomanContant.TASK_STATUS_KEY, XiaomanContant.TASK_STATUS_VALUE, XiaomanContant.DELAY_DELETE_KEY_TIME);
         if (!result) {
             String mes = stringRedisTemplate.opsForValue().get(XiaomanContant.TASK_STATUS_DESC_KEY);
@@ -63,6 +61,8 @@ public class XiaomanApiServiceImpl implements XiaomanApiService {
         }
         stringRedisTemplate.opsForValue().set(XiaomanContant.TASK_STATUS_DESC_KEY, "全量更新正在进行中");
         try {
+            getSelectorData();
+
             XiaomanConfig config = xiaomanConfigService.getConfig();
             String token = config.getAccessToken();
             List<XiaomanCustomerVo> list = xiaomanCustomerService.getList(new XiaomanCustomerSelectDto());
@@ -321,4 +321,17 @@ public class XiaomanApiServiceImpl implements XiaomanApiService {
             dictTenantDataService.saveBatch(list);
         }
     }
+
+    @Override
+    public void dealCustomerTagDict(String label,String key) {
+
+        DictTenantData dictTenantData = new DictTenantData();
+        dictTenantData.setDictCode("customer_tag");
+        dictTenantData.setDictValue(label);
+        dictTenantData.setDictKey(key);
+        dictTenantData.setTenantId(XiaomanContant.TENANT_ID);
+        dictTenantData.setSort(100);
+        dictTenantDataService.save(dictTenantData);
+
+    }
 }

+ 1 - 1
hx-customer/src/main/java/com/fjhx/customer/service/xiaoman/impl/XiaomanCustomerInfoJsonServiceImpl.java

@@ -1,5 +1,6 @@
 package com.fjhx.customer.service.xiaoman.impl;
 
+import cn.hutool.core.util.ObjectUtil;
 import com.fjhx.customer.entity.xiaoman.po.XiaomanCustomerInfoJson;
 import com.fjhx.customer.mapper.xiaoman.XiaomanCustomerInfoJsonMapper;
 import com.fjhx.customer.service.xiaoman.XiaomanCustomerInfoJsonService;
@@ -29,7 +30,6 @@ public class XiaomanCustomerInfoJsonServiceImpl extends ServiceImpl<XiaomanCusto
     @Override
     public Page<XiaomanCustomerInfoJsonVo> getPage(XiaomanCustomerInfoJsonSelectDto dto) {
         IWrapper<XiaomanCustomerInfoJson> wrapper = getWrapper();
-        wrapper.orderByDesc("xcij", XiaomanCustomerInfoJson::getCompanyId);
         Page<XiaomanCustomerInfoJsonVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
         return page;
     }

+ 89 - 47
hx-customer/src/main/java/com/fjhx/customer/service/xiaoman/impl/XiaomanCustomerServiceImpl.java

@@ -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();
+    }
 }

+ 3 - 2
hx-customer/src/main/resources/mapper/customer/CustomerMapper.xml

@@ -30,7 +30,8 @@
             c.fax,
             c.tel_area_code,
             c.tel,
-            c.remark
+            c.remark,
+            c.country_name
         from customer c
             ${ew.customSqlSegment}
     </select>
@@ -61,7 +62,7 @@
             c.fax,
             c.tel_area_code,
             c.tel,
-            c.remark
+            c.country_name
         from customer c
             ${ew.customSqlSegment}
     </select>