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

This commit is contained in:
高嵩
2023-03-29 21:56:12 +08:00
parent 3f54f10258
commit 3559c7739d
2 changed files with 121 additions and 9 deletions
@@ -0,0 +1,58 @@
package com.jero.modules.ota.entity;
import com.jero.modules.extRepo.entity.ERFTreeData;
import com.jero.modules.ota.service.impl.OtaBaSjSjmbclServiceImpl;
import org.jetbrains.annotations.NotNull;
import java.util.Date;
public class VinObj {
String vin;
String cx;
String gglx;
Date scrq;
String scrqStr;
public String getVin() {
return vin;
}
public void setVin(String vin) {
this.vin = vin;
}
public String getCx() {
return cx;
}
public void setCx(String cx) {
this.cx = cx;
}
public String getGglx() {
return gglx;
}
public void setGglx(String gglx) {
this.gglx = gglx;
}
public Date getScrq() {
return scrq;
}
public void setScrq(Date scrq) {
this.scrq = scrq;
}
public String getScrqStr() {
return scrqStr;
}
public void setScrqStr(String scrqStr) {
this.scrqStr = scrqStr;
}
}
@@ -2,15 +2,13 @@ package com.jero.modules.ota.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jero.common.exception.JeroBootException;
import com.jero.modules.extRepo.entity.ERFTreeData;
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.OtaBaSjSjmbclMapper;
import com.jero.modules.ota.service.IOtaBaCxTxjlService;
import com.jero.modules.ota.service.IOtaBaSjListService;
import com.jero.modules.ota.service.IOtaBaSjLsjlService;
import com.jero.modules.ota.service.IOtaBaSjSjmbclService;
import com.jero.modules.ota.service.*;
import com.jero.modules.ota.utils.ComparisonUtil;
import com.jero.modules.ota.utils.ImportFileUtil;
import com.jero.modules.system.service.ISysDictService;
@@ -20,14 +18,14 @@ 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.jetbrains.annotations.NotNull;
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 java.util.UUID;
import java.text.SimpleDateFormat;
import java.util.*;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.web.multipart.MultipartFile;
@@ -44,6 +42,8 @@ import javax.servlet.http.HttpServletResponse;
@Service
public class OtaBaSjSjmbclServiceImpl extends ServiceImpl<OtaBaSjSjmbclMapper, OtaBaSjSjmbcl> implements IOtaBaSjSjmbclService {
private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
@Value(value = "${ota.templatePath}")
private String templatePath;
@@ -59,6 +59,10 @@ public class OtaBaSjSjmbclServiceImpl extends ServiceImpl<OtaBaSjSjmbclMapper, O
@Autowired
private IOSSFileService ossFileService;
@Autowired
private IOtaBaSjSjmbcxService otaBaSjSjmbcxService;
/**
* 保存
*
@@ -183,14 +187,63 @@ public class OtaBaSjSjmbclServiceImpl extends ServiceImpl<OtaBaSjSjmbclMapper, O
if (null == upFile) {
throw new JeroBootException("请上传正确的文件");
}
OtaBaSjSjmbcl mbcl = parseFile(upFile, cut);
OtaBaSjSjmbcl mbcl = parseFile(upFile, otaId, cut);
mbcl.setOtaId(otaId);
add(mbcl);
return mbcl;
}
private OtaBaSjSjmbcl parseFile(File upFile, String cut) {
private OtaBaSjSjmbcl parseFile(File upFile, String otaId, String cut) throws Exception {
OtaBaSjSjmbcl mbcl = new OtaBaSjSjmbcl();
OtaBaSjSjmbcx mbcx = otaBaSjSjmbcxService.queryByOtaId(otaId, "");
if (ObjectUtils.isNotEmpty(mbcx) && StringUtils.isNotEmpty(mbcx.getCpxh())) {
String cx = mbcx.getCpxh();
Workbook wb = ImportFileUtil.readExcel(upFile);
Sheet s = wb.getSheetAt(0);
int rows = s.getPhysicalNumberOfRows();
List<VinObj> vinList = new ArrayList<>();
for (int i = 1; i < rows; i++) {
VinObj vinObj = new VinObj();
Row row = s.getRow(i);
Cell cell = row.getCell(0);
vinObj.setVin(ImportFileUtil.getCellValue(cell, wb));
cell = row.getCell(1);
vinObj.setCx(ImportFileUtil.getCellValue(cell, wb));
if (!cx.equals(vinObj.getCx())) {
continue;
}
cell = row.getCell(2);
vinObj.setGglx(ImportFileUtil.getCellValue(cell, wb));
cell = row.getCell(3);
vinObj.setScrq(cell.getDateCellValue());
vinObj.setScrqStr(sdf.format(vinObj.getScrq()));
vinList.add(vinObj);
}
mbcl.setOtaId(otaId);
if (ObjectUtils.isNotEmpty(vinList)) {
// 匿名比较器排序
Collections.sort(vinList, new Comparator<VinObj>() {
@Override
public int compare(VinObj p1, VinObj p2) {
return p1.getScrq().compareTo(p2.getScrq());
}
});
mbcl.setZsl(String.valueOf(vinList.size()));
mbcl.setScrqks(vinList.get(0).getScrq());
mbcl.setScrqjs(vinList.get(vinList.size() - 1).getScrq());
// 匿名比较器排序
Collections.sort(vinList, new Comparator<VinObj>() {
@Override
public int compare(VinObj p1, VinObj p2) {
return p1.getVin().compareTo(p2.getVin());
}
});
mbcl.setVinList(vinList.get(0).getVin() + "-" + vinList.get(vinList.size() - 1).getVin());
}
}
return mbcl;
}
@@ -205,4 +258,5 @@ public class OtaBaSjSjmbclServiceImpl extends ServiceImpl<OtaBaSjSjmbclMapper, O
public void exportData(File file, String otaId, String cut) throws Exception {
}
}