1
zyy
2 days ago a8e2dbcd82859a3f972192c60b95cba4defe1738
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package com.yami.trading.api.controller;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yami.trading.bean.item.domain.Item;
import com.yami.trading.bean.model.MoneyLog;
import com.yami.trading.common.constants.Constants;
import com.yami.trading.common.domain.Result;
import com.yami.trading.common.util.DateTimeTools;
import com.yami.trading.common.util.DateUtils;
import com.yami.trading.common.util.StringUtils;
import com.yami.trading.security.common.util.SecurityUtils;
import com.yami.trading.service.MoneyLogService;
import com.yami.trading.service.item.ItemService;
import com.yami.trading.service.user.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
 
@RestController
@CrossOrigin
@Slf4j
public class ApiMoneyLogController {
    @Autowired
    MoneyLogService moneyLogService;
    @Autowired
    UserService userService;
    @Autowired
    ItemService itemService;
 
    @RequestMapping("api/moneylog!list.action")
    public Result list(HttpServletRequest request) throws IOException {
        String partyId = SecurityUtils.getUser().getUserId();
        String page_no = request.getParameter("page_no");
        String symbolType = request.getParameter("symbolType");
        if (StringUtils.isNullOrEmpty(page_no)
                || !StringUtils.isInteger(page_no) || Integer.valueOf(page_no) <= 0) {
            page_no = "1";
        }
        double amount = 0;
        int pageNo = Integer.valueOf(page_no);
        String category = request.getParameter("category");
        String contentType = request.getParameter("contentType");
        if (symbolType==null){
            symbolType="";
        }
        List<String> symbols = itemService.findByType(symbolType).stream().map(Item::getSymbol).collect(Collectors.toList());
        symbols.add("-1");
        Page<MoneyLog> page = new Page<>(pageNo, 20);
        LambdaQueryWrapper<MoneyLog> lambdaQueryWrapper = Wrappers.<MoneyLog>query().lambda().eq(MoneyLog::getUserId, partyId);
        // 不显示不可见的
        lambdaQueryWrapper.ne(MoneyLog::getShow, "0");
        if (StringUtils.isNotEmpty(category)){
            if(category.equals(Constants.MONEYLOG_CATEGORY_EXCHANGE)){
                lambdaQueryWrapper.and((wrapper)->{
                    wrapper.eq(MoneyLog::getCategory, category)
                            .or().eq(MoneyLog::getCategory, Item.forex)
                            .or().eq(MoneyLog::getCategory, Item.indices)
                            .or().eq(MoneyLog::getCategory, Item.commodities)
                            .or().eq(MoneyLog::getCategory, Item.cryptos)
                            .or().eq(MoneyLog::getCategory, Item.US_STOCKS)
                            .or().eq(MoneyLog::getCategory, Item.HK_STOCKS)
                            .or().eq(MoneyLog::getCategory, Item.SG_STOCKS)
                            .or().eq(MoneyLog::getCategory, Item.UK_STOCKS)
                            .or().eq(MoneyLog::getCategory, Item.TW_STOCKS)
                            .or().eq(MoneyLog::getCategory, Item.A_STOCKS)
                            .or().eq(MoneyLog::getCategory, Item.JP_STOCKS)
                            .or().eq(MoneyLog::getCategory, Item.INDIA_STOCKS)
                            .or().eq(MoneyLog::getCategory, Item.DE_STOCKS)
                            .or().eq(MoneyLog::getCategory, Item.BZ_STOCKS)
                            .or().eq(MoneyLog::getCategory, Item.INDIA_STOCKS)
                            .or().eq(MoneyLog::getCategory, Item.INDIA_STOCKS)
                            .or().eq(MoneyLog::getCategory, Item.CATEGORY_GLOBAL)
                            .or().eq(MoneyLog::getCategory, Item.CATEGORY_GOLD)
                            .or().eq(MoneyLog::getCategory, Item.CATEGORY_AI)
                            .or().eq(MoneyLog::getCategory, Item.CATEGORY_ENERGY)
                            .or().eq(MoneyLog::getCategory, Item.CAD_STOCKS)
                            .or().eq(MoneyLog::getCategory, Item.FR_STOCKS)
                    ;
                });
            }else{
                lambdaQueryWrapper.eq(MoneyLog::getCategory, category);
            }
        }
 
        if (StringUtils.isNotEmpty(contentType)){
            if(contentType.equals(Constants.MONEYLOG_CATEGORY_RECHARGE)){
                lambdaQueryWrapper.and((wrapper)->{
                    wrapper.eq(MoneyLog::getContentType, contentType).or().eq(MoneyLog::getContentType, Constants.MONEYLOG_CATEGORY_BANK_CARD_RECHARGE);
                });
            }else if(contentType.equals(Constants.MONEYLOG_CATEGORY_WITHDRAW)){
                lambdaQueryWrapper.and((wrapper)->{
                    wrapper.eq(MoneyLog::getContentType, contentType).or().eq(MoneyLog::getContentType, Constants.MONEYLOG_CATEGORY_BANK_CARD_WITHDRAW);
                });
            }else{
                lambdaQueryWrapper.eq(MoneyLog::getContentType, contentType);
            }
        }
        if (StringUtils.isNotEmpty(symbolType)){
            lambdaQueryWrapper.in(MoneyLog::getSymbol,symbols);
        }
        lambdaQueryWrapper.orderByDesc(MoneyLog::getCreateTime);
        moneyLogService.page(page, lambdaQueryWrapper);
        for (MoneyLog log : page.getRecords()) {
            log.setContent_type(log.getContentType());
            log.setWallet_type(log.getWalletType());
            log.setAmount_after(log.getAmountAfter().setScale(4, RoundingMode.FLOOR));
            log.setAmount_before(log.getAmountBefore().setScale(4, RoundingMode.FLOOR));
            log.setAmountAfter(log.getAmountAfter().setScale(4, RoundingMode.FLOOR));
            log.setAmountBefore(log.getAmountBefore().setScale(4, RoundingMode.FLOOR));
            if (Constants.MONEYLOG_CONTENT_FINANCE_PROFIT.equals(log.getContentType())) {
                log.setAmount(log.getAmount().add(new BigDecimal(amount)).setScale(4, RoundingMode.FLOOR));
 
                // 时区转换
                Date showCreateTime = DateTimeTools.transferToShowTime(log.getCreateTime());
                log.setCreateTimeStr(DateUtils.format(showCreateTime, DateUtils.DF_yyyyMMddHHmmss));
            }
        }
 
        return Result.succeed(page.getRecords());
    }
 
}