diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/controller/OtaBaCxKsjjsmccsController.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/controller/OtaBaCxKsjjsmccsController.java index 01b4585de..e130485b5 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/controller/OtaBaCxKsjjsmccsController.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/controller/OtaBaCxKsjjsmccsController.java @@ -18,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 +187,26 @@ public class OtaBaCxKsjjsmccsController 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 { + try { + this.otaBaCxKsjjsmccsService.importData(file, otaId, cut); + } catch (Exception e) { + e.printStackTrace(); + return Result.error(e.getMessage()); + } + return Result.OK(); + } + } diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/IOtaBaCxKsjjsmccsService.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/IOtaBaCxKsjjsmccsService.java index a716b4495..d4c232672 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/IOtaBaCxKsjjsmccsService.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/IOtaBaCxKsjjsmccsService.java @@ -3,7 +3,10 @@ package com.jero.modules.ota.service; import com.alibaba.fastjson.JSONObject; import com.jero.modules.ota.entity.OtaBaCxKsjjsmccs; 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 IOtaBaCxKsjjsmccsService extends IService { List queryList(); JSONObject queryByOtaId(String otaId, String otaIdT); + + void exportTemplate(HttpServletResponse response, HttpServletRequest request); + + void 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/OtaBaCxKsjjsmccsServiceImpl.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxKsjjsmccsServiceImpl.java index 2d8059e19..6526cea06 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxKsjjsmccsServiceImpl.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxKsjjsmccsServiceImpl.java @@ -4,6 +4,7 @@ import cn.hutool.core.util.ObjectUtil; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.jero.common.exception.JeroBootException; import com.jero.modules.ota.entity.*; import com.jero.modules.ota.enums.OtaModuleEnum; import com.jero.modules.ota.enums.OtaTitleEnum; @@ -12,16 +13,27 @@ import com.jero.modules.ota.service.IOtaBaCxKsjjsmccsService; import com.jero.modules.ota.service.IOtaBaCxListService; 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 com.jero.modules.system.util.StringUtils; import org.apache.commons.lang3.ObjectUtils; +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.lang.reflect.Field; import java.util.*; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; /** @@ -33,6 +45,12 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @Service public class OtaBaCxKsjjsmccsServiceImpl extends ServiceImpl implements IOtaBaCxKsjjsmccsService { + @Value(value = "${ota.templatePath}") + private String templatePath; + + @Value(value = "${ota.uploadPath}") + private String uploadPath; + @Autowired private IOtaBaCxListService otaBaCxListService; @@ -180,4 +198,90 @@ public class OtaBaCxKsjjsmccsServiceImpl 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("请上传正确的文件"); + } + + List oldList = getByOtaId(otaId); + List mccsList = parseFile(upFile, otaId, cut); + ComparisonUtil cu = new ComparisonUtil(); + List reList = cu.comparisonListRecord(otaId, OtaModuleEnum.CX_KZXSJDJSFZGNMCYCS, OtaTitleEnum.GNMC.getName(), oldList, mccsList, sysDictService); + deleteByOtaId(otaId); + saveOrUpdateBatch(mccsList); + otaBaCxTxjlService.saveBatch(reList); + } + + private List parseFile(File upFile, String otaId, String cut) throws Exception { + Date now = new Date(); + List mccsList = new ArrayList<>(); + Workbook wb = ImportFileUtil.readExcel(upFile); + Sheet s = wb.getSheetAt(0); + int rows = s.getPhysicalNumberOfRows(); + for (int i = 3; i < rows; i++) { + Row row = s.getRow(i); + Cell cell = row.getCell(0); + String str = ImportFileUtil.getCellValue(cell, wb); + OtaBaCxKsjjsmccs mssc = new OtaBaCxKsjjsmccs(); + if ("证明材料".equals(str)) { + //列表数据数量,在证明材料处结束 + OtaBaCxList otaBaCxList = otaBaCxListService.queryById(otaId); + if (ObjectUtils.isNotEmpty(otaBaCxList)) { + otaBaCxList.setZxsjjsfj(str); + otaBaCxListService.editById(otaBaCxList); + } + break; + } else { + mssc.setOtaId(otaId); + mssc.setGnmc(ImportFileUtil.getCellValue(cell, wb)); + cell = row.getCell(1); + mssc.setPzqk(ImportFileUtil.getCellValueYesOrNo(cell, wb)); + cell = row.getCell(2); + mssc.setSfksj(ImportFileUtil.getCellValueYesOrNo(cell, wb)); + cell = row.getCell(3); + mssc.setJszdhjb(ImportFileUtil.getCellValue(cell, wb)); + cell = row.getCell(4); + mssc.setSjggcs(ImportFileUtil.getCellValue(cell, wb)); + cell = row.getCell(5); + mssc.setGnms(ImportFileUtil.getCellValue(cell, wb)); + cell = row.getCell(6); + mssc.setSytj(ImportFileUtil.getCellValue(cell, wb)); + cell = row.getCell(7); + mssc.setKzqmc(ImportFileUtil.getCellValue(cell, wb)); + cell = row.getCell(8); + mssc.setKzqscqy(ImportFileUtil.getCellValue(cell, wb)); + cell = row.getCell(9); + mssc.setKzqxh(ImportFileUtil.getCellValue(cell, wb)); + cell = row.getCell(10); + mssc.setYjbbxx(ImportFileUtil.getCellValue(cell, wb)); + cell = row.getCell(11); + mssc.setRjkfqy(ImportFileUtil.getCellValue(cell, wb)); + cell = row.getCell(12); + mssc.setCzxtbbh(ImportFileUtil.getCellValue(cell, wb)); + cell = row.getCell(13); + mssc.setCsyzsj(ImportFileUtil.getCellValue(cell, wb)); + mssc.setCreateTime(now); + mssc.setUpdateTime(now); + mccsList.add(mssc); + } + } + return mccsList; + } }