|
@@ -107,8 +107,8 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
|
|
|
|
|
|
@Autowired
|
|
|
private ICtopOauthTokenService tokenService;
|
|
|
- private static final String CHANNEL_STR = "-{{渠道号}}-";
|
|
|
- private static final String NUMBER_STR = "-{{编号}}-";
|
|
|
+ private static final String CHANNEL_STR = "{{渠道号}}";
|
|
|
+ private static final String NUMBER_STR = "{{编号}}";
|
|
|
private static final String CHANNEL = "_channel_FLAG";
|
|
|
|
|
|
static ExecutorService executorService = Executors.newFixedThreadPool(5);
|
|
@@ -182,7 +182,7 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
|
|
|
//根据命名格式获取
|
|
|
queryWrapper.eq("channel_code", strategy.getChannelCode());
|
|
|
KuaishouChannelCreateStrategy sameNameOne = channelCreateStrategyService.getOne(queryWrapper);
|
|
|
- if (!Check.isNull(sameNameOne) && one.getNumberMax() >= strategy.getNumberMin()) {
|
|
|
+ if (!Check.isNull(sameNameOne) && one.getCreateType() == 1 && one.getNumberMax() >= strategy.getNumberMin()) {
|
|
|
return Result.error("创建失败,编号重叠,现有最大编号为:" + one.getNumberMax());
|
|
|
}
|
|
|
}
|
|
@@ -569,11 +569,22 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
|
|
|
//渠道号
|
|
|
String channelCode = strategy.getChannelCode().replace(NUMBER_STR, numberStr).trim();
|
|
|
channelStrategy.setChannelCode(channelCode);
|
|
|
- if (strategy.getChannelName().contains(CHANNEL_STR) || strategy.getChannelName().contains(NUMBER_STR)) {
|
|
|
- channelStrategy.setChannelName(strategy.getChannelName().replace(CHANNEL_STR, channelCode).replace(NUMBER_STR, numberStr).trim());
|
|
|
+ String channelName = strategy.getChannelName();
|
|
|
+ if (channelName.contains(CHANNEL_STR) || channelName.contains(NUMBER_STR)) {
|
|
|
+ channelName = channelName.replace(CHANNEL_STR, channelCode).replace(NUMBER_STR, numberStr).trim();
|
|
|
+ channelName = channelName.replace("--", "-");
|
|
|
+ channelName = channelName.replace("--", "-");
|
|
|
+ if (channelName.startsWith("-")) {
|
|
|
+ channelName = channelName.substring(1, channelName.length());
|
|
|
+ }
|
|
|
+ if (channelName.endsWith("-")) {
|
|
|
+ channelName = channelName.substring(0, channelName.length() - 1);
|
|
|
+ }
|
|
|
+ channelStrategy.setChannelName(channelName);
|
|
|
}
|
|
|
- if (!Check.isNull(strategy.getSchemaUri()) && strategy.getSchemaUri().contains(CHANNEL_STR)) {
|
|
|
- channelStrategy.setSchemaUri(strategy.getSchemaUri().replace(CHANNEL_STR, channelCode).trim());
|
|
|
+ String schemaUri = strategy.getSchemaUri();
|
|
|
+ if (!Check.isNull(schemaUri) && schemaUri.contains(CHANNEL_STR)) {
|
|
|
+ channelStrategy.setSchemaUri(schemaUri.replace(CHANNEL_STR, channelCode).trim());
|
|
|
}
|
|
|
if (strategy.getUrl().contains(CHANNEL_STR)) {
|
|
|
channelStrategy.setUrl(strategy.getUrl().replace(CHANNEL_STR, channelCode).trim());
|
|
@@ -869,7 +880,7 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Result<Object> queryChannel(Long accountId, String level) throws Exception {
|
|
|
+ public Result<Object> queryChannel(Long accountId, String level, String appName) throws Exception {
|
|
|
//查询账户策略
|
|
|
List<KuaishouChannelCreateStrategy> strategys = channelCreateStrategyService.queryChannelStrategyByAccountId(accountId);
|
|
|
if (Check.isNull(strategys) || strategys.isEmpty()) {
|
|
@@ -890,26 +901,25 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
|
|
|
/**============================账户范围============================*/
|
|
|
if ("account".equals(usageLevel)) {
|
|
|
//---------------------账户层级---------------------
|
|
|
- return doAccountRangeAccountLevel(accountId, strategys);
|
|
|
+ return doAccountRangeAccountLevel(accountId, strategys, appName);
|
|
|
} else if ("plan".equals(usageLevel) && usageLevel.equals(level)) {
|
|
|
//---------------------计划层级---------------------
|
|
|
- return doAccountRangePlanLevel(accountId, strategys);
|
|
|
+ return doPlanLevel(accountId, strategys, appName);
|
|
|
} else if ("group".equals(usageLevel)) {
|
|
|
//---------------------组层级---------------------
|
|
|
- return doAccountRangeGroupLevel(accountId, strategys);
|
|
|
+ return doGroupLevel(accountId, strategys, appName);
|
|
|
}
|
|
|
-
|
|
|
} else {
|
|
|
/**============================项目范围============================*/
|
|
|
if ("account".equals(usageLevel)) {
|
|
|
//---------------------账户层级---------------------
|
|
|
- return doAccountRangePlanLevel(accountId, strategys);
|
|
|
+ return doAccountRangeAccountLevel(accountId, strategys, appName);
|
|
|
} else if ("plan".equals(usageLevel) && usageLevel.equals(level)) {
|
|
|
//---------------------计划层级---------------------
|
|
|
- return doProjectRangePlanLevel(accountId, strategys);
|
|
|
+ return doPlanLevel(accountId, strategys, appName);
|
|
|
} else if ("group".equals(usageLevel)) {
|
|
|
//---------------------组层级---------------------
|
|
|
- return doProjectRangeGroupLevel(accountId, strategys);
|
|
|
+ return doGroupLevel(accountId, strategys, appName);
|
|
|
}
|
|
|
}
|
|
|
return Result.error("未查到渠道号");
|
|
@@ -918,15 +928,15 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
|
|
|
@Override
|
|
|
public Result<Object> queryChannelLevel(JSONObject data) {
|
|
|
Long accountId = data.getLong("accountId");
|
|
|
- JSONArray appIdArray = data.getJSONArray("appIdArray");
|
|
|
- Long appId = appIdArray.getLong(0);
|
|
|
+ JSONArray appNameArray = data.getJSONArray("appNameArray");
|
|
|
+ String appName = appNameArray.getString(0);
|
|
|
KuaishouChannel channel = channelMapper.queryByAccountId(accountId);
|
|
|
if (Check.isNull(channel)) {
|
|
|
return Result.ok("没有渠道号");
|
|
|
}
|
|
|
JSONObject request = new JSONObject();
|
|
|
if (channel.getIsHaveItem() == 1) {
|
|
|
- List<JSONObject> list = channelMapper.queryItemsListByAccountId(accountId,appId);
|
|
|
+ List<JSONObject> list = channelMapper.queryItemsListByAccountId(accountId, appName);
|
|
|
request.put("list", list);
|
|
|
}
|
|
|
request.put("channel", channel);
|
|
@@ -969,11 +979,11 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private Result<Object> doAccountRangeAccountLevel(Long accountId, List<KuaishouChannelCreateStrategy> strategys) throws Exception {
|
|
|
+ private Result<Object> doAccountRangeAccountLevel(Long accountId, List<KuaishouChannelCreateStrategy> strategys, String appName) throws Exception {
|
|
|
List<KuaishouChannel> channelList = channelMapper.queryByAccountIdLevel(accountId, "account");
|
|
|
if (!Check.isNull(channelList)) {
|
|
|
for (KuaishouChannel channel : channelList) {
|
|
|
- KuaishouChannelRel channelRel = channelRelService.queryByAccountChannelCode(channel.getChannelCode(), accountId);
|
|
|
+ KuaishouChannelRel channelRel = channelRelService.queryByAccountChannelCode(channel.getChannelCode(), accountId, appName);
|
|
|
if (Check.isNull(channelRel)) {
|
|
|
continue;
|
|
|
}
|
|
@@ -996,14 +1006,14 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
|
|
|
}
|
|
|
|
|
|
//通过账户范围计划层级查询
|
|
|
- private Result<Object> doAccountRangePlanLevel(Long accountId, List<KuaishouChannelCreateStrategy> strategys) throws
|
|
|
+ private Result<Object> doPlanLevel(Long accountId, List<KuaishouChannelCreateStrategy> strategys, String appName) throws
|
|
|
Exception {
|
|
|
List<Integer> haveCycleTimesList = channelMapper.queryUsedLevel(strategys);
|
|
|
if (Check.isNull(haveCycleTimesList)) {
|
|
|
return Result.error("渠道号已无效");
|
|
|
}
|
|
|
for (Integer haveCycleTimes : haveCycleTimesList) {
|
|
|
- //获取20个可用渠道号,筛查出一个返回给前端
|
|
|
+ //获取可用渠道号,筛查出一个返回给前端
|
|
|
List<KuaishouChannel> list = channelMapper.queryChannelByHaveCycleTimes(haveCycleTimes, "plan", strategys);
|
|
|
if (Check.isNull(list)) {
|
|
|
continue;
|
|
@@ -1014,103 +1024,10 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
|
|
|
//优先判断已经循环的次数 大于 使用次数
|
|
|
if (haveCycleTimes > usageTimes) {
|
|
|
// 符合条件,获取该渠道号
|
|
|
- KuaishouChannelRel channelRel = channelRelService.queryByAccountChannelCode(channel.getChannelCode(), accountId);
|
|
|
- if (Check.isNull(channelRel.getAppId())) {
|
|
|
- //创建APP
|
|
|
- createNewApp(channel, accountId, 1);
|
|
|
- if (Check.isNull(channel.getAppId())) {
|
|
|
- continue;
|
|
|
- } else {
|
|
|
- channelRel.setAppId(channel.getAppId());
|
|
|
- channelRelService.saveOrUpdate(channelRel);
|
|
|
- return Result.ok(channel);
|
|
|
- }
|
|
|
- } else {
|
|
|
- channel.setAppId(channelRel.getAppId());
|
|
|
- return Result.ok(channel);
|
|
|
- }
|
|
|
- } else {
|
|
|
- //判断可循环次数 大于 已经循环的次数
|
|
|
- if (cycleTimes > haveCycleTimes) {
|
|
|
- //已循环次数+1
|
|
|
- channel.setHaveCycleTimes(haveCycleTimes + 1);
|
|
|
- this.saveOrUpdate(channel);
|
|
|
- }
|
|
|
- continue;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return Result.ok("未查询到渠道号");
|
|
|
- }
|
|
|
-
|
|
|
- //通过账户范围广告组层级查询
|
|
|
- private Result<Object> doAccountRangeGroupLevel(Long
|
|
|
- accountId, List<KuaishouChannelCreateStrategy> strategys) throws Exception {
|
|
|
- List<Integer> haveCycleTimesList = channelMapper.queryUsedLevel(strategys);
|
|
|
- if (Check.isNull(haveCycleTimesList)) {
|
|
|
- return Result.error("渠道号已无效");
|
|
|
- }
|
|
|
- for (Integer haveCycleTimes : haveCycleTimesList) {
|
|
|
- //获取20个可用渠道号,筛查出一个返回给前端
|
|
|
- List<KuaishouChannel> list = channelMapper.queryChannelByHaveCycleTimes(haveCycleTimes, "group", strategys);
|
|
|
- if (Check.isNull(list)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- for (KuaishouChannel channel : list) {
|
|
|
- Integer cycleTimes = channel.getCycleTimes();//可循环次数
|
|
|
- Integer usageTimes = channel.getUsageTimes();//使用次数
|
|
|
- //优先判断已经循环的次数 大于 使用次数
|
|
|
- if (haveCycleTimes > usageTimes) {
|
|
|
- // 符合条件,获取该渠道号
|
|
|
- KuaishouChannelRel channelRel = channelRelService.queryByAccountChannelCode(channel.getChannelCode(), accountId);
|
|
|
- if (Check.isNull(channelRel.getAppId())) {
|
|
|
- //创建APP
|
|
|
- createNewApp(channel, accountId, 1);
|
|
|
- if (Check.isNull(channel.getAppId())) {
|
|
|
- continue;
|
|
|
- } else {
|
|
|
- channelRel.setAppId(channel.getAppId());
|
|
|
- channelRelService.saveOrUpdate(channelRel);
|
|
|
- return Result.ok(channel);
|
|
|
- }
|
|
|
- } else {
|
|
|
- channel.setAppId(channelRel.getAppId());
|
|
|
- return Result.ok(channel);
|
|
|
- }
|
|
|
- } else {
|
|
|
- //判断可循环次数 大于 已经循环的次数
|
|
|
- if (cycleTimes > haveCycleTimes) {
|
|
|
- //已循环次数+1
|
|
|
- channel.setHaveCycleTimes(haveCycleTimes + 1);
|
|
|
- this.saveOrUpdate(channel);
|
|
|
+ KuaishouChannelRel channelRel = channelRelService.queryByAccountChannelCode(channel.getChannelCode(), accountId, appName);
|
|
|
+ if (Check.isNull(channelRel)) {
|
|
|
+ continue;
|
|
|
}
|
|
|
- continue;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return Result.ok("未查询到渠道号");
|
|
|
- }
|
|
|
-
|
|
|
- //通过项目范围账户层级查询
|
|
|
- private Result<Object> doProjectRangePlanLevel(Long accountId, List<KuaishouChannelCreateStrategy> strategys) throws
|
|
|
- Exception {
|
|
|
- List<Integer> haveCycleTimesList = channelMapper.queryUsedLevel(strategys);
|
|
|
- if (Check.isNull(haveCycleTimesList)) {
|
|
|
- return Result.error("渠道号已无效");
|
|
|
- }
|
|
|
- for (Integer haveCycleTimes : haveCycleTimesList) {
|
|
|
- //获取20个可用渠道号,筛查出一个返回给前端
|
|
|
- List<KuaishouChannel> list = channelMapper.queryChannelByHaveCycleTimes(haveCycleTimes, "plan", strategys);
|
|
|
- if (Check.isNull(list)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- for (KuaishouChannel channel : list) {
|
|
|
- Integer cycleTimes = channel.getCycleTimes();//可循环次数
|
|
|
- Integer usageTimes = channel.getUsageTimes();//使用次数
|
|
|
- //优先判断已经循环的次数 大于 使用次数
|
|
|
- if (haveCycleTimes > usageTimes) {
|
|
|
- // 符合条件,获取该渠道号
|
|
|
- KuaishouChannelRel channelRel = channelRelService.queryByAccountChannelCode(channel.getChannelCode(), accountId);
|
|
|
if (Check.isNull(channelRel.getAppId())) {
|
|
|
//创建APP
|
|
|
createNewApp(channel, accountId, 1);
|
|
@@ -1140,8 +1057,7 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
|
|
|
}
|
|
|
|
|
|
//通过项目范围广告组层级查询
|
|
|
- private Result<Object> doProjectRangeGroupLevel(Long
|
|
|
- accountId, List<KuaishouChannelCreateStrategy> strategys) throws Exception {
|
|
|
+ private Result<Object> doGroupLevel(Long accountId, List<KuaishouChannelCreateStrategy> strategys, String appName) throws Exception {
|
|
|
List<Integer> haveCycleTimesList = channelMapper.queryUsedLevel(strategys);
|
|
|
if (Check.isNull(haveCycleTimesList)) {
|
|
|
return Result.error("渠道号已无效");
|
|
@@ -1158,7 +1074,10 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
|
|
|
//优先判断已经循环的次数 大于 使用次数
|
|
|
if (haveCycleTimes > usageTimes) {
|
|
|
// 符合条件,获取该渠道号
|
|
|
- KuaishouChannelRel channelRel = channelRelService.queryByAccountChannelCode(channel.getChannelCode(), accountId);
|
|
|
+ KuaishouChannelRel channelRel = channelRelService.queryByAccountChannelCode(channel.getChannelCode(), accountId, appName);
|
|
|
+ if (Check.isNull(channelRel)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
if (Check.isNull(channelRel.getAppId())) {
|
|
|
//创建APP
|
|
|
createNewApp(channel, accountId, 1);
|