开发OTA备案工具-导入导出
This commit is contained in:
+26
@@ -8,6 +8,7 @@ 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.OtaBaCxAqcs;
|
||||
import com.jero.modules.ota.entity.OtaBaCxZxsjyq;
|
||||
import com.jero.modules.ota.service.IOtaBaCxAqcsService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
@@ -17,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;
|
||||
@@ -186,4 +188,28 @@ public class OtaBaCxAqcsController extends JeroController<OtaBaCxAqcs, IOtaBaCxA
|
||||
return super.importExcel(request, response, OtaBaCxAqcs.class);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "车型备案-安全措施-模板下载")
|
||||
@GetMapping(value = "/exportTemplate")
|
||||
// @RequiresPermissions("otaBaCx:exportTemplate")
|
||||
public void exportTemplate(HttpServletResponse response, HttpServletRequest request) throws Exception {
|
||||
this.otaBaCxAqcsService.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 {
|
||||
OtaBaCxAqcs res;
|
||||
try {
|
||||
res = this.otaBaCxAqcsService.importData(file, otaId, cut);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
return Result.OK(res);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+7
@@ -2,7 +2,10 @@ package com.jero.modules.ota.service;
|
||||
|
||||
import com.jero.modules.ota.entity.OtaBaCxAqcs;
|
||||
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 IOtaBaCxAqcsService extends IService<OtaBaCxAqcs> {
|
||||
List<OtaBaCxAqcs> queryList();
|
||||
|
||||
OtaBaCxAqcs queryByOtaId(String otaId, String otaIdT);
|
||||
|
||||
void exportTemplate(HttpServletResponse response, HttpServletRequest request);
|
||||
|
||||
OtaBaCxAqcs importData(MultipartFile file, String otaId, String cut) throws Exception;
|
||||
}
|
||||
|
||||
+72
-4
@@ -2,25 +2,34 @@ package com.jero.modules.ota.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.jero.modules.ota.entity.AttachmentEO;
|
||||
import com.jero.modules.ota.entity.OtaBaCxAqcs;
|
||||
import com.jero.modules.ota.entity.OtaBaCxJbxx;
|
||||
import com.jero.modules.ota.entity.OtaBaCxTxjl;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.modules.ota.entity.*;
|
||||
import com.jero.modules.ota.enums.OtaModuleEnum;
|
||||
import com.jero.modules.ota.mapper.OtaBaCxAqcsMapper;
|
||||
import com.jero.modules.ota.service.IOtaBaCxAqcsService;
|
||||
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 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 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 +39,11 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
*/
|
||||
@Service
|
||||
public class OtaBaCxAqcsServiceImpl extends ServiceImpl<OtaBaCxAqcsMapper, OtaBaCxAqcs> implements IOtaBaCxAqcsService {
|
||||
@Value(value = "${ota.templatePath}")
|
||||
private String templatePath;
|
||||
|
||||
@Value(value = "${ota.uploadPath}")
|
||||
private String uploadPath;
|
||||
|
||||
@Autowired
|
||||
private IOtaBaCxTxjlService otaBaCxTxjlService;
|
||||
@@ -146,4 +160,58 @@ public class OtaBaCxAqcsServiceImpl extends ServiceImpl<OtaBaCxAqcsMapper, OtaBa
|
||||
queryWrapper.eq(OtaBaCxAqcs::getOtaId, otaId);
|
||||
return this.getOne(queryWrapper, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exportTemplate(HttpServletResponse response, HttpServletRequest request) {
|
||||
ImportFileUtil.exportTemplate(response, templatePath + "安全措施.zip");
|
||||
}
|
||||
|
||||
@Override
|
||||
public OtaBaCxAqcs 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("请上传正确的文件");
|
||||
}
|
||||
OtaBaCxAqcs aqcs = parseFile(upFile, cut);
|
||||
aqcs.setOtaId(otaId);
|
||||
add(aqcs);
|
||||
return aqcs;
|
||||
}
|
||||
|
||||
private OtaBaCxAqcs parseFile(File upFile, String cut) throws Exception {
|
||||
OtaBaCxAqcs aqcs = new OtaBaCxAqcs();
|
||||
Workbook wb = ImportFileUtil.readExcel(upFile);
|
||||
Sheet s = wb.getSheetAt(0);
|
||||
|
||||
Row row = s.getRow(2);
|
||||
Cell cell = row.getCell(2);
|
||||
aqcs.setBhjz(ImportFileUtil.getCellValueDict(cell, wb, "protection_mechanism", sysDictService, cut));
|
||||
|
||||
row = s.getRow(3);
|
||||
cell = row.getCell(2);
|
||||
aqcs.setFsxjz(ImportFileUtil.getCellValueDict(cell, wb, "fail_safe_mechanism", sysDictService, cut));
|
||||
|
||||
row = s.getRow(4);
|
||||
cell = row.getCell(2);
|
||||
aqcs.setSjsbcs(ImportFileUtil.getCellValueDict(cell, wb, "upgrade_failure", sysDictService, cut));
|
||||
|
||||
row = s.getRow(5);
|
||||
cell = row.getCell(2);
|
||||
aqcs.setXxaqjz(ImportFileUtil.getCellValueDict(cell, wb, "Information_security_mechanism", sysDictService, cut));
|
||||
|
||||
row = s.getRow(2);
|
||||
cell = row.getCell(3);
|
||||
aqcs.setZmcl(ImportFileUtil.getCellValue(cell, wb));
|
||||
|
||||
return aqcs;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-16
@@ -213,22 +213,10 @@ public class OtaBaCxJbxxServiceImpl extends ServiceImpl<OtaBaCxJbxxMapper, OtaBa
|
||||
jbxx.setDllx2(ImportFileUtil.getCellValue(cell, wb));
|
||||
row = s.getRow(10);
|
||||
cell = row.getCell(1);
|
||||
String txzdStr = ImportFileUtil.getCellValue(cell, wb);
|
||||
if (StringUtils.isNotEmpty(txzdStr)) {
|
||||
String[] txzdStrs = txzdStr.split(",");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < txzdStrs.length; i++) {
|
||||
if (i >= txzdStrs.length - 1) {
|
||||
sb.append(sysDictService.queryDictItemByValue("communication_terminal", txzdStrs[i], cut));
|
||||
} else {
|
||||
sb.append(sysDictService.queryDictItemByValue("communication_terminal", txzdStrs[i], cut)).append(",");
|
||||
}
|
||||
}
|
||||
jbxx.setTxzd(sb.toString());
|
||||
row = s.getRow(11);
|
||||
cell = row.getCell(1);
|
||||
jbxx.setCdotasj(ImportFileUtil.getCellValue(cell, wb));
|
||||
}
|
||||
jbxx.setTxzd(ImportFileUtil.getCellValueDict(cell, wb, "communication_terminal", sysDictService, cut));
|
||||
row = s.getRow(11);
|
||||
cell = row.getCell(1);
|
||||
jbxx.setCdotasj(ImportFileUtil.getCellValue(cell, wb));
|
||||
return jbxx;
|
||||
}
|
||||
|
||||
|
||||
+20
@@ -4,6 +4,7 @@ import com.aliyuncs.utils.IOUtils;
|
||||
import com.jero.common.constant.enums.CutEnum;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.modules.split.common.FileUnZip;
|
||||
import com.jero.modules.system.service.ISysDictService;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -190,4 +191,23 @@ public class ImportFileUtil {
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static String getCellValueDict(Cell cell, Workbook wb, String dictType, ISysDictService sysDictService, String cut) throws Exception {
|
||||
String res = "";
|
||||
String str = ImportFileUtil.getCellValue(cell, wb);
|
||||
if (StringUtils.isNotEmpty(str)) {
|
||||
String[] strs = str.split(",");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < strs.length; i++) {
|
||||
if (i >= strs.length - 1) {
|
||||
sb.append(sysDictService.queryDictItemByValue(dictType, strs[i], cut));
|
||||
} else {
|
||||
sb.append(sysDictService.queryDictItemByValue(dictType, strs[i], cut)).append(",");
|
||||
}
|
||||
}
|
||||
res = sb.toString();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user