Commit ecee4836 by lanmw

fileImport and fileExport use dept to filter

parent dc3f9bf6
......@@ -27,13 +27,15 @@ public class TagFileCtrl {
@GetMapping("/exportTag")
public int export(HttpServletResponse response) {
String userName = UserInfoUtils.getUserName();
return tagExportService.exportExcel(userName, response);
String dept = userName;
return tagExportService.exportExcel(dept, response);
}
@PostMapping("/importTag")
public String importExcel(MultipartFile file, HttpServletResponse response) throws Exception {
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 {
@Autowired
private TagRepository tagRepository;
public int exportExcel(String userName, HttpServletResponse response) {
List<Tag> toExportTags = mongoOperations.find(Query.query(Criteria.where("creator").is(userName)
.and("dimensionType").is(Constants.TAG_DIMENSION_TRUE)), Tag.class);
public int exportExcel(String dept, HttpServletResponse response) {
List<Tag> toExportTags = mongoOperations.find(Query.query(Criteria.where("dept").is(dept)), Tag.class);
// 导出操作
ExcelUtils.exportExcel(toExportTags, null , "sheet1", Tag.class, "标签.xlsx", response);
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.setCreator(userName);
mongoOperations.save(importLog);
new Thread(new ExcelImportExecutor(userName, file, importLog)).start();
new Thread(new ExcelImportExecutor(userName, dept, file, importLog)).start();
return "ok";
}
......@@ -140,18 +139,20 @@ public class TagFileService {
}
class ExcelImportExecutor implements Runnable{
private String userName;
private String dept;
private MultipartFile file;
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.dept = dept;
this.file = file;
this.importLog = importLog;
}
@Override
public void run() {
List<Tag> dimensionTags = mongoOperations.find(Query.query(
Criteria.where("dimensionType").is(Constants.TAG_DIMENSION_TRUE)),
Criteria.where("dept").is(dept)),
Tag.class);
Map<String, Tag> pathTags = dimensionTags.stream().collect(Collectors.toMap(Tag::getPath, tag -> tag));
try {
......@@ -192,6 +193,7 @@ public class TagFileService {
t.setIdPath(parentIdPath + Constants.TAG_PATH_SEPARATOR + t.getId());
t.setLevel(t.getPath().split(",").length);
t.setCreator(userName);
t.setDept(dept);
t.setDimensionType(Constants.TAG_DIMENSION_TRUE);
t.setCreateDate(DateUtils.formatDate(new Date(), "yyyy-MM-dd"));
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