Procházet zdrojové kódy

修改数据组删除编辑的限制

zhoupeng před 2 roky
rodič
revize
710e594ce4

+ 3 - 1
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/dao/DataModelDao.java

@@ -2,10 +2,12 @@ package com.example.opc_da.dao;
 
 import com.example.opc_common.entity.DataModel;
 import com.example.opc_common.entity.Item;
+import com.example.opc_common.entity.ItemGroup;
 import com.example.opc_common.entity.TableDataDto;
 import org.springframework.stereotype.Repository;
 
 import java.util.List;
+import java.util.Map;
 
 @Repository
 public interface DataModelDao {
@@ -24,5 +26,5 @@ public interface DataModelDao {
 
     List<DataModel> getDmListByItemList(List<Item> itemList);
 
-    List<Item> getItemByDaModel(Integer id);
+    List<Map<String,Object>> getItemGroupByDm(Integer id);
 }

+ 6 - 4
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/service/impl/DataModelServiceImpl.java

@@ -3,6 +3,7 @@ package com.example.opc_da.service.impl;
 import com.alibaba.fastjson.JSONObject;
 import com.example.opc_common.entity.DataModel;
 import com.example.opc_common.entity.Item;
+import com.example.opc_common.entity.ItemGroup;
 import com.example.opc_common.enums.ResultEnum;
 import com.example.opc_common.util.Blank;
 import com.example.opc_common.util.MathUtil;
@@ -16,6 +17,7 @@ import org.springframework.transaction.annotation.Transactional;
 import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.util.List;
+import java.util.Map;
 
 @Service
 @Transactional
@@ -64,14 +66,14 @@ public class DataModelServiceImpl implements DataModelService {
 
     @Override
     public Result delDataModelById(Integer id) {
-        List<Item> itemList = dataModelDao.getItemByDaModel(id);
-        if (Blank.isNotEmpty(itemList)) {
+        List<Map<String, Object>> mapList = dataModelDao.getItemGroupByDm(id);
+        if (Blank.isNotEmpty(mapList)) {
             String message = "此数据模型已被配置在【";
-            for (int i = 0; i < itemList.size(); i++) {
+            for (int i = 0; i < mapList.size(); i++) {
                 if (i != 0) {
                     message += ",";
                 }
-                message += "组"+itemList.get(i).getItemGroupName() + "的标签" + itemList.get(i).getItemName();
+                message += "组" + mapList.get(i).get("item_group_name") + "-" + mapList.get(i).get("count") + "个标签";
             }
             message += "】中,无法直接删除";
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), message);

+ 11 - 1
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/service/impl/ItemGroupServiceImpl.java

@@ -335,7 +335,12 @@ public class ItemGroupServiceImpl implements ItemGroupService {
     }
 
     @Override
-    public Result updateItem(Item item) {
+    public synchronized Result updateItem(Item item) {
+        Item item1 = itemGroupDao.getItemById(item.getId());
+        ItemGroup itemGroup = itemGroupDao.getItemGroupById(item1.getItemGroupId());
+        if (itemGroup.getRunState() == ConstantStr.START_UP) {
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "此数据组现在处于运行中,不允许删除");
+        }
         if (itemGroupDao.updateItem(item) <= 0) {
             return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "修改item失败");
         }
@@ -365,6 +370,11 @@ public class ItemGroupServiceImpl implements ItemGroupService {
 
     @Override
     public synchronized Result deleteItemByIdList(List<Integer> idList) {
+        Item item = itemGroupDao.getItemById(idList.get(0));
+        ItemGroup itemGroup = itemGroupDao.getItemGroupById(item.getItemGroupId());
+        if (itemGroup.getRunState() == ConstantStr.START_UP) {
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "此数据组现在处于运行中,不允许删除");
+        }
         if (itemGroupDao.deleteItemByIdList(idList) <= 0) {
             return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), ResultEnum.SERVER_ERROR.getRespMsg());
         }

+ 12 - 16
chaunyi_opc/opc_da/src/main/resources/mapper/DataModelDao.xml

@@ -69,22 +69,18 @@
         </foreach>
     </select>
 
-    <select id="getItemByDaModel" resultType="com.example.opc_common.entity.Item">
-        select ti.id
-             , ti.item_group_id
-             , ti.item_name
-             , ti.item_read_name
-             , ti.node_index
-             , ti.data_type
-             , ti.`describe`
-             , ti.data_model_id
-             , ti.event_mode
-             , ti.event_value
-             , ti.table_report_id
-             , tig.group_name as item_group_name
-        from t_item ti
-                 left join t_item_group tig on ti.item_group_id = tig.id
-        where data_model_id = #{id}
+    <select id="getItemGroupByDm" resultType="java.util.Map">
+        SELECT ti.item_group_id,
+               tig.group_name AS item_group_name,
+               count(ti.id) AS count
+        FROM
+            t_item ti
+            LEFT JOIN t_item_group tig
+        ON ti.item_group_id = tig.id
+        WHERE
+            ti.data_model_id = 48
+        GROUP BY
+            ti.item_group_id;
     </select>
 
 </mapper>