forked from dyf/fys-Multi-tenant
分页查询设备
This commit is contained in:
@ -0,0 +1,206 @@
|
||||
package com.fuyuanshen.equipment.controller;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fuyuanshen.common.core.domain.PageResult;
|
||||
import com.fuyuanshen.common.core.domain.ResponseVO;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.dto.DeviceQueryCriteria;
|
||||
import com.fuyuanshen.equipment.service.DeviceService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
* @Author: WY
|
||||
* @Date: 2025/5/16
|
||||
**/
|
||||
@Slf4j
|
||||
// @Api(tags = "设备:设备管理")
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/device")
|
||||
public class DeviceController {
|
||||
|
||||
private final DeviceService deviceService;
|
||||
|
||||
|
||||
|
||||
@GetMapping
|
||||
public ResponseVO<PageResult<Device>> queryDevice(DeviceQueryCriteria criteria) {
|
||||
Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize());
|
||||
PageResult<Device> devices = null;
|
||||
try {
|
||||
devices = deviceService.queryAll(criteria, page);
|
||||
} catch (IOException e) {
|
||||
log.error("queryDevice error: " + e.getMessage());
|
||||
return ResponseVO.fail("");
|
||||
}
|
||||
return ResponseVO.success(devices);
|
||||
}
|
||||
|
||||
//
|
||||
// @Log("新增设备")
|
||||
// @ApiOperation("新增设备")
|
||||
// @PostMapping(value = "/add")
|
||||
// public ResponseVO<Object> addDevice(@Validated @ModelAttribute DeviceForm deviceForm) {
|
||||
// try {
|
||||
// deviceService.addDevice(deviceForm);
|
||||
// } catch (Exception e) {
|
||||
// log.error("addDevice error: " + e.getMessage());
|
||||
// return ResponseVO.fail(e.getMessage());
|
||||
// }
|
||||
// return ResponseVO.success(null);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * @param deviceForm
|
||||
// * @return
|
||||
// * @ModelAttribute 主要用于将请求参数绑定到 Java 对象上,它会从 HTTP 请求的查询参数(Query Parameters)
|
||||
// * 或表单数据(Form Data)中提取值,并自动填充到指定的对象属性中。
|
||||
// */
|
||||
// @Log("解绑设备")
|
||||
// @ApiOperation("解绑设备")
|
||||
// @PostMapping(value = "/unbind")
|
||||
// public ResponseVO<Object> unbindDevice(@Validated @ModelAttribute DeviceForm deviceForm) {
|
||||
// deviceService.unbindDevice(deviceForm);
|
||||
// return ResponseVO.success("解绑成功!!!");
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Log("修改设备")
|
||||
// @ApiOperation("修改设备")
|
||||
// @PutMapping(value = "/update")
|
||||
// public ResponseVO<Object> updateDevice(@Validated @ModelAttribute DeviceForm deviceForm) {
|
||||
// try {
|
||||
// deviceService.update(deviceForm);
|
||||
// } catch (Exception e) {
|
||||
// log.error("updateDevice error: " + e.getMessage());
|
||||
// return ResponseVO.fail("出错了");
|
||||
// }
|
||||
// return ResponseVO.success(null);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Log("分配客户")
|
||||
// @ApiOperation("分配客户")
|
||||
// @PutMapping(value = "/assignCustomer")
|
||||
// public ResponseVO<Object> assignCustomer(@Validated @RequestBody CustomerVo customerVo) {
|
||||
// deviceService.assignCustomer(customerVo);
|
||||
// return ResponseVO.success(null);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Log("撤回设备")
|
||||
// @ApiOperation("撤回设备")
|
||||
// @PostMapping(value = "/withdraw")
|
||||
// public ResponseVO<Object> withdrawDevice(@Validated @ModelAttribute DeviceForm deviceForm) {
|
||||
// try {
|
||||
// deviceService.withdrawDevice(deviceForm);
|
||||
// } catch (Exception e) {
|
||||
// log.error("updateDevice error: " + e.getMessage());
|
||||
// return ResponseVO.fail("出错了");
|
||||
// }
|
||||
// return ResponseVO.success(null);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @ApiOperation("设备详情")
|
||||
// @GetMapping(value = "/detail/{id}")
|
||||
// public ResponseVO<Object> getDevice(@PathVariable Long id) {
|
||||
// Device device = deviceService.getById(id);
|
||||
// return ResponseVO.success(device);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Log("删除设备")
|
||||
// @ApiOperation("删除设备")
|
||||
// @DeleteMapping(value = "/delete")
|
||||
// public ResponseVO<Object> deleteDevice(@ApiParam(value = "传ID数组[]") @RequestBody List<Long> ids) {
|
||||
// // deviceService.deleteAll(ids);
|
||||
// deviceService.deleteAssign(ids);
|
||||
// return ResponseVO.success(ResponseMessageConstants.DELETE_SUCCESS);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @ApiOperation("导出数据设备")
|
||||
// @GetMapping(value = "/download")
|
||||
// public void exportDevice(HttpServletResponse response, DeviceQueryCriteria criteria) throws IOException {
|
||||
// // deviceService.download(deviceService.queryAll(criteria), response);
|
||||
// User onlineuser = userService.findByName(SecurityUtils.getCurrentUsername());
|
||||
//
|
||||
// // 只能看到自己的创建的设备,以及被分配的设备。
|
||||
// if (onlineuser.getTenantId() != null && !onlineuser.getTenantId().equals(UserConstants.SUPER_ADMIN_ID)) {
|
||||
// // criteria.setTenantId(onlineuser.getTenantId());
|
||||
// criteria.setCurrentOwnerId(onlineuser.getId());
|
||||
// }
|
||||
// exportService.export(deviceService.queryAll(criteria), response);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @ApiOperation("设备定位")
|
||||
// @GetMapping(value = "/locateDevice")
|
||||
// public ResponseVO<Object> locateDevice(DeviceQueryCriteria criteria) throws IOException {
|
||||
// List<Device> devices = deviceService.queryAllDevices(criteria);
|
||||
// return ResponseVO.success(devices);
|
||||
// }
|
||||
//
|
||||
// @ApiOperation("设备数据模板下载")
|
||||
// @GetMapping("/template")
|
||||
// public void download(HttpServletRequest request, HttpServletResponse response) throws IOException, URISyntaxException {
|
||||
// // String filePath = "resources" + File.separator + "template" + File.separator + "device_import.csv";
|
||||
// Path path = Paths.get(ClassLoader.getSystemResource("template/device_import.csv").toURI());
|
||||
// FileUtil.downloadFile(request, response, new File(path.toUri()), true);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @ApiOperation("导入设备数据")
|
||||
// @PostMapping(value = "/import", consumes = "multipart/form-data")
|
||||
// public ResponseVO<ImportResult> importData(@ApiParam(value = "文件", required = true) @RequestPart("file") MultipartFile file) {
|
||||
//
|
||||
// String suffix = FileUtil.getExtensionName(file.getOriginalFilename());
|
||||
// if (!("xlsx".equalsIgnoreCase(suffix))) {
|
||||
// throw new BadRequestException("只能上传Excel——xlsx格式文件");
|
||||
// }
|
||||
//
|
||||
// ImportResult result = new ImportResult();
|
||||
// try {
|
||||
// User currentUser = userMapper.findByUsername(SecurityUtils.getCurrentUsername());
|
||||
// DeviceImportParams params = DeviceImportParams.builder().ip(ip).deviceService(deviceService).tenantId(currentUser.getTenantId()).file(file).filePath(filePath).deviceMapper(deviceMapper).deviceAssignmentsService(deviceAssignmentsService).deviceTypeMapper(deviceTypeMapper).userId(currentUser.getId()).userMapper(userMapper).build();
|
||||
// // 创建监听器
|
||||
// UploadDeviceDataListener listener = new UploadDeviceDataListener(params);
|
||||
// // 读取Excel
|
||||
// EasyExcel.read(file.getInputStream(), DeviceExcelImportDTO.class, listener).sheet().doRead();
|
||||
// // 获取导入结果
|
||||
// result = listener.getImportResult();
|
||||
// // 设置响应消息
|
||||
// String message = String.format("成功导入 %d 条数据,失败 %d 条", result.getSuccessCount(), result.getFailureCount());
|
||||
// // 返回带有正确泛型的响应
|
||||
// return ResponseVO.<ImportResult>success(message, result);
|
||||
// } catch (Exception e) {
|
||||
// log.error("导入设备数据出错: {}", e.getMessage(), e);
|
||||
// // 在异常情况下,设置默认结果
|
||||
// String errorMessage = String.format("导入失败: %s。成功 %d 条,失败 %d 条", e.getMessage(), result.getSuccessCount(), result.getFailureCount());
|
||||
// // 使用新方法确保类型正确
|
||||
// return ResponseVO.<ImportResult>fail(errorMessage, result);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @ApiOperation("下载导入错误报告")
|
||||
// @GetMapping("/download-import-errors")
|
||||
// public ResponseEntity<byte[]> downloadImportErrors(@RequestParam String errorData) {
|
||||
// try {
|
||||
// // 解码Base64字符串
|
||||
// byte[] data = Base64.getDecoder().decode(errorData);
|
||||
// return ResponseEntity.ok().header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"import_errors.xlsx\"").contentType(MediaType.APPLICATION_OCTET_STREAM).body(data);
|
||||
// } catch (Exception e) {
|
||||
// log.error("下载错误报告失败", e);
|
||||
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
Reference in New Issue
Block a user