From 9ad4559d0ca58d678f5940f789df020dd66cad68 Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期四, 11 七月 2024 16:32:28 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 server/service/src/main/java/com/doumee/biz/zbom/impl/ZbomCRMServiceImpl.java |  116 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 116 insertions(+), 0 deletions(-)

diff --git a/server/service/src/main/java/com/doumee/biz/zbom/impl/ZbomCRMServiceImpl.java b/server/service/src/main/java/com/doumee/biz/zbom/impl/ZbomCRMServiceImpl.java
new file mode 100644
index 0000000..80212ef
--- /dev/null
+++ b/server/service/src/main/java/com/doumee/biz/zbom/impl/ZbomCRMServiceImpl.java
@@ -0,0 +1,116 @@
+package com.doumee.biz.zbom.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.doumee.biz.zbom.ZbomCRMService;
+import com.doumee.biz.zbom.model.CrmCustomerInfoModel;
+import com.doumee.biz.zbom.model.CrmCustomerSubmmitModel;
+import com.doumee.core.utils.Constants;
+import com.doumee.core.utils.HttpsUtil;
+import com.doumee.dao.business.CrmInterfaceLogMapper;
+import com.doumee.dao.business.CustomerLogMapper;
+import com.doumee.dao.business.model.CrmInterfaceLog;
+import com.doumee.dao.business.model.CustomerLog;
+import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Service;
+
+import java.util.*;
+
+/**
+ * 蹇楅偊CRM瀹㈡埛淇℃伅鎻愪氦鎺ュ彛
+ * @author 姹熻箘韫�
+ * @date 2023/11/30 15:33
+ */
+@Service
+public class ZbomCRMServiceImpl implements ZbomCRMService {
+
+    @Autowired
+    private CustomerLogMapper customerLogMapper;
+    @Autowired
+    private CrmInterfaceLogMapper crmInterfaceLogMapper;
+
+    @Autowired
+    private RedisTemplate<String, Object> redisTemplate;
+
+    /**
+     * 蹇楅偊瀹㈡埛淇℃伅鎻愪氦鎺ュ彛
+     * @param entity
+     * @return
+     */
+    @Override
+    public int postDataToCrm(CrmCustomerSubmmitModel entity )  {
+        // TODO Auto-generated method stub
+        int status = 2;
+        if(entity==null || entity.getCusInfo()==null || entity.getCusInfo().size() ==0){
+            return status;
+        }
+        String type = "postCusData";
+        String appid = (String) redisTemplate.opsForValue().get(Constants.RedisKeys.ZBOM_CRM_API_KEY);
+        String urlStr =  (String)redisTemplate.opsForValue().get(Constants.RedisKeys.ZBOM_CRM_API_URL) ;
+
+        long _t = System.currentTimeMillis();
+        String crmInfo="鎻愪氦澶辫触";
+        if (StringUtils.isNotBlank(appid)||StringUtils.isNotBlank(urlStr)) {
+            String token = DigestUtils.md5Hex(type + _t + appid);
+            String url = urlStr + "?type=" + type + "&_t=" + _t + "&token=" + token;// 鎻愪氦CRM鍦板潃
+            String param = JSONObject.toJSONString(entity);
+            int success =1;
+            String result = null;
+            try {
+                  result = HttpsUtil.postJson(url,param);
+                if (StringUtils.isNotBlank(result)) {
+                    JSONObject r = JSONObject.parseObject(result.replace("(", "").replace(")", ""));
+                    if (r != null && (StringUtils.equalsIgnoreCase(r.getString("code"), "1")
+                            || StringUtils.equalsIgnoreCase(r.getString("code"), "2"))) {
+                          status = 1;
+                          crmInfo="鎻愪氦鎴愬姛";
+                        success =0;
+                    }else{
+                        status = 2;
+                        crmInfo="鎻愪氦澶辫触["+ result+"]";
+                    }
+                }
+            }catch (Exception e){
+                e.printStackTrace();
+                crmInfo+= e.getMessage();
+            }finally {
+                saveInterfaceLog(url,"蹇楅偊CRM瀹㈡埛鐣欒祫淇℃伅鎻愪氦",param,success,result);
+            }
+        }else{
+            status = 2;
+            crmInfo="鎻愪氦澶辫触crm閰嶇疆鏈夎锛宎ppid:["+ appid+"]"+"url:["+ urlStr+"]";
+        }
+        List<Long> idList = new ArrayList<>();
+        for(CrmCustomerInfoModel info : entity.getCusInfo()){
+            idList.add(info.getId());
+        }
+        // 濡傛灉鎻愪氦鎴愬姛
+        CustomerLog d = new CustomerLog();
+        d.setId(entity.getCusInfo().get(0).getId());
+        d.setCrmStatus(Constants.ONE);
+        customerLogMapper.update(null,new UpdateWrapper<CustomerLog>().lambda()
+                .in(CustomerLog::getId,idList)
+                .set(CustomerLog::getCrmStatus,Constants.ONE )
+                .set(CustomerLog::getCrmInfo,crmInfo )
+                .set(CustomerLog::getCrmDate,new Date() ));// 鏇存柊鐘舵��
+        return status;// 榛樿澶辫触
+    }
+    public  void  saveInterfaceLog(String url,String name,String  param,Integer success,String respone){
+            CrmInterfaceLog log = new CrmInterfaceLog();
+            log.setCreateDate(new Date());
+            log.setUrl(url);
+            log.setEditDate(log.getCreateDate());
+            log.setPlat(Constants.ZERO);
+            log.setName(name);
+            log.setIsdeleted(Constants.ZERO);
+            log.setRequest(param);
+            log.setType(Constants.ONE);
+            log.setSuccess(success);
+            log.setRepose(respone);
+            crmInterfaceLogMapper.insert(log);
+    }
+}

--
Gitblit v1.9.3