Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
markliu2013 committed Mar 16, 2024
1 parent b111005 commit afbf6ed
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/main/java/cn/biq/mn/TestController.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class TestController {

@RequestMapping(method = RequestMethod.GET, value = "/version")
public BaseResponse handleVersion() {
return new DataResponse<>("93.34");
return new DataResponse<>("93.35");
}

@GetMapping("/test3")
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/cn/biq/mn/book/BookService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cn.biq.mn.book;

import cn.biq.mn.bean.ApplicationScopeBean;
import cn.biq.mn.book.tpl.BookTplDataLoader;
import cn.biq.mn.exception.FailureMessageException;
import cn.biq.mn.exception.ItemExistsException;
import cn.biq.mn.exception.ItemNotFoundException;
Expand Down Expand Up @@ -166,7 +167,7 @@ public boolean toggle(Integer id) {
// 账本模板列表,复制功能使用
public boolean addByTemplate(BookAddByTemplateForm form) {
Group group = sessionUtil.getCurrentGroup();
List<BookTemplate> bookTplList = applicationScopeBean.getBookTplList();
List<BookTemplate> bookTplList = BookTplDataLoader.load();
Optional<BookTemplate> bookTemplateOptional = bookTplList.stream()
.filter(bookTemplate -> bookTemplate.getId().equals(form.getTemplateId()))
.findFirst();
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/cn/biq/mn/book/tpl/BookTplDataLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


@Component
Expand All @@ -20,13 +22,22 @@ public class BookTplDataLoader implements ApplicationRunner {

@Override
public void run(ApplicationArguments args) {
try {
applicationScopeBean.setBookTplList(load());
} catch (Exception e) {
e.printStackTrace();
}
}

public static List<BookTemplate> load() {
try {
Resource resource = new ClassPathResource("book_tpl.json");
ObjectMapper objectMapper = new ObjectMapper();
BookTemplate[] bookTemplateList = objectMapper.readValue(resource.getInputStream(), BookTemplate[].class);
applicationScopeBean.setBookTplList(Arrays.asList(bookTemplateList));
return Arrays.asList(bookTemplateList);
} catch (Exception e) {
e.printStackTrace();
return new ArrayList<>();
}
}

Expand Down

0 comments on commit afbf6ed

Please sign in to comment.