Browse Source

完善消息统计

zhongwei
段飞宇 2 years ago
parent
commit
21395db120
  1. 4
      hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/vo/msgpushrecord/MessagePushRecordTypeVo.java
  2. 6
      hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/vo/msgpushrecord/MessagePushRecordVo.java
  3. 1
      hzims-service/message/src/main/java/com/hnac/hzims/message/mapper/MessagePushRecordMapper.xml
  4. 108
      hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessagePushRecordServiceImpl.java
  5. 9
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/OperationApplication.java

4
hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/vo/msgpushrecord/MessagePushRecordTypeVo.java

@ -17,6 +17,10 @@ public class MessagePushRecordTypeVo {
* 消息类型
*/
private String type;
/**
* 消息类型名称
*/
private String typeName;
private List<MessagePushRecordVo> messagePushRecordList;
}

6
hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/vo/msgpushrecord/MessagePushRecordVo.java

@ -40,6 +40,12 @@ public class MessagePushRecordVo implements Serializable {
*/
private String type;
/**
* 消息类型名称
*/
private String typeName;
/**
* 统计数量
*/

1
hzims-service/message/src/main/java/com/hnac/hzims/message/mapper/MessagePushRecordMapper.xml

@ -22,6 +22,7 @@
from hzims_message_push_record
<where>
IS_DELETED = 0
and PLAN_TIME BETWEEN DATE_SUB(NOW(), INTERVAL 12 MONTH) AND NOW()
<if test="vo.stationCode != null and vo.stationCode != ''">
and
DEPT_ID = #{vo.stationCode}

108
hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessagePushRecordServiceImpl.java

@ -34,10 +34,13 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import javax.validation.Valid;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Year;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@ -146,6 +149,52 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl<MessagePushRec
messagePushRecordTypeVo.setMessagePushRecordList(value);
messagePushRecordTypeVos.add(messagePushRecordTypeVo);
});
//封装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());
if (previousMonth.contains(strMonth)) {
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 messagePushRecordTypeVos;
}
@ -271,8 +320,44 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl<MessagePushRec
case 3:
value = PushStatEnum.CONFIRMED.getValue();
break;
case 4:
default:
value = DictCache.getValue("messageStatus", key);
if (value == null) {
log.error("状态异常,没有这状态");
value = String.valueOf(key);
}
break;
}
return value;
}
/**
* type ===> typeName
*
* @param key 状态
*/
private String getTypeByName(String key) {
String value = null;
switch (key) {
case "appPush":
value = "app推送";
break;
case "smsPush":
value = "短信推送";
break;
case "websocketPush":
value = "web推送";
break;
case "mailPush":
value = "邮件推送";
break;
default:
value = DictCache.getValue("messageType", key);
if (value == null) {
log.error("状态异常,没有这状态");
value = key;
}
break;
}
return value;
@ -300,8 +385,14 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl<MessagePushRec
case "inspect":
value = "巡检消息";
break;
case "":
case "warning":
value = "告警消息";
default:
value = DictCache.getValue("businessClassify", key);
if (value == null) {
log.error("状态业务分类,没有这状态");
value = key;
}
break;
}
return value;
@ -321,4 +412,17 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl<MessagePushRec
}
/**
* 往前推12个月,获取以往12个月的数据
*/
private List<YearMonth> getPreviousMonth() {
List<YearMonth> month = new ArrayList<>();
YearMonth today = YearMonth.now();
for (int i = 0; i <= 11; i++) {
YearMonth localDate = today.minusMonths(i);
month.add(localDate);
}
return month;
}
}

9
hzims-service/operational/src/main/java/com/hnac/hzims/operational/OperationApplication.java

@ -40,6 +40,15 @@ import javax.annotation.Resource;
@Resource
public class OperationApplication extends SpringBootServletInitializer {
static{
System.setProperty("--spring.cloud.nacos.discovery.server-addr", "http://175.6.40.67:10042");
System.setProperty("--spring.cloud.nacos.config.server-addr", "http://175.6.40.67:10042");
System.setProperty("--spring.cloud.nacos.username", "nacos");
System.setProperty("--spring.cloud.nacos.password", "nacos");
}
public static void main(String[] args) {
BladeApplication.run(OperationalConstants.APP_NAME, OperationApplication.class, args);
}

Loading…
Cancel
Save