|
@@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.date.DateField;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.util.NumberUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.http.HttpUtil;
|
|
@@ -14,6 +15,8 @@ import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
|
|
import com.fjhx.common.constant.SourceConstant;
|
|
|
import com.fjhx.customer.contants.XiaomanContant;
|
|
|
+import com.fjhx.customer.entity.customer.dto.CustomerDto;
|
|
|
+import com.fjhx.customer.entity.customer.po.CustomerUser;
|
|
|
import com.fjhx.customer.entity.xiaoman.dto.XiaomanCustomerSelectDto;
|
|
|
import com.fjhx.customer.entity.xiaoman.po.XiaomanConfig;
|
|
|
import com.fjhx.customer.entity.xiaoman.vo.CustomerListApiVo;
|
|
@@ -27,6 +30,7 @@ import com.fjhx.tenant.entity.dict.dto.DictTenantDataSelectDto;
|
|
|
import com.fjhx.tenant.entity.dict.po.DictTenantData;
|
|
|
import com.fjhx.tenant.entity.dict.vo.DictTenantDataVo;
|
|
|
import com.fjhx.tenant.service.dict.DictTenantDataService;
|
|
|
+import com.ruoyi.common.core.redis.RedisCache;
|
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
@@ -49,24 +53,29 @@ public class XiaomanApiServiceImpl implements XiaomanApiService {
|
|
|
XiaomanCustomerService xiaomanCustomerService;
|
|
|
@Resource
|
|
|
DictTenantDataService dictTenantDataService;
|
|
|
+ @Resource
|
|
|
+ RedisCache redisCache;
|
|
|
|
|
|
// @DSTransactional
|
|
|
@Override
|
|
|
@Async
|
|
|
public void initAllList() {
|
|
|
- boolean result = setNxWithExpiration(XiaomanContant.TASK_STATUS_KEY, XiaomanContant.TASK_STATUS_VALUE, XiaomanContant.DELAY_DELETE_KEY_TIME);
|
|
|
- if (!result) {
|
|
|
- String mes = stringRedisTemplate.opsForValue().get(XiaomanContant.TASK_STATUS_DESC_KEY);
|
|
|
- throw new RuntimeException(StrUtil.isBlank(mes)? "全量更新正在进行中" : mes);
|
|
|
- }
|
|
|
- stringRedisTemplate.opsForValue().set(XiaomanContant.TASK_STATUS_DESC_KEY, "全量更新正在进行中");
|
|
|
+// boolean result = setNxWithExpiration(XiaomanContant.TASK_STATUS_KEY, XiaomanContant.TASK_STATUS_VALUE, XiaomanContant.DELAY_DELETE_KEY_TIME);
|
|
|
+// if (!result) {
|
|
|
+// String mes = stringRedisTemplate.opsForValue().get(XiaomanContant.TASK_STATUS_DESC_KEY);
|
|
|
+// throw new RuntimeException(StrUtil.isBlank(mes)? "全量更新正在进行中" : mes);
|
|
|
+// }
|
|
|
+// stringRedisTemplate.opsForValue().set(XiaomanContant.TASK_STATUS_DESC_KEY, "全量更新正在进行中");
|
|
|
try {
|
|
|
getSelectorData();
|
|
|
|
|
|
|
|
|
List<XiaomanCustomerVo> list = xiaomanCustomerService.getList(new XiaomanCustomerSelectDto());
|
|
|
Set<Long> collect = list.stream().map(XiaomanCustomerVo::getCompanyId).collect(Collectors.toSet());
|
|
|
- int pageIndex = 1;
|
|
|
+ int pageIndex = redisCache.getCacheObject(XiaomanContant.ALL_CUSTOMER_PAGE_INDEX_KEY);
|
|
|
+ if (!NumberUtil.isValidNumber(pageIndex)) {
|
|
|
+ pageIndex = 1;
|
|
|
+ }
|
|
|
int totalPage;
|
|
|
do {
|
|
|
XiaomanConfig config = xiaomanConfigService.getCache();
|
|
@@ -77,15 +86,16 @@ public class XiaomanApiServiceImpl implements XiaomanApiService {
|
|
|
int totalItem = customerListApiVo.getTotalItem();
|
|
|
totalPage = (totalItem / XiaomanContant.PAGE_SIZE) + (totalItem % XiaomanContant.PAGE_SIZE > 0 ? 1 : 0);
|
|
|
pageIndex++;
|
|
|
+ redisCache.setCacheObject(XiaomanContant.ALL_CUSTOMER_PAGE_INDEX_KEY, pageIndex);
|
|
|
} while (pageIndex <= totalPage);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- stringRedisTemplate.delete(XiaomanContant.TASK_STATUS_KEY);
|
|
|
- stringRedisTemplate.opsForValue().set(XiaomanContant.TASK_STATUS_DESC_KEY, "全量更新出现异常,已停止");
|
|
|
- return;
|
|
|
+// stringRedisTemplate.delete(XiaomanContant.TASK_STATUS_KEY);
|
|
|
+// stringRedisTemplate.opsForValue().set(XiaomanContant.TASK_STATUS_DESC_KEY, "全量更新出现异常,已停止");
|
|
|
+// return;
|
|
|
}
|
|
|
- stringRedisTemplate.delete(XiaomanContant.TASK_STATUS_KEY);
|
|
|
- stringRedisTemplate.opsForValue().set(XiaomanContant.TASK_STATUS_DESC_KEY, "全量更新完成,完成时间:" + DateUtil.now());
|
|
|
+// stringRedisTemplate.delete(XiaomanContant.TASK_STATUS_KEY);
|
|
|
+// stringRedisTemplate.opsForValue().set(XiaomanContant.TASK_STATUS_DESC_KEY, "全量更新完成,完成时间:" + DateUtil.now());
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -128,12 +138,13 @@ public class XiaomanApiServiceImpl implements XiaomanApiService {
|
|
|
|
|
|
/**
|
|
|
* 客户更新列表
|
|
|
+ *
|
|
|
* @author hj
|
|
|
* @date 2024/4/6 21:54
|
|
|
*/
|
|
|
@Override
|
|
|
@Async
|
|
|
- public void updateList(int hours){
|
|
|
+ public void updateList(int hours) {
|
|
|
try {
|
|
|
//先更新一下数据字典
|
|
|
getSelectorData();
|
|
@@ -337,4 +348,84 @@ public class XiaomanApiServiceImpl implements XiaomanApiService {
|
|
|
DynamicDataSourceContextHolder.poll();
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 推送客户数据到小满
|
|
|
+ */
|
|
|
+ @DSTransactional
|
|
|
+ @Override
|
|
|
+ public void updateXiaomanData(CustomerDto dto) {
|
|
|
+ if (ObjectUtil.isEmpty(dto.getCompanyId())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ XiaomanUpdateInfoVO xVo = new XiaomanUpdateInfoVO();
|
|
|
+ List<XiaomanUpdateInfoVO.Customer> xiaomanCustomerUserList = new ArrayList<>();
|
|
|
+
|
|
|
+ //=========================
|
|
|
+ List<CustomerUser> customerUserList = dto.getCustomerUserList();
|
|
|
+ for (CustomerUser cu : customerUserList) {
|
|
|
+ String contactJsonStr = cu.getContactJson();
|
|
|
+ log.info("->" + contactJsonStr + "<-");
|
|
|
+ JSONArray contactJsonArr = ObjectUtil.isEmpty(contactJsonStr) ? new JSONArray() : JSONArray.parseArray(contactJsonStr);
|
|
|
+
|
|
|
+ XiaomanUpdateInfoVO.Customer xCU = new XiaomanUpdateInfoVO.Customer();
|
|
|
+ xCU.setName(cu.getName());//联系人名称
|
|
|
+ xCU.setEmail(cu.getEmail());//客户简称
|
|
|
+ xCU.setRemark(dto.getRemark());//客户联系人备注
|
|
|
+ xCU.setTelAreaCode(Long.parseLong(dto.getTelAreaCode())); //客户联系人电话区号
|
|
|
+
|
|
|
+ //更多联系方式
|
|
|
+ for (int i = 0; i < contactJsonArr.size(); i++) {
|
|
|
+ JSONObject contactJson = contactJsonArr.getJSONObject(i);
|
|
|
+ String contactNo = contactJson.getString("contactNo");
|
|
|
+ switch (contactJson.getString("type")) {
|
|
|
+ case "mobile":
|
|
|
+ xCU.setTel(contactJson.getLong("contactNo"));//客户联系人电话
|
|
|
+ break;
|
|
|
+ case "qq":
|
|
|
+ xCU.setQq(contactNo);//客户联系人QQ
|
|
|
+ break;
|
|
|
+ case "LinkedIn":
|
|
|
+ xCU.setLinkedin(contactNo);//客户联系人LinkedIn
|
|
|
+ break;
|
|
|
+ case "Skype":
|
|
|
+ xCU.setSkype(contactNo);//客户联系人Skype
|
|
|
+ break;
|
|
|
+ case "wa":
|
|
|
+ xCU.setWhatsapp(contactNo);//客户联系人Whatsapp
|
|
|
+ break;
|
|
|
+ case "Facebook":
|
|
|
+ xCU.setFacebook(contactNo);//客户联系人Facebook
|
|
|
+ break;
|
|
|
+ case "wechat":
|
|
|
+ xCU.setWechat(contactNo);//客户联系人Wechat
|
|
|
+ break;
|
|
|
+ case "twitter":
|
|
|
+ xCU.setTwitter(contactNo);//客户联系人Twitter
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ xiaomanCustomerUserList.add(xCU);
|
|
|
+ }
|
|
|
+ //=========================
|
|
|
+ xVo.setCompanyId(dto.getCompanyId());//公司客户ID (创建时无需设置,更新时需要设置)
|
|
|
+ xVo.setSerialId(dto.getCustomerCode());//客户编号id->客户表customer_code
|
|
|
+ xVo.setName(dto.getName());//客户名称
|
|
|
+ xVo.setShortName(dto.getShortName());//客户简称
|
|
|
+ xVo.setHomepage(dto.getHomepage());//网站主页
|
|
|
+ xVo.setFax(Long.parseLong(dto.getFax()));//传真
|
|
|
+ xVo.setTelAreaCode(Long.parseLong(dto.getTelAreaCode()));//客户电话区号
|
|
|
+ xVo.setTel(Long.parseLong(dto.getTel()));//客户电话
|
|
|
+ xVo.setAddress(dto.getAddress());//地址
|
|
|
+ xVo.setRemark(dto.getRemark());//备注
|
|
|
+ xVo.setCustomers(xiaomanCustomerUserList);//客户联系人
|
|
|
+ //客户来源ID
|
|
|
+ List<Long> originList = Arrays.stream(dto.getSource().split(",")).map(Long::valueOf).collect(Collectors.toList());
|
|
|
+ xVo.setOriginList(originList);
|
|
|
+ xVo.setTrailStatus(Long.parseLong(dto.getStatus()));//客户状态ID
|
|
|
+ //=========================
|
|
|
+
|
|
|
+ updateXiaomanData(xVo);
|
|
|
+ }
|
|
|
}
|