|
@@ -0,0 +1,194 @@
|
|
|
+package com.sooka.sponest.data.housingconstruction.service.impl;
|
|
|
+
|
|
|
+import com.ruoyi.common.core.utils.DateUtils;
|
|
|
+import com.ruoyi.common.core.utils.uuid.IdUtils;
|
|
|
+import com.ruoyi.common.datascope.annotation.DataScopeMutiDept;
|
|
|
+import com.ruoyi.common.security.utils.SecurityUtils;
|
|
|
+import com.sooka.sponest.data.base.service.impl.BaseServiceImpl;
|
|
|
+import com.sooka.sponest.data.housingconstruction.domain.CenterdataTHousingconstructionStoragetank;
|
|
|
+import com.sooka.sponest.data.housingconstruction.domain.CenterdataTHousingconstructionStoragetankLog;
|
|
|
+import com.sooka.sponest.data.housingconstruction.domain.eventEntity.SensorEventVo;
|
|
|
+import com.sooka.sponest.data.housingconstruction.domain.eventEntity.StaticEntity;
|
|
|
+import com.sooka.sponest.data.housingconstruction.feignClient.service.RemoteHousingconstructionEventService;
|
|
|
+import com.sooka.sponest.data.housingconstruction.mapper.CenterdataTHousingconstructionStoragetankLogMapper;
|
|
|
+import com.sooka.sponest.data.housingconstruction.mapper.CenterdataTHousingconstructionStoragetankMapper;
|
|
|
+import com.sooka.sponest.data.housingconstruction.service.ICenterdataTHousingconstructionStoragetankLogService;
|
|
|
+import org.apache.commons.collections4.MapUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 储罐存储数据日志Service业务层处理
|
|
|
+ *
|
|
|
+ * @author LG
|
|
|
+ * @date 2024-08-02
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class CenterdataTHousingconstructionStoragetankLogServiceImpl extends BaseServiceImpl implements ICenterdataTHousingconstructionStoragetankLogService {
|
|
|
+ @Autowired
|
|
|
+ private CenterdataTHousingconstructionStoragetankLogMapper centerdataTHousingconstructionStoragetankLogMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CenterdataTHousingconstructionStoragetankMapper storagetankMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RemoteHousingconstructionEventService eventService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询储罐存储数据日志
|
|
|
+ *
|
|
|
+ * @param id 储罐存储数据日志主键
|
|
|
+ * @return 储罐存储数据日志
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public CenterdataTHousingconstructionStoragetankLog selectCenterdataTHousingconstructionStoragetankLogById(String id) {
|
|
|
+ return centerdataTHousingconstructionStoragetankLogMapper.selectCenterdataTHousingconstructionStoragetankLogById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询储罐存储数据日志列表
|
|
|
+ *
|
|
|
+ * @param centerdataTHousingconstructionStoragetankLog 储罐存储数据日志
|
|
|
+ * @return 储罐存储数据日志
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @DataScopeMutiDept(deptAlias = "d")
|
|
|
+ public List<CenterdataTHousingconstructionStoragetankLog> selectCenterdataTHousingconstructionStoragetankLogList(CenterdataTHousingconstructionStoragetankLog centerdataTHousingconstructionStoragetankLog) {
|
|
|
+ setSookaDataBase(centerdataTHousingconstructionStoragetankLog);
|
|
|
+ return centerdataTHousingconstructionStoragetankLogMapper.selectCenterdataTHousingconstructionStoragetankLogList(centerdataTHousingconstructionStoragetankLog);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增储罐存储数据日志
|
|
|
+ *
|
|
|
+ * @param storagetankLog 储罐存储数据日志
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int insertCenterdataTHousingconstructionStoragetankLog(CenterdataTHousingconstructionStoragetankLog storagetankLog) {
|
|
|
+ storagetankLog.setId(IdUtils.fastSimpleUUID());
|
|
|
+ storagetankLog.setCreateTime(DateUtils.getNowDate());
|
|
|
+ storagetankLog.setCreateBy(SecurityUtils.getUserId().toString());
|
|
|
+ storagetankLog.setCreateName(SecurityUtils.getLoginUser().getSysUser().getNickName());
|
|
|
+
|
|
|
+ Map<String, Object> storagetank = storagetankMapper.selectStoragetankById(storagetankLog.getStoragetankId());
|
|
|
+ //数据比对
|
|
|
+ dataComparison(storagetankLog, storagetank);
|
|
|
+ return centerdataTHousingconstructionStoragetankLogMapper.insertCenterdataTHousingconstructionStoragetankLog(storagetankLog);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void dataComparison(CenterdataTHousingconstructionStoragetankLog storagetankLog, Map<String, Object> storagetank){
|
|
|
+ //企业名称
|
|
|
+ String enterpriseName = MapUtils.getString(storagetank, "enterpriseName");
|
|
|
+ //储罐名称
|
|
|
+ String storagetankName = MapUtils.getString(storagetank, "name");
|
|
|
+ //设置储罐记录中出现预警的项
|
|
|
+ StringBuilder securityState = new StringBuilder();
|
|
|
+ //设置数值单位
|
|
|
+ List<String> units = Arrays.asList(new String[]{"m", "℃", "PMa", "%LEL"});
|
|
|
+
|
|
|
+ //设置基础模板
|
|
|
+ StringBuilder template = new StringBuilder();
|
|
|
+ template.append(enterpriseName).append("的").append(storagetankName).append("发生");
|
|
|
+
|
|
|
+ //创建事件实体类
|
|
|
+ SensorEventVo sensorEventVo = new SensorEventVo(
|
|
|
+ MapUtils.getString(storagetank, "longitude"),
|
|
|
+ MapUtils.getString(storagetank, "latitude"),
|
|
|
+ MapUtils.getString(storagetank, "enterpriseId"),
|
|
|
+ enterpriseName,
|
|
|
+ new Date(),
|
|
|
+ MapUtils.getString(storagetank, "registeredAddress")
|
|
|
+ );
|
|
|
+
|
|
|
+ //液位上限
|
|
|
+ if(storagetankLog.getLevel() >= MapUtils.getInteger(storagetank, "levelCeiling")){
|
|
|
+ //当前液位高于上限或低于下限, 触发时间告警
|
|
|
+ securityState.append("1").append(",");
|
|
|
+ sendEvent(template.toString(), StaticEntity.LEVEL_CEILING_NAME, MapUtils.getString(storagetank, "levelCeiling") + units.get(0), storagetankLog.getLevel() + units.get(0), sensorEventVo, StaticEntity.LEVEL_CEILING_CODE);
|
|
|
+ }
|
|
|
+
|
|
|
+ //液位下限
|
|
|
+ if(storagetankLog.getLevel() <= MapUtils.getInteger(storagetank, "levelFloor")){
|
|
|
+ //当前液位高于上限或低于下限, 触发时间告警
|
|
|
+ securityState.append("1").append(",");
|
|
|
+ sendEvent(template.toString(), StaticEntity.LEVEL_FLOOR_NAME, MapUtils.getString(storagetank, "levelFloor") + units.get(0), storagetankLog.getLevel() + units.get(0), sensorEventVo, StaticEntity.LEVEL_FLOOR_CODE);
|
|
|
+ }
|
|
|
+
|
|
|
+ //温度
|
|
|
+ if(storagetankLog.getHeat() >= MapUtils.getInteger(storagetank, "heat")){
|
|
|
+ //当前温度高于设定温度阈值
|
|
|
+ securityState.append("2").append(",");
|
|
|
+ sendEvent(template.toString(), StaticEntity.HEAT_NAME, MapUtils.getString(storagetank, "heat") + units.get(1), storagetankLog.getHeat() + units.get(1), sensorEventVo, StaticEntity.HEAT_CODE);
|
|
|
+ }
|
|
|
+
|
|
|
+ //内部气压
|
|
|
+ if(storagetankLog.getPressure() >= MapUtils.getInteger(storagetank, "pressure")){
|
|
|
+ //当前内部气压高于设定阈值
|
|
|
+ securityState.append("3").append(",");
|
|
|
+ sendEvent(template.toString(), StaticEntity.PRESSURE_NAME, MapUtils.getString(storagetank, "pressure") + units.get(2), storagetankLog.getPressure() + units.get(2), sensorEventVo, StaticEntity.PRESSURE_CODE);
|
|
|
+ }
|
|
|
+
|
|
|
+ //可燃气体
|
|
|
+ if(storagetankLog.getGasLeak() >= MapUtils.getInteger(storagetank, "gasLeak")){
|
|
|
+ //可燃性气体泄露值高于设定的阈值
|
|
|
+ securityState.append("4").append(",");
|
|
|
+ sendEvent(template.toString(), StaticEntity.GAS_LEAK_NAME, MapUtils.getString(storagetank, "gasLeak") + units.get(3), storagetankLog.getGasLeak() + units.get(3), sensorEventVo, StaticEntity.GAS_LEAK_CODE);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 确保 StringBuilder 不为空
|
|
|
+ if (securityState.length() > 0) {
|
|
|
+ securityState.deleteCharAt(securityState.length() - 1);
|
|
|
+ }
|
|
|
+ storagetankLog.setSecurityState(securityState.toString());
|
|
|
+ storagetankLog.setDeptId(MapUtils.getLong(storagetank, "deptId"));
|
|
|
+ storagetankLog.setDeptName(MapUtils.getString(storagetank, "deptName"));
|
|
|
+ }
|
|
|
+
|
|
|
+ private void sendEvent(String title, String eventName, String threshold, String current, SensorEventVo eventVo, String eventCode){
|
|
|
+ String template = "%s%s, 设定阈值:%s, 当前值:%s, 请及时处理!";
|
|
|
+ String format = String.format(template, title, eventName, threshold, current);
|
|
|
+ eventVo.setEventTypeXl(eventCode);
|
|
|
+ eventVo.setEventDescription(format);
|
|
|
+ //发送事件
|
|
|
+ eventService.sendEvent(eventVo);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改储罐存储数据日志
|
|
|
+ *
|
|
|
+ * @param centerdataTHousingconstructionStoragetankLog 储罐存储数据日志
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int updateCenterdataTHousingconstructionStoragetankLog(CenterdataTHousingconstructionStoragetankLog centerdataTHousingconstructionStoragetankLog) {
|
|
|
+ centerdataTHousingconstructionStoragetankLog.setUpdateTime(DateUtils.getNowDate());
|
|
|
+ centerdataTHousingconstructionStoragetankLog.setUpdateBy(SecurityUtils.getUserId());
|
|
|
+ centerdataTHousingconstructionStoragetankLog.setUpdateName(SecurityUtils.getLoginUser().getSysUser().getNickName());
|
|
|
+ return centerdataTHousingconstructionStoragetankLogMapper.updateCenterdataTHousingconstructionStoragetankLog(centerdataTHousingconstructionStoragetankLog);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量删除储罐存储数据日志
|
|
|
+ *
|
|
|
+ * @param ids 需要删除的储罐存储数据日志主键
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int deleteCenterdataTHousingconstructionStoragetankLogByIds(String[] ids) {
|
|
|
+ return centerdataTHousingconstructionStoragetankLogMapper.deleteCenterdataTHousingconstructionStoragetankLogByIds(ids);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除储罐存储数据日志信息
|
|
|
+ *
|
|
|
+ * @param id 储罐存储数据日志主键
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int deleteCenterdataTHousingconstructionStoragetankLogById(String id) {
|
|
|
+ return centerdataTHousingconstructionStoragetankLogMapper.deleteCenterdataTHousingconstructionStoragetankLogById(id);
|
|
|
+ }
|
|
|
+}
|