diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/controller/OtaBaCxZxsjyqController.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/controller/OtaBaCxZxsjyqController.java index 35ed36890..573d8480a 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/controller/OtaBaCxZxsjyqController.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/controller/OtaBaCxZxsjyqController.java @@ -1,26 +1,27 @@ package com.jero.modules.ota.controller; -import java.util.Arrays; -import java.util.List; -import javax.servlet.http.HttpServletRequest; -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.OtaBaCxZxsjyq; -import com.jero.modules.ota.service.IOtaBaCxZxsjyqService; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import lombok.extern.slf4j.Slf4j; +import com.jero.common.api.vo.Result; +import com.jero.common.aspect.annotation.AutoLog; import com.jero.common.system.base.controller.JeroController; +import com.jero.common.system.query.QueryGenerator; +import com.jero.modules.ota.entity.OtaBaCxZxsjyq; +import com.jero.modules.ota.service.IOtaBaCxZxsjyqService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; 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; -import com.jero.common.aspect.annotation.AutoLog; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.Arrays; +import java.util.List; /** @@ -183,4 +184,27 @@ public class OtaBaCxZxsjyqController 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 { + OtaBaCxZxsjyq res; + try { + res = this.otaBaCxZxsjyqService.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/IOtaBaCxZxsjyqService.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/IOtaBaCxZxsjyqService.java index ad8232b57..29f193a7b 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/IOtaBaCxZxsjyqService.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/IOtaBaCxZxsjyqService.java @@ -1,8 +1,12 @@ package com.jero.modules.ota.service; +import com.jero.modules.ota.entity.OtaBaCxJbxx; import com.jero.modules.ota.entity.OtaBaCxZxsjyq; 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 +65,8 @@ public interface IOtaBaCxZxsjyqService extends IService { List queryList(); OtaBaCxZxsjyq queryByOtaId(String otaId, String otaIdT); + + void exportTemplate(HttpServletResponse response, HttpServletRequest request); + + OtaBaCxZxsjyq 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/OtaBaCxJbxxServiceImpl.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxJbxxServiceImpl.java index ec7dad81a..13ca660d3 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 @@ -174,14 +174,6 @@ public class OtaBaCxJbxxServiceImpl extends ServiceImpl implements IOtaBaCxZxsjyqService { + @Value(value = "${ota.templatePath}") + private String templatePath; + + @Value(value = "${ota.uploadPath}") + private String uploadPath; @Autowired private IOtaBaCxTxjlService otaBaCxTxjlService; @@ -150,4 +163,70 @@ public class OtaBaCxZxsjyqServiceImpl 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("请上传正确的文件"); + } + OtaBaCxZxsjyq otaBaCxZxsjyq = parseFile(upFile, cut); + otaBaCxZxsjyq.setOtaId(otaId); + add(otaBaCxZxsjyq); + return otaBaCxZxsjyq; + } + + private OtaBaCxZxsjyq parseFile(File upFile, String cut) throws Exception { + OtaBaCxZxsjyq otaBaCxZxsjyq = new OtaBaCxZxsjyq(); + Workbook wb = ImportFileUtil.readExcel(upFile); + Sheet s = wb.getSheetAt(0); + Row row = s.getRow(2); + Cell cell = row.getCell(2); + otaBaCxZxsjyq.setBhsjb(ImportFileUtil.getCellValueYesOrNo(cell, wb)); + row = s.getRow(3); + cell = row.getCell(2); + otaBaCxZxsjyq.setBhclbb(ImportFileUtil.getCellValueYesOrNo(cell, wb)); + row = s.getRow(4); + cell = row.getCell(2); + otaBaCxZxsjyq.setClgxnl(ImportFileUtil.getCellValueYesOrNo(cell, wb)); + row = s.getRow(5); + cell = row.getCell(2); + otaBaCxZxsjyq.setClsjtj(ImportFileUtil.getCellValueYesOrNo(cell, wb)); + row = s.getRow(6); + cell = row.getCell(2); + otaBaCxZxsjyq.setClsjdl(ImportFileUtil.getCellValueYesOrNo(cell, wb)); + row = s.getRow(7); + cell = row.getCell(2); + otaBaCxZxsjyq.setSjbhaq(ImportFileUtil.getCellValueYesOrNo(cell, wb)); + row = s.getRow(8); + cell = row.getCell(2); + otaBaCxZxsjyq.setSjantj(ImportFileUtil.getCellValueYesOrNo(cell, wb)); + row = s.getRow(9); + cell = row.getCell(2); + otaBaCxZxsjyq.setSjsbaq(ImportFileUtil.getCellValueYesOrNo(cell, wb)); + row = s.getRow(10); + cell = row.getCell(2); + otaBaCxZxsjyq.setSjgg(ImportFileUtil.getCellValueYesOrNo(cell, wb)); + row = s.getRow(11); + cell = row.getCell(2); + otaBaCxZxsjyq.setSjzt(ImportFileUtil.getCellValueYesOrNo(cell, wb)); + row = s.getRow(2); + cell = row.getCell(3); + otaBaCxZxsjyq.setZmcl(ImportFileUtil.getCellValue(cell, wb)); + return otaBaCxZxsjyq; + } } 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 c33a92dbd..2f4aa8054 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 @@ -5,10 +5,10 @@ import com.jero.common.constant.enums.CutEnum; import com.jero.common.exception.JeroBootException; import com.jero.modules.split.common.FileUnZip; import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.ObjectUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.poi.hssf.usermodel.HSSFWorkbook; -import org.apache.poi.ss.usermodel.Cell; -import org.apache.poi.ss.usermodel.CellType; -import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.springframework.web.multipart.MultipartFile; @@ -166,4 +166,28 @@ public class ImportFileUtil { } return wb; } + + public static String getCellValue(Cell cell, Workbook workbook) throws Exception { + FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator(); + DataFormatter formatter = new DataFormatter(); + //单元格不设置数字格式 + if (ObjectUtils.isNotEmpty(cell)) { + cell.setCellStyle(null); + return formatter.formatCellValue(cell, evaluator); + } + return ""; + } + + public static String getCellValueYesOrNo(Cell cell, Workbook workbook) throws Exception { + String res = ""; + String str = getCellValue(cell, workbook); + if (StringUtils.isNotEmpty(str)) { + if (str.equals("是")) { + res = "1"; + } else if (str.equals("否")) { + res = "2"; + } + } + return res; + } }