mirror of
https://gitee.com/pan648540858/wvp-GB28181-pro.git
synced 2026-05-22 21:37:48 +08:00
实现按筛选条件清空报警信息功能
This commit is contained in:
parent
280ed4aee3
commit
f5f86c40a0
@ -17,6 +17,9 @@ public interface IAlarmService {
|
|||||||
// 删除报警信息
|
// 删除报警信息
|
||||||
void deleteAlarmInfo(List<Long> ids);
|
void deleteAlarmInfo(List<Long> ids);
|
||||||
|
|
||||||
|
// 按筛选条件清空报警信息
|
||||||
|
int clearAlarmsByCondition(List<AlarmType> alarmType, String beginTime, String endTime);
|
||||||
|
|
||||||
// 根据ID获取报警快照
|
// 根据ID获取报警快照
|
||||||
String getAlarmSnapById(Long id);
|
String getAlarmSnapById(Long id);
|
||||||
|
|
||||||
|
|||||||
@ -27,6 +27,7 @@ import org.springframework.context.event.EventListener;
|
|||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -165,6 +166,30 @@ public class AlarmServiceImpl implements IAlarmService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public int clearAlarmsByCondition(List<AlarmType> alarmType, String beginTime, String endTime) {
|
||||||
|
Long beginTimeLong = null;
|
||||||
|
Long endTimeLong = null;
|
||||||
|
if (beginTime != null) {
|
||||||
|
beginTimeLong = DateUtil.yyyy_MM_dd_HH_mm_ssToTimestampMs(beginTime);
|
||||||
|
}
|
||||||
|
if (endTime != null) {
|
||||||
|
endTimeLong = DateUtil.yyyy_MM_dd_HH_mm_ssToTimestampMs(endTime);
|
||||||
|
}
|
||||||
|
// 清理前缓存数据,数据库删除后,相关的报警快照文件也需要清理掉
|
||||||
|
alarmMapper.getAlarms(alarmType, beginTimeLong, endTimeLong).forEach(alarm -> {
|
||||||
|
String snapPath = alarm.getSnapPath();
|
||||||
|
if (snapPath != null) {
|
||||||
|
File file = new File(snapPath);
|
||||||
|
if (file.exists()) {
|
||||||
|
file.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return alarmMapper.deleteAlarmsByCondition(alarmType, beginTimeLong, endTimeLong);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAlarmSnapById(Long id) {
|
public String getAlarmSnapById(Long id) {
|
||||||
return alarmMapper.getSnapPathById(id);
|
return alarmMapper.getSnapPathById(id);
|
||||||
|
|||||||
@ -51,4 +51,19 @@ public interface AlarmMapper {
|
|||||||
|
|
||||||
@Select("SELECT snap_path FROM wvp_alarm WHERE id = #{id}")
|
@Select("SELECT snap_path FROM wvp_alarm WHERE id = #{id}")
|
||||||
String getSnapPathById(@Param("id") Long id);
|
String getSnapPathById(@Param("id") Long id);
|
||||||
|
|
||||||
|
@Delete("<script>" +
|
||||||
|
"DELETE FROM wvp_alarm WHERE 1=1" +
|
||||||
|
"<if test='alarmType != null and alarmType.size() > 0'>" +
|
||||||
|
" AND alarm_type IN " +
|
||||||
|
"<foreach collection='alarmType' item='item' open='(' separator=',' close=')'>" +
|
||||||
|
"#{item}" +
|
||||||
|
"</foreach>" +
|
||||||
|
"</if>" +
|
||||||
|
"<if test='beginTimeLong != null'> AND alarm_time >= #{beginTimeLong}</if>" +
|
||||||
|
"<if test='endTimeLong != null'> AND alarm_time <= #{endTimeLong}</if>" +
|
||||||
|
"</script>")
|
||||||
|
int deleteAlarmsByCondition(@Param("alarmType") List<AlarmType> alarmType,
|
||||||
|
@Param("beginTimeLong") Long beginTimeLong,
|
||||||
|
@Param("endTimeLong") Long endTimeLong);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -55,6 +55,18 @@ public class AlarmController {
|
|||||||
alarmService.deleteAlarmInfo(ids);
|
alarmService.deleteAlarmInfo(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ResponseBody
|
||||||
|
@DeleteMapping("/clear")
|
||||||
|
@Operation(summary = "按筛选条件清空报警信息", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||||
|
@Parameter(name = "alarmType", description = "报警类型列表,为空则不限类型")
|
||||||
|
@Parameter(name = "beginTime", description = "开始时间,格式:yyyy-MM-dd HH:mm:ss")
|
||||||
|
@Parameter(name = "endTime", description = "结束时间,格式:yyyy-MM-dd HH:mm:ss")
|
||||||
|
public int clear(@RequestParam(required = false) List<AlarmType> alarmType,
|
||||||
|
@RequestParam(required = false) String beginTime,
|
||||||
|
@RequestParam(required = false) String endTime) {
|
||||||
|
return alarmService.clearAlarmsByCondition(alarmType, beginTime, endTime);
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/snap/{id}")
|
@GetMapping("/snap/{id}")
|
||||||
@Operation(summary = "获取报警快照图片")
|
@Operation(summary = "获取报警快照图片")
|
||||||
@Parameter(name = "id", description = "报警ID", required = true)
|
@Parameter(name = "id", description = "报警ID", required = true)
|
||||||
|
|||||||
@ -23,3 +23,18 @@ export function deleteAlarms(ids) {
|
|||||||
data: ids
|
data: ids
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function clearAlarms(params) {
|
||||||
|
const { alarmType, beginTime, endTime } = params || {}
|
||||||
|
const query = new URLSearchParams()
|
||||||
|
if (alarmType && alarmType.length > 0) {
|
||||||
|
alarmType.forEach(t => query.append('alarmType', t))
|
||||||
|
}
|
||||||
|
if (beginTime) query.append('beginTime', beginTime)
|
||||||
|
if (endTime) query.append('endTime', endTime)
|
||||||
|
const qs = query.toString()
|
||||||
|
return request({
|
||||||
|
method: 'delete',
|
||||||
|
url: `/api/alarm/clear${qs ? '?' + qs : ''}`
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { getAlarmList, deleteAlarms } from '@/api/alarm'
|
import { getAlarmList, deleteAlarms, clearAlarms } from '@/api/alarm'
|
||||||
|
|
||||||
const actions = {
|
const actions = {
|
||||||
getAlarmList({ commit }, params) {
|
getAlarmList({ commit }, params) {
|
||||||
@ -20,6 +20,16 @@ const actions = {
|
|||||||
reject(error)
|
reject(error)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
clearAlarms({ commit }, params) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
clearAlarms(params).then(response => {
|
||||||
|
const { data } = response
|
||||||
|
resolve(data)
|
||||||
|
}).catch(error => {
|
||||||
|
reject(error)
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -55,6 +55,17 @@
|
|||||||
删除选中
|
删除选中
|
||||||
</el-button>
|
</el-button>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
<el-form-item>
|
||||||
|
<el-button
|
||||||
|
size="mini"
|
||||||
|
type="danger"
|
||||||
|
plain
|
||||||
|
icon="el-icon-delete-solid"
|
||||||
|
@click="clearByCondition"
|
||||||
|
>
|
||||||
|
清空
|
||||||
|
</el-button>
|
||||||
|
</el-form-item>
|
||||||
<el-form-item style="float: right;">
|
<el-form-item style="float: right;">
|
||||||
<el-button icon="el-icon-refresh-right" circle size="mini" @click="getAlarmList()" />
|
<el-button icon="el-icon-refresh-right" circle size="mini" @click="getAlarmList()" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
@ -358,6 +369,40 @@ export default {
|
|||||||
})
|
})
|
||||||
}).catch(() => {})
|
}).catch(() => {})
|
||||||
},
|
},
|
||||||
|
clearByCondition() {
|
||||||
|
const hasFilter = this.beginTime || this.endTime || this.selectedAlarmTypes.length > 0
|
||||||
|
const filterDesc = hasFilter
|
||||||
|
? [
|
||||||
|
this.beginTime ? `开始时间:${this.beginTime}` : null,
|
||||||
|
this.endTime ? `结束时间:${this.endTime}` : null,
|
||||||
|
this.selectedAlarmTypes.length > 0 ? `报警类型:${this.selectedAlarmTypes.map(v => {
|
||||||
|
const opt = this.alarmTypeOptions.find(o => o.value === v)
|
||||||
|
return opt ? opt.label : v
|
||||||
|
}).join('、')}` : null
|
||||||
|
].filter(Boolean).join(';')
|
||||||
|
: '全部'
|
||||||
|
this.$confirm(
|
||||||
|
`将删除符合当前筛选条件的所有报警记录(${filterDesc}),此操作不可恢复,确定继续?`,
|
||||||
|
'清空报警',
|
||||||
|
{
|
||||||
|
confirmButtonText: '确定删除',
|
||||||
|
cancelButtonText: '取消',
|
||||||
|
type: 'warning'
|
||||||
|
}
|
||||||
|
).then(() => {
|
||||||
|
this.$store.dispatch('alarm/clearAlarms', {
|
||||||
|
alarmType: this.selectedAlarmTypes.length > 0 ? this.selectedAlarmTypes : undefined,
|
||||||
|
beginTime: this.beginTime || undefined,
|
||||||
|
endTime: this.endTime || undefined
|
||||||
|
}).then(count => {
|
||||||
|
this.$message({ showClose: true, message: `已清空 ${count != null ? count : ''} 条报警记录`, type: 'success' })
|
||||||
|
this.currentPage = 1
|
||||||
|
this.getAlarmList()
|
||||||
|
}).catch(error => {
|
||||||
|
this.$message({ showClose: true, message: error, type: 'error' })
|
||||||
|
})
|
||||||
|
}).catch(() => {})
|
||||||
|
},
|
||||||
getAlarmTypeLabel(value) {
|
getAlarmTypeLabel(value) {
|
||||||
const option = ALARM_TYPE_OPTIONS.find(o => o.value === value)
|
const option = ALARM_TYPE_OPTIONS.find(o => o.value === value)
|
||||||
return option ? option.label : value
|
return option ? option.label : value
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user