|
@@ -18,6 +18,7 @@ import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -227,14 +228,14 @@ public class KuaiShouAccountCleanServiceImpl implements KuaiShouAccountCleanServ
|
|
@Override
|
|
@Override
|
|
public Result getCleanUpLog(String templateId, String userId, String pageNum, String pageSize) {
|
|
public Result getCleanUpLog(String templateId, String userId, String pageNum, String pageSize) {
|
|
Result result = new Result();
|
|
Result result = new Result();
|
|
- List<KuaiShouAccountCleanLogInfo> cleanUpLog=new ArrayList<>();
|
|
|
|
|
|
+ List<KuaiShouAccountCleanLogInfo> cleanUpLog = new ArrayList<>();
|
|
try {
|
|
try {
|
|
//查询当前登录人角色
|
|
//查询当前登录人角色
|
|
String roleCode = sysRoleService.getRoleCodeByUserId(userId);
|
|
String roleCode = sysRoleService.getRoleCodeByUserId(userId);
|
|
PageHelper.startPage(Integer.parseInt(pageNum), Integer.parseInt(pageSize));
|
|
PageHelper.startPage(Integer.parseInt(pageNum), Integer.parseInt(pageSize));
|
|
if (roleCode != null && roleCode.equals("admin")) {
|
|
if (roleCode != null && roleCode.equals("admin")) {
|
|
cleanUpLog = kuaishouAccountCleanTemplateMapper.getCleanUpLog(templateId, null);
|
|
cleanUpLog = kuaishouAccountCleanTemplateMapper.getCleanUpLog(templateId, null);
|
|
- }else {
|
|
|
|
|
|
+ } else {
|
|
cleanUpLog = kuaishouAccountCleanTemplateMapper.getCleanUpLog(templateId, userId);
|
|
cleanUpLog = kuaishouAccountCleanTemplateMapper.getCleanUpLog(templateId, userId);
|
|
}
|
|
}
|
|
PageHelper.startPage(Integer.parseInt(pageNum), Integer.parseInt(pageSize));
|
|
PageHelper.startPage(Integer.parseInt(pageNum), Integer.parseInt(pageSize));
|
|
@@ -291,12 +292,22 @@ public class KuaiShouAccountCleanServiceImpl implements KuaiShouAccountCleanServ
|
|
public Result cleanAccount() {
|
|
public Result cleanAccount() {
|
|
Result result = new Result();
|
|
Result result = new Result();
|
|
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
+ Map optimizationObjectiveMap = new HashMap();
|
|
|
|
+ //优化目标 activation:激活数 bclick:行为数 formSize :表单数 pay:付费 roi:首日roi evocativeApplication:唤起应用
|
|
|
|
+ // effectiveClues:有效线索 creditApp:授信-APP creditGrant:授信-落地页 finishedPieceApp:完件数-APP finishedPieceGrant:完件数-落地页 registered:注册
|
|
|
|
+ optimizationObjectiveMap.put("180", "activation");
|
|
|
|
+ optimizationObjectiveMap.put("53", "formSize");
|
|
|
|
+ optimizationObjectiveMap.put("190", "pay");
|
|
|
|
+ optimizationObjectiveMap.put("324", "evocativeApplication");
|
|
|
|
+ optimizationObjectiveMap.put("396", "registered");
|
|
try {
|
|
try {
|
|
//查询需要执行的规则模板
|
|
//查询需要执行的规则模板
|
|
List<KuaiShouAccountCleanTemplateInfo> templateListBystatus = kuaishouAccountCleanTemplateMapper.getTemplateListBystatus();
|
|
List<KuaiShouAccountCleanTemplateInfo> templateListBystatus = kuaishouAccountCleanTemplateMapper.getTemplateListBystatus();
|
|
if (!templateListBystatus.isEmpty()) {
|
|
if (!templateListBystatus.isEmpty()) {
|
|
templateListBystatus.stream().forEach(ob -> {
|
|
templateListBystatus.stream().forEach(ob -> {
|
|
- if(ob.getAccountId()!=null){
|
|
|
|
|
|
+ AtomicInteger count= new AtomicInteger();
|
|
|
|
+ if (ob.getAccountId() != null) {
|
|
|
|
+ StringBuilder unitIds = new StringBuilder();
|
|
//获取各项优化目标
|
|
//获取各项优化目标
|
|
List<String> optimizationObjectiveList = Arrays.asList(ob.getOptimizationObjective().split(","));
|
|
List<String> optimizationObjectiveList = Arrays.asList(ob.getOptimizationObjective().split(","));
|
|
//获取清理时间范围
|
|
//获取清理时间范围
|
|
@@ -305,26 +316,48 @@ public class KuaiShouAccountCleanServiceImpl implements KuaiShouAccountCleanServ
|
|
Calendar calendar = Calendar.getInstance();//此时打印它获取的是系统当前时间
|
|
Calendar calendar = Calendar.getInstance();//此时打印它获取的是系统当前时间
|
|
calendar.add(Calendar.DATE, -Integer.parseInt(cleanTime));
|
|
calendar.add(Calendar.DATE, -Integer.parseInt(cleanTime));
|
|
String startDate = new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime());
|
|
String startDate = new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime());
|
|
- //查询符合模板规则的组
|
|
|
|
- List<String> groupMessage = kuaishouAccountCleanTemplateMapper.getGroupMessage(ob, optimizationObjectiveList, startDate);
|
|
|
|
AtomicReference<Boolean> falg = new AtomicReference<>(true);
|
|
AtomicReference<Boolean> falg = new AtomicReference<>(true);
|
|
- if (!groupMessage.isEmpty()) {
|
|
|
|
- //获取Token
|
|
|
|
- CtopOauthToken ctopOauthToken = ctopOauthTokenMapper.selectByAccountId(Long.parseLong(ob.getAccountId()));
|
|
|
|
- if (ctopOauthToken != null) {
|
|
|
|
- groupMessage.stream().forEach(item -> {
|
|
|
|
- //修改广告组状态
|
|
|
|
- Map<String, Object> resultMap = iKuaiShouUpdateService.updateUnitStatus(ctopOauthToken.getAccessToken(), Long.parseLong(ob.getAccountId()), Long.parseLong(item), Integer.parseInt(ob.getPerformOperations()), null);
|
|
|
|
- Boolean resultFlag = (Boolean) resultMap.get("success");
|
|
|
|
- //判断有没有失败
|
|
|
|
- if (!resultFlag) {
|
|
|
|
- falg.set(false);
|
|
|
|
|
|
+ //查询改账户下所有组
|
|
|
|
+ List<Map> groupByAccount = kuaishouAccountCleanTemplateMapper.getGroupByAccount(ob.getAccountId());
|
|
|
|
+ if (!groupByAccount.isEmpty()) {
|
|
|
|
+ groupByAccount.stream().forEach(obj -> {
|
|
|
|
+ if (obj.get("unitId") != null && obj.get("type") != null) {
|
|
|
|
+ String unitId = Long.toString((Long) obj.get("unitId")) ;
|
|
|
|
+ //OCPM
|
|
|
|
+ String type = Integer.toString((Integer) obj.get("type")) ;
|
|
|
|
+ if(optimizationObjectiveMap.get(type)!=null){
|
|
|
|
+ String optimizationObjective= (String) optimizationObjectiveMap.get(type);
|
|
|
|
+ //查询组是否符合清理规则
|
|
|
|
+ String groupMessage = kuaishouAccountCleanTemplateMapper.getGroupMessage(ob, optimizationObjective, startDate,unitId);
|
|
|
|
+ if(groupMessage!=null){
|
|
|
|
+ count.getAndIncrement();
|
|
|
|
+ //符合清理规则清理
|
|
|
|
+ //获取Token
|
|
|
|
+ CtopOauthToken ctopOauthToken = ctopOauthTokenMapper.selectByAccountId(Long.parseLong(ob.getAccountId()));
|
|
|
|
+ if (ctopOauthToken != null) {
|
|
|
|
+ //修改广告组状态
|
|
|
|
+ Map<String, Object> resultMap = iKuaiShouUpdateService.updateUnitStatus(ctopOauthToken.getAccessToken(), Long.parseLong(ob.getAccountId()), Long.parseLong(unitId), Integer.parseInt(ob.getPerformOperations()), null);
|
|
|
|
+ Boolean resultFlag = (Boolean) resultMap.get("success");
|
|
|
|
+ //判断有没有失败
|
|
|
|
+ if (resultFlag) {
|
|
|
|
+ //清理成功
|
|
|
|
+ unitIds.append(unitId).append(",");
|
|
|
|
+ log.info("组"+unitId+"已被清理");
|
|
|
|
+ }else {
|
|
|
|
+ //清理失败
|
|
|
|
+ log.info("组"+unitId+"清理失败:{}",resultMap.get("message"));
|
|
|
|
+ falg.set(false);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- });
|
|
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
+ });
|
|
}
|
|
}
|
|
- if (!groupMessage.isEmpty() && falg.get()) {
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if (count.get()>0 && falg.get()) {
|
|
//修改成功插入日志记录
|
|
//修改成功插入日志记录
|
|
KuaiShouAccountCleanLogInfo kuaiShouAccountCleanLogInfo = new KuaiShouAccountCleanLogInfo();
|
|
KuaiShouAccountCleanLogInfo kuaiShouAccountCleanLogInfo = new KuaiShouAccountCleanLogInfo();
|
|
//设置账户id
|
|
//设置账户id
|
|
@@ -332,18 +365,14 @@ public class KuaiShouAccountCleanServiceImpl implements KuaiShouAccountCleanServ
|
|
// 1-投放、2-暂停、3-删除
|
|
// 1-投放、2-暂停、3-删除
|
|
kuaiShouAccountCleanLogInfo.setOperationType(ob.getPerformOperations());
|
|
kuaiShouAccountCleanLogInfo.setOperationType(ob.getPerformOperations());
|
|
//设置运营
|
|
//设置运营
|
|
- Map<String, String> map = kuaishouAccountCleanTemplateMapper.getUserNameByAccountId(ob.getAccountId());
|
|
|
|
- String authName = "";
|
|
|
|
- if (map != null) {
|
|
|
|
- kuaiShouAccountCleanLogInfo.setUserName(map.get("userName"));
|
|
|
|
- authName = map.get("authName");
|
|
|
|
- }
|
|
|
|
|
|
+// Map<String, String> map = kuaishouAccountCleanTemplateMapper.getUserNameByAccountId(ob.getAccountId());
|
|
|
|
+// String authName = "";
|
|
|
|
+// if (map != null) {
|
|
|
|
+// kuaiShouAccountCleanLogInfo.setUserName(map.get("userName"));
|
|
|
|
+// authName = map.get("authName");
|
|
|
|
+// }
|
|
//设置时间
|
|
//设置时间
|
|
kuaiShouAccountCleanLogInfo.setCreateTime(sd.format(new Date()));
|
|
kuaiShouAccountCleanLogInfo.setCreateTime(sd.format(new Date()));
|
|
- StringBuilder unitIds = new StringBuilder();
|
|
|
|
- groupMessage.stream().forEach(unid -> {
|
|
|
|
- unitIds.append(unid).append(",");
|
|
|
|
- });
|
|
|
|
//操作类型
|
|
//操作类型
|
|
String operationType = null;
|
|
String operationType = null;
|
|
if (ob.getPerformOperations().equals("2")) {
|
|
if (ob.getPerformOperations().equals("2")) {
|
|
@@ -353,10 +382,11 @@ public class KuaiShouAccountCleanServiceImpl implements KuaiShouAccountCleanServ
|
|
operationType = "删除";
|
|
operationType = "删除";
|
|
}
|
|
}
|
|
//执行信息
|
|
//执行信息
|
|
- String textMessage = "清理规则执行: 账户:" + ob.getAccountId() + ", 授权名称: " + authName + ",推广组:" + unitIds + "已经被清理规则" + operationType;
|
|
|
|
|
|
+ String textMessage = "清理规则执行: 账户:" + ob.getAccountId() + ", 授权名称: " + ob.getCreateUser() + ",推广组:" + unitIds + "已经被清理规则" + operationType;
|
|
kuaiShouAccountCleanLogInfo.setExecutiveInformation(textMessage);
|
|
kuaiShouAccountCleanLogInfo.setExecutiveInformation(textMessage);
|
|
kuaiShouAccountCleanLogInfo.setTemplateId(ob.getId());
|
|
kuaiShouAccountCleanLogInfo.setTemplateId(ob.getId());
|
|
kuaiShouAccountCleanLogInfo.setCreateTemplateId(ob.getCreateId());
|
|
kuaiShouAccountCleanLogInfo.setCreateTemplateId(ob.getCreateId());
|
|
|
|
+ kuaiShouAccountCleanLogInfo.setUserName(ob.getCreateUser());
|
|
kuaishouAccountCleanTemplateMapper.saveCleamLog(kuaiShouAccountCleanLogInfo);
|
|
kuaishouAccountCleanTemplateMapper.saveCleamLog(kuaiShouAccountCleanLogInfo);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -370,6 +400,7 @@ public class KuaiShouAccountCleanServiceImpl implements KuaiShouAccountCleanServ
|
|
}
|
|
}
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 根据模板名称查询
|
|
* 根据模板名称查询
|
|
*
|
|
*
|
|
@@ -380,9 +411,9 @@ public class KuaiShouAccountCleanServiceImpl implements KuaiShouAccountCleanServ
|
|
public Result getTemplateName(String templateName) {
|
|
public Result getTemplateName(String templateName) {
|
|
Result result = new Result();
|
|
Result result = new Result();
|
|
try {
|
|
try {
|
|
- int number = kuaishouAccountCleanTemplateMapper.getTemplateName(templateName.trim());
|
|
|
|
|
|
+ int number = kuaishouAccountCleanTemplateMapper.getTemplateName(templateName.trim());
|
|
result.setResult(number);
|
|
result.setResult(number);
|
|
- }catch (Exception e){
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
log.info("查询失败:{}", e.toString());
|
|
log.info("查询失败:{}", e.toString());
|
|
result.error500("查询失败");
|
|
result.error500("查询失败");
|
|
}
|
|
}
|