From 568d14d4138dd0d345a25db5c654a2b8c6f14185 Mon Sep 17 00:00:00 2001 From: ronger Date: Fri, 24 Dec 2021 20:58:20 +0800 Subject: [PATCH 1/4] =?UTF-8?q?:art:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../forest/service/impl/NotificationServiceImpl.java | 7 +++---- .../web/api/notification/NotificationController.java | 8 ++++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/rymcu/forest/service/impl/NotificationServiceImpl.java b/src/main/java/com/rymcu/forest/service/impl/NotificationServiceImpl.java index 22b22d1..b571e6f 100644 --- a/src/main/java/com/rymcu/forest/service/impl/NotificationServiceImpl.java +++ b/src/main/java/com/rymcu/forest/service/impl/NotificationServiceImpl.java @@ -23,12 +23,11 @@ public class NotificationServiceImpl extends AbstractService imple @Resource private NotificationMapper notificationMapper; - private final static String unRead = "0"; + private final static String UN_READ = "0"; @Override public List findUnreadNotifications(Integer idUser) { - List list = notificationMapper.selectUnreadNotifications(idUser); - return list; + return notificationMapper.selectUnreadNotifications(idUser); } @Override @@ -41,7 +40,7 @@ public class NotificationServiceImpl extends AbstractService imple BeanCopierUtil.copy(notificationDTO, notification); } else { // 关联数据已删除,且未读 - if (unRead.equals(notification.getHasRead())) { + if (UN_READ.equals(notification.getHasRead())) { notificationMapper.readNotification(notification.getIdNotification()); } NotificationDTO dto = new NotificationDTO(); diff --git a/src/main/java/com/rymcu/forest/web/api/notification/NotificationController.java b/src/main/java/com/rymcu/forest/web/api/notification/NotificationController.java index e4509f1..42c5072 100644 --- a/src/main/java/com/rymcu/forest/web/api/notification/NotificationController.java +++ b/src/main/java/com/rymcu/forest/web/api/notification/NotificationController.java @@ -11,11 +11,13 @@ import com.rymcu.forest.service.NotificationService; import com.rymcu.forest.util.UserUtils; import com.rymcu.forest.util.Utils; import com.rymcu.forest.web.api.exception.BaseApiException; +import com.rymcu.forest.web.api.exception.ErrorCode; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.List; import java.util.Map; +import java.util.Objects; /** * 消息通知 @@ -31,6 +33,9 @@ public class NotificationController { @GetMapping("/all") public GlobalResult notifications(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows) throws BaseApiException { User user = UserUtils.getCurrentUserByToken(); + if (Objects.isNull(user)) { + throw new BaseApiException(ErrorCode.TOKEN_); + } PageHelper.startPage(page, rows); List list = notificationService.findNotifications(user.getIdUser()); PageInfo pageInfo = new PageInfo(list); @@ -41,6 +46,9 @@ public class NotificationController { @GetMapping("/unread") public GlobalResult unreadNotification(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows) throws BaseApiException { User user = UserUtils.getCurrentUserByToken(); + if (Objects.isNull(user)) { + throw new BaseApiException(ErrorCode.TOKEN_); + } PageHelper.startPage(page, rows); List list = notificationService.findUnreadNotifications(user.getIdUser()); PageInfo pageInfo = new PageInfo(list); From 64f16f701519ebfe32fdf1a3febdb534828a93d1 Mon Sep 17 00:00:00 2001 From: ronger Date: Tue, 28 Dec 2021 22:32:37 +0800 Subject: [PATCH 2/4] =?UTF-8?q?:sparkles:=20=E6=88=91=E7=9A=84=E9=92=B1?= =?UTF-8?q?=E5=8C=85-=E4=BA=A4=E6=98=93=E8=AE=B0=E5=BD=95=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=97=B6=E9=97=B4=E6=AE=B5=E6=A3=80=E7=B4=A2=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapper/TransactionRecordMapper.java | 4 ++- .../forest/service/BankAccountService.java | 4 ++- .../service/TransactionRecordService.java | 5 +-- .../service/impl/BankAccountServiceImpl.java | 18 +++++++++-- .../impl/TransactionRecordServiceImpl.java | 8 ++--- .../web/api/bank/BankAccountController.java | 4 --- .../forest/web/api/bank/BankController.java | 5 +-- .../forest/web/api/bank/WalletController.java | 31 ++++++++++++++++--- .../java/mapper/TransactionRecordMapper.xml | 5 ++- 9 files changed, 58 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/rymcu/forest/mapper/TransactionRecordMapper.java b/src/main/java/com/rymcu/forest/mapper/TransactionRecordMapper.java index 75c1b3f..065efe7 100644 --- a/src/main/java/com/rymcu/forest/mapper/TransactionRecordMapper.java +++ b/src/main/java/com/rymcu/forest/mapper/TransactionRecordMapper.java @@ -24,9 +24,11 @@ public interface TransactionRecordMapper extends Mapper { /** * 查询指定账户的交易记录 * @param bankAccount + * @param startDate + * @param endDate * @return */ - List selectTransactionRecords(@Param("bankAccount") String bankAccount); + List selectTransactionRecords(@Param("bankAccount") String bankAccount, @Param("startDate") String startDate, @Param("endDate") String endDate); /** * 校验今日是否已发放答题奖励 diff --git a/src/main/java/com/rymcu/forest/service/BankAccountService.java b/src/main/java/com/rymcu/forest/service/BankAccountService.java index d7e2d10..1794336 100644 --- a/src/main/java/com/rymcu/forest/service/BankAccountService.java +++ b/src/main/java/com/rymcu/forest/service/BankAccountService.java @@ -3,8 +3,8 @@ package com.rymcu.forest.service; import com.rymcu.forest.core.service.Service; 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 org.apache.ibatis.annotations.Param; import java.util.List; @@ -45,4 +45,6 @@ public interface BankAccountService extends Service { * @return */ BankAccount findInfoByBankAccount(String formBankAccount); + + List findUserTransactionRecords(String bankAccount, String startDate, String endDate); } diff --git a/src/main/java/com/rymcu/forest/service/TransactionRecordService.java b/src/main/java/com/rymcu/forest/service/TransactionRecordService.java index 2f0acdd..28e406a 100644 --- a/src/main/java/com/rymcu/forest/service/TransactionRecordService.java +++ b/src/main/java/com/rymcu/forest/service/TransactionRecordService.java @@ -5,7 +5,6 @@ import com.rymcu.forest.dto.TransactionRecordDTO; import com.rymcu.forest.entity.TransactionRecord; import com.rymcu.forest.enumerate.TransactionEnum; -import java.math.BigDecimal; import java.util.List; /** @@ -23,9 +22,11 @@ public interface TransactionRecordService extends Service { /** * 查询指定账户的交易记录 * @param bankAccount + * @param startDate + * @param endDate * @return */ - List findTransactionRecords(String bankAccount); + List findTransactionRecords(String bankAccount, String startDate, String endDate); /** * 根据用户主键进行交易 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 da34cca..0c96c82 100644 --- a/src/main/java/com/rymcu/forest/service/impl/BankAccountServiceImpl.java +++ b/src/main/java/com/rymcu/forest/service/impl/BankAccountServiceImpl.java @@ -1,5 +1,6 @@ package com.rymcu.forest.service.impl; +import cn.hutool.core.date.LocalDateTimeUtil; import com.rymcu.forest.core.service.AbstractService; import com.rymcu.forest.dto.BankAccountDTO; import com.rymcu.forest.dto.BankAccountSearchDTO; @@ -13,6 +14,8 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; import java.util.Date; import java.util.List; import java.util.Objects; @@ -54,12 +57,21 @@ public class BankAccountServiceImpl extends AbstractService impleme bankAccountMapper.insertSelective(bankAccount); bankAccountDTO = bankAccountMapper.selectBankAccount(bankAccount.getIdBankAccount()); } - // 查询交易记录 - List records = transactionRecordService.findTransactionRecords(bankAccountDTO.getBankAccount()); - bankAccountDTO.setTransactionRecords(records); return bankAccountDTO; } + @Override + public List findUserTransactionRecords(String bankAccount, String startDate, String endDate) { + if (StringUtils.isBlank(startDate)) { + LocalDateTime now = LocalDateTime.now(); + endDate = LocalDateTimeUtil.format(now, "yyyy-MM-dd"); + startDate = LocalDateTimeUtil.format(now.minus(30, ChronoUnit.DAYS), "yyyy-MM-dd"); + } + // 查询交易记录 + List records = transactionRecordService.findTransactionRecords(bankAccount, startDate, endDate); + return records; + } + @Override public BankAccountDTO findByBankAccount(String bankAccount) { return bankAccountMapper.selectByBankAccount(bankAccount); 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 c0a2167..7298956 100644 --- a/src/main/java/com/rymcu/forest/service/impl/TransactionRecordServiceImpl.java +++ b/src/main/java/com/rymcu/forest/service/impl/TransactionRecordServiceImpl.java @@ -4,19 +4,15 @@ 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; @@ -59,8 +55,8 @@ public class TransactionRecordServiceImpl extends AbstractService findTransactionRecords(String bankAccount) { - List list = transactionRecordMapper.selectTransactionRecords(bankAccount); + public List findTransactionRecords(String bankAccount, String startDate, String endDate) { + List list = transactionRecordMapper.selectTransactionRecords(bankAccount, startDate, endDate); list.forEach(transactionRecordDTO -> genTransactionRecord(transactionRecordDTO)); return list; } diff --git a/src/main/java/com/rymcu/forest/web/api/bank/BankAccountController.java b/src/main/java/com/rymcu/forest/web/api/bank/BankAccountController.java index acfacbf..ab81e25 100644 --- a/src/main/java/com/rymcu/forest/web/api/bank/BankAccountController.java +++ b/src/main/java/com/rymcu/forest/web/api/bank/BankAccountController.java @@ -4,13 +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.BankAccountDTO; import com.rymcu.forest.dto.BankAccountSearchDTO; -import com.rymcu.forest.entity.Bank; -import com.rymcu.forest.entity.BankAccount; import com.rymcu.forest.service.BankAccountService; -import com.rymcu.forest.service.BankService; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; diff --git a/src/main/java/com/rymcu/forest/web/api/bank/BankController.java b/src/main/java/com/rymcu/forest/web/api/bank/BankController.java index 6dda2de..f155982 100644 --- a/src/main/java/com/rymcu/forest/web/api/bank/BankController.java +++ b/src/main/java/com/rymcu/forest/web/api/bank/BankController.java @@ -36,10 +36,7 @@ public class BankController { PageInfo pageInfo = new PageInfo(list); Map map = new HashMap(2); map.put("banks", pageInfo.getList()); - Map pagination = new HashMap(4); - pagination.put("pageSize", pageInfo.getPageSize()); - pagination.put("total", pageInfo.getTotal()); - pagination.put("currentPage", pageInfo.getPageNum()); + Map pagination = Utils.getPagination(pageInfo); map.put("pagination", pagination); return GlobalResultGenerator.genSuccessResult(map); } diff --git a/src/main/java/com/rymcu/forest/web/api/bank/WalletController.java b/src/main/java/com/rymcu/forest/web/api/bank/WalletController.java index d5d8372..965530e 100644 --- a/src/main/java/com/rymcu/forest/web/api/bank/WalletController.java +++ b/src/main/java/com/rymcu/forest/web/api/bank/WalletController.java @@ -1,16 +1,21 @@ package com.rymcu.forest.web.api.bank; +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.core.service.security.annotation.SecurityInterceptor; import com.rymcu.forest.dto.BankAccountDTO; +import com.rymcu.forest.dto.TransactionRecordDTO; import com.rymcu.forest.service.BankAccountService; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import com.rymcu.forest.util.Utils; +import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * Created on 2021/12/10 19:25. @@ -32,4 +37,22 @@ public class WalletController { BankAccountDTO bankAccount = bankAccountService.findBankAccountByIdUser(idUser); return GlobalResultGenerator.genSuccessResult(bankAccount); } + + + @GetMapping("/transaction-records") + @SecurityInterceptor + public GlobalResult transactionRecords(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "20") Integer rows, HttpServletRequest request) { + String idUser = request.getParameter("idUser"); + String startDate = request.getParameter("startDate"); + String endDate = request.getParameter("endDate"); + BankAccountDTO bankAccount = bankAccountService.findBankAccountByIdUser(Integer.valueOf(idUser)); + PageHelper.startPage(page, rows); + List list = bankAccountService.findUserTransactionRecords(bankAccount.getBankAccount(), startDate, endDate); + PageInfo pageInfo = new PageInfo(list); + Map map = new HashMap(2); + map.put("records", pageInfo.getList()); + Map pagination = Utils.getPagination(pageInfo); + map.put("pagination", pagination); + return GlobalResultGenerator.genSuccessResult(map); + } } diff --git a/src/main/java/mapper/TransactionRecordMapper.xml b/src/main/java/mapper/TransactionRecordMapper.xml index 0ae14b6..62df2f2 100644 --- a/src/main/java/mapper/TransactionRecordMapper.xml +++ b/src/main/java/mapper/TransactionRecordMapper.xml @@ -16,7 +16,10 @@ update forest_bank_account set account_balance = account_balance + #{money} where bank_account = #{toBankAccount};