|
|
@@ -1,6 +1,7 @@
|
|
|
package com.ytpm.middle.service.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.text.CharSequenceUtil;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
@@ -9,6 +10,7 @@ import com.alibaba.fastjson.JSONArray;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
import com.ytpm.agent.model.YtApp;
|
|
|
+import com.ytpm.agent.model.YtAppConfigLog;
|
|
|
import com.ytpm.agent.model.YtPlatformUserApp;
|
|
|
import com.ytpm.agent.param.AppListParam;
|
|
|
import com.ytpm.agent.param.AppParam;
|
|
|
@@ -23,13 +25,15 @@ import com.ytpm.middle.dao.AppMapper;
|
|
|
import com.ytpm.middle.dao.RiskMapper;
|
|
|
import com.ytpm.middle.service.ApkService;
|
|
|
import com.ytpm.middle.util.AliOSSUtil;
|
|
|
+import com.ytpm.middle.util.BeanChangeUtil;
|
|
|
import com.ytpm.middle.util.FeignClientInvoker;
|
|
|
import com.ytpm.middle.view.MiddleUserInfo;
|
|
|
import com.ytpm.risk.model.YtRiskConfig;
|
|
|
import com.ytpm.risk.model.YtRiskTemplate;
|
|
|
import com.ytpm.risk.model.YtRiskTemplateConfig;
|
|
|
import com.ytpm.util.DateUtil;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -44,6 +48,7 @@ import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
@RefreshScope
|
|
|
public class ApkServiceImpl implements ApkService {
|
|
|
@@ -52,6 +57,11 @@ public class ApkServiceImpl implements ApkService {
|
|
|
private ApkMapper apkMapper;
|
|
|
@Resource
|
|
|
private RiskMapper riskMapper;
|
|
|
+ @Resource
|
|
|
+ private FeignClientInvoker feignInvoker;
|
|
|
+ @Resource
|
|
|
+ private AppMapper appMapper;
|
|
|
+
|
|
|
@Value("${risk.config.initEcpm}")
|
|
|
private String initEcpm;
|
|
|
@Value("${risk.config.initRevenue}")
|
|
|
@@ -89,10 +99,7 @@ public class ApkServiceImpl implements ApkService {
|
|
|
@Value(("${risk.config.visitor.initRidCount:10}"))
|
|
|
private String initVisitorRidCount;
|
|
|
|
|
|
- @Autowired
|
|
|
- private FeignClientInvoker feignInvoker;
|
|
|
- @Autowired
|
|
|
- private AppMapper appMapper;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 查询应用列表
|
|
|
@@ -119,6 +126,12 @@ public class ApkServiceImpl implements ApkService {
|
|
|
Map<String, Integer> countDownloadMap = AliOSSUtil.getCountDownload(
|
|
|
Math.toIntExact(DateUtil.getTodayStart().getTime() / 1000), (int) (System.currentTimeMillis() / 1000));
|
|
|
WxDefaultConfig config;
|
|
|
+ // 查询配置修改记录
|
|
|
+ List<YtAppConfigLog> configLogs = appMapper.selectLastConfigLog(appIds);
|
|
|
+ Map<String, YtAppConfigLog> configLogMap = configLogs.stream().collect(Collectors.toMap(
|
|
|
+ YtAppConfigLog::getAppId, item-> item,
|
|
|
+ (o1,o2) -> o2
|
|
|
+ ));
|
|
|
for (AgentAppView view : views) {
|
|
|
if(appTypeMap.containsKey(view.getAppId())) {
|
|
|
config = appTypeMap.get(view.getAppId());
|
|
|
@@ -144,6 +157,7 @@ public class ApkServiceImpl implements ApkService {
|
|
|
view.setBrushTip(config.getBrushTip());
|
|
|
view.setFlowIntervalTime(config.getFlowIntervalTime());
|
|
|
view.setCanAllowAutoRefresh(config.getCanAllowAutoRefresh());
|
|
|
+ view.setLastChangeLog(configLogMap.get(view.getAppId()));
|
|
|
}
|
|
|
if(CharSequenceUtil.isBlank(view.getApkUrl()))continue;
|
|
|
String substring = view.getApkUrl().substring(view.getApkUrl().lastIndexOf("/")+1).toLowerCase(Locale.ENGLISH);
|
|
|
@@ -160,17 +174,19 @@ public class ApkServiceImpl implements ApkService {
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Result<?> saveApp(AppParam param, MiddleUserInfo loginUser) {
|
|
|
+ YtPlatformUserApp app = appMapper.getByPrimary(param.getSuperiorId());
|
|
|
+ // 保存修改记录
|
|
|
+ saveConfigChangeLog(param, app, loginUser.getUserId());
|
|
|
//数据库操作,有appId为修改, 没有时为新增
|
|
|
changeDataAction(param, loginUser.getUserId());
|
|
|
//出包修改 default_config
|
|
|
changeDefaultConfig(param);
|
|
|
if(CharSequenceUtil.isNotBlank(param.getAppId())){
|
|
|
//修改时判断已生成风控配置,则说明出过包,仅需更换即可
|
|
|
- YtRiskTemplate template = riskMapper.getTemplateByAppId(param.getAppId());
|
|
|
+ YtRiskTemplate template = riskMapper.getTemplateByAppId(param.getAppId());
|
|
|
if(Objects.isNull(template)){
|
|
|
generateRiskDefaultConfig(param,loginUser);
|
|
|
}
|
|
|
- return Result.resultOk(RepMessage.SAVE_SUCCESS);
|
|
|
}
|
|
|
return Result.resultOk(RepMessage.SAVE_SUCCESS);
|
|
|
}
|
|
|
@@ -181,6 +197,8 @@ public class ApkServiceImpl implements ApkService {
|
|
|
@Override
|
|
|
public Result<?> changeConfig(AppParam param) {
|
|
|
//出包修改 default_config
|
|
|
+ YtPlatformUserApp app = appMapper.getByPrimary(param.getSuperiorId());
|
|
|
+ saveConfigChangeLog(param, app, null);
|
|
|
changeDefaultConfig(param);
|
|
|
return Result.resultOk(RepMessage.SAVE_SUCCESS);
|
|
|
}
|
|
|
@@ -190,6 +208,11 @@ public class ApkServiceImpl implements ApkService {
|
|
|
*/
|
|
|
private void changeDefaultConfig(AppParam param) {
|
|
|
YtPlatformUserApp app = appMapper.getByPrimary(param.getSuperiorId());
|
|
|
+ YtAppDefaultConfig config = convertToYtDefaultConfig(param, app);
|
|
|
+ feignInvoker.invoke(app.getServiceName(), "updateAppConfig", config);
|
|
|
+ }
|
|
|
+
|
|
|
+ private YtAppDefaultConfig convertToYtDefaultConfig(AppParam param, YtPlatformUserApp app){
|
|
|
YtAppDefaultConfig config = new YtAppDefaultConfig();
|
|
|
config.setAppId(param.getAppId());
|
|
|
if(Objects.nonNull(param.getDitchId())){
|
|
|
@@ -214,7 +237,47 @@ public class ApkServiceImpl implements ApkService {
|
|
|
config.setCanCacheVideo(param.getCanCacheVideo());
|
|
|
config.setStartWaitTime(param.getStartWaitTime());
|
|
|
config.setCanAllowAutoRefresh(param.getCanAllowAutoRefresh());
|
|
|
- feignInvoker.invoke(app.getServiceName(), "updateAppConfig",config);
|
|
|
+ return config;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void saveConfigChangeLog(AppParam appParam, YtPlatformUserApp app, String loginUserId) {
|
|
|
+ StringBuilder changeContent = new StringBuilder();
|
|
|
+ try {
|
|
|
+ YtApp oldYtApp = appMapper.selectByPrimaryId(appParam.getAppId());
|
|
|
+ if (oldYtApp != null) {
|
|
|
+ YtApp newYtApp = new YtApp();
|
|
|
+ BeanUtil.copyProperties(appParam, newYtApp);
|
|
|
+ changeContent.append(BeanChangeUtil.compareBeans(oldYtApp, newYtApp));
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ Object object = feignInvoker.invoke(app.getServiceName(), "getConfigs", appParam.getAppId());
|
|
|
+ WxDefaultConfig oldDefault = null;
|
|
|
+ if (object != null) {
|
|
|
+ List<WxDefaultConfig> configList = JSONArray.parseArray(JSON.toJSONString(object), WxDefaultConfig.class);
|
|
|
+ oldDefault = CollUtil.isNotEmpty(configList) ? configList.get(0) : null;
|
|
|
+ }
|
|
|
+ if (oldDefault != null) {
|
|
|
+ // 变更记录修改
|
|
|
+ YtAppDefaultConfig config = convertToYtDefaultConfig(appParam, app);
|
|
|
+ WxDefaultConfig newConfig = new WxDefaultConfig();
|
|
|
+ BeanUtils.copyProperties(config, newConfig);
|
|
|
+ changeContent.append(BeanChangeUtil.compareBeans(oldDefault, newConfig));
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ }
|
|
|
+ if (changeContent.length() > 0) {
|
|
|
+ YtAppConfigLog configLog = new YtAppConfigLog();
|
|
|
+ configLog.setRecordId(IdUtil.fastSimpleUUID());
|
|
|
+ configLog.setAppId(appParam.getAppId());
|
|
|
+ configLog.setChangeContent(changeContent.toString());
|
|
|
+ configLog.setChangeTime(new Date());
|
|
|
+ configLog.setChangeBy(loginUserId);
|
|
|
+ appMapper.insertConfigLog(configLog);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|