diff --git a/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/util/ExcelUtils.java b/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/util/ExcelUtils.java index 4535cba..d657830 100644 --- a/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/util/ExcelUtils.java +++ b/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; /** @@ -68,7 +73,7 @@ public class ExcelUtils { * @throws IOException 写入失败的情况 */ public static void writeCSV(HttpServletResponse response, String filename, String sheetName, - Class head, List data) throws IOException { + Class head, List data) throws IOException { response.setHeader("Content-Disposition", "attachment;filename=" + HttpUtils.encodeUtf8(filename)); // response.setContentType("application/vnd.ms-excel;charset=UTF-8"); response.setContentType("application/vnd.opencmlformats-officedocument.spreadsheetml.sheet"); @@ -89,11 +94,4 @@ public class ExcelUtils { } - public static List readCSV(MultipartFile file, Class head) throws IOException { - return EasyExcel.read(file.getInputStream(), head, null) - .excelType(ExcelTypeEnum.CSV) - .autoCloseStream(false) // 不要自动关闭,交给 Servlet 自己处理 - .doReadAllSync(); - } - } diff --git a/yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/controller/admin/exa/EXAController.java b/yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/controller/admin/exa/EXAController.java index a4282bd..eee1249 100644 --- a/yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/controller/admin/exa/EXAController.java +++ b/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 importExcel(@RequestParam("file") MultipartFile file, @RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport) throws Exception { System.out.println(file.getInputStream()); - List list = ExcelUtils.readCSV(file, Point.class); + List list = ExcelUtils.read(file, Point.class); return success(exaService.importPointList(list, updateSupport)); } diff --git a/yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/controller/admin/exa/vo/Point.java b/yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/controller/admin/exa/vo/Point.java index dd03725..88a9c9c 100644 --- a/yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/controller/admin/exa/vo/Point.java +++ b/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=""; diff --git a/yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/service/exa/EXAServiceImpl.java b/yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/service/exa/EXAServiceImpl.java index 25d163c..aa2e74b 100644 --- a/yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/service/exa/EXAServiceImpl.java +++ b/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; //根据测点名称测点描述模糊查询 + /** * 根据测点名称测点描述模糊查询 * @@ -47,7 +48,7 @@ public class EXAServiceImpl implements EXAService { */ @Override public PageResult getEXAPage(EXAPageReqVO reqVO) throws IOException, URISyntaxException { - List exaListAll = exaUtils.getPointInfo(EXA_IP,reqVO); + List exaListAll = exaUtils.getPointInfo(EXA_IP, reqVO); Long total = Long.valueOf(exaListAll.size()); List exaList = getPartList(exaListAll, reqVO.getPageNo(), reqVO.getPageSize()); @@ -67,7 +68,7 @@ public class EXAServiceImpl implements EXAService { list.forEach(entity -> { try { - entity.setValue(exaUtils.getNowData(EXA_IP,entity.getItemName()).get(0)); + entity.setValue(exaUtils.getNowData(EXA_IP, entity.getItemName()).get(0)); } catch (URISyntaxException e) { throw new RuntimeException(e); } catch (IOException e) { @@ -86,8 +87,9 @@ public class EXAServiceImpl implements EXAService { */ @Override 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 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 分页结果 */ @Override - public List> getEXAHistory(EXAHistoryReqVO exaHistoryReqVo) { - return exaUtils.getHistory(EXA_IP,exaHistoryReqVo); + public List> getEXAHistory(EXAHistoryReqVO exaHistoryReqVo) { + return exaUtils.getHistory(EXA_IP, exaHistoryReqVo); } + /** * 根据多个点号查询历史值 * @@ -116,23 +120,25 @@ public class EXAServiceImpl implements EXAService { * @return 分页结果 */ @Override - public List>> getEXAHistorys(EXAHistoryReqVO exaHistoryReqVo) { - return exaUtils.getHistorys(EXA_IP,exaHistoryReqVo); + public List>> getEXAHistorys(EXAHistoryReqVO exaHistoryReqVo) { + return exaUtils.getHistorys(EXA_IP, exaHistoryReqVo); } @Override - public String createPoint(Point pointVo) throws IOException { - return exaUtils.setPoint(EXA_IP,pointVo); + public String createPoint(Point pointVo) throws IOException { + return exaUtils.setPoint(EXA_IP, pointVo); } + /** * 查询EXA所有分组信息 * * @return 分页结果 */ @Override - public List> getEXAGroupInfo() throws URISyntaxException, IOException { + public List> getEXAGroupInfo() throws URISyntaxException, IOException { return exaUtils.getGroup(EXA_IP); } + /** * 删除EXA点号 * @@ -140,14 +146,15 @@ public class EXAServiceImpl implements EXAService { * @return 分页结果 */ @Override - public String deletePoint(String ItemName){ - return exaUtils.deletePoint(EXA_IP,ItemName); + public String deletePoint(String ItemName) { + return exaUtils.deletePoint(EXA_IP, ItemName); } + /** * 导入EXA点号 * - * @param importPoints 导入点号列表 + * @param importPoints 导入点号列表 * @param isUpdateSupport 是否支持更新 * @return 分页结果 */ @@ -164,15 +171,17 @@ public class EXAServiceImpl implements EXAService { .updateNames(new ArrayList<>()).failureNames(new LinkedHashMap<>()).build(); importPoints.forEach(importUser -> { try { - String createResult=createPoint(importUser); + String createResult = createPoint(importUser); EXAResult vo = JSON.parseObject(createResult, EXAResult.class); - - if(vo.ReturnValue.equals(1L)){ + 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; diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java index 46ee4df..c59a7ee 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java +++ b/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测点数据失败!失败测点:({})"); + }