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

This commit is contained in:
高嵩
2023-03-29 01:10:24 +08:00
parent 2e59c45189
commit 99bbcf3954
7 changed files with 186 additions and 37 deletions
@@ -8,6 +8,7 @@ import javax.servlet.http.HttpServletResponse;
import com.alibaba.fastjson.JSONObject;
import com.jero.common.api.vo.Result;
import com.jero.common.system.query.QueryGenerator;
import com.jero.modules.ota.entity.OtaBaCxJbxx;
import com.jero.modules.ota.entity.OtaBaSjSjxtbh;
import com.jero.modules.ota.service.IOtaBaSjSjxtbhService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -18,6 +19,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;
@@ -76,8 +78,6 @@ public class OtaBaSjSjxtbhController extends JeroController<OtaBaSjSjxtbh, IOtaB
/**
* 添加
*
* @param otaBaSjSjxtbh
* @return
*/
@AutoLog(value = "升级备案-本次升级的系统名称与参数变化-添加")
@ApiOperation(value = "升级备案-本次升级的系统名称与参数变化-添加", notes = "升级备案-本次升级的系统名称与参数变化-添加")
@@ -188,4 +188,30 @@ public class OtaBaSjSjxtbhController extends JeroController<OtaBaSjSjxtbh, IOtaB
return super.importExcel(request, response, OtaBaSjSjxtbh.class);
}
@ApiOperation(value = "升级备案-本次升级的系统名称与参数变化-模板下载")
@GetMapping(value = "/exportTemplate")
// @RequiresPermissions("otaBaCx:exportTemplate")
public void exportTemplate(HttpServletResponse response, HttpServletRequest request) throws Exception {
this.otaBaSjSjxtbhService.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.otaBaSjSjxtbhService.importData(file, otaId, cut);
} catch (Exception e) {
e.printStackTrace();
return Result.error(e.getMessage());
}
return Result.OK();
}
}
@@ -1,62 +1,75 @@
package com.jero.modules.ota.service;
import com.alibaba.fastjson.JSONObject;
import com.jero.modules.ota.entity.OtaBaCxJbxx;
import com.jero.modules.ota.entity.OtaBaSjSjxtbh;
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 IOtaBaSjSjxtbhService extends IService<OtaBaSjSjxtbh> {
/**
* 保存
*
*/
/**
* 保存
*/
void add(JSONObject json);
/**
* 更新
*
* @param otaBaSjSjxtbh
* @return
*/
/**
* 更新
*
* @param otaBaSjSjxtbh
* @return
*/
void editById(OtaBaSjSjxtbh otaBaSjSjxtbh);
/**
* 通过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
*/
OtaBaSjSjxtbh queryById(String id);
/**
* 列表查询
*
* @return
*/
* 列表查询
*
* @return
*/
List<OtaBaSjSjxtbh> queryList();
JSONObject queryByOtaId(String otaId, String otaIdT);
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;
}
@@ -284,6 +284,9 @@ public class OtaBaCxJsfzbacsServiceImpl extends ServiceImpl<OtaBaCxJsfzbacsMappe
List<OtaBaCxSjmk> oldList = OtaBaCxSjmkService.queryByOtaId(otaId);
OtaBaCxSjmkService.deleteByOtaId(otaId);
List<OtaBaCxSjmk> sjmkList = parseList(upFile, otaId, cut);
if (ObjectUtils.isEmpty(oldList)) {
oldList = new ArrayList<>();
}
reList.addAll(cu.comparisonListRecord(otaId, OtaModuleEnum.CX_JSFZXTJCBACS, OtaTitleEnum.BJMC.getName(), oldList, sjmkList, sysDictService));
OtaBaCxSjmkService.saveOrUpdateBatch(sjmkList);
otaBaCxTxjlService.saveBatch(reList);
@@ -239,6 +239,9 @@ public class OtaBaCxKsjjsmccsServiceImpl extends ServiceImpl<OtaBaCxKsjjsmccsMap
}
List<OtaBaCxKsjjsmccs> oldList = getByOtaId(otaId);
if (ObjectUtils.isEmpty(oldList)) {
oldList = new ArrayList<>();
}
List<OtaBaCxKsjjsmccs> mccsList = parseFile(upFile, attFile, otaId, cut);
ComparisonUtil cu = new ComparisonUtil();
List<OtaBaCxTxjl> reList = cu.comparisonListRecord(otaId, OtaModuleEnum.CX_KZXSJDJSFZGNMCYCS, OtaTitleEnum.GNMC.getName(), oldList, mccsList, sysDictService);
@@ -236,6 +236,9 @@ public class OtaBaCxKsjxtmccsServiceImpl extends ServiceImpl<OtaBaCxKsjxtmccsMap
throw new JeroBootException("请上传正确的文件");
}
List<OtaBaCxKsjxtmccs> oldList = getByOtaId(otaId);
if (ObjectUtils.isEmpty(oldList)) {
oldList = new ArrayList<>();
}
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);
@@ -50,6 +50,8 @@ public class OtaBaSjListServiceImpl extends ServiceImpl<OtaBaSjListMapper, OtaBa
@Autowired
private IOtaBaCxAqcsService otaBaCxAqcsService;
@Autowired
private IOtaBaSjSjxtbhService otaBaSjSjxtbhService;
/**
@@ -162,6 +164,7 @@ public class OtaBaSjListServiceImpl extends ServiceImpl<OtaBaSjListMapper, OtaBa
if (StringUtils.isNotEmpty(otaId)) {
otaBaSjSjmbclService.parseFileList(fileList, otaId, cut);
otaBaCxAqcsService.parseFileList(fileList, otaId, cut);
otaBaSjSjxtbhService.parseFileList(fileList, otaId, cut);
} else {
throw new JeroBootException("导入失败");
@@ -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;
@@ -12,16 +13,27 @@ import com.jero.modules.ota.mapper.OtaBaSjSjxtbhMapper;
import com.jero.modules.ota.service.IOtaBaCxTxjlService;
import com.jero.modules.ota.service.IOtaBaSjSjxtbhService;
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: 升级备案-本次升级的系统名称与参数变化
@@ -40,6 +52,12 @@ public class OtaBaSjSjxtbhServiceImpl extends ServiceImpl<OtaBaSjSjxtbhMapper, O
@Autowired
private IOSSFileService ossFileService;
@Value(value = "${ota.templatePath}")
private String templatePath;
@Value(value = "${ota.uploadPath}")
private String uploadPath;
/**
* 保存
*/
@@ -82,7 +100,7 @@ public class OtaBaSjSjxtbhServiceImpl extends ServiceImpl<OtaBaSjSjxtbhMapper, O
oldList = new ArrayList<>();
}
ComparisonUtil cu = new ComparisonUtil();
List<OtaBaCxTxjl> reList = cu.comparisonListRecord(otaId, OtaModuleEnum.SJ_SJXTMCBH, OtaTitleEnum.XTMC.getName(), oldList, newList, sysDictService);
List<OtaBaCxTxjl> reList = cu.comparisonListRecord(otaId, OtaModuleEnum.SJ_SJXTMCBH, OtaTitleEnum.SJKZQMC.getName(), oldList, newList, sysDictService);
saveOrUpdateBatch(newList);
otaBaCxTxjlService.saveBatch(reList);
}
@@ -173,4 +191,84 @@ public class OtaBaSjSjxtbhServiceImpl extends ServiceImpl<OtaBaSjSjxtbhMapper, O
queryWrapper.eq(OtaBaSjSjxtbh::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 upFile = null;
for (File f : upLoadFiles) {
if (f.getName().equals("本次升级的系统名称与变更参数.xlsx")) {
upFile = f;
}
}
if (null == upFile) {
throw new JeroBootException("请上传正确的文件");
}
List<OtaBaSjSjxtbh> newList = parseFile(upFile, otaId, cut);
List<OtaBaSjSjxtbh> oldList = getByOtaId(otaId);
if (ObjectUtils.isEmpty(oldList)) {
oldList = new ArrayList<>();
}
ComparisonUtil cu = new ComparisonUtil();
List<OtaBaCxTxjl> reList = cu.comparisonListRecord(otaId, OtaModuleEnum.SJ_SJXTMCBH, OtaTitleEnum.SJKZQMC.getName(), oldList, newList, sysDictService);
saveOrUpdateBatch(newList);
otaBaCxTxjlService.saveBatch(reList);
}
private List<OtaBaSjSjxtbh> parseFile(File upFile, String otaId, String cut) throws Exception {
Date now = new Date();
List<OtaBaSjSjxtbh> list = 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);
OtaBaSjSjxtbh xtbh = new OtaBaSjSjxtbh();
cell = row.getCell(1);
xtbh.setSjqbgcs(ImportFileUtil.getCellValue(cell, wb));
cell = row.getCell(2);
xtbh.setSjhbgcs(ImportFileUtil.getCellValue(cell, wb));
cell = row.getCell(3);
xtbh.setSjkzqmc(ImportFileUtil.getCellValue(cell, wb));
cell = row.getCell(4);
xtbh.setYjbb(ImportFileUtil.getCellValue(cell, wb));
cell = row.getCell(5);
xtbh.setSjqrjbb(ImportFileUtil.getCellValue(cell, wb));
cell = row.getCell(6);
xtbh.setSjhrjbb(ImportFileUtil.getCellValue(cell, wb));
cell = row.getCell(7);
xtbh.setSjqczxt(ImportFileUtil.getCellValue(cell, wb));
cell = row.getCell(8);
xtbh.setSjhczxt(ImportFileUtil.getCellValue(cell, wb));
cell = row.getCell(9);
xtbh.setSjbyzsj(ImportFileUtil.getCellValue(cell, wb));
cell = row.getCell(10);
xtbh.setSjbdx(ImportFileUtil.getCellValue(cell, wb));
cell = row.getCell(11);
xtbh.setSfcfsj(ImportFileUtil.getCellValue(cell, wb));
xtbh.setCreateTime(now);
xtbh.setUpdateTime(now);
xtbh.setOtaId(otaId);
list.add(xtbh);
}
return list;
}
@Override
public void exportData(File file, String otaId, String cut) throws Exception {
}
}