From 79eb093e61e406b62400bbe08c94408b1144c594 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E5=B5=A9?= Date: Mon, 27 Mar 2023 03:28:20 +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 --- .../OtaBaCxKsjxtmccsController.java | 25 +++++ .../ota/service/IOtaBaCxKsjxtmccsService.java | 7 ++ .../impl/OtaBaCxJsfzbacsServiceImpl.java | 5 +- .../impl/OtaBaCxKsjjsmccsServiceImpl.java | 2 +- .../impl/OtaBaCxKsjxtmccsServiceImpl.java | 106 +++++++++++++++++- .../modules/ota/utils/ComparisonUtil.java | 10 +- 6 files changed, 147 insertions(+), 8 deletions(-) diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/controller/OtaBaCxKsjxtmccsController.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/controller/OtaBaCxKsjxtmccsController.java index 777960fc7..8aa33040d 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/controller/OtaBaCxKsjxtmccsController.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/controller/OtaBaCxKsjxtmccsController.java @@ -9,6 +9,7 @@ import com.alibaba.fastjson.JSONObject; import com.jero.common.api.vo.Result; import com.jero.common.system.query.QueryGenerator; import com.jero.modules.ota.entity.OtaBaCxKsjxtmccs; +import com.jero.modules.ota.entity.OtaBaCxZxsjyq; import com.jero.modules.ota.service.IOtaBaCxKsjxtmccsService; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -18,6 +19,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,27 @@ public class OtaBaCxKsjxtmccsController 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.otaBaCxKsjxtmccsService.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/IOtaBaCxKsjxtmccsService.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/IOtaBaCxKsjxtmccsService.java index a33518354..a745b52b4 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/IOtaBaCxKsjxtmccsService.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/IOtaBaCxKsjxtmccsService.java @@ -3,7 +3,10 @@ package com.jero.modules.ota.service; import com.alibaba.fastjson.JSONObject; import com.jero.modules.ota.entity.OtaBaCxKsjxtmccs; 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 IOtaBaCxKsjxtmccsService 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/OtaBaCxJsfzbacsServiceImpl.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxJsfzbacsServiceImpl.java index b3ed65347..ad1f79ba7 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxJsfzbacsServiceImpl.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxJsfzbacsServiceImpl.java @@ -53,20 +53,19 @@ public class OtaBaCxJsfzbacsServiceImpl extends ServiceImpl reList = cu.comparisonRecord(otaId, OtaModuleEnum.CX_JSFZXTJCBACS, otaBaCxJsfzbacsOld, otaBaCxJsfzbacs, sysDictService); - + saveOrUpdate(otaBaCxJsfzbacs); //处理控制器列表,先删除,后添加 List oldList = OtaBaCxSjmkService.queryByOtaId(otaId); OtaBaCxSjmkService.deleteByOtaId(otaId); JSONArray kzq = json.getJSONArray("kzq"); List sjmkList = parseKzqData(kzq, otaId); + reList.addAll(cu.comparisonListRecord(otaId, OtaModuleEnum.CX_JSFZXTJCBACS, OtaTitleEnum.BJMC.getName(), oldList, sjmkList, sysDictService)); OtaBaCxSjmkService.saveOrUpdateBatch(sjmkList); - cu.comparisonListRecord(otaId, OtaModuleEnum.CX_JSFZXTJCBACS, OtaTitleEnum.BJMC.getName(), oldList, sjmkList, sysDictService); otaBaCxTxjlService.saveBatch(reList); } 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 b87c37f44..2d8059e19 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 @@ -78,11 +78,11 @@ public class OtaBaCxKsjjsmccsServiceImpl extends ServiceImpl reList = cu.comparisonListRecord(otaId, OtaModuleEnum.CX_KZXSJDJSFZGNMCYCS, OtaTitleEnum.GNMC.getName(), oldList, newList, sysDictService); + saveOrUpdateBatch(newList); otaBaCxTxjlService.saveBatch(reList); String fj = (String) json.get("fj"); if (StringUtils.isNotEmpty(fj)) { diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxKsjxtmccsServiceImpl.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxKsjxtmccsServiceImpl.java index 3c968a234..179b957bf 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxKsjxtmccsServiceImpl.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxKsjxtmccsServiceImpl.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.IOtaBaCxKsjxtmccsService; 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; /** * @Description: 车型备案-可升级的系统名称参数 @@ -31,6 +43,11 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; */ @Service public class OtaBaCxKsjxtmccsServiceImpl extends ServiceImpl implements IOtaBaCxKsjxtmccsService { + @Value(value = "${ota.templatePath}") + private String templatePath; + + @Value(value = "${ota.uploadPath}") + private String uploadPath; @Autowired private IOtaBaCxListService otaBaCxListService; @@ -77,11 +94,11 @@ public class OtaBaCxKsjxtmccsServiceImpl extends ServiceImpl reList = cu.comparisonListRecord(otaId, OtaModuleEnum.CX_KSJDXTMCYCS, OtaTitleEnum.XTLB.getName(), oldList, newList, sysDictService); + saveOrUpdateBatch(newList); otaBaCxTxjlService.saveBatch(reList); String fj = (String) json.get("fj"); if (StringUtils.isNotEmpty(fj)) { @@ -181,4 +198,91 @@ public class OtaBaCxKsjxtmccsServiceImpl 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_KSJDXTMCYCS, OtaTitleEnum.XTLB.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); + OtaBaCxKsjxtmccs mssc = new OtaBaCxKsjxtmccs(); + if ("证明材料".equals(str)) { + //列表数据数量,在证明材料处结束 + OtaBaCxList otaBaCxList = otaBaCxListService.queryById(otaId); + if (ObjectUtils.isNotEmpty(otaBaCxList)) { + otaBaCxList.setZxsjxtfj(str); + otaBaCxListService.editById(otaBaCxList); + } + break; + } else { + mssc.setOtaId(otaId); + mssc.setXtlb(ImportFileUtil.getCellValue(cell, wb)); + cell = row.getCell(1); + mssc.setSfksj(ImportFileUtil.getCellValueYesOrNo(cell, wb)); + cell = row.getCell(2); + mssc.setSjbgcs(ImportFileUtil.getCellValue(cell, wb)); + cell = row.getCell(3); + mssc.setTpt(ImportFileUtil.getCellValue(cell, wb)); + cell = row.getCell(4); + mssc.setKzqmc(ImportFileUtil.getCellValue(cell, wb)); + cell = row.getCell(5); + mssc.setAqwzxdj(ImportFileUtil.getCellValue(cell, wb)); + cell = row.getCell(6); + mssc.setKzqscqy(ImportFileUtil.getCellValue(cell, wb)); + cell = row.getCell(7); + mssc.setKzqxh(ImportFileUtil.getCellValue(cell, wb)); + cell = row.getCell(8); + mssc.setYjbbxx(ImportFileUtil.getCellValue(cell, wb)); + cell = row.getCell(9); + mssc.setCsrjbbh(ImportFileUtil.getCellValue(cell, wb)); + cell = row.getCell(10); + mssc.setCsrjbwzsj(ImportFileUtil.getCellValue(cell, wb)); + cell = row.getCell(11); + mssc.setSjsfyx(ImportFileUtil.getCellValue(cell, wb)); + cell = row.getCell(12); + mssc.setCzxtlx(ImportFileUtil.getCellValue(cell, wb)); + cell = row.getCell(13); + mssc.setCzxtscqy(ImportFileUtil.getCellValue(cell, wb)); + cell = row.getCell(14); + mssc.setCzxtbbh(ImportFileUtil.getCellValue(cell, wb)); + mssc.setCreateTime(now); + mssc.setUpdateTime(now); + mccsList.add(mssc); + } + } + return mccsList; + } } diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/utils/ComparisonUtil.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/utils/ComparisonUtil.java index 14590deba..6a991d9f1 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/utils/ComparisonUtil.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/utils/ComparisonUtil.java @@ -54,7 +54,9 @@ public class ComparisonUtil { idField.setAccessible(true); Object id = idField.get(newObj); if (ObjectUtils.isEmpty(id)) { - String content = "新增了一条" + newObj.getClass().getDeclaredField(tableTitle).get(newObj).toString(); + Field tableField = newObj.getClass().getDeclaredField(tableTitle); + tableField.setAccessible(true); + String content = "新增了一条" + tableField.get(newObj).toString(); resList.add(new OtaBaCxTxjl(otaId, otaModuleEnum.getName(), content)); Field[] fields = newObj.getClass().getDeclaredFields(); for (Field field : fields) { @@ -70,7 +72,7 @@ public class ComparisonUtil { if (ObjectUtils.isNotEmpty(newVal)) { newStr = newVal.toString(); } - content = "增加" + newObj.getClass().getDeclaredField(tableTitle).get(newObj).toString() + "中" + title + "为" + newStr; + content = "增加" + tableField.get(newObj).toString() + "中" + title + "为" + newStr; resList.add(new OtaBaCxTxjl(otaId, otaModuleEnum.getName(), content)); } } else { @@ -134,7 +136,9 @@ public class ComparisonUtil { Object newVal = field.get(newClazz); String newTitleStr = "空"; if (ObjectUtils.isNotEmpty(newVal)) { - Object newTitleVal = newVal.getClass().getDeclaredField(tableTitle).get(newVal); + Field tableField = newVal.getClass().getDeclaredField(tableTitle); + tableField.setAccessible(true); + Object newTitleVal = tableField.get(newVal); if (ObjectUtils.isNotEmpty(newTitleVal)) { newTitleStr = newTitleVal.toString(); }