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

This commit is contained in:
高嵩
2023-03-27 17:32:15 +08:00
parent 8b216ec2ae
commit eddd8faa7c
4 changed files with 113 additions and 11 deletions
@@ -3,6 +3,8 @@ 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.oss.entity.OSSFile;
import com.jero.modules.oss.service.IOSSFileService;
import com.jero.modules.ota.entity.*;
import com.jero.modules.ota.enums.OtaModuleEnum;
import com.jero.modules.ota.mapper.OtaBaCxAqcsMapper;
@@ -51,6 +53,9 @@ public class OtaBaCxAqcsServiceImpl extends ServiceImpl<OtaBaCxAqcsMapper, OtaBa
@Autowired
private ISysDictService sysDictService;
@Autowired
private IOSSFileService ossFileService;
/**
* 保存
@@ -187,13 +192,13 @@ public class OtaBaCxAqcsServiceImpl extends ServiceImpl<OtaBaCxAqcsMapper, OtaBa
if (null == upFile || null == attFile) {
throw new JeroBootException("请上传正确的文件");
}
OtaBaCxAqcs aqcs = parseFile(upFile, cut);
OtaBaCxAqcs aqcs = parseFile(upFile, attFile, cut);
aqcs.setOtaId(otaId);
add(aqcs);
return aqcs;
}
private OtaBaCxAqcs parseFile(File upFile, String cut) throws Exception {
private OtaBaCxAqcs parseFile(File upFile, File attFile, String cut) throws Exception {
OtaBaCxAqcs aqcs = new OtaBaCxAqcs();
Workbook wb = ImportFileUtil.readExcel(upFile);
Sheet s = wb.getSheetAt(0);
@@ -216,8 +221,16 @@ public class OtaBaCxAqcsServiceImpl extends ServiceImpl<OtaBaCxAqcsMapper, OtaBa
row = s.getRow(2);
cell = row.getCell(3);
aqcs.setZmcl(ImportFileUtil.getCellValue(cell, wb));
String[] strs = ImportFileUtil.getCellValue(cell, wb).split(",");
List<OSSFile> list = ImportFileUtil.uploadFiles1(attFile, strs, ossFileService);
JSONArray obj = new JSONArray();
for (OSSFile f : list) {
AttachmentEO aeo = new AttachmentEO();
aeo.setId(f.getId());
aeo.setFileName(f.getFileName());
obj.add(aeo);
}
aqcs.setZmcl(obj.toString());
return aqcs;
}
}
@@ -5,6 +5,8 @@ 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.oss.entity.OSSFile;
import com.jero.modules.oss.service.IOSSFileService;
import com.jero.modules.ota.entity.*;
import com.jero.modules.ota.enums.OtaModuleEnum;
import com.jero.modules.ota.enums.OtaTitleEnum;
@@ -58,6 +60,10 @@ public class OtaBaCxKsjxtmccsServiceImpl extends ServiceImpl<OtaBaCxKsjxtmccsMap
@Autowired
private ISysDictService sysDictService;
@Autowired
private IOSSFileService ossFileService;
/**
* 保存
*
@@ -225,7 +231,7 @@ public class OtaBaCxKsjxtmccsServiceImpl extends ServiceImpl<OtaBaCxKsjxtmccsMap
throw new JeroBootException("请上传正确的文件");
}
List<OtaBaCxKsjxtmccs> oldList = getByOtaId(otaId);
List<OtaBaCxKsjxtmccs> mccsList = parseFile(upFile, otaId, cut);
List<OtaBaCxKsjxtmccs> mccsList = parseFile(upFile, attFile, otaId, cut);
ComparisonUtil cu = new ComparisonUtil();
List<OtaBaCxTxjl> reList = cu.comparisonListRecord(otaId, OtaModuleEnum.CX_KSJDXTMCYCS, OtaTitleEnum.XTLB.getName(), oldList, mccsList, sysDictService);
deleteByOtaId(otaId);
@@ -233,7 +239,7 @@ public class OtaBaCxKsjxtmccsServiceImpl extends ServiceImpl<OtaBaCxKsjxtmccsMap
otaBaCxTxjlService.saveBatch(reList);
}
private List<OtaBaCxKsjxtmccs> parseFile(File upFile, String otaId, String cut) throws Exception {
private List<OtaBaCxKsjxtmccs> parseFile(File upFile, File attFile, String otaId, String cut) throws Exception {
Date now = new Date();
List<OtaBaCxKsjxtmccs> mccsList = new ArrayList<>();
Workbook wb = ImportFileUtil.readExcel(upFile);
@@ -248,7 +254,8 @@ public class OtaBaCxKsjxtmccsServiceImpl extends ServiceImpl<OtaBaCxKsjxtmccsMap
//列表数据数量,在证明材料处结束
OtaBaCxList otaBaCxList = otaBaCxListService.queryById(otaId);
if (ObjectUtils.isNotEmpty(otaBaCxList)) {
otaBaCxList.setZxsjxtfj(str);
String[] strs = str.split(",");
otaBaCxList.setZxsjxtfj(ImportFileUtil.uploadFiles(attFile, strs, ossFileService));
otaBaCxListService.editById(otaBaCxList);
}
break;
@@ -262,7 +269,8 @@ public class OtaBaCxKsjxtmccsServiceImpl extends ServiceImpl<OtaBaCxKsjxtmccsMap
cell = row.getCell(3);
mssc.setTpt(ImportFileUtil.getCellValue(cell, wb));
cell = row.getCell(4);
mssc.setKzqmc(ImportFileUtil.getCellValue(cell, wb));
String[] strs = ImportFileUtil.getCellValue(cell, wb).split(",");
mssc.setKzqmc(ImportFileUtil.uploadFiles(attFile, strs, ossFileService));
cell = row.getCell(5);
mssc.setAqwzxdj(ImportFileUtil.getCellValue(cell, wb));
cell = row.getCell(6);
@@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jero.common.exception.JeroBootException;
import com.jero.modules.oss.entity.OSSFile;
import com.jero.modules.oss.service.IOSSFileService;
import com.jero.modules.ota.entity.AttachmentEO;
import com.jero.modules.ota.entity.OtaBaCxTxjl;
import com.jero.modules.ota.entity.OtaBaCxZxsjyq;
@@ -53,6 +55,9 @@ public class OtaBaCxZxsjyqServiceImpl extends ServiceImpl<OtaBaCxZxsjyqMapper, O
@Autowired
private ISysDictService sysDictService;
@Autowired
private IOSSFileService ossFileService;
/**
* 保存
*
@@ -190,13 +195,13 @@ public class OtaBaCxZxsjyqServiceImpl extends ServiceImpl<OtaBaCxZxsjyqMapper, O
if (null == upFile || null == attFile) {
throw new JeroBootException("请上传正确的文件");
}
OtaBaCxZxsjyq otaBaCxZxsjyq = parseFile(upFile, cut);
OtaBaCxZxsjyq otaBaCxZxsjyq = parseFile(upFile, attFile, cut);
otaBaCxZxsjyq.setOtaId(otaId);
add(otaBaCxZxsjyq);
return otaBaCxZxsjyq;
}
private OtaBaCxZxsjyq parseFile(File upFile, String cut) throws Exception {
private OtaBaCxZxsjyq parseFile(File upFile, File attFile, String cut) throws Exception {
OtaBaCxZxsjyq otaBaCxZxsjyq = new OtaBaCxZxsjyq();
Workbook wb = ImportFileUtil.readExcel(upFile);
Sheet s = wb.getSheetAt(0);
@@ -230,9 +235,19 @@ public class OtaBaCxZxsjyqServiceImpl extends ServiceImpl<OtaBaCxZxsjyqMapper, O
row = s.getRow(11);
cell = row.getCell(2);
otaBaCxZxsjyq.setSjzt(ImportFileUtil.getCellValueYesOrNo(cell, wb));
row = s.getRow(2);
cell = row.getCell(3);
otaBaCxZxsjyq.setZmcl(ImportFileUtil.getCellValue(cell, wb));
String[] strs = ImportFileUtil.getCellValue(cell, wb).split(",");
List<OSSFile> list = ImportFileUtil.uploadFiles1(attFile, strs, ossFileService);
JSONArray obj = new JSONArray();
for (OSSFile f : list) {
AttachmentEO aeo = new AttachmentEO();
aeo.setId(f.getId());
aeo.setFileName(f.getFileName());
obj.add(aeo);
}
otaBaCxZxsjyq.setZmcl(obj.toString());
return otaBaCxZxsjyq;
}
}
@@ -3,14 +3,18 @@ package com.jero.modules.ota.utils;
import com.aliyuncs.utils.IOUtils;
import com.jero.common.constant.enums.CutEnum;
import com.jero.common.exception.JeroBootException;
import com.jero.modules.oss.entity.OSSFile;
import com.jero.modules.oss.service.IOSSFileService;
import com.jero.modules.split.common.FileUnZip;
import com.jero.modules.system.service.ISysDictService;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.entity.ContentType;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
@@ -174,4 +178,66 @@ public class ImportFileUtil {
return res;
}
public static File findFile(File file, String fileName) throws Exception {
// 获取此地址中的所有文件以及文件夹(File[] list)
File[] listFiles = file.listFiles();// 获取此地址中的所有文件以及文件夹(File[] list)
for (File file1 : listFiles) {// 遍历数组
// 判断当前的File对象是否为文件夹
if (!file1.isDirectory()) {
String name = file1.getName();
if (name.equals(fileName)) {
return file1;
}
}
}
return null;
}
public static MultipartFile createMfileByFile(File file) {
MultipartFile mFile = null;
try {
FileInputStream fileInputStream = new FileInputStream(file);
String fileName = file.getName();
fileName = fileName.substring((fileName.lastIndexOf(File.separator) + 1));
mFile = new MockMultipartFile(fileName, fileName, ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStream);
} catch (Exception e) {
e.printStackTrace();
}
return mFile;
}
public static List<OSSFile> uploadFiles1(File attFile, String[] strs, IOSSFileService ossFileService) throws Exception {
List<OSSFile> res = new ArrayList<>();
for (int i = 0; i < strs.length; i++) {
File file = ImportFileUtil.findFile(attFile, strs[i]);
if (null == file) {
throw new JeroBootException("找不到文件:" + strs[i]);
}
OSSFile ossFile = ossFileService.uploadLocalOfCos(ImportFileUtil.createMfileByFile(file), "", null, null);
if (ObjectUtils.isNotEmpty(ossFile)) {
res.add(ossFile);
}
}
return res;
}
public static String uploadFiles(File attFile, String[] strs, IOSSFileService ossFileService) throws Exception {
String res = "";
for (int i = 0; i < strs.length; i++) {
File file = ImportFileUtil.findFile(attFile, strs[i]);
if (null == file) {
throw new JeroBootException("找不到文件:" + strs[i]);
}
OSSFile ossFile = ossFileService.uploadLocalOfCos(ImportFileUtil.createMfileByFile(file), "", null, null);
if (ObjectUtils.isNotEmpty(ossFile)) {
if (i >= strs.length - 1) {
res += ossFile.getId();
} else {
res += ossFile.getId() + ",";
}
}
}
return res;
}
}