Commit 6d71c671 authored by ma's avatar ma

批量处理告警已读

parent bbf0a99e
......@@ -2,6 +2,9 @@ package iot.sixiang.license.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import iot.sixiang.license.entity.AlarmRead;
import iot.sixiang.license.model.vo.AlarmVo;
import java.util.List;
/**
* <p>
......@@ -13,5 +16,5 @@ import iot.sixiang.license.entity.AlarmRead;
*/
public interface AlarmReadMapper extends BaseMapper<AlarmRead> {
boolean readAlarm(int alarmId,int typeId, String title, String content,int userId);
boolean readAlarm(List<AlarmVo> alarmVos, int userId);
}
......@@ -33,6 +33,7 @@ public class AlarmReadServiceImpl extends ServiceImpl<AlarmReadMapper, AlarmRead
AlarmMapper alarmMapper;
@Resource
AlarmReadMapper alarmReadMapper;
private static final int INSERT_BATCH_SIZE = 1000;
@Override
......@@ -42,6 +43,7 @@ public class AlarmReadServiceImpl extends ServiceImpl<AlarmReadMapper, AlarmRead
}
userId = Integer.valueOf(XssUtil.checkXSS(String.valueOf(userId)));
List<AlarmVo> alarmList = alarmMapper.getAlarmList(userId);
List<AlarmVo> newAlarmList = new ArrayList<>();
for (AlarmVo alarm: alarmList) {
if (alarm.getReadFlag() == 0) {
int alarmId = alarm.getId();
......@@ -54,10 +56,33 @@ public class AlarmReadServiceImpl extends ServiceImpl<AlarmReadMapper, AlarmRead
title = XssUtil.checkXSS(title);
content = XssUtil.checkXSS(content);
boolean res = alarmReadMapper.readAlarm(alarmId, typeId, title, content, userId);
alarm.setTitle(title);
alarm.setContent(content);
alarm.setId(alarmId);
alarm.setTypeId(typeId);
newAlarmList.add(alarm);
}
}
int size = newAlarmList.size();
if (size < INSERT_BATCH_SIZE) {
boolean res = alarmReadMapper.readAlarm(newAlarmList, userId);
if (!res) {
return false;
}
} else {
for (int i = 0; i <= size / INSERT_BATCH_SIZE; i++) {
List<AlarmVo> list;
if (i != size / INSERT_BATCH_SIZE) {
list = newAlarmList.subList(i * INSERT_BATCH_SIZE, i * INSERT_BATCH_SIZE + INSERT_BATCH_SIZE);
} else {
list = newAlarmList.subList(i * INSERT_BATCH_SIZE, size);
}
if (list.size() != 0) {
boolean res = alarmReadMapper.readAlarm(list, userId);
if (!res) {
return false;
}
}
}
}
return true;
......
......@@ -2,7 +2,10 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="iot.sixiang.license.mapper.AlarmReadMapper">
<insert id="readAlarm" parameterType="iot.sixiang.license.entity.AlarmRead">
insert into alarm_read (alarm_id, type_id, title, content, create_time, user_id) values (#{alarmId},#{typeId},#{title},#{content},now(),#{userId});
<insert id="readAlarm">
insert into alarm_read (alarm_id, type_id, title, content, create_time, user_id) values
<foreach collection="alarmVos" separator="," item="item">
(#{item.id},#{item.typeId},#{item.title},#{item.content},now(),#{userId})
</foreach>
</insert>
</mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment