k94314517
2024-07-25 a75b18a4157ab486e0b51c438ac165ab3a08e3e0
server/service/src/main/java/com/doumee/biz/zbom/impl/ZbomCRMServiceImpl.java
@@ -8,8 +8,6 @@
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.biz.zbom.model.zhongtai.ZTConstants;
import com.doumee.biz.zbom.model.zhongtai.response.ZTBaseResponse;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.utils.Constants;
@@ -27,11 +25,6 @@
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.*;
@@ -48,7 +41,6 @@
    private CustomerLogMapper customerLogMapper;
    @Autowired
    private CrmInterfaceLogMapper crmInterfaceLogMapper;
    @Autowired
    private RedisTemplate<String, Object> redisTemplate;
@@ -61,7 +53,10 @@
     */
    @Override
    @Async
    public int dealCustomerLogData(CustomerLog customerLog){
    public void dealCustomerLogData(CustomerLog customerLog){
        if(StringUtils.isBlank(customerLog.getPhone())){
            return;
        }
        CrmCustomerInfoRequest entity = new CrmCustomerInfoRequest();
        entity.setId(customerLog.getId());
        entity.setName(customerLog.getName());
@@ -77,7 +72,8 @@
            entity.setSource(CRMConstants.CRM_SOURCE.SOURCE_MP02);
            entity.setChannel(CRMConstants.CRM_SOURCE.SOURCE_MP02+"00");
        }
        entity.setOpenId(customerLog.getOpenid());
//        entity.setOpenId(customerLog.getOpenid());
        entity.setOpenid(customerLog.getOpenid());
        entity.setDate(DateUtil.dateToString(customerLog.getCreateDate(),"yyyy/MM/dd HH:mm"));
        CrmCustomerPostRequest obj = new CrmCustomerPostRequest();
        obj.setCusInfo(new ArrayList<>());
@@ -98,7 +94,6 @@
                .set(CustomerLog::getCrmStatus,Constants.ONE )
                .set(CustomerLog::getCrmInfo,crmInfo )
                .set(CustomerLog::getCrmDate,new Date() ));// 更新状态
        return status;// 默认失败
    }
    /**
     * 获取导购绑定列表
@@ -110,7 +105,10 @@
        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);
        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;// 默认失败
    }
@@ -124,13 +122,16 @@
        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);
        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 appKey = (String) redisTemplate.opsForValue().get(Constants.RedisKeys.ZBOM_CRM_POSTCUS_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)) {
@@ -158,7 +159,7 @@
        }
        return  null;
    }
    public   <T> CRMBaseResponse<T> sendHttpRequest(String interfaceUrl,  String name,  String param){
    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 ;
@@ -170,8 +171,6 @@
                url += "?timestamp=" + _t + "&sign=" + DigestUtils.md5Hex( _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)){
@@ -245,18 +244,20 @@
     * @return
     */
    @Override
    public    String getCrmGoUrl(String userName){
        StringBuffer sb = new StringBuffer();
        String result = null;
    public    String getCrmGoUrl(String userName,Integer type){
        try {
            // 创建StringBuffer对象用来操作字符串
            int _t = (int)(System.currentTimeMillis());
            String pageKey ="mp";//客户列表页面码
            if(Constants.equalsInteger(type,Constants.ONE)){
                pageKey = "mpAddIntention";//新增意向页面码
            }
            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)
            String  url =   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);;
                    + "&bindKey="+pageKey+"&sign="+ DigestUtils.md5Hex( _t + appkey);;
            return url;
        }catch (Exception e){
            e.printStackTrace();