开发OTA备案工具-导入导出
This commit is contained in:
+25
@@ -9,6 +9,7 @@ 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.OtaBaCxKsjxtmccs;
|
||||
import com.jero.modules.ota.entity.OtaBaCxZxsjyq;
|
||||
import com.jero.modules.ota.service.IOtaBaCxKsjxtmccsService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
@@ -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;
|
||||
@@ -186,4 +188,27 @@ public class OtaBaCxKsjxtmccsController extends JeroController<OtaBaCxKsjxtmccs,
|
||||
return super.importExcel(request, response, OtaBaCxKsjxtmccs.class);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "车型备案-可升级的系统名称参数-模板下载")
|
||||
@GetMapping(value = "/exportTemplate")
|
||||
// @RequiresPermissions("otaBaCx:exportTemplate")
|
||||
public void exportTemplate(HttpServletResponse response, HttpServletRequest request) throws Exception {
|
||||
this.otaBaCxKsjxtmccsService.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 {
|
||||
this.otaBaCxKsjxtmccsService.importData(file, otaId, cut);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
return Result.OK();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+7
@@ -3,7 +3,10 @@ package com.jero.modules.ota.service;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.jero.modules.ota.entity.OtaBaCxKsjxtmccs;
|
||||
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.util.List;
|
||||
|
||||
/**
|
||||
@@ -61,4 +64,8 @@ public interface IOtaBaCxKsjxtmccsService extends IService<OtaBaCxKsjxtmccs> {
|
||||
List<OtaBaCxKsjxtmccs> queryList();
|
||||
|
||||
JSONObject queryByOtaId(String otaId, String otaIdT);
|
||||
|
||||
void exportTemplate(HttpServletResponse response, HttpServletRequest request);
|
||||
|
||||
void importData(MultipartFile file, String otaId, String cut) throws Exception;
|
||||
}
|
||||
|
||||
+2
-3
@@ -53,20 +53,19 @@ public class OtaBaCxJsfzbacsServiceImpl extends ServiceImpl<OtaBaCxJsfzbacsMappe
|
||||
Date now = new Date();
|
||||
otaBaCxJsfzbacs.setCreateTime(now);
|
||||
otaBaCxJsfzbacs.setUpdateTime(now);
|
||||
saveOrUpdate(otaBaCxJsfzbacs);
|
||||
ComparisonUtil cu = new ComparisonUtil();
|
||||
if (ObjectUtils.isEmpty(otaBaCxJsfzbacsOld)) {
|
||||
otaBaCxJsfzbacsOld = new OtaBaCxJsfzbacs();
|
||||
}
|
||||
List<OtaBaCxTxjl> reList = cu.comparisonRecord(otaId, OtaModuleEnum.CX_JSFZXTJCBACS, otaBaCxJsfzbacsOld, otaBaCxJsfzbacs, sysDictService);
|
||||
|
||||
saveOrUpdate(otaBaCxJsfzbacs);
|
||||
//处理控制器列表,先删除,后添加
|
||||
List<OtaBaCxSjmk> oldList = OtaBaCxSjmkService.queryByOtaId(otaId);
|
||||
OtaBaCxSjmkService.deleteByOtaId(otaId);
|
||||
JSONArray kzq = json.getJSONArray("kzq");
|
||||
List<OtaBaCxSjmk> sjmkList = parseKzqData(kzq, otaId);
|
||||
reList.addAll(cu.comparisonListRecord(otaId, OtaModuleEnum.CX_JSFZXTJCBACS, OtaTitleEnum.BJMC.getName(), oldList, sjmkList, sysDictService));
|
||||
OtaBaCxSjmkService.saveOrUpdateBatch(sjmkList);
|
||||
cu.comparisonListRecord(otaId, OtaModuleEnum.CX_JSFZXTJCBACS, OtaTitleEnum.BJMC.getName(), oldList, sjmkList, sysDictService);
|
||||
otaBaCxTxjlService.saveBatch(reList);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -78,11 +78,11 @@ public class OtaBaCxKsjjsmccsServiceImpl extends ServiceImpl<OtaBaCxKsjjsmccsMap
|
||||
otaBaCxJsfzbacs.setOtaId(otaId);
|
||||
otaBaCxJsfzbacs.setCreateTime(now);
|
||||
otaBaCxJsfzbacs.setUpdateTime(now);
|
||||
saveOrUpdate(otaBaCxJsfzbacs);
|
||||
newList.add(otaBaCxJsfzbacs);
|
||||
}
|
||||
ComparisonUtil cu = new ComparisonUtil();
|
||||
List<OtaBaCxTxjl> reList = cu.comparisonListRecord(otaId, OtaModuleEnum.CX_KZXSJDJSFZGNMCYCS, OtaTitleEnum.GNMC.getName(), oldList, newList, sysDictService);
|
||||
saveOrUpdateBatch(newList);
|
||||
otaBaCxTxjlService.saveBatch(reList);
|
||||
String fj = (String) json.get("fj");
|
||||
if (StringUtils.isNotEmpty(fj)) {
|
||||
|
||||
+105
-1
@@ -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.ota.entity.*;
|
||||
import com.jero.modules.ota.enums.OtaModuleEnum;
|
||||
import com.jero.modules.ota.enums.OtaTitleEnum;
|
||||
@@ -12,16 +13,27 @@ import com.jero.modules.ota.service.IOtaBaCxKsjxtmccsService;
|
||||
import com.jero.modules.ota.service.IOtaBaCxListService;
|
||||
import com.jero.modules.ota.service.IOtaBaCxTxjlService;
|
||||
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: 车型备案-可升级的系统名称参数
|
||||
@@ -31,6 +43,11 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
*/
|
||||
@Service
|
||||
public class OtaBaCxKsjxtmccsServiceImpl extends ServiceImpl<OtaBaCxKsjxtmccsMapper, OtaBaCxKsjxtmccs> implements IOtaBaCxKsjxtmccsService {
|
||||
@Value(value = "${ota.templatePath}")
|
||||
private String templatePath;
|
||||
|
||||
@Value(value = "${ota.uploadPath}")
|
||||
private String uploadPath;
|
||||
|
||||
@Autowired
|
||||
private IOtaBaCxListService otaBaCxListService;
|
||||
@@ -77,11 +94,11 @@ public class OtaBaCxKsjxtmccsServiceImpl extends ServiceImpl<OtaBaCxKsjxtmccsMap
|
||||
otaBaCxKsjxtmccs.setOtaId(otaId);
|
||||
otaBaCxKsjxtmccs.setCreateTime(now);
|
||||
otaBaCxKsjxtmccs.setUpdateTime(now);
|
||||
saveOrUpdate(otaBaCxKsjxtmccs);
|
||||
newList.add(otaBaCxKsjxtmccs);
|
||||
}
|
||||
ComparisonUtil cu = new ComparisonUtil();
|
||||
List<OtaBaCxTxjl> reList = cu.comparisonListRecord(otaId, OtaModuleEnum.CX_KSJDXTMCYCS, OtaTitleEnum.XTLB.getName(), oldList, newList, sysDictService);
|
||||
saveOrUpdateBatch(newList);
|
||||
otaBaCxTxjlService.saveBatch(reList);
|
||||
String fj = (String) json.get("fj");
|
||||
if (StringUtils.isNotEmpty(fj)) {
|
||||
@@ -181,4 +198,91 @@ public class OtaBaCxKsjxtmccsServiceImpl extends ServiceImpl<OtaBaCxKsjxtmccsMap
|
||||
}
|
||||
this.deleteByIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exportTemplate(HttpServletResponse response, HttpServletRequest request) {
|
||||
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);
|
||||
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<OtaBaCxKsjxtmccs> oldList = getByOtaId(otaId);
|
||||
List<OtaBaCxKsjxtmccs> mccsList = parseFile(upFile, otaId, cut);
|
||||
ComparisonUtil cu = new ComparisonUtil();
|
||||
List<OtaBaCxTxjl> reList = cu.comparisonListRecord(otaId, OtaModuleEnum.CX_KSJDXTMCYCS, OtaTitleEnum.XTLB.getName(), oldList, mccsList, sysDictService);
|
||||
deleteByOtaId(otaId);
|
||||
saveOrUpdateBatch(mccsList);
|
||||
otaBaCxTxjlService.saveBatch(reList);
|
||||
}
|
||||
|
||||
private List<OtaBaCxKsjxtmccs> parseFile(File upFile, String otaId, String cut) throws Exception {
|
||||
Date now = new Date();
|
||||
List<OtaBaCxKsjxtmccs> mccsList = new ArrayList<>();
|
||||
Workbook wb = ImportFileUtil.readExcel(upFile);
|
||||
Sheet s = wb.getSheetAt(0);
|
||||
int rows = s.getPhysicalNumberOfRows();
|
||||
for (int i = 3; i < rows; i++) {
|
||||
Row row = s.getRow(i);
|
||||
Cell cell = row.getCell(0);
|
||||
String str = ImportFileUtil.getCellValue(cell, wb);
|
||||
OtaBaCxKsjxtmccs mssc = new OtaBaCxKsjxtmccs();
|
||||
if ("证明材料".equals(str)) {
|
||||
//列表数据数量,在证明材料处结束
|
||||
OtaBaCxList otaBaCxList = otaBaCxListService.queryById(otaId);
|
||||
if (ObjectUtils.isNotEmpty(otaBaCxList)) {
|
||||
otaBaCxList.setZxsjxtfj(str);
|
||||
otaBaCxListService.editById(otaBaCxList);
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
mssc.setOtaId(otaId);
|
||||
mssc.setXtlb(ImportFileUtil.getCellValue(cell, wb));
|
||||
cell = row.getCell(1);
|
||||
mssc.setSfksj(ImportFileUtil.getCellValueYesOrNo(cell, wb));
|
||||
cell = row.getCell(2);
|
||||
mssc.setSjbgcs(ImportFileUtil.getCellValue(cell, wb));
|
||||
cell = row.getCell(3);
|
||||
mssc.setTpt(ImportFileUtil.getCellValue(cell, wb));
|
||||
cell = row.getCell(4);
|
||||
mssc.setKzqmc(ImportFileUtil.getCellValue(cell, wb));
|
||||
cell = row.getCell(5);
|
||||
mssc.setAqwzxdj(ImportFileUtil.getCellValue(cell, wb));
|
||||
cell = row.getCell(6);
|
||||
mssc.setKzqscqy(ImportFileUtil.getCellValue(cell, wb));
|
||||
cell = row.getCell(7);
|
||||
mssc.setKzqxh(ImportFileUtil.getCellValue(cell, wb));
|
||||
cell = row.getCell(8);
|
||||
mssc.setYjbbxx(ImportFileUtil.getCellValue(cell, wb));
|
||||
cell = row.getCell(9);
|
||||
mssc.setCsrjbbh(ImportFileUtil.getCellValue(cell, wb));
|
||||
cell = row.getCell(10);
|
||||
mssc.setCsrjbwzsj(ImportFileUtil.getCellValue(cell, wb));
|
||||
cell = row.getCell(11);
|
||||
mssc.setSjsfyx(ImportFileUtil.getCellValue(cell, wb));
|
||||
cell = row.getCell(12);
|
||||
mssc.setCzxtlx(ImportFileUtil.getCellValue(cell, wb));
|
||||
cell = row.getCell(13);
|
||||
mssc.setCzxtscqy(ImportFileUtil.getCellValue(cell, wb));
|
||||
cell = row.getCell(14);
|
||||
mssc.setCzxtbbh(ImportFileUtil.getCellValue(cell, wb));
|
||||
mssc.setCreateTime(now);
|
||||
mssc.setUpdateTime(now);
|
||||
mccsList.add(mssc);
|
||||
}
|
||||
}
|
||||
return mccsList;
|
||||
}
|
||||
}
|
||||
|
||||
+7
-3
@@ -54,7 +54,9 @@ public class ComparisonUtil<T> {
|
||||
idField.setAccessible(true);
|
||||
Object id = idField.get(newObj);
|
||||
if (ObjectUtils.isEmpty(id)) {
|
||||
String content = "新增了一条" + newObj.getClass().getDeclaredField(tableTitle).get(newObj).toString();
|
||||
Field tableField = newObj.getClass().getDeclaredField(tableTitle);
|
||||
tableField.setAccessible(true);
|
||||
String content = "新增了一条" + tableField.get(newObj).toString();
|
||||
resList.add(new OtaBaCxTxjl(otaId, otaModuleEnum.getName(), content));
|
||||
Field[] fields = newObj.getClass().getDeclaredFields();
|
||||
for (Field field : fields) {
|
||||
@@ -70,7 +72,7 @@ public class ComparisonUtil<T> {
|
||||
if (ObjectUtils.isNotEmpty(newVal)) {
|
||||
newStr = newVal.toString();
|
||||
}
|
||||
content = "增加" + newObj.getClass().getDeclaredField(tableTitle).get(newObj).toString() + "中" + title + "为" + newStr;
|
||||
content = "增加" + tableField.get(newObj).toString() + "中" + title + "为" + newStr;
|
||||
resList.add(new OtaBaCxTxjl(otaId, otaModuleEnum.getName(), content));
|
||||
}
|
||||
} else {
|
||||
@@ -134,7 +136,9 @@ public class ComparisonUtil<T> {
|
||||
Object newVal = field.get(newClazz);
|
||||
String newTitleStr = "空";
|
||||
if (ObjectUtils.isNotEmpty(newVal)) {
|
||||
Object newTitleVal = newVal.getClass().getDeclaredField(tableTitle).get(newVal);
|
||||
Field tableField = newVal.getClass().getDeclaredField(tableTitle);
|
||||
tableField.setAccessible(true);
|
||||
Object newTitleVal = tableField.get(newVal);
|
||||
if (ObjectUtils.isNotEmpty(newTitleVal)) {
|
||||
newTitleStr = newTitleVal.toString();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user