提交 356894cd authored 作者: xc's avatar xc

[excel导入]修改路径

上级 e4e016f5
...@@ -5,6 +5,7 @@ import org.springframework.context.annotation.Configuration; ...@@ -5,6 +5,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.builders.RequestHandlerSelectors;
...@@ -27,7 +28,7 @@ import java.io.File; ...@@ -27,7 +28,7 @@ import java.io.File;
@Configuration @Configuration
@EnableSwagger2 @EnableSwagger2
public class WebMvcConfig { public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Bean @Bean
public WebMvcConfigurer corsConfigurer() { public WebMvcConfigurer corsConfigurer() {
...@@ -61,4 +62,10 @@ public class WebMvcConfig { ...@@ -61,4 +62,10 @@ public class WebMvcConfig {
.build(); .build();
} }
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
// 这里之所以多了一"/",是为了解决打war时访问不到问题
registry.addResourceHandler("/webs/**").addResourceLocations("classpath:/webs/");
}
} }
...@@ -16,4 +16,5 @@ import javax.persistence.Table; ...@@ -16,4 +16,5 @@ import javax.persistence.Table;
public class ExcelConfig extends BaseEntity { public class ExcelConfig extends BaseEntity {
private String path; private String path;
private String rootPath; private String rootPath;
private Integer fillIn;//0填写,1不天
} }
package com.tykj.model_layer.excel;
import lombok.Data;
import java.util.List;
@Data
public class CompareData {
private String ruleName;//字段别名
private List<String> dataList;//真实数据
private List<String> sheetNameList;//sheetname
}
...@@ -17,6 +17,7 @@ import com.tykj.model_layer.service.ModelService; ...@@ -17,6 +17,7 @@ import com.tykj.model_layer.service.ModelService;
import com.tykj.model_layer.service.RuleService; import com.tykj.model_layer.service.RuleService;
import com.tykj.model_layer.service.impl.ModelHelper; import com.tykj.model_layer.service.impl.ModelHelper;
import io.swagger.models.auth.In; import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Row;
...@@ -39,6 +40,7 @@ import java.util.regex.Pattern; ...@@ -39,6 +40,7 @@ import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Component @Component
@Slf4j
public class ExcelData { public class ExcelData {
@Autowired @Autowired
private ModelService modelService; private ModelService modelService;
...@@ -61,16 +63,16 @@ public class ExcelData { ...@@ -61,16 +63,16 @@ public class ExcelData {
} }
public ResponseEntity getExcelData(int id){ public ResponseEntity getExcelData(int id){
String successPath = rootPath + "/research/successFile/"; String successPath = rootPath + "/successFile/";
String errorPath = rootPath + "/research/errorFile/"; String errorPath = rootPath + "/errorFile/";
File success = new File(successPath); // File success = new File(successPath);
File error = new File(errorPath); // File error = new File(errorPath);
if (!success.exists()){ // if (!success.exists()){
success.mkdirs(); // success.mkdirs();
} // }
if (!error.exists()){ // if (!error.exists()){
error.mkdirs(); // error.mkdirs();
} // }
this.percent =0;//百分比数字 this.percent =0;//百分比数字
String jsonData = modelHelper.getJsonExpample(id); String jsonData = modelHelper.getJsonExpample(id);
...@@ -81,12 +83,11 @@ public class ExcelData { ...@@ -81,12 +83,11 @@ public class ExcelData {
List<File> dataFiles = new ArrayList<>(); List<File> dataFiles = new ArrayList<>();
List<File> erroeFiles = new ArrayList<>(); List<File> erroeFiles = new ArrayList<>();
//先预览数据
compareRule(1, dataFiles, erroeFiles); compareRule(1, dataFiles, erroeFiles);
System.out.println(path);
File[] successFile = new File(path).listFiles(); File[] successFile = new File(path).listFiles();
int totalNum = successFile == null ? 0 : successFile.length; int totalNum = successFile == null ? 0 : successFile.length;
// File[] dataFiles = file.listFiles(); if (dataFiles.size() == 0){
if (dataFiles == null || dataFiles.size() == 0){
excelLogService.save(new ExcelLog("导入失败", "文件路径下没有文件", "")); excelLogService.save(new ExcelLog("导入失败", "文件路径下没有文件", ""));
return ResultUtil.failed("没有待导入文件!"); return ResultUtil.failed("没有待导入文件!");
} }
...@@ -101,6 +102,7 @@ public class ExcelData { ...@@ -101,6 +102,7 @@ public class ExcelData {
int total = 0;//操作完成的总数量 int total = 0;//操作完成的总数量
int successNum = 0; int successNum = 0;
int errorNum = 0; int errorNum = 0;
//把预览失败的文件移动到errorFile
for (File file1 : erroeFiles){ for (File file1 : erroeFiles){
file1.renameTo(new File(errorPath + file1.getName())); file1.renameTo(new File(errorPath + file1.getName()));
} }
...@@ -189,7 +191,6 @@ public class ExcelData { ...@@ -189,7 +191,6 @@ public class ExcelData {
if (!propertyNameAndData.isEmpty()){ if (!propertyNameAndData.isEmpty()){
Map<String, Object> classNameAndDataMap = new HashMap<>(); Map<String, Object> classNameAndDataMap = new HashMap<>();
classNameAndDataMap.put(className, propertyNameAndData); classNameAndDataMap.put(className, propertyNameAndData);
System.out.println(classNameAndDataMap);
saveMapList.add(classNameAndDataMap); saveMapList.add(classNameAndDataMap);
} }
} }
...@@ -214,10 +215,6 @@ public class ExcelData { ...@@ -214,10 +215,6 @@ public class ExcelData {
} }
} }
System.out.println(successPath);
System.out.println(errorPath);
errorNum = errorNum + erroeFiles.size(); errorNum = errorNum + erroeFiles.size();
ExcelVo excelVo = new ExcelVo(totalNum, successNum, errorNum, 0, new Date(),null); ExcelVo excelVo = new ExcelVo(totalNum, successNum, errorNum, 0, new Date(),null);
if (!"".equals(errorFileNameList)){ if (!"".equals(errorFileNameList)){
...@@ -241,6 +238,9 @@ public class ExcelData { ...@@ -241,6 +238,9 @@ public class ExcelData {
/** /**
* 预览 * 预览
* @param num 当前文件不符合规则数量,超过这个数量就不再对比
* @param resultFiles 符合规则的文件列表
* @param errorFiles 不符合规则的文件列表
* @return * @return
*/ */
public ResponseEntity compareRule(int num, List<File> resultFiles, List<File> errorFiles){ public ResponseEntity compareRule(int num, List<File> resultFiles, List<File> errorFiles){
...@@ -258,7 +258,7 @@ public class ExcelData { ...@@ -258,7 +258,7 @@ public class ExcelData {
File rootFile = new File(rootPath); File rootFile = new File(rootPath);
rootFile.mkdirs(); rootFile.mkdirs();
} }
tmpPath = rootPath + "/research/tmp/"; tmpPath = rootPath + "/tmp/";
File tmp = new File(tmpPath); File tmp = new File(tmpPath);
if (!tmp.exists()){ if (!tmp.exists()){
tmp.mkdirs(); tmp.mkdirs();
...@@ -267,7 +267,6 @@ public class ExcelData { ...@@ -267,7 +267,6 @@ public class ExcelData {
List<ExcelErrorVo> excelVos = new ArrayList<>(); List<ExcelErrorVo> excelVos = new ArrayList<>();
List<Rule> rules = ruleService.findAll(); List<Rule> rules = ruleService.findAll();
int total = 0;//总文件数量 int total = 0;//总文件数量
boolean isSuccess = true;
try { try {
Template template = new Template(); Template template = new Template();
String tem = template.getTemplate("template.txt"); String tem = template.getTemplate("template.txt");
...@@ -275,7 +274,6 @@ public class ExcelData { ...@@ -275,7 +274,6 @@ public class ExcelData {
if (indexMap.isEmpty()){ if (indexMap.isEmpty()){
return ResultUtil.failed("没有excle模板,请导入模板文件!"); return ResultUtil.failed("没有excle模板,请导入模板文件!");
} }
File file = new File(path); File file = new File(path);
File[] dataFiles = file.listFiles(); File[] dataFiles = file.listFiles();
if (dataFiles == null || dataFiles.length == 0){ if (dataFiles == null || dataFiles.length == 0){
...@@ -284,45 +282,43 @@ public class ExcelData { ...@@ -284,45 +282,43 @@ public class ExcelData {
} }
total = dataFiles.length; total = dataFiles.length;
//用于判断excel内容是否符合选项 //用于判断excel内容是否符合选项,取所有字段的引用map<字段名,引用列表>
String className = null; String className = null;
for (String key : indexMap.keySet()){ for (String key : indexMap.keySet()){
className = key.split("[.]")[0]; className = key.split("[.]")[0];
break; break;
} }
//取所有字段的引用map<字段名,引用列表>
Map<String, List<Quote>> he = modelHelper.getQuoteList(className); Map<String, List<Quote>> he = modelHelper.getQuoteList(className);
for (File dataFile : dataFiles){ for (File dataFile : dataFiles){
String fileName = dataFile.getName(); String fileName = dataFile.getName();
isSuccess = true;//判断该文件是否全部符合规则 boolean isSuccess = true;//判断该文件是否全部符合规则
String tel = null;//联系方式 String tel = null;//联系方式
String unitName = null;//联系方式 String unitName = null;//联系方式
String buildTel = null;//承建单位 String buildTel = null;//承建单位
List<String> result = new ArrayList<>(); List<String> result = new ArrayList<>();
try { try {
FileInputStream dataFis = new FileInputStream(dataFile); FileInputStream dataFis = new FileInputStream(dataFile);
Workbook wb = null; Workbook wb = null;
if(fileName.endsWith("xls")) { if(fileName.endsWith("xls")) {
wb = new HSSFWorkbook(dataFis); wb = new HSSFWorkbook(dataFis);
} else if(fileName.endsWith("xlsx")) { } else if(fileName.endsWith("xlsx")) {
wb = new XSSFWorkbook(dataFis); wb = new XSSFWorkbook(dataFis);
} }
//{别名=数据} //{别名=数据}
Map<String, List<String>> ruleNameAndDataList = new HashMap<>(); // Map<String, List<String>> ruleNameAndDataList = new HashMap<>();
Map<String, List<String>> ruleNameAndSheetNameList = new HashMap<>(); // Map<String, List<String>> ruleNameAndSheetNameList = new HashMap<>();
List<CompareData> compareDatas = new ArrayList<>();
Map<String, String> sheetNameAndContent = new HashMap<>(); Map<String, String> sheetNameAndContent = new HashMap<>();
Map<String, String> networkNameAndSheetName = new HashMap<>(); Map<String, String> networkNameAndSheetName = new HashMap<>();
//循环每个sheet
for (int i = 0; i < wb.getNumberOfSheets(); i++){ for (int i = 0; i < wb.getNumberOfSheets(); i++){
Sheet sheet1 = wb.getSheetAt(i); Sheet sheet1 = wb.getSheetAt(i);
if ("引用表(请勿改动)".equals(sheet1.getSheetName()) || sheet1 ==null){ if (sheet1 ==null || "引用表(请勿改动)".equals(sheet1.getSheetName())){
continue; continue;
} }
String sameNetSheetName = null;//网络名称sheet List<String> sameNetSheetName = new ArrayList<>();//网络名称sheet
String sameNetName = "";//网络名称别名 //循环取excel数据
Row row = null;
for (String key : indexMap.keySet()){ for (String key : indexMap.keySet()){
if (result.size() > num){ if (result.size() > num){
break; break;
...@@ -331,7 +327,7 @@ public class ExcelData { ...@@ -331,7 +327,7 @@ public class ExcelData {
int[] value = indexMap.get(key); int[] value = indexMap.get(key);
int dataRow = value[0]; int dataRow = value[0];
int dataCell = value[1]; int dataCell = value[1];
row = sheet1.getRow(dataRow); Row row = sheet1.getRow(dataRow);
row.getCell(dataCell).setCellType(CellType.STRING); row.getCell(dataCell).setCellType(CellType.STRING);
String data = row.getCell(dataCell).getStringCellValue(); String data = row.getCell(dataCell).getStringCellValue();
...@@ -354,86 +350,51 @@ public class ExcelData { ...@@ -354,86 +350,51 @@ public class ExcelData {
} }
//判断引用是否符合规则 //判断引用是否符合规则
String propertyName = key.split("[.]")[1]; String propertyName = key.split("[.]")[1];
List<Quote> quotes = he.get(propertyName); if (!compareQuote(he, propertyName, data)){
if (quotes != null && quotes.size() > 0){ int k = result.size() + 1;
boolean isQuote = true; result.add(k + ".\"" + sheet1.getSheetName() + "\"第" + (dataRow + 1) + "行第" + (dataCell + 1) + "列不符合规则");
for (Quote quote : quotes){ isSuccess = false;
if(Objects.equals(data, quote.getValue())){ log.info(sheet1.getSheetName() + data +"不符合引用");
isQuote = false;
break;
}
}
if (isQuote){
int k = result.size() + 1;
result.add(k + ".\"" + sheet1.getSheetName() + "\"第" + (dataRow + 1) + "行第" + (dataCell + 1) + "列不符合规则");
isSuccess = false;
}
}
//正则规则判断
List<Rule> ruleList = rules.stream().filter(rule1 -> rule1.getRuleKey().equals(key)).collect(Collectors.toList());
if (!ruleList.isEmpty()) {
Rule rule = ruleList.get(0);
//判断同一个文件里所有sheet中该字段是否相同,数据准备
if (rule.getCompare() == 1) {
if (ruleNameAndDataList.get(rule.getName())== null || ruleNameAndDataList.get(rule.getName()).isEmpty()) {
List<String> list = new ArrayList<>();
list.add(data);
List<String> list1 = new ArrayList<>();
list1.add(sheet1.getSheetName());
ruleNameAndDataList.put(rule.getName(), list);
ruleNameAndSheetNameList.put(rule.getName(), list1);
} else {
if (!ruleNameAndDataList.get(rule.getName()).contains(data)){
ruleNameAndDataList.get(rule.getName()).add(data);
ruleNameAndSheetNameList.get(rule.getName()).add(sheet1.getSheetName());
}
}
}else if (rule.getCompare() == 2){
//判断统一文件中该字段是否唯一,网络名称是否唯一,数据准备
if (networkNameAndSheetName.keySet().contains(data)) {
sameNetSheetName = networkNameAndSheetName.get(data);//网络名称相同的sheetName
}
sameNetName = rule.getName();//别名
networkNameAndSheetName.put(data, sheet1.getSheetName());
}
//正则判断
Pattern p = Pattern.compile(rule.getRule());
Matcher m = p.matcher(data);
if (!m.matches()) {
//不符合
int k = result.size() + 1;
result.add(k + ".\"" + sheet1.getSheetName() + "\"第" + (dataRow + 1) + "行第" + (dataCell + 1) + "列不符合规则");
isSuccess = false;
}
} }
//正则规则判断
boolean isMatcher =compareMatcher(rules, key, data, sheet1.getSheetName(), compareDatas,
networkNameAndSheetName, sameNetSheetName);
if (!isMatcher){
//不符合
int k = result.size() + 1;
result.add(k + ".\"" + sheet1.getSheetName() + "\"第" + (dataRow + 1) + "行第" + (dataCell + 1) + "列不符合规则");
isSuccess = false;
log.info(sheet1.getSheetName() + "\"第" + (dataRow + 1) + "行第" + (dataCell + 1) +"不符合正则");
}
} }
//判断网络名字是否一样 //判断网络名字是否一样
if (sameNetSheetName != null){ if (sameNetSheetName.size() > 0){
String sameSheetName = sameNetSheetName.get(0);
String now = sheetNameAndContent.get(sheet1.getSheetName()); String now = sheetNameAndContent.get(sheet1.getSheetName());
String last = sheetNameAndContent.get(sameNetSheetName); String last = sheetNameAndContent.get(sameSheetName);
int k = result.size() + 1; int k = result.size() + 1;
if (Objects.equals(now, last)){ if (Objects.equals(now, last)){
result.add(k + ".\"" + sameNetSheetName + "\"与\"" + sheet1.getSheetName() + "\"存在内容相同表"); result.add(k + ".\"" + sameSheetName + "\"与\"" + sheet1.getSheetName() + "\"存在内容相同表");
}else { }else {
result.add(k + ".\"" + sameNetSheetName + "\"与\"" + sheet1.getSheetName() + "\"的\"" + sameNetName + "\"重名"); result.add(k + ".\"" + sameSheetName + "\"与\"" + sheet1.getSheetName() + "\"的\"网络名称\"重名");
} }
isSuccess = false; isSuccess = false;
} }
} }
//判断所有sheet ruleName的数据是否一样 //判断所有sheet 单位名字等数据是否一样
if (!ruleNameAndDataList.isEmpty()){ if (!compareDatas.isEmpty()){
for (String key : ruleNameAndDataList.keySet()){ for (CompareData compareData : compareDatas){
List<String> list = ruleNameAndSheetNameList.get(key); List<String> sheetNameList = compareData.getSheetNameList();
if (ruleNameAndDataList.get(key).size() > 1){ if (compareData.getDataList().size() > 1){
String sheetName = ""; String sheetName = "";
for (String s : list){ for (String s : sheetNameList){
sheetName = sheetName + "\"" + s + "\""; sheetName = sheetName + "\"" + s + "\"";
} }
//不是全部相同 //不是全部相同
int k = result.size() + 1; int k = result.size() + 1;
result.add(k + "." + sheetName + "中的\"" + key + "\"不同"); result.add(k + "." + sheetName + "中的\"" + compareData.getRuleName() + "\"不同");
isSuccess = false; isSuccess = false;
} }
} }
...@@ -446,6 +407,7 @@ public class ExcelData { ...@@ -446,6 +407,7 @@ public class ExcelData {
} }
}catch (Exception e){ }catch (Exception e){
e.printStackTrace();
int k = result.size() + 1; int k = result.size() + 1;
result.add(k + "." + "不是模板文件或读文件失败"); result.add(k + "." + "不是模板文件或读文件失败");
excelVos.add(new ExcelErrorVo(fileName, unitName, tel, buildTel, result)); excelVos.add(new ExcelErrorVo(fileName, unitName, tel, buildTel, result));
...@@ -464,6 +426,82 @@ public class ExcelData { ...@@ -464,6 +426,82 @@ public class ExcelData {
return ResultUtil.success(excelVo, "预览成功"); return ResultUtil.success(excelVo, "预览成功");
} }
/**
* 判断是否符合引用规则
* @param he 所有字段的全部引用map
* @param propertyName 字段名称
* @param data 真实数据
* @return 符合规则返回true
*/
private boolean compareQuote(Map<String, List<Quote>> he, String propertyName, String data){
List<Quote> quotes = he.get(propertyName);
boolean isQuote = false;
if (quotes != null && quotes.size() > 0){
for (Quote quote : quotes){
if(Objects.equals(data, quote.getValue())){
isQuote = true;
break;
}
}
}else {
isQuote = true;
}
return isQuote;
}
/**
* 判断是否符合正则规则
* @param rules 所有字段的规则
* @param key 字段名称
* @param data 真实数据
* @param sheetName 当前sheet名字
* @param compareDatas 用于判断单位名字等数据是否一样,数据准备
* @param networkNameAndSheetName 网络名称是否唯一
* @param sheetNameList 与当前网络名字相同的上一个sheet名字
* @return 符合返回true
*/
private boolean compareMatcher(List<Rule> rules, String key, String data, String sheetName,
List<CompareData> compareDatas,
Map<String, String> networkNameAndSheetName,
List<String> sheetNameList){
List<Rule> ruleList = rules.stream().filter(rule1 -> rule1.getRuleKey().equals(key)).collect(Collectors.toList());
if (!ruleList.isEmpty()) {
Rule rule = ruleList.get(0);
//判断同一个文件里所有sheet中该字段是否相同,数据准备
if (rule.getCompare() == 1) {
List<CompareData> dataList = compareDatas.stream().filter(compareData -> compareData.getRuleName().equals(rule.getName())).collect(Collectors.toList());
if (dataList.size() > 0) {
if (!dataList.get(0).getDataList().contains(data)){
dataList.get(0).getDataList().add(data);
dataList.get(0).getSheetNameList().add(sheetName);
}
} else {
List<String> list = new ArrayList<>();
list.add(data);
List<String> list1 = new ArrayList<>();
list1.add(sheetName);
CompareData compareData = new CompareData();
compareData.setDataList(list);
compareData.setSheetNameList(list1);
compareData.setRuleName(rule.getName());
compareDatas.add(compareData);
}
}else if (rule.getCompare() == 2){
//判断统一文件中该字段是否唯一,网络名称是否唯一,数据准备
if (networkNameAndSheetName.keySet().contains(data)) {
sheetNameList.add(networkNameAndSheetName.get(data));//网络名称相同的sheetName
}
networkNameAndSheetName.put(data, sheetName);
}
//正则判断
Pattern p = Pattern.compile(rule.getRule());
Matcher m = p.matcher(data);
return m.matches();
}
return true;
}
/** /**
* 读取模板文件 * 读取模板文件
* @param file 前端传过来的模板文件,如果没有传就读本地文件 * @param file 前端传过来的模板文件,如果没有传就读本地文件
...@@ -474,8 +512,7 @@ public class ExcelData { ...@@ -474,8 +512,7 @@ public class ExcelData {
List<ExcelRemarks> remarksList = new ArrayList<>(); List<ExcelRemarks> remarksList = new ArrayList<>();
if (file != null){ if (file != null){
String fileName = file.getResource().getFilename(); String fileName = file.getResource().getFilename();
InputStream fis = null; InputStream fis = file.getInputStream();
fis = file.getInputStream();
Workbook wb = null; Workbook wb = null;
if(fileName.endsWith("xls")) { if(fileName.endsWith("xls")) {
wb = new HSSFWorkbook(fis); wb = new HSSFWorkbook(fis);
...@@ -483,15 +520,13 @@ public class ExcelData { ...@@ -483,15 +520,13 @@ public class ExcelData {
wb = new XSSFWorkbook(fis); wb = new XSSFWorkbook(fis);
} }
Sheet sheet = wb.getSheetAt(0); Sheet sheet = wb.getSheetAt(0);
Row row = null;
int lastRow = sheet.getLastRowNum(); int lastRow = sheet.getLastRowNum();
for (int index = 0; index <= lastRow; index++){ for (int index = 0; index <= lastRow; index++){
row = sheet.getRow(index); Row row = sheet.getRow(index);
for(int i = row.getFirstCellNum(); i < row.getLastCellNum(); ++i) { for(int i = row.getFirstCellNum(); i < row.getLastCellNum(); ++i) {
row.getCell(i).setCellType(CellType.STRING); row.getCell(i).setCellType(CellType.STRING);
String data = row.getCell(i).getStringCellValue(); String data = row.getCell(i).getStringCellValue();
if (row.getCell(i) != null && data.contains("$")) { if (row.getCell(i) != null && data.contains("$")) {
int[] idenx = new int[2]; int[] idenx = new int[2];
idenx[0] = row.getRowNum(); idenx[0] = row.getRowNum();
idenx[1] = i; idenx[1] = i;
...@@ -503,29 +538,18 @@ public class ExcelData { ...@@ -503,29 +538,18 @@ public class ExcelData {
type = re[0].substring(1); type = re[0].substring(1);
remarksList.add(new ExcelRemarks(type, re[1], re[2], re[3], idenx)); remarksList.add(new ExcelRemarks(type, re[1], re[2], re[3], idenx));
} }
}else { }else {
//{className.propertyName=[1,2]},data=$A.name //{className.propertyName=[1,2]},data=$A.name
type = data.substring(1); type = data.substring(1);
indexMap.put(type.trim(), idenx); indexMap.put(type.trim(), idenx);
} }
} }
} }
} }
Template template = new Template(); Template template = new Template();
template.saveTemplate(JSON.toJSONString(indexMap), "template.txt"); template.saveTemplate(JSON.toJSONString(indexMap), "template.txt");
template.saveTemplate(JSON.toJSONString(remarksList), "remarksTemplate.txt"); template.saveTemplate(JSON.toJSONString(remarksList), "remarksTemplate.txt");
} }
// else {
// Template template = new Template();
// String tem = template.getTemplate();
// if (tem.isEmpty()){
// return indexMap;
// }
// indexMap = JSON.parseObject(tem, new TypeReference<Map<String, int[]>>(){});
// }
return indexMap; return indexMap;
} }
...@@ -538,8 +562,32 @@ public class ExcelData { ...@@ -538,8 +562,32 @@ public class ExcelData {
} }
return ResultUtil.failed("查询失败"); return ResultUtil.failed("查询失败");
} }
private void createFile(String path, String rootPath){
File pathFile = new File(path);
File rootFile = new File(rootPath);
if (!pathFile.exists()){
pathFile.mkdirs();
}
if (!rootFile.exists()){
rootFile.mkdirs();
}
String successPath = rootPath + "/successFile/";
String errorPath = rootPath + "/errorFile/";
File success = new File(successPath);
File error = new File(errorPath);
if (!success.exists()){
success.mkdirs();
}
if (!error.exists()){
error.mkdirs();
}
}
public ResponseEntity savePath(String path, String rootPath){ public ResponseEntity savePath(String path, String rootPath){
try { try {
if ("".equals(path)){
path = rootPath + "/workspace";
}
this.path = path; this.path = path;
this.rootPath = rootPath; this.rootPath = rootPath;
List<ExcelConfig> excelConfigs = excelConfigDao.findAll(); List<ExcelConfig> excelConfigs = excelConfigDao.findAll();
...@@ -547,8 +595,10 @@ public class ExcelData { ...@@ -547,8 +595,10 @@ public class ExcelData {
if (excelConfigs != null && excelConfigs.size() > 0){ if (excelConfigs != null && excelConfigs.size() > 0){
excelConfig = excelConfigs.get(0); excelConfig = excelConfigs.get(0);
} }
excelConfig.setPath(path); excelConfig.setPath(this.path);
excelConfig.setRootPath(rootPath); excelConfig.setRootPath(rootPath);
excelConfig.setFillIn(1);
createFile(path, rootPath);
excelConfigDao.saveAndFlush(excelConfig); excelConfigDao.saveAndFlush(excelConfig);
return ResultUtil.success("","保存成功"); return ResultUtil.success("","保存成功");
}catch (Exception e){ }catch (Exception e){
...@@ -558,18 +608,22 @@ public class ExcelData { ...@@ -558,18 +608,22 @@ public class ExcelData {
} }
private ExcelConfig findPaths(){ private ExcelConfig findPaths(){
List<ExcelConfig> excelConfigs = excelConfigDao.findAll(); List<ExcelConfig> excelConfigs = excelConfigDao.findAll();
ExcelConfig excelConfig = new ExcelConfig();
if (excelConfigs != null && excelConfigs.size() > 0){ if (excelConfigs != null && excelConfigs.size() > 0){
return excelConfigs.get(0); return excelConfigs.get(0);
}else {
String m = System.getProperty("user.dir") + "/";
excelConfig.setRootPath(m);
excelConfig.setFillIn(0);
// createFile(m + "workspace", m);
} }
return new ExcelConfig(); return excelConfig;
} }
public ResponseEntity findPrecen(){ public ResponseEntity findPrecen(){
DecimalFormat df=new DecimalFormat("0");//设置保留位数 DecimalFormat df=new DecimalFormat("0");//设置保留位数
String s = df.format(this.percent * 100); String s = df.format(this.percent * 100);
System.out.println("=============================================");
System.out.println(s);
if ("100".equals(s)){ if ("100".equals(s)){
this.percent = 0; this.percent = 0;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论