diff --git a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/MessageConstants.java b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/MessageConstants.java index 94d6454..ac86971 100644 --- a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/MessageConstants.java +++ b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/MessageConstants.java @@ -89,6 +89,20 @@ public class MessageConstants { public final static Integer PUSH_FAILED = 2; /**已确认**/ public final static Integer CONFIRM = 3; + + @AllArgsConstructor + public enum MessagePushResultEnum { + NON(NOT_PUSH,"未推送"), + SUCCESS(PUSH_SUCCESS,"推送成功"), + FAILED(PUSH_FAILED,"推送失败"), + CONFIRM(MessageConstants.CONFIRM,"已确认") + ; + @Getter + private Integer key; + @Getter + private String value; + + } /**====================================推送状态====================================**/ /**====================================推送类型====================================**/ diff --git a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/constants/DictKeyConstants.java b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/constants/DictKeyConstants.java index 2ef0f7d..4e84bb2 100644 --- a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/constants/DictKeyConstants.java +++ b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/constants/DictKeyConstants.java @@ -5,4 +5,17 @@ public interface DictKeyConstants { /**消息推送类型 [appPush-app推送 smsPush-短信推送 websocketPush-web推送 mailPush-邮件推送]**/ String MESSAGE_TYPE = "messageType"; + /*** + * 业务分类 + * system-系统通知 + * business-事务消息 + * dailyRemind-日常提醒 + * inspect-巡检消息 + * warning-告警消息 + * duty-值班消息 + * safe-安全消息 + * access-检修消息 + */ + String BUSINESS_CLASSIFY = "businessClassify"; + } diff --git a/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessagePushRecordServiceImpl.java b/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessagePushRecordServiceImpl.java index 015735b..276b1b3 100644 --- a/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessagePushRecordServiceImpl.java +++ b/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessagePushRecordServiceImpl.java @@ -13,8 +13,10 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.google.common.collect.Lists; import com.hnac.hzims.common.constant.CommonConstant; import com.hnac.hzims.common.utils.CacheUtil; +import com.hnac.hzims.common.utils.DateUtil; import com.hnac.hzims.message.MessageConstants; import com.hnac.hzims.message.config.MessageFactory; +import com.hnac.hzims.message.constants.DictKeyConstants; import com.hnac.hzims.message.dto.BusinessMessageDTO; import com.hnac.hzims.message.dto.WxMessageDTO; import com.hnac.hzims.message.entity.MessagePushRecordEntity; @@ -41,6 +43,7 @@ import org.springblade.core.tool.utils.BeanUtil; import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.SpringUtil; import org.springblade.system.cache.DictCache; +import org.springblade.system.entity.Dict; import org.springblade.system.feign.ISysClient; import org.springblade.system.user.cache.UserCache; import org.springblade.system.user.entity.User; @@ -56,6 +59,7 @@ import java.time.format.DateTimeFormatter; import java.util.*; import java.util.concurrent.FutureTask; import java.util.stream.Collectors; +import java.util.stream.IntStream; @Service @RequiredArgsConstructor @@ -156,71 +160,37 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl smsPushStat(MessagePushRecordEntityVo vo) { + List result = Lists.newArrayList(); //根据type统计数量 List messagePushRecordVos = baseMapper.smsPushStat(vo); - messagePushRecordVos.forEach(item -> { - YearMonth strMonth = item.getStrMonth(); - // 字符串转localDate 获取月份 - item.setMonth(strMonth.getMonthValue()); - item.setYear(strMonth.getYear()); + List types = DictCache.getList(DictKeyConstants.MESSAGE_TYPE); + List lastYearMonths = this.getLastYearMonths(); + types.forEach(dict -> { + MessagePushRecordTypeVo typeVO = new MessagePushRecordTypeVo(); + typeVO.setType(dict.getDictKey()); + typeVO.setTypeName(dict.getDictValue()); + List recordVOList = lastYearMonths.stream().map(yearMonth -> { + MessagePushRecordVo recordVO = new MessagePushRecordVo(); + recordVO.setYear(yearMonth.getYear()); + recordVO.setMonth(yearMonth.getMonthValue()); + recordVO.setStrMonth(yearMonth); + Long power = messagePushRecordVos.stream().filter(group -> group.getType().equals(dict.getDictKey()) && yearMonth.equals(group.getStrMonth())).findFirst().map(MessagePushRecordVo::getPower).orElse(0L); + recordVO.setPower(power); + return recordVO; + }).collect(Collectors.toList()); + typeVO.setMessagePushRecordList(recordVOList); + result.add(typeVO); }); + return result; + } - //按类型分组 - Map> collect = messagePushRecordVos.stream().collect(Collectors.groupingBy(MessagePushRecordVo::getType)); - - List messagePushRecordTypeVos = new ArrayList<>(); - //封装数据 - collect.forEach((key, value) -> { - MessagePushRecordTypeVo messagePushRecordTypeVo = new MessagePushRecordTypeVo(); - messagePushRecordTypeVo.setType(key); - messagePushRecordTypeVo.setMessagePushRecordList(value); - messagePushRecordTypeVos.add(messagePushRecordTypeVo); - }); - - - //封装typeName的数据 - messagePushRecordTypeVos.forEach(item1 -> { - List messagePushRecordList = item1.getMessagePushRecordList(); - //String messageType = DictCache.getValue("messageType", item1.getType()); - //System.out.println("messageType = " + messageType); - String typeByName = getTypeByName(item1.getType()); - item1.setTypeName(typeByName); - //获取以往12个月的数据 - List previousMonth = this.getPreviousMonth(); - //创建新的数组 List - List lists = new ArrayList<>(); - messagePushRecordList.forEach(item2 -> { - YearMonth strMonth = item2.getStrMonth(); - // 字符串转localDate 获取月份 - item2.setMonth(strMonth.getMonthValue()); - item2.setYear(strMonth.getYear()); - previousMonth.remove(strMonth); - //封装typeValue - item2.setTypeName(typeByName); - lists.add(item2); - }); - - //如果还存在YearMonth,把MessagePushRecordVo添加到新的数组 List - if (CollectionUtils.isNotEmpty(previousMonth)) { - for (YearMonth yearMonth : previousMonth) { - MessagePushRecordVo messagePushRecordVo = new MessagePushRecordVo(); - messagePushRecordVo.setYear(yearMonth.getYear()); - messagePushRecordVo.setMonth(yearMonth.getMonthValue()); - messagePushRecordVo.setType(item1.getType()); - messagePushRecordVo.setPower(0L); - messagePushRecordVo.setStrMonth(yearMonth); - //封装typeValue - messagePushRecordVo.setTypeName(typeByName); - lists.add(messagePushRecordVo); - } - } - List newLists = lists.stream().sorted(Comparator.comparing(MessagePushRecordVo::getStrMonth).reversed()).collect(Collectors.toList()); - // 封装到 setMessagePushRecordList - item1.setMessagePushRecordList(newLists); - }); - - - return messagePushRecordTypeVos; + /** + * 获取从当前月份开始过去一年内的月份 + * @return 过去一年的月份 + */ + private List getLastYearMonths () { + YearMonth now = YearMonth.now(); + return IntStream.iterate(0,index -> index + 1).limit(12).mapToObj(index -> now.minusMonths(index)).collect(Collectors.toList()); } /** @@ -231,11 +201,14 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl businessTypeStat(MessagePushRecordEntityVo vo) { List businessTypeStatVos = baseMapper.businessTypeStat(vo); - businessTypeStatVos.forEach(item -> { - String businessClassifyByName = this.getBusinessClassifyByName(item.getBusinessClassify()); - item.setBusinessClassifyName(businessClassifyByName); - }); - return businessTypeStatVos; + List classifies = DictCache.getList(DictKeyConstants.BUSINESS_CLASSIFY); + return classifies.stream().map(dict -> { + BusinessTypeStatVo result = new BusinessTypeStatVo(); + result.setBusinessClassify(dict.getDictKey()); + result.setBusinessClassifyName(dict.getDictValue()); + result.setPower(businessTypeStatVos.stream().filter(stat -> dict.getDictKey().equals(stat.getBusinessClassify())).map(BusinessTypeStatVo::getPower).findFirst().orElse(0L)); + return result; + }).collect(Collectors.toList()); } /** @@ -459,45 +432,25 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl pushStat(MessagePushRecordEntityVo vo) { List pushStatTypeVos = baseMapper.pushStat(vo); - pushStatTypeVos.forEach(item -> { - //查询出状态信息 - List statusList = baseMapper.selectByStatus(); - //业务类型名称 - String businessClassify = item.getBusinessClassify(); - String businessTypeName = this.getBusinessClassifyByName(businessClassify); - item.setBusinessClassifyName(businessTypeName); - List pushStatList = item.getPushStatList(); - List newPushStatList = new ArrayList<>(); - for (PushStatVo pushStat : pushStatList) { - //业务类型名称 - String businessClassifyPushStat = pushStat.getBusinessClassify(); - String businessTypeNamePushStat = this.getBusinessClassifyByName(businessClassifyPushStat); - pushStat.setBusinessClassifyName(businessTypeNamePushStat); - Integer status = pushStat.getStatus(); - //如果list 包含这条数删除 - statusList.remove(status); - //状态名称 - String name = this.getStatusByName(status); - pushStat.setStatusName(name); - newPushStatList.add(pushStat); - } - //如何list不为空补0 - if (CollectionUtils.isNotEmpty(statusList)) { - for (int i = 0; i < statusList.size(); i++) { - PushStatVo pushStat = new PushStatVo(); - int status = statusList.get(i); - pushStat.setStatus(status); - pushStat.setPower(0L); - pushStat.setBusinessClassify(businessClassify); - pushStat.setBusinessClassifyName(businessTypeName); - pushStat.setStatusName(this.getStatusByName(status)); - newPushStatList.add(pushStat); - } - } - - item.setPushStatList(newPushStatList); - }); - return pushStatTypeVos; + List classifies = DictCache.getList(DictKeyConstants.BUSINESS_CLASSIFY); + return classifies.stream().map(dict -> { + PushStatTypeVo typeVO = new PushStatTypeVo(); + typeVO.setBusinessClassify(dict.getDictKey()); + typeVO.setBusinessClassifyName(dict.getDictValue()); + List pushStatVoList = Arrays.stream(MessageConstants.MessagePushResultEnum.class.getEnumConstants()).map(pushResultTypeEnums -> { + PushStatVo statVo = new PushStatVo(); + statVo.setStatus(pushResultTypeEnums.getKey()); + statVo.setStatusName(pushResultTypeEnums.getValue()); + statVo.setBusinessClassify(dict.getDictKey()); + statVo.setBusinessClassifyName(dict.getDictValue()); + Optional statVO = pushStatTypeVos.stream().filter(group -> dict.getDictKey().equals(group.getBusinessClassify())) + .flatMap(group -> group.getPushStatList().stream()).filter(stat -> stat.getStatus().equals(pushResultTypeEnums.getKey())).findFirst(); + statVo.setPower(statVO.map(PushStatVo::getPower).orElse(0L)); + return statVo; + }).collect(Collectors.toList()); + typeVO.setPushStatList(pushStatVoList); + return typeVO; + }).collect(Collectors.toList()); } @Override