|
|
@@ -1,15 +1,13 @@
|
|
|
package com.ruoyi.project.ps.inspection.controller;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.ruoyi.framework.web.controller.BaseController;
|
|
|
import com.ruoyi.framework.web.domain.AjaxResult;
|
|
|
import com.ruoyi.framework.web.page.TableDataInfo;
|
|
|
import com.ruoyi.project.ps.inspection.domain.*;
|
|
|
import com.ruoyi.project.ps.inspection.dto.InspectionQueryRequest;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
@@ -21,7 +19,7 @@ import java.util.Map;
|
|
|
* @date 2025-01-XX
|
|
|
*/
|
|
|
@RestController
|
|
|
-@RequestMapping("/app/ps/inspection")
|
|
|
+@RequestMapping("/ps/dev")
|
|
|
public class TPsInspectionAppController extends BaseController {
|
|
|
|
|
|
// 注入各个Controller
|
|
|
@@ -68,14 +66,14 @@ public class TPsInspectionAppController extends BaseController {
|
|
|
* @param request 查询请求参数
|
|
|
* @return 查询结果
|
|
|
*/
|
|
|
- @PostMapping("/list")
|
|
|
- public AjaxResult list(@RequestBody InspectionQueryRequest request) {
|
|
|
+ @GetMapping("/list")
|
|
|
+ public AjaxResult list(InspectionQueryRequest request) {
|
|
|
if (request.getType() == null || request.getType().isEmpty()) {
|
|
|
return AjaxResult.error("巡检记录类型不能为空");
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- TableDataInfo dataTable = queryByType(request);
|
|
|
+ TableDataInfo dataTable = queryByType(request.getType(), JSON.toJSONString(request));
|
|
|
return AjaxResult.success(dataTable);
|
|
|
} catch (Exception e) {
|
|
|
logger.error("查询巡检记录失败", e);
|
|
|
@@ -89,7 +87,7 @@ public class TPsInspectionAppController extends BaseController {
|
|
|
* @param request 修改请求参数(包含type和具体的数据对象)
|
|
|
* @return 修改结果
|
|
|
*/
|
|
|
- @PostMapping("/update")
|
|
|
+ @PutMapping("/update")
|
|
|
public AjaxResult update(@RequestBody Map<String, Object> request) {
|
|
|
String type = (String) request.get("type");
|
|
|
if (type == null || type.isEmpty()) {
|
|
|
@@ -107,98 +105,80 @@ public class TPsInspectionAppController extends BaseController {
|
|
|
/**
|
|
|
* 根据类型查询数据,调用对应Controller的list方法
|
|
|
*/
|
|
|
- private TableDataInfo queryByType(InspectionQueryRequest request) {
|
|
|
- String type = request.getType().toLowerCase();
|
|
|
+ private TableDataInfo queryByType(String type, String dataJson) {
|
|
|
+ type = type.toLowerCase();
|
|
|
|
|
|
switch (type) {
|
|
|
case "alarm":
|
|
|
- TPsInspectionAlarm alarm = new TPsInspectionAlarm();
|
|
|
- copyCommonFields(request, alarm);
|
|
|
+ TPsInspectionAlarm alarm = (TPsInspectionAlarm) setFilterFields(dataJson, TPsInspectionAlarm.class);
|
|
|
return alarmController.list(alarm);
|
|
|
|
|
|
case "extinguisher":
|
|
|
- TPsInspectionExtinguisher extinguisher = new TPsInspectionExtinguisher();
|
|
|
- copyCommonFields(request, extinguisher);
|
|
|
+ TPsInspectionExtinguisher extinguisher = (TPsInspectionExtinguisher) setFilterFields(dataJson, TPsInspectionExtinguisher.class);
|
|
|
return extinguisherController.list(extinguisher);
|
|
|
|
|
|
case "hydrant":
|
|
|
- TPsInspectionHydrant hydrant = new TPsInspectionHydrant();
|
|
|
- copyCommonFields(request, hydrant);
|
|
|
+ TPsInspectionHydrant hydrant = (TPsInspectionHydrant) setFilterFields(dataJson, TPsInspectionHydrant.class);
|
|
|
return hydrantController.list(hydrant);
|
|
|
|
|
|
case "firedoor":
|
|
|
- TPsInspectionFiredoor firedoor = new TPsInspectionFiredoor();
|
|
|
- copyCommonFields(request, firedoor);
|
|
|
+ TPsInspectionFiredoor firedoor = (TPsInspectionFiredoor) setFilterFields(dataJson, TPsInspectionFiredoor.class);
|
|
|
return firedoorController.list(firedoor);
|
|
|
|
|
|
case "lift":
|
|
|
- TPsInspectionLift lift = new TPsInspectionLift();
|
|
|
- copyCommonFields(request, lift);
|
|
|
+ TPsInspectionLift lift = (TPsInspectionLift) setFilterFields(dataJson, TPsInspectionLift.class);
|
|
|
return liftController.list(lift);
|
|
|
|
|
|
case "cabinet":
|
|
|
- TPsInspectionCabinet cabinet = new TPsInspectionCabinet();
|
|
|
- copyCommonFields(request, cabinet);
|
|
|
+ TPsInspectionCabinet cabinet = (TPsInspectionCabinet) setFilterFields(dataJson, TPsInspectionCabinet.class);
|
|
|
return cabinetController.list(cabinet);
|
|
|
|
|
|
case "callsystem":
|
|
|
- TPsInspectionCallsystem callsystem = new TPsInspectionCallsystem();
|
|
|
- copyCommonFields(request, callsystem);
|
|
|
+ TPsInspectionCallsystem callsystem = (TPsInspectionCallsystem) setFilterFields(dataJson, TPsInspectionCallsystem.class);
|
|
|
return callsystemController.list(callsystem);
|
|
|
|
|
|
case "fgs":
|
|
|
- TPsInspectionFgs fgs = new TPsInspectionFgs();
|
|
|
- copyCommonFields(request, fgs);
|
|
|
+ TPsInspectionFgs fgs = (TPsInspectionFgs) setFilterFields(dataJson, TPsInspectionFgs.class);
|
|
|
return fgsController.list(fgs);
|
|
|
|
|
|
case "curtain":
|
|
|
- TPsInspectionCurtain curtain = new TPsInspectionCurtain();
|
|
|
- copyCommonFields(request, curtain);
|
|
|
+ TPsInspectionCurtain curtain = (TPsInspectionCurtain) setFilterFields(dataJson, TPsInspectionCurtain.class);
|
|
|
return curtainController.list(curtain);
|
|
|
|
|
|
case "steam":
|
|
|
- TPsInspectionSteam steam = new TPsInspectionSteam();
|
|
|
- copyCommonFields(request, steam);
|
|
|
+ TPsInspectionSteam steam = (TPsInspectionSteam) setFilterFields(dataJson, TPsInspectionSteam.class);
|
|
|
return steamController.list(steam);
|
|
|
|
|
|
case "monitor":
|
|
|
- TPsInspectionMonitor monitor = new TPsInspectionMonitor();
|
|
|
- copyCommonFields(request, monitor);
|
|
|
+ TPsInspectionMonitor monitor = (TPsInspectionMonitor) setFilterFields(dataJson, TPsInspectionMonitor.class);
|
|
|
return monitorController.list(monitor);
|
|
|
|
|
|
case "coffer":
|
|
|
- TPsInspectionCoffer coffer = new TPsInspectionCoffer();
|
|
|
- copyCommonFields(request, coffer);
|
|
|
+ TPsInspectionCoffer coffer = (TPsInspectionCoffer) setFilterFields(dataJson, TPsInspectionCoffer.class);
|
|
|
return cofferController.list(coffer);
|
|
|
|
|
|
case "sump":
|
|
|
- TPsInspectionSump sump = new TPsInspectionSump();
|
|
|
- copyCommonFields(request, sump);
|
|
|
+ TPsInspectionSump sump = (TPsInspectionSump) setFilterFields(dataJson, TPsInspectionSump.class);
|
|
|
return sumpController.list(sump);
|
|
|
|
|
|
case "pit":
|
|
|
- TPsInspectionPit pit = new TPsInspectionPit();
|
|
|
- copyCommonFields(request, pit);
|
|
|
+ TPsInspectionPit pit = (TPsInspectionPit) setFilterFields(dataJson, TPsInspectionPit.class);
|
|
|
return pitController.list(pit);
|
|
|
|
|
|
case "rainvalve":
|
|
|
- TPsInspectionRainvalve rainvalve = new TPsInspectionRainvalve();
|
|
|
- copyCommonFields(request, rainvalve);
|
|
|
+ TPsInspectionRainvalve rainvalve = (TPsInspectionRainvalve) setFilterFields(dataJson, TPsInspectionRainvalve.class);
|
|
|
return rainvalveController.list(rainvalve);
|
|
|
|
|
|
case "ventvalve":
|
|
|
- TPsInspectionVentvalve ventvalve = new TPsInspectionVentvalve();
|
|
|
- copyCommonFields(request, ventvalve);
|
|
|
+ TPsInspectionVentvalve ventvalve = (TPsInspectionVentvalve) setFilterFields(dataJson, TPsInspectionVentvalve.class);
|
|
|
return ventvalveController.list(ventvalve);
|
|
|
|
|
|
case "utilitystation":
|
|
|
- TPsInspectionUtilitystation utilitystation = new TPsInspectionUtilitystation();
|
|
|
- copyCommonFields(request, utilitystation);
|
|
|
+ TPsInspectionUtilitystation utilitystation = (TPsInspectionUtilitystation) setFilterFields(dataJson, TPsInspectionUtilitystation.class);
|
|
|
return utilitystationController.list(utilitystation);
|
|
|
|
|
|
case "eyewash":
|
|
|
- TPsInspectionEyewash eyewash = new TPsInspectionEyewash();
|
|
|
- copyCommonFields(request, eyewash);
|
|
|
+ TPsInspectionEyewash eyewash = (TPsInspectionEyewash) setFilterFields(dataJson, TPsInspectionEyewash.class);
|
|
|
return eyewashController.list(eyewash);
|
|
|
|
|
|
default:
|
|
|
@@ -209,86 +189,87 @@ public class TPsInspectionAppController extends BaseController {
|
|
|
/**
|
|
|
* 根据类型更新数据,调用对应Controller的edit方法
|
|
|
*/
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
private AjaxResult updateByType(String type, Map<String, Object> request) {
|
|
|
type = type.toLowerCase();
|
|
|
- Map<String, Object> data = (Map<String, Object>) request.get("data");
|
|
|
+ Object dataObj = request.get("data");
|
|
|
|
|
|
- if (data == null) {
|
|
|
+ if (dataObj == null) {
|
|
|
throw new IllegalArgumentException("更新数据不能为空");
|
|
|
}
|
|
|
|
|
|
+ String dataJson = JSON.toJSONString(dataObj);
|
|
|
+
|
|
|
switch (type) {
|
|
|
case "alarm":
|
|
|
- TPsInspectionAlarm alarm = convertToAlarm(data);
|
|
|
+ TPsInspectionAlarm alarm = JSON.parseObject(dataJson, TPsInspectionAlarm.class);
|
|
|
return alarmController.edit(alarm);
|
|
|
|
|
|
case "extinguisher":
|
|
|
- TPsInspectionExtinguisher extinguisher = convertToExtinguisher(data);
|
|
|
+ TPsInspectionExtinguisher extinguisher = JSON.parseObject(dataJson, TPsInspectionExtinguisher.class);
|
|
|
return extinguisherController.edit(extinguisher);
|
|
|
|
|
|
case "hydrant":
|
|
|
- TPsInspectionHydrant hydrant = convertToHydrant(data);
|
|
|
+ TPsInspectionHydrant hydrant = JSON.parseObject(dataJson, TPsInspectionHydrant.class);
|
|
|
return hydrantController.edit(hydrant);
|
|
|
|
|
|
case "firedoor":
|
|
|
- TPsInspectionFiredoor firedoor = convertToFiredoor(data);
|
|
|
+ TPsInspectionFiredoor firedoor = JSON.parseObject(dataJson, TPsInspectionFiredoor.class);
|
|
|
return firedoorController.edit(firedoor);
|
|
|
|
|
|
case "lift":
|
|
|
- TPsInspectionLift lift = convertToLift(data);
|
|
|
+ TPsInspectionLift lift = JSON.parseObject(dataJson, TPsInspectionLift.class);
|
|
|
return liftController.edit(lift);
|
|
|
|
|
|
case "cabinet":
|
|
|
- TPsInspectionCabinet cabinet = convertToCabinet(data);
|
|
|
+ TPsInspectionCabinet cabinet = JSON.parseObject(dataJson, TPsInspectionCabinet.class);
|
|
|
return cabinetController.edit(cabinet);
|
|
|
|
|
|
case "callsystem":
|
|
|
- TPsInspectionCallsystem callsystem = convertToCallsystem(data);
|
|
|
+ TPsInspectionCallsystem callsystem = JSON.parseObject(dataJson, TPsInspectionCallsystem.class);
|
|
|
return callsystemController.edit(callsystem);
|
|
|
|
|
|
case "fgs":
|
|
|
- TPsInspectionFgs fgs = convertToFgs(data);
|
|
|
+ TPsInspectionFgs fgs = JSON.parseObject(dataJson, TPsInspectionFgs.class);
|
|
|
return fgsController.edit(fgs);
|
|
|
|
|
|
case "curtain":
|
|
|
- TPsInspectionCurtain curtain = convertToCurtain(data);
|
|
|
+ TPsInspectionCurtain curtain = JSON.parseObject(dataJson, TPsInspectionCurtain.class);
|
|
|
return curtainController.edit(curtain);
|
|
|
|
|
|
case "steam":
|
|
|
- TPsInspectionSteam steam = convertToSteam(data);
|
|
|
+ TPsInspectionSteam steam = JSON.parseObject(dataJson, TPsInspectionSteam.class);
|
|
|
return steamController.edit(steam);
|
|
|
|
|
|
case "monitor":
|
|
|
- TPsInspectionMonitor monitor = convertToMonitor(data);
|
|
|
+ TPsInspectionMonitor monitor = JSON.parseObject(dataJson, TPsInspectionMonitor.class);
|
|
|
return monitorController.edit(monitor);
|
|
|
|
|
|
case "coffer":
|
|
|
- TPsInspectionCoffer coffer = convertToCoffer(data);
|
|
|
+ TPsInspectionCoffer coffer = JSON.parseObject(dataJson, TPsInspectionCoffer.class);
|
|
|
return cofferController.edit(coffer);
|
|
|
|
|
|
case "sump":
|
|
|
- TPsInspectionSump sump = convertToSump(data);
|
|
|
+ TPsInspectionSump sump = JSON.parseObject(dataJson, TPsInspectionSump.class);
|
|
|
return sumpController.edit(sump);
|
|
|
|
|
|
case "pit":
|
|
|
- TPsInspectionPit pit = convertToPit(data);
|
|
|
+ TPsInspectionPit pit = JSON.parseObject(dataJson, TPsInspectionPit.class);
|
|
|
return pitController.edit(pit);
|
|
|
|
|
|
case "rainvalve":
|
|
|
- TPsInspectionRainvalve rainvalve = convertToRainvalve(data);
|
|
|
+ TPsInspectionRainvalve rainvalve = JSON.parseObject(dataJson, TPsInspectionRainvalve.class);
|
|
|
return rainvalveController.edit(rainvalve);
|
|
|
|
|
|
case "ventvalve":
|
|
|
- TPsInspectionVentvalve ventvalve = convertToVentvalve(data);
|
|
|
+ TPsInspectionVentvalve ventvalve = JSON.parseObject(dataJson, TPsInspectionVentvalve.class);
|
|
|
return ventvalveController.edit(ventvalve);
|
|
|
|
|
|
case "utilitystation":
|
|
|
- TPsInspectionUtilitystation utilitystation = convertToUtilitystation(data);
|
|
|
+ TPsInspectionUtilitystation utilitystation = JSON.parseObject(dataJson, TPsInspectionUtilitystation.class);
|
|
|
return utilitystationController.edit(utilitystation);
|
|
|
|
|
|
case "eyewash":
|
|
|
- TPsInspectionEyewash eyewash = convertToEyewash(data);
|
|
|
+ TPsInspectionEyewash eyewash = JSON.parseObject(dataJson, TPsInspectionEyewash.class);
|
|
|
return eyewashController.edit(eyewash);
|
|
|
|
|
|
default:
|
|
|
@@ -297,281 +278,28 @@ public class TPsInspectionAppController extends BaseController {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 复制通用字段到实体对象
|
|
|
+ * 使用 FastJSON 解析 JSON 字符串为对象
|
|
|
*/
|
|
|
- private void copyCommonFields(InspectionQueryRequest request, Object entity) {
|
|
|
- if (request.getId() != null) {
|
|
|
- setFieldValue(entity, "id", request.getId());
|
|
|
- }
|
|
|
- if (request.getDevNo() != null) {
|
|
|
- setFieldValue(entity, "devNo", request.getDevNo());
|
|
|
- }
|
|
|
- if (request.getPosition() != null) {
|
|
|
- setFieldValue(entity, "position", request.getPosition());
|
|
|
- }
|
|
|
- if (request.getMonth() != null) {
|
|
|
- setFieldValue(entity, "month", request.getMonth());
|
|
|
- }
|
|
|
- if (request.getYear() != null) {
|
|
|
- setFieldValue(entity, "year", request.getYear());
|
|
|
- }
|
|
|
- if (request.getPlanId() != null) {
|
|
|
- setFieldValue(entity, "planId", request.getPlanId());
|
|
|
- }
|
|
|
- if (request.getDeptId() != null) {
|
|
|
- setFieldValue(entity, "deptId", request.getDeptId());
|
|
|
- }
|
|
|
- if (request.getCheckStatus() != null) {
|
|
|
- setFieldValue(entity, "checkStatus", request.getCheckStatus());
|
|
|
- }
|
|
|
- if (request.getIssuesStatus() != null) {
|
|
|
- setFieldValue(entity, "issuesStatus", request.getIssuesStatus());
|
|
|
- }
|
|
|
- if (request.getIssuesFlag() != null) {
|
|
|
- setFieldValue(entity, "issuesFlag", request.getIssuesFlag());
|
|
|
+ private Object setFilterFields(String dataJson, Class<?> entityClass) {
|
|
|
+ if (dataJson == null || dataJson.isEmpty()) {
|
|
|
+ try {
|
|
|
+ return entityClass.newInstance();
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("创建对象失败: {}", entityClass.getName(), e);
|
|
|
+ throw new RuntimeException("创建对象失败: " + entityClass.getName(), e);
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 使用反射设置字段值
|
|
|
- */
|
|
|
- private void setFieldValue(Object obj, String fieldName, Object value) {
|
|
|
try {
|
|
|
- java.lang.reflect.Field field = obj.getClass().getDeclaredField(fieldName);
|
|
|
- field.setAccessible(true);
|
|
|
- field.set(obj, value);
|
|
|
+ return JSON.parseObject(dataJson, entityClass);
|
|
|
} catch (Exception e) {
|
|
|
- // 忽略不存在的字段
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 将Map转换为Alarm对象
|
|
|
- */
|
|
|
- private TPsInspectionAlarm convertToAlarm(Map<String, Object> data) {
|
|
|
- TPsInspectionAlarm alarm = new TPsInspectionAlarm();
|
|
|
- convertMapToObject(data, alarm);
|
|
|
- return alarm;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 将Map转换为Extinguisher对象
|
|
|
- */
|
|
|
- private TPsInspectionExtinguisher convertToExtinguisher(Map<String, Object> data) {
|
|
|
- TPsInspectionExtinguisher extinguisher = new TPsInspectionExtinguisher();
|
|
|
- convertMapToObject(data, extinguisher);
|
|
|
- return extinguisher;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 将Map转换为Hydrant对象
|
|
|
- */
|
|
|
- private TPsInspectionHydrant convertToHydrant(Map<String, Object> data) {
|
|
|
- TPsInspectionHydrant hydrant = new TPsInspectionHydrant();
|
|
|
- convertMapToObject(data, hydrant);
|
|
|
- return hydrant;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 将Map转换为Firedoor对象
|
|
|
- */
|
|
|
- private TPsInspectionFiredoor convertToFiredoor(Map<String, Object> data) {
|
|
|
- TPsInspectionFiredoor firedoor = new TPsInspectionFiredoor();
|
|
|
- convertMapToObject(data, firedoor);
|
|
|
- return firedoor;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 将Map转换为Lift对象
|
|
|
- */
|
|
|
- private TPsInspectionLift convertToLift(Map<String, Object> data) {
|
|
|
- TPsInspectionLift lift = new TPsInspectionLift();
|
|
|
- convertMapToObject(data, lift);
|
|
|
- return lift;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 将Map转换为Cabinet对象
|
|
|
- */
|
|
|
- private TPsInspectionCabinet convertToCabinet(Map<String, Object> data) {
|
|
|
- TPsInspectionCabinet cabinet = new TPsInspectionCabinet();
|
|
|
- convertMapToObject(data, cabinet);
|
|
|
- return cabinet;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 将Map转换为Callsystem对象
|
|
|
- */
|
|
|
- private TPsInspectionCallsystem convertToCallsystem(Map<String, Object> data) {
|
|
|
- TPsInspectionCallsystem callsystem = new TPsInspectionCallsystem();
|
|
|
- convertMapToObject(data, callsystem);
|
|
|
- return callsystem;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 将Map转换为Fgs对象
|
|
|
- */
|
|
|
- private TPsInspectionFgs convertToFgs(Map<String, Object> data) {
|
|
|
- TPsInspectionFgs fgs = new TPsInspectionFgs();
|
|
|
- convertMapToObject(data, fgs);
|
|
|
- return fgs;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 将Map转换为Curtain对象
|
|
|
- */
|
|
|
- private TPsInspectionCurtain convertToCurtain(Map<String, Object> data) {
|
|
|
- TPsInspectionCurtain curtain = new TPsInspectionCurtain();
|
|
|
- convertMapToObject(data, curtain);
|
|
|
- return curtain;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 将Map转换为Steam对象
|
|
|
- */
|
|
|
- private TPsInspectionSteam convertToSteam(Map<String, Object> data) {
|
|
|
- TPsInspectionSteam steam = new TPsInspectionSteam();
|
|
|
- convertMapToObject(data, steam);
|
|
|
- return steam;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 将Map转换为Monitor对象
|
|
|
- */
|
|
|
- private TPsInspectionMonitor convertToMonitor(Map<String, Object> data) {
|
|
|
- TPsInspectionMonitor monitor = new TPsInspectionMonitor();
|
|
|
- convertMapToObject(data, monitor);
|
|
|
- return monitor;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 将Map转换为Coffer对象
|
|
|
- */
|
|
|
- private TPsInspectionCoffer convertToCoffer(Map<String, Object> data) {
|
|
|
- TPsInspectionCoffer coffer = new TPsInspectionCoffer();
|
|
|
- convertMapToObject(data, coffer);
|
|
|
- return coffer;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 将Map转换为Sump对象
|
|
|
- */
|
|
|
- private TPsInspectionSump convertToSump(Map<String, Object> data) {
|
|
|
- TPsInspectionSump sump = new TPsInspectionSump();
|
|
|
- convertMapToObject(data, sump);
|
|
|
- return sump;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 将Map转换为Pit对象
|
|
|
- */
|
|
|
- private TPsInspectionPit convertToPit(Map<String, Object> data) {
|
|
|
- TPsInspectionPit pit = new TPsInspectionPit();
|
|
|
- convertMapToObject(data, pit);
|
|
|
- return pit;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 将Map转换为Rainvalve对象
|
|
|
- */
|
|
|
- private TPsInspectionRainvalve convertToRainvalve(Map<String, Object> data) {
|
|
|
- TPsInspectionRainvalve rainvalve = new TPsInspectionRainvalve();
|
|
|
- convertMapToObject(data, rainvalve);
|
|
|
- return rainvalve;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 将Map转换为Ventvalve对象
|
|
|
- */
|
|
|
- private TPsInspectionVentvalve convertToVentvalve(Map<String, Object> data) {
|
|
|
- TPsInspectionVentvalve ventvalve = new TPsInspectionVentvalve();
|
|
|
- convertMapToObject(data, ventvalve);
|
|
|
- return ventvalve;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 将Map转换为Utilitystation对象
|
|
|
- */
|
|
|
- private TPsInspectionUtilitystation convertToUtilitystation(Map<String, Object> data) {
|
|
|
- TPsInspectionUtilitystation utilitystation = new TPsInspectionUtilitystation();
|
|
|
- convertMapToObject(data, utilitystation);
|
|
|
- return utilitystation;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 将Map转换为Eyewash对象
|
|
|
- */
|
|
|
- private TPsInspectionEyewash convertToEyewash(Map<String, Object> data) {
|
|
|
- TPsInspectionEyewash eyewash = new TPsInspectionEyewash();
|
|
|
- convertMapToObject(data, eyewash);
|
|
|
- return eyewash;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 将Map转换为对象(使用反射)
|
|
|
- */
|
|
|
- private void convertMapToObject(Map<String, Object> map, Object obj) {
|
|
|
- for (Map.Entry<String, Object> entry : map.entrySet()) {
|
|
|
- String key = entry.getKey();
|
|
|
- Object value = entry.getValue();
|
|
|
-
|
|
|
- // 将下划线命名转换为驼峰命名
|
|
|
- String fieldName = toCamelCase(key);
|
|
|
-
|
|
|
+ logger.warn("解析JSON失败: {}", e.getMessage());
|
|
|
try {
|
|
|
- java.lang.reflect.Field field = obj.getClass().getDeclaredField(fieldName);
|
|
|
- field.setAccessible(true);
|
|
|
-
|
|
|
- // 类型转换
|
|
|
- if (value != null) {
|
|
|
- Class<?> fieldType = field.getType();
|
|
|
- if (fieldType == Long.class || fieldType == long.class) {
|
|
|
- if (value instanceof Number) {
|
|
|
- field.set(obj, ((Number) value).longValue());
|
|
|
- } else if (value instanceof String) {
|
|
|
- field.set(obj, Long.parseLong((String) value));
|
|
|
- }
|
|
|
- } else if (fieldType == Integer.class || fieldType == int.class) {
|
|
|
- if (value instanceof Number) {
|
|
|
- field.set(obj, ((Number) value).intValue());
|
|
|
- } else if (value instanceof String) {
|
|
|
- field.set(obj, Integer.parseInt((String) value));
|
|
|
- }
|
|
|
- } else if (fieldType == String.class) {
|
|
|
- field.set(obj, value.toString());
|
|
|
- } else {
|
|
|
- field.set(obj, value);
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- // 忽略不存在的字段
|
|
|
+ return entityClass.newInstance();
|
|
|
+ } catch (Exception ex) {
|
|
|
+ throw new RuntimeException("创建对象失败: " + entityClass.getName(), ex);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 下划线命名转驼峰命名
|
|
|
- */
|
|
|
- private String toCamelCase(String str) {
|
|
|
- if (str == null || str.isEmpty()) {
|
|
|
- return str;
|
|
|
- }
|
|
|
- StringBuilder result = new StringBuilder();
|
|
|
- boolean nextUpperCase = false;
|
|
|
- for (int i = 0; i < str.length(); i++) {
|
|
|
- char c = str.charAt(i);
|
|
|
- if (c == '_') {
|
|
|
- nextUpperCase = true;
|
|
|
- } else {
|
|
|
- if (nextUpperCase) {
|
|
|
- result.append(Character.toUpperCase(c));
|
|
|
- nextUpperCase = false;
|
|
|
- } else {
|
|
|
- result.append(c);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return result.toString();
|
|
|
- }
|
|
|
}
|
|
|
|