feat(iot): 新增设备类型字段和分组管理功能
- 在 iot_things_model 表添加 dev_type 设备类型字段 - 修改 model_name 字段字符集并更新注释 - 新增设备类型字典数据和翻译配置 - 创建 iot_group 设备分组表并初始化基础数据 - 在 iot_category 表添加 industry_code 设备编码字段 - 更新 ThingsModel 实体类添加 devType 属性 - 修改 Excel 导入功能支持 sheetName 参数并优化类型识别逻辑 - 更新数据库映射文件支持设备类型字段操作 - 优化缓存实现按设备类型区分标识符避免冲突 - 调整导入数据验证逻辑并完善错误处理机制 Signed-off-by: Gjm <你的邮箱>
This commit is contained in:
@@ -16,13 +16,18 @@ import iot.lidee.iot.model.modbus.ModbusAndThingsVO;
|
||||
import iot.lidee.iot.service.IThingsModelService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.ss.usermodel.WorkbookFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -167,11 +172,81 @@ public class ThingsModelController extends BaseController
|
||||
@PostMapping(value = "/importData")
|
||||
public AjaxResult importData(MultipartFile file,Long productId) throws Exception{
|
||||
ExcelUtil<ThingsModel> excelUtil = new ExcelUtil<>(ThingsModel.class);
|
||||
List<ThingsModel> list = excelUtil.importExcel(file.getInputStream());
|
||||
String result = thingsModelService.importData(list, productId);
|
||||
byte[] bytes = file.getBytes();
|
||||
|
||||
Workbook wb = WorkbookFactory.create(new ByteArrayInputStream(bytes));
|
||||
Sheet sheet = wb.getSheetAt(0);
|
||||
|
||||
|
||||
List<ThingsModel> list = excelUtil.importExcel(new ByteArrayInputStream(bytes));
|
||||
if (!CollectionUtils.isEmpty( list)){
|
||||
this.parseList(list);
|
||||
}
|
||||
String result = thingsModelService.importData(list, productId,sheet.getSheetName());
|
||||
return AjaxResult.success(result);
|
||||
}
|
||||
|
||||
private void parseList(List<ThingsModel> list) {
|
||||
if (list == null || list.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (ThingsModel thingsModel : list) {
|
||||
String modelName = thingsModel.getModelName();
|
||||
if (StringUtils.isEmpty(modelName)) {
|
||||
thingsModel.setType(1);
|
||||
continue;
|
||||
}
|
||||
|
||||
thingsModel.setType(classifyModelType(modelName));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据物模型名称分类类型
|
||||
* @param modelName 物模型名称
|
||||
* @return 1-属性, 2-功能, 3-事件
|
||||
*/
|
||||
private Integer classifyModelType(String modelName) {
|
||||
// 事件类型关键词
|
||||
if (containsAny(modelName, "报警", "异常", "故障", "不能", "联锁", "过长", "超限", "超限度")) {
|
||||
return 3;
|
||||
}
|
||||
|
||||
// 特殊处理:包含"高"或"低"但不包含其他功能关键词的归为事件
|
||||
if ((modelName.contains("高") || modelName.contains("低"))
|
||||
&& !containsAny(modelName, "阀", "电机", "开门", "关门", "启动", "停止")) {
|
||||
return 3;
|
||||
}
|
||||
|
||||
if (containsAny(modelName, "阀", "电机", "开门", "关门", "启动", "停止", "复位", "引入",
|
||||
"加压", "冷却", "排水", "抽气", "充气")) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
// 默认为属性类型
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断字符串是否包含任意一个关键词
|
||||
* @param str 待检查的字符串
|
||||
* @param keywords 关键词数组
|
||||
* @return 是否包含任一关键词
|
||||
*/
|
||||
private boolean containsAny(String str, String... keywords) {
|
||||
if (str == null || keywords == null) {
|
||||
return false;
|
||||
}
|
||||
for (String keyword : keywords) {
|
||||
if (str.contains(keyword)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取modbus配置可选择物模型
|
||||
|
||||
Reference in New Issue
Block a user