Parcourir la source

增加分组发送次数减少逻辑

xueyiming il y a 2 semaines
Parent
commit
06f5c0abef

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

@@ -808,7 +808,7 @@ public class CoreServiceImpl implements CoreService {
             }
         }
         int remainingDaysInCurrentMonth = DateUtil.getRemainingDaysInCurrentMonth();
-        int remainingCount = 0;
+        int remainingCount;
         List<String> sendOpenIds = new ArrayList<>();
         if (remainingDaysInCurrentMonth <= 4) {
             remainingCount = articleUseGroupMapper.selectRemainingCountByGzhId(planAccount.getGhId(), remainingDaysInCurrentMonth);
@@ -990,13 +990,46 @@ public class CoreServiceImpl implements CoreService {
                         Objects.equals(planAccount.getPushType(), PublishGzhPushTypeEnum.batch_group_publish.getVal())) {
                     planAccountService.updateStatus(2, planAccountId);
                 }
-                GroupSendResultExample groupSendResultExample = new GroupSendResultExample();
-                groupSendResultExample.createCriteria().andPushIdEqualTo(pushId);
-                List<GroupSendResult> groupSendResults = groupSendResultMapper.selectByExample(groupSendResultExample);
-                if (!CollectionUtils.isEmpty(groupSendResults)) {
-                    GroupSendResult updateGroupSendResult = new GroupSendResult();
-                    updateGroupSendResult.setStatus(updateStatus);
-                    groupSendResultMapper.updateByExampleSelective(updateGroupSendResult, groupSendResultExample);
+                if (fwhGhIdList != null && fwhGhIdList.contains(planAccount.getGhId())) {
+                    GroupSendResultExample groupSendResultExample = new GroupSendResultExample();
+                    groupSendResultExample.createCriteria().andPushIdEqualTo(pushId);
+                    List<GroupSendResult> groupSendResults = groupSendResultMapper.selectByExample(groupSendResultExample);
+                    if (!CollectionUtils.isEmpty(groupSendResults)) {
+                        GroupSendResult updateGroupSendResult = new GroupSendResult();
+                        updateGroupSendResult.setStatus(updateStatus);
+                        groupSendResultMapper.updateByExampleSelective(updateGroupSendResult, groupSendResultExample);
+                        Set<String> groupKeys = groupSendResults.stream()
+                                .map(e -> e.getGhId() + "_" + e.getPublishDate() + "_" + e.getUserGroupId())
+                                .collect(Collectors.toSet());
+                        for (String groupKey : groupKeys) {
+                            String[] groupArray = groupKey.split("_");
+                            String ghId = groupArray[0];
+                            String publishDate = groupArray[1];
+                            String userGroupId = groupArray[2];
+                            GroupSendOpenIdExample groupSendOpenIdExample = new GroupSendOpenIdExample();
+                            groupSendOpenIdExample.createCriteria().andGhIdEqualTo(ghId)
+                                    .andPublishDateEqualTo(publishDate)
+                                    .andUserGroupIdEqualTo(Integer.parseInt(userGroupId));
+                            List<GroupSendOpenId> groupSendOpenIds = groupSendOpenIdMapper.selectByExample(groupSendOpenIdExample);
+                            if (!CollectionUtils.isEmpty(groupSendOpenIds)) {
+                                for (GroupSendOpenId groupSendOpenId : groupSendOpenIds) {
+                                    ArticleUseGroupExample articleUseGroupExample = new ArticleUseGroupExample();
+                                    articleUseGroupExample.createCriteria().andGzhIdEqualTo(groupSendOpenId.getGhId())
+                                            .andOpenIdEqualTo(groupSendOpenId.getOpenId());
+                                    List<ArticleUseGroup> articleUseGroups = articleUseGroupMapper.selectByExample(articleUseGroupExample);
+                                    if (!CollectionUtils.isEmpty(articleUseGroups)) {
+                                        for (ArticleUseGroup articleUseGroup : articleUseGroups) {
+                                            ArticleUseGroup updateArticleUseGroup = new ArticleUseGroup();
+                                            updateArticleUseGroup.setId(articleUseGroup.getId());
+                                            updateArticleUseGroup.setRemainingCount(articleUseGroup.getRemainingCount() - 1);
+                                            articleUseGroupMapper.updateByPrimaryKeySelective(updateArticleUseGroup);
+                                        }
+                                    }
+                                }
+                            }
+                        }
+
+                    }
                 }
             }
             if (updateStatus == 3) {