开发OTA备案工具-车辆升级

This commit is contained in:
高嵩
2023-03-29 01:48:22 +08:00
parent 99bbcf3954
commit 8ce523b4b3
7 changed files with 278 additions and 39 deletions
@@ -17,6 +17,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;
@@ -187,4 +188,30 @@ public class OtaBaSjGgnrfsController extends JeroController<OtaBaSjGgnrfs, IOtaB
return super.importExcel(request, response, OtaBaSjGgnrfs.class);
}
@ApiOperation(value = "升级备案-用户告知内容及方式-模板下载")
@GetMapping(value = "/exportTemplate")
// @RequiresPermissions("otaBaCx:exportTemplate")
public void exportTemplate(HttpServletResponse response, HttpServletRequest request) throws Exception {
this.otaBaSjGgnrfsService.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 {
String[] params = otaId.split("\\?");
otaId = params[0].equals("null") ? "" : params[0];
cut = params[1].replace("cut=", "");
this.otaBaSjGgnrfsService.importData(file, otaId, cut);
} catch (Exception e) {
e.printStackTrace();
return Result.error(e.getMessage());
}
return Result.OK();
}
}
@@ -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;
@@ -185,4 +186,30 @@ public class OtaBaSjSjfzbhController extends JeroController<OtaBaSjSjfzbh, IOtaB
return super.importExcel(request, response, OtaBaSjSjfzbh.class);
}
@ApiOperation(value = "升级备案-本次升级的驾驶辅助功能与参数变化-模板下载")
@GetMapping(value = "/exportTemplate")
// @RequiresPermissions("otaBaCx:exportTemplate")
public void exportTemplate(HttpServletResponse response, HttpServletRequest request) throws Exception {
this.otaBaSjSjfzbhService.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 {
String[] params = otaId.split("\\?");
otaId = params[0].equals("null") ? "" : params[0];
cut = params[1].replace("cut=", "");
this.otaBaSjSjfzbhService.importData(file, otaId, cut);
} catch (Exception e) {
e.printStackTrace();
return Result.error(e.getMessage());
}
return Result.OK();
}
}
@@ -2,6 +2,11 @@ package com.jero.modules.ota.service;
import com.jero.modules.ota.entity.OtaBaSjGgnrfs;
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.io.File;
import java.util.List;
/**
@@ -60,4 +65,11 @@ public interface IOtaBaSjGgnrfsService extends IService<OtaBaSjGgnrfs> {
List<OtaBaSjGgnrfs> queryList();
OtaBaSjGgnrfs queryByOtaId(String otaId, String otaIdT);
}
void exportTemplate(HttpServletResponse response, HttpServletRequest request) throws Exception;
void importData(MultipartFile file, String otaId, String cut) throws Exception;
void parseFileList(List<File> upLoadFiles, String otaId, String cut) throws Exception;
void exportData(File file, String otaId, String cut) throws Exception;}
@@ -3,62 +3,75 @@ package com.jero.modules.ota.service;
import com.alibaba.fastjson.JSONObject;
import com.jero.modules.ota.entity.OtaBaSjSjfzbh;
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.io.File;
import java.util.List;
/**
* @Description: 升级备案-本次升级的驾驶辅助功能与参数变化
* @Author: jero-boot
* @Date: 2023-03-17
* @Date: 2023-03-17
* @Version: V1.0
*/
public interface IOtaBaSjSjfzbhService extends IService<OtaBaSjSjfzbh> {
/**
* 保存
*
* @param otaBaSjSjfzbh
* @return
*/
/**
* 保存
*
* @param otaBaSjSjfzbh
* @return
*/
void add(JSONObject json);
/**
* 更新
*
* @param otaBaSjSjfzbh
* @return
*/
/**
* 更新
*
* @param otaBaSjSjfzbh
* @return
*/
void editById(OtaBaSjSjfzbh otaBaSjSjfzbh);
/**
* 通过id删除
*
* @param id
* @return
*/
/**
* 通过id删除
*
* @param id
* @return
*/
void deleteById(String id);
/**
* 批量删除
*
* @param ids
* @return
*/
/**
* 批量删除
*
* @param ids
* @return
*/
void deleteByIds(List<String> ids);
/**
* 通过id查询
*
* @param id
* @return
*/
/**
* 通过id查询
*
* @param id
* @return
*/
OtaBaSjSjfzbh queryById(String id);
/**
* 列表查询
*
* @return
*/
* 列表查询
*
* @return
*/
List<OtaBaSjSjfzbh> queryList();
JSONObject queryByOtaId(String otaId, String otaIdT);
void exportTemplate(HttpServletResponse response, HttpServletRequest request) throws Exception;
void importData(MultipartFile file, String otaId, String cut) throws Exception;
void parseFileList(List<File> upLoadFiles, String otaId, String cut) throws Exception;
void exportData(File file, String otaId, String cut) throws Exception;
}
@@ -2,6 +2,7 @@ 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.ota.entity.AttachmentEO;
import com.jero.modules.ota.entity.OtaBaCxAqcs;
import com.jero.modules.ota.entity.OtaBaCxTxjl;
@@ -11,15 +12,22 @@ import com.jero.modules.ota.mapper.OtaBaSjGgnrfsMapper;
import com.jero.modules.ota.service.IOtaBaCxTxjlService;
import com.jero.modules.ota.service.IOtaBaSjGgnrfsService;
import com.jero.modules.ota.utils.ComparisonUtil;
import com.jero.modules.ota.utils.ImportFileUtil;
import com.jero.modules.system.service.ISysDictService;
import org.apache.commons.lang3.ObjectUtils;
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.util.List;
import java.util.Date;
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: 升级备案-用户告知内容及方式
@@ -30,6 +38,11 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@Service
public class OtaBaSjGgnrfsServiceImpl extends ServiceImpl<OtaBaSjGgnrfsMapper, OtaBaSjGgnrfs> implements IOtaBaSjGgnrfsService {
@Value(value = "${ota.templatePath}")
private String templatePath;
@Value(value = "${ota.uploadPath}")
private String uploadPath;
@Autowired
private IOtaBaCxTxjlService otaBaCxTxjlService;
@@ -137,4 +150,37 @@ public class OtaBaSjGgnrfsServiceImpl extends ServiceImpl<OtaBaSjGgnrfsMapper, O
queryWrapper.eq(OtaBaSjGgnrfs::getOtaId, otaId);
return this.getOne(queryWrapper, false);
}
@Override
public void exportTemplate(HttpServletResponse response, HttpServletRequest request) throws Exception {
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);
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) {
if (f.isDirectory() && f.getName().equals("用户告知内容及方式")) {
attFile = f;
}
// else if (f.getName().equals("用户告知内容及方式.xlsx")) {
// upFile = f;
// }
}
if (null == upFile || null == attFile) {
throw new JeroBootException("请上传正确的文件");
}
}
@Override
public void exportData(File file, String otaId, String cut) throws Exception {
}
}
@@ -50,9 +50,16 @@ public class OtaBaSjListServiceImpl extends ServiceImpl<OtaBaSjListMapper, OtaBa
@Autowired
private IOtaBaCxAqcsService otaBaCxAqcsService;
@Autowired
private IOtaBaSjSjxtbhService otaBaSjSjxtbhService;
@Autowired
private IOtaBaSjSjfzbhService otaBaSjSjfzbhService;
@Autowired
private IOtaBaSjGgnrfsService otaBaSjGgnrfsService;
/**
* 保存
@@ -165,12 +172,11 @@ public class OtaBaSjListServiceImpl extends ServiceImpl<OtaBaSjListMapper, OtaBa
otaBaSjSjmbclService.parseFileList(fileList, otaId, cut);
otaBaCxAqcsService.parseFileList(fileList, otaId, cut);
otaBaSjSjxtbhService.parseFileList(fileList, otaId, cut);
otaBaSjSjfzbhService.parseFileList(fileList, otaId, cut);
otaBaSjGgnrfsService.parseFileList(fileList, otaId, cut);
} else {
throw new JeroBootException("导入失败");
}
}
@Override
@@ -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.oss.service.IOSSFileService;
import com.jero.modules.ota.entity.*;
import com.jero.modules.ota.enums.OtaModuleEnum;
@@ -13,16 +14,27 @@ import com.jero.modules.ota.service.IOtaBaCxTxjlService;
import com.jero.modules.ota.service.IOtaBaSjListService;
import com.jero.modules.ota.service.IOtaBaSjSjfzbhService;
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: 升级备案-本次升级的驾驶辅助功能与参数变化
@@ -45,6 +57,12 @@ public class OtaBaSjSjfzbhServiceImpl extends ServiceImpl<OtaBaSjSjfzbhMapper, O
@Autowired
private IOSSFileService ossFileService;
@Value(value = "${ota.templatePath}")
private String templatePath;
@Value(value = "${ota.uploadPath}")
private String uploadPath;
/**
* 保存
*/
@@ -189,4 +207,94 @@ public class OtaBaSjSjfzbhServiceImpl extends ServiceImpl<OtaBaSjSjfzbhMapper, O
queryWrapper.eq(OtaBaSjSjfzbh::getOtaId, otaId);
return this.list(queryWrapper);
}
@Override
public void exportTemplate(HttpServletResponse response, HttpServletRequest request) throws Exception {
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);
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) {
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<OtaBaSjSjfzbh> oldList = getByOtaId(otaId);
if (ObjectUtils.isEmpty(oldList)) {
oldList = new ArrayList<>();
}
List<OtaBaSjSjfzbh> newList = parseFile(upFile, attFile, otaId, cut);
ComparisonUtil cu = new ComparisonUtil();
List<OtaBaCxTxjl> reList = cu.comparisonListRecord(otaId, OtaModuleEnum.SJ_SJJSMCBH, OtaTitleEnum.GNMC.getName(), oldList, newList, sysDictService);
deleteByOtaId(otaId);
saveOrUpdateBatch(newList);
otaBaCxTxjlService.saveBatch(reList);
}
private List<OtaBaSjSjfzbh> parseFile(File upFile, File attFile, String otaId, String cut) throws Exception {
Date now = new Date();
List<OtaBaSjSjfzbh> fzbhList = new ArrayList<>();
Workbook wb = ImportFileUtil.readExcel(upFile);
Sheet s = wb.getSheetAt(0);
int rows = s.getPhysicalNumberOfRows();
for (int i = 4; i < rows; i++) {
Row row = s.getRow(i);
Cell cell = row.getCell(0);
String str = ImportFileUtil.getCellValue(cell, wb);
OtaBaSjSjfzbh fzbh = new OtaBaSjSjfzbh();
if ("证明材料".equals(str)) {
//列表数据数量,在证明材料处结束
OtaBaSjList otaBaSjList = otaBaSjListService.queryById(otaId);
if (ObjectUtils.isNotEmpty(otaBaSjList)) {
cell = row.getCell(1);
str = ImportFileUtil.getCellValue(cell, wb);
String[] strs = str.split(",");
otaBaSjList.setSjjsfj(ImportFileUtil.uploadFiles(attFile, strs, ossFileService));
otaBaSjListService.editById(otaBaSjList);
}
break;
} else {
fzbh.setOtaId(otaId);
fzbh.setCreateTime(now);
fzbh.setUpdateTime(now);
cell = row.getCell(0);
fzbh.setGnmc(ImportFileUtil.getCellValue(cell, wb));
cell = row.getCell(1);
fzbh.setSjmdlx(ImportFileUtil.getCellValue(cell, wb));
cell = row.getCell(2);
fzbh.setSjqbgcs(ImportFileUtil.getCellValue(cell, wb));
cell = row.getCell(3);
fzbh.setSjhbgcs(ImportFileUtil.getCellValue(cell, wb));
cell = row.getCell(4);
fzbh.setGnbgms(ImportFileUtil.getCellValue(cell, wb));
cell = row.getCell(5);
fzbh.setSytjbg(ImportFileUtil.getCellValue(cell, wb));
cell = row.getCell(6);
fzbh.setSjsjkzq(ImportFileUtil.getCellValue(cell, wb));
fzbhList.add(fzbh);
}
}
return fzbhList;
}
@Override
public void exportData(File file, String otaId, String cut) throws Exception {
}
}