|
@@ -24,6 +24,7 @@ import org.json.JSONArray;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
@@ -34,24 +35,25 @@ import java.util.Map;
|
|
|
* @version V1.0 2021-09-08 22:30:38
|
|
|
*/
|
|
|
@Service
|
|
|
-public class AlarmConditionServiceImpl extends ServiceImpl<AlarmConditionMapper, AlarmCondition>
|
|
|
- implements IAlarmConditionService {
|
|
|
-
|
|
|
+public class AlarmConditionServiceImpl extends ServiceImpl<AlarmConditionMapper, AlarmCondition>
|
|
|
+ implements IAlarmConditionService {
|
|
|
+
|
|
|
/**
|
|
|
- * 创建报警条件
|
|
|
- * @return 报警条件主键
|
|
|
- * @author lixing
|
|
|
- * @version V1.0 2021-09-08 22:30:38
|
|
|
- */
|
|
|
+ * 创建报警条件
|
|
|
+ *
|
|
|
+ * @return 报警条件主键
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-09-08 22:30:38
|
|
|
+ */
|
|
|
@Override
|
|
|
public String createAlarmCondition(AddAlarmConditionDTO addAlarmConditionDTO) {
|
|
|
AlarmCondition alarmCondition = ConvertAlarmConditionTool.INSTANCE.convertAddDto2Entity(addAlarmConditionDTO);
|
|
|
List<List<CalculateMethodDTO>> frontend = addAlarmConditionDTO.getFrontend();
|
|
|
- Map<String, String> infoCodes = addAlarmConditionDTO.getInfoCodes();
|
|
|
- String frontJson = JSON.toJSONString(frontend);
|
|
|
- alarmCondition.setFrontend(frontJson);
|
|
|
+ addAlarmConditionDTO.getInfoCodes();
|
|
|
+ Object json = JSON.toJSON(frontend);
|
|
|
+ alarmCondition.setFrontend(json);
|
|
|
//将前端公式转换成后台公式
|
|
|
- String backend = frontend2Backend(frontend,infoCodes);
|
|
|
+ String backend = frontend2Backend(frontend);
|
|
|
alarmCondition.setBackend(backend);
|
|
|
// 设置默认值
|
|
|
setDefaultValue(alarmCondition);
|
|
@@ -59,25 +61,24 @@ public class AlarmConditionServiceImpl extends ServiceImpl<AlarmConditionMapper,
|
|
|
return alarmCondition.getId();
|
|
|
}
|
|
|
|
|
|
- private String frontend2Backend(List<List<CalculateMethodDTO>> frontend, Map<String, String> infoCodes) {
|
|
|
-
|
|
|
+ private String frontend2Backend(List<List<CalculateMethodDTO>> frontend) {
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
for (List<CalculateMethodDTO> calculateMethodDTOS : frontend) {
|
|
|
- StringBuffer sb = new StringBuffer();
|
|
|
-
|
|
|
+ StringBuffer calculateString = new StringBuffer();
|
|
|
for (CalculateMethodDTO calculateMethodDTO : calculateMethodDTOS) {
|
|
|
- StringBuffer calculateString = new StringBuffer();
|
|
|
calculateString.append("(")
|
|
|
.append(calculateMethodDTO.getMonitorIndicatorId())
|
|
|
- .append(calculateMethodDTO.getOperator())
|
|
|
- .append(calculateMethodDTO.getFormula()).append(") &&");
|
|
|
- sb.append(calculateString);
|
|
|
+ .append(calculateMethodDTO.getOperator())
|
|
|
+ .append(calculateMethodDTO.getFormula()).append(")")
|
|
|
+ .append(" && ");
|
|
|
}
|
|
|
-
|
|
|
+ sb.append(calculateString.substring(0,calculateString.length()-4)).append(" || ");
|
|
|
}
|
|
|
+ String substring = sb.substring(0, sb.length() - 4);
|
|
|
// for (Map.Entry<String, String> entry : infoCodes.entrySet()) {
|
|
|
// calculateString.toString().replace(entry.getKey(),entry.getValue());
|
|
|
// }
|
|
|
- return null;
|
|
|
+ return substring;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -89,18 +90,22 @@ public class AlarmConditionServiceImpl extends ServiceImpl<AlarmConditionMapper,
|
|
|
*/
|
|
|
private void setDefaultValue(AlarmCondition alarmCondition) {
|
|
|
alarmCondition.setCreator(PoemsContext.getContext().getUserId());
|
|
|
+ alarmCondition.setCreationTime(new Date());
|
|
|
+ alarmCondition.setModifiedTime(new Date());
|
|
|
+ alarmCondition.setModifier(PoemsContext.getContext().getUserId());
|
|
|
alarmCondition.setId(DataUtils.getUUID());
|
|
|
// todo 其他默认的属性
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
- * 报警条件详情
|
|
|
- * @param id 主键
|
|
|
- * @return 部门do类
|
|
|
- * @author lixing
|
|
|
- * @version V1.0 2021-09-08 22:30:38
|
|
|
- */
|
|
|
+ * 报警条件详情
|
|
|
+ *
|
|
|
+ * @param id 主键
|
|
|
+ * @return 部门do类
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-09-08 22:30:38
|
|
|
+ */
|
|
|
@Override
|
|
|
public AlarmCondition queryAlarmConditionDetail(String id) {
|
|
|
AlarmCondition alarmCondition = getById(id);
|
|
@@ -109,20 +114,28 @@ public class AlarmConditionServiceImpl extends ServiceImpl<AlarmConditionMapper,
|
|
|
}
|
|
|
return alarmCondition;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
- * 更新报警条件
|
|
|
- * @author lixing
|
|
|
- * @version V1.0 2021-09-08 22:30:38
|
|
|
- */
|
|
|
+ * 更新报警条件
|
|
|
+ *
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-09-08 22:30:38
|
|
|
+ */
|
|
|
@Override
|
|
|
public void updateAlarmCondition(UpdateAlarmConditionDTO updateAlarmConditionDTO) {
|
|
|
AlarmCondition alarmCondition = getById(updateAlarmConditionDTO.getId());
|
|
|
alarmCondition = ConvertAlarmConditionTool.INSTANCE.convertUpdateDto2Entity(alarmCondition, updateAlarmConditionDTO);
|
|
|
alarmCondition.setModifier(PoemsContext.getContext().getUserId());
|
|
|
+ List<List<CalculateMethodDTO>> frontend = updateAlarmConditionDTO.getFrontend();
|
|
|
+ //Map<String, String> infoCodes = updateAlarmConditionDTO.getInfoCodes();
|
|
|
+ String frontJson = JSON.toJSONString(frontend);
|
|
|
+ alarmCondition.setFrontend(frontJson);
|
|
|
+ //将前端公式转换成后台公式
|
|
|
+ String backend = frontend2Backend(frontend);
|
|
|
+ alarmCondition.setBackend(backend);
|
|
|
updateById(alarmCondition);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 校验报警条件是否可删除
|
|
|
*
|
|
@@ -144,109 +157,111 @@ public class AlarmConditionServiceImpl extends ServiceImpl<AlarmConditionMapper,
|
|
|
|
|
|
return alarmCondition;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
- * 删除报警条件
|
|
|
- * @param id 主键
|
|
|
- * @author lixing
|
|
|
- * @version V1.0 2021-09-08 22:30:38
|
|
|
- */
|
|
|
+ * 删除报警条件
|
|
|
+ *
|
|
|
+ * @param id 主键
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-09-08 22:30:38
|
|
|
+ */
|
|
|
@Override
|
|
|
public void deleteAlarmCondition(String id) {
|
|
|
// 校验是否可删除
|
|
|
AlarmCondition alarmCondition = checkDeletable(id);
|
|
|
-
|
|
|
alarmCondition.setValid(ValidEnum.FALSE.getType());
|
|
|
updateById(alarmCondition);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
- * 查询报警条件
|
|
|
- * @return List<AlarmCondition>
|
|
|
- * @author lixing
|
|
|
- * @version V1.0 2021-09-08 22:30:38
|
|
|
- */
|
|
|
+ * 查询报警条件
|
|
|
+ *
|
|
|
+ * @return List<AlarmCondition>
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-09-08 22:30:38
|
|
|
+ */
|
|
|
@Override
|
|
|
public List<AlarmCondition> queryAlarmConditionList(QueryAlarmConditionDTO queryAlarmConditionDTO) {
|
|
|
QueryWrapper<AlarmCondition> queryWrapper = new QueryWrapper<>();
|
|
|
queryWrapper.eq(AlarmCondition.PROP_VALID, ValidEnum.TRUE.getType());
|
|
|
// 默认按创建时间倒序排序
|
|
|
queryWrapper.orderBy(true, false, AlarmCondition.PROP_CREATIONTIME);
|
|
|
-
|
|
|
+
|
|
|
if (queryAlarmConditionDTO != null) {
|
|
|
-
|
|
|
+
|
|
|
if (queryAlarmConditionDTO.getInfoCodes() != null) {
|
|
|
queryWrapper.eq(AlarmCondition.PROP_INFO_CODES, queryAlarmConditionDTO.getInfoCodes());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (queryAlarmConditionDTO.getFrontend() != null) {
|
|
|
queryWrapper.eq(AlarmCondition.PROP_FRONTEND, queryAlarmConditionDTO.getFrontend());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (queryAlarmConditionDTO.getBackend() != null) {
|
|
|
queryWrapper.eq(AlarmCondition.PROP_BACKEND, queryAlarmConditionDTO.getBackend());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (queryAlarmConditionDTO.getTriggerUphold() != null) {
|
|
|
queryWrapper.eq(AlarmCondition.PROP_TRIGGER_UPHOLD, queryAlarmConditionDTO.getTriggerUphold());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// todo 需判断使用like还是eq
|
|
|
if (StringUtils.isNotEmpty(queryAlarmConditionDTO.getAlarmLevel())) {
|
|
|
queryWrapper.like(AlarmCondition.PROP_ALARM_LEVEL, queryAlarmConditionDTO.getAlarmLevel());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return list(queryWrapper);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
- * 分页查询报警条件
|
|
|
- * @return IPage<AlarmCondition>
|
|
|
- * @author lixing
|
|
|
- * @version V1.0 2021-09-08 22:30:38
|
|
|
- */
|
|
|
+ * 分页查询报警条件
|
|
|
+ *
|
|
|
+ * @return IPage<AlarmCondition>
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-09-08 22:30:38
|
|
|
+ */
|
|
|
@Override
|
|
|
public IPage<AlarmCondition> pageQueryAlarmCondition(PageQueryAlarmConditionDTO pageQueryAlarmConditionDTO) {
|
|
|
QueryWrapper<AlarmCondition> queryWrapper = new QueryWrapper<>();
|
|
|
queryWrapper.eq(AlarmCondition.PROP_VALID, ValidEnum.TRUE.getType());
|
|
|
// 这里认为pageQueryDTO是经过校验的,肯定包含分页信息
|
|
|
- IPage<AlarmCondition> pageParam = new Page<>(pageQueryAlarmConditionDTO.getPage(), pageQueryAlarmConditionDTO.getSize(),true);
|
|
|
+ IPage<AlarmCondition> pageParam = new Page<>(pageQueryAlarmConditionDTO.getPage(), pageQueryAlarmConditionDTO.getSize(), true);
|
|
|
// 排序信息
|
|
|
- if(CollectionUtils.isEmpty(pageQueryAlarmConditionDTO.getOrders())){
|
|
|
+ if (CollectionUtils.isEmpty(pageQueryAlarmConditionDTO.getOrders())) {
|
|
|
// 默认按创建时间倒序排序
|
|
|
queryWrapper.orderBy(true, false, AlarmCondition.PROP_CREATIONTIME);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
List<Sort> orders = pageQueryAlarmConditionDTO.getOrders();
|
|
|
- for(Sort sort: orders) {
|
|
|
+ for (Sort sort : orders) {
|
|
|
// 将驼峰转换为下划线格式
|
|
|
- sort.setColumn(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE,sort.getColumn()));
|
|
|
+ sort.setColumn(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, sort.getColumn()));
|
|
|
queryWrapper.orderBy(true, sort.isAsc(), sort.getColumn());
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (pageQueryAlarmConditionDTO.getInfoCodes() != null) {
|
|
|
queryWrapper.eq(AlarmCondition.PROP_INFO_CODES, pageQueryAlarmConditionDTO.getInfoCodes());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (pageQueryAlarmConditionDTO.getFrontend() != null) {
|
|
|
queryWrapper.eq(AlarmCondition.PROP_FRONTEND, pageQueryAlarmConditionDTO.getFrontend());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (pageQueryAlarmConditionDTO.getBackend() != null) {
|
|
|
queryWrapper.eq(AlarmCondition.PROP_BACKEND, pageQueryAlarmConditionDTO.getBackend());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (pageQueryAlarmConditionDTO.getTriggerUphold() != null) {
|
|
|
queryWrapper.eq(AlarmCondition.PROP_TRIGGER_UPHOLD, pageQueryAlarmConditionDTO.getTriggerUphold());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// todo 需判断使用like还是eq
|
|
|
if (StringUtils.isNotEmpty(pageQueryAlarmConditionDTO.getAlarmLevel())) {
|
|
|
queryWrapper.like(AlarmCondition.PROP_ALARM_LEVEL, pageQueryAlarmConditionDTO.getAlarmLevel());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return getBaseMapper().selectPage(pageParam, queryWrapper);
|
|
|
}
|
|
|
}
|