Browse Source

fix:适配exa接口-导入EXA

pull/44/head
xjf 1 month ago
parent
commit
e9c3354463
  1. 12
      yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/util/ExcelUtils.java
  2. 2
      yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/controller/admin/exa/EXAController.java
  3. 12
      yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/controller/admin/exa/vo/Point.java
  4. 15
      yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/service/exa/EXAServiceImpl.java
  5. 5
      yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java

12
yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/util/ExcelUtils.java

@ -1,7 +1,9 @@
package cn.iocoder.yudao.framework.excel.core.util;
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
import cn.iocoder.yudao.framework.common.util.http.HttpUtils;
import cn.iocoder.yudao.framework.excel.core.handler.SelectSheetWriteHandler;
import cn.iocoder.yudao.module.system.enums.ErrorCodeConstants;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.converters.longconverter.LongStringConverter;
import com.alibaba.excel.support.ExcelTypeEnum;
@ -9,7 +11,10 @@ import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.multipart.MultipartFile;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.List;
/**
@ -89,11 +94,4 @@ public class ExcelUtils {
}
public static <T> List<T> readCSV(MultipartFile file, Class<T> head) throws IOException {
return EasyExcel.read(file.getInputStream(), head, null)
.excelType(ExcelTypeEnum.CSV)
.autoCloseStream(false) // 不要自动关闭,交给 Servlet 自己处理
.doReadAllSync();
}
}

2
yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/controller/admin/exa/EXAController.java

@ -133,7 +133,7 @@ public class EXAController {
public CommonResult<EXAPointImportRespVO> importExcel(@RequestParam("file") MultipartFile file,
@RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport) throws Exception {
System.out.println(file.getInputStream());
List<Point> list = ExcelUtils.readCSV(file, Point.class);
List<Point> list = ExcelUtils.read(file, Point.class);
return success(exaService.importPointList(list, updateSupport));
}

12
yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/controller/admin/exa/vo/Point.java

@ -42,12 +42,12 @@ public class Point {
@ExcelProperty("自动保存")
public Boolean AutoSave=true;
public Double UpperBound=9999999.0;
public Double LowerBound=-9999999.0;
public Double UpperLimit=9999999.0;
public Double LowerLimit=-9999999.0;
public Double UpperUpperLimit=9999999.0;
public Double LowerLowerLimit=-9999999.0;
// public Double UpperBound=9999999.0;
// public Double LowerBound=-9999999.0;
// public Double UpperLimit=9999999.0;
// public Double LowerLimit=-9999999.0;
// public Double UpperUpperLimit=9999999.0;
// public Double LowerLowerLimit=-9999999.0;
public String Comment="";
public String Note="";

15
yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/service/exa/EXAServiceImpl.java

@ -39,6 +39,7 @@ public class EXAServiceImpl implements EXAService {
private String EXA_IP;
//根据测点名称测点描述模糊查询
/**
* 根据测点名称测点描述模糊查询
*
@ -88,6 +89,7 @@ public class EXAServiceImpl implements EXAService {
public EXAResult getEXAListNowReal(EXANowListReqVO list) throws URISyntaxException, IOException {
return exaUtils.getNowDataList(EXA_IP, list);
}
/**
* 根据点号查询实时值
*
@ -99,6 +101,7 @@ public class EXAServiceImpl implements EXAService {
return exaUtils.getNowData(EXA_IP, itemName).get(0);
}
/**
* 根据点号查询历史值
*
@ -109,6 +112,7 @@ public class EXAServiceImpl implements EXAService {
public List<List<Double>> getEXAHistory(EXAHistoryReqVO exaHistoryReqVo) {
return exaUtils.getHistory(EXA_IP, exaHistoryReqVo);
}
/**
* 根据多个点号查询历史值
*
@ -124,6 +128,7 @@ public class EXAServiceImpl implements EXAService {
public String createPoint(Point pointVo) throws IOException {
return exaUtils.setPoint(EXA_IP, pointVo);
}
/**
* 查询EXA所有分组信息
*
@ -133,6 +138,7 @@ public class EXAServiceImpl implements EXAService {
public List<List<String>> getEXAGroupInfo() throws URISyntaxException, IOException {
return exaUtils.getGroup(EXA_IP);
}
/**
* 删除EXA点号
*
@ -144,6 +150,7 @@ public class EXAServiceImpl implements EXAService {
return exaUtils.deletePoint(EXA_IP, ItemName);
}
/**
* 导入EXA点号
*
@ -166,13 +173,15 @@ public class EXAServiceImpl implements EXAService {
try {
String createResult = createPoint(importUser);
EXAResult vo = JSON.parseObject(createResult, EXAResult.class);
if (vo.ReturnValue.equals(1L)) {
respVO.getCreateNames().add(importUser.getItemName());
} else if (vo.ReturnValue.equals(-19L)) {
respVO.getFailureNames().put(importUser.getItemName(), "该点号已存在");
} else {
respVO.getFailureNames().put(importUser.getItemName(), "未知错误");
}
} catch (IOException e) {
throw new RuntimeException(e);
throw exception(EXA_POINT_IMPORT_FAILED, importUser.getItemName(), e);
}
});
return respVO;

5
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java

@ -167,7 +167,6 @@ public interface ErrorCodeConstants {
ErrorCode NOTIFY_SEND_TEMPLATE_PARAM_MISS = new ErrorCode(1_002_028_000, "模板参数({})缺失");
ErrorCode EXA_POINT_IMPORT_LIST_IS_EMPTY = new ErrorCode(1_002_029_000, "导入EXA测点数据不能为空!");
// ========== 模型实例模块 3-001==========
@ -192,4 +191,8 @@ public interface ErrorCodeConstants {
// ========== Excel 导入导出 1-002-034-000 ==========
ErrorCode EXCEL_FILE_EMPTY = new ErrorCode(1_002_034_000, "Excel 文件为空");
// ========== EXA模块 1-002-034-000 ==========
ErrorCode EXA_POINT_IMPORT_LIST_IS_EMPTY = new ErrorCode(6_001_000, "导入EXA测点数据不能为空!");
ErrorCode EXA_POINT_IMPORT_FAILED = new ErrorCode(6_001_001, "导入EXA测点数据失败!失败测点:({})");
}

Loading…
Cancel
Save