CRM-同步信息改为nacos配置
This commit is contained in:
parent
13bfc612bf
commit
c8484f775c
|
|
@ -5,7 +5,6 @@ import cn.hutool.cache.impl.TimedCache;
|
|||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.nflg.mobilebroken.admin.pojo.dto.CrmGetTokenResultDTO;
|
||||
import com.nflg.mobilebroken.admin.pojo.vo.CmrAgentResultVO;
|
||||
import com.nflg.mobilebroken.admin.pojo.vo.CmrDeviceResultVO;
|
||||
|
|
@ -13,6 +12,8 @@ import com.nflg.mobilebroken.common.constant.STATE;
|
|||
import com.nflg.mobilebroken.common.exception.NflgException;
|
||||
import com.nflg.mobilebroken.common.util.HttpUtils;
|
||||
import com.nflg.mobilebroken.common.util.VUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
@ -23,9 +24,33 @@ import java.util.*;
|
|||
*/
|
||||
|
||||
@Service
|
||||
@RefreshScope
|
||||
public class CrmService {
|
||||
|
||||
|
||||
@Value("${token.crm.client_id}")
|
||||
private String clientId;
|
||||
|
||||
@Value("${token.crm.username}")
|
||||
private String username;
|
||||
|
||||
@Value("${token.crm.password}")
|
||||
private String password;
|
||||
|
||||
@Value("${token.crm.client_secret}")
|
||||
private String clientSecret;
|
||||
|
||||
@Value("${token.crm.url}")
|
||||
private String tokenUrl;
|
||||
|
||||
@Value("${sync.crm.customer.url}")
|
||||
private String getAgentUrl;
|
||||
|
||||
|
||||
@Value("${sync.crm.device.url}")
|
||||
private String getDeviceUrl;
|
||||
|
||||
|
||||
private final Integer expire = 50 * 60 * 1000; //50分种
|
||||
private final String tokenCacheKey = "CRM-TOKEN-CATCH-KEY";
|
||||
|
||||
|
|
@ -43,11 +68,11 @@ public class CrmService {
|
|||
HttpUtils httpUtils = new HttpUtils();
|
||||
Map<String, String> paramMp = new HashMap<>();
|
||||
paramMp.put("grant_type", "password");
|
||||
paramMp.put("client_id", "3MVG9aWdXtdHRrI2TLduzcs5jZphm2K9lqodDnAQXRRVUOkf_XmSC53xLZIv09jQIC1K69nCdYma6ylnjFw9i");
|
||||
paramMp.put("username", "nflgcrm@nflg.com.sandbox4");
|
||||
paramMp.put("password", "BWcrm2019nflg");
|
||||
paramMp.put("client_secret", "6BEEFE93BFBC080FF9203563D74945E3161232BC5C30CF4286126E0CE18C15E4");
|
||||
String s = httpUtils.doformPost("https://nflg--sandbox4.sandbox.my.salesforce.com/services/oauth2/token", paramMp);
|
||||
paramMp.put("client_id", clientId);
|
||||
paramMp.put("username", username);
|
||||
paramMp.put("password", password);
|
||||
paramMp.put("client_secret", clientSecret);
|
||||
String s = httpUtils.doformPost(tokenUrl, paramMp);
|
||||
CrmGetTokenResultDTO result = JSONObject.parseObject(s, CrmGetTokenResultDTO.class);
|
||||
if (Objects.nonNull(result) && StrUtil.isNotBlank(result.getAccess_token())) {
|
||||
|
||||
|
|
@ -75,7 +100,7 @@ public class CrmService {
|
|||
Map<String, String> reBody = new HashMap<>();
|
||||
reBody.put("CrLsDate", date);
|
||||
String token = StrUtil.join(" ", "Bearer", getToken());
|
||||
String orderResult = httpUtils.doPost("https://nflg--sandbox4.sandbox.my.salesforce.com/services/apexrest/YDPCFSGetAgent", JSON.toJSONString(reBody), token);
|
||||
String orderResult = httpUtils.doPost(getAgentUrl, JSON.toJSONString(reBody), token);
|
||||
JSONObject jsonObject = JSONObject.parseObject(orderResult);
|
||||
String code = jsonObject.getString("code");
|
||||
if (Objects.equals(code, "0")) {
|
||||
|
|
@ -99,7 +124,7 @@ public class CrmService {
|
|||
Map<String, String> reBody = new HashMap<>();
|
||||
reBody.put("CrLsDate", startDate);
|
||||
String token = StrUtil.join(" ", "Bearer", getToken());
|
||||
String orderResult = httpUtils.doPost("https://nflg--sandbox4.sandbox.my.salesforce.com/services/apexrest/YDPCFSGetAsset", JSON.toJSONString(reBody), token);
|
||||
String orderResult = httpUtils.doPost(getDeviceUrl, JSON.toJSONString(reBody), token);
|
||||
JSONObject jsonObject = JSONObject.parseObject(orderResult);
|
||||
String code = jsonObject.getString("code");
|
||||
if (Objects.equals(code, "0")) {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import cn.hutool.core.date.DatePattern;
|
|||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.nflg.mobilebroken.admin.pojo.dto.TiketTimeoutDTO;
|
||||
import com.nflg.mobilebroken.admin.service.AdminCustomerService;
|
||||
import com.nflg.mobilebroken.admin.service.AdminDeviceService;
|
||||
import com.nflg.mobilebroken.common.constant.Constant;
|
||||
import com.nflg.mobilebroken.common.constant.MessageSubType;
|
||||
import com.nflg.mobilebroken.common.constant.UserState;
|
||||
|
|
@ -22,6 +24,7 @@ import org.springframework.stereotype.Component;
|
|||
import javax.annotation.Resource;
|
||||
import javax.mail.MessagingException;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
|
|
@ -68,6 +71,12 @@ public class TicketScheduledTasks {
|
|||
@Resource
|
||||
private IDeviceService deviceService;
|
||||
|
||||
@Resource
|
||||
private AdminCustomerService adminCustomerService;
|
||||
|
||||
@Resource
|
||||
private AdminDeviceService adminDeviceService;
|
||||
|
||||
/**
|
||||
* 工单评论邀请邮件
|
||||
* 每天午夜12点执行一次
|
||||
|
|
@ -158,6 +167,37 @@ public class TicketScheduledTasks {
|
|||
log.info("执行更新设备质保状态完成");
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步代理商公司列表
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
@Scheduled(cron = "0 0 1 * * ?")
|
||||
public void syncCustomerFromCrm(){
|
||||
LocalDate currentDate = LocalDate.now();
|
||||
// 将当前日期减一天
|
||||
LocalDate previousDate = currentDate.minusDays(1);
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
String cdate = formatter.format(previousDate);
|
||||
adminCustomerService.syncFromCrm(cdate,cdate);
|
||||
log.info("同步代理商公司-成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步设备
|
||||
* @return
|
||||
*/
|
||||
@Scheduled(cron = "0 0 2 * * ?")
|
||||
public void syncDeviceCrm(){
|
||||
LocalDate currentDate = LocalDate.now();
|
||||
// 将当前日期减一天
|
||||
LocalDate previousDate = currentDate.minusDays(1);
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
String cdate = formatter.format(previousDate);
|
||||
adminDeviceService.syncFormCrm(cdate,cdate);
|
||||
log.info("同步CRM设备-成功");
|
||||
}
|
||||
|
||||
private void emergencyRemind(TiketTimeoutDTO cfgTimeout) {
|
||||
log.info("【工单超时提醒】获取状态为紧急且{}天未解决的工单", cfgTimeout.getEmergency());
|
||||
List<Ticket> tickets = ticketService.getEmergencys(cfgTimeout.getEmergency());
|
||||
|
|
|
|||
Loading…
Reference in New Issue