浏览代码

1、入库

lqh 1 年之前
父节点
当前提交
fb82496d35

+ 38 - 0
hx-customer/src/main/java/com/fjhx/customer/entity/customer/po/Customer.java

@@ -2,6 +2,7 @@ package com.fjhx.customer.entity.customer.po;
 
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonProperty;
 import com.ruoyi.common.core.domain.BasePo;
 import lombok.Getter;
 import lombok.Setter;
@@ -144,4 +145,41 @@ public class Customer extends BasePo {
      */
     private Date lastFollowTime;
 
+    /**
+     * 小满客户表客户ID
+     */
+    private Long companyId;
+
+    /**
+     * 客户简称
+     */
+    private String shortName;
+
+    /**
+     * 小满公司网站
+     */
+    private String homepage;
+    /**
+     * 小满公司网站
+     */
+    private Long scaleId;
+
+    /**
+     * 小满传真
+     */
+    private String fax;
+
+    /**
+     * 小满电话区号
+     */
+    private String telAreaCode;
+    /**
+     * 小满电话
+     */
+    private String tel;
+    /**
+     * 小满备注
+     */
+    private String remark;
+
 }

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

@@ -51,10 +51,10 @@ public class XiaomanCustomer {
     private String shortName;
 
     /**
-     * 公司编号
+     * 客户代码
      */
     @JsonProperty("serial_id")
-    private Integer serialId;
+    private String serialId;
 
     /**
      * 最近更新时间

+ 1 - 1
hx-customer/src/main/java/com/fjhx/customer/entity/xiaoman/vo/CustomerInfoVo.java

@@ -157,7 +157,7 @@ public class CustomerInfoVo {
     private String city;
 
     @JsonProperty("scale_id")
-    private int scaleId;
+    private Long scaleId;
 
     @JsonProperty("trail_status")
     private String trailStatus;

+ 2 - 2
hx-customer/src/main/java/com/fjhx/customer/handle/HandleXiaomanData.java

@@ -53,7 +53,7 @@ public class HandleXiaomanData {
     private static StringRedisTemplate redisTemplate = SpringUtils.getBean(StringRedisTemplate.class);
     private static DictTenantDataService dictTenantDataService = SpringUtils.getBean(DictTenantDataService.class);
     private static final int PAGE_SIZE = 20;
-    private static final String TENANT_ID = "ehsd";
+    public static final String TENANT_ID = "ehsd";
     public static void main(String[] args) {
         String filePath = "D:\\java_conding\\erhong\\hx-customer\\src\\main\\java\\com\\fjhx\\customer\\handle\\bbb.json";
         String jsonData = "";
@@ -130,7 +130,7 @@ public class HandleXiaomanData {
             String token = config.getAccessToken();
             List<XiaomanCustomerVo> list = xiaomanCustomerService.getList(new XiaomanCustomerSelectDto());
             Set<Long> collect = list.stream().map(XiaomanCustomerVo::getCompanyId).collect(Collectors.toSet());
-            int pageIndex = 4326;
+            int pageIndex = 1;
             int totalPage;
             do {
                 String str = getData(XiaomanContant.ALL_CUSTOMER_API_URL, token, initPageParams(pageIndex));

+ 173 - 8
hx-customer/src/main/java/com/fjhx/customer/service/xiaoman/impl/XiaomanCustomerServiceImpl.java

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

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

@@ -22,7 +22,15 @@
             c.create_time,
             c.update_user,
             c.update_time,
-            c.tag
+            c.tag,
+            c.company_id,
+            c.short_name,
+            c.homepage,
+            c.scale_id,
+            c.fax,
+            c.tel_area_code,
+            c.tel,
+            c.remark
         from customer c
             ${ew.customSqlSegment}
     </select>
@@ -45,7 +53,15 @@
             c.create_time,
             c.update_user,
             c.update_time,
-            c.tag
+            c.tag,
+            c.company_id,
+            c.short_name,
+            c.homepage,
+            c.scale_id,
+            c.fax,
+            c.tel_area_code,
+            c.tel,
+            c.remark
         from customer c
             ${ew.customSqlSegment}
     </select>