Explorar o código

属性获取接口

learshaw hai 4 meses
pai
achega
7c6f606247

+ 3 - 57
ems/ems-cloud/ems-server/src/main/java/com/ruoyi/ems/controller/EmsObjAttrController.java

@@ -1,26 +1,15 @@
 package com.ruoyi.ems.controller;
 
-import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
 import com.huashe.common.domain.AjaxResult;
 import com.ruoyi.common.core.web.controller.BaseController;
 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.EmsDeviceComponent;
-import com.ruoyi.ems.domain.EmsFacs;
 import com.ruoyi.ems.domain.EmsObjAttr;
-import com.ruoyi.ems.domain.EmsObjAttrValue;
-import com.ruoyi.ems.enums.DevObjType;
-import com.ruoyi.ems.service.IEmsDeviceComponentService;
-import com.ruoyi.ems.service.IEmsDeviceService;
-import com.ruoyi.ems.service.IEmsFacsService;
+import com.ruoyi.ems.domain.EmsObjAttrDto;
 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;
@@ -32,7 +21,6 @@ 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.List;
 
 /**
@@ -48,18 +36,6 @@ public class EmsObjAttrController extends BaseController {
     @Autowired
     private IEmsObjAttrService attrService;
 
-    @Autowired
-    private IEmsObjAttrValueService objAttrValueService;
-
-    @Autowired
-    private IEmsDeviceService deviceService;
-
-    @Autowired
-    private IEmsFacsService facsService;
-
-    @Autowired
-    private IEmsDeviceComponentService componentService;
-
     /**
      * 查询能源对象属性列表
      */
@@ -91,20 +67,8 @@ public class EmsObjAttrController extends BaseController {
             json.put("objType", objType);
             json.put("objCode", objCode);
 
-            // 获取对象模型代码
-            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);
-            }
-            else {
-                json.put("attrs", new JSONArray(0));
-                json.put("attrValues", new JSONArray(0));
-            }
+            List<EmsObjAttrDto> attrDtos = attrService.selectObjAttrItem(objType, objCode);
+            json.put("attrs", attrDtos);
 
             result = success(json);
         }
@@ -115,24 +79,6 @@ 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;
-    }
-
     /**
      * 新增能源对象属性
      */

+ 0 - 81
ems/ems-cloud/ems-server/src/main/java/com/ruoyi/ems/controller/EmsObjAttrEnumController.java

@@ -1,81 +0,0 @@
-package com.ruoyi.ems.controller;
-
-import com.huashe.common.domain.AjaxResult;
-import com.ruoyi.common.core.web.controller.BaseController;
-import com.ruoyi.ems.domain.EmsObjAttrEnum;
-import com.ruoyi.ems.service.IEmsObjAttrEnumService;
-import io.swagger.annotations.Api;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.DeleteMapping;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-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.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
-
-import java.util.List;
-
-/**
- * 能源对象属性枚举Controller
- *
- * @author ruoyi
- * @date 2025-02-26
- */
-@RestController
-@RequestMapping("/object/attr/emum")
-@Api(value = "EmsObjAttrEnumController", description = "能源对象属性枚举管理")
-public class EmsObjAttrEnumController extends BaseController {
-    @Autowired
-    private IEmsObjAttrEnumService objAttrEnumService;
-
-    /**
-     * 查询能源对象属性枚举列表
-     */
-    @GetMapping("/list")
-    public AjaxResult list(@RequestParam(name = "modelCode") String modelCode,
-        @RequestParam(name = "attrKey", required = false) String attrKey) {
-        List<EmsObjAttrEnum> list = objAttrEnumService.getObjAttrEnumList(modelCode, attrKey);
-        return success(list);
-    }
-
-    /**
-     * 获取能源对象属性枚举详细信息
-     */
-    @GetMapping
-    public AjaxResult getInfo(@RequestParam(name = "modelCode") String modelCode,
-        @RequestParam(name = "attrKey") String attrKey, @RequestParam(name = "attrValue") String attrValue) {
-        EmsObjAttrEnum ret = objAttrEnumService.getObjAttrEnum(modelCode, attrKey, attrValue);
-        return success(ret);
-    }
-
-    /**
-     * 新增能源对象属性枚举
-     */
-    @PostMapping
-    public AjaxResult add(@RequestBody EmsObjAttrEnum objAttrEnum) {
-        return success(objAttrEnumService.addObjAttrEnum(objAttrEnum));
-    }
-
-    @PostMapping("/batch")
-    public AjaxResult addBatch(@RequestBody List<EmsObjAttrEnum> objAttrEnums) {
-        return success(objAttrEnumService.addObjAttrEnumBatch(objAttrEnums));
-    }
-
-    /**
-     * 删除能源对象属性枚举
-     */
-    @DeleteMapping("/deleteByModelCode")
-    public AjaxResult deleteByModelCode(@RequestParam(name = "modelCode") String modelCode) {
-        return success(objAttrEnumService.deleteByModelCode(modelCode));
-    }
-
-    /**
-     * 删除能源对象属性枚举
-     */
-    @DeleteMapping("/{id}")
-    public AjaxResult deleteById(@PathVariable Long id) {
-        return success(objAttrEnumService.deleteById(id));
-    }
-}

+ 91 - 0
ems/ems-core/src/main/java/com/ruoyi/ems/domain/EmsObjAttrDto.java

@@ -0,0 +1,91 @@
+/*
+ * 文 件 名:  ObjAttrItem
+ * 版    权:  华设设计集团股份有限公司
+ * 描    述:  <描述>
+ * 修 改 人:  lvwenbin
+ * 修改时间:  2025/3/4
+ * 跟踪单号:  <跟踪单号>
+ * 修改单号:  <修改单号>
+ * 修改内容:  <修改内容>
+ */
+package com.ruoyi.ems.domain;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+
+import java.util.Date;
+
+/**
+ * 对象能力属性记录
+ * <功能详细描述>
+ *
+ * @author lvwenbin
+ * @version [版本号, 2025/3/4]
+ * @see [相关类/方法]
+ * @since [产品/模块版本]
+ */
+public class EmsObjAttrDto {
+    private Integer attrType;
+
+    /** 属性标识 */
+    private String attrKey;
+
+    /** 属性名称 */
+    private String attrName;
+
+    /** 属性值 */
+    private String attrValue;
+
+    /** 属性值名称 */
+    private String attrValueName;
+
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date updateTime;
+
+    public Integer getAttrType() {
+        return attrType;
+    }
+
+    public void setAttrType(Integer attrType) {
+        this.attrType = attrType;
+    }
+
+    public String getAttrKey() {
+        return attrKey;
+    }
+
+    public void setAttrKey(String attrKey) {
+        this.attrKey = attrKey;
+    }
+
+    public String getAttrName() {
+        return attrName;
+    }
+
+    public void setAttrName(String attrName) {
+        this.attrName = attrName;
+    }
+
+    public String getAttrValue() {
+        return attrValue;
+    }
+
+    public void setAttrValue(String attrValue) {
+        this.attrValue = attrValue;
+    }
+
+    public String getAttrValueName() {
+        return attrValueName;
+    }
+
+    public void setAttrValueName(String attrValueName) {
+        this.attrValueName = attrValueName;
+    }
+
+    public Date getUpdateTime() {
+        return updateTime;
+    }
+
+    public void setUpdateTime(Date updateTime) {
+        this.updateTime = updateTime;
+    }
+}

+ 12 - 0
ems/ems-core/src/main/java/com/ruoyi/ems/mapper/EmsObjAttrMapper.java

@@ -1,6 +1,7 @@
 package com.ruoyi.ems.mapper;
 
 import com.ruoyi.ems.domain.EmsObjAttr;
+import com.ruoyi.ems.domain.EmsObjAttrDto;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
@@ -37,6 +38,17 @@ public interface EmsObjAttrMapper {
     List<EmsObjAttr> selectByModelCode(@Param("modelCode") String modelCode);
 
     /**
+     * 查询能源对象属性列表
+     *
+     * @param modelCode 设备模型代码
+     * @param objType   设备类型
+     * @param objCode   设备编码
+     * @return 能源对象属性集合
+     */
+    List<EmsObjAttrDto> selectObjAttrDto(@Param("modelCode") String modelCode, @Param("objType") Integer objType,
+        @Param("objCode") String objCode);
+
+    /**
      * 新增能源对象属性
      *
      * @param objAttr 能源对象属性

+ 0 - 23
ems/ems-core/src/main/java/com/ruoyi/ems/model/ObjAttrItem.java

@@ -1,23 +0,0 @@
-/*
- * 文 件 名:  ObjAttrItem
- * 版    权:  华设设计集团股份有限公司
- * 描    述:  <描述>
- * 修 改 人:  lvwenbin
- * 修改时间:  2025/3/4
- * 跟踪单号:  <跟踪单号>
- * 修改单号:  <修改单号>
- * 修改内容:  <修改内容>
- */
-package com.ruoyi.ems.model;
-
-/**
- * 对象能力属性记录
- * <功能详细描述>
- *
- * @author lvwenbin
- * @version [版本号, 2025/3/4]
- * @see [相关类/方法]
- * @since [产品/模块版本]
- */
-public class ObjAttrItem {
-}

+ 9 - 0
ems/ems-core/src/main/java/com/ruoyi/ems/service/IEmsObjAttrService.java

@@ -1,6 +1,7 @@
 package com.ruoyi.ems.service;
 
 import com.ruoyi.ems.domain.EmsObjAttr;
+import com.ruoyi.ems.domain.EmsObjAttrDto;
 
 import java.util.List;
 
@@ -36,6 +37,14 @@ public interface IEmsObjAttrService {
     List<EmsObjAttr> selectByModelCode(String modelCode);
 
     /**
+     * 查询能源对象属性
+     * @param objType 对象类型
+     * @param objCode 对象编号
+     * @return 能源对象属性集合
+     */
+    List<EmsObjAttrDto> selectObjAttrItem(Integer objType, String objCode);
+
+    /**
      * 新增能源对象属性
      *
      * @param objAttr 能源对象属性

+ 76 - 11
ems/ems-core/src/main/java/com/ruoyi/ems/service/impl/EmsObjAttrServiceImpl.java

@@ -1,8 +1,16 @@
 package com.ruoyi.ems.service.impl;
 
+import com.ruoyi.ems.domain.EmsDevice;
+import com.ruoyi.ems.domain.EmsDeviceComponent;
+import com.ruoyi.ems.domain.EmsFacs;
 import com.ruoyi.ems.domain.EmsObjAttr;
+import com.ruoyi.ems.domain.EmsObjAttrDto;
 import com.ruoyi.ems.domain.EmsObjAttrEnum;
+import com.ruoyi.ems.enums.DevObjType;
 import com.ruoyi.ems.mapper.EmsObjAttrMapper;
+import com.ruoyi.ems.service.IEmsDeviceComponentService;
+import com.ruoyi.ems.service.IEmsDeviceService;
+import com.ruoyi.ems.service.IEmsFacsService;
 import com.ruoyi.ems.service.IEmsObjAttrEnumService;
 import com.ruoyi.ems.service.IEmsObjAttrService;
 import org.apache.commons.collections4.CollectionUtils;
@@ -10,6 +18,7 @@ import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -27,7 +36,13 @@ public class EmsObjAttrServiceImpl implements IEmsObjAttrService {
     private IEmsObjAttrEnumService enumService;
 
     @Autowired
-    private IEmsObjAttrEnumService valueEnumService;
+    private IEmsDeviceService deviceService;
+
+    @Autowired
+    private IEmsFacsService facsService;
+
+    @Autowired
+    private IEmsDeviceComponentService componentService;
 
     /**
      * 查询能源对象属性
@@ -81,6 +96,23 @@ public class EmsObjAttrServiceImpl implements IEmsObjAttrService {
         return list;
     }
 
+    @Override
+    public List<EmsObjAttrDto> selectObjAttrItem(Integer objType, String objCode) {
+        List<EmsObjAttrDto> retList = null;
+
+        // 获取对象模型代码
+        String modeCode = getModeCode(objType, objCode);
+
+        if (StringUtils.isNotEmpty(modeCode)) {
+            retList = objAttrMapper.selectObjAttrDto(modeCode, objType, objCode);
+        }
+        else {
+            retList = new ArrayList<>();
+        }
+
+        return retList;
+    }
+
     /**
      * 新增能源对象属性
      *
@@ -90,21 +122,24 @@ public class EmsObjAttrServiceImpl implements IEmsObjAttrService {
     @Override
     public int insertObjAttr(EmsObjAttr objAttr) {
         int cnt = objAttrMapper.insertObjAttr(objAttr);
-
-        if (StringUtils.equals(objAttr.getAttrValueType(), "Enum")) {
-            valueEnumService.deleteByModelCode(objAttr.getModelCode());
-
-            if (CollectionUtils.isNotEmpty(objAttr.getValueEnums())) {
-                valueEnumService.addObjAttrEnumBatch(objAttr.getValueEnums());
-            }
-        }
+        mergeAttrEnum(objAttr);
 
         return cnt;
     }
 
     @Override
     public int insertBatch(List<EmsObjAttr> list) {
-        return objAttrMapper.insertBatch(list);
+        int cnt = 0;
+
+        if (CollectionUtils.isNotEmpty(list)) {
+            cnt = objAttrMapper.insertBatch(list);
+
+            for (EmsObjAttr objAttr : list) {
+                mergeAttrEnum(objAttr);
+            }
+        }
+
+        return cnt;
     }
 
     /**
@@ -115,7 +150,9 @@ public class EmsObjAttrServiceImpl implements IEmsObjAttrService {
      */
     @Override
     public int updateObjAttr(EmsObjAttr objAttr) {
-        return objAttrMapper.updateObjAttr(objAttr);
+        int cnt = objAttrMapper.updateObjAttr(objAttr);
+        mergeAttrEnum(objAttr);
+        return cnt;
     }
 
     /**
@@ -162,4 +199,32 @@ public class EmsObjAttrServiceImpl implements IEmsObjAttrService {
         enumService.deleteByModelCode(modelCode);
         return cnt;
     }
+
+    private void mergeAttrEnum(EmsObjAttr objAttr) {
+        if (StringUtils.equals(objAttr.getAttrValueType(), "Enum")) {
+            enumService.deleteByModelCode(objAttr.getModelCode());
+
+            if (CollectionUtils.isNotEmpty(objAttr.getValueEnums())) {
+                enumService.addObjAttrEnumBatch(objAttr.getValueEnums());
+            }
+        }
+    }
+
+    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;
+    }
 }

+ 27 - 0
ems/ems-core/src/main/resources/mapper/ems/EmsObjAttrMapper.xml

@@ -14,6 +14,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="attrValueType"    column="attr_value_type"    />
     </resultMap>
 
+    <resultMap type="com.ruoyi.ems.domain.EmsObjAttrDto" id="ObjAttrDtoResult">
+        <result property="attrType"    column="attr_type"    />
+        <result property="attrKey"    column="attr_key"    />
+        <result property="attrName"    column="attr_name"    />
+        <result property="attrValue"    column="attr_value"    />
+        <result property="attrValueName"    column="attr_value_name"    />
+        <result property="updateTime"    column="update_time"    />
+    </resultMap>
+
     <sql id="selectAdmEmsObjAttrVo">
         select id, model_code, attr_type, attr_key, attr_name, attr_unit, attr_value_type from adm_ems_obj_attr
     </sql>
@@ -31,6 +40,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <select id="selectByModelCode" parameterType="java.lang.String" resultMap="ObjAttrResult">
         <include refid="selectAdmEmsObjAttrVo"/>
         where model_code = #{modelCode}
+        order by attr_type, attr_name
+    </select>
+
+    <select id="selectObjAttrDto"  resultMap="ObjAttrDtoResult">
+        select
+            a.attr_key, a.attr_name,v.attr_value, e.attr_value_name, a.attr_type, v.update_time from  adm_ems_obj_attr a
+        left join
+            (
+               select
+                 attr_key, attr_value, update_time
+               from adm_ems_obj_attr_value
+               where model_code = #{modelCode} and obj_type = #{objType} and obj_code = #{objCode}
+            ) v on a.attr_key = v.attr_key
+        left join
+            adm_ems_obj_attr_enum e
+           on a.model_code = e.model_code and a.attr_key = e.attr_key and v.attr_value = e.attr_value
+        WHERE a.model_code = #{modelCode}
+        order by attr_type, attr_name
     </select>
     
     <select id="selectObjAttrById" parameterType="Long" resultMap="ObjAttrResult">