提交 8568b692 authored 作者: 马晨俊's avatar 马晨俊

mcj:更新

上级 77026748
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version> <version>2.1.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository --> <relativePath/> <!-- lookup parent from repository -->
</parent> </parent>
<groupId>com.zjty</groupId> <groupId>com.zjty</groupId>
...@@ -22,28 +22,11 @@ ...@@ -22,28 +22,11 @@
</profile> </profile>
</profiles> </profiles>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version> <java.version>1.8</java.version>
<spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
<swagger.version>2.9.2</swagger.version> <swagger.version>2.9.2</swagger.version>
<lombok.version>1.18.2</lombok.version>
<fastjson.version>1.2.46</fastjson.version>
<!--<fastjson.version>1.2.31</fastjson.version>-->
<liujie.latest.version>1.0-SNAPSHOT</liujie.latest.version>
</properties> </properties>
<dependencies> <dependencies>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.0.1</version>
</dependency>
<dependency> <dependency>
<groupId>io.springfox</groupId> <groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId> <artifactId>springfox-swagger2</artifactId>
...@@ -115,10 +98,8 @@ ...@@ -115,10 +98,8 @@
<artifactId>snakeyaml</artifactId> <artifactId>snakeyaml</artifactId>
<version>1.25</version> <version>1.25</version>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency> <dependency>
<groupId>net.lingala.zip4j</groupId> <groupId>net.lingala.zip4j</groupId>
<artifactId>zip4j</artifactId> <artifactId>zip4j</artifactId>
...@@ -138,14 +119,6 @@ ...@@ -138,14 +119,6 @@
<plugin> <plugin>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
......
...@@ -78,16 +78,6 @@ public class RuleController { ...@@ -78,16 +78,6 @@ public class RuleController {
return ResponseEntity.ok(ruleService.findAll()); return ResponseEntity.ok(ruleService.findAll());
} }
/**
* 查询所有规则
* @return 规则
*/
@ApiOperation("查询所有规则")
@GetMapping("/test")
public ResponseEntity test(){
ruleService.test();
return ResponseEntity.ok(200);
}
/** /**
* 分页+多条件查询 * 分页+多条件查询
* @param searchMap 查询条件封装 * @param searchMap 查询条件封装
......
...@@ -42,5 +42,4 @@ public interface RuleService { ...@@ -42,5 +42,4 @@ public interface RuleService {
List<RuleQo> findByName(String name); List<RuleQo> findByName(String name);
Page<RuleQo> findSearch(Map searchMap, int page, int size); Page<RuleQo> findSearch(Map searchMap, int page, int size);
void test();
} }
...@@ -6,7 +6,6 @@ import com.zjty.inspect.entity.Rule; ...@@ -6,7 +6,6 @@ import com.zjty.inspect.entity.Rule;
import com.zjty.inspect.entity.RuleQo; import com.zjty.inspect.entity.RuleQo;
import com.zjty.inspect.service.RuleService; import com.zjty.inspect.service.RuleService;
import com.zjty.inspect.service.TechnologyService; import com.zjty.inspect.service.TechnologyService;
import com.zjty.inspect.utils.ExcelReader;
import com.zjty.inspect.utils.UUIDUtil; import com.zjty.inspect.utils.UUIDUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
...@@ -41,28 +40,6 @@ public class RuleServiceImpl implements RuleService { ...@@ -41,28 +40,6 @@ public class RuleServiceImpl implements RuleService {
@Autowired @Autowired
private TechnologyService technologyService; private TechnologyService technologyService;
@Override
public void test() {
List<ExcelDataVo> excelDataVos = ExcelReader.readExcel("C:\\Users\\Jey\\Desktop\\生成代码\\规则表.xlsx");
System.out.println(excelDataVos);
HashSet<String> set=new HashSet();
for (ExcelDataVo excelDataVo : excelDataVos) {
List<Rule> rules = ruleDao.findAllByTarget(excelDataVo.getName());
if(rules==null||rules.size()==0){
set.add(excelDataVo.getName());
}
}
for (String s : set) {
Rule rule=new Rule();
rule.setTechnologyName("国产化依赖(支持)");
rule.setTechnologyId("967a8bd0-eb27-4fb6-ba1d-1bca21cea5b4");
rule.setSuffix("java");
rule.setTarget(s);
rule.setId(UUIDUtil.getUUID());
ruleDao.save(rule);
}
}
/** /**
* 新增规则 * 新增规则
......
package com.zjty.inspect.utils;
import com.zjty.inspect.entity.ExcelDataVo;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
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.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
public class ExcelReader {
private static final String XLS = "xls";
private static final String XLSX = "xlsx";
/**
* 根据文件后缀名类型获取对应的工作簿对象
* @param inputStream 读取文件的输入流
* @param fileType 文件后缀名类型(xls或xlsx)
* @return 包含文件数据的工作簿对象
* @throws IOException
*/
public static Workbook getWorkbook(InputStream inputStream, String fileType) throws IOException {
Workbook workbook = null;
if (fileType.equalsIgnoreCase(XLS)) {
workbook = new HSSFWorkbook(inputStream);
} else if (fileType.equalsIgnoreCase(XLSX)) {
workbook = new XSSFWorkbook(inputStream);
}
return workbook;
}
/**
* 读取Excel文件内容
* @param fileName 要读取的Excel文件所在路径
* @return 读取结果列表,读取失败时返回null
*/
public static List<ExcelDataVo> readExcel(String fileName) {
Workbook workbook = null;
FileInputStream inputStream = null;
try {
// 获取Excel后缀名
String fileType = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length());
// 获取Excel文件
File excelFile = new File(fileName);
if (!excelFile.exists()) {
System.out.println("指定的Excel文件不存在!");
return null;
}
// 获取Excel工作簿
inputStream = new FileInputStream(excelFile);
workbook = getWorkbook(inputStream, fileType);
// 读取excel中的数据
List<ExcelDataVo> resultDataList = parseExcel(workbook);
return resultDataList;
} catch (Exception e) {
System.out.println("解析Excel失败,文件名:" + fileName + " 错误信息:" + e.getMessage());
return null;
} finally {
try {
if (null != workbook) {
workbook.close();
}
if (null != inputStream) {
inputStream.close();
}
} catch (Exception e) {
System.out.println("关闭数据流出错!错误信息:" + e.getMessage());
return null;
}
}
}
/**
* 解析Excel数据
* @param workbook Excel工作簿对象
* @return 解析结果
*/
private static List<ExcelDataVo> parseExcel(Workbook workbook) {
List<ExcelDataVo> resultDataList = new ArrayList<>();
// 解析sheet
for (int sheetNum = 0; sheetNum < workbook.getNumberOfSheets(); sheetNum++) {
Sheet sheet = workbook.getSheetAt(sheetNum);
// 校验sheet是否合法
if (sheet == null) {
continue;
}
// 获取第一行数据
int firstRowNum = sheet.getFirstRowNum();
Row firstRow = sheet.getRow(firstRowNum);
if (null == firstRow) {
System.out.println("解析Excel失败,在第一行没有读取到任何数据!");
}
// 解析每一行的数据,构造数据对象
int rowStart = firstRowNum + 1;
int rowEnd = sheet.getPhysicalNumberOfRows();
for (int rowNum = rowStart; rowNum < rowEnd; rowNum++) {
Row row = sheet.getRow(rowNum);
if (null == row) {
continue;
}
ExcelDataVo resultData = convertRowToData(row);
if (null == resultData) {
System.out.println("第 " + row.getRowNum() + "行数据不合法,已忽略!");
continue;
}
resultDataList.add(resultData);
}
}
return resultDataList;
}
/**
* 将单元格内容转换为字符串
* @param cell
* @return
*/
private static String convertCellValueToString(Cell cell) {
if(cell==null){
return null;
}
String returnValue = null;
switch (cell.getCellType()) {
case NUMERIC: //数字
Double doubleValue = cell.getNumericCellValue();
// 格式化科学计数法,取一位整数
DecimalFormat df = new DecimalFormat("0");
returnValue = df.format(doubleValue);
break;
case STRING: //字符串
returnValue = cell.getStringCellValue();
break;
case BOOLEAN: //布尔
Boolean booleanValue = cell.getBooleanCellValue();
returnValue = booleanValue.toString();
break;
case BLANK: // 空值
break;
case FORMULA: // 公式
returnValue = cell.getCellFormula();
break;
case ERROR: // 故障
break;
default:
break;
}
return returnValue;
}
/**
* 提取每一行中需要的数据,构造成为一个结果数据对象
*
* 当该行中有单元格的数据为空或不合法时,忽略该行的数据
*
* @param row 行数据
* @return 解析后的行数据对象,行数据错误时返回null
*/
private static ExcelDataVo convertRowToData(Row row) {
ExcelDataVo resultData = new ExcelDataVo();
Cell cell;
int cellNum = 0;
// 获取姓名
cell = row.getCell(cellNum++);
String name = convertCellValueToString(cell);
resultData.setName(name);
return resultData;
}
}
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#spring.profiles.active=prod #spring.profiles.active=prod
# \u670D\u52A1\u5668\u76F8\u5173\u914D\u7F6E # \u670D\u52A1\u5668\u76F8\u5173\u914D\u7F6E
server.port=8080 server.port=8079
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
# \u65E5\u5FD7\u6587\u4EF6\u76F8\u5173\u914D\u7F6E # \u65E5\u5FD7\u6587\u4EF6\u76F8\u5173\u914D\u7F6E
# logging.level.org.hibernate.sql=debug # logging.level.org.hibernate.sql=debug
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论