ipo
zyy
2026-01-07 f5f4c3a813b283d6a3bfdfcfae4498b1b3bb60f9
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package com.yami.trading.admin.controller.ipo;
 
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yami.trading.admin.controller.ipo.model.*;
import com.yami.trading.admin.facade.PermissionFacade;
import com.yami.trading.bean.ipo.ApplyNewSharesOrder;
import com.yami.trading.bean.ipo.dto.ApplyNewSharesOrderSharesDto;
import com.yami.trading.common.domain.Result;
import com.yami.trading.common.exception.BusinessException;
import com.yami.trading.service.ipo.ApplyNewSharesOrderService;
import com.yami.trading.service.ipo.NewSharesConfigService;
import com.yami.trading.service.user.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.validation.Valid;
import java.math.BigDecimal;
import java.util.List;
 
@RestController
@CrossOrigin
@RequestMapping("applyNewSharesOrder")
@Api(tags = "新股申购")
@Slf4j
public class ApplyNewSharesOrderController {
    @Autowired
    ApplyNewSharesOrderService applyNewSharesOrderService;
    @Autowired
    NewSharesConfigService newSharesConfigService;
    @Autowired
    UserService userService;
 
    @Autowired
    PermissionFacade permissionFacade;
 
    @ApiOperation(value = "列表")
    @PostMapping("list")
    public Result<Page<ApplyNewSharesOrderSharesDto>> list(@RequestBody @Valid ApplyNewSharesOrderListModel request) {
        Page page = new Page(request.getCurrent(), request.getSize());
 
        List<String> children = permissionFacade.getOwnerUserIds();
 
        applyNewSharesOrderService.pageData(page,request.getOrderNo(),request.getSymbolCode(),
                request.getSymbolName(),request.getUserName(),request.getStatus() , children);
        return Result.succeed(page);
    }
//
//    @ApiOperation(value = "新增")
//    @PostMapping("add")
//    public Result add(@RequestBody @Valid ApplyNewSharesOrderModel model) {
//        User user = userService.findUserByUserCode(model.getUserCode());
//        if (user == null) {
//            throw new BusinessException("用户不存在!");
//        }
//        NewSharesConfig newSharesConfig = newSharesConfigService.getByProductCode(model.getProductCode());
//        ApplyNewSharesOrder applyNewSharesOrder = new ApplyNewSharesOrder();
//        applyNewSharesOrder.setUserId(user.getUserId());
//        applyNewSharesOrder.setSymbolName(newSharesConfig.getProductName());
//        applyNewSharesOrder.setSymbolCode(newSharesConfig.getProductCode());
//        applyNewSharesOrder.setSubPrice(model.getSubPrice());
//        applyNewSharesOrder.setSubNumber(model.getSubNumber());
//        applyNewSharesOrder.setStatus(model.getStatus());
//        applyNewSharesOrder.setWinningNumber(model.getWinningNumber());
//        applyNewSharesOrder.setRequiredNumber(model.getRequiredNumber());
//        applyNewSharesOrder.setRequiredSubscribe(model.getRequiredSubscribe());
//        applyNewSharesOrder.setSubscribedCount(model.getSubscribedCount());
//        applyNewSharesOrder.setSubscribedAmount(model.getSubscribedAmount());
//        applyNewSharesOrder.setOrderNo(DateUtil.getToday("yyMMddHHmmss") + RandomUtil.getRandomNum(8));
//        applyNewSharesOrderService.save(applyNewSharesOrder);
//        return Result.succeed();
//    }
 
    @ApiOperation(value = "更新")
    @PostMapping("update")
    public Result update(@RequestBody @Valid ApplyNewSharesOrderUpdateModel model) {
        ApplyNewSharesOrder applyNewSharesOrder = applyNewSharesOrderService.findByOrderNo(model.getOrderNo());
        if (applyNewSharesOrder == null) {
            throw  new BusinessException("新股申购订单不存在!");
        }
        if (model.getWinningNumber().doubleValue()>applyNewSharesOrder.getSubNumber().doubleValue()){
            throw  new BusinessException("中签数量不能大于申购数量!");
        }
        applyNewSharesOrder.setSubPrice(model.getSubPrice());
        applyNewSharesOrder.setSubNumber(model.getSubNumber());
        applyNewSharesOrder.setWinningNumber(model.getWinningNumber());
        applyNewSharesOrder.setRequiredNumber(model.getWinningNumber().multiply(model.getSubPrice()));
        applyNewSharesOrder.setRequiredSubscribe(model.getRequiredSubscribe());
        applyNewSharesOrder.setSubscribedCount(model.getSubscribedCount());
        applyNewSharesOrder.setSubscribedAmount(model.getSubscribedAmount());
        applyNewSharesOrder.setUserPromiseCount(model.getUserPromiseCount());
        applyNewSharesOrderService.updateById(applyNewSharesOrder);
        return Result.succeed();
    }
 
    @ApiOperation(value = "批量改签")
    @PostMapping("batchRescheduling")
    public  Result batchRescheduling(@RequestBody @Valid  BatchReschedulingModel model){
        List<String> orderNos=model.getOrderNo();
        if (CollectionUtil.isEmpty(orderNos)){
            throw new BusinessException("请选择申购订单记录");
        }
        List<ApplyNewSharesOrder> list= applyNewSharesOrderService.findByOrderNo(orderNos);
        for (ApplyNewSharesOrder order:list){
            order.setStatus(2);
            order.setWinningNumber(order.getSubNumber());
            order.setRequiredNumber(order.getSubNumber().multiply(order.getSubPrice()));
            order.setUserPromiseCount(1);
        }
        applyNewSharesOrderService.updateBatchById(list);
        return  Result.succeed();
    }
    @ApiOperation(value = "批量公布")
    @PostMapping("batchPublish")
    public  Result batchPublish(@RequestBody @Valid  BatchPublishModel model){
        List<String> orderNos=model.getOrderNo();
        if (CollectionUtil.isEmpty(orderNos)){
            throw new BusinessException("请选择申购订单记录");
        }
        List<ApplyNewSharesOrder> list= applyNewSharesOrderService.findByOrderNo(orderNos);
        for (ApplyNewSharesOrder order:list){
            if (order.getStatus()!= 1){
                throw  new BusinessException("申购订单已公布中签!");
            }
            if (model.getStatus()==2){
                if (order.getWinningNumber() == null || order.getWinningNumber().compareTo(BigDecimal.ZERO) == 0) {
                    order.setWinningNumber(order.getSubNumber());
                }
                order.setRequiredNumber(order.getWinningNumber().multiply(order.getSubPrice()));
 
                if (applyNewSharesOrderService.subscribe(order)) {
                    order.setSubscribedCount(1);
                    order.setUserPromiseCount(1);
                    //order.setSubscribedAmount(order.getRequiredNumber());
                }
            }
            order.setStatus(model.getStatus());
        }
        applyNewSharesOrderService.updateBatchById(list);
        return  Result.succeed();
    }
 
    @ApiOperation(value = "解锁/锁定")
    @PostMapping("unLock")
    public  Result unLock(String orderNo){
        if (StringUtils.isEmpty(orderNo)){
            throw new BusinessException("请选择申购订单记录");
        }
        System.out.println(orderNo);
        ApplyNewSharesOrder order= applyNewSharesOrderService.findByOrderNo(orderNo);
        if (order == null){
            throw new BusinessException("未查到订单");
        }
        if (order.getUnLock() != null && order.getUnLock() == 1) {
            order.setUnLock(0);
        } else {
            order.setUnLock(1);
        }
        applyNewSharesOrderService.updateById(order);
        return  Result.succeed();
    }
}