|
|
@@ -5,6 +5,7 @@ import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.ytpm.advertise.enums.AdPlatformTypeEnum;
|
|
|
import com.ytpm.advertise.enums.AdSourceTypeEnum;
|
|
|
import com.ytpm.agent.enums.UserStatusEnum;
|
|
|
@@ -74,21 +75,9 @@ public class AdServiceImpl implements AdService {
|
|
|
param.setBeginTime(param.getFinishTime());
|
|
|
}
|
|
|
BeanUtils.copyProperties(param, adRecord);
|
|
|
- if (param.getBegintimestamp() != null && param.getFinishtimestamp() != null) {
|
|
|
- // 处理 begintimestamp(兼容秒级和毫秒级)
|
|
|
- long beginTimestamp = param.getBegintimestamp();
|
|
|
- if (String.valueOf(beginTimestamp).length() == 10) { // 秒级时间戳(10位)
|
|
|
- beginTimestamp *= 1000; // 转为毫秒级
|
|
|
- }
|
|
|
- adRecord.setBeginTime(DateUtil.format(new Date(beginTimestamp), "yyyy-MM-dd HH:mm:ss"));
|
|
|
|
|
|
- // 处理 finishtimestamp(兼容秒级和毫秒级)
|
|
|
- long finishTimestamp = param.getFinishtimestamp();
|
|
|
- if (String.valueOf(finishTimestamp).length() == 10) { // 秒级时间戳(10位)
|
|
|
- finishTimestamp *= 1000; // 转为毫秒级
|
|
|
- }
|
|
|
- adRecord.setFinishTime(DateUtil.format(new Date(finishTimestamp), "yyyy-MM-dd HH:mm:ss"));
|
|
|
- }
|
|
|
+ getEcpm(param);
|
|
|
+ timeParse(param, adRecord);
|
|
|
adRecord.setIosId(param.getIosId());
|
|
|
adRecord.setAppId(appId);
|
|
|
adRecord.setRecordId(IdUtil.fastSimpleUUID());
|
|
|
@@ -115,6 +104,26 @@ public class AdServiceImpl implements AdService {
|
|
|
return Result.resultOk(RepMessage.SAVE_SUCCESS);
|
|
|
}
|
|
|
|
|
|
+ private static void getEcpm(DyzAdRecordParam param) {
|
|
|
+ if (param.getEcpm() == null){
|
|
|
+ try {
|
|
|
+ // 1. 将 JSON 字符串解析为 Map 或自定义对象
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ Map<String, Object> jsonMap = objectMapper.readValue(param.getResultJson(), Map.class);
|
|
|
+
|
|
|
+ // 2. 提取 adsource_price 的值
|
|
|
+ BigDecimal adsourcePrice = new BigDecimal(jsonMap.get("adsource_price").toString()) ;
|
|
|
+
|
|
|
+ // 3. 设置到 ecpm 字段
|
|
|
+ param.setEcpm(adsourcePrice);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 异常处理(如 JSON 解析失败)
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private String getTipsMsg(){
|
|
|
String[] split = tips.split(",");
|
|
|
return split[RandomUtil.randomInt(split.length)];
|
|
|
@@ -322,7 +331,23 @@ public class AdServiceImpl implements AdService {
|
|
|
if(Objects.isNull(param.getBeginTime())){
|
|
|
param.setBeginTime(param.getFinishTime());
|
|
|
}
|
|
|
+ getEcpm(param);
|
|
|
BeanUtils.copyProperties(param, adRecord);
|
|
|
+ timeParse(param, adRecord);
|
|
|
+ adRecord.setIosId(param.getIosId());
|
|
|
+ adRecord.setRecordId(IdUtil.fastSimpleUUID());
|
|
|
+ adRecord.setUserId(user.getUserId());
|
|
|
+ adRecord.setNetworkName(AdPlatformTypeEnum.getDesc(Integer.parseInt(param.getNetworkFormId())));
|
|
|
+ adRecordMapper.addOne(adRecord);
|
|
|
+ //修改用户信息, 广告次数+1 总收益 + revenue
|
|
|
+ YtDyzUser dyzUser = new YtDyzUser();
|
|
|
+ dyzUser.setUserId(user.getUserId());
|
|
|
+ dyzUser.setTotalVideo(Objects.isNull(user.getTotalVideo())?1:(user.getTotalVideo()+1));
|
|
|
+ dyzUser.setTotalIncome(user.getTotalIncome().add(param.getRevenue()));
|
|
|
+ appUserMapper.updateUser(dyzUser);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void timeParse(DyzAdRecordParam param, YtDyzAdRecord adRecord) {
|
|
|
if (param.getBegintimestamp() != null && param.getFinishtimestamp() != null) {
|
|
|
// 处理 begintimestamp(兼容秒级和毫秒级)
|
|
|
long beginTimestamp = param.getBegintimestamp();
|
|
|
@@ -338,16 +363,5 @@ public class AdServiceImpl implements AdService {
|
|
|
}
|
|
|
adRecord.setFinishTime(DateUtil.format(new Date(finishTimestamp), "yyyy-MM-dd HH:mm:ss"));
|
|
|
}
|
|
|
- adRecord.setIosId(param.getIosId());
|
|
|
- adRecord.setRecordId(IdUtil.fastSimpleUUID());
|
|
|
- adRecord.setUserId(user.getUserId());
|
|
|
- adRecord.setNetworkName(AdPlatformTypeEnum.getDesc(Integer.parseInt(param.getNetworkFormId())));
|
|
|
- adRecordMapper.addOne(adRecord);
|
|
|
- //修改用户信息, 广告次数+1 总收益 + revenue
|
|
|
- YtDyzUser dyzUser = new YtDyzUser();
|
|
|
- dyzUser.setUserId(user.getUserId());
|
|
|
- dyzUser.setTotalVideo(Objects.isNull(user.getTotalVideo())?1:(user.getTotalVideo()+1));
|
|
|
- dyzUser.setTotalIncome(user.getTotalIncome().add(param.getRevenue()));
|
|
|
- appUserMapper.updateUser(dyzUser);
|
|
|
}
|
|
|
}
|