|
@@ -3,11 +3,16 @@ package com.zksy.web.controller.base;
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.zksy.base.domain.EquipmentBase;
|
|
import com.zksy.base.domain.EquipmentBase;
|
|
|
|
|
+import com.zksy.base.domain.EquipmentType;
|
|
|
import com.zksy.base.domain.dto.EquipmentBatchCreateDTO;
|
|
import com.zksy.base.domain.dto.EquipmentBatchCreateDTO;
|
|
|
import com.zksy.base.domain.dto.EquipmentBatchCreateResult;
|
|
import com.zksy.base.domain.dto.EquipmentBatchCreateResult;
|
|
|
|
|
+import com.zksy.base.domain.dto.EquipmentExportDTO;
|
|
|
import com.zksy.base.domain.vo.EquipmentBaseVO;
|
|
import com.zksy.base.domain.vo.EquipmentBaseVO;
|
|
|
|
|
+import com.zksy.base.enums.DistrictEnum;
|
|
|
|
|
+import com.zksy.base.perception.service.PerceptionService;
|
|
|
import com.zksy.base.service.EquipmentBaseService;
|
|
import com.zksy.base.service.EquipmentBaseService;
|
|
|
import com.zksy.base.service.EquipmentBatchCreateService;
|
|
import com.zksy.base.service.EquipmentBatchCreateService;
|
|
|
|
|
+import com.zksy.base.service.EquipmentTypeService;
|
|
|
import com.zksy.base.util.EquipmentImportTemplateWriter;
|
|
import com.zksy.base.util.EquipmentImportTemplateWriter;
|
|
|
import com.zksy.common.annotation.Anonymous;
|
|
import com.zksy.common.annotation.Anonymous;
|
|
|
import com.zksy.common.annotation.Log;
|
|
import com.zksy.common.annotation.Log;
|
|
@@ -24,8 +29,13 @@ import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
|
|
+import java.util.Comparator;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
@RestController
|
|
@RestController
|
|
@@ -33,12 +43,21 @@ import java.util.Map;
|
|
|
@Api(tags = "物联感知设备-设备管理")
|
|
@Api(tags = "物联感知设备-设备管理")
|
|
|
public class EquipmentBaseController {
|
|
public class EquipmentBaseController {
|
|
|
|
|
|
|
|
|
|
+ private static final long EXPORT_MAX_ROWS = 100000;
|
|
|
|
|
+ private static final DateTimeFormatter LAST_COMM_TIME_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
+
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private EquipmentBaseService service;
|
|
private EquipmentBaseService service;
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private EquipmentBatchCreateService equipmentBatchCreateService;
|
|
private EquipmentBatchCreateService equipmentBatchCreateService;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private EquipmentTypeService equipmentTypeService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private PerceptionService perceptionService;
|
|
|
|
|
+
|
|
|
@GetMapping
|
|
@GetMapping
|
|
|
@ApiOperation(value = "设备基础信息分页")
|
|
@ApiOperation(value = "设备基础信息分页")
|
|
|
@Anonymous
|
|
@Anonymous
|
|
@@ -103,7 +122,7 @@ public class EquipmentBaseController {
|
|
|
FileUtils.setAttachmentResponseHeader(response, "设备台账导入模板.xlsx");
|
|
FileUtils.setAttachmentResponseHeader(response, "设备台账导入模板.xlsx");
|
|
|
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
response.setCharacterEncoding("utf-8");
|
|
response.setCharacterEncoding("utf-8");
|
|
|
- EquipmentImportTemplateWriter.write(response.getOutputStream());
|
|
|
|
|
|
|
+ EquipmentImportTemplateWriter.write(response.getOutputStream(), equipmentTypeService.listImportableTypeNames());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@PostMapping("/importData")
|
|
@PostMapping("/importData")
|
|
@@ -124,6 +143,60 @@ public class EquipmentBaseController {
|
|
|
return AjaxResult.success(result.getMessage(), result);
|
|
return AjaxResult.success(result.getMessage(), result);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @PostMapping("/export")
|
|
|
|
|
+ @ApiOperation(value = "导出设备台账(列同导入模板,末尾追加最后通讯时间)")
|
|
|
|
|
+ @Log(title = "设备台账导出", businessType = BusinessType.EXPORT)
|
|
|
|
|
+ public void exportEquipment(HttpServletResponse response,
|
|
|
|
|
+ @RequestParam(required = false) String equipmentCode,
|
|
|
|
|
+ @RequestParam(required = false) String equipmentName,
|
|
|
|
|
+ @ApiParam("设备类型ID") @RequestParam(required = false) Integer equipmentTypeId,
|
|
|
|
|
+ @ApiParam("设备根类型ID(菜单 rootTypeId 数据范围过滤)")
|
|
|
|
|
+ @RequestParam(required = false) Integer rootTypeId,
|
|
|
|
|
+ @ApiParam("设备类型ID集合") @RequestParam(required = false) List<Integer> equipmentTypeIds,
|
|
|
|
|
+ @ApiParam("在线状态(0-离线,1-在线)") @RequestParam(required = false) Integer onlineStatus,
|
|
|
|
|
+ @ApiParam("报警状态(0-正常,1-报警)") @RequestParam(required = false) Integer alarmStatus,
|
|
|
|
|
+ @ApiParam("设备编码/名称模糊关键字") @RequestParam(required = false) String keyword) throws Exception {
|
|
|
|
|
+ Page<EquipmentBaseVO> page = service.findByPage(1, EXPORT_MAX_ROWS, equipmentCode, equipmentName,
|
|
|
|
|
+ equipmentTypeId, rootTypeId, equipmentTypeIds, onlineStatus, alarmStatus, null, null, null, keyword);
|
|
|
|
|
+ Map<Integer, Integer> typeRank = new HashMap<>();
|
|
|
|
|
+ List<EquipmentType> orderedTypes = equipmentTypeService.listOrdered();
|
|
|
|
|
+ for (int i = 0; i < orderedTypes.size(); i++) {
|
|
|
|
|
+ EquipmentType type = orderedTypes.get(i);
|
|
|
|
|
+ if (type != null && type.getId() != null) {
|
|
|
|
|
+ typeRank.put(type.getId(), i);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ List<EquipmentBaseVO> sortedRecords = page.getRecords().stream()
|
|
|
|
|
+ .sorted(Comparator
|
|
|
|
|
+ .comparingInt((EquipmentBaseVO vo) -> typeRank.getOrDefault(toInt(vo.getEquipmentTypeId()), Integer.MAX_VALUE))
|
|
|
|
|
+ .thenComparing(vo -> vo.getEquipmentCode() == null ? "" : vo.getEquipmentCode()))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ Map<String, LocalDateTime> lastCommTimes = perceptionService.getLastCommTimes(sortedRecords);
|
|
|
|
|
+ FileUtils.setAttachmentResponseHeader(response, "设备台账.xlsx");
|
|
|
|
|
+ List<EquipmentExportDTO> rows = sortedRecords.stream().map(vo -> {
|
|
|
|
|
+ LocalDateTime lastCommTime = lastCommTimes.get(vo.getEquipmentCode());
|
|
|
|
|
+ String formatted = lastCommTime == null ? "" : lastCommTime.format(LAST_COMM_TIME_FORMAT);
|
|
|
|
|
+ return EquipmentExportDTO.from(vo, districtName(vo.getDistrict()), formatted);
|
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
|
+ new ExcelUtil<>(EquipmentExportDTO.class).exportExcel(response, rows, "设备台账");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String districtName(Integer district) {
|
|
|
|
|
+ String name = DistrictEnum.getDescByCode(district);
|
|
|
|
|
+ return name == null ? "" : name;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Integer toInt(String value) {
|
|
|
|
|
+ if (value == null || value.trim().isEmpty()) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ return Integer.valueOf(value.trim());
|
|
|
|
|
+ } catch (NumberFormatException ignored) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@PostMapping
|
|
@PostMapping
|
|
|
@ApiOperation(value = "新增设备基础信息")
|
|
@ApiOperation(value = "新增设备基础信息")
|
|
|
@Log(title = "新增设备基础信息", businessType = BusinessType.INSERT)
|
|
@Log(title = "新增设备基础信息", businessType = BusinessType.INSERT)
|