|
|
@@ -1,172 +1,214 @@
|
|
|
package com.txz.cif.web;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
-import cn.hutool.core.util.StrUtil;
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
import com.txz.cif.core.*;
|
|
|
import com.txz.cif.model.Account;
|
|
|
import com.txz.cif.model.AccountFlow;
|
|
|
+import com.txz.cif.model.AccountFreezd;
|
|
|
import com.txz.cif.model.User;
|
|
|
-import com.txz.cif.service.AccountFlowService;
|
|
|
-import com.txz.cif.service.AccountService;
|
|
|
-import com.txz.cif.service.RedEnvelopeService;
|
|
|
-import com.txz.cif.service.UserService;
|
|
|
-import com.txz.cif.web.bo.*;
|
|
|
+import com.txz.cif.service.*;
|
|
|
+import com.txz.cif.web.bo.AccountFlowBO;
|
|
|
+import com.txz.cif.web.bo.AccountInfoBO;
|
|
|
+import com.txz.cif.web.bo.AccountWalletInfoBO;
|
|
|
import com.txz.cif.web.para.AccountFlowParam;
|
|
|
-
|
|
|
-import com.github.pagehelper.PageHelper;
|
|
|
-import com.github.pagehelper.PageInfo;
|
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
+import com.txz.cif.web.vo.AccountFreezdVO;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
-
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
import tk.mybatis.mapper.entity.Condition;
|
|
|
import tk.mybatis.mapper.entity.Example.Criteria;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
/**
|
|
|
-* Created by CodeGenerator on 2022/11/16.
|
|
|
-*/
|
|
|
+ * Created by CodeGenerator on 2022/11/16.
|
|
|
+ */
|
|
|
@Api(tags = "[api]结算管理")
|
|
|
@RestController
|
|
|
@RequestMapping("/account/api")
|
|
|
public class AccountApiController extends AbstractApiController {
|
|
|
-
|
|
|
- private static Logger log = LoggerFactory.getLogger(AccountApiController.class);
|
|
|
-
|
|
|
+
|
|
|
+ private static Logger log = LoggerFactory.getLogger(AccountApiController.class);
|
|
|
+
|
|
|
@Resource
|
|
|
private AccountFlowService accountFlowService;
|
|
|
-
|
|
|
- @Resource
|
|
|
- private AccountService accountService;
|
|
|
-
|
|
|
- @Resource
|
|
|
- private RedEnvelopeService redEnvelopeService;
|
|
|
-
|
|
|
-
|
|
|
- @Resource
|
|
|
- private UserService userService;
|
|
|
- @Resource
|
|
|
- private AuthService authService;
|
|
|
-
|
|
|
- @ApiOperation(value = "查询收益账号信息", notes = "",httpMethod = "GET")
|
|
|
- @GetMapping("/getAccountInfo")
|
|
|
- public Result<AccountInfoBO> getAccountInfo(HttpServletRequest request) {
|
|
|
- Long userId = authService.getTokenUserId(request);
|
|
|
- if (userId == null ){
|
|
|
- return ResultGenerator.genFailResult(ResultCode.OAUTH_INVALID_ACCESS_TOKEN);
|
|
|
- }
|
|
|
- User user = userService.findById(userId);
|
|
|
- if (user == null ){
|
|
|
- return ResultGenerator.genFailResult(ResultCode.USER_IS_NULL);
|
|
|
-
|
|
|
- }
|
|
|
- Account earnings = accountService.getAccount(userId, 2);
|
|
|
- AccountInfoBO bo = new AccountInfoBO();
|
|
|
- bo.setBalance(earnings.getBalance());
|
|
|
- bo.setSettledAmount(earnings.getTotalInamount());
|
|
|
- BigDecimal pendingAmount = redEnvelopeService.sumWithDay(null,userId,1);
|
|
|
- if (pendingAmount == null){
|
|
|
- pendingAmount = BigDecimal.ZERO;
|
|
|
- }
|
|
|
- bo.setPendingAmount(pendingAmount);
|
|
|
-
|
|
|
- BigDecimal tDEamings = redEnvelopeService.sumWithDay(DateUtil.today(),userId,null);
|
|
|
- if (tDEamings == null){
|
|
|
- tDEamings = BigDecimal.ZERO;
|
|
|
- }
|
|
|
- bo.setTDEamings(tDEamings);
|
|
|
- BigDecimal yDEamings = redEnvelopeService.sumWithDay(DateUtil.yesterday().toDateStr(),userId,null);
|
|
|
- if (yDEamings == null){
|
|
|
- yDEamings = BigDecimal.ZERO;
|
|
|
- }
|
|
|
- bo.setYDEamings(yDEamings.subtract(tDEamings));
|
|
|
- BigDecimal mTDEamings = redEnvelopeService.sumWithDay(DateUtil.beginOfMonth(DateUtil.date()).toDateStr(),userId,null);
|
|
|
- if (mTDEamings == null){
|
|
|
- mTDEamings = BigDecimal.ZERO;
|
|
|
- }
|
|
|
- bo.setMTDEamings(mTDEamings);
|
|
|
- BigDecimal settleAmount = redEnvelopeService.sumWithDay(null,userId,2);
|
|
|
- if (settleAmount == null){
|
|
|
- settleAmount = BigDecimal.ZERO;
|
|
|
- }
|
|
|
- bo.setSettledAmount(settleAmount);
|
|
|
- BigDecimal totalEarnings = settleAmount.add(pendingAmount);
|
|
|
- bo.setTotalEarnings(totalEarnings);
|
|
|
- return ResultGenerator.genSuccessResult(bo);
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "查询钱包账号信息", notes = "",httpMethod = "GET")
|
|
|
- @GetMapping("/getWalletAccountInfo")
|
|
|
- public Result<AccountWalletInfoBO> getWalletAccountInfo(HttpServletRequest request) {
|
|
|
- Long userId = authService.getTokenUserId(request);
|
|
|
- if (userId == null ){
|
|
|
- return ResultGenerator.genFailResult(ResultCode.OAUTH_INVALID_ACCESS_TOKEN);
|
|
|
- }
|
|
|
- User user = userService.findById(userId);
|
|
|
- if (user == null ){
|
|
|
- return ResultGenerator.genFailResult(ResultCode.USER_IS_NULL);
|
|
|
- }
|
|
|
- Account wallet = accountService.getAccount(userId, 1);
|
|
|
- AccountWalletInfoBO bo = new AccountWalletInfoBO();
|
|
|
- bo.setBalance(wallet.getBalance());
|
|
|
- bo.setFreezeAmount(wallet.getFreezeAmount());
|
|
|
- return ResultGenerator.genSuccessResult(bo);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @PostMapping("/accountFlowList")
|
|
|
- @ApiOperation(value = "出入流水",httpMethod = "POST")
|
|
|
- public Result<AccountFlowBO> accountFlowList(@RequestBody AccountFlowParam param,HttpServletRequest request) {
|
|
|
- Long userId = authService.getTokenUserId(request);
|
|
|
- if (userId == null ){
|
|
|
- return ResultGenerator.genFailResult(ResultCode.OAUTH_INVALID_ACCESS_TOKEN);
|
|
|
- }
|
|
|
- User user = userService.findById(userId);
|
|
|
- if (user == null){
|
|
|
- return ResultGenerator.genFailResult(ResultCode.USER_IS_NULL);
|
|
|
- }
|
|
|
- Account account = accountService.getAccount(userId, 1);
|
|
|
- if (account == null){
|
|
|
- return ResultGenerator.genFailResult(ResultCode.ACCOUNT_IS_NULL);
|
|
|
- }
|
|
|
- PageHelper.startPage(param.getPage(), param.getSize());
|
|
|
- Condition c = new Condition(AccountFlow.class);
|
|
|
- Criteria criteria = c.createCriteria().andEqualTo("accountId",account.getId());
|
|
|
- if (param.getType() == 1 ){
|
|
|
- criteria.andGreaterThanOrEqualTo("createTime", DateUtil.today());
|
|
|
- } else if (param.getType() == 2){
|
|
|
- Date yesterdayStart = DateUtil.beginOfDay(DateUtil.yesterday());
|
|
|
- Date todayStart = DateUtil.beginOfDay(DateUtil.date());
|
|
|
- criteria.andBetween("createTime", yesterdayStart,todayStart);
|
|
|
- } else if (param.getType() == 3){
|
|
|
- Date start = DateUtil.beginOfDay(DateUtil.offsetDay(DateUtil.date(),-7));
|
|
|
- criteria.andGreaterThanOrEqualTo("createTime",start);
|
|
|
- } else if (param.getType() == 4){
|
|
|
- Date start = DateUtil.beginOfMonth(DateUtil.date());
|
|
|
- criteria.andGreaterThanOrEqualTo("createTime",start);
|
|
|
- } else if (param.getType() == 5){
|
|
|
- Date start = DateUtil.beginOfYear(DateUtil.date());
|
|
|
- criteria.andGreaterThanOrEqualTo("createTime",start);
|
|
|
- }
|
|
|
- c.setOrderByClause("create_time desc");
|
|
|
- List<AccountFlow> flows = accountFlowService.findByCondition(c);
|
|
|
- PageInfo pageInfo = new PageInfo(flows);
|
|
|
- List<AccountFlowBO> bos = flows.stream().map(temp -> {
|
|
|
- AccountFlowBO bo = temp.generator();
|
|
|
- if (account != null){
|
|
|
- bo.setAccountName(account.getName());
|
|
|
- }
|
|
|
- return bo;
|
|
|
- }).collect(Collectors.toList());
|
|
|
- pageInfo.setList(bos);
|
|
|
- return ResultGenerator.genSuccessResult(pageInfo);
|
|
|
- }
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private AccountService accountService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private RedEnvelopeService redEnvelopeService;
|
|
|
+
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private UserService userService;
|
|
|
+ @Resource
|
|
|
+ private AuthService authService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private AccountFreezdService accountFreezdService;
|
|
|
+
|
|
|
+ @ApiOperation(value = "查询收益账号信息", notes = "", httpMethod = "GET")
|
|
|
+ @GetMapping("/getAccountInfo")
|
|
|
+ public Result<AccountInfoBO> getAccountInfo(HttpServletRequest request) {
|
|
|
+ Long userId = authService.getTokenUserId(request);
|
|
|
+ if (userId == null) {
|
|
|
+ return ResultGenerator.genFailResult(ResultCode.OAUTH_INVALID_ACCESS_TOKEN);
|
|
|
+ }
|
|
|
+ User user = userService.findById(userId);
|
|
|
+ if (user == null) {
|
|
|
+ return ResultGenerator.genFailResult(ResultCode.USER_IS_NULL);
|
|
|
+
|
|
|
+ }
|
|
|
+ Account earnings = accountService.getAccount(userId, 2);
|
|
|
+ AccountInfoBO bo = new AccountInfoBO();
|
|
|
+ bo.setBalance(earnings.getBalance());
|
|
|
+ bo.setSettledAmount(earnings.getTotalInamount());
|
|
|
+ BigDecimal pendingAmount = redEnvelopeService.sumWithDay(null, userId, 1);
|
|
|
+ if (pendingAmount == null) {
|
|
|
+ pendingAmount = BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ bo.setPendingAmount(pendingAmount);
|
|
|
+
|
|
|
+ BigDecimal tDEamings = redEnvelopeService.sumWithDay(DateUtil.today(), userId, null);
|
|
|
+ if (tDEamings == null) {
|
|
|
+ tDEamings = BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ bo.setTDEamings(tDEamings);
|
|
|
+ BigDecimal yDEamings = redEnvelopeService.sumWithDay(DateUtil.yesterday().toDateStr(), userId, null);
|
|
|
+ if (yDEamings == null) {
|
|
|
+ yDEamings = BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ bo.setYDEamings(yDEamings.subtract(tDEamings));
|
|
|
+ BigDecimal mTDEamings = redEnvelopeService.sumWithDay(DateUtil.beginOfMonth(DateUtil.date()).toDateStr(), userId, null);
|
|
|
+ if (mTDEamings == null) {
|
|
|
+ mTDEamings = BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ bo.setMTDEamings(mTDEamings);
|
|
|
+ BigDecimal settleAmount = redEnvelopeService.sumWithDay(null, userId, 2);
|
|
|
+ if (settleAmount == null) {
|
|
|
+ settleAmount = BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ bo.setSettledAmount(settleAmount);
|
|
|
+ BigDecimal totalEarnings = settleAmount.add(pendingAmount);
|
|
|
+ bo.setTotalEarnings(totalEarnings);
|
|
|
+ return ResultGenerator.genSuccessResult(bo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "查询钱包账号信息", notes = "", httpMethod = "GET")
|
|
|
+ @GetMapping("/getWalletAccountInfo")
|
|
|
+ public Result<AccountWalletInfoBO> getWalletAccountInfo(HttpServletRequest request) {
|
|
|
+ Long userId = authService.getTokenUserId(request);
|
|
|
+ if (userId == null) {
|
|
|
+ return ResultGenerator.genFailResult(ResultCode.OAUTH_INVALID_ACCESS_TOKEN);
|
|
|
+ }
|
|
|
+ User user = userService.findById(userId);
|
|
|
+ if (user == null) {
|
|
|
+ return ResultGenerator.genFailResult(ResultCode.USER_IS_NULL);
|
|
|
+ }
|
|
|
+ Account wallet = accountService.getAccount(userId, 1);
|
|
|
+ AccountWalletInfoBO bo = new AccountWalletInfoBO();
|
|
|
+ bo.setBalance(wallet.getBalance());
|
|
|
+ bo.setFreezeAmount(wallet.getFreezeAmount());
|
|
|
+ bo.setAvailableAmount(wallet.getBalance().subtract(wallet.getFreezeAmount()));
|
|
|
+ return ResultGenerator.genSuccessResult(bo);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 冻结列表
|
|
|
+ */
|
|
|
+ @GetMapping("getFreeds")
|
|
|
+ public Result<PageInfo<List<AccountFreezdVO>>> getFreeds(AccountFlowParam param, HttpServletRequest request) {
|
|
|
+ Long userId = authService.getTokenUserId(request);
|
|
|
+ if (userId == null) {
|
|
|
+ return ResultGenerator.genFailResult(ResultCode.OAUTH_INVALID_ACCESS_TOKEN);
|
|
|
+ }
|
|
|
+ PageHelper.startPage(param.getPage(), param.getSize());
|
|
|
+
|
|
|
+ Condition c = new Condition(AccountFreezd.class);
|
|
|
+ c.createCriteria()
|
|
|
+ .andIn("status", CollUtil.newArrayList(1, 2))
|
|
|
+ .andEqualTo("userId", userId)
|
|
|
+ ;
|
|
|
+ c.setOrderByClause("create_time desc");
|
|
|
+ List<AccountFreezd> accountFreezds = accountFreezdService.findByCondition(c);
|
|
|
+ if (CollectionUtil.isEmpty(accountFreezds)) {
|
|
|
+ return ResultGenerator.genSuccessResult(new PageInfo());
|
|
|
+ }
|
|
|
+ PageInfo pageInfo = new PageInfo(accountFreezds);
|
|
|
+
|
|
|
+ List<AccountFreezd> list = pageInfo.getList();
|
|
|
+
|
|
|
+ List<AccountFreezdVO> result = new ArrayList<>();
|
|
|
+ for (AccountFreezd accountFreezd : list) {
|
|
|
+ AccountFreezdVO freezdVO = BeanUtil.copyProperties(accountFreezd, AccountFreezdVO.class);
|
|
|
+ freezdVO.setFreezeAmount(freezdVO.getAmount().subtract(freezdVO.getUnfreezeAmount()));
|
|
|
+ result.add(freezdVO);
|
|
|
+ }
|
|
|
+ pageInfo.setList(result);
|
|
|
+ return ResultGenerator.genSuccessResult(pageInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @PostMapping("/accountFlowList")
|
|
|
+ @ApiOperation(value = "出入流水", httpMethod = "POST")
|
|
|
+ public Result<AccountFlowBO> accountFlowList(@RequestBody AccountFlowParam param, HttpServletRequest request) {
|
|
|
+ Long userId = authService.getTokenUserId(request);
|
|
|
+ if (userId == null) {
|
|
|
+ return ResultGenerator.genFailResult(ResultCode.OAUTH_INVALID_ACCESS_TOKEN);
|
|
|
+ }
|
|
|
+ User user = userService.findById(userId);
|
|
|
+ if (user == null) {
|
|
|
+ return ResultGenerator.genFailResult(ResultCode.USER_IS_NULL);
|
|
|
+ }
|
|
|
+ Account account = accountService.getAccount(userId, 1);
|
|
|
+ if (account == null) {
|
|
|
+ return ResultGenerator.genFailResult(ResultCode.ACCOUNT_IS_NULL);
|
|
|
+ }
|
|
|
+ PageHelper.startPage(param.getPage(), param.getSize());
|
|
|
+ Condition c = new Condition(AccountFlow.class);
|
|
|
+ Criteria criteria = c.createCriteria().andEqualTo("accountId", account.getId());
|
|
|
+ if (param.getType() == 1) {
|
|
|
+ criteria.andGreaterThanOrEqualTo("createTime", DateUtil.today());
|
|
|
+ } else if (param.getType() == 2) {
|
|
|
+ Date yesterdayStart = DateUtil.beginOfDay(DateUtil.yesterday());
|
|
|
+ Date todayStart = DateUtil.beginOfDay(DateUtil.date());
|
|
|
+ criteria.andBetween("createTime", yesterdayStart, todayStart);
|
|
|
+ } else if (param.getType() == 3) {
|
|
|
+ Date start = DateUtil.beginOfDay(DateUtil.offsetDay(DateUtil.date(), -7));
|
|
|
+ criteria.andGreaterThanOrEqualTo("createTime", start);
|
|
|
+ } else if (param.getType() == 4) {
|
|
|
+ Date start = DateUtil.beginOfMonth(DateUtil.date());
|
|
|
+ criteria.andGreaterThanOrEqualTo("createTime", start);
|
|
|
+ } else if (param.getType() == 5) {
|
|
|
+ Date start = DateUtil.beginOfYear(DateUtil.date());
|
|
|
+ criteria.andGreaterThanOrEqualTo("createTime", start);
|
|
|
+ }
|
|
|
+ c.setOrderByClause("create_time desc");
|
|
|
+ List<AccountFlow> flows = accountFlowService.findByCondition(c);
|
|
|
+ PageInfo pageInfo = new PageInfo(flows);
|
|
|
+ List<AccountFlowBO> bos = flows.stream().map(temp -> {
|
|
|
+ AccountFlowBO bo = temp.generator();
|
|
|
+ if (account != null) {
|
|
|
+ bo.setAccountName(account.getName());
|
|
|
+ }
|
|
|
+ return bo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ pageInfo.setList(bos);
|
|
|
+ return ResultGenerator.genSuccessResult(pageInfo);
|
|
|
+ }
|
|
|
}
|