Commit ecee4836 by lanmw

fileImport and fileExport use dept to filter

parent dc3f9bf6
...@@ -27,13 +27,15 @@ public class TagFileCtrl { ...@@ -27,13 +27,15 @@ public class TagFileCtrl {
@GetMapping("/exportTag") @GetMapping("/exportTag")
public int export(HttpServletResponse response) { public int export(HttpServletResponse response) {
String userName = UserInfoUtils.getUserName(); String userName = UserInfoUtils.getUserName();
return tagExportService.exportExcel(userName, response); String dept = userName;
return tagExportService.exportExcel(dept, response);
} }
@PostMapping("/importTag") @PostMapping("/importTag")
public String importExcel(MultipartFile file, HttpServletResponse response) throws Exception { public String importExcel(MultipartFile file, HttpServletResponse response) throws Exception {
String userName = UserInfoUtils.getUserName(); String userName = UserInfoUtils.getUserName();
return tagExportService.importExcel(userName, file); String dept = userName;
return tagExportService.importExcel(userName, dept, file);
} }
......
...@@ -43,19 +43,18 @@ public class TagFileService { ...@@ -43,19 +43,18 @@ public class TagFileService {
@Autowired @Autowired
private TagRepository tagRepository; private TagRepository tagRepository;
public int exportExcel(String userName, HttpServletResponse response) { public int exportExcel(String dept, HttpServletResponse response) {
List<Tag> toExportTags = mongoOperations.find(Query.query(Criteria.where("creator").is(userName) List<Tag> toExportTags = mongoOperations.find(Query.query(Criteria.where("dept").is(dept)), Tag.class);
.and("dimensionType").is(Constants.TAG_DIMENSION_TRUE)), Tag.class);
// 导出操作 // 导出操作
ExcelUtils.exportExcel(toExportTags, null , "sheet1", Tag.class, "标签.xlsx", response); ExcelUtils.exportExcel(toExportTags, null , "sheet1", Tag.class, "标签.xlsx", response);
return toExportTags.size(); return toExportTags.size();
} }
public String importExcel(String userName, MultipartFile file) throws Exception { public String importExcel(String userName, String dept, MultipartFile file) throws Exception {
ImportLog importLog = new ImportLog(UUID.randomUUID().toString()); ImportLog importLog = new ImportLog(UUID.randomUUID().toString());
importLog.setCreator(userName); importLog.setCreator(userName);
mongoOperations.save(importLog); mongoOperations.save(importLog);
new Thread(new ExcelImportExecutor(userName, file, importLog)).start(); new Thread(new ExcelImportExecutor(userName, dept, file, importLog)).start();
return "ok"; return "ok";
} }
...@@ -140,18 +139,20 @@ public class TagFileService { ...@@ -140,18 +139,20 @@ public class TagFileService {
} }
class ExcelImportExecutor implements Runnable{ class ExcelImportExecutor implements Runnable{
private String userName; private String dept;
private MultipartFile file; private MultipartFile file;
private ImportLog importLog; private ImportLog importLog;
public ExcelImportExecutor(String userName, MultipartFile file, ImportLog importLog) { private String userName;
public ExcelImportExecutor(String userName, String dept, MultipartFile file, ImportLog importLog) {
this.userName = userName; this.userName = userName;
this.dept = dept;
this.file = file; this.file = file;
this.importLog = importLog; this.importLog = importLog;
} }
@Override @Override
public void run() { public void run() {
List<Tag> dimensionTags = mongoOperations.find(Query.query( List<Tag> dimensionTags = mongoOperations.find(Query.query(
Criteria.where("dimensionType").is(Constants.TAG_DIMENSION_TRUE)), Criteria.where("dept").is(dept)),
Tag.class); Tag.class);
Map<String, Tag> pathTags = dimensionTags.stream().collect(Collectors.toMap(Tag::getPath, tag -> tag)); Map<String, Tag> pathTags = dimensionTags.stream().collect(Collectors.toMap(Tag::getPath, tag -> tag));
try { try {
...@@ -192,6 +193,7 @@ public class TagFileService { ...@@ -192,6 +193,7 @@ public class TagFileService {
t.setIdPath(parentIdPath + Constants.TAG_PATH_SEPARATOR + t.getId()); t.setIdPath(parentIdPath + Constants.TAG_PATH_SEPARATOR + t.getId());
t.setLevel(t.getPath().split(",").length); t.setLevel(t.getPath().split(",").length);
t.setCreator(userName); t.setCreator(userName);
t.setDept(dept);
t.setDimensionType(Constants.TAG_DIMENSION_TRUE); t.setDimensionType(Constants.TAG_DIMENSION_TRUE);
t.setCreateDate(DateUtils.formatDate(new Date(), "yyyy-MM-dd")); t.setCreateDate(DateUtils.formatDate(new Date(), "yyyy-MM-dd"));
t.setImportId(importLog.getId()); t.setImportId(importLog.getId());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment