From beeb6cb350b189fb560523a1317f16ccf4ec6b1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E4=B8=89=E7=82=AE?= <15856818120@163.com> Date: Sun, 27 Apr 2025 17:55:15 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B4=A2=E9=81=93=E8=BF=90=E8=BE=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../basic/controller/TbTowerController.java | 34 +++++++++++++++++++ .../basic/service/TbTowerService.java | 8 +++++ .../service/impl/TbTowerServiceImpl.java | 28 +++++++++++++++ 3 files changed, 70 insertions(+) diff --git a/src/main/java/com/bonus/digitalSignage/basic/controller/TbTowerController.java b/src/main/java/com/bonus/digitalSignage/basic/controller/TbTowerController.java index 7331f5e..47bf637 100644 --- a/src/main/java/com/bonus/digitalSignage/basic/controller/TbTowerController.java +++ b/src/main/java/com/bonus/digitalSignage/basic/controller/TbTowerController.java @@ -12,9 +12,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; +import java.io.IOException; import java.util.List; /** @@ -123,4 +125,36 @@ public class TbTowerController { return ServerResponse.createErroe("杆塔管理-查询所有"); } } + + /** + * 杆塔管理导出 + * @param file + * @param tbTowerVo + * @return + * @throws IOException + */ + @PostMapping(value = "/tbTowerImport") + @DecryptAndVerify(decryptedClass = TbTowerVo.class) + @LogAnnotation(operModul = "杆塔管理-导出", operation = "导出", operDesc = "系统级事件",operType="导出") + public ServerResponse tbTowerExport(MultipartFile file, TbTowerVo tbTowerVo) throws IOException { + String fileName = file.getOriginalFilename(); + if (fileName != null) { + String fileExtension = fileName.substring(fileName.lastIndexOf(".") + 1); + long fileSize = file.getSize(); + if (!fileExtension.equalsIgnoreCase("xls") && !fileExtension.equalsIgnoreCase("xlsx")) { + // 文件后缀名不符合要求 + return ServerResponse.createErroe("文件后缀名不符合要求"); + } else if (fileSize > 10 * 1024 * 1024) { + // 文件大小超过10M + return ServerResponse.createErroe("文件大小超过10M"); + } + } + ExcelUtil util = new ExcelUtil(TbTowerVo.class); + List tbTowerVoList = util.importExcel(file.getInputStream()); + if (tbTowerVoList.size()>3000){ + return ServerResponse.createErroe("文件条数超过3000"); + } + String message = tbTowerService.importMaProp(tbTowerVoList, tbTowerVo); + return ServerResponse.createSuccess(message); + } } diff --git a/src/main/java/com/bonus/digitalSignage/basic/service/TbTowerService.java b/src/main/java/com/bonus/digitalSignage/basic/service/TbTowerService.java index 616b880..6b1425f 100644 --- a/src/main/java/com/bonus/digitalSignage/basic/service/TbTowerService.java +++ b/src/main/java/com/bonus/digitalSignage/basic/service/TbTowerService.java @@ -47,4 +47,12 @@ public interface TbTowerService { * @return */ List tbProjectExport(TbTowerVo data); + + /** + * 杆塔管理导入 + * @param tbTowerVoList + * @param tbTowerVo + * @return + */ + String importMaProp(List tbTowerVoList, TbTowerVo tbTowerVo); } diff --git a/src/main/java/com/bonus/digitalSignage/basic/service/impl/TbTowerServiceImpl.java b/src/main/java/com/bonus/digitalSignage/basic/service/impl/TbTowerServiceImpl.java index 039d41a..e240136 100644 --- a/src/main/java/com/bonus/digitalSignage/basic/service/impl/TbTowerServiceImpl.java +++ b/src/main/java/com/bonus/digitalSignage/basic/service/impl/TbTowerServiceImpl.java @@ -159,4 +159,32 @@ public class TbTowerServiceImpl implements TbTowerService { List tbTowerVoList = tbTowerMapper.getTbProjectList(data); return tbTowerVoList; } + + /** + * 杆塔管理导入 + * @param tbTowerVoList + * @param tbTowerVo + * @return + */ + @Override + public String importMaProp(List tbTowerVoList, TbTowerVo tbTowerVo) { + if (tbTowerVoList.size()>0){ + int num = 1; + try { + for (int i = 0; i < tbTowerVoList.size(); i++) { + TbTowerVo tbTower = new TbTowerVo(); + tbTower.setProId(tbTowerVo.getProId()); + tbTower.setUploadType(tbTowerVo.getUploadType()); + addTbTower(tbTower); + num++; + } + }catch (Exception e){ + log.error("第{}条数据导入失败,错误信息为:{}",num,e.getMessage()); + } + return "导入成功"; + }else { + return "数据不能为空"; + } + + } }