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

This commit is contained in:
高嵩
2023-03-27 16:10:22 +08:00
parent 32cd717501
commit 36db0dc5d2
16 changed files with 123 additions and 77 deletions
@@ -58,6 +58,7 @@ public class OtaBaCxListController extends JeroController<OtaBaCxList, IOtaBaCxL
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
HttpServletRequest req) { HttpServletRequest req) {
QueryWrapper<OtaBaCxList> queryWrapper = QueryGenerator.initQueryWrapper(otaBaCxList, req.getParameterMap()); QueryWrapper<OtaBaCxList> queryWrapper = QueryGenerator.initQueryWrapper(otaBaCxList, req.getParameterMap());
queryWrapper.orderByDesc("create_time");
Page<OtaBaCxList> page = new Page<OtaBaCxList>(pageNo, pageSize); Page<OtaBaCxList> page = new Page<OtaBaCxList>(pageNo, pageSize);
IPage<OtaBaCxList> pageList = otaBaCxListService.page(page, queryWrapper); IPage<OtaBaCxList> pageList = otaBaCxListService.page(page, queryWrapper);
return Result.OK(pageList); return Result.OK(pageList);
@@ -6,6 +6,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.List; import java.util.List;
/** /**
@@ -68,4 +69,6 @@ public interface IOtaBaCxAqcsService extends IService<OtaBaCxAqcs> {
void exportTemplate(HttpServletResponse response, HttpServletRequest request); void exportTemplate(HttpServletResponse response, HttpServletRequest request);
OtaBaCxAqcs importData(MultipartFile file, String otaId, String cut) throws Exception; OtaBaCxAqcs importData(MultipartFile file, String otaId, String cut) throws Exception;
OtaBaCxAqcs parseFileList(List<File> upLoadFiles, String otaId, String cut) throws Exception;
} }
@@ -6,6 +6,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.List; import java.util.List;
/** /**
@@ -68,4 +69,6 @@ public interface IOtaBaCxJbxxService extends IService<OtaBaCxJbxx> {
void exportTemplate(HttpServletResponse response, HttpServletRequest request) throws Exception; void exportTemplate(HttpServletResponse response, HttpServletRequest request) throws Exception;
OtaBaCxJbxx importData(MultipartFile file, String otaId, String cut) throws Exception; OtaBaCxJbxx importData(MultipartFile file, String otaId, String cut) throws Exception;
OtaBaCxJbxx parseFileList(List<File> upLoadFiles, String otaId, String cut) throws Exception;
} }
@@ -7,6 +7,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.List; import java.util.List;
/** /**
@@ -68,4 +69,6 @@ public interface IOtaBaCxJsfzbacsService extends IService<OtaBaCxJsfzbacs> {
void exportTemplate(HttpServletResponse response, HttpServletRequest request); void exportTemplate(HttpServletResponse response, HttpServletRequest request);
void importData(MultipartFile file, String otaId, String cut) throws Exception; void importData(MultipartFile file, String otaId, String cut) throws Exception;
void parseFileList(List<File> upLoadFiles, String otaId, String cut) throws Exception;
} }
@@ -7,6 +7,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.List; import java.util.List;
/** /**
@@ -68,4 +69,6 @@ public interface IOtaBaCxKsjjsmccsService extends IService<OtaBaCxKsjjsmccs> {
void exportTemplate(HttpServletResponse response, HttpServletRequest request); void exportTemplate(HttpServletResponse response, HttpServletRequest request);
void importData(MultipartFile file, String otaId, String cut) throws Exception; void importData(MultipartFile file, String otaId, String cut) throws Exception;
void parseFileList(List<File> upLoadFiles, String otaId, String cut) throws Exception;
} }
@@ -7,6 +7,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.List; import java.util.List;
/** /**
@@ -68,4 +69,6 @@ public interface IOtaBaCxKsjxtmccsService extends IService<OtaBaCxKsjxtmccs> {
void exportTemplate(HttpServletResponse response, HttpServletRequest request); void exportTemplate(HttpServletResponse response, HttpServletRequest request);
void importData(MultipartFile file, String otaId, String cut) throws Exception; void importData(MultipartFile file, String otaId, String cut) throws Exception;
void parseFileList(List<File> upLoadFiles, String otaId, String cut) throws Exception;
} }
@@ -68,7 +68,7 @@ public interface IOtaBaCxListService extends IService<OtaBaCxList> {
void exportTemplate(HttpServletResponse response, HttpServletRequest request); void exportTemplate(HttpServletResponse response, HttpServletRequest request);
void importData(MultipartFile file, String cut); void importData(MultipartFile file, String cut) throws Exception;
void exportData(String otaId, HttpServletResponse response, HttpServletRequest request); void exportData(String otaId, HttpServletResponse response, HttpServletRequest request);
@@ -7,6 +7,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.List; import java.util.List;
/** /**
@@ -69,4 +70,6 @@ public interface IOtaBaCxZxsjyqService extends IService<OtaBaCxZxsjyq> {
void exportTemplate(HttpServletResponse response, HttpServletRequest request); void exportTemplate(HttpServletResponse response, HttpServletRequest request);
OtaBaCxZxsjyq importData(MultipartFile file, String otaId, String cut) throws Exception; OtaBaCxZxsjyq importData(MultipartFile file, String otaId, String cut) throws Exception;
OtaBaCxZxsjyq parseFileList(List<File> upLoadFiles, String otaId, String cut) throws Exception;
} }
@@ -169,6 +169,12 @@ public class OtaBaCxAqcsServiceImpl extends ServiceImpl<OtaBaCxAqcsMapper, OtaBa
@Override @Override
public OtaBaCxAqcs importData(MultipartFile file, String otaId, String cut) throws Exception { public OtaBaCxAqcs importData(MultipartFile file, String otaId, String cut) throws Exception {
List<File> upLoadFiles = ImportFileUtil.importZip(file, cut, uploadPath); List<File> upLoadFiles = ImportFileUtil.importZip(file, cut, uploadPath);
OtaBaCxAqcs aqcs = parseFileList(upLoadFiles, otaId, cut);
return aqcs;
}
@Override
public OtaBaCxAqcs parseFileList(List<File> upLoadFiles, String otaId, String cut) throws Exception {
File attFile = null; File attFile = null;
File upFile = null; File upFile = null;
for (File f : upLoadFiles) { for (File f : upLoadFiles) {
@@ -169,9 +169,15 @@ public class OtaBaCxJbxxServiceImpl extends ServiceImpl<OtaBaCxJbxxMapper, OtaBa
@Override @Override
public OtaBaCxJbxx importData(MultipartFile file, String otaId, String cut) throws Exception { public OtaBaCxJbxx importData(MultipartFile file, String otaId, String cut) throws Exception {
List<File> upLoadFiles = ImportFileUtil.importZip(file, cut, uploadPath); List<File> upLoadFiles = ImportFileUtil.importZip(file, cut, uploadPath);
OtaBaCxJbxx jbxx = parseFileList(upLoadFiles, otaId, cut);
return jbxx;
}
@Override
public OtaBaCxJbxx parseFileList(List<File> upLoadFiles, String otaId, String cut) throws Exception {
File upFile = null; File upFile = null;
for (File f : upLoadFiles) { for (File f : upLoadFiles) {
if (f.getName().equals("可在线升级的系统名称与参数.xlsx")) { if (f.getName().equals("车型基本信息.xlsx")) {
upFile = f; upFile = f;
} }
} }
@@ -180,7 +186,8 @@ public class OtaBaCxJbxxServiceImpl extends ServiceImpl<OtaBaCxJbxxMapper, OtaBa
} }
OtaBaCxJbxx jbxx = parseFile(upFile, cut); OtaBaCxJbxx jbxx = parseFile(upFile, cut);
jbxx.setOtaId(otaId); jbxx.setOtaId(otaId);
return add(jbxx); add(jbxx);
return jbxx;
} }
private OtaBaCxJbxx parseFile(File file, String cut) throws Exception { private OtaBaCxJbxx parseFile(File file, String cut) throws Exception {
@@ -245,6 +245,11 @@ public class OtaBaCxJsfzbacsServiceImpl extends ServiceImpl<OtaBaCxJsfzbacsMappe
@Override @Override
public void importData(MultipartFile file, String otaId, String cut) throws Exception { public void importData(MultipartFile file, String otaId, String cut) throws Exception {
List<File> upLoadFiles = ImportFileUtil.importZip(file, cut, uploadPath); List<File> upLoadFiles = ImportFileUtil.importZip(file, cut, uploadPath);
parseFileList(upLoadFiles, otaId, cut);
}
@Override
public void parseFileList(List<File> upLoadFiles, String otaId, String cut) throws Exception {
File upFile = null; File upFile = null;
for (File f : upLoadFiles) { for (File f : upLoadFiles) {
if (f.getName().equals("驾驶辅助系统基础备案参数.xlsx")) { if (f.getName().equals("驾驶辅助系统基础备案参数.xlsx")) {
@@ -274,6 +279,7 @@ public class OtaBaCxJsfzbacsServiceImpl extends ServiceImpl<OtaBaCxJsfzbacsMappe
otaBaCxTxjlService.saveBatch(reList); otaBaCxTxjlService.saveBatch(reList);
} }
private List<OtaBaCxSjmk> parseList(File upFile, String otaId, String cut) throws Exception { private List<OtaBaCxSjmk> parseList(File upFile, String otaId, String cut) throws Exception {
Date now = new Date(); Date now = new Date();
List<OtaBaCxSjmk> sjmkList = new ArrayList<>(); List<OtaBaCxSjmk> sjmkList = new ArrayList<>();
@@ -98,7 +98,7 @@ public class OtaBaCxKsjjsmccsServiceImpl extends ServiceImpl<OtaBaCxKsjjsmccsMap
otaBaCxJsfzbacs.setUpdateTime(now); otaBaCxJsfzbacs.setUpdateTime(now);
newList.add(otaBaCxJsfzbacs); newList.add(otaBaCxJsfzbacs);
} }
if(ObjectUtils.isEmpty(oldList)){ if (ObjectUtils.isEmpty(oldList)) {
oldList = new ArrayList<>(); oldList = new ArrayList<>();
} }
ComparisonUtil cu = new ComparisonUtil(); ComparisonUtil cu = new ComparisonUtil();
@@ -210,6 +210,11 @@ public class OtaBaCxKsjjsmccsServiceImpl extends ServiceImpl<OtaBaCxKsjjsmccsMap
@Override @Override
public void importData(MultipartFile file, String otaId, String cut) throws Exception { public void importData(MultipartFile file, String otaId, String cut) throws Exception {
List<File> upLoadFiles = ImportFileUtil.importZip(file, cut, uploadPath); List<File> upLoadFiles = ImportFileUtil.importZip(file, cut, uploadPath);
parseFileList(upLoadFiles, otaId, cut);
}
@Override
public void parseFileList(List<File> upLoadFiles, String otaId, String cut) throws Exception {
File attFile = null; File attFile = null;
File upFile = null; File upFile = null;
for (File f : upLoadFiles) { for (File f : upLoadFiles) {
@@ -230,6 +235,7 @@ public class OtaBaCxKsjjsmccsServiceImpl extends ServiceImpl<OtaBaCxKsjjsmccsMap
deleteByOtaId(otaId); deleteByOtaId(otaId);
saveOrUpdateBatch(mccsList); saveOrUpdateBatch(mccsList);
otaBaCxTxjlService.saveBatch(reList); otaBaCxTxjlService.saveBatch(reList);
} }
private List<OtaBaCxKsjjsmccs> parseFile(File upFile, String otaId, String cut) throws Exception { private List<OtaBaCxKsjjsmccs> parseFile(File upFile, String otaId, String cut) throws Exception {
@@ -207,6 +207,11 @@ public class OtaBaCxKsjxtmccsServiceImpl extends ServiceImpl<OtaBaCxKsjxtmccsMap
@Override @Override
public void importData(MultipartFile file, String otaId, String cut) throws Exception { public void importData(MultipartFile file, String otaId, String cut) throws Exception {
List<File> upLoadFiles = ImportFileUtil.importZip(file, cut, uploadPath); List<File> upLoadFiles = ImportFileUtil.importZip(file, cut, uploadPath);
parseFileList(upLoadFiles, otaId, cut);
}
@Override
public void parseFileList(List<File> upLoadFiles, String otaId, String cut) throws Exception {
File attFile = null; File attFile = null;
File upFile = null; File upFile = null;
for (File f : upLoadFiles) { for (File f : upLoadFiles) {
@@ -2,17 +2,14 @@ package com.jero.modules.ota.service.impl;
import com.aliyuncs.utils.IOUtils; import com.aliyuncs.utils.IOUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jero.common.constant.enums.CutEnum;
import com.jero.common.exception.JeroBootException; import com.jero.common.exception.JeroBootException;
import com.jero.modules.ota.entity.OtaBaCxJbxx;
import com.jero.modules.ota.entity.OtaBaCxList; import com.jero.modules.ota.entity.OtaBaCxList;
import com.jero.modules.ota.entity.OtaBaCxLsjl; import com.jero.modules.ota.entity.OtaBaCxLsjl;
import com.jero.modules.ota.mapper.OtaBaCxListMapper; import com.jero.modules.ota.mapper.OtaBaCxListMapper;
import com.jero.modules.ota.service.IOtaBaCxListService; import com.jero.modules.ota.service.*;
import com.jero.modules.ota.service.IOtaBaCxLsjlService;
import com.jero.modules.ota.utils.ImportFileUtil; import com.jero.modules.ota.utils.ImportFileUtil;
import com.jero.modules.split.common.FileUnZip;
import com.jero.modules.system.util.StringUtils; import com.jero.modules.system.util.StringUtils;
import org.apache.commons.io.FileUtils;
import org.apache.ibatis.logging.Log; import org.apache.ibatis.logging.Log;
import org.apache.ibatis.logging.LogFactory; import org.apache.ibatis.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -22,9 +19,11 @@ import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.*; import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@@ -44,6 +43,24 @@ public class OtaBaCxListServiceImpl extends ServiceImpl<OtaBaCxListMapper, OtaBa
@Autowired @Autowired
private IOtaBaCxLsjlService otaBaCxLsjlService; private IOtaBaCxLsjlService otaBaCxLsjlService;
@Autowired
private IOtaBaCxJbxxService otaBaCxJbxxService;
@Autowired
private IOtaBaCxZxsjyqService otaBaCxZxsjyqService;
@Autowired
private IOtaBaCxAqcsService otaBaCxAqcsService;
@Autowired
private IOtaBaCxKsjxtmccsService otaBaCxKsjxtmccsService;
@Autowired
private IOtaBaCxKsjjsmccsService otaBaCxKsjjsmccsService;
@Autowired
private IOtaBaCxJsfzbacsService otaBaCxJsfzbacsService;
@Value(value = "${ota.templatePath}") @Value(value = "${ota.templatePath}")
private String templatePath; private String templatePath;
@@ -154,9 +171,19 @@ public class OtaBaCxListServiceImpl extends ServiceImpl<OtaBaCxListMapper, OtaBa
} }
@Override @Override
public void importData(MultipartFile file, String cut) { public void importData(MultipartFile file, String cut) throws Exception {
List<File> fileList =ImportFileUtil.importZip(file,cut,uploadPath); List<File> fileList = ImportFileUtil.importZip(file, cut, uploadPath);
OtaBaCxJbxx jbxx = otaBaCxJbxxService.parseFileList(fileList, "", cut);
String otaId = jbxx.getOtaId();
if (StringUtils.isNotEmpty(otaId)) {
otaBaCxZxsjyqService.parseFileList(fileList, otaId, cut);
otaBaCxAqcsService.parseFileList(fileList, otaId, cut);
otaBaCxKsjxtmccsService.parseFileList(fileList, otaId, cut);
otaBaCxKsjjsmccsService.parseFileList(fileList, otaId, cut);
otaBaCxJsfzbacsService.parseFileList(fileList, otaId, cut);
} else {
throw new JeroBootException("导入失败");
}
} }
@Override @Override
@@ -172,6 +172,12 @@ public class OtaBaCxZxsjyqServiceImpl extends ServiceImpl<OtaBaCxZxsjyqMapper, O
@Override @Override
public OtaBaCxZxsjyq importData(MultipartFile file, String otaId, String cut) throws Exception { public OtaBaCxZxsjyq importData(MultipartFile file, String otaId, String cut) throws Exception {
List<File> upLoadFiles = ImportFileUtil.importZip(file, cut, uploadPath); List<File> upLoadFiles = ImportFileUtil.importZip(file, cut, uploadPath);
OtaBaCxZxsjyq otaBaCxZxsjyq = parseFileList(upLoadFiles, otaId, cut);
return otaBaCxZxsjyq;
}
@Override
public OtaBaCxZxsjyq parseFileList(List<File> upLoadFiles, String otaId, String cut) throws Exception {
File attFile = null; File attFile = null;
File upFile = null; File upFile = null;
for (File f : upLoadFiles) { for (File f : upLoadFiles) {
@@ -48,73 +48,37 @@ public class ImportFileUtil {
} }
public static List<File> importZip(MultipartFile file, String cut, String uploadPath) { public static List<File> importZip(MultipartFile file, String cut, String uploadPath) throws Exception {
List<File> fileList = new ArrayList<>(); List<File> fileList = new ArrayList<>();
try { int pos = file.getOriginalFilename().lastIndexOf(".");
int pos = file.getOriginalFilename().lastIndexOf("."); String str = file.getOriginalFilename().substring(pos + 1).toLowerCase();
String str = file.getOriginalFilename().substring(pos + 1).toLowerCase(); String filenameorg = file.getOriginalFilename().substring(0, pos);
String filenameorg = file.getOriginalFilename().substring(0, pos); //判断上传文件必须是zip
//判断上传文件必须是zip if (!str.equals("zip") && !str.equals("rar")) {
if (!str.equals("zip") && !str.equals("rar")) { if (CutEnum.CN.getValue().equals(cut)) {
if (CutEnum.CN.getValue().equals(cut)) { throw new JeroBootException("请上传zip格式的文件或rar格式的文件");
throw new JeroBootException("请上传zip格式的文件或rar格式的文件");
} else {
throw new JeroBootException("Please upload a zip file or rar file");
}
}
String path = uploadPath + File.separator + "modal" + File.separator + filenameorg + System.currentTimeMillis();
File saveDirectory = new File(path);
if (!saveDirectory.isDirectory()) {
saveDirectory.mkdir();
}
FileUtils.copyInputStreamToFile(file.getInputStream(), new File(path + File.separator + file.getOriginalFilename()));
//解压缩
String zipEntryName = "";
if (str.equals("zip") || str.equals("rar")) {
zipEntryName = FileUnZip.unZipFiles(path + File.separator + file.getOriginalFilename(), path);
} else { } else {
// zipEntryName = FileRarUtils.rarUnCompress(path + File.separator + file.getOriginalFilename(), path); throw new JeroBootException("Please upload a zip file or rar file");
} }
//判断压缩包下是否只有一个文件夹 }
// File fileTemp = new File(path); String path = uploadPath + File.separator + "modal" + File.separator + filenameorg + System.currentTimeMillis();
// int length = fileTemp.listFiles().length; File saveDirectory = new File(path);
// if (length > 2) { if (!saveDirectory.isDirectory()) {
// //删除原上传文件 saveDirectory.mkdir();
// FileUnZip.deleteDir(saveDirectory); }
// if (CutEnum.CN.getValue().equals(cut)) { FileUtils.copyInputStreamToFile(file.getInputStream(), new File(path + File.separator + file.getOriginalFilename()));
// throw new JeroBootException("压缩包中必须有且仅有一个文件夹,请重新上传");
// } else { //解压缩
// throw new JeroBootException("There must be only one folder in the compressed package Please upload it again"); String zipEntryName = "";
// } if (str.equals("zip")) {
// zipEntryName = FileUnZip.unZipFiles(path + File.separator + file.getOriginalFilename(), path);
// } }
File fileNew = new File(zipEntryName); File fileNew = new File(path);
for (File file1 : fileNew.listFiles()) { for (File file1 : fileNew.listFiles()) {
if (file1.getName().contains(".xls") || file1.getName().contains(".xlsx") || file1.isDirectory() if (file1.getName().contains(".xls") || file1.getName().contains(".xlsx") || file1.isDirectory()
|| file1.getName().contains(".docx") || file1.getName().contains(".doc")) { || file1.getName().contains(".docx") || file1.getName().contains(".doc")) {
fileList.add(file1); fileList.add(file1);
}
} }
// if (fileList.size() == 0) {
// //删除原上传文件
// FileUnZip.deleteDir(saveDirectory);
// if (CutEnum.CN.getValue().equals(cut)) {
// throw new JeroBootException("压缩包根目录下没有excel作为导入数据,请重新上传");
// } else {
// throw new JeroBootException("Excel does not exist in the root directory of the compressed package Please upload it again");
// }
// } else if (fileList.size() > 1) {
// //删除原上传文件
// FileUnZip.deleteDir(saveDirectory);
// if (CutEnum.CN.getValue().equals(cut)) {
// throw new JeroBootException("压缩包根目录下仅能存在一个excel为导入数据,请重新上传");
// } else {
// throw new JeroBootException("Only one Excel file can be imported in the compressed package root directory. Please upload data again");
// }
// }
} catch (IOException e) {
e.printStackTrace();
} }
return fileList; return fileList;
} }