From 20b11236b4364034f52df294b9240776f539ede1 Mon Sep 17 00:00:00 2001 From: liukangdong <898885815@qq.com> Date: 星期二, 16 七月 2024 14:49:01 +0800 Subject: [PATCH] Merge branch 'master' of http://139.186.142.91:10010/r/productDev/zbomyoujia --- server/service/src/main/java/com/doumee/biz/zbom/impl/ZbomCRMServiceImpl.java | 262 ++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 190 insertions(+), 72 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 index f6d1d27..bd00ca2 100644 --- 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 @@ -1,10 +1,15 @@ package com.doumee.biz.zbom.impl; import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.TypeReference; 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.biz.zbom.model.crm.*; +import com.doumee.biz.zbom.model.crm.response.CRMBaseResponse; +import com.doumee.biz.zbom.model.crm.response.CRMCustomerListResponse; +import com.doumee.biz.zbom.model.crm.response.CRMDaogouBindListResponse; +import com.doumee.core.constants.ResponseStatus; +import com.doumee.core.exception.BusinessException; import com.doumee.core.utils.Constants; import com.doumee.core.utils.DateUtil; import com.doumee.core.utils.HttpsUtil; @@ -12,6 +17,7 @@ import com.doumee.dao.business.CustomerLogMapper; import com.doumee.dao.business.model.CrmInterfaceLog; import com.doumee.dao.business.model.CustomerLog; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -19,6 +25,7 @@ import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; +import java.net.URLEncoder; import java.util.*; /** @@ -27,6 +34,7 @@ * @date 2023/11/30 15:33 */ @Service +@Slf4j public class ZbomCRMServiceImpl implements ZbomCRMService { @Autowired @@ -38,93 +46,152 @@ private RedisTemplate<String, Object> redisTemplate; - @Override - @Async - public void dealCustomerLogData(CustomerLog customerLog){ - CrmCustomerSubmmitModel entity = new CrmCustomerSubmmitModel(); - List<CrmCustomerInfoModel> cusInfo = new ArrayList(); - CrmCustomerInfoModel crmCustomerInfoModel = new CrmCustomerInfoModel(); - crmCustomerInfoModel.setId(customerLog.getId()); - crmCustomerInfoModel.setName(customerLog.getName()); - crmCustomerInfoModel.setPhone(customerLog.getPhone()); - crmCustomerInfoModel.setAreaname(customerLog.getAreaName()); - crmCustomerInfoModel.setAreacode(customerLog.getAreaCode()); - crmCustomerInfoModel.setOpenid(customerLog.getOpenid()); - crmCustomerInfoModel.setSource(Constants.CrmSources.SOURCE_ZBJX); - crmCustomerInfoModel.setChannel(crmCustomerInfoModel.getSource()+"00"); - crmCustomerInfoModel.setDate(DateUtil.dateToString(customerLog.getCreateDate(),"yyyy/MM/dd HH:mm")); - cusInfo.add(crmCustomerInfoModel); - entity.setCusInfo(cusInfo); - this.postDataToCrm(entity); - - } - - /** * 蹇楅偊瀹㈡埛淇℃伅鎻愪氦鎺ュ彛 - * @param entity + * @param customerLog * @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; + @Async + public int dealCustomerLogData(CustomerLog customerLog){ + CrmCustomerInfoRequest entity = new CrmCustomerInfoRequest(); + entity.setId(customerLog.getId()); + entity.setName(customerLog.getName()); + entity.setPhone(zbomEncode(customerLog.getPhone())); + entity.setAreaname(customerLog.getAreaName()); + entity.setAreacode(customerLog.getAreaCode()); + entity.setOpenid(customerLog.getOpenid()); +// 鎻愪氦绫诲瀷 0-娴嬭瘯瑁呬慨椋庢牸锛�1-0鍏冨畾鍒讹紱2瑁呬慨璁$畻鍣� + if(Constants.equalsInteger(customerLog.getType(),Constants.ONE)){ + entity.setSource(CRMConstants.CRM_SOURCE.SOURCE_MP01); + entity.setChannel(CRMConstants.CRM_SOURCE.SOURCE_MP01+"00"); + }else{ + entity.setSource(CRMConstants.CRM_SOURCE.SOURCE_MP02); + entity.setChannel(CRMConstants.CRM_SOURCE.SOURCE_MP02+"00"); } - 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 param = JSONObject.toJSONString(entity); - String result = null; - int success =1; - String url = urlStr; - try { - String token = DigestUtils.md5Hex(type + _t + appid); - url = urlStr + "?type=" + type + "&_t=" + _t + "&token=" + token;// 鎻愪氦CRM鍦板潃 - 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); - } + entity.setOpenid(customerLog.getOpenid()); + entity.setDate(DateUtil.dateToString(customerLog.getCreateDate(),"yyyy/MM/dd HH:mm")); + CrmCustomerPostRequest obj = new CrmCustomerPostRequest(); + obj.setCusInfo(new ArrayList<>()); + obj.getCusInfo().add(entity); + int status ; + String crmInfo; + String param = JSONObject.toJSONString(obj); + CRMBaseResponse result = sendCusHttpRequest(CRMConstants.IntegerUrl.POST_CUS_DATA_URL,CRMConstants.IntegerName.POST_CUS_DATA_NAME,param); + if (result != null && (StringUtils.equalsIgnoreCase(result.getCode(), CRMConstants.CODE_SUCCESS))) { + status = 1; + crmInfo="鎻愪氦鎴愬姛"; }else{ status = 2; - crmInfo="鎻愪氦澶辫触crm閰嶇疆鏈夎锛宎ppid:["+ appid+"]"+"url:["+ urlStr+"]"; + crmInfo="鎻愪氦澶辫触["+ result!=null?result.getMsg():"鎺ュ彛璇锋眰澶辫触锛�"+"]"; } - 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) + .eq(CustomerLog::getId,entity.getId()) .set(CustomerLog::getCrmStatus,Constants.ONE ) .set(CustomerLog::getCrmInfo,crmInfo ) .set(CustomerLog::getCrmDate,new Date() ));// 鏇存柊鐘舵�� return status;// 榛樿澶辫触 } + /** + * 鑾峰彇瀵艰喘缁戝畾鍒楄〃 + * @param entity + * @return + */ + @Override + public CRMBaseResponse<List<CRMDaogouBindListResponse>> getDaogouBindList(CrmDaogouBindListRequest entity ){ + int status ; + String crmInfo; + String param = JSONObject.toJSONString(entity); + CRMBaseResponse<List<CRMDaogouBindListResponse>> result = sendHttpRequest(CRMConstants.IntegerUrl.DAOGOU_BIND_LIST_URL, + CRMConstants.IntegerName.DAOGOU_BIND_LIST_NAME, + param, + new TypeReference<CRMBaseResponse<List<CRMDaogouBindListResponse>>>(){}); + return result;// 榛樿澶辫触 + } + /** + * 鑾峰彇瀹㈡埛鍒楄〃 + * @param entity + * @return + */ + @Override + public CRMBaseResponse<List<CRMCustomerListResponse>> getCustomerList(CrmCustomerListRequest entity ){ + int status ; + String crmInfo; + String param = JSONObject.toJSONString(entity); + CRMBaseResponse<List<CRMCustomerListResponse>> result = sendHttpRequest(CRMConstants.IntegerUrl.CUS_BEFORE_PAGE_LIST_URL + ,CRMConstants.IntegerName.CUS_BEFORE_PAGE_LIST_NAME + ,param + ,new TypeReference<CRMBaseResponse<List<CRMCustomerListResponse>>>(){}); + return result;// 榛樿澶辫触 + } + + public <T> CRMBaseResponse<T> sendCusHttpRequest(String interfaceUrl, String name, String param){ + log.info("銆�"+name+"銆�================寮�濮�===="+ JSONObject.toJSONString(param)); + String appKey = (String) redisTemplate.opsForValue().get(Constants.RedisKeys.ZBOM_CRM_API_KEY); + String url = redisTemplate.opsForValue().get(Constants.RedisKeys.ZBOM_CRM_API_URL) + interfaceUrl ; + long _t = System.currentTimeMillis(); + if (StringUtils.isNotBlank(appKey)||StringUtils.isNotBlank(url)) { + String res = null; + int success = 0; + try { + url += "?type=postCusData&_t=" + _t + "&token=" + DigestUtils.md5Hex( "postCusData" + _t + appKey); + Map<String,String> headers = new HashMap<>(); + res = HttpsUtil.postJson(url,param); + TypeReference typeReference = + new TypeReference<CRMBaseResponse<T>>(){}; + CRMBaseResponse<T> result = JSONObject.parseObject(res, typeReference.getType()); + logResult(result,name); + if(StringUtils.equals(result.getCode(),CRMConstants.CODE_SUCCESS)){ + return result; + }else{ + success =1; + } + }catch (Exception e){ + success = 1; + log.error("銆�"+name+"銆�================澶辫触===="+ JSONObject.toJSONString(param)); + }finally { + saveInterfaceLog(url,name,param,success,res); + } + } + return null; + } + public <T> CRMBaseResponse<T> sendHttpRequest(String interfaceUrl, String name, String param,TypeReference<CRMBaseResponse<T>> typeReference){ + log.info("銆�"+name+"銆�================寮�濮�===="+ JSONObject.toJSONString(param)); + String appKey = (String) redisTemplate.opsForValue().get(Constants.RedisKeys.ZBOM_CRM_API_KEY); + String url = redisTemplate.opsForValue().get(Constants.RedisKeys.ZBOM_CRM_API_URL) + interfaceUrl ; + long _t = System.currentTimeMillis(); + if (StringUtils.isNotBlank(appKey)||StringUtils.isNotBlank(url)) { + String res = null; + int success = 0; + try { + url += "?timestamp=" + _t + "&sign=" + DigestUtils.md5Hex( _t + appKey); + Map<String,String> headers = new HashMap<>(); + res = HttpsUtil.postJson(url,param); + CRMBaseResponse<T> result = JSONObject.parseObject(res, typeReference.getType()); + logResult(result,name); + if(StringUtils.equals(result.getCode(),CRMConstants.CODE_SUCCESS)){ + return result; + }else{ + success =1; + } + }catch (Exception e){ + success = 1; + log.error("銆�"+name+"銆�================澶辫触===="+ JSONObject.toJSONString(param)); + }finally { + saveInterfaceLog(url,name,param,success,res); + } + } + return null; + } + private static void logResult(CRMBaseResponse res,String name) { + if(StringUtils.equals(res.getCode(), CRMConstants.CODE_SUCCESS)){ + log.info("銆怌RM鎺ュ彛锛�"+name+"銆�================鎴愬姛====\n"+res); + }else{ + log.error("銆怌RM鎺ュ彛锛�"+name+"銆�================澶辫触====锛歕n"+ res); + } + } public void saveInterfaceLog(String url,String name,String param,Integer success,String respone){ if(crmInterfaceLogMapper ==null){ return; @@ -142,4 +209,55 @@ log.setRepose(respone); crmInterfaceLogMapper.insert(log); } + + /** + * 蹇楅偊瀛楃涓插姞瀵� + * @param str + * @return + */ + + @Override + public String zbomEncode(String str) { + StringBuffer sb = new StringBuffer(); + String result = null; + try { + // 鍒涘缓StringBuffer瀵硅薄鐢ㄦ潵鎿嶄綔瀛楃涓� + String urlStr = (String) redisTemplate.opsForValue().get(Constants.RedisKeys.ZBOM_ENCODE_URL); + sb = new StringBuffer( + urlStr + "?code=" + URLEncoder.encode(str, "UTF-8") + "&type=0&numstr=wy?"); + result = HttpsUtil.sendGet(sb.toString()); + + }catch (Exception e){ + e.printStackTrace(); + }finally { + saveInterfaceLog(sb.toString(),"蹇楅偊瀛楃涓插姞瀵嗘帴鍙�",str, result==null?1:0,result ); + } + return result; + } + + /** + * 璺宠浆crm鍔熻兘 鑾峰彇鎺堟潈鍦板潃 + * http://localhost:8080/core/oauth/authorize/jump?timestamp=1719998741&sign=41fbeb13965c43916876db7b5799e8ac&agent_phone_number=199077&bindKey=mp + * @param userName + * @return + */ + @Override + public String getCrmGoUrl(String userName){ + StringBuffer sb = new StringBuffer(); + String result = null; + try { + // 鍒涘缓StringBuffer瀵硅薄鐢ㄦ潵鎿嶄綔瀛楃涓� + int _t = (int)(System.currentTimeMillis()); + String appkey = (String) redisTemplate.opsForValue().get(Constants.RedisKeys.ZBOM_CRM_AUTH_API_KEY); + String url = (String) redisTemplate.opsForValue().get(Constants.RedisKeys.ZBOM_CRM_API_URL) + +CRMConstants.IntegerUrl.GO_CRM_AUTH_URL + + "?timestamp="+_t + +"&agent_phone_number=" + URLEncoder.encode(userName, "UTF-8") + + "&bindKey=mp&sign="+ DigestUtils.md5Hex( _t + appkey);; + return url; + }catch (Exception e){ + e.printStackTrace(); + } + throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鑾峰彇璺宠浆鍦板潃澶辫触鍝︼紒"); + } } -- Gitblit v1.9.3