zyy
2025-12-29 645f40f5f61f8fa217ef01b5b2aaaf687b173577
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
package com.yami.trading.admin.controller.future;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yami.trading.admin.facade.PermissionFacade;
import com.yami.trading.admin.facade.ProfitAndLossConfigServiceFacade;
import com.yami.trading.bean.future.domain.ProfitLossConfig;
import com.yami.trading.bean.future.dto.ProfitLossConfigAdd;
import com.yami.trading.bean.future.dto.ProfitLossConfigDTO;
import com.yami.trading.bean.future.dto.ProfitLossConfigUpdate;
import com.yami.trading.bean.future.mapstruct.ProfitLossConfigWrapper;
import com.yami.trading.bean.future.query.ProfitLossConfigQuery;
import com.yami.trading.bean.model.User;
import com.yami.trading.common.constants.Constants;
import com.yami.trading.common.domain.Result;
import com.yami.trading.common.exception.BusinessException;
import com.yami.trading.common.exception.YamiShopBindException;
import com.yami.trading.security.common.util.SecurityUtils;
import com.yami.trading.service.user.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
 
/**
 * 交割合约Controller
 *
 * @author lucas
 * @version 2023-04-08
 */
@Slf4j
@Api(tags = "【管理后台】交割场控设置")
@RestController
@CrossOrigin
@RequestMapping(value = "normal/adminProfitAndLossConfigAction!")
public class ProfitLossConfigController {
 
    @Autowired
    private ProfitAndLossConfigServiceFacade profitAndLossConfigServiceFacade;
    @Autowired
    private UserService userService;
    @Autowired
    private PermissionFacade permissionFacade;
    @Autowired
    private ProfitLossConfigWrapper wrapper;
    /**
     * 交割合约列表数据
     */
    @ApiOperation(value = "获取 交割场控设置 列表")
    @GetMapping("list.action")
    public Result<IPage<ProfitLossConfigDTO>> list(ProfitLossConfigQuery profitLossConfigQuery, Page<ProfitLossConfig> page) throws Exception {
        profitLossConfigQuery.setChildren(permissionFacade.getOwnerUserIds());
 
        IPage<ProfitLossConfigDTO> result = profitAndLossConfigServiceFacade.getProfitLossConfigService().listRecord(page, profitLossConfigQuery);
        return Result.ok(result);
    }
 
 
    /**
     * 交割合约列表数据
     */
    @ApiOperation(value = "新增 交割场控设置 下拉配置")
    @GetMapping("config.action")
    public Result<Map<String, String>> list() {
        return Result.ok(Constants.PROFIT_LOSS_TYPE);
    }
 
    /**
     * 交割合约列表数据
     */
    @ApiOperation(value = "获取交割场控设置详情")
    @GetMapping("get.action")
    public Result<ProfitLossConfigDTO> findById(@RequestParam String id) {
        ProfitLossConfig profitLossConfig = profitAndLossConfigServiceFacade.getProfitLossConfigService().getById(id);
        User party = this.userService.getById(profitLossConfig.getPartyId());
        ProfitLossConfigDTO profitLossConfigDTO = wrapper.toDTO(profitLossConfig);
        profitLossConfigDTO.setUserCode(party.getUserCode());
        profitLossConfigDTO.setUserName(party.getUserName());
        return Result.ok(profitLossConfigDTO);
    }
    /**
     *
     */
    @ApiOperation(value = "新增 交割场控设置")
    @PostMapping("add.action")
    public Result<String> add(@RequestBody @Valid ProfitLossConfigAdd profitLossConfigAdd) {
        String usercode = profitLossConfigAdd.getUserCode();
        String type = profitLossConfigAdd.getType();
        String symbolType = profitLossConfigAdd.getSymbolType();
 
        String remark = profitLossConfigAdd.getRemark();
 
 
 
        try {
            User party = userService.findUserByUserCode(usercode);
            if (null == party) {
                throw new YamiShopBindException("用户不存在");
            }
 
            // todo代理上逻辑
            List<String> ownerUserIds = permissionFacade.getOwnerUserIds();
 
            if(ownerUserIds!=null &&!ownerUserIds.contains(usercode)){
                throw new BusinessException("用户不存在或者不属于登录用户名下");
            }
 
            ProfitLossConfig profitAndLossConfig = new ProfitLossConfig();
            profitAndLossConfig.setType(type);
            profitAndLossConfig.setRemark(remark);
            profitAndLossConfig.setSymbolType(symbolType);
            profitAndLossConfig.setPartyId(party.getUserId());
            String opName = SecurityUtils.getSysUser().getUsername();
            this.profitAndLossConfigServiceFacade.save(profitAndLossConfig, opName);
 
        } catch (Exception e) {
            log.error("保存场控失败", e);
            throw new YamiShopBindException("保存场控失败:"+ e.getMessage());
        }
        return Result.ok("操作成功");
    }
 
    /**
     *
     */
    @ApiOperation(value = "批量新增 交割场控设置")
    @PostMapping("addBatch.action")
    public Result<String> addBatch(@RequestBody @Valid ProfitLossConfigAdd profitLossConfigs) {
        String type = profitLossConfigs.getType();
        String symbolType = profitLossConfigs.getSymbolType();
 
        String remark = profitLossConfigs.getRemark();
        //校验合法性
        String[] usercodes = profitLossConfigs.getUserCode().split(",");
//        if(usercodes.length>=1000){
//            throw new YamiShopBindException("用户不存在");
//        }
        List<String> ownerUserIds = permissionFacade.getOwnerUserIds();
        Map<String,User> userMap = new HashMap<>();
        for(String usercode:usercodes){
            User party = userService.findUserByUserCode(usercode);
            if (null == party) {
                throw new YamiShopBindException("用户不存在usercode="+usercode);
            }
            if(ownerUserIds!=null &&!ownerUserIds.contains(usercode)){
                throw new BusinessException("用户不存在或者不属于登录用户名下usercode="+usercode);
            }
            userMap.put(usercode,party);
        }
 
        for(User party:userMap.values()){
            try {
                ProfitLossConfig profitAndLossConfig = new ProfitLossConfig();
                profitAndLossConfig.setType(type);
                profitAndLossConfig.setRemark(remark);
                profitAndLossConfig.setSymbolType(symbolType);
                profitAndLossConfig.setPartyId(party.getUserId());
                String opName = SecurityUtils.getSysUser().getUsername();
                this.profitAndLossConfigServiceFacade.save(profitAndLossConfig, opName);
            }catch (Exception e) {
                log.error("保存场控失败usercode:{}", party.getUserCode(),e);
                throw new YamiShopBindException("保存场控失败usercode:"+ party.getUserCode());
            }
        }
 
        return Result.ok("操作成功");
    }
 
 
    /**
     * 保存交割合约
     */
    @ApiOperation(value = "修改 交割场控设置")
    @PostMapping("update.action")
    public Result<String> update(@Valid @RequestBody ProfitLossConfigUpdate update) {
        ProfitLossConfig profitAndLossConfig = this.profitAndLossConfigServiceFacade.getProfitLossConfigService().getById(update.getUuid());
        User party = userService.getById(profitAndLossConfig.getPartyId());
        if (null == party) {
            throw new YamiShopBindException("用户不存在");
        }
        String opName = SecurityUtils.getSysUser().getUsername();
        // todo 代理商数据权限验证
        /**
         * List<String> childrens = this.userRecomService.findChildren(party_login.getId());
         *
         *                 double isChildren = 0;
         *                 if (childrens != null) {
         *                     for (String children : childrens) {
         *                         if (party.getId().equals(children)) {
         *                             isChildren = 1;
         *                                                }*                     }
         *                 }
         *
         */
        profitAndLossConfig.setRemark(update.getRemark());
        profitAndLossConfig.setType(update.getType());
        profitAndLossConfigServiceFacade.update(profitAndLossConfig, opName);
 
        return Result.ok("保存交割合约成功");
    }
 
 
    /**
     * 保存交割合约
     */
    @ApiOperation(value = "删除 交割场控设置")
    @GetMapping("toDelete.action")
    public Result<String> toDelete(@RequestParam String uuid) {
        ProfitLossConfig profitAndLossConfig = this.profitAndLossConfigServiceFacade.getProfitLossConfigService().getById(uuid);
        User party = userService.getById(profitAndLossConfig.getPartyId());
        if (null == party) {
            throw new YamiShopBindException("用户不存在");
        }
        String opName = SecurityUtils.getSysUser().getUsername();
        // todo 代理商数据权限验证
        /**
         * List<String> childrens = this.userRecomService.findChildren(party_login.getId());
         *
         *                 double isChildren = 0;
         *                 if (childrens != null) {
         *                     for (String children : childrens) {
         *                         if (party.getId().equals(children)) {
         *                             isChildren = 1;
         *                                                }*                     }
         *                 }
         *
         */
        profitAndLossConfigServiceFacade.delete(uuid, opName);
 
        return Result.ok("保存交割合约成功");
    }
 
 
}