开发OTA备案工具-导入导出
This commit is contained in:
+37
-13
@@ -1,26 +1,27 @@
|
||||
package com.jero.modules.ota.controller;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.common.system.query.QueryGenerator;
|
||||
import com.jero.modules.ota.entity.OtaBaCxZxsjyq;
|
||||
import com.jero.modules.ota.service.IOtaBaCxZxsjyqService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.common.aspect.annotation.AutoLog;
|
||||
import com.jero.common.system.base.controller.JeroController;
|
||||
import com.jero.common.system.query.QueryGenerator;
|
||||
import com.jero.modules.ota.entity.OtaBaCxZxsjyq;
|
||||
import com.jero.modules.ota.service.IOtaBaCxZxsjyqService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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;
|
||||
import com.jero.common.aspect.annotation.AutoLog;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
@@ -183,4 +184,27 @@ public class OtaBaCxZxsjyqController extends JeroController<OtaBaCxZxsjyq, IOtaB
|
||||
return super.importExcel(request, response, OtaBaCxZxsjyq.class);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "车型备案-在线升级要求-模板下载")
|
||||
@GetMapping(value = "/exportTemplate")
|
||||
// @RequiresPermissions("otaBaCx:exportTemplate")
|
||||
public void exportTemplate(HttpServletResponse response, HttpServletRequest request) throws Exception {
|
||||
this.otaBaCxZxsjyqService.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 {
|
||||
OtaBaCxZxsjyq res;
|
||||
try {
|
||||
res = this.otaBaCxZxsjyqService.importData(file, otaId, cut);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
return Result.OK(res);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+8
@@ -1,8 +1,12 @@
|
||||
package com.jero.modules.ota.service;
|
||||
|
||||
import com.jero.modules.ota.entity.OtaBaCxJbxx;
|
||||
import com.jero.modules.ota.entity.OtaBaCxZxsjyq;
|
||||
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 +65,8 @@ public interface IOtaBaCxZxsjyqService extends IService<OtaBaCxZxsjyq> {
|
||||
List<OtaBaCxZxsjyq> queryList();
|
||||
|
||||
OtaBaCxZxsjyq queryByOtaId(String otaId, String otaIdT);
|
||||
|
||||
void exportTemplate(HttpServletResponse response, HttpServletRequest request);
|
||||
|
||||
OtaBaCxZxsjyq importData(MultipartFile file, String otaId, String cut) throws Exception;
|
||||
}
|
||||
|
||||
+11
-19
@@ -174,14 +174,6 @@ public class OtaBaCxJbxxServiceImpl extends ServiceImpl<OtaBaCxJbxxMapper, OtaBa
|
||||
return add(jbxx);
|
||||
}
|
||||
|
||||
public static String getCellValue(Cell cell, Workbook workbook) throws Exception {
|
||||
FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
|
||||
DataFormatter formatter = new DataFormatter();
|
||||
//单元格不设置数字格式
|
||||
cell.setCellStyle(null);
|
||||
return formatter.formatCellValue(cell, evaluator);
|
||||
}
|
||||
|
||||
private OtaBaCxJbxx parseFile(File file, String cut) throws Exception {
|
||||
OtaBaCxJbxx jbxx = new OtaBaCxJbxx();
|
||||
Workbook wb = ImportFileUtil.readExcel(file);
|
||||
@@ -189,39 +181,39 @@ public class OtaBaCxJbxxServiceImpl extends ServiceImpl<OtaBaCxJbxxMapper, OtaBa
|
||||
|
||||
Row row = s.getRow(1);
|
||||
Cell cell = row.getCell(1);
|
||||
jbxx.setQymc(getCellValue(cell, wb));
|
||||
jbxx.setQymc(ImportFileUtil.getCellValue(cell, wb));
|
||||
|
||||
row = s.getRow(2);
|
||||
cell = row.getCell(1);
|
||||
String cpbh = getCellValue(cell, wb);
|
||||
String cpbh = ImportFileUtil.getCellValue(cell, wb);
|
||||
if (StringUtils.isEmpty(cpbh)) {
|
||||
throw new JeroBootException("产品编号不能为空");
|
||||
}
|
||||
jbxx.setDjbh(cpbh);
|
||||
row = s.getRow(3);
|
||||
cell = row.getCell(1);
|
||||
jbxx.setCplb(getCellValue(cell, wb));
|
||||
jbxx.setCplb(ImportFileUtil.getCellValue(cell, wb));
|
||||
row = s.getRow(4);
|
||||
cell = row.getCell(1);
|
||||
jbxx.setGgpc(getCellValue(cell, wb));
|
||||
jbxx.setGgpc(ImportFileUtil.getCellValue(cell, wb));
|
||||
row = s.getRow(5);
|
||||
cell = row.getCell(1);
|
||||
jbxx.setCpsb(getCellValue(cell, wb));
|
||||
jbxx.setCpsb(ImportFileUtil.getCellValue(cell, wb));
|
||||
row = s.getRow(6);
|
||||
cell = row.getCell(1);
|
||||
jbxx.setCpmc(getCellValue(cell, wb));
|
||||
jbxx.setCpmc(ImportFileUtil.getCellValue(cell, wb));
|
||||
row = s.getRow(7);
|
||||
cell = row.getCell(1);
|
||||
jbxx.setCpxh(getCellValue(cell, wb));
|
||||
jbxx.setCpxh(ImportFileUtil.getCellValue(cell, wb));
|
||||
row = s.getRow(8);
|
||||
cell = row.getCell(1);
|
||||
jbxx.setDllx1(getCellValue(cell, wb));
|
||||
jbxx.setDllx1(ImportFileUtil.getCellValue(cell, wb));
|
||||
row = s.getRow(9);
|
||||
cell = row.getCell(1);
|
||||
jbxx.setDllx2(getCellValue(cell, wb));
|
||||
jbxx.setDllx2(ImportFileUtil.getCellValue(cell, wb));
|
||||
row = s.getRow(10);
|
||||
cell = row.getCell(1);
|
||||
String txzdStr = getCellValue(cell, wb);
|
||||
String txzdStr = ImportFileUtil.getCellValue(cell, wb);
|
||||
if (StringUtils.isNotEmpty(txzdStr)) {
|
||||
String[] txzdStrs = txzdStr.split(",");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
@@ -235,7 +227,7 @@ public class OtaBaCxJbxxServiceImpl extends ServiceImpl<OtaBaCxJbxxMapper, OtaBa
|
||||
jbxx.setTxzd(sb.toString());
|
||||
row = s.getRow(11);
|
||||
cell = row.getCell(1);
|
||||
jbxx.setCdotasj(getCellValue(cell, wb));
|
||||
jbxx.setCdotasj(ImportFileUtil.getCellValue(cell, wb));
|
||||
}
|
||||
return jbxx;
|
||||
}
|
||||
|
||||
+84
-5
@@ -1,10 +1,10 @@
|
||||
package com.jero.modules.ota.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
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.ota.entity.AttachmentEO;
|
||||
import com.jero.modules.ota.entity.OtaBaCxJbxx;
|
||||
import com.jero.modules.ota.entity.OtaBaCxTxjl;
|
||||
import com.jero.modules.ota.entity.OtaBaCxZxsjyq;
|
||||
import com.jero.modules.ota.enums.OtaModuleEnum;
|
||||
@@ -12,16 +12,24 @@ import com.jero.modules.ota.mapper.OtaBaCxZxsjyqMapper;
|
||||
import com.jero.modules.ota.service.IOtaBaCxTxjlService;
|
||||
import com.jero.modules.ota.service.IOtaBaCxZxsjyqService;
|
||||
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.apache.commons.lang3.StringUtils;
|
||||
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 org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.util.Date;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description: 车型备案-在线升级要求
|
||||
@@ -32,6 +40,11 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
@Service
|
||||
public class OtaBaCxZxsjyqServiceImpl extends ServiceImpl<OtaBaCxZxsjyqMapper, OtaBaCxZxsjyq> implements IOtaBaCxZxsjyqService {
|
||||
|
||||
@Value(value = "${ota.templatePath}")
|
||||
private String templatePath;
|
||||
|
||||
@Value(value = "${ota.uploadPath}")
|
||||
private String uploadPath;
|
||||
|
||||
@Autowired
|
||||
private IOtaBaCxTxjlService otaBaCxTxjlService;
|
||||
@@ -150,4 +163,70 @@ public class OtaBaCxZxsjyqServiceImpl extends ServiceImpl<OtaBaCxZxsjyqMapper, O
|
||||
queryWrapper.eq(OtaBaCxZxsjyq::getOtaId, otaId);
|
||||
return this.getOne(queryWrapper, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exportTemplate(HttpServletResponse response, HttpServletRequest request) {
|
||||
ImportFileUtil.exportTemplate(response, templatePath + "在线升级要求.zip");
|
||||
}
|
||||
|
||||
@Override
|
||||
public OtaBaCxZxsjyq 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("请上传正确的文件");
|
||||
}
|
||||
OtaBaCxZxsjyq otaBaCxZxsjyq = parseFile(upFile, cut);
|
||||
otaBaCxZxsjyq.setOtaId(otaId);
|
||||
add(otaBaCxZxsjyq);
|
||||
return otaBaCxZxsjyq;
|
||||
}
|
||||
|
||||
private OtaBaCxZxsjyq parseFile(File upFile, String cut) throws Exception {
|
||||
OtaBaCxZxsjyq otaBaCxZxsjyq = new OtaBaCxZxsjyq();
|
||||
Workbook wb = ImportFileUtil.readExcel(upFile);
|
||||
Sheet s = wb.getSheetAt(0);
|
||||
Row row = s.getRow(2);
|
||||
Cell cell = row.getCell(2);
|
||||
otaBaCxZxsjyq.setBhsjb(ImportFileUtil.getCellValueYesOrNo(cell, wb));
|
||||
row = s.getRow(3);
|
||||
cell = row.getCell(2);
|
||||
otaBaCxZxsjyq.setBhclbb(ImportFileUtil.getCellValueYesOrNo(cell, wb));
|
||||
row = s.getRow(4);
|
||||
cell = row.getCell(2);
|
||||
otaBaCxZxsjyq.setClgxnl(ImportFileUtil.getCellValueYesOrNo(cell, wb));
|
||||
row = s.getRow(5);
|
||||
cell = row.getCell(2);
|
||||
otaBaCxZxsjyq.setClsjtj(ImportFileUtil.getCellValueYesOrNo(cell, wb));
|
||||
row = s.getRow(6);
|
||||
cell = row.getCell(2);
|
||||
otaBaCxZxsjyq.setClsjdl(ImportFileUtil.getCellValueYesOrNo(cell, wb));
|
||||
row = s.getRow(7);
|
||||
cell = row.getCell(2);
|
||||
otaBaCxZxsjyq.setSjbhaq(ImportFileUtil.getCellValueYesOrNo(cell, wb));
|
||||
row = s.getRow(8);
|
||||
cell = row.getCell(2);
|
||||
otaBaCxZxsjyq.setSjantj(ImportFileUtil.getCellValueYesOrNo(cell, wb));
|
||||
row = s.getRow(9);
|
||||
cell = row.getCell(2);
|
||||
otaBaCxZxsjyq.setSjsbaq(ImportFileUtil.getCellValueYesOrNo(cell, wb));
|
||||
row = s.getRow(10);
|
||||
cell = row.getCell(2);
|
||||
otaBaCxZxsjyq.setSjgg(ImportFileUtil.getCellValueYesOrNo(cell, wb));
|
||||
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));
|
||||
return otaBaCxZxsjyq;
|
||||
}
|
||||
}
|
||||
|
||||
+27
-3
@@ -5,10 +5,10 @@ import com.jero.common.constant.enums.CutEnum;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.modules.split.common.FileUnZip;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellType;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@@ -166,4 +166,28 @@ public class ImportFileUtil {
|
||||
}
|
||||
return wb;
|
||||
}
|
||||
|
||||
public static String getCellValue(Cell cell, Workbook workbook) throws Exception {
|
||||
FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
|
||||
DataFormatter formatter = new DataFormatter();
|
||||
//单元格不设置数字格式
|
||||
if (ObjectUtils.isNotEmpty(cell)) {
|
||||
cell.setCellStyle(null);
|
||||
return formatter.formatCellValue(cell, evaluator);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String getCellValueYesOrNo(Cell cell, Workbook workbook) throws Exception {
|
||||
String res = "";
|
||||
String str = getCellValue(cell, workbook);
|
||||
if (StringUtils.isNotEmpty(str)) {
|
||||
if (str.equals("是")) {
|
||||
res = "1";
|
||||
} else if (str.equals("否")) {
|
||||
res = "2";
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user