|
@@ -53,6 +53,7 @@ public class KuaiShouAccountCleanServiceImpl implements KuaiShouAccountCleanServ
|
|
|
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
Random rand = new Random();
|
|
|
int id = 100000 + rand.nextInt(99900000);
|
|
|
+
|
|
|
//设置6-8位数字
|
|
|
kuaiShouAccountCleanTemplateInfo.setId(String.valueOf(id));
|
|
|
//设置应用媒体 固定写死
|
|
@@ -62,6 +63,8 @@ public class KuaiShouAccountCleanServiceImpl implements KuaiShouAccountCleanServ
|
|
|
//设置创建日期
|
|
|
kuaiShouAccountCleanTemplateInfo.setCreateTime(sd.format(new Date()));
|
|
|
try {
|
|
|
+ String userRealName = kuaishouAccountCleanTemplateMapper.getUserRealName(kuaiShouAccountCleanTemplateInfo.getCreateId());
|
|
|
+ kuaiShouAccountCleanTemplateInfo.setCreateUser(userRealName);
|
|
|
kuaishouAccountCleanTemplateMapper.saveAccountCleanTemplate(kuaiShouAccountCleanTemplateInfo);
|
|
|
result.success("创建模板成功");
|
|
|
} catch (Exception e) {
|
|
@@ -74,11 +77,11 @@ public class KuaiShouAccountCleanServiceImpl implements KuaiShouAccountCleanServ
|
|
|
/**
|
|
|
* 查询模板列表
|
|
|
*
|
|
|
- * @param templateId 模板id createUser创建人
|
|
|
+ * @param templateName 模板名称 createUser创建人
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public Result getTemplateList(String templateId, String createUser, String userId, String pageNum, String pageSize) {
|
|
|
+ public Result getTemplateList(String templateName, String createUser, String userId, String pageNum, String pageSize) {
|
|
|
Result result = new Result();
|
|
|
PageHelper pageHelper = new PageHelper();
|
|
|
List<KuaiShouAccountCleanTemplateInfo> templateList = new ArrayList<>();
|
|
@@ -86,12 +89,12 @@ public class KuaiShouAccountCleanServiceImpl implements KuaiShouAccountCleanServ
|
|
|
//查询当前登录人角色
|
|
|
String roleCode = sysRoleService.getRoleCodeByUserId(userId);
|
|
|
PageHelper.startPage(Integer.parseInt(pageNum), Integer.parseInt(pageSize));
|
|
|
- if (roleCode != null && "admin".equals(roleCode)) {
|
|
|
+ if (roleCode != null && roleCode.equals("admin")) {
|
|
|
//管理员查询全部
|
|
|
- templateList = kuaishouAccountCleanTemplateMapper.getTemplateList(templateId, createUser, null);
|
|
|
+ templateList = kuaishouAccountCleanTemplateMapper.getTemplateList(templateName, createUser, null);
|
|
|
} else {
|
|
|
//其他角色查询自己拥有的
|
|
|
- templateList = kuaishouAccountCleanTemplateMapper.getTemplateList(templateId, createUser, userId);
|
|
|
+ templateList = kuaishouAccountCleanTemplateMapper.getTemplateList(templateName, createUser, userId);
|
|
|
}
|
|
|
PageInfo pageInfo = new PageInfo(templateList);
|
|
|
result.success("查询成功");
|
|
@@ -185,10 +188,10 @@ public class KuaiShouAccountCleanServiceImpl implements KuaiShouAccountCleanServ
|
|
|
public Result updateTemplateStatus(String templateId, String status) {
|
|
|
Result result = new Result();
|
|
|
String message = "修改";
|
|
|
- if ("0".equals(status)) {
|
|
|
+ if (status.equals("0")) {
|
|
|
message = "开启";
|
|
|
}
|
|
|
- if ("1".equals(status)) {
|
|
|
+ if (status.equals("1")) {
|
|
|
message = "关闭";
|
|
|
}
|
|
|
try {
|
|
@@ -222,11 +225,20 @@ public class KuaiShouAccountCleanServiceImpl implements KuaiShouAccountCleanServ
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Result getCleanUpLog(String userName, String accountId, String pageNum, String pageSize) {
|
|
|
+ public Result getCleanUpLog(String templateId, String userId, String pageNum, String pageSize) {
|
|
|
Result result = new Result();
|
|
|
+ List<KuaiShouAccountCleanLogInfo> cleanUpLog=new ArrayList<>();
|
|
|
try {
|
|
|
+ //查询当前登录人角色
|
|
|
+ String roleCode = sysRoleService.getRoleCodeByUserId(userId);
|
|
|
PageHelper.startPage(Integer.parseInt(pageNum), Integer.parseInt(pageSize));
|
|
|
- List<KuaiShouAccountCleanLogInfo> cleanUpLog = kuaishouAccountCleanTemplateMapper.getCleanUpLog(userName, accountId);
|
|
|
+ if (roleCode != null && roleCode.equals("admin")) {
|
|
|
+ cleanUpLog = kuaishouAccountCleanTemplateMapper.getCleanUpLog(templateId, null);
|
|
|
+ }else {
|
|
|
+ cleanUpLog = kuaishouAccountCleanTemplateMapper.getCleanUpLog(templateId, userId);
|
|
|
+ }
|
|
|
+ PageHelper.startPage(Integer.parseInt(pageNum), Integer.parseInt(pageSize));
|
|
|
+
|
|
|
PageInfo pageInfo = new PageInfo(cleanUpLog);
|
|
|
result.success("查询成功");
|
|
|
result.setResult(pageInfo);
|
|
@@ -252,7 +264,7 @@ public class KuaiShouAccountCleanServiceImpl implements KuaiShouAccountCleanServ
|
|
|
//查询当前登录人角色
|
|
|
String roleCode = sysRoleService.getRoleCodeByUserId(userId);
|
|
|
PageHelper.startPage(Integer.parseInt(pageNum), Integer.parseInt(pageSize));
|
|
|
- if (roleCode != null && "admin".equals(roleCode)) {
|
|
|
+ if (roleCode != null && roleCode.equals("admin")) {
|
|
|
//管理员查询全部
|
|
|
templateList = kuaishouAccountCleanTemplateMapper.getMyselfTemplateList(accountId, userName, null);
|
|
|
} else {
|
|
@@ -284,74 +296,95 @@ public class KuaiShouAccountCleanServiceImpl implements KuaiShouAccountCleanServ
|
|
|
List<KuaiShouAccountCleanTemplateInfo> templateListBystatus = kuaishouAccountCleanTemplateMapper.getTemplateListBystatus();
|
|
|
if (!templateListBystatus.isEmpty()) {
|
|
|
templateListBystatus.stream().forEach(ob -> {
|
|
|
- //获取各项优化目标
|
|
|
- List<String> optimizationObjectiveList = Arrays.asList(ob.getOptimizationObjective().split(";"));
|
|
|
- //获取清理时间范围
|
|
|
- String cleanTime = ob.getCleanTime();
|
|
|
- //计算最早清理时间
|
|
|
- Calendar calendar = Calendar.getInstance();//此时打印它获取的是系统当前时间
|
|
|
- calendar.add(Calendar.DATE, -Integer.parseInt(cleanTime));
|
|
|
- String startDate = new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime());
|
|
|
- //查询符合模板规则的组
|
|
|
- List<String> groupMessage = kuaishouAccountCleanTemplateMapper.getGroupMessage(ob, optimizationObjectiveList, startDate);
|
|
|
- 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);
|
|
|
- }
|
|
|
- });
|
|
|
+ if(ob.getAccountId()!=null){
|
|
|
+ //获取各项优化目标
|
|
|
+ List<String> optimizationObjectiveList = Arrays.asList(ob.getOptimizationObjective().split(";"));
|
|
|
+ //获取清理时间范围
|
|
|
+ String cleanTime = ob.getCleanTime();
|
|
|
+ //计算最早清理时间
|
|
|
+ Calendar calendar = Calendar.getInstance();//此时打印它获取的是系统当前时间
|
|
|
+ calendar.add(Calendar.DATE, -Integer.parseInt(cleanTime));
|
|
|
+ String startDate = new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime());
|
|
|
+ //查询符合模板规则的组
|
|
|
+ List<String> groupMessage = kuaishouAccountCleanTemplateMapper.getGroupMessage(ob, optimizationObjectiveList, startDate);
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- if (!groupMessage.isEmpty() && falg.get()) {
|
|
|
- //修改成功插入日志记录
|
|
|
- KuaiShouAccountCleanLogInfo kuaiShouAccountCleanLogInfo = new KuaiShouAccountCleanLogInfo();
|
|
|
- //设置账户id
|
|
|
- kuaiShouAccountCleanLogInfo.setAccountId(ob.getAccountId());
|
|
|
- // 1-投放、2-暂停、3-删除
|
|
|
- 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");
|
|
|
- }
|
|
|
- //设置时间
|
|
|
- kuaiShouAccountCleanLogInfo.setCreateTime(sd.format(new Date()));
|
|
|
- StringBuilder unitIds = new StringBuilder();
|
|
|
- groupMessage.stream().forEach(unid -> {
|
|
|
- unitIds.append(unid).append(",");
|
|
|
- });
|
|
|
- //操作类型
|
|
|
- String operationType = null;
|
|
|
- if ("2".equals(ob.getPerformOperations())) {
|
|
|
- operationType = "暂停";
|
|
|
- }
|
|
|
- if ("3".equals(ob.getPerformOperations())) {
|
|
|
- operationType = "删除";
|
|
|
+ if (!groupMessage.isEmpty() && falg.get()) {
|
|
|
+ //修改成功插入日志记录
|
|
|
+ KuaiShouAccountCleanLogInfo kuaiShouAccountCleanLogInfo = new KuaiShouAccountCleanLogInfo();
|
|
|
+ //设置账户id
|
|
|
+ kuaiShouAccountCleanLogInfo.setAccountId(ob.getAccountId());
|
|
|
+ // 1-投放、2-暂停、3-删除
|
|
|
+ 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");
|
|
|
+ }
|
|
|
+ //设置时间
|
|
|
+ kuaiShouAccountCleanLogInfo.setCreateTime(sd.format(new Date()));
|
|
|
+ StringBuilder unitIds = new StringBuilder();
|
|
|
+ groupMessage.stream().forEach(unid -> {
|
|
|
+ unitIds.append(unid).append(",");
|
|
|
+ });
|
|
|
+ //操作类型
|
|
|
+ String operationType = null;
|
|
|
+ if (ob.getPerformOperations().equals("2")) {
|
|
|
+ operationType = "暂停";
|
|
|
+ }
|
|
|
+ if (ob.getPerformOperations().equals("3")) {
|
|
|
+ operationType = "删除";
|
|
|
+ }
|
|
|
+ //执行信息
|
|
|
+ String textMessage = "清理规则执行: 账户:" + ob.getAccountId() + ", 授权名称: " + authName + ",推广组:" + unitIds + "已经被清理规则" + operationType;
|
|
|
+ kuaiShouAccountCleanLogInfo.setExecutiveInformation(textMessage);
|
|
|
+ kuaiShouAccountCleanLogInfo.setTemplateId(ob.getId());
|
|
|
+ kuaiShouAccountCleanLogInfo.setCreateTemplateId(ob.getCreateId());
|
|
|
+ kuaishouAccountCleanTemplateMapper.saveCleamLog(kuaiShouAccountCleanLogInfo);
|
|
|
}
|
|
|
- //执行信息
|
|
|
- String textMessage = "清理规则执行: 账户:" + ob.getAccountId() + ", 授权名称: " + authName + ",推广组:" + unitIds + "已经被清理规则" + operationType;
|
|
|
- kuaiShouAccountCleanLogInfo.setExecutiveInformation(textMessage);
|
|
|
- kuaishouAccountCleanTemplateMapper.saveCleamLog(kuaiShouAccountCleanLogInfo);
|
|
|
}
|
|
|
-
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- result.success("修改成功");
|
|
|
+ result.success("执行计划成功");
|
|
|
} catch (Exception e) {
|
|
|
- log.info("修改失败:{}", e.toString());
|
|
|
- result.error500("修改失败");
|
|
|
+ log.info("执行计划失败:{}", e.toString());
|
|
|
+ result.error500("执行计划失败");
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 根据模板名称查询
|
|
|
+ *
|
|
|
+ * @param templateName
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Result getTemplateName(String templateName) {
|
|
|
+ Result result = new Result();
|
|
|
+ try {
|
|
|
+ int number = kuaishouAccountCleanTemplateMapper.getTemplateName(templateName);
|
|
|
+ result.setResult(number);
|
|
|
+ }catch (Exception e){
|
|
|
+ log.info("查询失败:{}", e.toString());
|
|
|
+ result.error500("查询失败");
|
|
|
}
|
|
|
return result;
|
|
|
}
|