开发OTA备案工具-导入导出
This commit is contained in:
+1
@@ -58,6 +58,7 @@ public class OtaBaCxListController extends JeroController<OtaBaCxList, IOtaBaCxL
|
||||
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
|
||||
HttpServletRequest req) {
|
||||
QueryWrapper<OtaBaCxList> queryWrapper = QueryGenerator.initQueryWrapper(otaBaCxList, req.getParameterMap());
|
||||
queryWrapper.orderByDesc("create_time");
|
||||
Page<OtaBaCxList> page = new Page<OtaBaCxList>(pageNo, pageSize);
|
||||
IPage<OtaBaCxList> pageList = otaBaCxListService.page(page, queryWrapper);
|
||||
return Result.OK(pageList);
|
||||
|
||||
+3
@@ -6,6 +6,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -68,4 +69,6 @@ public interface IOtaBaCxAqcsService extends IService<OtaBaCxAqcs> {
|
||||
void exportTemplate(HttpServletResponse response, HttpServletRequest request);
|
||||
|
||||
OtaBaCxAqcs importData(MultipartFile file, String otaId, String cut) throws Exception;
|
||||
|
||||
OtaBaCxAqcs parseFileList(List<File> upLoadFiles, String otaId, String cut) throws Exception;
|
||||
}
|
||||
|
||||
+3
@@ -6,6 +6,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -68,4 +69,6 @@ public interface IOtaBaCxJbxxService extends IService<OtaBaCxJbxx> {
|
||||
void exportTemplate(HttpServletResponse response, HttpServletRequest request) throws Exception;
|
||||
|
||||
OtaBaCxJbxx importData(MultipartFile file, String otaId, String cut) throws Exception;
|
||||
|
||||
OtaBaCxJbxx parseFileList(List<File> upLoadFiles, String otaId, String cut) throws Exception;
|
||||
}
|
||||
|
||||
+3
@@ -7,6 +7,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -68,4 +69,6 @@ public interface IOtaBaCxJsfzbacsService extends IService<OtaBaCxJsfzbacs> {
|
||||
void exportTemplate(HttpServletResponse response, HttpServletRequest request);
|
||||
|
||||
void importData(MultipartFile file, String otaId, String cut) throws Exception;
|
||||
|
||||
void parseFileList(List<File> upLoadFiles, String otaId, String cut) throws Exception;
|
||||
}
|
||||
|
||||
+3
@@ -7,6 +7,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -68,4 +69,6 @@ public interface IOtaBaCxKsjjsmccsService extends IService<OtaBaCxKsjjsmccs> {
|
||||
void exportTemplate(HttpServletResponse response, HttpServletRequest request);
|
||||
|
||||
void importData(MultipartFile file, String otaId, String cut) throws Exception;
|
||||
|
||||
void parseFileList(List<File> upLoadFiles, String otaId, String cut) throws Exception;
|
||||
}
|
||||
|
||||
+3
@@ -7,6 +7,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -68,4 +69,6 @@ public interface IOtaBaCxKsjxtmccsService extends IService<OtaBaCxKsjxtmccs> {
|
||||
void exportTemplate(HttpServletResponse response, HttpServletRequest request);
|
||||
|
||||
void importData(MultipartFile file, String otaId, String cut) throws Exception;
|
||||
|
||||
void parseFileList(List<File> upLoadFiles, String otaId, String cut) throws Exception;
|
||||
}
|
||||
|
||||
+1
-1
@@ -68,7 +68,7 @@ public interface IOtaBaCxListService extends IService<OtaBaCxList> {
|
||||
|
||||
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);
|
||||
|
||||
|
||||
+3
@@ -7,6 +7,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -69,4 +70,6 @@ public interface IOtaBaCxZxsjyqService extends IService<OtaBaCxZxsjyq> {
|
||||
void exportTemplate(HttpServletResponse response, HttpServletRequest request);
|
||||
|
||||
OtaBaCxZxsjyq importData(MultipartFile file, String otaId, String cut) throws Exception;
|
||||
|
||||
OtaBaCxZxsjyq parseFileList(List<File> upLoadFiles, String otaId, String cut) throws Exception;
|
||||
}
|
||||
|
||||
+6
@@ -169,6 +169,12 @@ public class OtaBaCxAqcsServiceImpl extends ServiceImpl<OtaBaCxAqcsMapper, OtaBa
|
||||
@Override
|
||||
public OtaBaCxAqcs importData(MultipartFile file, String otaId, String cut) throws Exception {
|
||||
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 upFile = null;
|
||||
for (File f : upLoadFiles) {
|
||||
|
||||
+9
-2
@@ -169,9 +169,15 @@ public class OtaBaCxJbxxServiceImpl extends ServiceImpl<OtaBaCxJbxxMapper, OtaBa
|
||||
@Override
|
||||
public OtaBaCxJbxx importData(MultipartFile file, String otaId, String cut) throws Exception {
|
||||
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;
|
||||
for (File f : upLoadFiles) {
|
||||
if (f.getName().equals("可在线升级的系统名称与参数.xlsx")) {
|
||||
if (f.getName().equals("车型基本信息.xlsx")) {
|
||||
upFile = f;
|
||||
}
|
||||
}
|
||||
@@ -180,7 +186,8 @@ public class OtaBaCxJbxxServiceImpl extends ServiceImpl<OtaBaCxJbxxMapper, OtaBa
|
||||
}
|
||||
OtaBaCxJbxx jbxx = parseFile(upFile, cut);
|
||||
jbxx.setOtaId(otaId);
|
||||
return add(jbxx);
|
||||
add(jbxx);
|
||||
return jbxx;
|
||||
}
|
||||
|
||||
private OtaBaCxJbxx parseFile(File file, String cut) throws Exception {
|
||||
|
||||
+6
@@ -245,6 +245,11 @@ public class OtaBaCxJsfzbacsServiceImpl extends ServiceImpl<OtaBaCxJsfzbacsMappe
|
||||
@Override
|
||||
public void importData(MultipartFile file, String otaId, String cut) throws Exception {
|
||||
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;
|
||||
for (File f : upLoadFiles) {
|
||||
if (f.getName().equals("驾驶辅助系统基础备案参数.xlsx")) {
|
||||
@@ -274,6 +279,7 @@ public class OtaBaCxJsfzbacsServiceImpl extends ServiceImpl<OtaBaCxJsfzbacsMappe
|
||||
otaBaCxTxjlService.saveBatch(reList);
|
||||
}
|
||||
|
||||
|
||||
private List<OtaBaCxSjmk> parseList(File upFile, String otaId, String cut) throws Exception {
|
||||
Date now = new Date();
|
||||
List<OtaBaCxSjmk> sjmkList = new ArrayList<>();
|
||||
|
||||
+7
-1
@@ -98,7 +98,7 @@ public class OtaBaCxKsjjsmccsServiceImpl extends ServiceImpl<OtaBaCxKsjjsmccsMap
|
||||
otaBaCxJsfzbacs.setUpdateTime(now);
|
||||
newList.add(otaBaCxJsfzbacs);
|
||||
}
|
||||
if(ObjectUtils.isEmpty(oldList)){
|
||||
if (ObjectUtils.isEmpty(oldList)) {
|
||||
oldList = new ArrayList<>();
|
||||
}
|
||||
ComparisonUtil cu = new ComparisonUtil();
|
||||
@@ -210,6 +210,11 @@ public class OtaBaCxKsjjsmccsServiceImpl extends ServiceImpl<OtaBaCxKsjjsmccsMap
|
||||
@Override
|
||||
public void importData(MultipartFile file, String otaId, String cut) throws Exception {
|
||||
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 upFile = null;
|
||||
for (File f : upLoadFiles) {
|
||||
@@ -230,6 +235,7 @@ public class OtaBaCxKsjjsmccsServiceImpl extends ServiceImpl<OtaBaCxKsjjsmccsMap
|
||||
deleteByOtaId(otaId);
|
||||
saveOrUpdateBatch(mccsList);
|
||||
otaBaCxTxjlService.saveBatch(reList);
|
||||
|
||||
}
|
||||
|
||||
private List<OtaBaCxKsjjsmccs> parseFile(File upFile, String otaId, String cut) throws Exception {
|
||||
|
||||
+5
@@ -207,6 +207,11 @@ public class OtaBaCxKsjxtmccsServiceImpl extends ServiceImpl<OtaBaCxKsjxtmccsMap
|
||||
@Override
|
||||
public void importData(MultipartFile file, String otaId, String cut) throws Exception {
|
||||
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 upFile = null;
|
||||
for (File f : upLoadFiles) {
|
||||
|
||||
+37
-10
@@ -2,17 +2,14 @@ package com.jero.modules.ota.service.impl;
|
||||
|
||||
import com.aliyuncs.utils.IOUtils;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.jero.common.constant.enums.CutEnum;
|
||||
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.OtaBaCxLsjl;
|
||||
import com.jero.modules.ota.mapper.OtaBaCxListMapper;
|
||||
import com.jero.modules.ota.service.IOtaBaCxListService;
|
||||
import com.jero.modules.ota.service.IOtaBaCxLsjlService;
|
||||
import com.jero.modules.ota.service.*;
|
||||
import com.jero.modules.ota.utils.ImportFileUtil;
|
||||
import com.jero.modules.split.common.FileUnZip;
|
||||
import com.jero.modules.system.util.StringUtils;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.ibatis.logging.Log;
|
||||
import org.apache.ibatis.logging.LogFactory;
|
||||
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.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.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@@ -44,6 +43,24 @@ public class OtaBaCxListServiceImpl extends ServiceImpl<OtaBaCxListMapper, OtaBa
|
||||
@Autowired
|
||||
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}")
|
||||
private String templatePath;
|
||||
@@ -154,9 +171,19 @@ public class OtaBaCxListServiceImpl extends ServiceImpl<OtaBaCxListMapper, OtaBa
|
||||
}
|
||||
|
||||
@Override
|
||||
public void importData(MultipartFile file, String cut) {
|
||||
List<File> fileList =ImportFileUtil.importZip(file,cut,uploadPath);
|
||||
|
||||
public void importData(MultipartFile file, String cut) throws Exception {
|
||||
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
|
||||
|
||||
+6
@@ -172,6 +172,12 @@ public class OtaBaCxZxsjyqServiceImpl extends ServiceImpl<OtaBaCxZxsjyqMapper, O
|
||||
@Override
|
||||
public OtaBaCxZxsjyq importData(MultipartFile file, String otaId, String cut) throws Exception {
|
||||
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 upFile = null;
|
||||
for (File f : upLoadFiles) {
|
||||
|
||||
+27
-63
@@ -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<>();
|
||||
try {
|
||||
int pos = file.getOriginalFilename().lastIndexOf(".");
|
||||
String str = file.getOriginalFilename().substring(pos + 1).toLowerCase();
|
||||
String filenameorg = file.getOriginalFilename().substring(0, pos);
|
||||
//判断上传文件必须是zip
|
||||
if (!str.equals("zip") && !str.equals("rar")) {
|
||||
if (CutEnum.CN.getValue().equals(cut)) {
|
||||
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);
|
||||
int pos = file.getOriginalFilename().lastIndexOf(".");
|
||||
String str = file.getOriginalFilename().substring(pos + 1).toLowerCase();
|
||||
String filenameorg = file.getOriginalFilename().substring(0, pos);
|
||||
//判断上传文件必须是zip
|
||||
if (!str.equals("zip") && !str.equals("rar")) {
|
||||
if (CutEnum.CN.getValue().equals(cut)) {
|
||||
throw new JeroBootException("请上传zip格式的文件或rar格式的文件");
|
||||
} 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);
|
||||
// int length = fileTemp.listFiles().length;
|
||||
// if (length > 2) {
|
||||
// //删除原上传文件
|
||||
// FileUnZip.deleteDir(saveDirectory);
|
||||
// if (CutEnum.CN.getValue().equals(cut)) {
|
||||
// throw new JeroBootException("压缩包中必须有且仅有一个文件夹,请重新上传");
|
||||
// } else {
|
||||
// throw new JeroBootException("There must be only one folder in the compressed package Please upload it again");
|
||||
// }
|
||||
//
|
||||
// }
|
||||
File fileNew = new File(zipEntryName);
|
||||
for (File file1 : fileNew.listFiles()) {
|
||||
if (file1.getName().contains(".xls") || file1.getName().contains(".xlsx") || file1.isDirectory()
|
||||
|| file1.getName().contains(".docx") || file1.getName().contains(".doc")) {
|
||||
fileList.add(file1);
|
||||
}
|
||||
}
|
||||
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")) {
|
||||
zipEntryName = FileUnZip.unZipFiles(path + File.separator + file.getOriginalFilename(), path);
|
||||
}
|
||||
File fileNew = new File(path);
|
||||
for (File file1 : fileNew.listFiles()) {
|
||||
if (file1.getName().contains(".xls") || file1.getName().contains(".xlsx") || file1.isDirectory()
|
||||
|| file1.getName().contains(".docx") || file1.getName().contains(".doc")) {
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user