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/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/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..fd399ab 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,16 +4,15 @@ 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.dto.TransactionRecordDTO; import com.rymcu.forest.service.BankAccountService; -import com.rymcu.forest.service.BankService; +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; @@ -49,4 +48,19 @@ public class BankAccountController { return GlobalResultGenerator.genSuccessResult(bankAccount); } + @GetMapping("/transaction-records") + public GlobalResult transactionRecords(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "20") Integer rows, HttpServletRequest request) { + String bankAccount = request.getParameter("bankAccount"); + String startDate = request.getParameter("startDate"); + String endDate = request.getParameter("endDate"); + PageHelper.startPage(page, rows); + List list = bankAccountService.findUserTransactionRecords(bankAccount, 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/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..44cb23c 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,21 @@ 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/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); 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};