Browse Source

Merge remote-tracking branch 'origin/master'

zhongwei
yang_shj 8 months ago
parent
commit
1478464369
  1. 14
      hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/MessageConstants.java
  2. 13
      hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/constants/DictKeyConstants.java
  3. 163
      hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessagePushRecordServiceImpl.java

14
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 PUSH_FAILED = 2;
/**已确认**/ /**已确认**/
public final static Integer CONFIRM = 3; 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;
}
/**====================================推送状态====================================**/ /**====================================推送状态====================================**/
/**====================================推送类型====================================**/ /**====================================推送类型====================================**/

13
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-邮件推送]**/ /**消息推送类型 [appPush-app推送 smsPush-短信推送 websocketPush-web推送 mailPush-邮件推送]**/
String MESSAGE_TYPE = "messageType"; String MESSAGE_TYPE = "messageType";
/***
* 业务分类
* system-系统通知
* business-事务消息
* dailyRemind-日常提醒
* inspect-巡检消息
* warning-告警消息
* duty-值班消息
* safe-安全消息
* access-检修消息
*/
String BUSINESS_CLASSIFY = "businessClassify";
} }

163
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.google.common.collect.Lists;
import com.hnac.hzims.common.constant.CommonConstant; import com.hnac.hzims.common.constant.CommonConstant;
import com.hnac.hzims.common.utils.CacheUtil; 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.MessageConstants;
import com.hnac.hzims.message.config.MessageFactory; 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.BusinessMessageDTO;
import com.hnac.hzims.message.dto.WxMessageDTO; import com.hnac.hzims.message.dto.WxMessageDTO;
import com.hnac.hzims.message.entity.MessagePushRecordEntity; 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.Func;
import org.springblade.core.tool.utils.SpringUtil; import org.springblade.core.tool.utils.SpringUtil;
import org.springblade.system.cache.DictCache; import org.springblade.system.cache.DictCache;
import org.springblade.system.entity.Dict;
import org.springblade.system.feign.ISysClient; import org.springblade.system.feign.ISysClient;
import org.springblade.system.user.cache.UserCache; import org.springblade.system.user.cache.UserCache;
import org.springblade.system.user.entity.User; import org.springblade.system.user.entity.User;
@ -56,6 +59,7 @@ import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import java.util.concurrent.FutureTask; import java.util.concurrent.FutureTask;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.IntStream;
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
@ -156,71 +160,37 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl<MessagePushRec
*/ */
@Override @Override
public List<MessagePushRecordTypeVo> smsPushStat(MessagePushRecordEntityVo vo) { public List<MessagePushRecordTypeVo> smsPushStat(MessagePushRecordEntityVo vo) {
List<MessagePushRecordTypeVo> result = Lists.newArrayList();
//根据type统计数量 //根据type统计数量
List<MessagePushRecordVo> messagePushRecordVos = baseMapper.smsPushStat(vo); List<MessagePushRecordVo> messagePushRecordVos = baseMapper.smsPushStat(vo);
messagePushRecordVos.forEach(item -> { List<Dict> types = DictCache.getList(DictKeyConstants.MESSAGE_TYPE);
YearMonth strMonth = item.getStrMonth(); List<YearMonth> lastYearMonths = this.getLastYearMonths();
// 字符串转localDate 获取月份 types.forEach(dict -> {
item.setMonth(strMonth.getMonthValue()); MessagePushRecordTypeVo typeVO = new MessagePushRecordTypeVo();
item.setYear(strMonth.getYear()); typeVO.setType(dict.getDictKey());
}); typeVO.setTypeName(dict.getDictValue());
List<MessagePushRecordVo> recordVOList = lastYearMonths.stream().map(yearMonth -> {
//按类型分组 MessagePushRecordVo recordVO = new MessagePushRecordVo();
Map<String, List<MessagePushRecordVo>> collect = messagePushRecordVos.stream().collect(Collectors.groupingBy(MessagePushRecordVo::getType)); recordVO.setYear(yearMonth.getYear());
recordVO.setMonth(yearMonth.getMonthValue());
List<MessagePushRecordTypeVo> messagePushRecordTypeVos = new ArrayList<>(); recordVO.setStrMonth(yearMonth);
//封装数据 Long power = messagePushRecordVos.stream().filter(group -> group.getType().equals(dict.getDictKey()) && yearMonth.equals(group.getStrMonth())).findFirst().map(MessagePushRecordVo::getPower).orElse(0L);
collect.forEach((key, value) -> { recordVO.setPower(power);
MessagePushRecordTypeVo messagePushRecordTypeVo = new MessagePushRecordTypeVo(); return recordVO;
messagePushRecordTypeVo.setType(key); }).collect(Collectors.toList());
messagePushRecordTypeVo.setMessagePushRecordList(value); typeVO.setMessagePushRecordList(recordVOList);
messagePushRecordTypeVos.add(messagePushRecordTypeVo); result.add(typeVO);
});
//封装typeName的数据
messagePushRecordTypeVos.forEach(item1 -> {
List<MessagePushRecordVo> 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<YearMonth> previousMonth = this.getPreviousMonth();
//创建新的数组 List<MessagePushRecordVo>
List<MessagePushRecordVo> 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<MessagePushRecordVo>
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<MessagePushRecordVo> newLists = lists.stream().sorted(Comparator.comparing(MessagePushRecordVo::getStrMonth).reversed()).collect(Collectors.toList());
// 封装到 setMessagePushRecordList
item1.setMessagePushRecordList(newLists);
}); });
return result;
}
/**
return messagePushRecordTypeVos; * 获取从当前月份开始过去一年内的月份
* @return 过去一年的月份
*/
private List<YearMonth> 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<MessagePushRec
@Override @Override
public List<BusinessTypeStatVo> businessTypeStat(MessagePushRecordEntityVo vo) { public List<BusinessTypeStatVo> businessTypeStat(MessagePushRecordEntityVo vo) {
List<BusinessTypeStatVo> businessTypeStatVos = baseMapper.businessTypeStat(vo); List<BusinessTypeStatVo> businessTypeStatVos = baseMapper.businessTypeStat(vo);
businessTypeStatVos.forEach(item -> { List<Dict> classifies = DictCache.getList(DictKeyConstants.BUSINESS_CLASSIFY);
String businessClassifyByName = this.getBusinessClassifyByName(item.getBusinessClassify()); return classifies.stream().map(dict -> {
item.setBusinessClassifyName(businessClassifyByName); BusinessTypeStatVo result = new BusinessTypeStatVo();
}); result.setBusinessClassify(dict.getDictKey());
return businessTypeStatVos; 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<MessagePushRec
@Override @Override
public List<PushStatTypeVo> pushStat(MessagePushRecordEntityVo vo) { public List<PushStatTypeVo> pushStat(MessagePushRecordEntityVo vo) {
List<PushStatTypeVo> pushStatTypeVos = baseMapper.pushStat(vo); List<PushStatTypeVo> pushStatTypeVos = baseMapper.pushStat(vo);
pushStatTypeVos.forEach(item -> { List<Dict> classifies = DictCache.getList(DictKeyConstants.BUSINESS_CLASSIFY);
//查询出状态信息 return classifies.stream().map(dict -> {
List<Integer> statusList = baseMapper.selectByStatus(); PushStatTypeVo typeVO = new PushStatTypeVo();
//业务类型名称 typeVO.setBusinessClassify(dict.getDictKey());
String businessClassify = item.getBusinessClassify(); typeVO.setBusinessClassifyName(dict.getDictValue());
String businessTypeName = this.getBusinessClassifyByName(businessClassify); List<PushStatVo> pushStatVoList = Arrays.stream(MessageConstants.MessagePushResultEnum.class.getEnumConstants()).map(pushResultTypeEnums -> {
item.setBusinessClassifyName(businessTypeName); PushStatVo statVo = new PushStatVo();
List<PushStatVo> pushStatList = item.getPushStatList(); statVo.setStatus(pushResultTypeEnums.getKey());
List<PushStatVo> newPushStatList = new ArrayList<>(); statVo.setStatusName(pushResultTypeEnums.getValue());
for (PushStatVo pushStat : pushStatList) { statVo.setBusinessClassify(dict.getDictKey());
//业务类型名称 statVo.setBusinessClassifyName(dict.getDictValue());
String businessClassifyPushStat = pushStat.getBusinessClassify(); Optional<PushStatVo> statVO = pushStatTypeVos.stream().filter(group -> dict.getDictKey().equals(group.getBusinessClassify()))
String businessTypeNamePushStat = this.getBusinessClassifyByName(businessClassifyPushStat); .flatMap(group -> group.getPushStatList().stream()).filter(stat -> stat.getStatus().equals(pushResultTypeEnums.getKey())).findFirst();
pushStat.setBusinessClassifyName(businessTypeNamePushStat); statVo.setPower(statVO.map(PushStatVo::getPower).orElse(0L));
Integer status = pushStat.getStatus(); return statVo;
//如果list 包含这条数删除 }).collect(Collectors.toList());
statusList.remove(status); typeVO.setPushStatList(pushStatVoList);
//状态名称 return typeVO;
String name = this.getStatusByName(status); }).collect(Collectors.toList());
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;
} }
@Override @Override

Loading…
Cancel
Save