From ce1767ac3f69d72ba4e7f138f11b933622b9719e Mon Sep 17 00:00:00 2001 From: ronger Date: Wed, 2 Jun 2021 21:47:13 +0800 Subject: [PATCH 1/7] =?UTF-8?q?:art:=20=E6=90=9C=E7=B4=A2=E7=BB=93?= =?UTF-8?q?=E6=9E=9C=E5=B1=95=E7=A4=BA=E6=95=88=E6=9E=9C=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/LuceneServiceImpl.java | 300 +++++++++--------- .../mapper/lucene/ArticleLuceneMapper.xml | 2 +- 2 files changed, 154 insertions(+), 148 deletions(-) diff --git a/src/main/java/com/rymcu/forest/lucene/service/impl/LuceneServiceImpl.java b/src/main/java/com/rymcu/forest/lucene/service/impl/LuceneServiceImpl.java index 412c865..294a93e 100644 --- a/src/main/java/com/rymcu/forest/lucene/service/impl/LuceneServiceImpl.java +++ b/src/main/java/com/rymcu/forest/lucene/service/impl/LuceneServiceImpl.java @@ -9,6 +9,7 @@ import com.rymcu.forest.lucene.service.LuceneService; import com.rymcu.forest.lucene.util.ArticleIndexUtil; import com.rymcu.forest.lucene.util.LucenePath; import com.rymcu.forest.lucene.util.SearchUtil; +import com.rymcu.forest.util.Html2TextUtil; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.document.Document; @@ -41,157 +42,162 @@ import java.util.concurrent.Executors; @Service public class LuceneServiceImpl implements LuceneService { - @Resource private ArticleLuceneMapper luceneMapper; + @Resource + private ArticleLuceneMapper luceneMapper; - /** - * 将文章的数据解析为一个个关键字词存储到索引文件中 - * - * @param list - */ - @Override - public void writeArticle(List list) { - try { - int totalCount = list.size(); - int perThreadCount = 3000; - int threadCount = totalCount / perThreadCount + (totalCount % perThreadCount == 0 ? 0 : 1); - ExecutorService pool = Executors.newFixedThreadPool(threadCount); - CountDownLatch countDownLatch1 = new CountDownLatch(1); - CountDownLatch countDownLatch2 = new CountDownLatch(threadCount); + /** + * 将文章的数据解析为一个个关键字词存储到索引文件中 + * + * @param list + */ + @Override + public void writeArticle(List list) { + try { + int totalCount = list.size(); + int perThreadCount = 3000; + int threadCount = totalCount / perThreadCount + (totalCount % perThreadCount == 0 ? 0 : 1); + ExecutorService pool = Executors.newFixedThreadPool(threadCount); + CountDownLatch countDownLatch1 = new CountDownLatch(1); + CountDownLatch countDownLatch2 = new CountDownLatch(threadCount); - for (int i = 0; i < threadCount; i++) { - int start = i * perThreadCount; - int end = Math.min((i + 1) * perThreadCount, totalCount); - List subList = list.subList(start, end); - Runnable runnable = - new ArticleBeanIndex( - LucenePath.ARTICLE_INDEX_PATH, i, countDownLatch1, countDownLatch2, subList); - // 子线程交给线程池管理 - pool.execute(runnable); - } - countDownLatch1.countDown(); - System.out.println("开始创建索引"); - // 等待所有线程都完成 - countDownLatch2.await(); - // 线程全部完成工作 - System.out.println("所有线程都创建索引完毕"); - // 释放线程池资源 - pool.shutdown(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Override - public void writeArticle(String id) { - writeArticle(luceneMapper.getById(id)); - } - - @Override - public void writeArticle(ArticleLucene articleLucene) { - ArticleIndexUtil.addIndex(articleLucene); - } - - @Override - public void updateArticle(String id) { - ArticleIndexUtil.updateIndex(luceneMapper.getById(id)); - } - - @Override - public void deleteArticle(String id) { - ArticleIndexUtil.deleteIndex(id); - } - - /** - * 关键词搜索 - * - * @param value - * @return - * @throws Exception - */ - @Override - public List searchArticle(String value) { - List resList = new ArrayList<>(); - ExecutorService service = Executors.newCachedThreadPool(); - // 定义分词器 - Analyzer analyzer = new IKAnalyzer(); - try { - IndexSearcher searcher = - SearchUtil.getIndexSearcherByParentPath(LucenePath.ARTICLE_INDEX_PATH, service); - String[] fields = {"title", "summary"}; - // 构造Query对象 - MultiFieldQueryParser parser = new MultiFieldQueryParser(fields, analyzer); - - BufferedReader in = - new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8)); - String line = value != null ? value : in.readLine(); - Query query = parser.parse(line); - // 最终被分词后添加的前缀和后缀处理器,默认是粗体 - SimpleHTMLFormatter htmlFormatter = - new SimpleHTMLFormatter("", ""); - // 高亮搜索的词添加到高亮处理器中 - Highlighter highlighter = new Highlighter(htmlFormatter, new QueryScorer(query)); - - // 获取搜索的结果,指定返回document返回的个数 - // TODO 默认搜索结果为显示第一页,1000 条,可以优化 - TopDocs results = SearchUtil.getScoreDocsByPerPage(1, 100, searcher, query); - ScoreDoc[] hits = results.scoreDocs; - - // 遍历,输出 - for (ScoreDoc hit : hits) { - int id = hit.doc; - float score = hit.score; - Document hitDoc = searcher.doc(hit.doc); - // 获取到summary - String name = hitDoc.get("summary"); - // 将查询的词和搜索词匹配,匹配到添加前缀和后缀 - TokenStream tokenStream = - TokenSources.getAnyTokenStream(searcher.getIndexReader(), id, "summary", analyzer); - // 传入的第二个参数是查询的值 - TextFragment[] frag = highlighter.getBestTextFragments(tokenStream, name, false, 10); - StringBuilder baikeValue = new StringBuilder(); - for (TextFragment textFragment : frag) { - if ((textFragment != null) && (textFragment.getScore() > 0)) { - // if ((frag[j] != null)) { - // 获取 summary 的值 - baikeValue.append(textFragment); - } + for (int i = 0; i < threadCount; i++) { + int start = i * perThreadCount; + int end = Math.min((i + 1) * perThreadCount, totalCount); + List subList = list.subList(start, end); + Runnable runnable = + new ArticleBeanIndex( + LucenePath.ARTICLE_INDEX_PATH, i, countDownLatch1, countDownLatch2, subList); + // 子线程交给线程池管理 + pool.execute(runnable); + } + countDownLatch1.countDown(); + System.out.println("开始创建索引"); + // 等待所有线程都完成 + countDownLatch2.await(); + // 线程全部完成工作 + System.out.println("所有线程都创建索引完毕"); + // 释放线程池资源 + pool.shutdown(); + } catch (Exception e) { + e.printStackTrace(); } - - // 获取到title - String title = hitDoc.get("title"); - TokenStream titleTokenStream = - TokenSources.getAnyTokenStream(searcher.getIndexReader(), id, "title", analyzer); - TextFragment[] titleFrag = - highlighter.getBestTextFragments(titleTokenStream, title, false, 10); - StringBuilder titleValue = new StringBuilder(); - for (int j = 0; j < titleFrag.length; j++) { - if ((frag[j] != null)) { - titleValue.append(titleFrag[j].toString()); - } - } - resList.add( - ArticleLucene.builder() - .idArticle(hitDoc.get("id")) - .articleTitle(titleValue.toString()) - .articleContent(baikeValue.toString()) - .score(String.valueOf(score)) - .build()); - } - } catch (IOException | ParseException | InvalidTokenOffsetsException e) { - e.printStackTrace(); - } finally { - service.shutdownNow(); } - return resList; - } - @Override - public List getAllArticleLucene() { - return luceneMapper.getAllArticleLucene(); - } + @Override + public void writeArticle(String id) { + writeArticle(luceneMapper.getById(id)); + } - @Override - public List getArticlesByIds(String[] ids) { - return luceneMapper.getArticlesByIds(ids); - } + @Override + public void writeArticle(ArticleLucene articleLucene) { + ArticleIndexUtil.addIndex(articleLucene); + } + + @Override + public void updateArticle(String id) { + ArticleIndexUtil.updateIndex(luceneMapper.getById(id)); + } + + @Override + public void deleteArticle(String id) { + ArticleIndexUtil.deleteIndex(id); + } + + /** + * 关键词搜索 + * + * @param value + * @return + * @throws Exception + */ + @Override + public List searchArticle(String value) { + List resList = new ArrayList<>(); + ExecutorService service = Executors.newCachedThreadPool(); + // 定义分词器 + Analyzer analyzer = new IKAnalyzer(); + try { + IndexSearcher searcher = + SearchUtil.getIndexSearcherByParentPath(LucenePath.ARTICLE_INDEX_PATH, service); + String[] fields = {"title", "summary"}; + // 构造Query对象 + MultiFieldQueryParser parser = new MultiFieldQueryParser(fields, analyzer); + + BufferedReader in = + new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8)); + String line = value != null ? value : in.readLine(); + Query query = parser.parse(line); + // 最终被分词后添加的前缀和后缀处理器,默认是粗体 + SimpleHTMLFormatter htmlFormatter = + new SimpleHTMLFormatter("", ""); + // 高亮搜索的词添加到高亮处理器中 + Highlighter highlighter = new Highlighter(htmlFormatter, new QueryScorer(query)); + + // 获取搜索的结果,指定返回document返回的个数 + // TODO 默认搜索结果为显示第一页,1000 条,可以优化 + TopDocs results = SearchUtil.getScoreDocsByPerPage(1, 100, searcher, query); + ScoreDoc[] hits = results.scoreDocs; + + // 遍历,输出 + for (ScoreDoc hit : hits) { + int id = hit.doc; + float score = hit.score; + Document hitDoc = searcher.doc(hit.doc); + // 获取到summary + String name = hitDoc.get("summary"); + // 将查询的词和搜索词匹配,匹配到添加前缀和后缀 + TokenStream tokenStream = + TokenSources.getAnyTokenStream(searcher.getIndexReader(), id, "summary", analyzer); + // 传入的第二个参数是查询的值 + TextFragment[] frag = highlighter.getBestTextFragments(tokenStream, name, false, 10); + StringBuilder baikeValue = new StringBuilder(); + for (TextFragment textFragment : frag) { + if ((textFragment != null) && (textFragment.getScore() > 0)) { + // if ((frag[j] != null)) { + // 获取 summary 的值 + baikeValue.append(textFragment); + } + } + + // 获取到title + String title = hitDoc.get("title"); + TokenStream titleTokenStream = + TokenSources.getAnyTokenStream(searcher.getIndexReader(), id, "title", analyzer); + TextFragment[] titleFrag = + highlighter.getBestTextFragments(titleTokenStream, title, false, 10); + StringBuilder titleValue = new StringBuilder(); + for (int j = 0; j < titleFrag.length; j++) { + if ((frag[j] != null)) { + titleValue.append(titleFrag[j].toString()); + } + } + resList.add( + ArticleLucene.builder() + .idArticle(hitDoc.get("id")) + .articleTitle(titleValue.toString()) + .articleContent(baikeValue.toString()) + .score(String.valueOf(score)) + .build()); + } + } catch (IOException | ParseException | InvalidTokenOffsetsException e) { + e.printStackTrace(); + } finally { + service.shutdownNow(); + } + return resList; + } + + @Override + public List getAllArticleLucene() { + List list = luceneMapper.getAllArticleLucene(); + for (ArticleLucene articleLucene : list) { + articleLucene.setArticleContent(Html2TextUtil.getContent(articleLucene.getArticleContent())); + } + return list; + } + + @Override + public List getArticlesByIds(String[] ids) { + return luceneMapper.getArticlesByIds(ids); + } } diff --git a/src/main/java/mapper/lucene/ArticleLuceneMapper.xml b/src/main/java/mapper/lucene/ArticleLuceneMapper.xml index c584a26..95a8c61 100755 --- a/src/main/java/mapper/lucene/ArticleLuceneMapper.xml +++ b/src/main/java/mapper/lucene/ArticleLuceneMapper.xml @@ -32,7 +32,7 @@ \ No newline at end of file From a7e0f7feee57200b19ce02a3e5635e0031cc3a82 Mon Sep 17 00:00:00 2001 From: ronger Date: Mon, 28 Jun 2021 08:06:37 +0800 Subject: [PATCH 3/7] =?UTF-8?q?1.=20=E6=96=87=E7=AB=A0=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=202.=20=E8=AF=84=E8=AE=BA=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/rymcu/forest/dto/ArticleDTO.java | 2 ++ .../java/com/rymcu/forest/dto/CommentDTO.java | 2 ++ .../rymcu/forest/mapper/CommentMapper.java | 6 ++++ .../rymcu/forest/service/CommentService.java | 17 ++++++++++ .../service/impl/CommentServiceImpl.java | 10 ++++++ .../forest/web/api/admin/AdminController.java | 33 +++++++++++++++++++ src/main/java/mapper/CommentMapper.xml | 3 ++ 7 files changed, 73 insertions(+) diff --git a/src/main/java/com/rymcu/forest/dto/ArticleDTO.java b/src/main/java/com/rymcu/forest/dto/ArticleDTO.java index 43a84b4..530998c 100644 --- a/src/main/java/com/rymcu/forest/dto/ArticleDTO.java +++ b/src/main/java/com/rymcu/forest/dto/ArticleDTO.java @@ -1,5 +1,6 @@ package com.rymcu.forest.dto; +import com.alibaba.fastjson.annotation.JSONField; import lombok.Data; import java.util.Date; @@ -44,6 +45,7 @@ public class ArticleDTO { /** 文章状态 */ private String articleStatus; /** 更新时间 */ + @JSONField(format = "yyyy-MM-dd HH:mm:ss") private Date updatedTime; private Author articleAuthor; diff --git a/src/main/java/com/rymcu/forest/dto/CommentDTO.java b/src/main/java/com/rymcu/forest/dto/CommentDTO.java index 1f93a53..cb5826b 100644 --- a/src/main/java/com/rymcu/forest/dto/CommentDTO.java +++ b/src/main/java/com/rymcu/forest/dto/CommentDTO.java @@ -1,5 +1,6 @@ package com.rymcu.forest.dto; +import com.alibaba.fastjson.annotation.JSONField; import lombok.Data; import java.util.Date; @@ -35,6 +36,7 @@ public class CommentDTO { /** 0:所有人可见,1:仅楼主和自己可见 */ private String commentVisible; /** 创建时间 */ + @JSONField(format = "yyyy-MM-dd HH:mm:ss") private Date createdTime; private Author commenter; diff --git a/src/main/java/com/rymcu/forest/mapper/CommentMapper.java b/src/main/java/com/rymcu/forest/mapper/CommentMapper.java index aa369ac..4969ece 100644 --- a/src/main/java/com/rymcu/forest/mapper/CommentMapper.java +++ b/src/main/java/com/rymcu/forest/mapper/CommentMapper.java @@ -40,4 +40,10 @@ public interface CommentMapper extends Mapper { * @return */ Integer updateCommentSharpUrl(@Param("idComment") Integer idComment, @Param("commentSharpUrl") String commentSharpUrl); + + /** + * 获取评论列表数据 + * @return + */ + List selectComments(); } diff --git a/src/main/java/com/rymcu/forest/service/CommentService.java b/src/main/java/com/rymcu/forest/service/CommentService.java index 9199b90..92b2b9d 100644 --- a/src/main/java/com/rymcu/forest/service/CommentService.java +++ b/src/main/java/com/rymcu/forest/service/CommentService.java @@ -13,7 +13,24 @@ import java.util.Map; */ public interface CommentService extends Service { + /** + * 获取文章评论数据 + * @param idArticle + * @return + */ List getArticleComments(Integer idArticle); + /** + * 评论 + * @param comment + * @param request + * @return + */ Map postComment(Comment comment, HttpServletRequest request); + + /** + * 获取评论列表数据 + * @return + */ + List findComments(); } diff --git a/src/main/java/com/rymcu/forest/service/impl/CommentServiceImpl.java b/src/main/java/com/rymcu/forest/service/impl/CommentServiceImpl.java index 174e66e..0602e87 100644 --- a/src/main/java/com/rymcu/forest/service/impl/CommentServiceImpl.java +++ b/src/main/java/com/rymcu/forest/service/impl/CommentServiceImpl.java @@ -36,6 +36,10 @@ public class CommentServiceImpl extends AbstractService implements Comm @Override public List getArticleComments(Integer idArticle) { List commentDTOList = commentMapper.selectArticleComments(idArticle); + return genComments(commentDTOList); + } + + private List genComments(List commentDTOList) { commentDTOList.forEach(commentDTO -> { commentDTO.setTimeAgo(Utils.getTimeAgo(commentDTO.getCreatedTime())); if (commentDTO.getCommentAuthorId() != null) { @@ -113,4 +117,10 @@ public class CommentServiceImpl extends AbstractService implements Comm return map; } + + @Override + public List findComments() { + List commentDTOList = commentMapper.selectComments(); + return genComments(commentDTOList); + } } diff --git a/src/main/java/com/rymcu/forest/web/api/admin/AdminController.java b/src/main/java/com/rymcu/forest/web/api/admin/AdminController.java index f39b423..216ea56 100644 --- a/src/main/java/com/rymcu/forest/web/api/admin/AdminController.java +++ b/src/main/java/com/rymcu/forest/web/api/admin/AdminController.java @@ -4,6 +4,9 @@ import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.rymcu.forest.core.result.GlobalResult; import com.rymcu.forest.core.result.GlobalResultGenerator; +import com.rymcu.forest.dto.ArticleDTO; +import com.rymcu.forest.dto.ArticleSearchDTO; +import com.rymcu.forest.dto.CommentDTO; import com.rymcu.forest.dto.UserSearchDTO; import com.rymcu.forest.dto.admin.TopicTagDTO; import com.rymcu.forest.dto.admin.UserRoleDTO; @@ -36,6 +39,10 @@ public class AdminController { private TagService tagService; @Resource private SpecialDayService specialDayService; + @Resource + private ArticleService articleService; + @Resource + private CommentService commentService; @GetMapping("/users") public GlobalResult> users(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows, UserSearchDTO searchDTO){ @@ -219,4 +226,30 @@ public class AdminController { return GlobalResultGenerator.genSuccessResult(map); } + @GetMapping("/articles") + public GlobalResult articles(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows, ArticleSearchDTO articleSearchDTO) { + PageHelper.startPage(page, rows); + List list = articleService.findArticles(articleSearchDTO); + PageInfo pageInfo = new PageInfo<>(list); + Map map = new HashMap<>(2); + map.put("articles", pageInfo.getList()); + Map pagination = Utils.getPagination(pageInfo); + map.put("pagination", pagination); + return GlobalResultGenerator.genSuccessResult(map); + } + + @GetMapping("/comments") + public GlobalResult comments(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows) { + PageHelper.startPage(page, rows); + List list = commentService.findComments(); + PageInfo pageInfo = new PageInfo<>(list); + Map map = new HashMap<>(2); + map.put("comments", pageInfo.getList()); + Map pagination = Utils.getPagination(pageInfo); + map.put("pagination", pagination); + return GlobalResultGenerator.genSuccessResult(map); + } + + + } diff --git a/src/main/java/mapper/CommentMapper.xml b/src/main/java/mapper/CommentMapper.xml index 646abb2..d49ce61 100644 --- a/src/main/java/mapper/CommentMapper.xml +++ b/src/main/java/mapper/CommentMapper.xml @@ -47,4 +47,7 @@ + \ No newline at end of file From 62d67e70b6e6ab0bfad8caf3bef05aa09afb2f4d Mon Sep 17 00:00:00 2001 From: ronger Date: Mon, 28 Jun 2021 09:57:08 +0800 Subject: [PATCH 4/7] =?UTF-8?q?:art:=20=E8=AF=84=E8=AE=BA=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=8A=9F=E8=83=BD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/rymcu/forest/dto/CommentDTO.java | 2 ++ src/main/java/mapper/CommentMapper.xml | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/rymcu/forest/dto/CommentDTO.java b/src/main/java/com/rymcu/forest/dto/CommentDTO.java index cb5826b..8920b41 100644 --- a/src/main/java/com/rymcu/forest/dto/CommentDTO.java +++ b/src/main/java/com/rymcu/forest/dto/CommentDTO.java @@ -42,4 +42,6 @@ public class CommentDTO { private Author commenter; private String timeAgo; + + private String articleTitle; } diff --git a/src/main/java/mapper/CommentMapper.xml b/src/main/java/mapper/CommentMapper.xml index d49ce61..5d73f0f 100644 --- a/src/main/java/mapper/CommentMapper.xml +++ b/src/main/java/mapper/CommentMapper.xml @@ -28,6 +28,7 @@ + @@ -39,7 +40,7 @@ update forest_comment set comment_sharp_url = #{commentSharpUrl} where id = #{idComment} \ No newline at end of file From f4b776a9038d46f675c59cc6f9b5a03c342f97b6 Mon Sep 17 00:00:00 2001 From: ronger Date: Mon, 28 Jun 2021 12:00:11 +0800 Subject: [PATCH 5/7] =?UTF-8?q?:art:=20=E6=88=91=E7=9A=84=E9=92=B1?= =?UTF-8?q?=E5=8C=85=E5=B1=95=E7=A4=BA=E6=95=88=E6=9E=9C=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../forest/dto/TransactionRecordDTO.java | 4 ++++ .../forest/mapper/BankAccountMapper.java | 7 ++++++ .../forest/service/BankAccountService.java | 2 +- .../service/impl/BankAccountServiceImpl.java | 6 ++--- .../impl/TransactionRecordServiceImpl.java | 18 +++++++++++++-- src/main/java/mapper/BankAccountMapper.xml | 22 ++++++++++++------- .../java/mapper/TransactionRecordMapper.xml | 2 +- 7 files changed, 45 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/rymcu/forest/dto/TransactionRecordDTO.java b/src/main/java/com/rymcu/forest/dto/TransactionRecordDTO.java index 14148d8..349dbb9 100644 --- a/src/main/java/com/rymcu/forest/dto/TransactionRecordDTO.java +++ b/src/main/java/com/rymcu/forest/dto/TransactionRecordDTO.java @@ -19,8 +19,12 @@ public class TransactionRecordDTO { private String funds; /** 交易发起方 */ private String formBankAccount; + /** 交易发起方 */ + private BankAccountDTO formBankAccountInfo; /** 交易收款方 */ private String toBankAccount; + /** 交易收款方 */ + private BankAccountDTO toBankAccountInfo; /** 交易金额 */ private BigDecimal money; /** 交易类型 */ diff --git a/src/main/java/com/rymcu/forest/mapper/BankAccountMapper.java b/src/main/java/com/rymcu/forest/mapper/BankAccountMapper.java index a71f580..a067c76 100644 --- a/src/main/java/com/rymcu/forest/mapper/BankAccountMapper.java +++ b/src/main/java/com/rymcu/forest/mapper/BankAccountMapper.java @@ -32,4 +32,11 @@ public interface BankAccountMapper extends Mapper { * @return */ String selectMaxBankAccount(); + + /** + * 根据卡号获取银行账号信息 + * @param bankAccount + * @return + */ + BankAccountDTO selectByBankAccount(@Param("bankAccount") String bankAccount); } diff --git a/src/main/java/com/rymcu/forest/service/BankAccountService.java b/src/main/java/com/rymcu/forest/service/BankAccountService.java index fa355e7..f8b1b54 100644 --- a/src/main/java/com/rymcu/forest/service/BankAccountService.java +++ b/src/main/java/com/rymcu/forest/service/BankAccountService.java @@ -31,7 +31,7 @@ public interface BankAccountService extends Service { * @param bankAccount * @return */ - BankAccount findByBankAccount(String bankAccount); + BankAccountDTO findByBankAccount(String bankAccount); /** * 查询系统社区银行 diff --git a/src/main/java/com/rymcu/forest/service/impl/BankAccountServiceImpl.java b/src/main/java/com/rymcu/forest/service/impl/BankAccountServiceImpl.java index 5721464..370b7a9 100644 --- a/src/main/java/com/rymcu/forest/service/impl/BankAccountServiceImpl.java +++ b/src/main/java/com/rymcu/forest/service/impl/BankAccountServiceImpl.java @@ -61,10 +61,8 @@ public class BankAccountServiceImpl extends AbstractService impleme } @Override - public BankAccount findByBankAccount(String bankAccount) { - BankAccount searchBankAccount = new BankAccount(); - searchBankAccount.setBankAccount(bankAccount); - return bankAccountMapper.selectOne(searchBankAccount); + public BankAccountDTO findByBankAccount(String bankAccount) { + return bankAccountMapper.selectByBankAccount(bankAccount); } @Override diff --git a/src/main/java/com/rymcu/forest/service/impl/TransactionRecordServiceImpl.java b/src/main/java/com/rymcu/forest/service/impl/TransactionRecordServiceImpl.java index a832bf3..eaef498 100644 --- a/src/main/java/com/rymcu/forest/service/impl/TransactionRecordServiceImpl.java +++ b/src/main/java/com/rymcu/forest/service/impl/TransactionRecordServiceImpl.java @@ -4,15 +4,19 @@ import com.rymcu.forest.core.exception.TransactionException; import com.rymcu.forest.core.service.AbstractService; import com.rymcu.forest.core.service.redis.RedisService; import com.rymcu.forest.dto.BankAccountDTO; +import com.rymcu.forest.dto.BankAccountSearchDTO; import com.rymcu.forest.dto.TransactionRecordDTO; import com.rymcu.forest.entity.BankAccount; import com.rymcu.forest.entity.TransactionRecord; +import com.rymcu.forest.entity.User; import com.rymcu.forest.enumerate.TransactionCode; import com.rymcu.forest.enumerate.TransactionEnum; import com.rymcu.forest.mapper.TransactionRecordMapper; import com.rymcu.forest.service.BankAccountService; import com.rymcu.forest.service.TransactionRecordService; import com.rymcu.forest.util.DateUtil; +import com.rymcu.forest.util.UserUtils; +import com.rymcu.forest.web.api.exception.BaseApiException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -56,7 +60,17 @@ public class TransactionRecordServiceImpl extends AbstractService findTransactionRecords(String bankAccount) { - return transactionRecordMapper.selectTransactionRecords(bankAccount); + List list = transactionRecordMapper.selectTransactionRecords(bankAccount); + list.forEach(transactionRecordDTO -> genTransactionRecord(transactionRecordDTO)); + return list; + } + + private TransactionRecordDTO genTransactionRecord(TransactionRecordDTO transactionRecordDTO) { + BankAccountDTO toBankAccount = bankAccountService.findByBankAccount(transactionRecordDTO.getToBankAccount()); + BankAccountDTO formBankAccount = bankAccountService.findByBankAccount(transactionRecordDTO.getFormBankAccount()); + transactionRecordDTO.setFormBankAccountInfo(formBankAccount); + transactionRecordDTO.setToBankAccountInfo(toBankAccount); + return transactionRecordDTO; } @Override @@ -122,7 +136,7 @@ public class TransactionRecordServiceImpl extends AbstractService 0) { return true; diff --git a/src/main/java/mapper/BankAccountMapper.xml b/src/main/java/mapper/BankAccountMapper.xml index 2cc2765..ff935f7 100644 --- a/src/main/java/mapper/BankAccountMapper.xml +++ b/src/main/java/mapper/BankAccountMapper.xml @@ -12,24 +12,30 @@ + \ No newline at end of file diff --git a/src/main/java/mapper/TransactionRecordMapper.xml b/src/main/java/mapper/TransactionRecordMapper.xml index effeafe..0ae14b6 100644 --- a/src/main/java/mapper/TransactionRecordMapper.xml +++ b/src/main/java/mapper/TransactionRecordMapper.xml @@ -16,7 +16,7 @@ update forest_bank_account set account_balance = account_balance + #{money} where bank_account = #{toBankAccount};