diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/controller/OtaBaSjGgnrfsController.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/controller/OtaBaSjGgnrfsController.java index 550736260..bd9c51908 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/controller/OtaBaSjGgnrfsController.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/controller/OtaBaSjGgnrfsController.java @@ -17,6 +17,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; @@ -187,4 +188,30 @@ public class OtaBaSjGgnrfsController 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 { + String[] params = otaId.split("\\?"); + otaId = params[0].equals("null") ? "" : params[0]; + cut = params[1].replace("cut=", ""); + this.otaBaSjGgnrfsService.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/controller/OtaBaSjSjfzbhController.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/controller/OtaBaSjSjfzbhController.java index 68f918d5c..092843d4f 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/controller/OtaBaSjSjfzbhController.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/controller/OtaBaSjSjfzbhController.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; @@ -185,4 +186,30 @@ public class OtaBaSjSjfzbhController 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 { + String[] params = otaId.split("\\?"); + otaId = params[0].equals("null") ? "" : params[0]; + cut = params[1].replace("cut=", ""); + this.otaBaSjSjfzbhService.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/IOtaBaSjGgnrfsService.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/IOtaBaSjGgnrfsService.java index d88eddf86..8f0b59aea 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/IOtaBaSjGgnrfsService.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/IOtaBaSjGgnrfsService.java @@ -2,6 +2,11 @@ package com.jero.modules.ota.service; import com.jero.modules.ota.entity.OtaBaSjGgnrfs; 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.io.File; import java.util.List; /** @@ -60,4 +65,11 @@ public interface IOtaBaSjGgnrfsService extends IService { List queryList(); OtaBaSjGgnrfs queryByOtaId(String otaId, String otaIdT); -} + + void exportTemplate(HttpServletResponse response, HttpServletRequest request) throws Exception; + + void importData(MultipartFile file, String otaId, String cut) throws Exception; + + void parseFileList(List upLoadFiles, String otaId, String cut) throws Exception; + + void exportData(File file, String otaId, String cut) throws Exception;} diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/IOtaBaSjSjfzbhService.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/IOtaBaSjSjfzbhService.java index 06182eeb4..ff3bfa535 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/IOtaBaSjSjfzbhService.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/IOtaBaSjSjfzbhService.java @@ -3,62 +3,75 @@ package com.jero.modules.ota.service; import com.alibaba.fastjson.JSONObject; import com.jero.modules.ota.entity.OtaBaSjSjfzbh; 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.io.File; import java.util.List; /** * @Description: 升级备案-本次升级的驾驶辅助功能与参数变化 * @Author: jero-boot - * @Date: 2023-03-17 + * @Date: 2023-03-17 * @Version: V1.0 */ public interface IOtaBaSjSjfzbhService extends IService { - /** - * 保存 - * - * @param otaBaSjSjfzbh - * @return - */ + /** + * 保存 + * + * @param otaBaSjSjfzbh + * @return + */ void add(JSONObject json); - /** - * 更新 - * - * @param otaBaSjSjfzbh - * @return - */ + /** + * 更新 + * + * @param otaBaSjSjfzbh + * @return + */ void editById(OtaBaSjSjfzbh otaBaSjSjfzbh); - /** - * 通过id删除 - * - * @param id - * @return - */ + /** + * 通过id删除 + * + * @param id + * @return + */ void deleteById(String id); - /** - * 批量删除 - * - * @param ids - * @return - */ + /** + * 批量删除 + * + * @param ids + * @return + */ void deleteByIds(List ids); - /** - * 通过id查询 - * - * @param id - * @return - */ + /** + * 通过id查询 + * + * @param id + * @return + */ OtaBaSjSjfzbh queryById(String id); /** - * 列表查询 - * - * @return - */ + * 列表查询 + * + * @return + */ List queryList(); JSONObject queryByOtaId(String otaId, String otaIdT); + + void exportTemplate(HttpServletResponse response, HttpServletRequest request) throws Exception; + + void importData(MultipartFile file, String otaId, String cut) throws Exception; + + void parseFileList(List upLoadFiles, String otaId, String cut) throws Exception; + + void exportData(File file, String otaId, String cut) throws Exception; } diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaSjGgnrfsServiceImpl.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaSjGgnrfsServiceImpl.java index 450dc1296..a3aeb236c 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaSjGgnrfsServiceImpl.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaSjGgnrfsServiceImpl.java @@ -2,6 +2,7 @@ package com.jero.modules.ota.service.impl; import com.alibaba.fastjson.JSONArray; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.jero.common.exception.JeroBootException; import com.jero.modules.ota.entity.AttachmentEO; import com.jero.modules.ota.entity.OtaBaCxAqcs; import com.jero.modules.ota.entity.OtaBaCxTxjl; @@ -11,15 +12,22 @@ import com.jero.modules.ota.mapper.OtaBaSjGgnrfsMapper; import com.jero.modules.ota.service.IOtaBaCxTxjlService; import com.jero.modules.ota.service.IOtaBaSjGgnrfsService; 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.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 +38,11 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @Service public class OtaBaSjGgnrfsServiceImpl extends ServiceImpl implements IOtaBaSjGgnrfsService { + @Value(value = "${ota.templatePath}") + private String templatePath; + + @Value(value = "${ota.uploadPath}") + private String uploadPath; @Autowired private IOtaBaCxTxjlService otaBaCxTxjlService; @@ -137,4 +150,37 @@ public class OtaBaSjGgnrfsServiceImpl extends ServiceImpl upLoadFiles = ImportFileUtil.importZip(file, cut, uploadPath); + parseFileList(upLoadFiles, otaId, cut); + } + + @Override + public void parseFileList(List upLoadFiles, String otaId, String cut) throws Exception { + 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("请上传正确的文件"); + } + } + + @Override + public void exportData(File file, String otaId, String cut) throws Exception { + + } } diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaSjListServiceImpl.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaSjListServiceImpl.java index 6170b0d8c..26ed5e1db 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaSjListServiceImpl.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaSjListServiceImpl.java @@ -50,9 +50,16 @@ public class OtaBaSjListServiceImpl extends ServiceImpl upLoadFiles = ImportFileUtil.importZip(file, cut, uploadPath); + parseFileList(upLoadFiles, otaId, cut); + } + + @Override + public void parseFileList(List upLoadFiles, String otaId, String cut) throws Exception { + 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); + if (ObjectUtils.isEmpty(oldList)) { + oldList = new ArrayList<>(); + } + List newList = parseFile(upFile, attFile, otaId, cut); + ComparisonUtil cu = new ComparisonUtil(); + List reList = cu.comparisonListRecord(otaId, OtaModuleEnum.SJ_SJJSMCBH, OtaTitleEnum.GNMC.getName(), oldList, newList, sysDictService); + deleteByOtaId(otaId); + saveOrUpdateBatch(newList); + otaBaCxTxjlService.saveBatch(reList); + } + + private List parseFile(File upFile, File attFile, String otaId, String cut) throws Exception { + Date now = new Date(); + List fzbhList = new ArrayList<>(); + Workbook wb = ImportFileUtil.readExcel(upFile); + Sheet s = wb.getSheetAt(0); + int rows = s.getPhysicalNumberOfRows(); + for (int i = 4; i < rows; i++) { + Row row = s.getRow(i); + Cell cell = row.getCell(0); + String str = ImportFileUtil.getCellValue(cell, wb); + OtaBaSjSjfzbh fzbh = new OtaBaSjSjfzbh(); + if ("证明材料".equals(str)) { + //列表数据数量,在证明材料处结束 + OtaBaSjList otaBaSjList = otaBaSjListService.queryById(otaId); + if (ObjectUtils.isNotEmpty(otaBaSjList)) { + cell = row.getCell(1); + str = ImportFileUtil.getCellValue(cell, wb); + String[] strs = str.split(","); + otaBaSjList.setSjjsfj(ImportFileUtil.uploadFiles(attFile, strs, ossFileService)); + otaBaSjListService.editById(otaBaSjList); + } + break; + } else { + fzbh.setOtaId(otaId); + fzbh.setCreateTime(now); + fzbh.setUpdateTime(now); + + cell = row.getCell(0); + fzbh.setGnmc(ImportFileUtil.getCellValue(cell, wb)); + cell = row.getCell(1); + fzbh.setSjmdlx(ImportFileUtil.getCellValue(cell, wb)); + cell = row.getCell(2); + fzbh.setSjqbgcs(ImportFileUtil.getCellValue(cell, wb)); + cell = row.getCell(3); + fzbh.setSjhbgcs(ImportFileUtil.getCellValue(cell, wb)); + cell = row.getCell(4); + fzbh.setGnbgms(ImportFileUtil.getCellValue(cell, wb)); + cell = row.getCell(5); + fzbh.setSytjbg(ImportFileUtil.getCellValue(cell, wb)); + cell = row.getCell(6); + fzbh.setSjsjkzq(ImportFileUtil.getCellValue(cell, wb)); + fzbhList.add(fzbh); + } + } + return fzbhList; + } + + @Override + public void exportData(File file, String otaId, String cut) throws Exception { + + } }