|
@@ -0,0 +1,107 @@
|
|
|
|
|
+package cn.com.ctop.job.adq.data.service.impl;
|
|
|
|
|
+
|
|
|
|
|
+import cn.com.ctop.job.adq.data.entity.AdqAdvertiserFundsDaily;
|
|
|
|
|
+import cn.com.ctop.job.adq.data.entity.AdqErrorLog;
|
|
|
|
|
+import cn.com.ctop.job.adq.data.mapper.AdqAdvertiserFundsMapper;
|
|
|
|
|
+import cn.com.ctop.job.adq.data.mapper.AdqErrorLogMapper;
|
|
|
|
|
+import cn.com.ctop.job.adq.data.service.IAdqAdvertiserFundsService;
|
|
|
|
|
+import cn.com.ctop.job.adq.data.utils.AlertUtils;
|
|
|
|
|
+import cn.com.ctop.job.adq.data.utils.Check;
|
|
|
|
|
+import cn.com.ctop.job.adq.data.utils.HttpUtils;
|
|
|
|
|
+import cn.com.ctop.job.adq.utils.RandomStringGenerator;
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+
|
|
|
|
|
+import java.time.Instant;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+
|
|
|
|
|
+@Slf4j
|
|
|
|
|
+@Service
|
|
|
|
|
+public class AdqAdvertiserFundsServiceImpl implements IAdqAdvertiserFundsService {
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private AdqAdvertiserFundsMapper adqAdvertiserFundsMapper;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private AdqErrorLogMapper adqErrorLogMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void getAdqAccountFunds(Long advertiserId, String accessToken, String fundsDate, Integer isLog, Long errId, Integer isSend) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ Map<String, Object> paramsMap = new HashMap<>();
|
|
|
|
|
+ paramsMap.put("access_token", accessToken);
|
|
|
|
|
+ long timestamp = Instant.now().getEpochSecond();
|
|
|
|
|
+ paramsMap.put("timestamp", String.valueOf(timestamp));
|
|
|
|
|
+ paramsMap.put("nonce", RandomStringGenerator.generateRandomString(32));
|
|
|
|
|
+ paramsMap.put("account_id", advertiserId);
|
|
|
|
|
+ List<AdqAdvertiserFundsDaily> fundsList = new ArrayList<>();
|
|
|
|
|
+ String s = HttpUtils.httpGet("https://api.e.qq.com/v3.0/funds/get", paramsMap, null);
|
|
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(s);
|
|
|
|
|
+ if (Check.isNull(jsonObject)) {
|
|
|
|
|
+ log.error("请求账户资金余额失败,account_id:{},返回为空。", advertiserId);
|
|
|
|
|
+ insertErrorLog(isLog, advertiserId, fundsDate, null);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ Integer code = jsonObject.getInteger("code");
|
|
|
|
|
+ if (code != 0) {
|
|
|
|
|
+ log.error("请求账户资金余额失败,account_id:{},返回信息:{}", advertiserId, jsonObject);
|
|
|
|
|
+ insertErrorLog(isLog, advertiserId, fundsDate, null);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ JSONObject data = jsonObject.getJSONObject("data");
|
|
|
|
|
+ if (!Check.isNull(data)) {
|
|
|
|
|
+ JSONArray list = data.getJSONArray("list");
|
|
|
|
|
+ if (!Check.isNull(list)) {
|
|
|
|
|
+ Long statTimeDay = Long.valueOf(fundsDate.replace("-", ""));
|
|
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
|
|
+ JSONObject fundJson = list.getJSONObject(i);
|
|
|
|
|
+ AdqAdvertiserFundsDaily funds = new AdqAdvertiserFundsDaily();
|
|
|
|
|
+ funds.setAdvertiserId(advertiserId);
|
|
|
|
|
+ funds.setStatTimeDay(statTimeDay);
|
|
|
|
|
+ funds.setFundType(fundJson.getString("fund_type"));
|
|
|
|
|
+ funds.setBalance(fundJson.getLong("balance"));
|
|
|
|
|
+ funds.setBillDepositAmount(fundJson.getLong("bill_deposit_amount"));
|
|
|
|
|
+ funds.setFundStatus(fundJson.getString("fund_status"));
|
|
|
|
|
+ funds.setRealtimeCost(fundJson.getLong("realtime_cost"));
|
|
|
|
|
+ funds.setRawResponse(fundJson.toJSONString());
|
|
|
|
|
+ fundsList.add(funds);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!Check.isNull(fundsList)) {
|
|
|
|
|
+ adqAdvertiserFundsMapper.addAdqAdvertiserFunds(fundsList);
|
|
|
|
|
+ }
|
|
|
|
|
+ log.info("请求账户资金余额完成,account_id:{},日期:{},条数:{}", advertiserId, fundsDate, fundsList.size());
|
|
|
|
|
+ if (errId != null) {
|
|
|
|
|
+ adqErrorLogMapper.deleteInfoByErrorId(errId);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (isSend != null && isSend == 1) {
|
|
|
|
|
+ AlertUtils.sendMessage(advertiserId, fundsDate, fundsDate, 3, "daily", 1, "funds");
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ insertErrorLog(isLog, advertiserId, fundsDate, e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void insertErrorLog(Integer isLog, Long advertiserId, String fundsDate, String msg) {
|
|
|
|
|
+ if (isLog != null && isLog == 1) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ AdqErrorLog errorInfo = new AdqErrorLog();
|
|
|
|
|
+ errorInfo.setAdvertiserId(advertiserId);
|
|
|
|
|
+ errorInfo.setStartDate(fundsDate);
|
|
|
|
|
+ errorInfo.setEndDate(fundsDate);
|
|
|
|
|
+ errorInfo.setDataDimension("funds");
|
|
|
|
|
+ errorInfo.setDataType("daily");
|
|
|
|
|
+ errorInfo.setMsg(msg);
|
|
|
|
|
+ adqErrorLogMapper.replaceErrorInfo(errorInfo);
|
|
|
|
|
+ } catch (Exception ex) {
|
|
|
|
|
+ log.error("记录账户资金余额失败日志异常,account_id:{}", advertiserId, ex);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|