From fec7516d8579ded88e5a293af4c73f935495d5cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E5=B5=A9?= Date: Mon, 27 Mar 2023 02:34:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=8F=91OTA=E5=A4=87=E6=A1=88?= =?UTF-8?q?=E5=B7=A5=E5=85=B7-=E5=AF=BC=E5=85=A5=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ota/controller/OtaBaCxAqcsController.java | 26 +++++++ .../ota/service/IOtaBaCxAqcsService.java | 7 ++ .../service/impl/OtaBaCxAqcsServiceImpl.java | 76 ++++++++++++++++++- .../service/impl/OtaBaCxJbxxServiceImpl.java | 20 +---- .../modules/ota/utils/ImportFileUtil.java | 20 +++++ 5 files changed, 129 insertions(+), 20 deletions(-) diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/controller/OtaBaCxAqcsController.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/controller/OtaBaCxAqcsController.java index dc27d6e5c..db5503637 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/controller/OtaBaCxAqcsController.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/controller/OtaBaCxAqcsController.java @@ -8,6 +8,7 @@ import javax.servlet.http.HttpServletResponse; import com.jero.common.api.vo.Result; import com.jero.common.system.query.QueryGenerator; import com.jero.modules.ota.entity.OtaBaCxAqcs; +import com.jero.modules.ota.entity.OtaBaCxZxsjyq; import com.jero.modules.ota.service.IOtaBaCxAqcsService; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -17,6 +18,7 @@ import com.jero.common.system.base.controller.JeroController; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import org.springframework.web.servlet.ModelAndView; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -186,4 +188,28 @@ public class OtaBaCxAqcsController extends JeroController importData(@RequestParam(value = "file", required = false) MultipartFile file, + @RequestParam(value = "cut", required = false) String cut, + @RequestParam(value = "otaId", required = false) String otaId) throws Exception { + OtaBaCxAqcs res; + try { + res = this.otaBaCxAqcsService.importData(file, otaId, cut); + } catch (Exception e) { + e.printStackTrace(); + return Result.error(e.getMessage()); + } + return Result.OK(res); + } + } diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/IOtaBaCxAqcsService.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/IOtaBaCxAqcsService.java index 48e66e4f2..7e4b92cd1 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/IOtaBaCxAqcsService.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/IOtaBaCxAqcsService.java @@ -2,7 +2,10 @@ package com.jero.modules.ota.service; import com.jero.modules.ota.entity.OtaBaCxAqcs; import com.baomidou.mybatisplus.extension.service.IService; +import org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import java.util.List; /** @@ -61,4 +64,8 @@ public interface IOtaBaCxAqcsService extends IService { List queryList(); OtaBaCxAqcs queryByOtaId(String otaId, String otaIdT); + + void exportTemplate(HttpServletResponse response, HttpServletRequest request); + + OtaBaCxAqcs importData(MultipartFile file, String otaId, String cut) throws Exception; } diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxAqcsServiceImpl.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxAqcsServiceImpl.java index 9e57c2d38..8dc38038d 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxAqcsServiceImpl.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxAqcsServiceImpl.java @@ -2,25 +2,34 @@ package com.jero.modules.ota.service.impl; import com.alibaba.fastjson.JSONArray; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.jero.modules.ota.entity.AttachmentEO; -import com.jero.modules.ota.entity.OtaBaCxAqcs; -import com.jero.modules.ota.entity.OtaBaCxJbxx; -import com.jero.modules.ota.entity.OtaBaCxTxjl; +import com.jero.common.exception.JeroBootException; +import com.jero.modules.ota.entity.*; import com.jero.modules.ota.enums.OtaModuleEnum; import com.jero.modules.ota.mapper.OtaBaCxAqcsMapper; import com.jero.modules.ota.service.IOtaBaCxAqcsService; import com.jero.modules.ota.service.IOtaBaCxTxjlService; import com.jero.modules.ota.utils.ComparisonUtil; +import com.jero.modules.ota.utils.ImportFileUtil; import com.jero.modules.system.service.ISysDictService; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import java.io.File; import java.util.List; import java.util.Date; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; /** * @Description: 车型备案-安全措施 @@ -30,6 +39,11 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; */ @Service public class OtaBaCxAqcsServiceImpl extends ServiceImpl implements IOtaBaCxAqcsService { + @Value(value = "${ota.templatePath}") + private String templatePath; + + @Value(value = "${ota.uploadPath}") + private String uploadPath; @Autowired private IOtaBaCxTxjlService otaBaCxTxjlService; @@ -146,4 +160,58 @@ public class OtaBaCxAqcsServiceImpl extends ServiceImpl upLoadFiles = ImportFileUtil.importZip(file, cut, uploadPath); + File attFile = null; + File upFile = null; + for (File f : upLoadFiles) { + if (f.isDirectory() && f.getName().equals("安全措施")) { + attFile = f; + } else if (f.getName().equals("安全措施.xlsx")) { + upFile = f; + } + } + if (null == upFile || null == attFile) { + throw new JeroBootException("请上传正确的文件"); + } + OtaBaCxAqcs aqcs = parseFile(upFile, cut); + aqcs.setOtaId(otaId); + add(aqcs); + return aqcs; + } + + private OtaBaCxAqcs parseFile(File upFile, String cut) throws Exception { + OtaBaCxAqcs aqcs = new OtaBaCxAqcs(); + Workbook wb = ImportFileUtil.readExcel(upFile); + Sheet s = wb.getSheetAt(0); + + Row row = s.getRow(2); + Cell cell = row.getCell(2); + aqcs.setBhjz(ImportFileUtil.getCellValueDict(cell, wb, "protection_mechanism", sysDictService, cut)); + + row = s.getRow(3); + cell = row.getCell(2); + aqcs.setFsxjz(ImportFileUtil.getCellValueDict(cell, wb, "fail_safe_mechanism", sysDictService, cut)); + + row = s.getRow(4); + cell = row.getCell(2); + aqcs.setSjsbcs(ImportFileUtil.getCellValueDict(cell, wb, "upgrade_failure", sysDictService, cut)); + + row = s.getRow(5); + cell = row.getCell(2); + aqcs.setXxaqjz(ImportFileUtil.getCellValueDict(cell, wb, "Information_security_mechanism", sysDictService, cut)); + + row = s.getRow(2); + cell = row.getCell(3); + aqcs.setZmcl(ImportFileUtil.getCellValue(cell, wb)); + + return aqcs; + } } diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxJbxxServiceImpl.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxJbxxServiceImpl.java index 13ca660d3..7507212fb 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxJbxxServiceImpl.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxJbxxServiceImpl.java @@ -213,22 +213,10 @@ public class OtaBaCxJbxxServiceImpl extends ServiceImpl= txzdStrs.length - 1) { - sb.append(sysDictService.queryDictItemByValue("communication_terminal", txzdStrs[i], cut)); - } else { - sb.append(sysDictService.queryDictItemByValue("communication_terminal", txzdStrs[i], cut)).append(","); - } - } - jbxx.setTxzd(sb.toString()); - row = s.getRow(11); - cell = row.getCell(1); - jbxx.setCdotasj(ImportFileUtil.getCellValue(cell, wb)); - } + jbxx.setTxzd(ImportFileUtil.getCellValueDict(cell, wb, "communication_terminal", sysDictService, cut)); + row = s.getRow(11); + cell = row.getCell(1); + jbxx.setCdotasj(ImportFileUtil.getCellValue(cell, wb)); return jbxx; } diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/utils/ImportFileUtil.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/utils/ImportFileUtil.java index 2f4aa8054..85f1cfbe3 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/utils/ImportFileUtil.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/utils/ImportFileUtil.java @@ -4,6 +4,7 @@ import com.aliyuncs.utils.IOUtils; import com.jero.common.constant.enums.CutEnum; import com.jero.common.exception.JeroBootException; import com.jero.modules.split.common.FileUnZip; +import com.jero.modules.system.service.ISysDictService; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; @@ -190,4 +191,23 @@ public class ImportFileUtil { } return res; } + + public static String getCellValueDict(Cell cell, Workbook wb, String dictType, ISysDictService sysDictService, String cut) throws Exception { + String res = ""; + String str = ImportFileUtil.getCellValue(cell, wb); + if (StringUtils.isNotEmpty(str)) { + String[] strs = str.split(","); + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < strs.length; i++) { + if (i >= strs.length - 1) { + sb.append(sysDictService.queryDictItemByValue(dictType, strs[i], cut)); + } else { + sb.append(sysDictService.queryDictItemByValue(dictType, strs[i], cut)).append(","); + } + } + res = sb.toString(); + } + return res; + } + }