170 lines
5.0 KiB
170 lines
5.0 KiB
package com.yingji.controller;
|
|
|
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.yingji.base.controller.BaseController;
|
|
import com.yingji.base.domain.AjaxResult;
|
|
import com.yingji.entity.Alarm;
|
|
import com.yingji.entity.dto.request.AlarmFindRequest;
|
|
import com.yingji.service.AlarmService;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PutMapping;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import javax.annotation.Resource;
|
|
import java.io.Serializable;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* 报警事件(Alarm)表控制层
|
|
*
|
|
* @author wu
|
|
* @since 2024-05-06 09:15:01
|
|
*/
|
|
@RestController
|
|
@RequestMapping("algorithms/alarm")
|
|
@Api(tags = "报警事件")
|
|
public class AlarmController extends BaseController {
|
|
/**
|
|
* 服务对象
|
|
*/
|
|
@Resource
|
|
private AlarmService alarmService;
|
|
|
|
/**
|
|
* 分页条件查询所有数据
|
|
*
|
|
* @param page 分页条件
|
|
* @param req 查询条件
|
|
* @return 所有数据
|
|
*/
|
|
@GetMapping
|
|
@ApiOperation(value = "分页条件查询报警事件", response = Alarm.class)
|
|
public AjaxResult page(Page<Alarm> page, AlarmFindRequest req) {
|
|
StpUtil.checkLogin();
|
|
return success(alarmService.page(page, req));
|
|
}
|
|
|
|
/**
|
|
* 条件查询所有报警事件
|
|
*
|
|
* @param req 查询条件
|
|
* @return 所有数据
|
|
*/
|
|
@GetMapping("/findAll")
|
|
@ApiOperation(value = "条件查询所有报警事件", response = Alarm.class)
|
|
public AjaxResult findAll(AlarmFindRequest req) {
|
|
StpUtil.checkLogin();
|
|
// StpUtil.renewTimeout(100);
|
|
return success(alarmService.findAll(req));
|
|
}
|
|
|
|
/**
|
|
* 通过主键查询单条数据
|
|
*
|
|
* @param id 主键
|
|
* @return 单条数据
|
|
*/
|
|
@GetMapping("{id}")
|
|
@ApiOperation(value = "通过主键查询单条报警事件", response = Alarm.class)
|
|
public AjaxResult getById(@PathVariable Serializable id) {
|
|
StpUtil.checkLogin();
|
|
return success(alarmService.getById(id));
|
|
}
|
|
|
|
/**
|
|
* 新增数据
|
|
*
|
|
* @param alarm 实体对象
|
|
* @return 新增结果
|
|
*/
|
|
@PostMapping
|
|
@ApiOperation(value = "新增报警事件", response = Alarm.class)
|
|
public AjaxResult insert(@RequestBody Alarm alarm) {
|
|
StpUtil.checkLogin();
|
|
return success(alarmService.save(alarm));
|
|
}
|
|
|
|
/**
|
|
* 修改数据
|
|
*
|
|
* @param alarm 实体对象
|
|
* @return 修改结果
|
|
*/
|
|
@PutMapping
|
|
@ApiOperation(value = "修改报警事件")
|
|
public AjaxResult update(@RequestBody Alarm alarm) {
|
|
StpUtil.checkLogin();
|
|
return success(alarmService.updateById(alarm));
|
|
}
|
|
|
|
/**
|
|
* 删除数据
|
|
*
|
|
* @param idList 主键集合
|
|
* @return 删除结果
|
|
*/
|
|
@DeleteMapping
|
|
@ApiOperation(value = "删除报警事件")
|
|
public AjaxResult delete(@RequestParam("idList") List<Long> idList) {
|
|
StpUtil.checkLogin();
|
|
return success(alarmService.removeByIds(idList));
|
|
}
|
|
|
|
/**
|
|
* 同步数据
|
|
*
|
|
* @param startTime 查询条件
|
|
* @param size 查询条数
|
|
* @return 所有数据
|
|
*/
|
|
@GetMapping("/synchronous")
|
|
@ApiOperation(value = "同步数据")
|
|
public AjaxResult synchronous(String startTime, Integer size) {
|
|
StpUtil.checkLogin();
|
|
alarmService.synchronous(startTime, size);
|
|
return success();
|
|
}
|
|
|
|
@ApiOperation(value = "登录")
|
|
@GetMapping("doLogin")
|
|
public AjaxResult doLogin(String clientId, String clientSecret) {
|
|
// 此处仅作模拟示例,真实项目需要从数据库中查询数据进行比对
|
|
if ("9219a5c1612c398c".equals(clientId) && "88aba31a35e3a713".equals(clientSecret)) {
|
|
StpUtil.login(10001);
|
|
return success((Object)StpUtil.getTokenValue());
|
|
}
|
|
return error("错误的授权码");
|
|
}
|
|
|
|
@ApiOperation(value = "查询登录状态")
|
|
@GetMapping("isLogin")
|
|
public String isLogin() {
|
|
return "当前会话是否登录:" + StpUtil.isLogin();
|
|
}
|
|
|
|
// public static void main(String[] args) {
|
|
// String encode = Base64.encode("123QWQAVA1314543");
|
|
// System.err.println(encode);
|
|
// MD5 md5 = MD5.create();
|
|
// String s = md5.digestHex16(encode);
|
|
// System.err.println(s);
|
|
//
|
|
// String encode2 = Base64.encode("321123QWQAVAORZ");
|
|
// System.err.println(encode2);
|
|
// MD5 md52 = MD5.create();
|
|
// String s2 = md5.digestHex16(encode2);
|
|
// System.err.println(s2);
|
|
// }
|
|
}
|
|
|