This commit is contained in:
高云鹏 2024-10-25 16:36:41 +08:00
commit 73c97a837f
4 changed files with 107 additions and 72 deletions

View File

@ -38,6 +38,7 @@ import org.springframework.web.multipart.MultipartFile;
import java.io.InputStream;
import java.util.*;
import java.util.stream.Collectors;
@Transactional(rollbackFor = Exception.class)
@Service
@ -85,13 +86,13 @@ public class SysIotModelServiceImpl implements SysIotModelService {
SysUserVo sysUserVo = (SysUserVo) StpUtil.getTokenSession().get(SessionUtil.SESSION_USER_KEY);
SysIotModelVo sysIotModelQuery = sysIotModelMapper.selectIotModelByCode(sysIotModelDto.getIotModelCode());
if (!(sysIotModelQuery == null)){
if(!(sysIotModelQuery.getId().equals(sysIotModelDto.getId()))){
if (!(sysIotModelQuery == null)) {
if (!(sysIotModelQuery.getId().equals(sysIotModelDto.getId()))) {
throw new ServiceException("物模型code已经存在");
}
}
SysIotModel oldSysIotModel = sysIotModelMapper.selectById(sysIotModelDto.getId());
if(!sysIotModelDto.getIotModelCode().equals(oldSysIotModel.getIotModelCode())) {
if (!sysIotModelDto.getIotModelCode().equals(oldSysIotModel.getIotModelCode())) {
throw new ServiceException("物模型code不能修改");
}
sysIotModel.setUpdatedTime(new Date());
@ -186,19 +187,19 @@ public class SysIotModelServiceImpl implements SysIotModelService {
}
SysIotModelFieldVo sysIotModelFieldQuery = sysIotModelFieldMapper.selectByAttributeCode(sysIotModelFieldDto.getIotModelId(), sysIotModelFieldDto.getAttributeCode());
if (!(sysIotModelFieldQuery == null)) {
if (!sysIotModelFieldQuery.getId().equals(sysIotModelFieldDto.getId())){
if (!sysIotModelFieldQuery.getId().equals(sysIotModelFieldDto.getId())) {
throw new ServiceException("物模型属性code已经存在");
}
}
sysIotModelFieldMapper.updateById(sysIotModelField);
SysIotModelField oldSysIotField = sysIotModelFieldMapper.selectById(sysIotModelFieldDto.getId());
if (oldSysIotField == null){
if (oldSysIotField == null) {
throw new ServiceException("未查找到该条记录");
}
if (!oldSysIotField.getAttributeCode().equals(sysIotModelField.getAttributeCode()) && oldSysIotField.getDataType().equals(sysIotModelField.getDataType()) && Objects.equals(oldSysIotField.getHighSpeed(), sysIotModelField.getHighSpeed())){
if (!oldSysIotField.getAttributeCode().equals(sysIotModelField.getAttributeCode()) && oldSysIotField.getDataType().equals(sysIotModelField.getDataType()) && Objects.equals(oldSysIotField.getHighSpeed(), sysIotModelField.getHighSpeed())) {
//更新td表结构
updateTDStableOrColumn(sysIotModelField,oldSysIotField);
updateTDStableOrColumn(sysIotModelField, oldSysIotField);
}
SysIotModelFieldVo sysIotModelFieldVo = new SysIotModelFieldVo();
BeanCopyUtils.copy(sysIotModelField, sysIotModelFieldVo);
@ -255,7 +256,7 @@ public class SysIotModelServiceImpl implements SysIotModelService {
SysIotModelServiceVo sysIotModelServiceQuery = sysIotModelServiceMapper.selectByServiceCode(sysIotModelServiceDto.getIotModelId(), sysIotModelServiceDto.getServiceCode());
if (!(sysIotModelServiceQuery == null)) {
if(sysIotModelServiceQuery.getId() != sysIotModelServiceDto.getId()){
if (sysIotModelServiceQuery.getId() != sysIotModelServiceDto.getId()) {
throw new ServiceException("物模型动作code已经存在");
}
}
@ -295,7 +296,7 @@ public class SysIotModelServiceImpl implements SysIotModelService {
exportList.add(sheetDTO);
List<SysIotModelServiceExcel> sysIotModelServiceVoList = sysIotModelMapper.queryServiceByModelId(sysIotModelDto.getId());
LinkedHashMap<String, String> map1= new LinkedHashMap<>();
LinkedHashMap<String, String> map1 = new LinkedHashMap<>();
SheetInfoBean sheetDTO1 = new SheetInfoBean();
map1.put("tag", "标识");
map1.put("iotModelCode", "所属物模型编码");
@ -314,7 +315,7 @@ public class SysIotModelServiceImpl implements SysIotModelService {
}
@Override
public void importSysIotModel(String iotModelId, MultipartFile file){
public void importSysIotModel(String iotModelId, MultipartFile file) {
try {
InputStream inputStream = file.getInputStream();
ExcelReader readerAll = ExcelUtil.getReader(inputStream);
@ -327,15 +328,17 @@ public class SysIotModelServiceImpl implements SysIotModelService {
List<List<Object>> list = sheetReader.read(1); // 从第二行开始读
if ("物模型属性".equals(sheetName)) {
saveIotModelFieldInfo(iotModelId, list);
}else {
} else {
saveIotModelServiceInfo(iotModelId, list);
}
}
} catch (Exception e) {
log.error("导入物模型异常:" + e.getMessage());
throw new ServiceException("导入物模型异常:" + e.getMessage());
}
}
private void saveIotModelServiceInfo(String iotModelId, List<List<Object>> list) {
List<SysIotModelServices> sysIotModelServiceList = new ArrayList<>();
List<SysIotModelServices> updateSysIotModelServiceList = new ArrayList<>();
@ -361,7 +364,7 @@ public class SysIotModelServiceImpl implements SysIotModelService {
//加入集合
sysIotModelServiceList.add(services);
}
}else {
} else {
services.setId(sysIotModelServiceQuery.getId());
services.setUpdatedTime(new Date());
services.setUpdatedBy(StpUtil.getLoginIdAsString());
@ -403,7 +406,7 @@ public class SysIotModelServiceImpl implements SysIotModelService {
//加入集合
sysIotModelFieldList.add(field);
}
}else {
} else {
buildFieldInfo(iotModelId, row, field);
field.setId(sysIotModelFieldQuery.getId());
field.setUpdatedTime(new Date());
@ -417,47 +420,76 @@ public class SysIotModelServiceImpl implements SysIotModelService {
}
}
if (CollectionUtils.isNotEmpty(sysIotModelFieldList)) {
//创建td表结构
//分为高频低频两个list创建
List<SysIotModelField> lowCreateList = sysIotModelFieldList.stream().filter(item -> item.getHighSpeed() == 0).collect(Collectors.toList());
List<SysIotModelField> highCreateList = sysIotModelFieldList.stream().filter(item -> item.getHighSpeed() == 1).collect(Collectors.toList());
for (int i = 0; i < lowCreateList.size(); i++) {
if (i == 0) {
createTdStableOrColumn(lowCreateList.get(i));
} else {
SysIotModelField sysIotModelField = lowCreateList.get(i);
//stable已经存在,新增stable列
SysIotModel sysIotModel = sysIotModelMapper.selectById(sysIotModelField.getIotModelId());
Map<String, String> map = new HashMap<>();
map.put(sysIotModelField.getAttributeCode(), sysIotModelField.getDataType());
//创建低频超级表
tdEngineService.addStableColumn(sysIotModel.getIotModelCode(), "l_", map);
}
}
for (int i = 0; i < highCreateList.size(); i++) {
if (i == 0) {
createTdStableOrColumn(highCreateList.get(i));
} else {
SysIotModelField sysIotModelField = highCreateList.get(i);
//stable已经存在,新增stable列
SysIotModel sysIotModel = sysIotModelMapper.selectById(sysIotModelField.getIotModelId());
Map<String, String> map = new HashMap<>();
map.put(sysIotModelField.getAttributeCode(), sysIotModelField.getDataType());
//创建高频超级表
tdEngineService.addStableColumn(sysIotModel.getIotModelCode(), "h_", map);
}
}
//新增pg数据库
sysIotModelFieldMapper.insertBatch(sysIotModelFieldList);
// ListUtil.page(sysIotModelFieldList, COMMIT_COUNT, create -> {
// for (SysIotModelField item : create){
// createTdStableOrColumn(item);
// }
// });
}
if (CollectionUtils.isNotEmpty(updateSysIotModelFieldList)) {
// ListUtil.page(updateSysIotModelFieldList, COMMIT_COUNT, update -> {
// for (SysIotModelField item : update){
// SysIotModelField oldSysIotField = sysIotModelFieldMapper.selectById(item.getId());
// if (oldSysIotField != null){
// if (!oldSysIotField.getAttributeCode().equals(item.getAttributeCode()) && oldSysIotField.getDataType().equals(item.getDataType()) && Objects.equals(oldSysIotField.getHighSpeed(), item.getHighSpeed())){
// //更新td表结构
// updateTDStableOrColumn(item,oldSysIotField);
// }
// }
// }
// });
for (SysIotModelField item : updateSysIotModelFieldList) {
SysIotModelField oldSysIotField = sysIotModelFieldMapper.selectById(item.getId());
if (oldSysIotField != null) {
if (!oldSysIotField.getAttributeCode().equals(item.getAttributeCode()) && oldSysIotField.getDataType().equals(item.getDataType()) && Objects.equals(oldSysIotField.getHighSpeed(), item.getHighSpeed())) {
//更新td表结构
updateTDStableOrColumn(item, oldSysIotField);
}
}
}
sysIotModelFieldMapper.updateBatchById(updateSysIotModelFieldList);
}
if (CollectionUtils.isNotEmpty(delSysIotModelFieldList)) {
// ListUtil.page(updateSysIotModelFieldList, COMMIT_COUNT, delete -> {
// for (SysIotModelField item : delete){
// deleteTDStableOrColumn(item);
// }
// });
sysIotModelFieldMapper.deleteBatchIds(delSysIotModelFieldList);
//循环删除td表结构
//分为高频低频两个list创建
for (SysIotModelField item : delSysIotModelFieldList) {
deleteTDStableOrColumn(item);
sysIotModelFieldMapper.deleteById(item);
}
}
}
private static void buildFieldInfo(String iotModelId, List<Object> row, SysIotModelField field) {
if (row.get(3).equals("") || row.get(4).equals("") || row.get(5).equals("") || row.get(7).equals("") || row.get(9).equals("") || row.get(11).equals("")) {
throw new ServiceException("字段不可为空请检查excel文件{}" + row);
}
field.setAttributeCode(row.get(3).toString().toLowerCase());
field.setAttributeName(row.get(4).toString());
field.setAttributeType(Integer.valueOf(row.get(5).toString()));
field.setUnit(row.get(6).toString());
field.setUnit(row.get(6).equals("") ? null : row.get(6).toString());
field.setPorder(Integer.valueOf(row.get(7).toString()));
field.setSubSystem(row.get(8).toString());
field.setSubSystem(row.get(8).equals("") ? null : row.get(8).toString());
field.setDataType(row.get(9).toString());
field.setVisible(Integer.valueOf(row.get(10).toString()));
field.setVisible(row.get(10).equals("") ? null : Integer.valueOf(row.get(10).toString()));
field.setHighSpeed(Integer.valueOf(row.get(11).toString()));
field.setIotModelId(Long.valueOf(iotModelId));
}
@ -468,69 +500,69 @@ public class SysIotModelServiceImpl implements SysIotModelService {
return list;
}
public void createTdStableOrColumn(SysIotModelField sysIotModelField){
public void createTdStableOrColumn(SysIotModelField sysIotModelField) {
//如果新增的是第一条记录 创建tdengine超级表 分为高频和低频
QueryWrapper<SysIotModelField> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("iot_model_id",sysIotModelField.getIotModelId());
queryWrapper.eq("highspeed",sysIotModelField.getHighSpeed());
queryWrapper.eq("iot_model_id", sysIotModelField.getIotModelId());
queryWrapper.eq("highspeed", sysIotModelField.getHighSpeed());
List<SysIotModelField> sysIotModelFields = sysIotModelFieldMapper.selectList(queryWrapper);
if (CollectionUtils.isEmpty(sysIotModelFields)){
if (sysIotModelField.getHighSpeed() == 0){
if (CollectionUtils.isEmpty(sysIotModelFields)) {
if (sysIotModelField.getHighSpeed() == 0) {
SysIotModel sysIotModel = sysIotModelMapper.selectById(sysIotModelField.getIotModelId());
Map<String,String> map = new HashMap<>();
Map<String, String> map = new HashMap<>();
map.put(sysIotModelField.getAttributeCode(), sysIotModelField.getDataType());
//创建低频超级表
tdEngineService.createStable(sysIotModel.getIotModelCode(),"l_",map);
tdEngineService.createStable(sysIotModel.getIotModelCode(), "l_", map);
}
if (sysIotModelField.getHighSpeed() == 1){
if (sysIotModelField.getHighSpeed() == 1) {
SysIotModel sysIotModel = sysIotModelMapper.selectById(sysIotModelField.getIotModelId());
Map<String,String> map = new HashMap<>();
Map<String, String> map = new HashMap<>();
map.put(sysIotModelField.getAttributeCode(), sysIotModelField.getDataType());
//创建高频超级表
tdEngineService.createStable(sysIotModel.getIotModelCode(),"h_",map);
tdEngineService.createStable(sysIotModel.getIotModelCode(), "h_", map);
}
}else {
} else {
//stable已经存在,新增stable列
if (sysIotModelField.getHighSpeed() == 0){
if (sysIotModelField.getHighSpeed() == 0) {
SysIotModel sysIotModel = sysIotModelMapper.selectById(sysIotModelField.getIotModelId());
Map<String,String> map = new HashMap<>();
Map<String, String> map = new HashMap<>();
map.put(sysIotModelField.getAttributeCode(), sysIotModelField.getDataType());
//创建低频超级表
tdEngineService.addStableColumn(sysIotModel.getIotModelCode(),"l_",map);
tdEngineService.addStableColumn(sysIotModel.getIotModelCode(), "l_", map);
}
if (sysIotModelField.getHighSpeed() == 1){
if (sysIotModelField.getHighSpeed() == 1) {
SysIotModel sysIotModel = sysIotModelMapper.selectById(sysIotModelField.getIotModelId());
Map<String,String> map = new HashMap<>();
Map<String, String> map = new HashMap<>();
map.put(sysIotModelField.getAttributeCode(), sysIotModelField.getDataType());
//创建高频超级表
tdEngineService.addStableColumn(sysIotModel.getIotModelCode(),"h_",map);
tdEngineService.addStableColumn(sysIotModel.getIotModelCode(), "h_", map);
}
}
}
public void updateTDStableOrColumn(SysIotModelField sysIotModelField,SysIotModelField oldIotModelField){
public void updateTDStableOrColumn(SysIotModelField sysIotModelField, SysIotModelField oldIotModelField) {
deleteTDStableOrColumn(oldIotModelField);
createTdStableOrColumn(sysIotModelField);
}
public void deleteTDStableOrColumn(SysIotModelField sysIotModelField){
public void deleteTDStableOrColumn(SysIotModelField sysIotModelField) {
String stableName = null;
SysIotModel sysIotModel = sysIotModelMapper.selectById(sysIotModelField.getIotModelId());
if(sysIotModelField.getHighSpeed() == 0) {
stableName = "l_" + sysIotModel.getIotModelCode();
if (sysIotModelField.getHighSpeed() == 0) {
stableName = "l_" + sysIotModel.getIotModelCode();
}
if(sysIotModelField.getHighSpeed() == 1) {
stableName = "h_" + sysIotModel.getIotModelCode();
if (sysIotModelField.getHighSpeed() == 1) {
stableName = "h_" + sysIotModel.getIotModelCode();
}
QueryWrapper<SysIotModelField> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("iot_model_id",sysIotModelField.getIotModelId());
queryWrapper.eq("highspeed",sysIotModelField.getHighSpeed());
queryWrapper.eq("iot_model_id", sysIotModelField.getIotModelId());
queryWrapper.eq("highspeed", sysIotModelField.getHighSpeed());
List<SysIotModelField> sysIotModelFields = sysIotModelFieldMapper.selectList(queryWrapper);
if (CollectionUtils.isNotEmpty(sysIotModelFields) && sysIotModelFields.size() > 1){
tdEngineService.deleteColumn(stableName,sysIotModelField.getAttributeCode());
if (CollectionUtils.isNotEmpty(sysIotModelFields) && sysIotModelFields.size() > 1) {
tdEngineService.deleteColumn(stableName, sysIotModelField.getAttributeCode());
}
//物模型属性只剩下最后一个删除表
if (CollectionUtils.isNotEmpty(sysIotModelFields) && sysIotModelFields.size() == 1){
if (CollectionUtils.isNotEmpty(sysIotModelFields) && sysIotModelFields.size() == 1) {
tdEngineService.deleteStable(stableName);
}
}

View File

@ -61,7 +61,6 @@ public class TDEngineService {
/**
* 创建超级表
*/
@Async
public void createStable(String iotModelCode, String stableType, Map<String, String> fieldNameTypeMap) {
try (Connection conn = hikariDataSource.getConnection();
Statement pstmt = conn.createStatement()) {
@ -95,7 +94,6 @@ public class TDEngineService {
/**
* 新增超级表列
*/
@Async
public void addStableColumn(String iotModelCode, String stableType, Map<String, String> fieldNameTypeMap) {
try (Connection conn = hikariDataSource.getConnection();
Statement pstmt = conn.createStatement()) {
@ -126,7 +124,6 @@ public class TDEngineService {
/**
* 删除超级表列
*/
@Async
public void deleteColumn(String stableName, String fieldCode) {
try (Connection conn = hikariDataSource.getConnection();
Statement pstmt = conn.createStatement()) {
@ -152,7 +149,6 @@ public class TDEngineService {
/**
* 删除超级表
*/
@Async
public void deleteStable(String stableName) {
try (Connection conn = hikariDataSource.getConnection();
Statement pstmt = conn.createStatement()) {

View File

@ -166,7 +166,7 @@
select distinct belong_line as name from sys_equipment t where t.object_type = 10002 and belong_line !='';
</select>
<select id="queryAllWindList" resultType="com.das.modules.page.domian.WindTurbinesPageVo">
select se.id as irn,se.name,se.model,se.belong_line as belongLine from sys_equipment se where se.object_type = #{objectType}
select se.id as irn,se.name,se.model,se.belong_line as belongLine from sys_equipment se where se.object_type = #{objectType} order by se.name
</select>

View File

@ -17,7 +17,7 @@
</div>
<template #footer>
<div class="dialog-footer">
<el-button type="primary" @click="onSubmitvalue">导出</el-button>
<el-button type="primary" @click="onExport">导出</el-button>
<el-button @click="visible = false">关闭</el-button>
</div>
</template>
@ -1013,6 +1013,13 @@ const tabhandleClick = (tabName) => {
color: #333333;
font-size: 20px;
}
.dialog-footer{
text-align: center;
.el-button{
width: 120px;
height: 40px;
}
}
.homelabel{
font-size: 18px;
color: #4E5969;