Commit fd4c8cb2 by HlQ

[add] 添加事件的增删改查以及绑定解绑相关接口

1 parent a6c59d43
package vion.controller.monitor;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.dromara.hutool.core.data.id.IdUtil;
import org.springframework.web.bind.annotation.*;
import vion.dto.monitor.EventDTO;
import vion.model.monitor.Event;
import vion.model.monitor.RAgentEvent;
import vion.service.monitor.IEventService;
import vion.service.monitor.IRAgentEventService;
import vion.vo.monitor.EventVO;
import java.util.List;
/**
* 事件管理
*/
@RestController
@RequestMapping("/api/event")
@RequiredArgsConstructor
public class EventController {
private final IEventService eventService;
private final IRAgentEventService agentEventService;
@GetMapping
@SaCheckPermission(value = "event:list", orRole = "admin")
public Page<Event> list(Event event) {
return eventService.lambdaQuery(event)
.orderByDesc(Event::getCreateTime)
.page(Page.of(event.getPageNum(), event.getPageSize()));
}
@GetMapping("/{id}")
@SaCheckPermission(value = "event:query", orRole = "admin")
public Event get(@PathVariable Long id) {
return eventService.getById(id);
}
@PostMapping
@SaCheckPermission(value = "event:save", orRole = "admin")
public String save(@RequestBody Event event) {
event.setUid(IdUtil.nanoId(20));
return eventService.save(event) ? "事件添加成功" : "事件添加失败";
}
@PostMapping("/{id}")
@SaCheckPermission(value = "event:edit", orRole = "admin")
public String update(@PathVariable Long id, @RequestBody Event event) {
event.setId(id);
return eventService.updateById(event) ? "事件更新成功" : "事件更新失败";
}
@DeleteMapping("/{id}")
@SaCheckPermission(value = "event:remove", orRole = "admin")
public String remove(@PathVariable Long id) {
return eventService.removeById(id) ? "事件删除成功" : "事件删除失败";
}
@GetMapping("/bind/{agentUid}")
@SaCheckPermission(value = "event:bind:list", orRole = "admin")
public Page<EventVO> listAgentEvent(EventDTO dto) {
return eventService.list(dto);
}
@PostMapping("/bind/{agentUid}")
@SaCheckPermission(value = "event:bind", orRole = "admin")
public String bind(@PathVariable String agentUid, @RequestBody List<RAgentEvent> dtoList) {
return agentEventService.bind(agentUid, dtoList);
}
@PostMapping("/unbind")
@SaCheckPermission(value = "event:unbind", orRole = "admin")
public String unbind(List<Long> idList) {
return agentEventService.unbind(idList);
}
}
package vion.dto.monitor;
import lombok.Getter;
import lombok.Setter;
import vion.dto.BaseDTO;
import java.time.LocalDate;
import java.time.LocalDateTime;
/**
* 监测事件
*/
@Getter
@Setter
public class EventDTO extends BaseDTO {
private Long id;
/**
* 唯一标识
*/
private String uid;
/**
* 事件名称
*/
private String name;
/**
* 事件类型
*/
private String eventType;
/**
* 来源 1:系统 2:设备 3:平台
*/
private Short source;
/**
* 监测时间
*/
private String cron;
/**
* 默认阈值,可为空
*/
private String threshold;
/**
* 对比周期
*/
private String contrastPeriod;
/**
* 规则
*/
private Object rule;
/**
* 备注
*/
private String remark;
/**
* 创建人
*/
private String createBy;
/**
* 修改人
*/
private String updateBy;
private LocalDateTime createTime;
private LocalDateTime updateTime;
/**
* agent uid
*/
private String agentUid;
/**
* account 信息
*/
private String accountUid;
private String accountName;
/**
* mall 信息
*/
private String mallUid;
private String mallName;
/**
* 开关 0:关 1:开
*/
private Short controlSwitch;
/**
* 过期日期
*/
private LocalDate expire;
}
\ No newline at end of file
package vion.mapper.monitor;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.github.yulichang.base.MPJBaseMapper;
import vion.model.monitor.Event;
/**
* @author vion
* @date 2024/10/31
*/
public interface EventMapper extends BaseMapper<Event> {
public interface EventMapper extends MPJBaseMapper<Event> {
}
\ No newline at end of file
package vion.mapper.monitor;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.github.yulichang.base.MPJBaseMapper;
import vion.model.monitor.RAgentEvent;
/**
* @author vion
* @date 2024/10/31
*/
public interface RAgentEventMapper extends BaseMapper<RAgentEvent> {
public interface RAgentEventMapper extends MPJBaseMapper<RAgentEvent> {
}
\ No newline at end of file
package vion.model.monitor;
import com.baomidou.mybatisplus.annotation.*;
import io.github.linpeilie.annotations.AutoMapper;
import io.github.linpeilie.annotations.AutoMappers;
import lombok.Getter;
import lombok.Setter;
import vion.dto.BaseDTO;
import vion.dto.monitor.EventDTO;
import vion.vo.monitor.EventVO;
import java.time.LocalDateTime;
......@@ -12,20 +17,24 @@ import java.time.LocalDateTime;
@Getter
@Setter
@TableName(value = "m_event")
public class Event {
@AutoMappers({
@AutoMapper(target = EventVO.class),
@AutoMapper(target = EventDTO.class),
})
public class Event extends BaseDTO {
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 唯一标识
*/
@TableField(value = "\"uid\"")
@TableField(value = "uid")
private String uid;
/**
* 事件名称
*/
@TableField(value = "\"name\"")
@TableField(value = "\"name\"", condition = SqlCondition.LIKE)
private String name;
/**
......
......@@ -54,6 +54,12 @@ public class Upgrade extends BaseDTO {
@TableField(value = "sha256")
private String sha256;
/**
* 备注
*/
@TableField(value = "remark")
private String remark;
@TableField(value = "create_time", fill = FieldFill.INSERT)
private LocalDateTime createTime;
......
package vion.service.impl.monitor;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import org.dromara.hutool.core.lang.Assert;
import org.springframework.stereotype.Service;
import vion.dto.monitor.EventDTO;
import vion.mapper.monitor.EventMapper;
import vion.model.monitor.Event;
import vion.model.monitor.RAgentEvent;
import vion.service.monitor.IEventService;
import vion.vo.monitor.EventVO;
/**
* @author vion
* @date 2024/10/31
*/
@Service
public class EventServiceImpl extends ServiceImpl<EventMapper, Event> implements IEventService {
@RequiredArgsConstructor
public class EventServiceImpl extends MPJBaseServiceImpl<EventMapper, Event> implements IEventService {
private final Converter converter;
@Override
public Page<EventVO> list(EventDTO dto) {
Assert.notNull(dto.getAgentUid(), "agentUid 不能为空");
Assert.notNull(dto.getMallUid(), "mallUid 不能为空");
var wrapper = new MPJLambdaWrapper<>(converter.convert(dto, Event.class))
.selectAs(Event::getName, EventVO::getName)
.selectAs(Event::getUid, EventVO::getUid)
.selectAsClass(RAgentEvent.class, EventVO.class)
.leftJoin(RAgentEvent.class, RAgentEvent::getEventUid, Event::getUid)
.orderByDesc(RAgentEvent::getUpdateTime);
return this.selectJoinListPage(Page.of(dto.getPageNum(), dto.getPageSize()), EventVO.class, wrapper);
}
}
package vion.service.impl.monitor;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.base.MPJBaseServiceImpl;
import org.dromara.hutool.core.lang.Opt;
import org.springframework.stereotype.Service;
import vion.mapper.monitor.RAgentEventMapper;
import vion.model.monitor.RAgentEvent;
import vion.service.monitor.IRAgentEventService;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* @author vion
* @date 2024/10/31
*/
@Service
public class RAgentEventServiceImpl extends ServiceImpl<RAgentEventMapper, RAgentEvent> implements IRAgentEventService {
public class RAgentEventServiceImpl extends MPJBaseServiceImpl<RAgentEventMapper, RAgentEvent> implements IRAgentEventService {
@Override
public String bind(String agentUid, List<RAgentEvent> dtoList) {
dtoList.forEach(ae -> ae.setAgentUid(agentUid));
var agentEventList = this.lambdaQuery().eq(RAgentEvent::getAgentUid, agentUid).list();
var mallUid2AEMap = agentEventList.stream().collect(Collectors.toMap(RAgentEvent::getMallUid, Function.identity()));
List<RAgentEvent> updList = new ArrayList<>();
List<RAgentEvent> insList = new ArrayList<>();
dtoList.forEach(dto -> {
if (mallUid2AEMap.containsKey(dto.getMallUid())) {
var ae = mallUid2AEMap.get(dto.getMallUid());
dto.setId(ae.getId());
updList.add(dto);
} else {
insList.add(dto);
}
});
Opt.ofEmptyAble(updList).ifPresent(this::updateBatchById);
Opt.ofEmptyAble(insList).ifPresent(this::saveBatch);
return "绑定成功";
}
@Override
public String unbind(List<Long> idList) {
return this.removeBatchByIds(idList) ? "解绑成功" : "解绑失败";
}
}
package vion.service.monitor;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.base.MPJBaseService;
import vion.dto.monitor.EventDTO;
import vion.model.monitor.Event;
/**
import vion.vo.monitor.EventVO;
/**
* @author vion
* @date 2024/10/31
*/
public interface IEventService extends IService<Event>{
public interface IEventService extends MPJBaseService<Event> {
Page<EventVO> list(EventDTO dto);
}
package vion.service.monitor;
import com.baomidou.mybatisplus.extension.service.IService;
import com.github.yulichang.base.MPJBaseService;
import vion.model.monitor.RAgentEvent;
/**
import java.util.List;
/**
* @author vion
* @date 2024/10/31
*/
public interface IRAgentEventService extends IService<RAgentEvent>{
public interface IRAgentEventService extends MPJBaseService<RAgentEvent> {
String bind(String agentUid, List<RAgentEvent> dtoList);
String unbind(List<Long> idList);
}
package vion.vo.monitor;
import lombok.Getter;
import lombok.Setter;
import java.time.LocalDate;
import java.time.LocalDateTime;
/**
* 监测事件
*/
@Getter
@Setter
public class EventVO {
private Long id;
/**
* 唯一标识
*/
private String uid;
/**
* 事件名称
*/
private String name;
/**
* 事件类型
*/
private String eventType;
/**
* 来源 1:系统 2:设备 3:平台
*/
private Short source;
/**
* 监测时间
*/
private String cron;
/**
* 默认阈值,可为空
*/
private String threshold;
/**
* 对比周期
*/
private String contrastPeriod;
/**
* 规则
*/
private Object rule;
/**
* 备注
*/
private String remark;
/**
* 创建人
*/
private String createBy;
/**
* 修改人
*/
private String updateBy;
private LocalDateTime createTime;
private LocalDateTime updateTime;
/**
* account 信息
*/
private String accountUid;
private String accountName;
/**
* mall 信息
*/
private String mallUid;
private String mallName;
/**
* 开关 0:关 1:开
*/
private Short controlSwitch;
/**
* 过期日期
*/
private LocalDate expire;
}
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!