|
@@ -382,38 +382,31 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
|
|
* 账户级批量创建渠道号
|
|
* 账户级批量创建渠道号
|
|
*/
|
|
*/
|
|
private void addMoreChannel(KuaishouChannelCreateStrategy strategy, Integer numberMin, Integer numberMax) {
|
|
private void addMoreChannel(KuaishouChannelCreateStrategy strategy, Integer numberMin, Integer numberMax) {
|
|
- //获取token
|
|
|
|
- CtopOauthToken token = tokenService.getTokenByAccountId(strategy.getAccountId());
|
|
|
|
- Thread thread = new Thread() {
|
|
|
|
- @Override
|
|
|
|
- public void run() {
|
|
|
|
- try {
|
|
|
|
- List<KuaiShouAppList> oldAppList = null;
|
|
|
|
- if (Check.isNull(strategy.getAppId())) {
|
|
|
|
- //使用范围是账户时,查询旧app来做匹配
|
|
|
|
- kuaishouInterfaceService.getAppList(token.getAccountId(), token.getAccessToken());
|
|
|
|
- oldAppList = kuaiShouAppListService.getAppListByAccountId(token.getAccountId());
|
|
|
|
- }
|
|
|
|
- if (!Check.isNull(strategy.getUrl()) && strategy.getUrl().contains(CHANNEL_STR)) {
|
|
|
|
- for (int i = numberMin; i <= numberMax; i++) {
|
|
|
|
- KuaishouChannelCreateStrategy replaceData = replaceWildcard(strategy, i);
|
|
|
|
- createApp(replaceData, token, oldAppList);
|
|
|
|
- createChannel(replaceData, i);
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- createApp(strategy, token, oldAppList);
|
|
|
|
- for (int i = numberMin; i <= numberMax; i++) {
|
|
|
|
- KuaishouChannelCreateStrategy replaceData = replaceWildcard(strategy, i);
|
|
|
|
- createChannel(replaceData, i);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
|
+ try {
|
|
|
|
+ //获取token
|
|
|
|
+ CtopOauthToken token = tokenService.getTokenByAccountId(strategy.getAccountId());
|
|
|
|
+ List<KuaiShouAppList> oldAppList = null;
|
|
|
|
+ if (Check.isNull(strategy.getAppId())) {
|
|
|
|
+ //使用范围是账户时,查询旧app来做匹配
|
|
|
|
+ kuaishouInterfaceService.getAppList(token.getAccountId(), token.getAccessToken());
|
|
|
|
+ oldAppList = kuaiShouAppListService.getAppListByAccountId(token.getAccountId());
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(strategy.getUrl()) && strategy.getUrl().contains(CHANNEL_STR)) {
|
|
|
|
+ for (int i = numberMin; i <= numberMax; i++) {
|
|
|
|
+ KuaishouChannelCreateStrategy replaceData = replaceWildcard(strategy, i);
|
|
|
|
+ createApp(replaceData, token, oldAppList);
|
|
|
|
+ createChannel(replaceData, i);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ createApp(strategy, token, oldAppList);
|
|
|
|
+ for (int i = numberMin; i <= numberMax; i++) {
|
|
|
|
+ KuaishouChannelCreateStrategy replaceData = replaceWildcard(strategy, i);
|
|
|
|
+ createChannel(replaceData, i);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- };
|
|
|
|
- thread.start();
|
|
|
|
-
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -446,27 +439,21 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
|
|
* 创建单个渠道号
|
|
* 创建单个渠道号
|
|
*/
|
|
*/
|
|
private void addSingleChannel(KuaishouChannelCreateStrategy strategy) {
|
|
private void addSingleChannel(KuaishouChannelCreateStrategy strategy) {
|
|
- Integer i = Integer.valueOf(strategy.getNumberValue());
|
|
|
|
- CtopOauthToken token = tokenService.getTokenByAccountId(strategy.getAccountId());
|
|
|
|
- Thread thread = new Thread() {
|
|
|
|
- @Override
|
|
|
|
- public void run() {
|
|
|
|
- try {
|
|
|
|
- List<KuaiShouAppList> oldAppList = null;
|
|
|
|
- if (Check.isNull(strategy.getAppId())) {
|
|
|
|
- //使用范围是账户时,查询旧app来做匹配
|
|
|
|
- kuaishouInterfaceService.getAppList(token.getAccountId(), token.getAccessToken());
|
|
|
|
- oldAppList = kuaiShouAppListService.getAppListByAccountId(token.getAccountId());
|
|
|
|
- }
|
|
|
|
- KuaishouChannelCreateStrategy replaceData = replaceWildcard(strategy, i);
|
|
|
|
- createApp(replaceData, token, oldAppList);
|
|
|
|
- createChannel(replaceData, i);
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
|
|
+ try {
|
|
|
|
+ Integer i = Integer.valueOf(strategy.getNumberValue());
|
|
|
|
+ List<KuaiShouAppList> oldAppList = null;
|
|
|
|
+ CtopOauthToken token = tokenService.getTokenByAccountId(strategy.getAccountId());
|
|
|
|
+ if (Check.isNull(strategy.getAppId())) {
|
|
|
|
+ //使用范围是账户时,查询旧app来做匹配
|
|
|
|
+ kuaishouInterfaceService.getAppList(token.getAccountId(), token.getAccessToken());
|
|
|
|
+ oldAppList = kuaiShouAppListService.getAppListByAccountId(token.getAccountId());
|
|
}
|
|
}
|
|
- };
|
|
|
|
- thread.start();
|
|
|
|
|
|
+ KuaishouChannelCreateStrategy replaceData = replaceWildcard(strategy, i);
|
|
|
|
+ createApp(replaceData, token, oldAppList);
|
|
|
|
+ createChannel(replaceData, i);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -962,48 +949,34 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Result<Object> queryChannel(Long accountId, String level, String appName, String photoName) throws Exception {
|
|
public Result<Object> queryChannel(Long accountId, String level, String appName, String photoName) throws Exception {
|
|
- //查询账户策略
|
|
|
|
- List<KuaishouChannelCreateStrategy> strategys = channelCreateStrategyService.queryChannelStrategyByAccountId(accountId);
|
|
|
|
- if (Check.isNull(strategys) || strategys.isEmpty()) {
|
|
|
|
- //查询账户所在项目策略
|
|
|
|
- strategys = channelCreateStrategyService.queryChannelStrategyByProjectId(accountId);
|
|
|
|
- if (Check.isNull(strategys) || strategys.isEmpty()) {
|
|
|
|
- return Result.error("渠道号获取失败,该账户没有创建过渠道号");
|
|
|
|
- }
|
|
|
|
|
|
+ //查询账户所有策略
|
|
|
|
+ List<Long> strategyIds = channelCreateStrategyService.queryAllIdByAccountId(accountId);
|
|
|
|
+ if (Check.isNull(strategyIds) || strategyIds.isEmpty()) {
|
|
|
|
+ return Result.error("渠道号获取失败,该账户没有创建过渠道号");
|
|
}
|
|
}
|
|
- //所有策略下的 使用范围,使用层级,是否循环等字段 保持一致
|
|
|
|
- KuaishouChannelCreateStrategy createStrategy = strategys.get(0);
|
|
|
|
- Integer usageRange = createStrategy.getUsageRange();
|
|
|
|
- String usageLevel = createStrategy.getUsageLevel();
|
|
|
|
- if ("plan".equals(level) && "group".equals(usageLevel)) {
|
|
|
|
- return Result.error("您只创建了广告组层级的渠道号,通过广告计划查询不到渠道号");
|
|
|
|
|
|
+ List<Integer> usageTimesTypes = channelMapper.queryUsedLevel(strategyIds);
|
|
|
|
+ if (Check.isNull(usageTimesTypes)) {
|
|
|
|
+ return Result.error("渠道号已无效");
|
|
}
|
|
}
|
|
- if (usageRange == 1) {
|
|
|
|
- /**============================账户范围============================*/
|
|
|
|
- if ("account".equals(usageLevel)) {
|
|
|
|
- //---------------------账户层级---------------------
|
|
|
|
- return doAccountRangeAccountLevel(accountId, strategys, appName);
|
|
|
|
- } else if ("plan".equals(usageLevel) && usageLevel.equals(level)) {
|
|
|
|
- //---------------------计划层级---------------------
|
|
|
|
- return doPlanLevel(accountId, strategys, appName, 0);
|
|
|
|
- } else if ("group".equals(usageLevel)) {
|
|
|
|
- //---------------------组层级-----------------------
|
|
|
|
- return doGroupLevel(accountId, strategys, appName, 0, photoName);
|
|
|
|
|
|
+ for (Integer usageTimes : usageTimesTypes) {
|
|
|
|
+ //获取可用渠道号,筛查出一个返回给前端
|
|
|
|
+ List<KuaishouChannel> list = channelMapper.queryChannelByUsageTimes(usageTimes, level, strategyIds, appName);
|
|
|
|
+ if (Check.isNull(list)) {
|
|
|
|
+ continue;
|
|
}
|
|
}
|
|
- } else {
|
|
|
|
- /**============================项目范围============================*/
|
|
|
|
- if ("account".equals(usageLevel)) {
|
|
|
|
- //---------------------账户层级---------------------
|
|
|
|
- return doAccountRangeAccountLevel(accountId, strategys, appName);
|
|
|
|
- } else if ("plan".equals(usageLevel) && usageLevel.equals(level)) {
|
|
|
|
- //---------------------计划层级---------------------
|
|
|
|
- return doPlanLevel(accountId, strategys, appName, 0);
|
|
|
|
- } else if ("group".equals(usageLevel)) {
|
|
|
|
- //---------------------组层级---------------------
|
|
|
|
- return doGroupLevel(accountId, strategys, appName, 0, photoName);
|
|
|
|
|
|
+ for (KuaishouChannel channel : list) {
|
|
|
|
+ //1 关联单品,无单品则跳过
|
|
|
|
+ if (channel.getIsHaveItem() == 1) {
|
|
|
|
+ List<KuaishouChannelItems> items = channelItemsRelService.queryItems(channel.getId());
|
|
|
|
+ if (Check.isNull(items) || items.isEmpty()) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ channel.setItems(items);
|
|
|
|
+ }
|
|
|
|
+ return Result.ok(channel);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- return Result.error("未查到渠道号");
|
|
|
|
|
|
+ return Result.error("查询失败");
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -1188,8 +1161,7 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private Result<Object> doAccountRangeAccountLevel(Long
|
|
|
|
- accountId, List<KuaishouChannelCreateStrategy> strategys, String appName) throws Exception {
|
|
|
|
|
|
+ private Result<Object> getRealAccountChannel(Long accountId, List<KuaishouChannelCreateStrategy> strategys, String appName) throws Exception {
|
|
List<KuaishouChannel> channelList = channelMapper.queryByAccountIdLevel(accountId, "account");
|
|
List<KuaishouChannel> channelList = channelMapper.queryByAccountIdLevel(accountId, "account");
|
|
if (!Check.isNull(channelList)) {
|
|
if (!Check.isNull(channelList)) {
|
|
for (KuaishouChannel channel : channelList) {
|
|
for (KuaishouChannel channel : channelList) {
|
|
@@ -1222,125 +1194,6 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
|
|
return Result.error("未查询到渠道号");
|
|
return Result.error("未查询到渠道号");
|
|
}
|
|
}
|
|
|
|
|
|
- //通过账户范围计划层级查询
|
|
|
|
- private Result<Object> doPlanLevel(Long accountId, List<KuaishouChannelCreateStrategy> strategys, String appName, int count) throws
|
|
|
|
- Exception {
|
|
|
|
- List<Integer> usageTimesTypes = channelMapper.queryUsedLevel(strategys);
|
|
|
|
- if (Check.isNull(usageTimesTypes)) {
|
|
|
|
- return Result.error("渠道号已无效");
|
|
|
|
- }
|
|
|
|
- for (Integer usageTimes : usageTimesTypes) {
|
|
|
|
- //获取可用渠道号,筛查出一个返回给前端
|
|
|
|
- List<KuaishouChannel> list = channelMapper.queryChannelByUsageTimes(usageTimes, "plan", strategys,appName);
|
|
|
|
- if (Check.isNull(list)) {
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- for (KuaishouChannel channel : list) {
|
|
|
|
- //1 关联单品,无单品则跳过
|
|
|
|
- if (channel.getIsHaveItem() == 1) {
|
|
|
|
- List<KuaishouChannelItems> items = channelItemsRelService.queryItems(channel.getId());
|
|
|
|
- if (Check.isNull(items) || items.isEmpty()) {
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- channel.setItems(items);
|
|
|
|
- }
|
|
|
|
- // 获取绑定应用的渠道号
|
|
|
|
- KuaishouChannelRel channelRel = channelRelService.queryByAccountChannelCode(channel.getChannelCode(), accountId, appName);
|
|
|
|
- if (Check.isNull(channelRel)) {
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- if (Check.isNull(channelRel.getAppId())) {
|
|
|
|
- //创建APP
|
|
|
|
- createNewApp(channel, accountId, 1);
|
|
|
|
- if (Check.isNull(channel.getAppId())) {
|
|
|
|
- continue;
|
|
|
|
- } else {
|
|
|
|
- channelRel.setAppId(channel.getAppId());
|
|
|
|
- channelRelService.saveOrUpdate(channelRel);
|
|
|
|
- this.saveOrUpdate(channel);
|
|
|
|
- return Result.ok(channel);
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- this.saveOrUpdate(channel);
|
|
|
|
- channel.setAppId(channelRel.getAppId());
|
|
|
|
- return Result.ok(channel);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (count == 0) {
|
|
|
|
- return doPlanLevel(accountId, strategys, appName, 1);
|
|
|
|
- }
|
|
|
|
- return Result.ok("未查询到渠道号");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //通过项目范围广告组层级查询
|
|
|
|
- private Result<Object> doGroupLevel(Long accountId, List<KuaishouChannelCreateStrategy> strategys, String
|
|
|
|
- appName, int count, String photoName) throws Exception {
|
|
|
|
- List<Integer> haveCycleTimesList = channelMapper.queryUsedLevel(strategys);
|
|
|
|
- if (Check.isNull(haveCycleTimesList)) {
|
|
|
|
- return Result.error("渠道号已无效");
|
|
|
|
- }
|
|
|
|
- for (Integer haveCycleTimes : haveCycleTimesList) {
|
|
|
|
- List<KuaishouChannel> list = channelMapper.queryChannelByUsageTimes(haveCycleTimes, "group", strategys,appName);
|
|
|
|
- if (Check.isNull(list)) {
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- for (KuaishouChannel channel : list) {
|
|
|
|
-// Integer cycleTimes = channel.getCycleTimes();//可循环次数
|
|
|
|
- Integer usageTimes = channel.getUsageTimes();//使用次数
|
|
|
|
- //优先判断已经循环的次数 大于 使用次数
|
|
|
|
- if (haveCycleTimes > usageTimes) {
|
|
|
|
- if (!Check.isNull(channel.getIsHaveItem()) && channel.getIsHaveItem() == 1) {
|
|
|
|
- //有单品
|
|
|
|
- List<KuaishouChannelItems> itemsList = channelItemsRelService.queryItems(channel.getId());
|
|
|
|
- if (Check.isNull(itemsList) || itemsList.isEmpty()) {
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- //素材名字和单品关键字做匹配
|
|
|
|
- String keyword = itemsList.get(0).getKeyword();
|
|
|
|
- if (!photoName.contains(keyword)) {
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- // 符合条件,获取该渠道号
|
|
|
|
- KuaishouChannelRel channelRel = channelRelService.queryByAccountChannelCode(channel.getChannelCode(), accountId, appName);
|
|
|
|
- if (Check.isNull(channelRel)) {
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- if (Check.isNull(channelRel.getAppId())) {
|
|
|
|
- //创建APP
|
|
|
|
- createNewApp(channel, accountId, 1);
|
|
|
|
- if (Check.isNull(channel.getAppId())) {
|
|
|
|
- continue;
|
|
|
|
- } else {
|
|
|
|
- channelRel.setAppId(channel.getAppId());
|
|
|
|
- channelRelService.saveOrUpdate(channelRel);
|
|
|
|
- this.saveOrUpdate(channel);
|
|
|
|
- return Result.ok(channel);
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- this.saveOrUpdate(channel);
|
|
|
|
- channel.setAppId(channelRel.getAppId());
|
|
|
|
- return Result.ok(channel);
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- //判断可循环次数 大于 已经循环的次数
|
|
|
|
-// if (cycleTimes > haveCycleTimes) {
|
|
|
|
-// //已循环次数+1
|
|
|
|
-// channel.setHaveCycleTimes(haveCycleTimes + 1);
|
|
|
|
-// this.saveOrUpdate(channel);
|
|
|
|
-// }
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (count == 0) {
|
|
|
|
- return doGroupLevel(accountId, strategys, appName, 1, photoName);
|
|
|
|
- }
|
|
|
|
- return Result.ok("未查询到渠道号");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
private void createNewApp(KuaishouChannel channel, Long accountId, int count) throws Exception {
|
|
private void createNewApp(KuaishouChannel channel, Long accountId, int count) throws Exception {
|
|
CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
|
|
CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
|
|
String accessToken = null;
|
|
String accessToken = null;
|