Parcourir la source

base表增删改——base_hy表增删改

LLL il y a 8 mois
Parent
commit
d20ab6d9fd

+ 13 - 0
jeecg-module-interlock/src/main/java/org/jeecg/modules/base/convert/InterlockBaseConvert.java

@@ -1,6 +1,7 @@
 package org.jeecg.modules.base.convert;
 
 import org.jeecg.modules.base.entity.InterlockBase;
+import org.jeecg.modules.base.entity.InterlockBaseHy;
 import org.jeecg.modules.base.vo.InterlockBaseTreeVO;
 import org.mapstruct.Mapper;
 import org.mapstruct.Mapping;
@@ -38,4 +39,16 @@ public interface InterlockBaseConvert {
     @Mapping(target ="children",source ="children")
     InterlockBaseTreeVO convertToInterlockBaseTreeVO2(InterlockBase interlockBase, List<InterlockBaseTreeVO> children);
 
+
+    @Mapping(target = "interlockSystemId", source ="interlockSystemId")
+    @Mapping(target = "interlockStatus", source ="interlockStatus")
+    @Mapping(target = "interlockStatusName", source ="interlockStatusName")
+    @Mapping(target = "bypass", source ="bypass")
+    @Mapping(target = "bypassName", source ="bypassName")
+    @Mapping(target = "instrumentStatus", source ="instrumentStatus")
+    @Mapping(target = "instrumentStatusName", source ="instrumentStatusName")
+    @Mapping(target = "controlSystemStatus", source ="controlSystemStatus")
+    @Mapping(target = "controlSystemStatusName", source ="controlSystemStatusName")
+    InterlockBaseHy toInterlockBaseHy(String interlockSystemId, String interlockStatus, String interlockStatusName, String bypass, String bypassName, String instrumentStatus, String instrumentStatusName, String controlSystemStatus, String controlSystemStatusName);
+
 }

+ 74 - 0
jeecg-module-interlock/src/main/java/org/jeecg/modules/base/service/impl/InterlockBaseServiceImpl.java

@@ -4,9 +4,14 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import org.jeecg.common.exception.JeecgBootException;
 import org.jeecg.common.util.oConvertUtils;
 import org.jeecg.common.system.vo.SelectTreeModel;
+import org.jeecg.modules.base.convert.InterlockBaseConvert;
 import org.jeecg.modules.base.entity.InterlockBase;
+import org.jeecg.modules.base.entity.InterlockBaseHy;
+import org.jeecg.modules.base.mapper.InterlockBaseHyMapper;
 import org.jeecg.modules.base.mapper.InterlockBaseMapper;
+import org.jeecg.modules.base.service.IInterlockBaseHyService;
 import org.jeecg.modules.base.service.IInterlockBaseService;
+import org.jeecg.modules.summary.constants.InterlockAllStatus;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -29,6 +34,9 @@ public class InterlockBaseServiceImpl extends ServiceImpl<InterlockBaseMapper, I
     @Autowired
     @SuppressWarnings("all")
     private InterlockBaseMapper interlockBaseMapper;
+    @Autowired
+    @SuppressWarnings("all")
+    private IInterlockBaseHyService hyService;
 
     /**查表中有无该系统下的联锁,无则新增*/
     public void judgeAndAdd(String pid, String interlockType, String interlockName, String hasChild){
@@ -58,6 +66,7 @@ public class InterlockBaseServiceImpl extends ServiceImpl<InterlockBaseMapper, I
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
 	public void addInterlockBase(InterlockBase interlockBase) {
 	   //新增时设置hasChild为0
 	    interlockBase.setHasChild(IInterlockBaseService.NOCHILD);
@@ -72,9 +81,52 @@ public class InterlockBaseServiceImpl extends ServiceImpl<InterlockBaseMapper, I
 			}
 		}
 		baseMapper.insert(interlockBase);
+
+		// 如果新增的是系统, 同时新增base_hy
+        if(interlockBase.getInterlockType().equals(InterlockAllStatus.INTERLOCK_TYPE_XT)){
+            List<InterlockBaseHy> baseHyList = toBaseHy(interlockBase);
+            hyService.saveBatch(baseHyList);
+        }
+
 	}
 
+    private List<InterlockBaseHy> toBaseHy(InterlockBase base){
+        List<InterlockBaseHy> list = new ArrayList<>();
+        InterlockBaseHy yhy = InterlockBaseConvert.INSTANCE.toInterlockBaseHy(
+                base.getId(),
+                base.getInterlockStatusTy(),
+                base.getInterlockStatusTyName(),
+                base.getBypassYes(),
+                base.getBypassYesName(),
+                base.getInstrumentStatusNormal(),
+                base.getInstrumentStatusNormalName(),
+                base.getControlSystemStatusNormal(),
+                base.getControlSystemStatusNormalName()
+                );
+        list.add(yhy);
+        InterlockBaseHy zhhy = InterlockBaseConvert.INSTANCE.toInterlockBaseHy(
+                base.getId(),
+                zh(base.getInterlockStatusTy()),
+                base.getInterlockStatusWtyName(),
+                zh(base.getBypassYes()),
+                base.getBypassNoName(),
+                zh(base.getInstrumentStatusNormal()),
+                base.getInstrumentStatusAbnormalName(),
+                zh(base.getControlSystemStatusNormal()),
+                base.getControlSystemStatusAbnormalName()
+        );
+        list.add(zhhy);
+        return list;
+    }
+
+    private String zh(String status){
+        if("0".equals(status)) return "1";
+        else if("1".equals(status)) return "0";
+        else return null;
+    }
+
 	@Override
+    @Transactional(rollbackFor = Exception.class)
 	public void updateInterlockBase(InterlockBase interlockBase) {
 		InterlockBase entity = this.getById(interlockBase.getId());
 		if(entity==null) {
@@ -92,6 +144,17 @@ public class InterlockBaseServiceImpl extends ServiceImpl<InterlockBaseMapper, I
 			}
 		}
 		baseMapper.updateById(interlockBase);
+
+        // 如果修改的是系统, 同时修改base_hy(直接删掉原来的,新增修改后的)
+        if(interlockBase.getInterlockType().equals(InterlockAllStatus.INTERLOCK_TYPE_XT)){
+            // 删除原InterlockBaseHy
+            LambdaQueryWrapper<InterlockBaseHy> wrapper = new LambdaQueryWrapper<>();
+            wrapper.eq(InterlockBaseHy::getInterlockSystemId,interlockBase.getId());
+            hyService.remove(wrapper);
+            // 新增InterlockBaseHy
+            List<InterlockBaseHy> baseHyList = toBaseHy(interlockBase);
+            hyService.saveBatch(baseHyList);
+        }
 	}
 
 	@Override
@@ -113,6 +176,12 @@ public class InterlockBaseServiceImpl extends ServiceImpl<InterlockBaseMapper, I
                         //如果当前节点原本有子节点 现在木有了,更新状态
                         sb.append(pidVal).append(",");
                     }
+
+                    //删除对应的base_hy数据
+                    LambdaQueryWrapper<InterlockBaseHy> wrapper = new LambdaQueryWrapper<>();
+                    wrapper.eq(InterlockBaseHy::getInterlockSystemId,interlockBase.getId());
+                    hyService.remove(wrapper);
+
                 }
             }
             //批量删除节点
@@ -129,6 +198,11 @@ public class InterlockBaseServiceImpl extends ServiceImpl<InterlockBaseMapper, I
             }
             updateOldParentNode(interlockBase.getPid());
             baseMapper.deleteById(id);
+
+            //删除对应的base_hy数据
+            LambdaQueryWrapper<InterlockBaseHy> wrapper = new LambdaQueryWrapper<>();
+            wrapper.eq(InterlockBaseHy::getInterlockSystemId,interlockBase.getId());
+            hyService.remove(wrapper);
         }
 	}
 

+ 4 - 0
jeecg-module-interlock/src/main/java/org/jeecg/modules/summary/constants/InterlockAllStatus.java

@@ -48,4 +48,8 @@ public class InterlockAllStatus {
 //    public static final String INTERLOCK_STATUS_TY = "1"; // 联锁状态-投用
 
 
+    // 类型 0装置1系统2联锁
+    public static final String INTERLOCK_TYPE_ZZ = "0"; // 类型-装置
+    public static final String INTERLOCK_TYPE_XT = "1"; // 类型-系统
+    public static final String INTERLOCK_TYPE_LS = "2"; // 类型-联锁
 }