|
@@ -1,8 +1,12 @@
|
|
|
package cn.com.ctop.job.bytedance.data.service.impl;
|
|
package cn.com.ctop.job.bytedance.data.service.impl;
|
|
|
|
|
|
|
|
|
|
+import cn.com.ctop.job.bytedance.data.entity.BytedanceErrorLog;
|
|
|
|
|
+import cn.com.ctop.job.bytedance.data.entity.ChangDuOrder;
|
|
|
import cn.com.ctop.job.bytedance.data.entity.ChannelChangdunovelInfo;
|
|
import cn.com.ctop.job.bytedance.data.entity.ChannelChangdunovelInfo;
|
|
|
|
|
+import cn.com.ctop.job.bytedance.data.mapper.BytedancePromoterReportMapper;
|
|
|
import cn.com.ctop.job.bytedance.data.mapper.ChannelMapper;
|
|
import cn.com.ctop.job.bytedance.data.mapper.ChannelMapper;
|
|
|
import cn.com.ctop.job.bytedance.data.service.IChannelService;
|
|
import cn.com.ctop.job.bytedance.data.service.IChannelService;
|
|
|
|
|
+import cn.com.ctop.job.bytedance.data.utils.AlertUtils;
|
|
|
import cn.com.ctop.job.bytedance.data.utils.Check;
|
|
import cn.com.ctop.job.bytedance.data.utils.Check;
|
|
|
import cn.com.ctop.job.bytedance.data.utils.DateUtils;
|
|
import cn.com.ctop.job.bytedance.data.utils.DateUtils;
|
|
|
import cn.com.ctop.job.bytedance.data.utils.HttpUtils;
|
|
import cn.com.ctop.job.bytedance.data.utils.HttpUtils;
|
|
@@ -22,6 +26,8 @@ import java.util.Map;
|
|
|
public class ChannelServiceImpl implements IChannelService {
|
|
public class ChannelServiceImpl implements IChannelService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private ChannelMapper channelMapper;
|
|
private ChannelMapper channelMapper;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private BytedancePromoterReportMapper promoterReportMapper;
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void getPromotionIdList(String startDt, String endDt, String distributorId, String secretKey, Integer offset) {
|
|
public void getPromotionIdList(String startDt, String endDt, String distributorId, String secretKey, Integer offset) {
|
|
@@ -65,6 +71,7 @@ public class ChannelServiceImpl implements IChannelService {
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
log.error("返回数据为空");
|
|
log.error("返回数据为空");
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (!Check.isNull(adds)) {
|
|
if (!Check.isNull(adds)) {
|
|
@@ -84,10 +91,166 @@ public class ChannelServiceImpl implements IChannelService {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void getOrderList(String startDt, String endDt, String appId, String appName, String distributorId, String secretKey, Integer isLog, Long errId, Integer isSend) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ Long dataRangeSeconds = 3600L;//常读订单拉取接口offset > 10000 时会报错,只能分段拉取
|
|
|
|
|
+ String startTime = startDt + (startDt.contains(" ") ? "" : " 00:00:00");
|
|
|
|
|
+ Long startT = DateUtils.getTimestampFormat("yyyy-MM-dd HH:mm:ss", startTime);
|
|
|
|
|
+ String endTime = endDt + (endDt.contains(" ") ? "" : " 23:59:59");
|
|
|
|
|
+ Long endT = DateUtils.getTimestampFormat("yyyy-MM-dd HH:mm:ss", endTime);
|
|
|
|
|
+ boolean hasMoreTime = true;
|
|
|
|
|
+ while (hasMoreTime) {
|
|
|
|
|
+ Long thisEndT = startT + dataRangeSeconds;
|
|
|
|
|
+ if (thisEndT >= endT) {
|
|
|
|
|
+ thisEndT = endT;
|
|
|
|
|
+ }
|
|
|
|
|
+ //push接口没有订单创建时间,支付时间作为创建时间,所以查询已入库订单需要延后点时间,延后20分钟
|
|
|
|
|
+ long endPayTimestamp = thisEndT + 20 * 60;
|
|
|
|
|
+ String endPayTime = DateUtils.formatTimestamp("yyyy-MM-dd HH:mm:ss", endPayTimestamp);
|
|
|
|
|
+ Integer endPayDate = Integer.parseInt(DateUtils.formatTimestamp("yyyyMMdd", endPayTimestamp));
|
|
|
|
|
+ String startPayTime = DateUtils.formatTimestamp("yyyy-MM-dd HH:mm:ss", startT);
|
|
|
|
|
+ Integer startPayDate = Integer.parseInt(DateUtils.formatTimestamp("yyyyMMdd", startT));
|
|
|
|
|
+ List<String> orderIds = channelMapper.getOrderIds(startPayDate, startPayTime, endPayDate, endPayTime);
|
|
|
|
|
+
|
|
|
|
|
+ String thisStartTime = startPayTime;
|
|
|
|
|
+ String thisEndTime = DateUtils.formatTimestamp("yyyy-MM-dd HH:mm:ss", thisEndT);
|
|
|
|
|
+ int offset = 0;
|
|
|
|
|
+ boolean hasMore = true;
|
|
|
|
|
+ while (hasMore) {
|
|
|
|
|
+ log.info("常读订单拉取 [{}] {}~{} {}", distributorId, thisStartTime, thisEndTime, offset);
|
|
|
|
|
+ String url = "https://www.changdunovel.com/novelsale/openapi/user/recharge/v1";
|
|
|
|
|
+ String ts = String.valueOf(System.currentTimeMillis()).substring(0, 10);
|
|
|
|
|
+ String sign = getSign(distributorId, secretKey, ts);
|
|
|
|
|
+ Map<String, Object> params = new JSONObject();
|
|
|
|
|
+ params.put("distributor_id", distributorId);
|
|
|
|
|
+ params.put("ts", ts);
|
|
|
|
|
+ params.put("offset", offset);
|
|
|
|
|
+ params.put("limit", 1000);
|
|
|
|
|
+ params.put("sign", sign);
|
|
|
|
|
+ params.put("begin", startT);
|
|
|
|
|
+ params.put("end", thisEndT);
|
|
|
|
|
+ params.put("paid", true);
|
|
|
|
|
+ String s = HttpUtils.httpGet(url, params, null);
|
|
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(s);
|
|
|
|
|
+ List<ChangDuOrder> adds = new ArrayList<>();
|
|
|
|
|
+ if (!Check.isNull(jsonObject)) {
|
|
|
|
|
+ Integer code = jsonObject.getInteger("code");
|
|
|
|
|
+ if (code == 200) {
|
|
|
|
|
+ hasMore = jsonObject.getBoolean("has_more");
|
|
|
|
|
+ offset = jsonObject.getInteger("next_offset");
|
|
|
|
|
+ JSONArray result = jsonObject.getJSONArray("result");
|
|
|
|
|
+ if (!Check.isNull(result)) {
|
|
|
|
|
+ for (int i = 0; i < result.size(); i++) {
|
|
|
|
|
+ JSONObject resultJson = result.getJSONObject(i);
|
|
|
|
|
+ ChangDuOrder order = JSONObject.parseObject(resultJson.toJSONString(), ChangDuOrder.class);
|
|
|
|
|
+ String orderNo = order.getOrderNo();
|
|
|
|
|
+ if (orderIds.contains(orderNo)) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ order.setFxId(1);
|
|
|
|
|
+ order.setDistributorId(distributorId);
|
|
|
|
|
+ order.setAppId(appId);
|
|
|
|
|
+ order.setAppName(appName);
|
|
|
|
|
+
|
|
|
|
|
+ String uid = order.getDeviceId();
|
|
|
|
|
+ order.setUid(uid);
|
|
|
|
|
+ String payTime = order.getPayTime();
|
|
|
|
|
+ Map<String, Object> userMap = channelMapper.getUserInfo(distributorId, payTime, uid);
|
|
|
|
|
+
|
|
|
|
|
+ String advertiserId = null;
|
|
|
|
|
+ String aId = null;
|
|
|
|
|
+ String adId = null;
|
|
|
|
|
+ Integer platType = null;
|
|
|
|
|
+ String dyingMovieId = null;
|
|
|
|
|
+ String dyingMovieName = null;
|
|
|
|
|
+ Integer appType = null;
|
|
|
|
|
+ if (!Check.isNullMap(userMap)) {
|
|
|
|
|
+ advertiserId = userMap.get("advertiser_id") == null ? null : userMap.get("advertiser_id").toString();
|
|
|
|
|
+ aId = userMap.get("aid") == null ? null : userMap.get("aid").toString();
|
|
|
|
|
+ adId = userMap.get("ad_id") == null ? null : userMap.get("ad_id").toString();
|
|
|
|
|
+ platType = userMap.get("plat_type") == null ? null : Integer.valueOf(userMap.get("plat_type").toString());
|
|
|
|
|
+ dyingMovieId = userMap.get("movie_id") == null ? null : userMap.get("movie_id").toString();
|
|
|
|
|
+ dyingMovieName = userMap.get("movie_name") == null ? null : userMap.get("movie_name").toString();
|
|
|
|
|
+ appType = userMap.get("app_type") == null ? null : Integer.valueOf(userMap.get("app_type").toString());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (platType == null) {
|
|
|
|
|
+ String linkId = order.getLinkId();
|
|
|
|
|
+ Map<String, Object> linkInfo = channelMapper.getLinkInfo(linkId);
|
|
|
|
|
+ if (!Check.isNullMap(linkInfo)) {
|
|
|
|
|
+ String mediaSource = linkInfo.get("media_source").toString();
|
|
|
|
|
+ if ("1".equals(mediaSource)) {
|
|
|
|
|
+ platType = 1;
|
|
|
|
|
+ } else if ("4".equals(mediaSource)) {
|
|
|
|
|
+ platType = 3;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ order.setAppType(appType == null ? channelMapper.getAppType(appId) : appType);
|
|
|
|
|
+ order.setPlatType(platType);
|
|
|
|
|
+ order.setStatDate(Integer.parseInt(order.getCreateTime().substring(0, 10).replace("-", "")));
|
|
|
|
|
+ order.setDyingTime(order.getRegisterTime());
|
|
|
|
|
+ order.setAdvertiserId(advertiserId);
|
|
|
|
|
+ order.setAdId(adId);
|
|
|
|
|
+ order.setAId(aId);
|
|
|
|
|
+ order.setMovieName(channelMapper.getMovieName(order.getMovieId()));
|
|
|
|
|
+ order.setDyingMovieId(dyingMovieId);
|
|
|
|
|
+ order.setDyingMovieName(dyingMovieName);
|
|
|
|
|
+ log.info("常读order:[{}]",order);
|
|
|
|
|
+ adds.add(order);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.error("[{}]番茄订单请求失败{}~{},返回信息:{}", distributorId, thisStartTime, thisEndTime, s);
|
|
|
|
|
+ insertErrorLog(isLog, Long.parseLong(distributorId), thisStartTime, endTime, "changdu_order", "daily", s);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.error("[{}]番茄订单返回数据为空{}~{}", distributorId, thisStartTime, thisEndTime);
|
|
|
|
|
+ insertErrorLog(isLog, Long.parseLong(distributorId), thisStartTime, endTime, "changdu_order", "daily", "订单返回数据为空");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!Check.isNull(adds)) {
|
|
|
|
|
+ channelMapper.insertOrder(adds);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ hasMoreTime = thisEndT < endT;
|
|
|
|
|
+ startT = thisEndT;
|
|
|
|
|
+ if (errId != null) {
|
|
|
|
|
+ promoterReportMapper.deleteInfoByErrorId(errId);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (isSend != null && isSend == 1) {
|
|
|
|
|
+ AlertUtils.sendMessage(Long.parseLong(distributorId), thisStartTime, thisEndTime, 2, "daily", 1, "changdu_order");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ log.info("[{}]番茄订单请求完成{}~{}.", distributorId, startDt, endDt);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<JSONObject> getChangDuRetry() {
|
|
|
|
|
+ return channelMapper.getChangDuRetryJob();
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
private static String getSign(String distributorId, String secretKey, String ts) {
|
|
private static String getSign(String distributorId, String secretKey, String ts) {
|
|
|
return SecureUtil.md5(distributorId + secretKey + ts).toLowerCase();
|
|
return SecureUtil.md5(distributorId + secretKey + ts).toLowerCase();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private void insertErrorLog(Integer isLog, Long advertiserId, String startDate, String endDate, String dataDimension, String dataType, String msg) {
|
|
|
|
|
+ if (isLog != null && 1 == isLog) {
|
|
|
|
|
+ BytedanceErrorLog errorInfo = new BytedanceErrorLog();
|
|
|
|
|
+ errorInfo.setAdvertiserId(advertiserId);
|
|
|
|
|
+ errorInfo.setStartDate(startDate);
|
|
|
|
|
+ errorInfo.setEndDate(endDate);
|
|
|
|
|
+ errorInfo.setDataDimension(dataDimension);
|
|
|
|
|
+ errorInfo.setDataType(dataType);
|
|
|
|
|
+ errorInfo.setMsg(msg);
|
|
|
|
|
+ promoterReportMapper.replaceErrorInfo(errorInfo);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
}
|
|
}
|