|
|
|
@ -5,7 +5,10 @@ import java.util.Date;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.hw.common.core.constant.Constants;
|
|
|
|
import com.hw.common.core.constant.SecurityConstants;
|
|
|
|
import com.hw.common.core.constant.SecurityConstants;
|
|
|
|
|
|
|
|
import com.hw.common.core.constant.TdEngineConstants;
|
|
|
|
|
|
|
|
import com.hw.common.core.domain.R;
|
|
|
|
import com.hw.common.core.exception.ServiceException;
|
|
|
|
import com.hw.common.core.exception.ServiceException;
|
|
|
|
import com.hw.common.core.utils.DateUtils;
|
|
|
|
import com.hw.common.core.utils.DateUtils;
|
|
|
|
import com.hw.common.core.utils.StringUtils;
|
|
|
|
import com.hw.common.core.utils.StringUtils;
|
|
|
|
@ -18,6 +21,8 @@ import com.hw.tdengine.api.domain.TdField;
|
|
|
|
import com.hw.tdengine.api.domain.TdTableVo;
|
|
|
|
import com.hw.tdengine.api.domain.TdTableVo;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import com.hw.tdengine.api.domain.AlterTagVo;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
@ -79,6 +84,7 @@ public class BaseMonitorInfo1ServiceImpl implements IBaseMonitorInfo1Service {
|
|
|
|
* @param baseMonitorInfo 计量设备信息
|
|
|
|
* @param baseMonitorInfo 计量设备信息
|
|
|
|
* @return 结果
|
|
|
|
* @return 结果
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
//@DS("#header.poolName")
|
|
|
|
//@DS("#header.poolName")
|
|
|
|
public int insertBaseMonitorInfo(BaseMonitorInfo baseMonitorInfo) {
|
|
|
|
public int insertBaseMonitorInfo(BaseMonitorInfo baseMonitorInfo) {
|
|
|
|
@ -89,8 +95,7 @@ public class BaseMonitorInfo1ServiceImpl implements IBaseMonitorInfo1Service {
|
|
|
|
//todo 新增父级为空判断,父级为空时会导致创建子表与创建计量设备与类型的对应对象失效
|
|
|
|
//todo 新增父级为空判断,父级为空时会导致创建子表与创建计量设备与类型的对应对象失效
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
BaseMonitorInfo monitor = baseMonitorInfoMapper.selectBaseMonitorInfoByObjid(baseMonitorInfo.getParentId());
|
|
|
|
BaseMonitorInfo monitor = baseMonitorInfoMapper.selectBaseMonitorInfoByObjid(baseMonitorInfo.getParentId());
|
|
|
|
//创建子表
|
|
|
|
|
|
|
|
this.createEmsTbale(baseMonitorInfo.getMonitorId(), baseMonitorInfo.getBuildId(),baseMonitorInfo.getMonitorName(),baseMonitorInfo.getObjid());
|
|
|
|
|
|
|
|
if (monitor != null) {
|
|
|
|
if (monitor != null) {
|
|
|
|
monitor.setAncestors(monitor.getAncestors() + "," + monitor.getMonitorId());
|
|
|
|
monitor.setAncestors(monitor.getAncestors() + "," + monitor.getMonitorId());
|
|
|
|
String[] split = monitor.getAncestors().split(",");
|
|
|
|
String[] split = monitor.getAncestors().split(",");
|
|
|
|
@ -101,48 +106,53 @@ public class BaseMonitorInfo1ServiceImpl implements IBaseMonitorInfo1Service {
|
|
|
|
List<BaseMonitorInfo> subsetList = this.selectMonitorSubsetList(new BaseMonitorInfo());
|
|
|
|
List<BaseMonitorInfo> subsetList = this.selectMonitorSubsetList(new BaseMonitorInfo());
|
|
|
|
// 添加线损对象
|
|
|
|
// 添加线损对象
|
|
|
|
this.insertLineLossList(subsetList);
|
|
|
|
this.insertLineLossList(subsetList);
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
System.out.println("新增计量设备信息异常1111:" + e.getMessage());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
baseMonitorInfo.setCreateTime(DateUtils.getNowDate());
|
|
|
|
baseMonitorInfo.setCreateTime(DateUtils.getNowDate());
|
|
|
|
baseMonitorInfo.setCreateBy(SecurityUtils.getUsername());
|
|
|
|
baseMonitorInfo.setCreateBy(SecurityUtils.getUsername());
|
|
|
|
return baseMonitorInfoMapper.insertBaseMonitorInfo(baseMonitorInfo);
|
|
|
|
int result = baseMonitorInfoMapper.insertBaseMonitorInfo(baseMonitorInfo);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//创建TDEngine子表
|
|
|
|
|
|
|
|
this.createEmsTbale(baseMonitorInfo.getMonitorId(), baseMonitorInfo.getBuildId(), baseMonitorInfo.getMonitorName(), baseMonitorInfo.getObjid());
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
System.out.println("新增计量设备信息异常1111:" + e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 创建能源子表
|
|
|
|
* 创建能源子表
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
//todo 调用tde 在创建计量设备时创建子表
|
|
|
|
public void createEmsTbale(String monitorId, String buildid, String monitorName, Long objid) {
|
|
|
|
public void createEmsTbale(String monitorId,String buildobjid,String monitorName,Long objid){
|
|
|
|
|
|
|
|
//调用tde创建一个子表
|
|
|
|
//调用tde创建一个子表
|
|
|
|
TdTableVo tableVo = new TdTableVo();
|
|
|
|
TdTableVo tableVo = new TdTableVo();
|
|
|
|
tableVo.setDatabaseName("db_hwmes");
|
|
|
|
tableVo.setDatabaseName("db_hwmes");
|
|
|
|
tableVo.setSuperTableName("st_electricity");
|
|
|
|
tableVo.setSuperTableName("st_electricity");
|
|
|
|
tableVo.setTableName("t_e_"+monitorId);
|
|
|
|
tableVo.setTableName(TdEngineConstants.getEmsTableName(objid));
|
|
|
|
List<TdField> fields = new ArrayList<TdField>();
|
|
|
|
List<TdField> fields = new ArrayList<TdField>();
|
|
|
|
List<TdField> field2s = new ArrayList<TdField>();
|
|
|
|
|
|
|
|
TdField field = new TdField();
|
|
|
|
TdField field = new TdField();
|
|
|
|
TdField field2 = new TdField();
|
|
|
|
TdField field2 = new TdField();
|
|
|
|
TdField field3 = new TdField();
|
|
|
|
TdField field3 = new TdField();
|
|
|
|
TdField field4 = new TdField();
|
|
|
|
TdField field4 = new TdField();
|
|
|
|
field.setFieldName("buildobjid");
|
|
|
|
field.setFieldName(TdEngineConstants.ST_TAG_EMS_BUILDID);
|
|
|
|
field.setFieldValue(buildobjid);
|
|
|
|
field.setFieldValue(buildid);
|
|
|
|
field.setDataType("int");
|
|
|
|
field2.setFieldName(TdEngineConstants.ST_TAG_EMS_MONITORNAME);
|
|
|
|
field2.setFieldName("monitorname");
|
|
|
|
|
|
|
|
field2.setFieldValue(monitorName);
|
|
|
|
field2.setFieldValue(monitorName);
|
|
|
|
field2.setDataType("nchar");
|
|
|
|
field3.setFieldName(TdEngineConstants.ST_TAG_EMS_MONITOROBJID);
|
|
|
|
field3.setFieldName("monitorobjid");
|
|
|
|
|
|
|
|
field3.setDataType("int");
|
|
|
|
|
|
|
|
field3.setFieldValue(objid);
|
|
|
|
field3.setFieldValue(objid);
|
|
|
|
|
|
|
|
field4.setFieldName(TdEngineConstants.ST_TAG_EMS_MONITORID);
|
|
|
|
|
|
|
|
field4.setFieldValue(monitorId);
|
|
|
|
fields.add(field);
|
|
|
|
fields.add(field);
|
|
|
|
fields.add(field2);
|
|
|
|
fields.add(field2);
|
|
|
|
fields.add(field3);
|
|
|
|
fields.add(field3);
|
|
|
|
field2s.add(field4);
|
|
|
|
fields.add(field4);
|
|
|
|
tableVo.setSchemaFields(field2s);
|
|
|
|
|
|
|
|
tableVo.setTagsFieldValues(fields);
|
|
|
|
tableVo.setTagsFieldValues(fields);
|
|
|
|
remoteTdEngineService.createTable(tableVo, SecurityConstants.INNER);
|
|
|
|
remoteTdEngineService.createTable(tableVo, SecurityConstants.INNER);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 新增线损对象信息
|
|
|
|
* 新增线损对象信息
|
|
|
|
*
|
|
|
|
*
|
|
|
|
@ -191,6 +201,7 @@ public class BaseMonitorInfo1ServiceImpl implements IBaseMonitorInfo1Service {
|
|
|
|
* @param baseMonitorInfo 计量设备信息
|
|
|
|
* @param baseMonitorInfo 计量设备信息
|
|
|
|
* @return 结果
|
|
|
|
* @return 结果
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
//@DS("#header.poolName")
|
|
|
|
//@DS("#header.poolName")
|
|
|
|
public int updateBaseMonitorInfo(BaseMonitorInfo baseMonitorInfo) {
|
|
|
|
public int updateBaseMonitorInfo(BaseMonitorInfo baseMonitorInfo) {
|
|
|
|
@ -201,8 +212,7 @@ public class BaseMonitorInfo1ServiceImpl implements IBaseMonitorInfo1Service {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
BaseMonitorInfo newParenMonitorInfo = baseMonitorInfoMapper.selectBaseMonitorInfoByObjid(baseMonitorInfo.getParentId());
|
|
|
|
BaseMonitorInfo newParenMonitorInfo = baseMonitorInfoMapper.selectBaseMonitorInfoByObjid(baseMonitorInfo.getParentId());
|
|
|
|
BaseMonitorInfo oldDeptMonitorInfo = selectBaseMonitorInfoByObjid(baseMonitorInfo.getObjid());
|
|
|
|
BaseMonitorInfo oldDeptMonitorInfo = selectBaseMonitorInfoByObjid(baseMonitorInfo.getObjid());
|
|
|
|
if (StringUtils.isNotNull(newParenMonitorInfo) && StringUtils.isNotNull(oldDeptMonitorInfo))
|
|
|
|
if (StringUtils.isNotNull(newParenMonitorInfo) && StringUtils.isNotNull(oldDeptMonitorInfo)) {
|
|
|
|
{
|
|
|
|
|
|
|
|
String newAncestors = newParenMonitorInfo.getAncestors() + "," + oldDeptMonitorInfo.getMonitorId();
|
|
|
|
String newAncestors = newParenMonitorInfo.getAncestors() + "," + oldDeptMonitorInfo.getMonitorId();
|
|
|
|
String oldAncestors = oldDeptMonitorInfo.getAncestors();
|
|
|
|
String oldAncestors = oldDeptMonitorInfo.getAncestors();
|
|
|
|
baseMonitorInfo.setAncestors(newAncestors);
|
|
|
|
baseMonitorInfo.setAncestors(newAncestors);
|
|
|
|
@ -214,31 +224,85 @@ public class BaseMonitorInfo1ServiceImpl implements IBaseMonitorInfo1Service {
|
|
|
|
|
|
|
|
|
|
|
|
this.insertOrUpdateBaseTypeRelation(baseMonitorInfo.getMonitorId(), baseMonitorInfo.getBuildId(),
|
|
|
|
this.insertOrUpdateBaseTypeRelation(baseMonitorInfo.getMonitorId(), baseMonitorInfo.getBuildId(),
|
|
|
|
baseMonitorInfo.getBusinessId(), baseMonitorInfo.getSubentryId());
|
|
|
|
baseMonitorInfo.getBusinessId(), baseMonitorInfo.getSubentryId());
|
|
|
|
|
|
|
|
baseMonitorInfo.setUpdateTime(DateUtils.getNowDate());
|
|
|
|
|
|
|
|
baseMonitorInfo.setUpdateBy(SecurityUtils.getUsername());
|
|
|
|
|
|
|
|
int result = baseMonitorInfoMapper.updateBaseMonitorInfo(baseMonitorInfo);
|
|
|
|
|
|
|
|
this.updateTdEngineTable(baseMonitorInfo, oldDeptMonitorInfo);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
baseMonitorInfo.setUpdateTime(DateUtils.getNowDate());
|
|
|
|
return 0;
|
|
|
|
baseMonitorInfo.setUpdateBy(SecurityUtils.getUsername());
|
|
|
|
|
|
|
|
return baseMonitorInfoMapper.updateBaseMonitorInfo(baseMonitorInfo);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 修改子元素关系
|
|
|
|
* 修改子元素关系
|
|
|
|
|
|
|
|
*
|
|
|
|
* @param monitorId 被修改的ID
|
|
|
|
* @param monitorId 被修改的ID
|
|
|
|
* @param newAncestors 新的父ID集合
|
|
|
|
* @param newAncestors 新的父ID集合
|
|
|
|
* @param oldAncestors 旧的父ID集合
|
|
|
|
* @param oldAncestors 旧的父ID集合
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private void updateMonitorChildren(String monitorId, String newAncestors, String oldAncestors) {
|
|
|
|
private void updateMonitorChildren(String monitorId, String newAncestors, String oldAncestors) {
|
|
|
|
List<BaseMonitorInfo> children = baseMonitorInfoMapper.selectChildrenMonitorById(monitorId);
|
|
|
|
List<BaseMonitorInfo> children = baseMonitorInfoMapper.selectChildrenMonitorById(monitorId);
|
|
|
|
for (BaseMonitorInfo child : children)
|
|
|
|
for (BaseMonitorInfo child : children) {
|
|
|
|
{
|
|
|
|
|
|
|
|
child.setAncestors(child.getAncestors().replaceFirst(oldAncestors, newAncestors));
|
|
|
|
child.setAncestors(child.getAncestors().replaceFirst(oldAncestors, newAncestors));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (children.size() > 0)
|
|
|
|
if (children.size() > 0) {
|
|
|
|
{
|
|
|
|
|
|
|
|
baseMonitorInfoMapper.updateMonitorChildren(children);
|
|
|
|
baseMonitorInfoMapper.updateMonitorChildren(children);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @param: baseMonitorInfo 前端传的对象
|
|
|
|
|
|
|
|
* @param: dbBaseMonitorInfo 目前数据库的对象
|
|
|
|
|
|
|
|
* @description 更新TdEngine数据库tag
|
|
|
|
|
|
|
|
* @author xins
|
|
|
|
|
|
|
|
* @date 2023-12-30 16:50
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private void updateTdEngineTable(BaseMonitorInfo baseMonitorInfo, BaseMonitorInfo dbBaseMonitorInfo) {
|
|
|
|
|
|
|
|
String databaseName = TdEngineConstants.EMS_DATABASE_NAME;
|
|
|
|
|
|
|
|
String tableName = TdEngineConstants.getEmsTableName(baseMonitorInfo.getObjid());
|
|
|
|
|
|
|
|
List<AlterTagVo> alterTagVos = new ArrayList<AlterTagVo>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
R<?> tdReturnMsg;
|
|
|
|
|
|
|
|
if (!baseMonitorInfo.getMonitorId().equals(dbBaseMonitorInfo.getMonitorId())) {
|
|
|
|
|
|
|
|
AlterTagVo alterTagVo = new AlterTagVo();
|
|
|
|
|
|
|
|
alterTagVo.setDatabaseName(databaseName);
|
|
|
|
|
|
|
|
alterTagVo.setTableName(tableName);
|
|
|
|
|
|
|
|
alterTagVo.setTagName(TdEngineConstants.ST_TAG_EMS_MONITORID);
|
|
|
|
|
|
|
|
alterTagVo.setTagValue("'" + baseMonitorInfo.getMonitorId() + "'");
|
|
|
|
|
|
|
|
alterTagVos.add(alterTagVo);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!baseMonitorInfo.getMonitorName().equals(dbBaseMonitorInfo.getMonitorName())) {
|
|
|
|
|
|
|
|
AlterTagVo alterTagVo = new AlterTagVo();
|
|
|
|
|
|
|
|
alterTagVo.setDatabaseName(databaseName);
|
|
|
|
|
|
|
|
alterTagVo.setTableName(tableName);
|
|
|
|
|
|
|
|
alterTagVo.setTagName(TdEngineConstants.ST_TAG_EMS_MONITORNAME);
|
|
|
|
|
|
|
|
alterTagVo.setTagValue("'" + baseMonitorInfo.getMonitorName() + "'");
|
|
|
|
|
|
|
|
alterTagVos.add(alterTagVo);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!baseMonitorInfo.getBuildId().equals(dbBaseMonitorInfo.getBuildId())) {
|
|
|
|
|
|
|
|
AlterTagVo alterTagVo = new AlterTagVo();
|
|
|
|
|
|
|
|
alterTagVo.setDatabaseName(databaseName);
|
|
|
|
|
|
|
|
alterTagVo.setTableName(tableName);
|
|
|
|
|
|
|
|
alterTagVo.setTagName(TdEngineConstants.ST_TAG_EMS_BUILDID);
|
|
|
|
|
|
|
|
alterTagVo.setTagValue("'" +baseMonitorInfo.getBuildId()+ "'");
|
|
|
|
|
|
|
|
alterTagVos.add(alterTagVo);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!alterTagVos.isEmpty()) {
|
|
|
|
|
|
|
|
tdReturnMsg = this.remoteTdEngineService.alterTableTags(alterTagVos, SecurityConstants.INNER);
|
|
|
|
|
|
|
|
if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
|
|
|
|
|
|
|
|
throw new RuntimeException(tdReturnMsg.getMsg());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 批量删除计量设备信息
|
|
|
|
* 批量删除计量设备信息
|
|
|
|
*
|
|
|
|
*
|
|
|
|
@ -387,5 +451,4 @@ public class BaseMonitorInfo1ServiceImpl implements IBaseMonitorInfo1Service {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|