Browse Source

fix:适配exa接口-导入EXA

pull/44/head
xjf 1 month ago
parent
commit
e9c3354463
  1. 14
      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. 47
      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

14
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; 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.common.util.http.HttpUtils;
import cn.iocoder.yudao.framework.excel.core.handler.SelectSheetWriteHandler; 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.EasyExcel;
import com.alibaba.excel.converters.longconverter.LongStringConverter; import com.alibaba.excel.converters.longconverter.LongStringConverter;
import com.alibaba.excel.support.ExcelTypeEnum; import com.alibaba.excel.support.ExcelTypeEnum;
@ -9,7 +11,10 @@ import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.List;
/** /**
@ -68,7 +73,7 @@ public class ExcelUtils {
* @throws IOException 写入失败的情况 * @throws IOException 写入失败的情况
*/ */
public static <T> void writeCSV(HttpServletResponse response, String filename, String sheetName, public static <T> void writeCSV(HttpServletResponse response, String filename, String sheetName,
Class<T> head, List<T> data) throws IOException { Class<T> head, List<T> data) throws IOException {
response.setHeader("Content-Disposition", "attachment;filename=" + HttpUtils.encodeUtf8(filename)); response.setHeader("Content-Disposition", "attachment;filename=" + HttpUtils.encodeUtf8(filename));
// response.setContentType("application/vnd.ms-excel;charset=UTF-8"); // response.setContentType("application/vnd.ms-excel;charset=UTF-8");
response.setContentType("application/vnd.opencmlformats-officedocument.spreadsheetml.sheet"); response.setContentType("application/vnd.opencmlformats-officedocument.spreadsheetml.sheet");
@ -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, public CommonResult<EXAPointImportRespVO> importExcel(@RequestParam("file") MultipartFile file,
@RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport) throws Exception { @RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport) throws Exception {
System.out.println(file.getInputStream()); 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)); 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("自动保存") @ExcelProperty("自动保存")
public Boolean AutoSave=true; public Boolean AutoSave=true;
public Double UpperBound=9999999.0; // public Double UpperBound=9999999.0;
public Double LowerBound=-9999999.0; // public Double LowerBound=-9999999.0;
public Double UpperLimit=9999999.0; // public Double UpperLimit=9999999.0;
public Double LowerLimit=-9999999.0; // public Double LowerLimit=-9999999.0;
public Double UpperUpperLimit=9999999.0; // public Double UpperUpperLimit=9999999.0;
public Double LowerLowerLimit=-9999999.0; // public Double LowerLowerLimit=-9999999.0;
public String Comment=""; public String Comment="";
public String Note=""; public String Note="";

47
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; private String EXA_IP;
//根据测点名称测点描述模糊查询 //根据测点名称测点描述模糊查询
/** /**
* 根据测点名称测点描述模糊查询 * 根据测点名称测点描述模糊查询
* *
@ -47,7 +48,7 @@ public class EXAServiceImpl implements EXAService {
*/ */
@Override @Override
public PageResult<EXAHttp> getEXAPage(EXAPageReqVO reqVO) throws IOException, URISyntaxException { public PageResult<EXAHttp> getEXAPage(EXAPageReqVO reqVO) throws IOException, URISyntaxException {
List<EXAHttp> exaListAll = exaUtils.getPointInfo(EXA_IP,reqVO); List<EXAHttp> exaListAll = exaUtils.getPointInfo(EXA_IP, reqVO);
Long total = Long.valueOf(exaListAll.size()); Long total = Long.valueOf(exaListAll.size());
List<EXAHttp> exaList = getPartList(exaListAll, reqVO.getPageNo(), reqVO.getPageSize()); List<EXAHttp> exaList = getPartList(exaListAll, reqVO.getPageNo(), reqVO.getPageSize());
@ -67,7 +68,7 @@ public class EXAServiceImpl implements EXAService {
list.forEach(entity -> { list.forEach(entity -> {
try { try {
entity.setValue(exaUtils.getNowData(EXA_IP,entity.getItemName()).get(0)); entity.setValue(exaUtils.getNowData(EXA_IP, entity.getItemName()).get(0));
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} catch (IOException e) { } catch (IOException e) {
@ -86,8 +87,9 @@ public class EXAServiceImpl implements EXAService {
*/ */
@Override @Override
public EXAResult getEXAListNowReal(EXANowListReqVO list) throws URISyntaxException, IOException { public EXAResult getEXAListNowReal(EXANowListReqVO list) throws URISyntaxException, IOException {
return exaUtils.getNowDataList(EXA_IP,list); return exaUtils.getNowDataList(EXA_IP, list);
} }
/** /**
* 根据点号查询实时值 * 根据点号查询实时值
* *
@ -96,9 +98,10 @@ public class EXAServiceImpl implements EXAService {
*/ */
@Override @Override
public String getEXANow(String itemName) throws URISyntaxException, IOException { public String getEXANow(String itemName) throws URISyntaxException, IOException {
return exaUtils.getNowData(EXA_IP,itemName).get(0); return exaUtils.getNowData(EXA_IP, itemName).get(0);
} }
/** /**
* 根据点号查询历史值 * 根据点号查询历史值
* *
@ -106,9 +109,10 @@ public class EXAServiceImpl implements EXAService {
* @return 分页结果 * @return 分页结果
*/ */
@Override @Override
public List<List<Double>> getEXAHistory(EXAHistoryReqVO exaHistoryReqVo) { public List<List<Double>> getEXAHistory(EXAHistoryReqVO exaHistoryReqVo) {
return exaUtils.getHistory(EXA_IP,exaHistoryReqVo); return exaUtils.getHistory(EXA_IP, exaHistoryReqVo);
} }
/** /**
* 根据多个点号查询历史值 * 根据多个点号查询历史值
* *
@ -116,23 +120,25 @@ public class EXAServiceImpl implements EXAService {
* @return 分页结果 * @return 分页结果
*/ */
@Override @Override
public List<List<List<Double>>> getEXAHistorys(EXAHistoryReqVO exaHistoryReqVo) { public List<List<List<Double>>> getEXAHistorys(EXAHistoryReqVO exaHistoryReqVo) {
return exaUtils.getHistorys(EXA_IP,exaHistoryReqVo); return exaUtils.getHistorys(EXA_IP, exaHistoryReqVo);
} }
@Override @Override
public String createPoint(Point pointVo) throws IOException { public String createPoint(Point pointVo) throws IOException {
return exaUtils.setPoint(EXA_IP,pointVo); return exaUtils.setPoint(EXA_IP, pointVo);
} }
/** /**
* 查询EXA所有分组信息 * 查询EXA所有分组信息
* *
* @return 分页结果 * @return 分页结果
*/ */
@Override @Override
public List<List<String>> getEXAGroupInfo() throws URISyntaxException, IOException { public List<List<String>> getEXAGroupInfo() throws URISyntaxException, IOException {
return exaUtils.getGroup(EXA_IP); return exaUtils.getGroup(EXA_IP);
} }
/** /**
* 删除EXA点号 * 删除EXA点号
* *
@ -140,14 +146,15 @@ public class EXAServiceImpl implements EXAService {
* @return 分页结果 * @return 分页结果
*/ */
@Override @Override
public String deletePoint(String ItemName){ public String deletePoint(String ItemName) {
return exaUtils.deletePoint(EXA_IP,ItemName); return exaUtils.deletePoint(EXA_IP, ItemName);
} }
/** /**
* 导入EXA点号 * 导入EXA点号
* *
* @param importPoints 导入点号列表 * @param importPoints 导入点号列表
* @param isUpdateSupport 是否支持更新 * @param isUpdateSupport 是否支持更新
* @return 分页结果 * @return 分页结果
*/ */
@ -164,15 +171,17 @@ public class EXAServiceImpl implements EXAService {
.updateNames(new ArrayList<>()).failureNames(new LinkedHashMap<>()).build(); .updateNames(new ArrayList<>()).failureNames(new LinkedHashMap<>()).build();
importPoints.forEach(importUser -> { importPoints.forEach(importUser -> {
try { try {
String createResult=createPoint(importUser); String createResult = createPoint(importUser);
EXAResult vo = JSON.parseObject(createResult, EXAResult.class); EXAResult vo = JSON.parseObject(createResult, EXAResult.class);
if (vo.ReturnValue.equals(1L)) {
if(vo.ReturnValue.equals(1L)){
respVO.getCreateNames().add(importUser.getItemName()); 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) { } catch (IOException e) {
throw new RuntimeException(e); throw exception(EXA_POINT_IMPORT_FAILED, importUser.getItemName(), e);
} }
}); });
return respVO; 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 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========== // ========== 模型实例模块 3-001==========
@ -192,4 +191,8 @@ public interface ErrorCodeConstants {
// ========== Excel 导入导出 1-002-034-000 ========== // ========== Excel 导入导出 1-002-034-000 ==========
ErrorCode EXCEL_FILE_EMPTY = new ErrorCode(1_002_034_000, "Excel 文件为空"); 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