Commit 771b029c authored by AfirSraftGarrier's avatar AfirSraftGarrier

Merge remote-tracking branch 'origin/master'

parents c0c2d9f3 6d71c671
...@@ -2,6 +2,9 @@ package iot.sixiang.license.mapper; ...@@ -2,6 +2,9 @@ package iot.sixiang.license.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import iot.sixiang.license.entity.AlarmRead; import iot.sixiang.license.entity.AlarmRead;
import iot.sixiang.license.model.vo.AlarmVo;
import java.util.List;
/** /**
* <p> * <p>
...@@ -13,5 +16,5 @@ import iot.sixiang.license.entity.AlarmRead; ...@@ -13,5 +16,5 @@ import iot.sixiang.license.entity.AlarmRead;
*/ */
public interface AlarmReadMapper extends BaseMapper<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 ...@@ -33,6 +33,7 @@ public class AlarmReadServiceImpl extends ServiceImpl<AlarmReadMapper, AlarmRead
AlarmMapper alarmMapper; AlarmMapper alarmMapper;
@Resource @Resource
AlarmReadMapper alarmReadMapper; AlarmReadMapper alarmReadMapper;
private static final int INSERT_BATCH_SIZE = 1000;
@Override @Override
...@@ -42,6 +43,7 @@ public class AlarmReadServiceImpl extends ServiceImpl<AlarmReadMapper, AlarmRead ...@@ -42,6 +43,7 @@ public class AlarmReadServiceImpl extends ServiceImpl<AlarmReadMapper, AlarmRead
} }
userId = Integer.valueOf(XssUtil.checkXSS(String.valueOf(userId))); userId = Integer.valueOf(XssUtil.checkXSS(String.valueOf(userId)));
List<AlarmVo> alarmList = alarmMapper.getAlarmList(userId); List<AlarmVo> alarmList = alarmMapper.getAlarmList(userId);
List<AlarmVo> newAlarmList = new ArrayList<>();
for (AlarmVo alarm: alarmList) { for (AlarmVo alarm: alarmList) {
if (alarm.getReadFlag() == 0) { if (alarm.getReadFlag() == 0) {
int alarmId = alarm.getId(); int alarmId = alarm.getId();
...@@ -54,10 +56,33 @@ public class AlarmReadServiceImpl extends ServiceImpl<AlarmReadMapper, AlarmRead ...@@ -54,10 +56,33 @@ public class AlarmReadServiceImpl extends ServiceImpl<AlarmReadMapper, AlarmRead
title = XssUtil.checkXSS(title); title = XssUtil.checkXSS(title);
content = XssUtil.checkXSS(content); 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) { if (!res) {
return false; 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; return true;
......
...@@ -2,7 +2,10 @@ ...@@ -2,7 +2,10 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!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"> <mapper namespace="iot.sixiang.license.mapper.AlarmReadMapper">
<insert id="readAlarm" parameterType="iot.sixiang.license.entity.AlarmRead"> <insert id="readAlarm">
insert into alarm_read (alarm_id, type_id, title, content, create_time, user_id) values (#{alarmId},#{typeId},#{title},#{content},now(),#{userId}); 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> </insert>
</mapper> </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