开发OTA备案工具-导入导出

This commit is contained in:
高嵩
2023-03-27 03:46:16 +08:00
parent 79eb093e61
commit 631a56fd02
3 changed files with 134 additions and 0 deletions
@@ -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<OtaBaCxKsjjsmccs,
return super.importExcel(request, response, OtaBaCxKsjjsmccs.class);
}
@ApiOperation(value = "车型备案-可在线升级的驾驶辅助功能名称与参数-模板下载")
@GetMapping(value = "/exportTemplate")
// @RequiresPermissions("otaBaCx:exportTemplate")
public void exportTemplate(HttpServletResponse response, HttpServletRequest request) throws Exception {
this.otaBaCxKsjjsmccsService.exportTemplate(response, request);
}
@ApiOperation(value = "车型备案-可在线升级的驾驶辅助功能名称与参数-数据导入")
@PostMapping(value = "/importData")
// @RequiresPermissions("otaBaCx:importData")
public Result<?> 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();
}
}
@@ -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<OtaBaCxKsjjsmccs> {
List<OtaBaCxKsjjsmccs> queryList();
JSONObject queryByOtaId(String otaId, String otaIdT);
void exportTemplate(HttpServletResponse response, HttpServletRequest request);
void importData(MultipartFile file, String otaId, String cut) throws Exception;
}
@@ -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<OtaBaCxKsjjsmccsMapper, OtaBaCxKsjjsmccs> 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<OtaBaCxKsjjsmccsMap
}
this.deleteByIds(ids);
}
@Override
public void exportTemplate(HttpServletResponse response, HttpServletRequest request) {
ImportFileUtil.exportTemplate(response, templatePath + "可在线升级的驾驶辅助功能名称与参数.zip");
}
@Override
public void importData(MultipartFile file, String otaId, String cut) throws Exception {
List<File> 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<OtaBaCxKsjjsmccs> oldList = getByOtaId(otaId);
List<OtaBaCxKsjjsmccs> mccsList = parseFile(upFile, otaId, cut);
ComparisonUtil cu = new ComparisonUtil();
List<OtaBaCxTxjl> reList = cu.comparisonListRecord(otaId, OtaModuleEnum.CX_KZXSJDJSFZGNMCYCS, OtaTitleEnum.GNMC.getName(), oldList, mccsList, sysDictService);
deleteByOtaId(otaId);
saveOrUpdateBatch(mccsList);
otaBaCxTxjlService.saveBatch(reList);
}
private List<OtaBaCxKsjjsmccs> parseFile(File upFile, String otaId, String cut) throws Exception {
Date now = new Date();
List<OtaBaCxKsjjsmccs> 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;
}
}