|
@@ -1,13 +1,23 @@
|
|
|
package com.ruoyi.ems.controller;
|
|
|
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.ruoyi.common.core.web.controller.BaseController;
|
|
|
import com.ruoyi.common.core.web.domain.AjaxResult;
|
|
|
import com.ruoyi.common.core.web.page.TableDataInfo;
|
|
|
import com.ruoyi.common.log.annotation.Log;
|
|
|
import com.ruoyi.common.log.enums.BusinessType;
|
|
|
+import com.ruoyi.ems.domain.EmsDevice;
|
|
|
+import com.ruoyi.ems.domain.EmsFacs;
|
|
|
import com.ruoyi.ems.domain.EmsObjAttr;
|
|
|
+import com.ruoyi.ems.domain.EmsObjAttrValue;
|
|
|
+import com.ruoyi.ems.domain.common.ObjType;
|
|
|
+import com.ruoyi.ems.service.IEmsDeviceService;
|
|
|
+import com.ruoyi.ems.service.IEmsFacsService;
|
|
|
import com.ruoyi.ems.service.IEmsObjAttrService;
|
|
|
+import com.ruoyi.ems.service.IEmsObjAttrValueService;
|
|
|
+import com.ruoyi.ems.util.exception.Assert;
|
|
|
import io.swagger.annotations.Api;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
@@ -16,30 +26,42 @@ import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.PutMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 能源对象属性Controller
|
|
|
- *
|
|
|
+ *
|
|
|
* @author ruoyi
|
|
|
* @date 2024-09-23
|
|
|
*/
|
|
|
@RestController
|
|
|
@RequestMapping("/object/attr")
|
|
|
@Api(value = "EmsObjAttrController", description = "能源对象属性管理")
|
|
|
-public class EmsObjAttrController extends BaseController
|
|
|
-{
|
|
|
+public class EmsObjAttrController extends BaseController {
|
|
|
@Autowired
|
|
|
private IEmsObjAttrService attrService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IEmsObjAttrValueService objAttrValueService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IEmsDeviceService deviceService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IEmsFacsService emsFacsService;
|
|
|
+
|
|
|
/**
|
|
|
* 查询能源对象属性列表
|
|
|
*/
|
|
|
@GetMapping("/list")
|
|
|
- public TableDataInfo list(EmsObjAttr objAttr)
|
|
|
- {
|
|
|
+ public TableDataInfo list(EmsObjAttr objAttr) {
|
|
|
startPage();
|
|
|
List<EmsObjAttr> list = attrService.selectObjAttrList(objAttr);
|
|
|
return getDataTable(list);
|
|
@@ -49,18 +71,57 @@ public class EmsObjAttrController extends BaseController
|
|
|
* 获取能源对象属性详细信息
|
|
|
*/
|
|
|
@GetMapping(value = "/{id}")
|
|
|
- public AjaxResult getInfo(@PathVariable("id") Long id)
|
|
|
- {
|
|
|
+ public AjaxResult getInfo(@PathVariable("id") Long id) {
|
|
|
return success(attrService.selectObjAttrById(id));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 查询能源对象属性值列表
|
|
|
+ */
|
|
|
+ @GetMapping("/getObjAttr")
|
|
|
+ public AjaxResult list(@RequestParam(name = "objType") Integer objType,
|
|
|
+ @RequestParam(name = "objCode") String objCode) {
|
|
|
+ AjaxResult result = null;
|
|
|
+
|
|
|
+ try {
|
|
|
+ String modeCode = null;
|
|
|
+
|
|
|
+ if (objType == ObjType.FACS.getCode()) {
|
|
|
+ EmsFacs facs = emsFacsService.selectEmsFacsByCode(objCode);
|
|
|
+ Assert.notNull(facs, -1, "能源对象不存在");
|
|
|
+ modeCode = facs.getFacsModel();
|
|
|
+ }
|
|
|
+ else if (objType == ObjType.DEVC.getCode()) {
|
|
|
+ EmsDevice device = deviceService.selectByCode(objCode);
|
|
|
+ Assert.notNull(device, -1, "能源对象不存在");
|
|
|
+ modeCode = device.getDeviceModel();
|
|
|
+ }
|
|
|
+
|
|
|
+ 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<>());
|
|
|
+
|
|
|
+ List<EmsObjAttrValue> attrValues = objAttrValueService.selectByObjCode(objType, objCode);
|
|
|
+ json.put("attrValues", attrValues);
|
|
|
+
|
|
|
+ result = success(json);
|
|
|
+ }
|
|
|
+ catch (Exception e) {
|
|
|
+ result = error(e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 新增能源对象属性
|
|
|
*/
|
|
|
@Log(title = "能源对象属性", businessType = BusinessType.INSERT)
|
|
|
@PostMapping
|
|
|
- public AjaxResult add(@RequestBody EmsObjAttr objAttr)
|
|
|
- {
|
|
|
+ public AjaxResult add(@RequestBody EmsObjAttr objAttr) {
|
|
|
return toAjax(attrService.insertObjAttr(objAttr));
|
|
|
}
|
|
|
|
|
@@ -69,8 +130,7 @@ public class EmsObjAttrController extends BaseController
|
|
|
*/
|
|
|
@Log(title = "能源对象属性", businessType = BusinessType.INSERT)
|
|
|
@PostMapping("/batch")
|
|
|
- public AjaxResult addBatch(@RequestBody List<EmsObjAttr> list)
|
|
|
- {
|
|
|
+ public AjaxResult addBatch(@RequestBody List<EmsObjAttr> list) {
|
|
|
return toAjax(attrService.insertBatch(list));
|
|
|
}
|
|
|
|
|
@@ -79,8 +139,7 @@ public class EmsObjAttrController extends BaseController
|
|
|
*/
|
|
|
@Log(title = "能源对象属性", businessType = BusinessType.UPDATE)
|
|
|
@PutMapping
|
|
|
- public AjaxResult edit(@RequestBody EmsObjAttr objAttr)
|
|
|
- {
|
|
|
+ public AjaxResult edit(@RequestBody EmsObjAttr objAttr) {
|
|
|
return toAjax(attrService.updateObjAttr(objAttr));
|
|
|
}
|
|
|
|
|
@@ -88,9 +147,8 @@ public class EmsObjAttrController extends BaseController
|
|
|
* 删除能源对象属性
|
|
|
*/
|
|
|
@Log(title = "能源对象属性", businessType = BusinessType.DELETE)
|
|
|
- @DeleteMapping("/{ids}")
|
|
|
- public AjaxResult remove(@PathVariable Long[] ids)
|
|
|
- {
|
|
|
+ @DeleteMapping("/{ids}")
|
|
|
+ public AjaxResult remove(@PathVariable Long[] ids) {
|
|
|
return toAjax(attrService.deleteObjAttrByIds(ids));
|
|
|
}
|
|
|
}
|