|
@@ -1,8 +1,8 @@
|
|
|
package com.ruoyi.ems.controller;
|
|
|
|
|
|
+import com.alibaba.fastjson2.JSONArray;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.huashe.common.domain.AjaxResult;
|
|
|
-import com.huashe.common.exception.Assert;
|
|
|
import com.ruoyi.common.core.web.controller.BaseController;
|
|
|
import com.ruoyi.common.core.web.page.TableDataInfo;
|
|
|
import com.ruoyi.common.log.annotation.Log;
|
|
@@ -20,6 +20,7 @@ import com.ruoyi.ems.service.IEmsObjAttrService;
|
|
|
import com.ruoyi.ems.service.IEmsObjAttrValueService;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
@@ -86,33 +87,24 @@ public class EmsObjAttrController extends BaseController {
|
|
|
AjaxResult result = null;
|
|
|
|
|
|
try {
|
|
|
- String modeCode = null;
|
|
|
-
|
|
|
- if (objType == DevObjType.FACS.getCode()) {
|
|
|
- EmsFacs facs = facsService.selectEmsFacsByCode(objCode);
|
|
|
- Assert.notNull(facs, -1, "能源设施不存在");
|
|
|
- modeCode = facs.getFacsModel();
|
|
|
- }
|
|
|
- else if (objType == DevObjType.DEVC.getCode()) {
|
|
|
- EmsDevice device = deviceService.selectByCode(objCode);
|
|
|
- Assert.notNull(device, -1, "能源设备不存在");
|
|
|
- modeCode = device.getDeviceModel();
|
|
|
- }
|
|
|
- else if (objType == DevObjType.COMPONENT.getCode()) {
|
|
|
- EmsDeviceComponent devCompo = componentService.selectByCode(objCode);
|
|
|
- Assert.notNull(devCompo, -1, "设备部件不存在");
|
|
|
- modeCode = devCompo.getCompoModel();
|
|
|
- }
|
|
|
-
|
|
|
JSONObject json = new JSONObject();
|
|
|
json.put("objType", objType);
|
|
|
json.put("objCode", objCode);
|
|
|
|
|
|
- List<EmsObjAttr> modelAttrs = attrService.selectByModelCode(modeCode);
|
|
|
- json.put("attrs", CollectionUtils.isNotEmpty(modelAttrs) ? modelAttrs : new ArrayList<>());
|
|
|
+ // 获取对象模型代码
|
|
|
+ String modeCode = getModeCode(objType, objCode);
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(modeCode)) {
|
|
|
+ List<EmsObjAttr> modelAttrs = attrService.selectByModelCode(modeCode);
|
|
|
+ json.put("attrs", CollectionUtils.isNotEmpty(modelAttrs) ? modelAttrs : new ArrayList<>());
|
|
|
|
|
|
- List<EmsObjAttrValue> attrValues = objAttrValueService.selectByObjCode(objType, objCode);
|
|
|
- json.put("attrValues", attrValues);
|
|
|
+ List<EmsObjAttrValue> attrValues = objAttrValueService.selectByObjCode(objType, objCode);
|
|
|
+ json.put("attrValues", attrValues);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ json.put("attrs", new JSONArray(0));
|
|
|
+ json.put("attrValues", new JSONArray(0));
|
|
|
+ }
|
|
|
|
|
|
result = success(json);
|
|
|
}
|
|
@@ -123,6 +115,24 @@ public class EmsObjAttrController extends BaseController {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ private String getModeCode(Integer objType, String objCode) {
|
|
|
+ String modeCode = null;
|
|
|
+
|
|
|
+ if (objType == DevObjType.FACS.getCode()) {
|
|
|
+ EmsFacs facs = facsService.selectEmsFacsByCode(objCode);
|
|
|
+ modeCode = null != facs ? facs.getFacsModel() : null;
|
|
|
+ }
|
|
|
+ else if (objType == DevObjType.DEVC.getCode()) {
|
|
|
+ EmsDevice device = deviceService.selectByCode(objCode);
|
|
|
+ modeCode = null != device ? device.getDeviceModel() : null;
|
|
|
+ }
|
|
|
+ else if (objType == DevObjType.COMPONENT.getCode()) {
|
|
|
+ EmsDeviceComponent devCompo = componentService.selectByCode(objCode);
|
|
|
+ modeCode = null != devCompo ? devCompo.getCompoModel() : null;
|
|
|
+ }
|
|
|
+ return modeCode;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 新增能源对象属性
|
|
|
*/
|