暂存功能
This commit is contained in:
@@ -74,4 +74,10 @@ public interface SimAndDigHarmonicService extends IService<SimAndDigHarmonicResu
|
||||
* @return
|
||||
*/
|
||||
List<SimAndDigHarmonicResult> listAllRawData(String scriptId, String code, String devId);
|
||||
|
||||
Map<String, Integer> maxSortByDevIds(String code, String scriptId, List<String> devIds);
|
||||
|
||||
List<SimAndDigHarmonicResult> listByDevIdsAndSorts(String code, String scriptId, List<String> devIds, List<Integer> sorts);
|
||||
|
||||
Map<String, List<Integer>> resultFlagsByDevIdsAndSorts(String code, String scriptId, List<String> devIds, List<Integer> sorts);
|
||||
}
|
||||
|
||||
@@ -79,4 +79,10 @@ public interface SimAndDigNonHarmonicService extends IService<SimAndDigNonHarmon
|
||||
* @return
|
||||
*/
|
||||
List<SimAndDigNonHarmonicResult> listAllSimAndDigRawData(String scriptId, String code, String devId);
|
||||
|
||||
Map<String, Integer> maxSortByDevIds(String code, String scriptId, List<String> devIds);
|
||||
|
||||
List<SimAndDigNonHarmonicResult> listByDevIdsAndSorts(String code, String scriptId, List<String> devIds, List<Integer> sorts);
|
||||
|
||||
Map<String, List<Integer>> resultFlagsByDevIdsAndSorts(String code, String scriptId, List<String> devIds, List<Integer> sorts);
|
||||
}
|
||||
|
||||
@@ -276,4 +276,96 @@ public class SimAndDigHarmonicServiceImpl extends ServiceImpl<SimAndDigHarmonicM
|
||||
DynamicTableNameHandler.remove();
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Integer> maxSortByDevIds(String code, String scriptId, List<String> devIds) {
|
||||
Map<String, Integer> result = new HashMap<>();
|
||||
if (CollUtil.isEmpty(devIds)) {
|
||||
return result;
|
||||
}
|
||||
DynamicTableNameHandler.setTableName("ad_harmonic_result_" + code);
|
||||
try {
|
||||
LambdaQueryWrapper<SimAndDigHarmonicResult> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.select(SimAndDigHarmonicResult::getDevMonitorId, SimAndDigHarmonicResult::getSort)
|
||||
.eq(SimAndDigHarmonicResult::getScriptId, scriptId)
|
||||
.and(w -> {
|
||||
for (String devId : devIds) {
|
||||
w.or().likeRight(SimAndDigHarmonicResult::getDevMonitorId, devId + "_");
|
||||
}
|
||||
});
|
||||
this.list(wrapper).forEach(row -> {
|
||||
String devId = row.getDevMonitorId().split("_")[0];
|
||||
result.merge(devId, row.getSort(), Math::max);
|
||||
});
|
||||
return result;
|
||||
} finally {
|
||||
DynamicTableNameHandler.remove();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SimAndDigHarmonicResult> listByDevIdsAndSorts(String code, String scriptId, List<String> devIds, List<Integer> sorts) {
|
||||
if (CollUtil.isEmpty(devIds) || CollUtil.isEmpty(sorts)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
DynamicTableNameHandler.setTableName("ad_harmonic_result_" + code);
|
||||
try {
|
||||
LambdaQueryWrapper<SimAndDigHarmonicResult> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SimAndDigHarmonicResult::getScriptId, scriptId)
|
||||
.in(SimAndDigHarmonicResult::getSort, sorts)
|
||||
.and(w -> {
|
||||
for (String devId : devIds) {
|
||||
w.or().likeRight(SimAndDigHarmonicResult::getDevMonitorId, devId + "_");
|
||||
}
|
||||
});
|
||||
return this.list(wrapper);
|
||||
} finally {
|
||||
DynamicTableNameHandler.remove();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, List<Integer>> resultFlagsByDevIdsAndSorts(String code, String scriptId, List<String> devIds, List<Integer> sorts) {
|
||||
Map<String, List<Integer>> result = new HashMap<>();
|
||||
if (CollUtil.isEmpty(devIds) || StrUtil.isBlank(code)) {
|
||||
return result;
|
||||
}
|
||||
if (sorts != null && CollUtil.isEmpty(sorts)) {
|
||||
return result;
|
||||
}
|
||||
DynamicTableNameHandler.setTableName("ad_harmonic_result_" + code);
|
||||
try {
|
||||
LambdaQueryWrapper<SimAndDigHarmonicResult> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.select(SimAndDigHarmonicResult::getDevMonitorId,
|
||||
SimAndDigHarmonicResult::getResultFlag)
|
||||
.eq(StrUtil.isNotBlank(scriptId), SimAndDigHarmonicResult::getScriptId, scriptId)
|
||||
.in(CollUtil.isNotEmpty(sorts), SimAndDigHarmonicResult::getSort, sorts)
|
||||
.and(w -> {
|
||||
for (String devId : devIds) {
|
||||
w.or().likeRight(SimAndDigHarmonicResult::getDevMonitorId, devId + "_");
|
||||
}
|
||||
});
|
||||
this.list(wrapper).forEach(row -> {
|
||||
String devId = resolveDevId(row.getDevMonitorId(), devIds);
|
||||
if (StrUtil.isNotBlank(devId) && row.getResultFlag() != null) {
|
||||
result.computeIfAbsent(devId, key -> new ArrayList<>()).add(row.getResultFlag());
|
||||
}
|
||||
});
|
||||
return result;
|
||||
} finally {
|
||||
DynamicTableNameHandler.remove();
|
||||
}
|
||||
}
|
||||
|
||||
private String resolveDevId(String devMonitorId, List<String> devIds) {
|
||||
if (StrUtil.isBlank(devMonitorId)) {
|
||||
return null;
|
||||
}
|
||||
for (String devId : devIds) {
|
||||
if (StrUtil.isNotBlank(devId) && devMonitorId.startsWith(devId + "_")) {
|
||||
return devId;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import com.njcn.db.mybatisplus.handler.DynamicTableNameHandler;
|
||||
@@ -211,5 +212,96 @@ public class SimAndDigNonHarmonicServiceImpl extends ServiceImpl<SimAndDigNonHar
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Integer> maxSortByDevIds(String code, String scriptId, List<String> devIds) {
|
||||
Map<String, Integer> result = new HashMap<>();
|
||||
if (CollUtil.isEmpty(devIds)) {
|
||||
return result;
|
||||
}
|
||||
DynamicTableNameHandler.setTableName("ad_non_harmonic_result_" + code);
|
||||
try {
|
||||
LambdaQueryWrapper<SimAndDigNonHarmonicResult> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.select(SimAndDigNonHarmonicResult::getDevMonitorId, SimAndDigNonHarmonicResult::getSort)
|
||||
.eq(SimAndDigNonHarmonicResult::getScriptId, scriptId)
|
||||
.and(w -> {
|
||||
for (String devId : devIds) {
|
||||
w.or().likeRight(SimAndDigNonHarmonicResult::getDevMonitorId, devId + "_");
|
||||
}
|
||||
});
|
||||
this.list(wrapper).forEach(row -> {
|
||||
String devId = row.getDevMonitorId().split("_")[0];
|
||||
result.merge(devId, row.getSort(), Math::max);
|
||||
});
|
||||
return result;
|
||||
} finally {
|
||||
DynamicTableNameHandler.remove();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SimAndDigNonHarmonicResult> listByDevIdsAndSorts(String code, String scriptId, List<String> devIds, List<Integer> sorts) {
|
||||
if (CollUtil.isEmpty(devIds) || CollUtil.isEmpty(sorts)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
DynamicTableNameHandler.setTableName("ad_non_harmonic_result_" + code);
|
||||
try {
|
||||
LambdaQueryWrapper<SimAndDigNonHarmonicResult> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SimAndDigNonHarmonicResult::getScriptId, scriptId)
|
||||
.in(SimAndDigNonHarmonicResult::getSort, sorts)
|
||||
.and(w -> {
|
||||
for (String devId : devIds) {
|
||||
w.or().likeRight(SimAndDigNonHarmonicResult::getDevMonitorId, devId + "_");
|
||||
}
|
||||
});
|
||||
return this.list(wrapper);
|
||||
} finally {
|
||||
DynamicTableNameHandler.remove();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, List<Integer>> resultFlagsByDevIdsAndSorts(String code, String scriptId, List<String> devIds, List<Integer> sorts) {
|
||||
Map<String, List<Integer>> result = new HashMap<>();
|
||||
if (CollUtil.isEmpty(devIds) || StrUtil.isBlank(code)) {
|
||||
return result;
|
||||
}
|
||||
if (sorts != null && CollUtil.isEmpty(sorts)) {
|
||||
return result;
|
||||
}
|
||||
DynamicTableNameHandler.setTableName("ad_non_harmonic_result_" + code);
|
||||
try {
|
||||
LambdaQueryWrapper<SimAndDigNonHarmonicResult> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.select(SimAndDigNonHarmonicResult::getDevMonitorId,
|
||||
SimAndDigNonHarmonicResult::getResultFlag)
|
||||
.eq(StrUtil.isNotBlank(scriptId), SimAndDigNonHarmonicResult::getScriptId, scriptId)
|
||||
.in(CollUtil.isNotEmpty(sorts), SimAndDigNonHarmonicResult::getSort, sorts)
|
||||
.and(w -> {
|
||||
for (String devId : devIds) {
|
||||
w.or().likeRight(SimAndDigNonHarmonicResult::getDevMonitorId, devId + "_");
|
||||
}
|
||||
});
|
||||
this.list(wrapper).forEach(row -> {
|
||||
String devId = resolveDevId(row.getDevMonitorId(), devIds);
|
||||
if (StrUtil.isNotBlank(devId) && row.getResultFlag() != null) {
|
||||
result.computeIfAbsent(devId, key -> new ArrayList<>()).add(row.getResultFlag());
|
||||
}
|
||||
});
|
||||
return result;
|
||||
} finally {
|
||||
DynamicTableNameHandler.remove();
|
||||
}
|
||||
}
|
||||
|
||||
private String resolveDevId(String devMonitorId, List<String> devIds) {
|
||||
if (StrUtil.isBlank(devMonitorId)) {
|
||||
return null;
|
||||
}
|
||||
for (String devId : devIds) {
|
||||
if (StrUtil.isNotBlank(devId) && devMonitorId.startsWith(devId + "_")) {
|
||||
return devId;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user