Bläddra i källkod

例外设置修改

xueyiming 5 månader sedan
förälder
incheckning
c82e60f6e0

+ 2 - 0
long-article-server/src/main/java/com/tzld/piaoquan/longarticle/service/local/AccountService.java

@@ -8,5 +8,7 @@ public interface AccountService {
 
     List<AccountSpecialSettings> getAccountSpecialSettings();
 
+    List<AccountSpecialSettings> getSendAccountSpecialSettings();
+
     void saveOrUpdateAccountSpecialSettings(AccountSpecialSettings accountSpecialSettings);
 }

+ 2 - 0
long-article-server/src/main/java/com/tzld/piaoquan/longarticle/service/local/PlanAccountService.java

@@ -17,6 +17,8 @@ public interface PlanAccountService {
 
     List<PlanAccount> getNormalPlanAccount();
 
+    List<PlanAccount> getNormalPlanAccount(String accountId);
+
     List<PlanAccount> getPlanAccount(String planId, String accountId);
 
     List<Plan> getPlanList();

+ 7 - 0
long-article-server/src/main/java/com/tzld/piaoquan/longarticle/service/local/impl/AccountServiceImpl.java

@@ -29,6 +29,13 @@ public class AccountServiceImpl implements AccountService {
         return accountSpecialSettingsMapper.selectByExample(example);
     }
 
+    public List<AccountSpecialSettings> getSendAccountSpecialSettings() {
+        String dateString = DateUtil.getTomorrowDateString();
+        AccountSpecialSettingsExample example = new AccountSpecialSettingsExample();
+        example.createCriteria().andEffectiveDateEqualTo(dateString);
+        return accountSpecialSettingsMapper.selectByExample(example);
+    }
+
     public void saveOrUpdateAccountSpecialSettings(AccountSpecialSettings accountSpecialSettings) {
         AccountSpecialSettingsExample example = new AccountSpecialSettingsExample();
         example.createCriteria().andAccountIdEqualTo(accountSpecialSettings.getAccountId())

+ 24 - 60
long-article-server/src/main/java/com/tzld/piaoquan/longarticle/service/local/impl/CoreServiceImpl.java

@@ -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);
         }
     }
 

+ 8 - 0
long-article-server/src/main/java/com/tzld/piaoquan/longarticle/service/local/impl/PlanAccountServiceImpl.java

@@ -75,6 +75,14 @@ public class PlanAccountServiceImpl implements PlanAccountService {
         return planAccountMapper.selectByExample(example);
     }
 
+    public List<PlanAccount> getNormalPlanAccount(String accountId) {
+        PlanAccountExample example = new PlanAccountExample();
+        example.createCriteria().andCreateTimeGreaterThan(DateUtil.getThatDayDate())
+                .andAccountIdEqualTo(accountId)
+                .andStatusEqualTo(0).andIsDeleteEqualTo(0).andPublishOpenFlagEqualTo(1);
+        return planAccountMapper.selectByExample(example);
+    }
+
     public List<PlanAccount> getPlanAccount(String planId, String accountId) {
         PlanAccountExample example = new PlanAccountExample();
         example.createCriteria().andCreateTimeGreaterThan(DateUtil.getThatDayDate())

+ 7 - 0
long-article-server/src/main/java/com/tzld/piaoquan/longarticle/utils/DateUtil.java

@@ -34,4 +34,11 @@ public class DateUtil {
         return dateFormat.format(today);
     }
 
+    public static String getTomorrowDateString() {
+        DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+        LocalDate tomorrow = LocalDate.now().minusDays(-1);
+        return dateFormat.format(tomorrow);
+    }
+
+
 }