From fc1030ae8bd1da1fed6e6f7138cb63de605467ef Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期四, 11 七月 2024 16:31:46 +0800
Subject: [PATCH] 提交

---
 server/service/src/main/java/com/doumee/biz/zbom/impl/ZbomSMSServiceImpl.java       |  107 +++++++++++++++++
 server/service/src/main/java/com/doumee/dao/business/model/CrmInterfaceLog.java     |    2 
 server/service/src/main/java/com/doumee/biz/zbom/ZbomCRMService.java                |   19 +++
 server/service/src/main/java/com/doumee/biz/zbom/ZbomZhongTaiService.java           |    2 
 server/service/src/main/java/com/doumee/core/utils/Constants.java                   |    8 +
 server/service/src/main/java/com/doumee/biz/zbom/ZbomIAMService.java                |    2 
 server/service/src/main/java/com/doumee/biz/zbom/impl/ZbomCRMServiceImpl.java       |  116 +++++++++++++++++++
 server/service/src/main/java/com/doumee/service/business/InitService.java           |    4 
 server/service/src/main/java/com/doumee/biz/zbom/ZbomSMSService.java                |   14 ++
 server/service/src/main/java/com/doumee/biz/zbom/model/CrmCustomerInfoModel.java    |   42 +++++++
 server/service/src/main/java/com/doumee/biz/zbom/model/CrmCustomerSubmmitModel.java |   19 +++
 11 files changed, 332 insertions(+), 3 deletions(-)

diff --git a/server/service/src/main/java/com/doumee/biz/zbom/ZbomCRMService.java b/server/service/src/main/java/com/doumee/biz/zbom/ZbomCRMService.java
new file mode 100644
index 0000000..e78f898
--- /dev/null
+++ b/server/service/src/main/java/com/doumee/biz/zbom/ZbomCRMService.java
@@ -0,0 +1,19 @@
+package com.doumee.biz.zbom;
+
+import com.doumee.biz.zbom.model.CrmCustomerSubmmitModel;
+import com.doumee.biz.zbom.model.IamUpateShopModel;
+import com.doumee.biz.zbom.model.IamUpateUserModel;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * 蹇楅偊CRM瀵规帴涓氬姟鎺ュ彛
+ * @author 姹熻箘韫�
+ * @date 2023/11/30 15:33
+ */
+@Service
+public interface ZbomCRMService {
+
+    int postDataToCrm(CrmCustomerSubmmitModel entity );
+}
diff --git a/server/service/src/main/java/com/doumee/biz/zbom/ZbomIAMService.java b/server/service/src/main/java/com/doumee/biz/zbom/ZbomIAMService.java
index 67b62b6..59c90e8 100644
--- a/server/service/src/main/java/com/doumee/biz/zbom/ZbomIAMService.java
+++ b/server/service/src/main/java/com/doumee/biz/zbom/ZbomIAMService.java
@@ -9,7 +9,7 @@
 import java.util.List;
 
 /**
- * 浜哄憳淇℃伅琛⊿ervice瀹炵幇
+ * 蹇楅偊IAM瀵规帴涓氬姟鎺ュ彛
  * @author 姹熻箘韫�
  * @date 2023/11/30 15:33
  */
diff --git a/server/service/src/main/java/com/doumee/biz/zbom/ZbomSMSService.java b/server/service/src/main/java/com/doumee/biz/zbom/ZbomSMSService.java
new file mode 100644
index 0000000..906ae4e
--- /dev/null
+++ b/server/service/src/main/java/com/doumee/biz/zbom/ZbomSMSService.java
@@ -0,0 +1,14 @@
+package com.doumee.biz.zbom;
+
+import com.doumee.biz.zbom.model.CrmCustomerSubmmitModel;
+import org.springframework.stereotype.Service;
+
+/**
+ * 蹇楅偊鐭俊閫氶亾瀵规帴涓氬姟鎺ュ彛
+ * @author 姹熻箘韫�
+ * @date 2023/11/30 15:33
+ */
+@Service
+public interface ZbomSMSService {
+    boolean sendMessage(String content,String phone) ;
+}
diff --git a/server/service/src/main/java/com/doumee/biz/zbom/ZbomZhongTaiService.java b/server/service/src/main/java/com/doumee/biz/zbom/ZbomZhongTaiService.java
index eb02b13..49eabf5 100644
--- a/server/service/src/main/java/com/doumee/biz/zbom/ZbomZhongTaiService.java
+++ b/server/service/src/main/java/com/doumee/biz/zbom/ZbomZhongTaiService.java
@@ -5,7 +5,7 @@
 import org.springframework.stereotype.Service;
 
 /**
- * 浜哄憳淇℃伅琛⊿ervice瀹炵幇
+ * 蹇楅偊涓彴瀵规帴涓氬姟鎺ュ彛
  * @author 姹熻箘韫�
  * @date 2023/11/30 15:33
  */
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);
+    }
+}
diff --git a/server/service/src/main/java/com/doumee/biz/zbom/impl/ZbomSMSServiceImpl.java b/server/service/src/main/java/com/doumee/biz/zbom/impl/ZbomSMSServiceImpl.java
new file mode 100644
index 0000000..5ee6a41
--- /dev/null
+++ b/server/service/src/main/java/com/doumee/biz/zbom/impl/ZbomSMSServiceImpl.java
@@ -0,0 +1,107 @@
+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.ZbomSMSService;
+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.stereotype.Service;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 蹇楅偊CRM瀹㈡埛淇℃伅鎻愪氦鎺ュ彛
+ * @author 姹熻箘韫�
+ * @date 2023/11/30 15:33
+ */
+@Service
+public class ZbomSMSServiceImpl implements ZbomSMSService  {
+
+    @Autowired
+    private CustomerLogMapper customerLogMapper;
+    @Autowired
+    private CrmInterfaceLogMapper crmInterfaceLogMapper;
+
+    @Autowired
+    private RedisTemplate<String, Object> redisTemplate;
+
+    /**
+     * 蹇楅偊瀹㈡埛淇℃伅鎻愪氦鎺ュ彛
+     * @return
+     */
+    @Override
+    public   boolean sendMessage(String content,String phone) {
+        // TODO Auto-generated method stub
+        if(StringUtils.isBlank(content)){
+            return false;
+        }
+        String appkey = (String) redisTemplate.opsForValue().get(Constants.RedisKeys.ZBOM_SMS_API_KEY);
+        String urlStr =  (String)redisTemplate.opsForValue().get(Constants.RedisKeys.ZBOM_SMS_API_URL) ;
+        try {
+            StringBuffer sb = new StringBuffer(urlStr);
+            Integer _t = (int) System.currentTimeMillis();
+            // 鍚慡tringBuffer杩藉姞鐢ㄦ埛鍚�
+            sb.append("_t=" + _t);
+            sb.append("&smsphone=" + phone);
+            sb.append("&smscode=10005");
+            // 鍚慡tringBuffer杩藉姞瀵嗙爜锛堢櫥闄嗙綉椤电増锛屽湪绠$悊涓績--鍩烘湰璧勬枡--鎺ュ彛瀵嗙爜锛屾槸28浣嶇殑锛�
+            sb.append("&smsmsg=" + URLEncoder.encode(content.replace(" ", ""), "UTF-8"));
+            // 鍔犲瘑
+            // 497fbc01e744ef44001296b7466148e8
+            sb.append("&token=" + DigestUtils.md5Hex(phone + _t + appkey));
+
+            // 鍒涘缓url瀵硅薄
+            URL url = new URL(sb.toString());
+            // 鎵撳紑url杩炴帴
+            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+
+            // 璁剧疆url璇锋眰鏂瑰紡 鈥榞et鈥� 鎴栬�� 鈥榩ost鈥�
+            connection.setRequestMethod("POST");
+            connection.setConnectTimeout(500);
+            connection.setReadTimeout(500);
+            // 鍙戦��
+            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
+            // 杩斿洖鍙戦�佺粨鏋�
+            String inputline = in.readLine();
+            // 杩斿洖缁撴灉涓衡��0锛�20140009090990,1锛屾彁浜ゆ垚鍔熲�� 鍙戦�佹垚鍔� 鍏蜂綋瑙佽鏄庢枃妗�
+            System.out.println(inputline);
+            saveInterfaceLog(urlStr,"蹇楅偊鐭俊鍙戦�佹帴鍙�", sb.toString(), 0,inputline);
+            return true;//
+        }catch (Exception e){
+            return false;
+        }
+
+    }
+    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);
+    }
+}
diff --git a/server/service/src/main/java/com/doumee/biz/zbom/model/CrmCustomerInfoModel.java b/server/service/src/main/java/com/doumee/biz/zbom/model/CrmCustomerInfoModel.java
new file mode 100644
index 0000000..956be0c
--- /dev/null
+++ b/server/service/src/main/java/com/doumee/biz/zbom/model/CrmCustomerInfoModel.java
@@ -0,0 +1,42 @@
+package com.doumee.biz.zbom.model;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+@ApiModel("蹇楅偊CRM瀹㈡埛鐣欒祫鎻愪氦鏄庣粏鍙傛暟")
+public class CrmCustomerInfoModel implements Serializable {
+    @ApiModelProperty(value = "浜哄憳缂栫爜")
+    private Long id;
+    @ApiModelProperty(value = "濮撳悕")
+    private String name;
+    @ApiModelProperty(value = "鎵嬫満鍙�")
+    private String phone;
+    @ApiModelProperty(value = "璁捐甯堟墜鏈哄彿")
+    private String shopper;
+    @ApiModelProperty(value = "鏉ユ簮")
+    private String source;
+    @ApiModelProperty(value = "娓犻亾")
+    private String channel;
+    @ApiModelProperty(value = "鏃ユ湡 yyyy/MM/dd HH:mm")
+    private String date;
+    @ApiModelProperty(value = "鎺ㄨ崘浜烘墜鏈哄彿")
+    private String recphone;
+    @ApiModelProperty(value = "鎺ㄨ崘浜哄鍚�")
+    private String recname;
+    @ApiModelProperty(value = "鍘垮尯鍚嶇О")
+    private String areaname;
+    @ApiModelProperty(value = "鍘垮尯缂栫爜")
+    private String areacode;
+    @ApiModelProperty(value = "绯荤粺鐗堟湰鍙�")
+    private String sysversion;
+    @ApiModelProperty(value = "娴忚鍣ㄤ俊鎭�")
+    private String browser;
+    @ApiModelProperty(value = "灏忕▼搴弌penid")
+    private String openid;
+    @ApiModelProperty(value = "缁堢淇℃伅")
+    private String terminal;
+}
diff --git a/server/service/src/main/java/com/doumee/biz/zbom/model/CrmCustomerSubmmitModel.java b/server/service/src/main/java/com/doumee/biz/zbom/model/CrmCustomerSubmmitModel.java
new file mode 100644
index 0000000..b2af4d4
--- /dev/null
+++ b/server/service/src/main/java/com/doumee/biz/zbom/model/CrmCustomerSubmmitModel.java
@@ -0,0 +1,19 @@
+package com.doumee.biz.zbom.model;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.gson.annotations.SerializedName;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+@Data
+@ApiModel("蹇楅偊CRM瀹㈡埛鐣欒祫鎻愪氦鍙傛暟")
+public class CrmCustomerSubmmitModel implements Serializable {
+    @ApiModelProperty(value = "瀹㈡埛淇℃伅")
+    @JsonProperty("cus_info")
+    @SerializedName("cus_info")
+    private List<CrmCustomerInfoModel> cusInfo;
+}
diff --git a/server/service/src/main/java/com/doumee/core/utils/Constants.java b/server/service/src/main/java/com/doumee/core/utils/Constants.java
index aaf7e4e..2243869 100644
--- a/server/service/src/main/java/com/doumee/core/utils/Constants.java
+++ b/server/service/src/main/java/com/doumee/core/utils/Constants.java
@@ -318,6 +318,10 @@
     public static final String WX_PLATFORM_APPID = "WX_PLATFORM_APPID";
     public static final String WX_PLATFORM_SECRET = "WX_PLATFORM_SECRET";
     public static final String WX_PLATFORM_AUDIT_VISIT = "WX_PLATFORM_AUDIT_VISIT";
+    public static final String ZBOM_CRM_API_URL = "ZBOM_CRM_API_URL";
+    public static final String ZBOM_CRM_API_KEY = "ZBOM_CRM_API_KEY";
+    public static final String ZBOM_SMS_API_KEY = "ZBOM_SMS_API_KEY";
+    public static final String ZBOM_SMS_API_URL = "ZBOM_SMS_API_URL";
     public static final String WX_PLATFORM_PREFIX = "WX_PLATFORM_PREFIX";
 
 
@@ -329,6 +333,10 @@
         public static final String IMPORTING_MEMBER ="IMPORTING_MEMBER";
         public static final String IMPORTING_SHOP ="IMPORTING_SHOP";
         public static final String IAM_APPID ="IAM_APPID";
+        public static final String ZBOM_CRM_API_KEY ="ZBOM_CRM_API_KEY";
+        public static final String ZBOM_CRM_API_URL ="ZBOM_CRM_API_URL";
+        public static final String ZBOM_SMS_API_KEY ="ZBOM_SMS_API_KEY";
+        public static final String ZBOM_SMS_API_URL ="ZBOM_SMS_API_URL";
         public static final String IAM_APPKEY ="IAM_APPKEY";
         public static final String SHOP_TREE ="SHOP_TREE";
         public static final String ERP_TOKEN ="ERP_TOKEN";
diff --git a/server/service/src/main/java/com/doumee/dao/business/model/CrmInterfaceLog.java b/server/service/src/main/java/com/doumee/dao/business/model/CrmInterfaceLog.java
index df95b7c..51cc07a 100644
--- a/server/service/src/main/java/com/doumee/dao/business/model/CrmInterfaceLog.java
+++ b/server/service/src/main/java/com/doumee/dao/business/model/CrmInterfaceLog.java
@@ -59,7 +59,7 @@
 
     @ApiModelProperty(value = "鍦板潃淇℃伅")
     @ExcelColumn(name="鍦板潃淇℃伅")
-    private Date url;
+    private String url;
 
     @ApiModelProperty(value = "璇锋眰鍙傛暟")
     @ExcelColumn(name="璇锋眰鍙傛暟")
diff --git a/server/service/src/main/java/com/doumee/service/business/InitService.java b/server/service/src/main/java/com/doumee/service/business/InitService.java
index b29b458..b8660df 100644
--- a/server/service/src/main/java/com/doumee/service/business/InitService.java
+++ b/server/service/src/main/java/com/doumee/service/business/InitService.java
@@ -36,6 +36,10 @@
     public void initIamAppIdAndAppKey(){
         redisTemplate.opsForValue().set(Constants.RedisKeys.IAM_APPKEY,systemDictDataBiz.queryByCode(Constants.ZBOM,Constants.ZBOM_IAM_APPKEY).getCode());
         redisTemplate.opsForValue().set(Constants.RedisKeys.IAM_APPID,systemDictDataBiz.queryByCode(Constants.ZBOM,Constants.ZBOM_IAM_APPID).getCode());
+        redisTemplate.opsForValue().set(Constants.RedisKeys.ZBOM_CRM_API_KEY,systemDictDataBiz.queryByCode(Constants.ZBOM,Constants.ZBOM_CRM_API_KEY).getCode());
+        redisTemplate.opsForValue().set(Constants.RedisKeys.ZBOM_CRM_API_URL,systemDictDataBiz.queryByCode(Constants.ZBOM,Constants.ZBOM_CRM_API_URL).getCode());
+        redisTemplate.opsForValue().set(Constants.RedisKeys.ZBOM_SMS_API_URL,systemDictDataBiz.queryByCode(Constants.ZBOM,Constants.ZBOM_SMS_API_URL).getCode());
+        redisTemplate.opsForValue().set(Constants.RedisKeys.ZBOM_SMS_API_KEY,systemDictDataBiz.queryByCode(Constants.ZBOM,Constants.ZBOM_SMS_API_KEY).getCode());
     }
     @PostConstruct
     public void cacheShopTree(){

--
Gitblit v1.9.3