zyy
2025-08-02 331800c37d20f0fb12513a8a4143b36c2e2764cb
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
package com.nq.controller.echo;
 
import com.nq.common.ServerResponse;
import com.nq.dao.EChoMapper;
import com.nq.enums.EStockType;
import com.nq.pojo.EChoBean;
import com.nq.pojo.User;
import com.nq.pojo.UserAssets;
import com.nq.service.IEchoServices;
import com.nq.service.IUserService;
import com.nq.service.impl.UserAssetsServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
 
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
 
/**
 * 利息报接口
 */
@Controller
@RequestMapping("/api/echo")
public class EChoController {
 
    @Autowired
    IEchoServices iEchoServices;
 
    @Autowired
    EChoMapper eChoMapper;
 
    @Autowired
    UserAssetsServices userAssetsServices;
 
    @Autowired
    IUserService iUserService;
 
    @PostMapping("queryEcho.do")
    @ResponseBody
    public ServerResponse queryEcho() {
        return ServerResponse.createBySuccess(iEchoServices.queryList());
    }
 
 
    @PostMapping("buyEcho.do")
    @ResponseBody
    public ServerResponse buyEcho(@RequestParam("eId") String eid, @RequestParam("money") BigDecimal money, HttpServletRequest request) {
        if(null == money || money.compareTo(BigDecimal.ZERO) <= 0){
            return ServerResponse.createByErrorMsg("金额不能小于0",request);
        }
        EChoBean eChoBean = eChoMapper.selectById(Integer.parseInt(eid));
        if (eChoBean == null) {
            return ServerResponse.createByErrorMsg("基金产品不存在",request);
        } else {
            if (null != eChoBean.getBuyLowestNum() && money.compareTo(new BigDecimal(eChoBean.getBuyLowestNum())) < 0) {
                return ServerResponse.createByErrorMsg("购买失败,最低购买数量:"+eChoBean.getBuyLowestNum(),request);
            }
        }
        User user = this.iUserService.getCurrentRefreshUser(request);
        UserAssets userAssets = userAssetsServices.assetsByTypeAndUserId(EStockType.MX.getCode(), user.getId());
        if(userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0){
            return ServerResponse.createByErrorMsg("请先缴清待补资金", request);
        }
        if(userAssets.getAvailableBalance().compareTo(money) < 0){
            return ServerResponse.createByErrorMsg("配资不足",request);
        }
        if (iEchoServices.buyECho(eid, money, userAssets.getAccectType(), request)) {
            return ServerResponse.createBySuccess("购买成功",request);
        } else {
            return ServerResponse.createByErrorMsg("购买失败",request);
        }
    }
 
 
    @PostMapping("queryOrderEcho.do")
    @ResponseBody
    public ServerResponse queryOrderEcho(HttpServletRequest request) {
        return ServerResponse.createBySuccess(iEchoServices.queryOrderEcho(request));
    }
 
    @PostMapping("queryOrderEchoPage.do")
    @ResponseBody
    public ServerResponse queryOrderEcho(@RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
                                         @RequestParam(value = "pageSize", defaultValue = "5") int pageSize,
                                         HttpServletRequest request) {
        return iEchoServices.queryOrderEchoPage(pageNum, pageSize, request);
    }
 
 
 
}