|
|
|
@ -287,184 +287,6 @@ public class StorePromotionDataService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 同步企业微信的拉黑和新增客户信息
|
|
|
|
|
*
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public void syncCustomerBlackList() throws Exception {
|
|
|
|
|
Date startDate = DateUtils.addDay(new Date(), -1);
|
|
|
|
|
Date endDate = DateUtils.addDay(new Date(), -1);
|
|
|
|
|
//获取token
|
|
|
|
|
String token = mainService.getAccessToken();
|
|
|
|
|
List<StorePromotionDataDO> cusList = storePromotionDataDOMapper.selectCustomer();
|
|
|
|
|
cusList.forEach(customer -> {
|
|
|
|
|
// 返回
|
|
|
|
|
try {
|
|
|
|
|
String userId = customer.getUserId();
|
|
|
|
|
WxCusInfoReqDO wxCusInfoReqDO = new WxCusInfoReqDO();
|
|
|
|
|
wxCusInfoReqDO.setAccess_token(token);
|
|
|
|
|
wxCusInfoReqDO.setUserid(userId);
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
//todo 分开写便于同步历史数据 最大跨度30天 最久当天往前180天 上线时改为System.currentTimeMillis()
|
|
|
|
|
wxCusInfoReqDO.setStart_time(startDate.getTime() / 1000);
|
|
|
|
|
wxCusInfoReqDO.setEnd_time(endDate.getTime() / 1000);
|
|
|
|
|
WxCusInfoRespDO wxCusInfoRespDO = getWxCusInfo(wxCusInfoReqDO);
|
|
|
|
|
if (wxCusInfoRespDO == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
wxCusInfoRespDO.setStoreId(customer.getStoreId());
|
|
|
|
|
wxCusInfoRespDO.setStatTime(startDate);
|
|
|
|
|
|
|
|
|
|
QueryWrapper<PoiCustomerContactDataStat> qw = new QueryWrapper();
|
|
|
|
|
qw.eq("store_id", customer.getStoreId()).eq("stat_time", startDate).last("limit 1");
|
|
|
|
|
PoiCustomerContactDataStat poiCustomerContactDataStat = poiCustomerContactDataStatMapper.selectOne(qw);
|
|
|
|
|
int syncRes = 0;
|
|
|
|
|
if (poiCustomerContactDataStat == null) {
|
|
|
|
|
syncRes = storePromotionDataDOMapper.insertStorePromotionData(wxCusInfoRespDO);
|
|
|
|
|
} else {
|
|
|
|
|
Long newApplyCnt = 0L;
|
|
|
|
|
if (wxCusInfoRespDO.getNew_apply_cnt() != null) {
|
|
|
|
|
newApplyCnt = new Long(wxCusInfoRespDO.getNew_apply_cnt());
|
|
|
|
|
}
|
|
|
|
|
poiCustomerContactDataStat.setNewApplyCnt(newApplyCnt);
|
|
|
|
|
|
|
|
|
|
Long avgReplyTime = 0L;
|
|
|
|
|
if (wxCusInfoRespDO.getAvg_reply_time() != null) {
|
|
|
|
|
avgReplyTime = new Long(wxCusInfoRespDO.getAvg_reply_time());
|
|
|
|
|
}
|
|
|
|
|
poiCustomerContactDataStat.setAvgReplyTime(avgReplyTime);
|
|
|
|
|
|
|
|
|
|
Long chatCny = 0L;
|
|
|
|
|
if (wxCusInfoRespDO.getChat_cnt() != null) {
|
|
|
|
|
chatCny = new Long(wxCusInfoRespDO.getChat_cnt());
|
|
|
|
|
}
|
|
|
|
|
poiCustomerContactDataStat.setChatCnt(chatCny);
|
|
|
|
|
|
|
|
|
|
Long messageCnt = 0L;
|
|
|
|
|
if (wxCusInfoRespDO.getMessage_cnt() != null) {
|
|
|
|
|
messageCnt = new Long(wxCusInfoRespDO.getMessage_cnt());
|
|
|
|
|
}
|
|
|
|
|
poiCustomerContactDataStat.setMessageCnt(messageCnt);
|
|
|
|
|
|
|
|
|
|
Float replyPercentage = 0F;
|
|
|
|
|
if (wxCusInfoRespDO.getReply_percentage() != null) {
|
|
|
|
|
replyPercentage = wxCusInfoRespDO.getReply_percentage();
|
|
|
|
|
}
|
|
|
|
|
poiCustomerContactDataStat.setReplyPercentage(replyPercentage);
|
|
|
|
|
|
|
|
|
|
Long newContactCnt = 0L;
|
|
|
|
|
if (wxCusInfoRespDO.getNew_contact_cnt() != null) {
|
|
|
|
|
newContactCnt = new Long(wxCusInfoRespDO.getNew_contact_cnt());
|
|
|
|
|
}
|
|
|
|
|
poiCustomerContactDataStat.setNewContactCnt(newContactCnt);
|
|
|
|
|
|
|
|
|
|
Long negativeFeedbackCnt = 0L;
|
|
|
|
|
if (wxCusInfoRespDO.getNegative_feedback_cnt() != null) {
|
|
|
|
|
negativeFeedbackCnt = new Long(wxCusInfoRespDO.getNegative_feedback_cnt());
|
|
|
|
|
}
|
|
|
|
|
poiCustomerContactDataStat.setNegativeFeedbackCnt(negativeFeedbackCnt);
|
|
|
|
|
|
|
|
|
|
syncRes = poiCustomerContactDataStatMapper.updateById(poiCustomerContactDataStat);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (syncRes == Constants.INSERT_FAIL) {
|
|
|
|
|
throw new RuntimeException("向数据库导入客户统计数据时出错");
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("请求企业微信api获取客户统计数据或日期转换出错!", e);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void syncCustomerBlackListByDate(Date startDate, Date endDate) throws Exception {
|
|
|
|
|
//获取token
|
|
|
|
|
String token = mainService.getAccessToken();
|
|
|
|
|
List<PrivilageCpUserDO> privilageCpUserDOS = privilageCpUserDOMapper.selectList(null);
|
|
|
|
|
privilageCpUserDOS.forEach(privilageCpUserDO -> {
|
|
|
|
|
// 返回
|
|
|
|
|
try {
|
|
|
|
|
Long storeId = privilageCpUserStoreDOMapper.selectOneByCpUserId(privilageCpUserDO.getCpUserId());
|
|
|
|
|
Long regionId = null;
|
|
|
|
|
if (storeId == null){
|
|
|
|
|
regionId = privilageCpUserDO.getId();
|
|
|
|
|
}
|
|
|
|
|
WxCusInfoReqDO wxCusInfoReqDO = new WxCusInfoReqDO();
|
|
|
|
|
wxCusInfoReqDO.setAccess_token(token);
|
|
|
|
|
wxCusInfoReqDO.setUserid(privilageCpUserDO.getCpUserId());
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
//todo 分开写便于同步历史数据 最大跨度30天 最久当天往前180天 上线时改为System.currentTimeMillis()
|
|
|
|
|
wxCusInfoReqDO.setStart_time(startDate.getTime() / 1000);
|
|
|
|
|
wxCusInfoReqDO.setEnd_time(endDate.getTime() / 1000);
|
|
|
|
|
WxCusInfoRespDO wxCusInfoRespDO = getWxCusInfo(wxCusInfoReqDO);
|
|
|
|
|
if (wxCusInfoRespDO == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
wxCusInfoRespDO.setStoreId(storeId);
|
|
|
|
|
wxCusInfoRespDO.setRegionId(regionId);
|
|
|
|
|
wxCusInfoRespDO.setStatTime(startDate);
|
|
|
|
|
|
|
|
|
|
QueryWrapper<PoiCustomerContactDataStat> qw = new QueryWrapper();
|
|
|
|
|
qw.eq("store_id", storeId).eq("region_id", regionId).eq("stat_time", startDate).last("limit 1");
|
|
|
|
|
PoiCustomerContactDataStat poiCustomerContactDataStat = poiCustomerContactDataStatMapper.selectOne(qw);
|
|
|
|
|
int syncRes = 0;
|
|
|
|
|
if (poiCustomerContactDataStat == null) {
|
|
|
|
|
syncRes = storePromotionDataDOMapper.insertStorePromotionData(wxCusInfoRespDO);
|
|
|
|
|
} else {
|
|
|
|
|
Long newApplyCnt = 0L;
|
|
|
|
|
if (wxCusInfoRespDO.getNew_apply_cnt() != null) {
|
|
|
|
|
newApplyCnt = new Long(wxCusInfoRespDO.getNew_apply_cnt());
|
|
|
|
|
}
|
|
|
|
|
poiCustomerContactDataStat.setNewApplyCnt(newApplyCnt);
|
|
|
|
|
|
|
|
|
|
Long avgReplyTime = 0L;
|
|
|
|
|
if (wxCusInfoRespDO.getAvg_reply_time() != null) {
|
|
|
|
|
avgReplyTime = new Long(wxCusInfoRespDO.getAvg_reply_time());
|
|
|
|
|
}
|
|
|
|
|
poiCustomerContactDataStat.setAvgReplyTime(avgReplyTime);
|
|
|
|
|
|
|
|
|
|
Long chatCny = 0L;
|
|
|
|
|
if (wxCusInfoRespDO.getChat_cnt() != null) {
|
|
|
|
|
chatCny = new Long(wxCusInfoRespDO.getChat_cnt());
|
|
|
|
|
}
|
|
|
|
|
poiCustomerContactDataStat.setChatCnt(chatCny);
|
|
|
|
|
|
|
|
|
|
Long messageCnt = 0L;
|
|
|
|
|
if (wxCusInfoRespDO.getMessage_cnt() != null) {
|
|
|
|
|
messageCnt = new Long(wxCusInfoRespDO.getMessage_cnt());
|
|
|
|
|
}
|
|
|
|
|
poiCustomerContactDataStat.setMessageCnt(messageCnt);
|
|
|
|
|
|
|
|
|
|
Float replyPercentage = 0F;
|
|
|
|
|
if (wxCusInfoRespDO.getReply_percentage() != null) {
|
|
|
|
|
replyPercentage = wxCusInfoRespDO.getReply_percentage();
|
|
|
|
|
}
|
|
|
|
|
poiCustomerContactDataStat.setReplyPercentage(replyPercentage);
|
|
|
|
|
|
|
|
|
|
Long newContactCnt = 0L;
|
|
|
|
|
if (wxCusInfoRespDO.getNew_contact_cnt() != null) {
|
|
|
|
|
newContactCnt = new Long(wxCusInfoRespDO.getNew_contact_cnt());
|
|
|
|
|
}
|
|
|
|
|
poiCustomerContactDataStat.setNewContactCnt(newContactCnt);
|
|
|
|
|
|
|
|
|
|
Long negativeFeedbackCnt = 0L;
|
|
|
|
|
if (wxCusInfoRespDO.getNegative_feedback_cnt() != null) {
|
|
|
|
|
negativeFeedbackCnt = new Long(wxCusInfoRespDO.getNegative_feedback_cnt());
|
|
|
|
|
}
|
|
|
|
|
poiCustomerContactDataStat.setNegativeFeedbackCnt(negativeFeedbackCnt);
|
|
|
|
|
|
|
|
|
|
syncRes = poiCustomerContactDataStatMapper.updateById(poiCustomerContactDataStat);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (syncRes == Constants.INSERT_FAIL) {
|
|
|
|
|
throw new RuntimeException("向数据库导入客户统计数据时出错");
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("请求企业微信api获取客户统计数据或日期转换出错!", e);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PageInfo<PoiCustomerContactDataStat> listUserBehaviorData(Long userId,Long companyId,Long shopId,Date startDate, Date endDate,Integer pageNum,Integer pageSize){
|
|
|
|
|
Set<Long> shopIds = new HashSet<>();
|
|
|
|
@ -512,21 +334,6 @@ public class StorePromotionDataService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取联系客户统计数据
|
|
|
|
|
*
|
|
|
|
|
* @param wxCusInfoReqDO
|
|
|
|
|
* @return
|
|
|
|
|
* @throws WxErrorException
|
|
|
|
|
*/
|
|
|
|
|
public WxCusInfoRespDO getWxCusInfo(WxCusInfoReqDO wxCusInfoReqDO) throws WxErrorException {
|
|
|
|
|
String url = mainService.getWxCpConfigStorage().getApiUrl("/cgi-bin/externalcontact/get_user_behavior_data");
|
|
|
|
|
String result = mainService.post(url, wxCusInfoReqDO.toJson());
|
|
|
|
|
JSONObject parseObject = JSON.parseObject(result);
|
|
|
|
|
String[] behavior_data = JSONObject.parseObject(parseObject.getString("behavior_data"), String[].class);
|
|
|
|
|
return JSONObject.parseObject(behavior_data[0], WxCusInfoRespDO.class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取联系客户统计数据
|
|
|
|
|
*
|
|
|
|
|