1
zj
2025-07-28 1caf228ac11217ac3191945f059d646a1585150c
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
package com.nq.controller.smart;
 
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.nq.common.ServerResponse;
import com.nq.dao.IntradayOrderMapper;
import com.nq.dao.StockMapper;
import com.nq.dao.UserAssetsMapper;
import com.nq.enums.EStockType;
import com.nq.enums.EUserAssets;
import com.nq.pojo.*;
import com.nq.service.IUserAssetsServices;
import com.nq.service.IUserService;
import com.nq.service.impl.IntradayOrderSerivceImpl;
import com.nq.service.impl.SmartIntradaySerivceImpl;
import com.nq.service.impl.StockServiceImpl;
import com.nq.utils.ConverterUtil;
import com.nq.vo.smart.IntradayOrderVo;
import com.nq.vo.smart.SmartIntradayVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;
 
/**
 * @program: dabaogp
 * @description:
 * @create: 2025-07-15 14:27
 **/
@Controller
@RequestMapping({"/api/intraday/"})
public class IntradayOrderController {
 
    @Autowired
    private IntradayOrderSerivceImpl intradayOrderSerivce;
 
    @Autowired
    private SmartIntradaySerivceImpl smartIntradaySerivce;
 
    @Autowired
    private StockMapper stockMapper;
 
    @Autowired
    private IUserService userService;
 
    @Autowired
    private IUserAssetsServices iUserAssetsServices;
 
    @Autowired
    private UserAssetsMapper userAssetsMapper;
 
    @Autowired
    private IntradayOrderMapper intradayOrderMapper;
 
 
 
    /**
     * 智能日内列表
     */
    @RequestMapping(value = {"listSmart.do"}, method = {RequestMethod.POST})
    @ResponseBody
    public ServerResponse listSmart() {
 
        // 创建查询条件
        LambdaQueryWrapper<SmartIntraday> wrapper = new LambdaQueryWrapper<>();
 
        wrapper.eq(SmartIntraday::getStatus,1);
        // 按创建时间倒序
        wrapper.orderByDesc(SmartIntraday::getCreatedAt);
        // 执行分页查询
        List<SmartIntraday>list = smartIntradaySerivce.list( wrapper);
        return ServerResponse.createBySuccess(list);
    }
 
    /**
     * 下单智能日内
     * @param vo
     * @return
     */
    @RequestMapping(value = {"addIntraday.do"}, method = {RequestMethod.POST})
    @ResponseBody
    public ServerResponse addIntraday(@Valid IntradayOrderVo vo,HttpServletRequest request) {
        SmartIntraday smartIntraday = smartIntradaySerivce.getById(vo.getSmartId());
        if(ObjectUtil.isEmpty(smartIntraday)){
            return ServerResponse.createBySuccess("产品已下架!",request);
        }
        User user = userService.getCurrentRefreshUser(request);
        UserAssets userAssets = iUserAssetsServices.assetsByTypeAndUserId(EStockType.JP.getCode(), user.getId());
        BigDecimal orderAmount = vo.getOrderAmount();
        if(userAssets.getAvailableBalance().compareTo(orderAmount)<0){
            return ServerResponse.createByErrorMsg("余额不足",request);
        }
 
        userAssets.setAvailableBalance(userAssets.getAvailableBalance().subtract(orderAmount));
        userAssetsMapper.updateById(userAssets);
 
        IntradayOrder intradayOrder = ConverterUtil.convert(vo, IntradayOrder.class);
        intradayOrder.setUserId(user.getId());
        intradayOrder.setSmartId(smartIntraday.getId());
        intradayOrder.setStockType(EStockType.JP.getCode());
        intradayOrderSerivce.save(intradayOrder);
        return ServerResponse.createBySuccess("下单成功",request);
    }
 
    /**
     * 智能日内订单列表
     */
    @RequestMapping(value = {"listIntraday.do"}, method = {RequestMethod.POST})
    @ResponseBody
    public ServerResponse listIntraday(@RequestParam(value = "status" , required = false) Integer status,HttpServletRequest request) {
        User user = userService.getCurrentRefreshUser(request);
        List<IntradayOrder> intradayOrderList = intradayOrderMapper.selectList(new LambdaQueryWrapper<>(IntradayOrder.class)
                .eq(IntradayOrder::getAuditStatus,status)
                .eq(IntradayOrder::getUserId,user.getId())
        );
        return ServerResponse.createBySuccess(intradayOrderList);
    }
}