|
@@ -750,13 +750,9 @@ public class CoreServiceImpl implements CoreService {
|
|
|
@Override
|
|
|
public void initPlanAccount() {
|
|
|
//例外设置查询和存储
|
|
|
- Map<String, AccountSpecialSettings> accountSpecialSettingsMap = null;
|
|
|
- Map<String, List<PlanAccount>> planAccountMap = new HashMap<>();
|
|
|
List<AccountSpecialSettings> accountSpecialSettings = accountService.getAccountSpecialSettings();
|
|
|
- if (!CollectionUtils.isEmpty(accountSpecialSettings)) {
|
|
|
- accountSpecialSettingsMap = accountSpecialSettings.stream()
|
|
|
- .collect(Collectors.toMap(AccountSpecialSettings::getAccountId, Function.identity()));
|
|
|
- }
|
|
|
+ List<String> specialAccountIds = accountSpecialSettings.stream().map(AccountSpecialSettings::getAccountId).collect(Collectors.toList());
|
|
|
+ List<AccountSpecialSettings> sendAccountSpecialSettings = accountService.getSendAccountSpecialSettings();
|
|
|
//操作计划遍历
|
|
|
List<Plan> planList = planAccountService.getPlanList();
|
|
|
Set<String> planIdSet = planList.stream().map(Plan::getPlanId).collect(Collectors.toSet());
|
|
@@ -817,9 +813,7 @@ public class CoreServiceImpl implements CoreService {
|
|
|
planAccount.setSortStrategy(sortStgMap.get(accountId));
|
|
|
}
|
|
|
planAccount.setPushType(longArticleSystemPlan.getPushType());
|
|
|
- if (accountSpecialSettingsMap != null && accountSpecialSettingsMap.containsKey(planAccount.getAccountId())) {
|
|
|
- planAccountMap.computeIfAbsent(planAccount.getAccountId(), k -> new ArrayList<>()).add(planAccount);
|
|
|
- } else {
|
|
|
+ if (CollectionUtils.isEmpty(specialAccountIds) || !specialAccountIds.contains(planAccount.getAccountId())) {
|
|
|
planAccountService.saveOrUpdatePlanAccount(planAccount);
|
|
|
}
|
|
|
}
|
|
@@ -839,65 +833,35 @@ public class CoreServiceImpl implements CoreService {
|
|
|
}
|
|
|
|
|
|
//例外设置处理
|
|
|
- if (!CollectionUtils.isEmpty(planAccountMap)) {
|
|
|
- setSpecialAccount(planAccountMap, accountSpecialSettingsMap);
|
|
|
- }
|
|
|
+ setSpecialAccount(accountSpecialSettings, sendAccountSpecialSettings);
|
|
|
}
|
|
|
|
|
|
- private void setSpecialAccount(Map<String, List<PlanAccount>> planAccountMap,
|
|
|
- Map<String, AccountSpecialSettings> accountSpecialSettingsMap) {
|
|
|
- for (Map.Entry<String, List<PlanAccount>> entry : planAccountMap.entrySet()) {
|
|
|
- String accountId = entry.getKey();
|
|
|
- List<PlanAccount> planAccounts = entry.getValue();
|
|
|
- AccountSpecialSettings accountSpecialSettings = accountSpecialSettingsMap.get(accountId);
|
|
|
- if (accountSpecialSettings == null) {
|
|
|
- LarkRobotUtil.sendMessage("获取例外设置失败,accountId=" + accountId);
|
|
|
+ private void setSpecialAccount(List<AccountSpecialSettings> accountSpecialSettings,
|
|
|
+ List<AccountSpecialSettings> sendAccountSpecialSettings) {
|
|
|
+
|
|
|
+ //当天计划不发送
|
|
|
+ for (AccountSpecialSettings accountSpecialSetting : accountSpecialSettings) {
|
|
|
+ List<PlanAccount> planAccountList = planAccountService.getPlanAccount(accountSpecialSetting.getAccountId());
|
|
|
+ if (CollectionUtils.isEmpty(planAccountList)) {
|
|
|
continue;
|
|
|
}
|
|
|
- //根据例外设置账号判断,当天已经有发送成功的记录,确保不会生成新的例外操作计划
|
|
|
- boolean isSend = false;
|
|
|
- List<PlanAccount> planAccountList = planAccountService.getPlanAccount(accountId);
|
|
|
for (PlanAccount planAccount : planAccountList) {
|
|
|
- int sendCount = publicContentService.getSendCount(planAccount.getId());
|
|
|
- if (sendCount > 0) {
|
|
|
- isSend = true;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (isSend) {
|
|
|
- continue;
|
|
|
+ planAccount.setPublishOpenFlag(0);
|
|
|
+ planAccountService.saveOrUpdatePlanAccount(planAccount);
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- //例外设置的新增和更新
|
|
|
- List<PlanAccount> normalPlanAccounts = planAccountList.stream().filter(e -> e.getIsDelete() == 0).filter(e -> e.getPublishOpenFlag() == 1).collect(Collectors.toList());
|
|
|
- if (CollectionUtils.isEmpty(normalPlanAccounts)) {
|
|
|
- Optional<PlanAccount> firstAccount = planAccounts.stream().min((a1, a2) -> -a1.getPublishNum().compareTo(a2.getPublishNum()));
|
|
|
- if (!firstAccount.isPresent()) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- PlanAccount targetPlanAccount = firstAccount.get();
|
|
|
- for (PlanAccount planAccount : planAccounts) {
|
|
|
- if (!Objects.equals(planAccount.getPlanId(), targetPlanAccount.getPlanId())) {
|
|
|
- planAccount.setPublishOpenFlag(0);
|
|
|
- planAccountService.saveOrUpdatePlanAccount(planAccount);
|
|
|
- continue;
|
|
|
- }
|
|
|
- updateAccountSetting(accountSpecialSettings, planAccount);
|
|
|
- planAccountService.saveOrUpdatePlanAccount(planAccount);
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (normalPlanAccounts.size() == 1) {
|
|
|
- PlanAccount planAccount = normalPlanAccounts.get(0);
|
|
|
- updateAccountSetting(accountSpecialSettings, planAccount);
|
|
|
- planAccountService.saveOrUpdatePlanAccount(planAccount);
|
|
|
- } else {
|
|
|
- LarkRobotUtil.sendMessage("存在多个例外计划,accountId=" + accountId);
|
|
|
- for (PlanAccount planAccount : planAccounts) {
|
|
|
- planAccount.setPublishOpenFlag(0);
|
|
|
- planAccountService.saveOrUpdatePlanAccount(planAccount);
|
|
|
- }
|
|
|
- }
|
|
|
+ //额外发送
|
|
|
+ for (AccountSpecialSettings accountSpecialSetting : sendAccountSpecialSettings) {
|
|
|
+ List<PlanAccount> planAccountList = planAccountService.getNormalPlanAccount(accountSpecialSetting.getAccountId());
|
|
|
+ if (CollectionUtils.isEmpty(planAccountList)) {
|
|
|
+ continue;
|
|
|
}
|
|
|
+ Optional<PlanAccount> firstAccount = planAccountList.stream().min((a1, a2) -> -a1.getPublishNum().compareTo(a2.getPublishNum()));
|
|
|
+ PlanAccount targetPlanAccount = firstAccount.get();
|
|
|
+ updateAccountSetting(accountSpecialSetting, targetPlanAccount);
|
|
|
+ targetPlanAccount.setId(null);
|
|
|
+ planAccountService.saveOrUpdatePlanAccount(targetPlanAccount);
|
|
|
}
|
|
|
}
|
|
|
|