歧义值管理 全局规则和测站规则缓存修改, 规则修改缓存清理修改,测站规则绑定缓存清理修改,歧异值判断接口测试修改, 规则查询修改
parent
cdd4f29989
commit
ac7e31bc23
|
|
@ -30,8 +30,8 @@ public class Knife4jConfiguration {
|
|||
|
||||
private ApiInfo getApiInfoBuilder() {
|
||||
return new ApiInfoBuilder()
|
||||
.title("奇异值管理api")
|
||||
.description("# 奇异值管理api RESTful APIs")
|
||||
.title("歧义数据管理api")
|
||||
.description("# 歧义数据管理api RESTful APIs")
|
||||
.termsOfServiceUrl("http://219.138.108.99:19000/jszx")
|
||||
.contact(new Contact("湖北纬皓端成", null, null))
|
||||
.version("1.0")
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package com.whdc.controller;
|
||||
|
||||
|
||||
import com.whdc.model.bean.ItemType;
|
||||
import com.whdc.model.dto.FindRuleDto;
|
||||
import com.whdc.model.entity.ERule;
|
||||
import com.whdc.model.entity.EStationRules;
|
||||
|
|
@ -10,11 +9,11 @@ import com.whdc.model.group.Update;
|
|||
import com.whdc.service.IERuleService;
|
||||
import com.whdc.service.IEStationRulesService;
|
||||
import com.whdc.utils.ResultJson;
|
||||
import com.whdc.valid.bean.ItemType;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
|
@ -28,7 +27,7 @@ import java.util.Objects;
|
|||
@Slf4j
|
||||
@Api(tags = "规则管理 - Controller")
|
||||
@RestController
|
||||
@RequestMapping("/v2/eRule")
|
||||
@RequestMapping("/eRule")
|
||||
public class ERuleController {
|
||||
|
||||
@Autowired
|
||||
|
|
@ -68,9 +67,12 @@ public class ERuleController {
|
|||
}
|
||||
|
||||
if (
|
||||
StringUtils.isBlank(model.getDiffMax())
|
||||
&& StringUtils.isBlank(model.getMin())
|
||||
&& StringUtils.isBlank(model.getMax())
|
||||
Objects.isNull(model.getDiffMax())
|
||||
&& Objects.isNull(model.getMin())
|
||||
&& Objects.isNull(model.getMax())
|
||||
&& Objects.isNull(model.getDuration())
|
||||
&& Objects.isNull(model.getLagTime())
|
||||
&& Objects.isNull(model.getLeadingTime())
|
||||
){
|
||||
return ResultJson.error("请设置规则");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.whdc.controller;
|
||||
|
||||
|
||||
import com.whdc.model.dto.ERuleDtoTest;
|
||||
import com.whdc.model.dto.FindStationDto;
|
||||
import com.whdc.model.entity.EStationRules;
|
||||
import com.whdc.model.group.Insert;
|
||||
|
|
@ -8,6 +9,7 @@ import com.whdc.model.group.Update;
|
|||
import com.whdc.service.IERuleService;
|
||||
import com.whdc.service.IEStationRulesService;
|
||||
import com.whdc.utils.ResultJson;
|
||||
import com.whdc.valid.service.ValidateService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
|
|
@ -23,7 +25,7 @@ import java.util.Objects;
|
|||
*/
|
||||
@Api(tags = "站点规则管理 - Controller")
|
||||
@RestController
|
||||
@RequestMapping("/v2/eStationRule")
|
||||
@RequestMapping("/eStationRule")
|
||||
public class EStationRulesController {
|
||||
|
||||
@Autowired
|
||||
|
|
@ -109,4 +111,13 @@ public class EStationRulesController {
|
|||
return ResultJson.ok(ieStationRulesService.removeById(id,model));
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private ValidateService validateService;
|
||||
|
||||
@ApiOperation(value = "规则测试 ")
|
||||
@PostMapping(value = "testRule")
|
||||
public ResultJson testRule(@RequestBody ERuleDtoTest test) {
|
||||
return ResultJson.ok(validateService.validate(test.getStr() ,test.getOldStr()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import org.apache.commons.lang3.StringUtils;
|
|||
import javax.validation.constraints.Max;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
|
|
@ -59,7 +60,7 @@ public class ERule extends Model<ERule> {
|
|||
*/
|
||||
@ApiParam(value = "规则类型", required = true, example = "")
|
||||
@ApiModelProperty(value = "规则类型", required = true, dataType = "String")
|
||||
@TableField(value = "ITEM", updateStrategy = FieldStrategy.NOT_EMPTY)
|
||||
@TableField(value = "ITEM", updateStrategy = FieldStrategy.IGNORED)
|
||||
@NotEmpty(message = "规则类型不能为空", groups = {Insert.class,Update.class})
|
||||
@Max(50)
|
||||
private String item;
|
||||
|
|
@ -77,34 +78,34 @@ public class ERule extends Model<ERule> {
|
|||
* 最小值
|
||||
*/
|
||||
@ApiParam(value = "最小值", required = false, example = "")
|
||||
@ApiModelProperty(value = "最小值", required = false, dataType = "String")
|
||||
@TableField(value = "MIN", updateStrategy = FieldStrategy.NOT_EMPTY)
|
||||
@ApiModelProperty(value = "最小值", required = false, dataType = "Numeric")
|
||||
@TableField(value = "MIN", updateStrategy = FieldStrategy.IGNORED)
|
||||
@Max(50)
|
||||
private String min;
|
||||
private BigDecimal min;
|
||||
|
||||
/**
|
||||
* 最大值
|
||||
*/
|
||||
@ApiParam(value = "最大值", required = false, example = "")
|
||||
@ApiModelProperty(value = "最大值", required = false, dataType = "String")
|
||||
@TableField(value = "MAX", updateStrategy = FieldStrategy.NOT_EMPTY)
|
||||
@ApiModelProperty(value = "最大值", required = false, dataType = "Numeric")
|
||||
@TableField(value = "MAX", updateStrategy = FieldStrategy.IGNORED)
|
||||
@Max(50)
|
||||
private String max;
|
||||
private BigDecimal max;
|
||||
|
||||
/**
|
||||
* 最大值
|
||||
*/
|
||||
@ApiParam(value = "两条数据之间的最大差值", required = false, example = "")
|
||||
@ApiModelProperty(value = "两条数据之间的最大差值", required = false, dataType = "String")
|
||||
@TableField(value = "DIFF_MAX", updateStrategy = FieldStrategy.NOT_EMPTY)
|
||||
private String diffMax;
|
||||
@ApiModelProperty(value = "两条数据之间的最大差值", required = false, dataType = "Numeric")
|
||||
@TableField(value = "DIFF_MAX", updateStrategy = FieldStrategy.IGNORED)
|
||||
private BigDecimal diffMax;
|
||||
|
||||
/**
|
||||
* 最大值
|
||||
*/
|
||||
@ApiParam(value = "时间段, 单位 s", required = false, example = "")
|
||||
@ApiModelProperty(value = "时间段, 单位 s", required = false, dataType = "Integer")
|
||||
@TableField(value = "DURATION", updateStrategy = FieldStrategy.NOT_EMPTY)
|
||||
@ApiModelProperty(value = "时间段, 单位 s", required = false, dataType = "Numeric")
|
||||
@TableField(value = "DURATION", updateStrategy = FieldStrategy.IGNORED)
|
||||
@Max(10)
|
||||
private Integer duration;
|
||||
|
||||
|
|
@ -112,8 +113,8 @@ public class ERule extends Model<ERule> {
|
|||
* 接收超出时间,单位: s ,指接收时间超前范围
|
||||
*/
|
||||
@ApiParam(value = "接收超前时间,单位: s ,指接收时间超前范围", required = false, example = "")
|
||||
@ApiModelProperty(value = "接收超前时间,单位: s ,指接收时间超前范围", required = false, dataType = "Integer")
|
||||
@TableField(value = "LEADING_TIME", updateStrategy = FieldStrategy.NOT_EMPTY)
|
||||
@ApiModelProperty(value = "接收超前时间,单位: s ,指接收时间超前范围", required = false, dataType = "Numeric")
|
||||
@TableField(value = "LEADING_TIME", updateStrategy = FieldStrategy.IGNORED)
|
||||
@Max(10)
|
||||
private Integer leadingTime;
|
||||
|
||||
|
|
@ -121,8 +122,8 @@ public class ERule extends Model<ERule> {
|
|||
* 接收滞后时间,单位: s ,指接收时间滞后范围
|
||||
*/
|
||||
@ApiParam(value = "接收滞后时间,单位: s ,指接收时间滞后范围", required = false, example = "")
|
||||
@ApiModelProperty(value = "接收滞后时间,单位: s ,指接收时间滞后范围", required = false, dataType = "Integer")
|
||||
@TableField(value = "LAG_TIME", updateStrategy = FieldStrategy.NOT_EMPTY)
|
||||
@ApiModelProperty(value = "接收滞后时间,单位: s ,指接收时间滞后范围", required = false, dataType = "Numeric")
|
||||
@TableField(value = "LAG_TIME", updateStrategy = FieldStrategy.IGNORED)
|
||||
@Max(10)
|
||||
private Integer lagTime;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,72 @@
|
|||
package com.whdc.valid.bean;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author xusan
|
||||
* @date 2023年3月22日10:32:54
|
||||
* @description: 雨量值时间规则
|
||||
*/
|
||||
public enum IntvType {
|
||||
|
||||
IT001(300, "0.05"),
|
||||
IT002(300, "0.08"),
|
||||
IT003(3600, "1");
|
||||
|
||||
private Integer name;
|
||||
private String value;
|
||||
|
||||
public Integer getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(Integer name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
IntvType(Integer name, String value) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static List<JSONObject> list() {
|
||||
List<JSONObject> list = new ArrayList<>();
|
||||
IntvType[] values = IntvType.values();
|
||||
for (IntvType type : values) {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("name", type.getName());
|
||||
obj.put("value", type.getValue());
|
||||
list.add(obj);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static Map<String, IntvType> map() {
|
||||
Map<String, IntvType> map = new HashMap<>();
|
||||
IntvType[] values = IntvType.values();
|
||||
for (IntvType e : values) {
|
||||
map.put(e.getValue(), e);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static IntvType getByValue(String value) {
|
||||
if (StringUtils.isEmpty(value)) return null;
|
||||
return map().get(value);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.whdc.model.bean;
|
||||
package com.whdc.valid.bean;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
|
@ -18,7 +18,8 @@ public enum ItemType {
|
|||
|
||||
YU_LIANG("雨量", "P"),
|
||||
SHUI_WEI("水位", "Z"),
|
||||
LIU_LIANG("流量", "Q");
|
||||
LIU_LIANG("流量", "Q"),
|
||||
TONG_YONG("通用", "ALL");
|
||||
|
||||
private String name;
|
||||
private String value;
|
||||
|
|
@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
|
@ -26,7 +27,9 @@ public class RuleRedisService {
|
|||
|
||||
public List<ValidateVo> getRule(String stcd,ValidateMapper validateMapper) {
|
||||
|
||||
log.info("获取规则: " + stcd);
|
||||
List<ValidateVo> rules = null;
|
||||
|
||||
log.info("获取规则: {}" , stcd);
|
||||
|
||||
String key = VALIDATE_REDIS_KEY + stcd;
|
||||
|
||||
|
|
@ -35,29 +38,48 @@ public class RuleRedisService {
|
|||
List<String> json = ruleRedisTemplate.opsForList().range(key, 0, -1);
|
||||
|
||||
if (CollectionUtils.isNotEmpty(json)) {
|
||||
return
|
||||
json.stream()
|
||||
|
||||
rules = json.stream()
|
||||
.filter(StringUtils::isNotBlank)
|
||||
.map(s -> JSON.toJavaObject(JSON.parseObject(s), ValidateVo.class))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
List<ValidateVo> rules = validateMapper.getRuleByStcd(stcd);
|
||||
|
||||
}
|
||||
}else{
|
||||
rules = validateMapper.getRuleByStcd(stcd);
|
||||
|
||||
log.info("保存规则: " + rules.size());
|
||||
|
||||
if (CollectionUtils.isNotEmpty(rules)) {
|
||||
if (CollectionUtils.isEmpty(rules)) {
|
||||
rules = new ArrayList<>();
|
||||
|
||||
// 添加空号缓存
|
||||
rules.add(new ValidateVo());
|
||||
}
|
||||
|
||||
Long aLong = ruleRedisTemplate.opsForList().rightPushAll(key, rules.stream().map(JSON::toJSONString).collect(Collectors.toList()));
|
||||
|
||||
if (aLong != rules.size()) {
|
||||
log.info("保存规则失败: " + key + "_" + rules.size());
|
||||
}
|
||||
} else {
|
||||
ruleRedisTemplate.opsForList().rightPushAll(key, "");
|
||||
}
|
||||
|
||||
|
||||
if (CollectionUtils.isNotEmpty(rules) && JSON.parseObject(JSON.toJSONString(rules.get(0))).isEmpty()){
|
||||
rules.remove(0);
|
||||
}
|
||||
|
||||
|
||||
if (CollectionUtils.isEmpty(rules)) {
|
||||
// 查询通用规则
|
||||
return this.getRule("ALL", validateMapper);
|
||||
|
||||
}
|
||||
|
||||
log.info("获取规则条数: {}" , rules.size());
|
||||
|
||||
|
||||
return rules;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,4 +21,5 @@ public interface ValidateMapper {
|
|||
List<ValidateVo> getRuleByStcd(String stcd);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,9 @@ public class ValidateDto implements Serializable {
|
|||
@ApiModelProperty(value = "监测时间", dataType = "java.lang.Date")
|
||||
private Date tm;
|
||||
|
||||
@ApiModelProperty(value = "累计时间", dataType = "java.lang.Date")
|
||||
private String intv;
|
||||
|
||||
private Data data;
|
||||
|
||||
@lombok.Data
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ public class ValidateVo implements Serializable {
|
|||
private BigDecimal max;
|
||||
|
||||
/**
|
||||
* 最大值
|
||||
* 差值
|
||||
*/
|
||||
@ApiParam(value = "两条数据之间的最大差值", required = false, example = "")
|
||||
@ApiModelProperty(value = "两条数据之间的最大差值", required = false, dataType = "String")
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@ package com.whdc.valid.service;
|
|||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONException;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.whdc.model.bean.ItemType;
|
||||
import com.whdc.valid.bean.IntvType;
|
||||
import com.whdc.valid.bean.ItemType;
|
||||
import com.whdc.valid.component.RuleRedisService;
|
||||
import com.whdc.valid.mapper.ValidateMapper;
|
||||
import com.whdc.valid.model.ValidateDto;
|
||||
|
|
@ -20,7 +21,7 @@ import java.util.List;
|
|||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.whdc.model.bean.ItemType.getByValue;
|
||||
import static com.whdc.valid.bean.ItemType.getByValue;
|
||||
import static com.whdc.valid.error.MyException.getException;
|
||||
|
||||
|
||||
|
|
@ -128,7 +129,7 @@ public class ValidateServiceImpl implements ValidateService {
|
|||
continue;
|
||||
}
|
||||
|
||||
if (Objects.isNull(min) && Objects.isNull(max) && Objects.isNull(leadingTime) && Objects.isNull(lagTime)) {
|
||||
if (Objects.isNull(min) && Objects.isNull(max)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -208,6 +209,9 @@ public class ValidateServiceImpl implements ValidateService {
|
|||
prevDto = getValidateDto(prevJson); // 老差值
|
||||
}
|
||||
|
||||
|
||||
String intv = dto.getIntv();
|
||||
|
||||
ValidateDto.Data data = dto.getData();
|
||||
BigDecimal p = data.getP();
|
||||
BigDecimal z = data.getZ();
|
||||
|
|
@ -235,6 +239,8 @@ public class ValidateServiceImpl implements ValidateService {
|
|||
|
||||
for (ValidateVo vo : rule) {
|
||||
|
||||
Integer duration = vo.getDuration();
|
||||
|
||||
BigDecimal min = vo.getMin();
|
||||
BigDecimal max = vo.getMax();
|
||||
Integer leadingTime = vo.getLeadingTime();
|
||||
|
|
@ -242,7 +248,6 @@ public class ValidateServiceImpl implements ValidateService {
|
|||
String item = vo.getItem();
|
||||
ItemType itemType = getByValue(item);
|
||||
|
||||
if (Objects.nonNull(min) && Objects.nonNull(max) && Objects.nonNull(leadingTime) && Objects.nonNull(lagTime)) {
|
||||
if (Objects.nonNull(leadingTime)) {
|
||||
long time = currentTime + (leadingTime * 1000);
|
||||
if (tm.getTime() > time) {
|
||||
|
|
@ -259,6 +264,8 @@ public class ValidateServiceImpl implements ValidateService {
|
|||
}
|
||||
}
|
||||
|
||||
if (Objects.nonNull(min) || Objects.nonNull(max)) {
|
||||
|
||||
|
||||
if (StringUtils.isBlank(item)) {
|
||||
log.info("规则类型为空");
|
||||
|
|
@ -272,9 +279,24 @@ public class ValidateServiceImpl implements ValidateService {
|
|||
|
||||
switch (itemType) {
|
||||
case YU_LIANG: { // 雨量判断 P
|
||||
|
||||
if (StringUtils.isNotBlank(intv) && Objects.nonNull(duration)){
|
||||
IntvType intvType = IntvType.getByValue(intv);
|
||||
|
||||
if (Objects.nonNull(intvType)){
|
||||
if (Objects.equals(intvType.getName(), duration)) {
|
||||
if (!rangeRuleValidate(p, min, max)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
|
||||
if (!rangeRuleValidate(p, min, max)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
@ -321,7 +343,7 @@ public class ValidateServiceImpl implements ValidateService {
|
|||
Date oldTm = prevDto.getTm();
|
||||
|
||||
BigDecimal diffMax = vo.getDiffMax();
|
||||
Integer duration = vo.getDuration();
|
||||
|
||||
|
||||
if (Objects.nonNull(duration)) {
|
||||
|
||||
|
|
@ -334,6 +356,10 @@ public class ValidateServiceImpl implements ValidateService {
|
|||
continue;
|
||||
}
|
||||
|
||||
if (Objects.isNull(diffMax)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (itemType) {
|
||||
case YU_LIANG: { // 雨量判断 P
|
||||
if (Objects.nonNull(p) && Objects.nonNull(oldP) && Math.abs(p.subtract(oldP).doubleValue()) > diffMax.doubleValue()) {
|
||||
|
|
|
|||
|
|
@ -6,12 +6,12 @@ spring:
|
|||
datasource:
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
driver-class-name: dm.jdbc.driver.DmDriver
|
||||
# url: jdbc:dm://127.0.0.1:5236?schema=SYSDBA
|
||||
# username: SYSDBA
|
||||
# password: 199999999
|
||||
url: jdbc:dm://10.42.6.247:5236?schema=SHZH
|
||||
username: SHZH
|
||||
password: Shzh_890
|
||||
url: jdbc:dm://127.0.0.1:5236?schema=SYSDBA
|
||||
username: SYSDBA
|
||||
password: 199999999
|
||||
# url: jdbc:dm://10.42.6.247:5236?schema=SHZH
|
||||
# username: SHZH
|
||||
# password: Shzh_890
|
||||
druid:
|
||||
initialSize: 5
|
||||
minIdle: 5
|
||||
|
|
@ -35,17 +35,17 @@ spring:
|
|||
# Redis
|
||||
redis:
|
||||
database: 5
|
||||
host: 10.42.6.75
|
||||
# host: 127.0.0.1
|
||||
# host: 10.42.6.75
|
||||
host: 127.0.0.1
|
||||
port: 6379
|
||||
# password:
|
||||
password: Whdc_890
|
||||
password:
|
||||
# password: Whdc_890
|
||||
|
||||
# 数据清洗专用redis
|
||||
redisRules:
|
||||
database: 6
|
||||
host: 10.42.6.75
|
||||
# host: 127.0.0.1
|
||||
# host: 10.42.6.75
|
||||
host: 127.0.0.1
|
||||
port: 6379
|
||||
# password: Whdc_890
|
||||
password:
|
||||
|
|
|
|||
Loading…
Reference in New Issue