|
@@ -1,20 +1,35 @@
|
|
|
package org.jeecg.modules.interlockAvoidCircular.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.Query;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
+import org.jeecg.common.exception.JeecgBootException;
|
|
|
import org.jeecg.common.util.DateUtils;
|
|
|
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.InterlockBaseMapper;
|
|
|
+import org.jeecg.modules.base.service.IInterlockBaseHyService;
|
|
|
import org.jeecg.modules.base.service.IInterlockBaseService;
|
|
|
import org.jeecg.modules.base.vo.InterlockBaseVo;
|
|
|
import org.jeecg.modules.detail.entity.InterlockDetail;
|
|
|
import org.jeecg.modules.detail.service.IInterlockDetailService;
|
|
|
+import org.jeecg.modules.history.entity.InterlockDetailHistory;
|
|
|
+import org.jeecg.modules.history.entity.InterlockSummaryHistory;
|
|
|
+import org.jeecg.modules.history.service.IInterlockDetailHistoryService;
|
|
|
+import org.jeecg.modules.history.service.IInterlockSummaryHistoryService;
|
|
|
import org.jeecg.modules.interlockAvoidCircular.entity.InterlockSumSystemDetailList;
|
|
|
import org.jeecg.modules.interlockAvoidCircular.mapper.InterlockAvoidCircularMapper;
|
|
|
import org.jeecg.modules.interlockAvoidCircular.service.InterlockAvoidCircularService;
|
|
|
+import org.jeecg.modules.interlockCountDay.entity.InterlockCountDay;
|
|
|
+import org.jeecg.modules.interlockCountDay.service.IInterlockCountDayService;
|
|
|
+import org.jeecg.modules.interlockCountMonth.entity.InterlockCountMonth;
|
|
|
+import org.jeecg.modules.interlockCountMonth.service.IInterlockCountMonthService;
|
|
|
import org.jeecg.modules.iotedgeCollectData.entity.IotedgeCollectData;
|
|
|
import org.jeecg.modules.iotedgeCollectData.service.IIotedgeCollectDataService;
|
|
|
import org.jeecg.modules.iotedgeCollectData.service.RestClientService;
|
|
@@ -28,6 +43,7 @@ import org.jeecg.modules.temp.service.IInterlockDetailTempService;
|
|
|
import org.jeecg.modules.temp.service.IInterlockSummaryTempService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.servlet.http.Cookie;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
@@ -37,6 +53,8 @@ import java.time.Duration;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
|
|
@@ -57,6 +75,7 @@ public class InterlockAvoidCircularServiceImpl implements InterlockAvoidCircular
|
|
|
private RestClientService restClientService;
|
|
|
|
|
|
@Autowired
|
|
|
+ @SuppressWarnings("all")
|
|
|
private IInterlockBaseService baseService;
|
|
|
|
|
|
@Autowired
|
|
@@ -77,6 +96,31 @@ public class InterlockAvoidCircularServiceImpl implements InterlockAvoidCircular
|
|
|
@SuppressWarnings("all")
|
|
|
private IIotedgeCollectDataService iotedgeCollectDataService;
|
|
|
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ @SuppressWarnings("all")
|
|
|
+ private InterlockBaseMapper baseMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ @SuppressWarnings("all")
|
|
|
+ private IInterlockBaseHyService hyService;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ @SuppressWarnings("all")
|
|
|
+ private IInterlockSummaryHistoryService summaryHistoryService;
|
|
|
+ @Autowired
|
|
|
+ @SuppressWarnings("all")
|
|
|
+ private IInterlockDetailHistoryService detailHistoryService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ @SuppressWarnings("all")
|
|
|
+ private IInterlockCountDayService countDayService;
|
|
|
+ @Autowired
|
|
|
+ @SuppressWarnings("all")
|
|
|
+ private IInterlockCountMonthService countMonthService;
|
|
|
+
|
|
|
private static final String SUCCESS_CODE = "200";
|
|
|
private static final String ERROR_CODE_ONE = "400";
|
|
|
private static final String ERROR_CODE_TWO = "500";
|
|
@@ -346,4 +390,243 @@ public class InterlockAvoidCircularServiceImpl implements InterlockAvoidCircular
|
|
|
}
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
+ public String deleteGroup(String interlockId, HttpServletRequest request) {
|
|
|
+
|
|
|
+ String resultCode = SUCCESS_CODE;
|
|
|
+
|
|
|
+ String eiToken = "";
|
|
|
+
|
|
|
+ Cookie[] cookies = request.getCookies();
|
|
|
+ if (cookies != null) {
|
|
|
+ for (Cookie cookie : cookies) {
|
|
|
+ if (cookie.getName().equals("EIToken")) {
|
|
|
+ eiToken = cookie.getValue();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 根据id 查询要删除的是装置还是系统
|
|
|
+ InterlockBase base = baseService.getById(interlockId);
|
|
|
+
|
|
|
+ if ("1".equals(base.getInterlockType())){
|
|
|
+ JSONObject jsonObject = null;
|
|
|
+ try {
|
|
|
+ jsonObject = restClientService.deleteGroup(base.getIotedgeGroupId(), eiToken);
|
|
|
+ } catch (Exception e) {
|
|
|
+ String message = e.getMessage();
|
|
|
+ JSONObject mJsonObject = JSONObject.parseObject(message);
|
|
|
+ Integer code = (Integer) mJsonObject.get("code");
|
|
|
+ String message1 = (String) mJsonObject.get("message");
|
|
|
+ if (ObjectUtil.isNotNull(code) && 400 == code){
|
|
|
+ // 400表示该组织已被使用 删除失败。
|
|
|
+ log.info("IoTedge中该组织已被使用,删除组织失败!请到IoTedge系统中进行处理");
|
|
|
+ resultCode = ERROR_CODE_ONE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if ("0".equals(base.getInterlockType())){
|
|
|
+ int count = 0;
|
|
|
+ List<InterlockBase> list = baseService.getListByPId(interlockId);
|
|
|
+ for (InterlockBase item : list) {
|
|
|
+ JSONObject jsonObject = null;
|
|
|
+ try {
|
|
|
+ jsonObject = restClientService.deleteGroup(item.getIotedgeGroupId(), eiToken);
|
|
|
+ } catch (Exception e) {
|
|
|
+ String message = e.getMessage();
|
|
|
+ JSONObject mJsonObject = JSONObject.parseObject(message);
|
|
|
+ Integer code = (Integer) mJsonObject.get("code");
|
|
|
+ String message1 = (String) mJsonObject.get("message");
|
|
|
+ if (ObjectUtil.isNotNull(code) && 400 == code){
|
|
|
+ // 400表示该组织已被使用 删除失败。
|
|
|
+ log.info("IoTedge中该组织已被使用,删除组织失败!请到IoTedge系统中进行处理");
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (count != 0){
|
|
|
+ resultCode = "400";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ baseService.deleteInterlockBase(interlockId);
|
|
|
+
|
|
|
+ return resultCode;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void deleteInterlockBase(String id) throws JeecgBootException {
|
|
|
+ //查询选中节点下所有子节点一并删除
|
|
|
+ id = this.queryTreeChildIds(id);
|
|
|
+ if(id.indexOf(",")>0) {
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+ String[] idArr = id.split(",");
|
|
|
+ for (String idVal : idArr) {
|
|
|
+ if(idVal != null){
|
|
|
+ InterlockBase interlockBase = baseService.getById(idVal);
|
|
|
+ String pidVal = interlockBase.getPid();
|
|
|
+ //查询此节点上一级是否还有其他子节点
|
|
|
+ List<InterlockBase> dataList = baseMapper.selectList(new QueryWrapper<InterlockBase>().eq("pid", pidVal).notIn("id", Arrays.asList(idArr)));
|
|
|
+ boolean flag = (dataList == null || dataList.size() == 0) && !Arrays.asList(idArr).contains(pidVal) && !sb.toString().contains(pidVal);
|
|
|
+ if(flag){
|
|
|
+ //如果当前节点原本有子节点 现在木有了,更新状态
|
|
|
+ sb.append(pidVal).append(",");
|
|
|
+ }
|
|
|
+
|
|
|
+ //删除对应的base_hy数据
|
|
|
+ LambdaQueryWrapper<InterlockBaseHy> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(InterlockBaseHy::getInterlockSystemId,interlockBase.getId());
|
|
|
+ hyService.remove(wrapper);
|
|
|
+
|
|
|
+ deleteInterlockSummaryDetailInfo(interlockBase.getId());
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //批量删除节点
|
|
|
+ baseMapper.deleteBatchIds(Arrays.asList(idArr));
|
|
|
+ //修改已无子节点的标识
|
|
|
+ String[] pidArr = sb.toString().split(",");
|
|
|
+ for(String pid : pidArr){
|
|
|
+ this.updateOldParentNode(pid);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ InterlockBase interlockBase = baseService.getById(id);
|
|
|
+ if(interlockBase==null) {
|
|
|
+ throw new JeecgBootException("未找到对应实体");
|
|
|
+ }
|
|
|
+ updateOldParentNode(interlockBase.getPid());
|
|
|
+ baseMapper.deleteById(id);
|
|
|
+
|
|
|
+ //删除对应的base_hy数据
|
|
|
+ LambdaQueryWrapper<InterlockBaseHy> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(InterlockBaseHy::getInterlockSystemId,interlockBase.getId());
|
|
|
+ hyService.remove(wrapper);
|
|
|
+
|
|
|
+ deleteInterlockSummaryDetailInfo(id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void deleteInterlockSummaryDetailInfo(String id) {
|
|
|
+ //删除对应的联锁
|
|
|
+ ArrayList<String> summaryIdList = new ArrayList<>();
|
|
|
+ QueryWrapper<InterlockSummary> summaryQuery = new QueryWrapper<>();
|
|
|
+ summaryQuery.eq("interlock_system_id",id);
|
|
|
+ List<InterlockSummary> summaryList = interlockSummaryService.list(summaryQuery);
|
|
|
+ for (InterlockSummary summary : summaryList) {
|
|
|
+ summaryIdList.add(summary.getId());
|
|
|
+ }
|
|
|
+ // 删除联锁条件
|
|
|
+ QueryWrapper<InterlockDetail> interlockDetailQueryWrapper = new QueryWrapper<>();
|
|
|
+ interlockDetailQueryWrapper.in("summaryid",summaryIdList);
|
|
|
+ if (ObjectUtil.isNotNull(summaryIdList)){
|
|
|
+ interlockDetailService.remove(interlockDetailQueryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 删除联锁
|
|
|
+ QueryWrapper<InterlockSummary> interlockSummaryQueryWrapper = new QueryWrapper<>();
|
|
|
+ interlockSummaryQueryWrapper.in("interlock_system_id",id);
|
|
|
+ interlockSummaryService.remove(interlockSummaryQueryWrapper);
|
|
|
+
|
|
|
+ //删除对应的临时表
|
|
|
+ ArrayList<String> tempSummaryIdList = new ArrayList<>();
|
|
|
+ QueryWrapper<InterlockSummaryTemp> tempSummaryQuery = new QueryWrapper<>();
|
|
|
+ tempSummaryQuery.eq("interlock_system_id",id);
|
|
|
+ List<InterlockSummaryTemp> tempSummaryList = interlockSummaryTempService.list(tempSummaryQuery);
|
|
|
+ for (InterlockSummaryTemp tempSummary : tempSummaryList) {
|
|
|
+ tempSummaryIdList.add(tempSummary.getId());
|
|
|
+ }
|
|
|
+ QueryWrapper<InterlockDetailTemp> interlockDetailTempQueryWrapper = new QueryWrapper<>();
|
|
|
+ interlockDetailTempQueryWrapper.in("summaryid",tempSummaryIdList);
|
|
|
+ if (ObjectUtil.isNotNull(tempSummaryIdList)){
|
|
|
+ interlockDetailTempService.remove(interlockDetailTempQueryWrapper);
|
|
|
+ }
|
|
|
+ QueryWrapper<InterlockSummaryTemp> interlockSummaryTempQueryWrapper = new QueryWrapper<>();
|
|
|
+ interlockSummaryTempQueryWrapper.in("interlock_system_id",id);
|
|
|
+ interlockSummaryTempService.remove(interlockSummaryTempQueryWrapper);
|
|
|
+
|
|
|
+ //删除对应的历史数据表
|
|
|
+ ArrayList<String> historySummaryIdList = new ArrayList<>();
|
|
|
+ QueryWrapper<InterlockSummaryHistory> historySummaryQuery = new QueryWrapper<>();
|
|
|
+ historySummaryQuery.eq("interlock_system_id",id);
|
|
|
+ List<InterlockSummaryHistory> historySummaryList = summaryHistoryService.list(historySummaryQuery);
|
|
|
+ for (InterlockSummaryHistory historySummary : historySummaryList) {
|
|
|
+ historySummaryIdList.add(historySummary.getId());
|
|
|
+ }
|
|
|
+ QueryWrapper<InterlockDetailHistory> interlockDetailHistoryQueryWrapper = new QueryWrapper<>();
|
|
|
+ interlockDetailHistoryQueryWrapper.in("summaryid",historySummaryIdList);
|
|
|
+ if (ObjectUtil.isNotNull(historySummaryIdList)) {
|
|
|
+ detailHistoryService.remove(interlockDetailHistoryQueryWrapper);
|
|
|
+ }
|
|
|
+ QueryWrapper<InterlockSummaryHistory> interlockSummaryHistoryQueryWrapper = new QueryWrapper<>();
|
|
|
+ interlockSummaryHistoryQueryWrapper.in("interlock_system_id",id);
|
|
|
+ summaryHistoryService.remove(interlockSummaryHistoryQueryWrapper);
|
|
|
+
|
|
|
+ //删除对应的统计数据表
|
|
|
+ QueryWrapper<InterlockCountDay> interlockCountDayQueryWrapper = new QueryWrapper<>();
|
|
|
+ interlockCountDayQueryWrapper.in("interlock_system_id",id);
|
|
|
+ countDayService.remove(interlockCountDayQueryWrapper);
|
|
|
+ QueryWrapper<InterlockCountMonth> interlockCountMonthQueryWrapper = new QueryWrapper<>();
|
|
|
+ interlockCountMonthQueryWrapper.in("interlock_system_id",id);
|
|
|
+ countMonthService.remove(interlockCountMonthQueryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据id查询所有子节点id
|
|
|
+ * @param ids
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String queryTreeChildIds(String ids) {
|
|
|
+ //获取id数组
|
|
|
+ String[] idArr = ids.split(",");
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+ for (String pidVal : idArr) {
|
|
|
+ if(pidVal != null){
|
|
|
+ if(!sb.toString().contains(pidVal)){
|
|
|
+ if(sb.toString().length() > 0){
|
|
|
+ sb.append(",");
|
|
|
+ }
|
|
|
+ sb.append(pidVal);
|
|
|
+ this.getTreeChildIds(pidVal,sb);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 递归查询所有子节点
|
|
|
+ * @param pidVal
|
|
|
+ * @param sb
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private StringBuffer getTreeChildIds(String pidVal,StringBuffer sb){
|
|
|
+ List<InterlockBase> dataList = baseMapper.selectList(new QueryWrapper<InterlockBase>().eq("pid", pidVal));
|
|
|
+ if(dataList != null && dataList.size()>0){
|
|
|
+ for(InterlockBase tree : dataList) {
|
|
|
+ if(!sb.toString().contains(tree.getId())){
|
|
|
+ sb.append(",").append(tree.getId());
|
|
|
+ }
|
|
|
+ this.getTreeChildIds(tree.getId(),sb);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return sb;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据所传pid查询旧的父级节点的子节点并修改相应状态值
|
|
|
+ * @param pid
|
|
|
+ */
|
|
|
+ private void updateOldParentNode(String pid) {
|
|
|
+ if(!IInterlockBaseService.ROOT_PID_VALUE.equals(pid)) {
|
|
|
+ Long count = baseMapper.selectCount(new QueryWrapper<InterlockBase>().eq("pid", pid));
|
|
|
+ if(count==null || count<=1) {
|
|
|
+ baseMapper.updateTreeNodeStatus(pid, IInterlockBaseService.NOCHILD);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|