feat:报警编码内容替换

This commit is contained in:
nieziyan 2024-04-09 18:19:37 +08:00
parent 4c16d4527d
commit eedcd67113
6 changed files with 76 additions and 9 deletions

View File

@ -13,4 +13,6 @@ public interface DictConstant {
String NOBLE_GAS_BETAGAMMA = "Noble Gas Beta-Gamma";
String NOBLE_GAS_HPGE = "Noble Gas HPGe";
String ALERT_SYSTEM_CODE = "Alert_System_Code";
}

View File

@ -8,31 +8,37 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
@RestController
@RequestMapping("alertSystem")
@RequestMapping("sys/alertSystem")
public class GardsAlertSystemController {
@Autowired
private IGardsAlertSystemService alertSystemService;
@GetMapping(value = "list")
@GetMapping( "list")
public Result<?> findPage(AlertSystemVo alertSystemVo) {
return alertSystemService.findPage(alertSystemVo);
}
@PostMapping(value = "saveOrUpdate")
@PostMapping( "saveOrUpdate")
public Result<?> saveOrUpdate(@RequestBody GardsAlertSystem alertSystem) {
return alertSystemService.saveOrUpdate1(alertSystem);
}
@DeleteMapping(value = "delete")
@DeleteMapping( "delete")
public Result<?> delete(@RequestParam("id") String id) {
return alertSystemService.delete(id);
}
@DeleteMapping(value = "deleteBatch")
@DeleteMapping( "deleteBatch")
public Result<?> deleteBatch(@RequestParam("ids") String ids) {
return alertSystemService.delete(ids);
}
@GetMapping("codeMap")
public Map<String, String> codeMap(){
return alertSystemService.codeMap();
}
}

View File

@ -6,6 +6,8 @@ import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.base.bizVo.AlertSystemVo;
import org.jeecg.modules.base.entity.configuration.GardsAlertSystem;
import java.util.Map;
public interface IGardsAlertSystemService extends IService<GardsAlertSystem> {
Result<?> findPage(AlertSystemVo alertSystemVo);
@ -15,4 +17,6 @@ public interface IGardsAlertSystemService extends IService<GardsAlertSystem> {
Result<?> delete(String id);
Result<?> deleteBatch(String ids);
Map<String, String> codeMap();
}

View File

@ -4,17 +4,20 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.DictConstant;
import org.jeecg.common.constant.Prompt;
import org.jeecg.common.system.vo.DictModel;
import org.jeecg.modules.base.bizVo.AlertSystemVo;
import org.jeecg.modules.base.entity.configuration.GardsAlertSystem;
import org.jeecg.modules.system.mapper.GardsAlertSystemMapper;
import org.jeecg.modules.system.service.IGardsAlertSystemService;
import org.jeecgframework.minidao.datasource.DataSourceContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
@ -44,7 +47,9 @@ public class GardsAlertSystemServiceImpl extends ServiceImpl<GardsAlertSystemMap
wrapper.like(StrUtil.isNotBlank(code), GardsAlertSystem::getCode, code);
wrapper.like(StrUtil.isNotBlank(content), GardsAlertSystem::getContent, content);
page = this.page(page, wrapper);
List<DictModel> items = dictService.getItems("");
// 手动切换为主数据源
DynamicDataSourceContextHolder.push("master");
List<DictModel> items = dictService.getItems(DictConstant.ALERT_SYSTEM_CODE);
Map<String, String> typeMap = items.stream().collect(Collectors
.toMap(DictModel::getValue, DictModel::getText, (oldValue, newValue) -> newValue));
page.getRecords().forEach(item -> {
@ -84,4 +89,9 @@ public class GardsAlertSystemServiceImpl extends ServiceImpl<GardsAlertSystemMap
return Result.OK(Prompt.DELETE_SUCC);
return Result.OK(Prompt.DELETE_ERR);
}
@Override
public Map<String, String> codeMap() {
return this.list().stream().collect(Collectors.toMap(GardsAlertSystem::getCode, GardsAlertSystem::getContent));
}
}

View File

@ -0,0 +1,16 @@
package org.jeecg.modules.feignclient;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import java.util.Map;
@Component
@FeignClient("armd-system")
public interface SystemClient {
/* GardsAlertSystemController下相关接口 */
@GetMapping("/sys/alertSystem/codeMap")
Map<String, String> codeMap();
}

View File

@ -1,8 +1,11 @@
package org.jeecg.modules.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.ReUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -15,6 +18,7 @@ import org.jeecg.common.util.ExportUtil;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.modules.entity.GardsAlertDataWeb;
import org.jeecg.modules.entity.GardsSohDataWeb;
import org.jeecg.modules.feignclient.SystemClient;
import org.jeecg.modules.mapper.GardsAlertDataMapper;
import org.jeecg.modules.mapper.GardsSohDataMapper;
import org.jeecg.modules.service.IGardsSohDataService;
@ -28,6 +32,7 @@ import java.io.IOException;
import java.io.OutputStream;
import java.text.ParseException;
import java.util.*;
import java.util.stream.Collectors;
@Service("gardsSohDataService")
@DS("ora")
@ -35,6 +40,10 @@ public class GardsSohDataServiceImpl extends ServiceImpl<GardsSohDataMapper, Gar
@Autowired
private RedisUtil redisUtil;
@Autowired
private SystemClient systemClient;
@Autowired
private GardsAlertDataMapper gardsAlertDataMapper;
@ -112,9 +121,29 @@ public class GardsSohDataServiceImpl extends ServiceImpl<GardsSohDataMapper, Gar
queryWrapper.le(GardsAlertDataWeb::getTime, endDate);
queryWrapper.orderByDesc(GardsAlertDataWeb::getTime);
Page<GardsAlertDataWeb> alertDataPage = gardsAlertDataMapper.selectPage(page, queryWrapper);
result.setSuccess(true);
result.setResult(alertDataPage);
return result;
List<GardsAlertDataWeb> records = alertDataPage.getRecords();
if (CollUtil.isEmpty(records))
return Result.OK(alertDataPage);
// 获取Map(key: code, value: code对应内容)
Map<String, String> codeMap = systemClient.codeMap();
String flag = "Error code: ";
String regex = flag + "(\\S+)";
for (GardsAlertDataWeb record : records) {
String alertType = record.getAlertType();
if (!StrUtil.equals(alertType, "ALERT_SYSTEM"))
continue;
String alertText = record.getAlertText();
if (!StrUtil.contains(alertText, flag))
continue;
// 获取code并通过code获取对应code内容
String code = ReUtil.getGroup1(regex, alertText);
String replace = flag + codeMap.get(code);
String replaced = ReUtil.getGroup0(regex, alertText);
// 将code替换为对应内容
alertText = StrUtil.replace(alertText, replaced, replace);
record.setAlertText(alertText);
}
return Result.OK(alertDataPage);
} catch (ParseException e) {
throw new RuntimeException(e);
}