|
|
|
@ -1,8 +1,6 @@
|
|
|
|
|
package com.os.ems.base.service.impl;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import com.os.common.utils.DateUtils;
|
|
|
|
@ -16,19 +14,19 @@ import com.os.ems.base.service.IEmsBaseMonitorInfoService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 计量设备信息Service业务层处理
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @author Yinq
|
|
|
|
|
* @date 2024-05-08
|
|
|
|
|
*/
|
|
|
|
|
@Service
|
|
|
|
|
public class EmsBaseMonitorInfoServiceImpl implements IEmsBaseMonitorInfoService
|
|
|
|
|
public class EmsBaseMonitorInfoServiceImpl implements IEmsBaseMonitorInfoService
|
|
|
|
|
{
|
|
|
|
|
@Autowired
|
|
|
|
|
private EmsBaseMonitorInfoMapper emsBaseMonitorInfoMapper;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询计量设备信息
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param objId 计量设备信息主键
|
|
|
|
|
* @return 计量设备信息
|
|
|
|
|
*/
|
|
|
|
@ -40,7 +38,7 @@ public class EmsBaseMonitorInfoServiceImpl implements IEmsBaseMonitorInfoService
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询计量设备信息列表
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param emsBaseMonitorInfo 计量设备信息
|
|
|
|
|
* @return 计量设备信息
|
|
|
|
|
*/
|
|
|
|
@ -62,7 +60,7 @@ public class EmsBaseMonitorInfoServiceImpl implements IEmsBaseMonitorInfoService
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 新增计量设备信息
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param emsBaseMonitorInfo 计量设备信息
|
|
|
|
|
* @return 结果
|
|
|
|
|
*/
|
|
|
|
@ -75,7 +73,7 @@ public class EmsBaseMonitorInfoServiceImpl implements IEmsBaseMonitorInfoService
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改计量设备信息
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param emsBaseMonitorInfo 计量设备信息
|
|
|
|
|
* @return 结果
|
|
|
|
|
*/
|
|
|
|
@ -88,7 +86,7 @@ public class EmsBaseMonitorInfoServiceImpl implements IEmsBaseMonitorInfoService
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 批量删除计量设备信息
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param objIds 需要删除的计量设备信息主键
|
|
|
|
|
* @return 结果
|
|
|
|
|
*/
|
|
|
|
@ -100,7 +98,7 @@ public class EmsBaseMonitorInfoServiceImpl implements IEmsBaseMonitorInfoService
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除计量设备信息信息
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param objId 计量设备信息主键
|
|
|
|
|
* @return 结果
|
|
|
|
|
*/
|
|
|
|
@ -125,12 +123,163 @@ public class EmsBaseMonitorInfoServiceImpl implements IEmsBaseMonitorInfoService
|
|
|
|
|
* @param
|
|
|
|
|
* @return 下拉树结构列表
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
/* @Override
|
|
|
|
|
public List<TreeSelects> buildMonitorInfoTreeSelect(List<EmsBaseMonitorInfo> baseMonitorInfos)
|
|
|
|
|
{
|
|
|
|
|
List<EmsBaseMonitorInfo> deptTrees = buildMonitorInfoTree(baseMonitorInfos);
|
|
|
|
|
return deptTrees.stream().map(TreeSelects::new).collect(Collectors.toList());
|
|
|
|
|
}*/
|
|
|
|
|
/*
|
|
|
|
|
public List<TreeSelects> buildMonitorInfoTreeSelect(List<EmsBaseMonitorInfo> baseMonitorInfos)
|
|
|
|
|
{
|
|
|
|
|
List<EmsBaseMonitorInfo> deptTrees = buildMonitorInfoTree(baseMonitorInfos);
|
|
|
|
|
// 对树节点进行排序
|
|
|
|
|
List<TreeSelects> treeSelectsList = deptTrees.stream()
|
|
|
|
|
.map(TreeSelects::new)
|
|
|
|
|
.sorted(Comparator.comparingInt((TreeSelects treeSelect) -> getOrderIndex(treeSelect.getLabel()))
|
|
|
|
|
.thenComparing(TreeSelects::getLabel)) // 添加二级排序
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
return treeSelectsList;
|
|
|
|
|
}
|
|
|
|
|
private int getOrderIndex(String name) {
|
|
|
|
|
List<String> specificOrder = Collections.unmodifiableList(Arrays.asList(
|
|
|
|
|
"赛轮沈阳", "公用橡胶", "三像","三橡", "维航", "维", "米其林高压", "米其林低压", "米其林",
|
|
|
|
|
"橡胶四厂", "三聚凯特", "世源", "联盛", "正兴", "天峰药业", "中科北方", "沃得",
|
|
|
|
|
"沈阳经济技术开发区管理委员会办公室","管理中心", "科创", "博泰", "亿纬", "普利司通"
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < specificOrder.size(); i++) {
|
|
|
|
|
String prefix = specificOrder.get(i);
|
|
|
|
|
if (name.equals(prefix) || name.startsWith(prefix) || name.contains(prefix) || name.endsWith(prefix) ) {
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return Integer.MAX_VALUE; // 如果找不到匹配项,则返回最大值
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
/**
|
|
|
|
|
* 构建监控信息树选择列表
|
|
|
|
|
* @param baseMonitorInfos 基础监控信息列表
|
|
|
|
|
* @return 树选择列表
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public List<TreeSelects> buildMonitorInfoTreeSelect(List<EmsBaseMonitorInfo> baseMonitorInfos) {
|
|
|
|
|
// 构建监控信息树
|
|
|
|
|
List<EmsBaseMonitorInfo> deptTrees = buildMonitorInfoTree(baseMonitorInfos);
|
|
|
|
|
|
|
|
|
|
// 对树节点进行排序
|
|
|
|
|
List<TreeSelects> treeSelectsList = deptTrees.stream()
|
|
|
|
|
// 将每个 EmsBaseMonitorInfo 对象映射为 TreeSelects 对象
|
|
|
|
|
.map(TreeSelects::new)
|
|
|
|
|
// 根据标签的排序索引进行排序,如果索引相同则按标签名称排序
|
|
|
|
|
.sorted(Comparator.comparingInt((TreeSelects treeSelect) -> getOrderIndex(treeSelect.getLabel()))
|
|
|
|
|
.thenComparing(TreeSelects::getLabel)) // 添加二级排序
|
|
|
|
|
// 收集排序后的结果到列表中
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
// 返回排序后的树选择列表
|
|
|
|
|
return treeSelectsList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取指定名称在特定顺序列表中的索引。
|
|
|
|
|
* @param name 要查找的名称
|
|
|
|
|
* @return 名称在特定顺序列表中的索引,如果找不到则返回Integer.MAX_VALUE
|
|
|
|
|
*/
|
|
|
|
|
private int getOrderIndex(String name) {
|
|
|
|
|
// 创建一个客户给的特定顺序列表
|
|
|
|
|
List<String> specificOrder = Collections.unmodifiableList(Arrays.asList(
|
|
|
|
|
"赛轮沈阳","赛轮","公用橡胶", "三像", "三橡", "维航", "维", "米其林高压", "米其林低压", "米其林",
|
|
|
|
|
"橡胶四厂", "三聚凯特", "世源", "联盛", "正兴", "天峰药业", "中科北方", "沃得",
|
|
|
|
|
"沈阳经济技术开发区管理委员会办公室", "管理中心", "科创", "博泰", "亿纬", "普利司通"
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
// 遍历特定顺序列表
|
|
|
|
|
for (int i = 0; i < specificOrder.size(); i++) {
|
|
|
|
|
// 获取当前前缀
|
|
|
|
|
String prefix = specificOrder.get(i);
|
|
|
|
|
// 如果名称包含当前前缀,则返回当前索引
|
|
|
|
|
if (kmpSearch(name, prefix) != -1) {
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 如果找不到匹配项,则返回最大值
|
|
|
|
|
return Integer.MAX_VALUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//KMP算法,字符串匹配
|
|
|
|
|
private int kmpSearch(String text, String pattern) {
|
|
|
|
|
// 计算模式串的最长前缀后缀数组
|
|
|
|
|
int[] lps = computeLPSArray(pattern);
|
|
|
|
|
// 文本串的索引
|
|
|
|
|
int i = 0;
|
|
|
|
|
// 模式串的索引
|
|
|
|
|
int j = 0;
|
|
|
|
|
// 遍历文本串
|
|
|
|
|
while (i < text.length()) {
|
|
|
|
|
// 如果当前字符匹配
|
|
|
|
|
if (pattern.charAt(j) == text.charAt(i)) {
|
|
|
|
|
// 移动到下一个字符
|
|
|
|
|
i++;
|
|
|
|
|
j++;
|
|
|
|
|
}
|
|
|
|
|
// 如果模式串完全匹配
|
|
|
|
|
if (j == pattern.length()) {
|
|
|
|
|
// 返回匹配的起始位置
|
|
|
|
|
return i - j;
|
|
|
|
|
// 如果当前字符不匹配
|
|
|
|
|
} else if (i < text.length() && pattern.charAt(j) != text.charAt(i)) {
|
|
|
|
|
// 如果模式串索引不为0,使用lps数组跳转
|
|
|
|
|
if (j != 0) {
|
|
|
|
|
j = lps[j - 1];
|
|
|
|
|
} else {
|
|
|
|
|
// 否则,移动文本串索引
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 如果没有找到匹配,返回-1
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 计算模式串的最长前缀后缀数组
|
|
|
|
|
private int[] computeLPSArray(String pattern) {
|
|
|
|
|
// 初始化LPS数组,长度与模式字符串相同
|
|
|
|
|
int[] lps = new int[pattern.length()];
|
|
|
|
|
// len表示当前最长前缀后缀的长度
|
|
|
|
|
int len = 0;
|
|
|
|
|
// i是遍历模式字符串的索引,从1开始
|
|
|
|
|
int i = 1;
|
|
|
|
|
// LPS数组的第一个元素总是0
|
|
|
|
|
lps[0] = 0;
|
|
|
|
|
// 当i小于模式字符串的长度时循环
|
|
|
|
|
while (i < pattern.length()) {
|
|
|
|
|
// 如果当前字符与len位置的字符匹配
|
|
|
|
|
if (pattern.charAt(i) == pattern.charAt(len)) {
|
|
|
|
|
// 增加len的值
|
|
|
|
|
len++;
|
|
|
|
|
// 更新LPS数组的当前位置为len
|
|
|
|
|
lps[i] = len;
|
|
|
|
|
// 移动到下一个字符
|
|
|
|
|
i++;
|
|
|
|
|
} else { // 如果当前字符与len位置的字符不匹配
|
|
|
|
|
if (len != 0) {
|
|
|
|
|
// 将len设置为LPS数组中len-1位置的值
|
|
|
|
|
len = lps[len - 1];
|
|
|
|
|
} else { // 如果len为0
|
|
|
|
|
// 设置LPS数组的当前位置为0
|
|
|
|
|
lps[i] = 0;
|
|
|
|
|
// 移动到下一个字符
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 返回计算好的LPS数组
|
|
|
|
|
return lps;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 构建前端所需要树结构
|
|
|
|
|