提交 e69a771b authored 作者: 孙洁清's avatar 孙洁清

评估报告管理页面修改v1.0.4

上级 17880927
...@@ -10,6 +10,7 @@ import io.swagger.annotations.ApiOperation; ...@@ -10,6 +10,7 @@ import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -100,4 +101,21 @@ public class RuleController { ...@@ -100,4 +101,21 @@ public class RuleController {
CustomPage<RuleCollection> search = ruleService.findSearch(searchMap, page, size); CustomPage<RuleCollection> search = ruleService.findSearch(searchMap, page, size);
return ResponseEntity.ok(search); return ResponseEntity.ok(search);
} }
/**
* 导出所有规则
* @return 规则
*/
@ApiOperation("导出所有规则")
@GetMapping("/export")
public ResponseEntity exportAllRules(){
String path = ruleService.exportData();
return ResponseEntity.ok(path);
}
@PostMapping("/importRules")
@ApiOperation("导入所有规则")
public ResponseEntity importRules(@RequestParam("file") MultipartFile file){
ruleService.importRules(file);
return null;
}
} }
package com.zjty.inspect.entity;
import lombok.Data;
import java.util.List;
@Data
public class SyncData {
private List<TechnologySyn> technologies;
}
package com.zjty.inspect.entity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;
import javax.persistence.Column;
import java.sql.Timestamp;
import java.util.List;
@Data
public class TechnologySyn {
private String id;
/**
* 技术名称
*/
private String technologyName;
/**
* 技术建议
*/
private String advice;
/**
* 金额(万元)
*/
@ApiModelProperty(value = "金额",example = "123")
private Integer fund;
/**
* 1:支持
* 2:不支持
* 3:未知
* 4:不完全支持
* 5:优化
*/
@ApiModelProperty(value = "是否支持",example = "1")
private Integer support;
/**
* 分类id
*/
private String category_id;
/**
* 技术类型
* 1:前端技术
* 2:后端技术
*/
@ApiModelProperty(value = "技术类型",example = "2")
private Integer backOrFront =2;
/**
* 数据创建时间
*/
private Timestamp createDate;
/**
* 数据更新时间
*/
private Timestamp updateDate;
private List<Rule> rules;
}
...@@ -4,6 +4,7 @@ import com.zjty.inspect.entity.CustomPage; ...@@ -4,6 +4,7 @@ import com.zjty.inspect.entity.CustomPage;
import com.zjty.inspect.entity.Rule; import com.zjty.inspect.entity.Rule;
import com.zjty.inspect.entity.RuleCollection; import com.zjty.inspect.entity.RuleCollection;
import com.zjty.inspect.entity.RuleQo; import com.zjty.inspect.entity.RuleQo;
import org.springframework.web.multipart.MultipartFile;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -25,7 +26,7 @@ public interface RuleService { ...@@ -25,7 +26,7 @@ public interface RuleService {
* @param ruleQo 规则封装类 * @param ruleQo 规则封装类
*/ */
public void upRule(RuleQo ruleQo); public void upRule(RuleQo ruleQo);
public String exportData();
/** /**
* 删除规则 * 删除规则
* @param ruleQo 规则封装类 * @param ruleQo 规则封装类
...@@ -49,4 +50,6 @@ public interface RuleService { ...@@ -49,4 +50,6 @@ public interface RuleService {
CustomPage<RuleCollection> findSearch(Map searchMap, int page, int size); CustomPage<RuleCollection> findSearch(Map searchMap, int page, int size);
List<Rule> findAllByTechnologyIdIn(List<String> technologyIds); List<Rule> findAllByTechnologyIdIn(List<String> technologyIds);
void importRules(MultipartFile file);
} }
package com.zjty.inspect.service.impl; package com.zjty.inspect.service.impl;
import com.alibaba.fastjson.JSON;
import com.zjty.inspect.dao.RuleCollectionDao; import com.zjty.inspect.dao.RuleCollectionDao;
import com.zjty.inspect.dao.RuleDao; import com.zjty.inspect.dao.RuleDao;
import com.zjty.inspect.entity.*; import com.zjty.inspect.entity.*;
import com.zjty.inspect.service.RuleService; import com.zjty.inspect.service.RuleService;
import com.zjty.inspect.service.TechnologyService;
import com.zjty.inspect.utils.FileUtil;
import com.zjty.inspect.utils.UUIDUtil; import com.zjty.inspect.utils.UUIDUtil;
import org.springframework.beans.BeanUtils;
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;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
...@@ -13,9 +17,14 @@ import org.springframework.data.jpa.domain.Specification; ...@@ -13,9 +17,14 @@ import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Modifying;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Predicate;
import java.io.*;
import java.io.File;
import java.util.*; import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/** /**
* 规则库 * 规则库
...@@ -34,6 +43,8 @@ public class RuleServiceImpl implements RuleService { ...@@ -34,6 +43,8 @@ public class RuleServiceImpl implements RuleService {
@Autowired @Autowired
private RuleDao ruleDao; private RuleDao ruleDao;
@Autowired
private TechnologyService technologyService;
@Autowired @Autowired
private RuleCollectionDao ruleCollectionDao; private RuleCollectionDao ruleCollectionDao;
...@@ -97,6 +108,8 @@ public class RuleServiceImpl implements RuleService { ...@@ -97,6 +108,8 @@ public class RuleServiceImpl implements RuleService {
return ruleDao.findAllByTechnologyIdIn(technologyIds); return ruleDao.findAllByTechnologyIdIn(technologyIds);
} }
/** /**
* 动态条件构建 * 动态条件构建
* *
...@@ -229,4 +242,80 @@ public class RuleServiceImpl implements RuleService { ...@@ -229,4 +242,80 @@ public class RuleServiceImpl implements RuleService {
} }
return ruleCollections; return ruleCollections;
} }
public String exportData(){
SyncData syncData=new SyncData();
List<TechnologySyn> technologySyns=new ArrayList<>();
//1.生成数据
List<Technology> technologies = technologyService.findAllTechnology();
for (Technology technology : technologies) {
TechnologySyn technologySyn=new TechnologySyn();
BeanUtils.copyProperties(technology,technologySyn);
List<Rule> rules = ruleDao.findAllByTechnologyId(technology.getId());
technologySyn.setRules(rules);
technologySyns.add(technologySyn);
}
syncData.setTechnologies(technologySyns);
String s = JSON.toJSONString(syncData);
String path=System.getProperty("user.dir")+ File.separator+"inspect"+File.separator+"评测微服务数据.txt";
//2.生成json文件
FileUtil.write(s,path);
return path;
}
@Override
public void importRules(MultipartFile file) {
if (file.isEmpty()) {
return;
}
String fileName = file.getOriginalFilename();
String fileType = fileName.substring(0,fileName.lastIndexOf("."));
File dest = new File(System.getProperty("user.dir") +File.separator+"inspect"+File.separator+UUIDUtil.getUUID()+File.separator+fileType);
if (!dest.getParentFile().exists()) {
dest.getParentFile().mkdirs();
}
try {
file.transferTo(dest);
} catch (IOException e) {
e.printStackTrace();
}
String s = readTxt(dest.getAbsolutePath());
System.out.println(s);
//1.导入json文件
//2.清洗规则数据
//3.将数据添加到数据库中
//4.生成json文件
}
public String readTxt(String filePath){
try {
String encoding = "UTF-8";
File file = new File(filePath);
if (file.isFile() && file.exists()) { // 判断文件是否存在
InputStreamReader read = new InputStreamReader(
new FileInputStream(file), encoding);// 考虑到编码格式
BufferedReader bufferedReader = new BufferedReader(read);
String lineTxt = null;
StringBuilder sb = new StringBuilder();
while ((lineTxt = bufferedReader.readLine()) != null) {
sb.append(lineTxt);
}
String s = sb.toString();
read.close();
return s;
} else {
System.out.println("找不到指定的文件");
}
} catch (Exception e) {
System.out.println("读取文件内容出错");
e.printStackTrace();
}
return null;
}
public void syncData(){
//1.导入json数据
//2.清空数据库
//3.导入到标准库
}
} }
...@@ -50,7 +50,7 @@ spring.resources.static-locations=classpath:/uploads/ ...@@ -50,7 +50,7 @@ spring.resources.static-locations=classpath:/uploads/
# mysql\u6570\u636E\u5E93\u914D\u7F6E # mysql\u6570\u636E\u5E93\u914D\u7F6E
spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.driver-class-name=com.mysql.jdbc.Driver
#spring.datasource.url=jdbc:mysql://192.168.1.249:3306/bservice?useSSL=false&serverTimezone=UTC&autoReconnect=true&characterEncoding=utf-8 #spring.datasource.url=jdbc:mysql://192.168.1.249:3306/bservice?useSSL=false&serverTimezone=UTC&autoReconnect=true&characterEncoding=utf-8
spring.datasource.url=jdbc:mysql://localhost:3306/adaptation?useSSL=false&serverTimezone=UTC&autoReconnect=true&characterEncoding=utf-8 spring.datasource.url=jdbc:mysql://120.55.57.35:3306/adaptation?useSSL=false&serverTimezone=UTC&autoReconnect=true&characterEncoding=utf-8
spring.datasource.username=root spring.datasource.username=root
spring.datasource.password=root spring.datasource.password=root
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论