This commit is contained in:
谷成伟 2024-12-10 08:57:38 +08:00
commit 705408796c
8 changed files with 114 additions and 8 deletions

View File

@ -28,6 +28,7 @@ import com.das.modules.equipment.mapper.SysIotModelMapper;
import com.das.modules.equipment.mapper.SysIotModelServiceMapper; import com.das.modules.equipment.mapper.SysIotModelServiceMapper;
import com.das.modules.equipment.service.SysIotModelService; import com.das.modules.equipment.service.SysIotModelService;
import com.das.modules.data.service.TDEngineService; import com.das.modules.data.service.TDEngineService;
import com.das.modules.record.service.SysRecordLogService;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -61,6 +62,9 @@ public class SysIotModelServiceImpl implements SysIotModelService {
@Autowired @Autowired
private DataServiceImpl dataService; private DataServiceImpl dataService;
@Autowired
SysRecordLogService sysRecordLogService;
public SysIotModelVo creatSysIotModel(SysIotModelDto sysIotModelDto) { public SysIotModelVo creatSysIotModel(SysIotModelDto sysIotModelDto) {
SysIotModel sysIotModel = new SysIotModel(); SysIotModel sysIotModel = new SysIotModel();
BeanCopyUtils.copy(sysIotModelDto, sysIotModel); BeanCopyUtils.copy(sysIotModelDto, sysIotModel);
@ -174,9 +178,10 @@ public class SysIotModelServiceImpl implements SysIotModelService {
if (sysIotModelFieldDto.getAttributeType() == 140) { if (sysIotModelFieldDto.getAttributeType() == 140) {
sysIotModelField.setDataType("tinyint"); sysIotModelField.setDataType("tinyint");
} }
sysIotModelFieldMapper.insert(sysIotModelField);
//动态执行创建td超级表字段 //动态执行创建td超级表字段
createTdStableOrColumn(sysIotModelField); createTdStableOrColumn(sysIotModelField);
sysIotModelFieldMapper.insert(sysIotModelField);
//新增物模型属性缓存 //新增物模型属性缓存
addModelFieldCache(sysIotModelField); addModelFieldCache(sysIotModelField);
SysIotModelFieldVo sysIotModelFieldVo = new SysIotModelFieldVo(); SysIotModelFieldVo sysIotModelFieldVo = new SysIotModelFieldVo();
@ -206,12 +211,13 @@ public class SysIotModelServiceImpl implements SysIotModelService {
if (oldSysIotField == null) { if (oldSysIotField == null) {
throw new ServiceException("未查找到该条记录"); throw new ServiceException("未查找到该条记录");
} }
sysIotModelFieldMapper.updateById(sysIotModelField);
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表结构 //更新td表结构
updateTDStableOrColumn(sysIotModelField, oldSysIotField); updateTDStableOrColumn(sysIotModelField, oldSysIotField);
updateModelFieldCache(sysIotModelField, oldSysIotField); updateModelFieldCache(sysIotModelField, oldSysIotField);
} }
sysIotModelFieldMapper.updateById(sysIotModelField);
SysIotModelFieldVo sysIotModelFieldVo = new SysIotModelFieldVo(); SysIotModelFieldVo sysIotModelFieldVo = new SysIotModelFieldVo();
BeanCopyUtils.copy(sysIotModelField, sysIotModelFieldVo); BeanCopyUtils.copy(sysIotModelField, sysIotModelFieldVo);
return sysIotModelFieldVo; return sysIotModelFieldVo;
@ -220,9 +226,10 @@ public class SysIotModelServiceImpl implements SysIotModelService {
@Override @Override
public void deleteSysIotModelField(SysIotModelFieldDto sysIotModelFieldDto) { public void deleteSysIotModelField(SysIotModelFieldDto sysIotModelFieldDto) {
SysIotModelField sysIotModelField = sysIotModelFieldMapper.selectById(sysIotModelFieldDto.getId()); SysIotModelField sysIotModelField = sysIotModelFieldMapper.selectById(sysIotModelFieldDto.getId());
sysIotModelFieldMapper.deleteById(sysIotModelFieldDto.getId());
//删除td表结构字段 //删除td表结构字段
deleteTDStableOrColumn(sysIotModelField); deleteTDStableOrColumn(sysIotModelField);
sysIotModelFieldMapper.deleteById(sysIotModelFieldDto.getId());
//删除物模型属性缓存 //删除物模型属性缓存
deleteModelFieldCache(sysIotModelField); deleteModelFieldCache(sysIotModelField);
} }
@ -453,6 +460,7 @@ public class SysIotModelServiceImpl implements SysIotModelService {
map.put(sysIotModelField.getAttributeCode(), sysIotModelField.getDataType()); map.put(sysIotModelField.getAttributeCode(), sysIotModelField.getDataType());
//创建低频超级表 //创建低频超级表
tdEngineService.addStableColumn(sysIotModel.getIotModelCode(), "l_", map); tdEngineService.addStableColumn(sysIotModel.getIotModelCode(), "l_", map);
sysRecordLogService.createRecordLog("/系统管理/物模型配置","新增低频TD超级表字段,"+"表名l_" +sysIotModel.getIotModelCode()+",字段:"+map);
addModelFieldCache(lowCreateList.get(i)); addModelFieldCache(lowCreateList.get(i));
} }
} }
@ -468,6 +476,7 @@ public class SysIotModelServiceImpl implements SysIotModelService {
map.put(sysIotModelField.getAttributeCode(), sysIotModelField.getDataType()); map.put(sysIotModelField.getAttributeCode(), sysIotModelField.getDataType());
//创建高频超级表 //创建高频超级表
tdEngineService.addStableColumn(sysIotModel.getIotModelCode(), "h_", map); tdEngineService.addStableColumn(sysIotModel.getIotModelCode(), "h_", map);
sysRecordLogService.createRecordLog("/系统管理/物模型配置","新增低频TD超级表字段,"+"表名h_" +sysIotModel.getIotModelCode()+",字段:"+map);
addModelFieldCache(highCreateList.get(i)); addModelFieldCache(highCreateList.get(i));
} }
} }
@ -535,6 +544,7 @@ public class SysIotModelServiceImpl implements SysIotModelService {
if (sysIotModelField.getAttributeType() == 199) { if (sysIotModelField.getAttributeType() == 199) {
String modelCode = dataService.iotModelMap.get(sysIotModelField.getIotModelId().toString()); String modelCode = dataService.iotModelMap.get(sysIotModelField.getIotModelId().toString());
tdEngineService.createCalStable(modelCode, sysIotModelField.getAttributeCode(), sysIotModelField.getDataType()); tdEngineService.createCalStable(modelCode, sysIotModelField.getAttributeCode(), sysIotModelField.getDataType());
sysRecordLogService.createRecordLog("/系统管理/物模型配置","创建计算超级表"+"c_" + modelCode + "_" + sysIotModelField.getAttributeCode());
} else { } else {
//创建type为138 139 140的超级表 //创建type为138 139 140的超级表
//如果新增的是第一条记录 创建tdengine超级表 分为高频和低频 //如果新增的是第一条记录 创建tdengine超级表 分为高频和低频
@ -549,6 +559,7 @@ public class SysIotModelServiceImpl implements SysIotModelService {
map.put(sysIotModelField.getAttributeCode(), sysIotModelField.getDataType()); map.put(sysIotModelField.getAttributeCode(), sysIotModelField.getDataType());
//创建低频超级表 //创建低频超级表
tdEngineService.createStable(sysIotModel.getIotModelCode(), "l_", map); tdEngineService.createStable(sysIotModel.getIotModelCode(), "l_", map);
sysRecordLogService.createRecordLog("/系统管理/物模型配置","创建低频TD超级表"+"l_" +sysIotModel.getIotModelCode());
} }
if (sysIotModelField.getHighSpeed() == 1) { if (sysIotModelField.getHighSpeed() == 1) {
SysIotModel sysIotModel = sysIotModelMapper.selectById(sysIotModelField.getIotModelId()); SysIotModel sysIotModel = sysIotModelMapper.selectById(sysIotModelField.getIotModelId());
@ -556,6 +567,7 @@ public class SysIotModelServiceImpl implements SysIotModelService {
map.put(sysIotModelField.getAttributeCode(), sysIotModelField.getDataType()); map.put(sysIotModelField.getAttributeCode(), sysIotModelField.getDataType());
//创建高频超级表 //创建高频超级表
tdEngineService.createStable(sysIotModel.getIotModelCode(), "h_", map); tdEngineService.createStable(sysIotModel.getIotModelCode(), "h_", map);
sysRecordLogService.createRecordLog("/系统管理/物模型配置","创建高频TD超级表"+"h_" +sysIotModel.getIotModelCode());
} }
} else { } else {
//stable已经存在,新增stable列 //stable已经存在,新增stable列
@ -565,6 +577,7 @@ public class SysIotModelServiceImpl implements SysIotModelService {
map.put(sysIotModelField.getAttributeCode(), sysIotModelField.getDataType()); map.put(sysIotModelField.getAttributeCode(), sysIotModelField.getDataType());
//创建低频超级表 //创建低频超级表
tdEngineService.addStableColumn(sysIotModel.getIotModelCode(), "l_", map); tdEngineService.addStableColumn(sysIotModel.getIotModelCode(), "l_", map);
sysRecordLogService.createRecordLog("/系统管理/物模型配置","新增低频TD超级表字段,"+"表名l_" +sysIotModel.getIotModelCode()+",字段:"+map);
} }
if (sysIotModelField.getHighSpeed() == 1) { if (sysIotModelField.getHighSpeed() == 1) {
SysIotModel sysIotModel = sysIotModelMapper.selectById(sysIotModelField.getIotModelId()); SysIotModel sysIotModel = sysIotModelMapper.selectById(sysIotModelField.getIotModelId());
@ -572,6 +585,7 @@ public class SysIotModelServiceImpl implements SysIotModelService {
map.put(sysIotModelField.getAttributeCode(), sysIotModelField.getDataType()); map.put(sysIotModelField.getAttributeCode(), sysIotModelField.getDataType());
//创建高频超级表 //创建高频超级表
tdEngineService.addStableColumn(sysIotModel.getIotModelCode(), "h_", map); tdEngineService.addStableColumn(sysIotModel.getIotModelCode(), "h_", map);
sysRecordLogService.createRecordLog("/系统管理/物模型配置","新增高频TD超级表字段,"+"表名h_" +sysIotModel.getIotModelCode()+",字段:"+map);
} }
} }
} }
@ -587,6 +601,7 @@ public class SysIotModelServiceImpl implements SysIotModelService {
Long iotModelId = sysIotModelField.getIotModelId(); Long iotModelId = sysIotModelField.getIotModelId();
String modelCode = dataService.iotModelMap.get(iotModelId.toString()); String modelCode = dataService.iotModelMap.get(iotModelId.toString());
tdEngineService.deleteStable("c_" + modelCode + "_" + sysIotModelField.getAttributeCode()); tdEngineService.deleteStable("c_" + modelCode + "_" + sysIotModelField.getAttributeCode());
sysRecordLogService.createRecordLog("/系统管理/物模型配置","删除TD超级表"+"c_" + modelCode + "_" + sysIotModelField.getAttributeCode());
} else { } else {
String stableName = null; String stableName = null;
SysIotModel sysIotModel = sysIotModelMapper.selectById(sysIotModelField.getIotModelId()); SysIotModel sysIotModel = sysIotModelMapper.selectById(sysIotModelField.getIotModelId());
@ -602,10 +617,12 @@ public class SysIotModelServiceImpl implements SysIotModelService {
List<SysIotModelField> sysIotModelFields = sysIotModelFieldMapper.selectList(queryWrapper); List<SysIotModelField> sysIotModelFields = sysIotModelFieldMapper.selectList(queryWrapper);
if (CollectionUtils.isNotEmpty(sysIotModelFields) && sysIotModelFields.size() > 1) { if (CollectionUtils.isNotEmpty(sysIotModelFields) && sysIotModelFields.size() > 1) {
tdEngineService.deleteColumn(stableName, sysIotModelField.getAttributeCode()); tdEngineService.deleteColumn(stableName, sysIotModelField.getAttributeCode());
sysRecordLogService.createRecordLog("/系统管理/物模型配置","删除TD超级表"+ stableName +"中字段:"+ sysIotModelField.getAttributeCode());
} }
//物模型属性只剩下最后一个删除表 //物模型属性只剩下最后一个删除表
if (CollectionUtils.isNotEmpty(sysIotModelFields) && sysIotModelFields.size() == 1) { if (CollectionUtils.isNotEmpty(sysIotModelFields) && sysIotModelFields.size() == 1) {
tdEngineService.deleteStable(stableName); tdEngineService.deleteStable(stableName);
sysRecordLogService.createRecordLog("/系统管理/物模型配置","删除TD超级表"+ stableName);
} }
} }

View File

@ -51,7 +51,7 @@ public class FaultRecorderController {
String code = jsonObject.getString("deviceCode"); String code = jsonObject.getString("deviceCode");
String startTime = jsonObject.getString("startTime"); String startTime = jsonObject.getString("startTime");
String endTime = jsonObject.getString("endTime"); String endTime = jsonObject.getString("endTime");
List<FileNode> result = faultRecorderService.getDirOrFileList("故障录波",code,startTime,endTime); List<FileNode> result = faultRecorderService.getDirOrFileList("Tracelog",code,startTime,endTime);
return R.success(result); return R.success(result);
} }

View File

@ -135,9 +135,9 @@ public class MinioViewsServcie {
try { try {
if (StringUtils.isBlank(directoryName)) { if (StringUtils.isBlank(directoryName)) {
build = ListObjectsArgs.builder().bucket(minioProperties.getBucket()).recursive(false).build(); build = ListObjectsArgs.builder().bucket(minioProperties.getBucket()).recursive(true).build();
} else { } else {
build = ListObjectsArgs.builder().bucket(minioProperties.getBucket()).prefix(directoryName+"/").recursive(false).build(); build = ListObjectsArgs.builder().bucket(minioProperties.getBucket()).prefix(directoryName+"/").recursive(true).build();
} }
Iterable<Result<Item>> results = minioClient.listObjects(build); Iterable<Result<Item>> results = minioClient.listObjects(build);
for (Result<Item> result : results) { for (Result<Item> result : results) {
@ -161,7 +161,7 @@ public class MinioViewsServcie {
lastModifyTime = zonedDateTime.format(dateFormat); lastModifyTime = zonedDateTime.format(dateFormat);
} }
if (parts.length > 0) { if (parts.length > 0) {
String nodeName = parts[1]; String nodeName = parts[2];
int type = isDir ? 0 : 1; int type = isDir ? 0 : 1;
itemName= isDir ? itemName.substring(0,itemName.lastIndexOf("/")) : itemName; itemName= isDir ? itemName.substring(0,itemName.lastIndexOf("/")) : itemName;
FileNode node = new FileNode(nodeName, type,size,lastModifyTime,"/"+itemName); FileNode node = new FileNode(nodeName, type,size,lastModifyTime,"/"+itemName);

View File

@ -44,7 +44,7 @@ public class PlcLogsController {
String code = jsonObject.getString("deviceCode"); String code = jsonObject.getString("deviceCode");
String startTime = jsonObject.getString("startTime"); String startTime = jsonObject.getString("startTime");
String endTime = jsonObject.getString("endTime"); String endTime = jsonObject.getString("endTime");
List<FileNode> result = plcLogService.getDirOrFileList("日志",code,startTime,endTime); List<FileNode> result = plcLogService.getDirOrFileList("Statuscode",code,startTime,endTime);
return R.success(result); return R.success(result);
} }

View File

@ -0,0 +1,40 @@
package com.das.modules.record.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
@TableName("sys_record_log")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class SysRecordLog {
@TableId(value = "id", type = IdType.ASSIGN_ID)
private Long id;
@TableField("user_id")
private String userId;
@TableField("user_name")
private String username;
@TableField("group_by")
private String groupBy;
@TableField("ip_address")
private String ipAddress;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@TableField("opt_time")
private Date optTime;
@TableField("opt_desc")
private String optDesc;
}

View File

@ -0,0 +1,10 @@
package com.das.modules.record.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.das.modules.record.domain.SysRecordLog;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface SysRecordLogMapper extends BaseMapper<SysRecordLog> {
}

View File

@ -0,0 +1,7 @@
package com.das.modules.record.service;
public interface SysRecordLogService {
void createRecordLog(String group, String desc);
}

View File

@ -0,0 +1,32 @@
package com.das.modules.record.service.impl;
import cn.dev33.satoken.stp.StpUtil;
import com.das.common.config.SessionUtil;
import com.das.modules.auth.domain.vo.SysUserVo;
import com.das.modules.plc.mapper.SysRunLogDescMapper;
import com.das.modules.record.domain.SysRecordLog;
import com.das.modules.record.mapper.SysRecordLogMapper;
import com.das.modules.record.service.SysRecordLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
@Service
public class SysRecordLogServiceImpl implements SysRecordLogService {
@Autowired
private SysRecordLogMapper sysRecordLogMapper;
@Override
public void createRecordLog(String group, String desc) {
SysRecordLog sysRecordLog = new SysRecordLog();
SysUserVo sysUserVo = (SysUserVo) StpUtil.getTokenSession().get(SessionUtil.SESSION_USER_KEY);
sysRecordLog.setUsername(sysUserVo.getAccount());
sysRecordLog.setUserId(sysUserVo.getAccount());
sysRecordLog.setOptTime(new Date());
sysRecordLog.setGroupBy(group);
sysRecordLog.setOptDesc(desc);
sysRecordLogMapper.insert(sysRecordLog);
}
}