gasWellWatch/src/main/java/com/isu/gaswellwatch/controller/DeviceController.java

147 lines
5.3 KiB
Java
Raw Normal View History

2024-11-25 01:04:53 +08:00
package com.isu.gaswellwatch.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.isu.gaswellwatch.annotation.OperationLog;
import com.isu.gaswellwatch.dto.DeviceCreateDTO;
import com.isu.gaswellwatch.dto.DeviceEditDTO;
2024-11-26 18:46:34 +08:00
import com.isu.gaswellwatch.entity.DeviceOptLog;
2024-11-25 01:04:53 +08:00
import com.isu.gaswellwatch.entity.Response;
import com.isu.gaswellwatch.enums.LogType;
import com.isu.gaswellwatch.exception.BusinessException;
2024-11-25 01:04:53 +08:00
import com.isu.gaswellwatch.service.DeviceService;
import com.isu.gaswellwatch.vo.DeviceHistoryVO;
2024-11-25 15:48:00 +08:00
import com.isu.gaswellwatch.vo.DeviceVO;
2024-11-25 01:04:53 +08:00
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.text.ParseException;
import java.util.Map;
2024-11-25 01:04:53 +08:00
/**
* 设备管理
*
* @author scwsl
* @date 2024-11-17
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/device")
public class DeviceController {
private final DeviceService deviceService;
/**
* 查询设备列表
*/
@GetMapping(value = "/page")
2024-11-25 15:48:00 +08:00
public Response<Page<DeviceVO>> page(@RequestParam(defaultValue = "1") Integer currentPage,
@RequestParam(defaultValue = "10") Integer pageSize,
@RequestParam(required = false) String gasWellName,
@RequestParam(required = false) String gasStationName,
@RequestParam Long deviceTypeId) {
2024-11-25 01:04:53 +08:00
return Response.succeed(deviceService.page(currentPage, pageSize, gasWellName,gasStationName,deviceTypeId));
}
/**
* 获取设备基础信息
*/
@GetMapping(value = "/getDevice")
2024-11-25 15:48:00 +08:00
public Response<DeviceVO> getDevice(@RequestParam Long id) {
2024-11-25 01:04:53 +08:00
return Response.succeed(deviceService.getDevice(id));
}
/**
*新增设备
*/
@PostMapping(value = "/add")
@OperationLog(description = "新增设备", type = LogType.ADD)
public Response<String> add(@RequestBody @Valid DeviceCreateDTO deviceCreateDTO) {
deviceService.add(deviceCreateDTO);
return Response.succeed();
}
/**
* 修改设备
*/
@PostMapping("/edit")
@OperationLog(description = "修改设备", type = LogType.UPDATE)
public Response<String> edit(@RequestBody @Valid DeviceEditDTO deviceEditDTO) {
deviceService.edit(deviceEditDTO);
return Response.succeed();
}
/**
* 删除设备
*/
@GetMapping("/delete")
@OperationLog(description = "删除设备", type = LogType.DELETE)
public Response<String> delete(@RequestParam Long id) {
deviceService.delete(id);
return Response.succeed();
}
/**
* 获取设备控制数据
*/
@GetMapping("/getDeviceControlData")
public Response<Map<String,String>> getDeviceControlData(@RequestParam Long deviceId) {
return Response.succeed(deviceService.getDeviceControlData(deviceId));
}
/**
* 保存设备控制数据
*/
@PostMapping("/saveDeviceControlData")
public Response<String> saveDeviceControlData(@RequestBody Map<String,String> controlData,@RequestParam Long deviceId) {
2024-11-26 18:46:34 +08:00
deviceService.saveDeviceControlData(controlData,deviceId);
2024-11-25 01:04:53 +08:00
return Response.succeed();
}
/**
* 获取设备历史数据
*/
@GetMapping("/getDeviceHistoryData")
public Response<Page<DeviceHistoryVO>> getDeviceHistoryData(@RequestParam(defaultValue = "1") Integer currentPage,
@RequestParam(defaultValue = "10") Integer pageSize,
@RequestParam(required = false)String startTime,
@RequestParam (required = false)String endTime,
@RequestParam Long deviceId) {
try {
return Response.succeed(deviceService.getDeviceHistoryData(currentPage,pageSize,startTime,endTime,deviceId));
} catch (ParseException e) {
throw new BusinessException("日期格式错误");
}
2024-11-25 01:04:53 +08:00
}
/**
* 获取设备日志数据
*/
@GetMapping("/getDeviceLogData")
2024-11-26 18:46:34 +08:00
public Response<Page<DeviceOptLog>> getDeviceLogData(@RequestParam(defaultValue = "1") Integer currentPage,
@RequestParam(defaultValue = "10") Integer pageSize,
@RequestParam(required = false)String startTime,
@RequestParam (required = false)String endTime,
@RequestParam Long deviceId) {
try {
return Response.succeed(deviceService.getDeviceLogData(currentPage,pageSize,startTime,endTime,deviceId));
} catch (ParseException e) {
throw new BusinessException("日期格式错误");
}
}
/**
* 控制开/关井
*
* @Param isOpen 1 开井 0 关井
* @Param deviceId 设备id
*/
@GetMapping("/wellCtl")
public Response<String> wellCtl(@RequestParam Integer isOpen, @RequestParam Long deviceId) {
deviceService.wellCtl(isOpen,deviceId);
2024-11-25 01:04:53 +08:00
return Response.succeed();
}
}