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; import com.isu.gaswellwatch.entity.DeviceOptLog; import com.isu.gaswellwatch.entity.Response; import com.isu.gaswellwatch.enums.LogType; import com.isu.gaswellwatch.exception.BusinessException; import com.isu.gaswellwatch.service.DeviceService; import com.isu.gaswellwatch.vo.DeviceHistoryVO; import com.isu.gaswellwatch.vo.DeviceVO; import jakarta.servlet.http.HttpServletResponse; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; import java.text.ParseException; import java.util.Map; /** * 设备管理 * * @author scwsl * @date 2024-11-17 */ @RestController @RequiredArgsConstructor @RequestMapping("/device") public class DeviceController { private final DeviceService deviceService; /** * 查询设备列表 */ @GetMapping(value = "/page") public Response> page(@RequestParam(defaultValue = "1") Integer currentPage, @RequestParam(defaultValue = "10") Integer pageSize, @RequestParam(required = false) String gasWellName, @RequestParam(required = false) String gasStationName, @RequestParam Long deviceTypeId,@RequestParam Long blockId) { return Response.succeed(deviceService.page(currentPage, pageSize, gasWellName,gasStationName,deviceTypeId,blockId)); } /** * 获取设备基础信息 */ @GetMapping(value = "/getDevice") public Response getDevice(@RequestParam Long id) { return Response.succeed(deviceService.getDevice(id)); } /** *新增设备 */ @PostMapping(value = "/add") @OperationLog(description = "新增设备", type = LogType.ADD) public Response add(@RequestBody @Valid DeviceCreateDTO deviceCreateDTO) { try { deviceService.add(deviceCreateDTO); }catch (NumberFormatException e){ throw new BusinessException("设备编号只能为纯数字格式"); } return Response.succeed(); } /** * 修改设备 */ @PostMapping("/edit") @OperationLog(description = "修改设备", type = LogType.UPDATE) public Response edit(@RequestBody @Valid DeviceEditDTO deviceEditDTO) { deviceService.edit(deviceEditDTO); return Response.succeed(); } /** * 删除设备 */ @GetMapping("/delete") @OperationLog(description = "删除设备", type = LogType.DELETE) public Response delete(@RequestParam Long id) { deviceService.delete(id); return Response.succeed(); } /** * 获取设备控制数据 */ @GetMapping("/getDeviceControlData") public Response> getDeviceControlData(@RequestParam Long deviceId) { return Response.succeed(deviceService.getDeviceControlData(deviceId)); } /** * 获取设备历史数据 */ @GetMapping("/getDeviceHistoryData") public Response> 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("日期格式错误"); } } /** * 获取设备日志数据 */ @GetMapping("/getDeviceLogData") public Response> 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("日期格式错误"); } } /** * 设备历史数据导出 */ @GetMapping("/exportHistoryData") @OperationLog(description = "设备历史数据导出",type = LogType.EXPORT) public void exportHistoryData(HttpServletResponse response, @RequestParam Long deviceId, @RequestParam String startTime, @RequestParam String endTime) { try{ deviceService.exportHistoryData(response,deviceId, startTime, endTime); } catch (ParseException e) { throw new BusinessException("日期格式错误"); } } /** * 设备开关状态数据导出 */ @GetMapping("/exportSwitchStatusData") @OperationLog(description = "设备开关状态数据导出",type = LogType.EXPORT) public void exportSwitchStatusData(HttpServletResponse response, @RequestParam String startTime, @RequestParam String endTime) { deviceService.exportSwitchStatusData(response, startTime, endTime); } }