新版仿ok交易所-后端
zj
2025-01-06 6e21cf6973aa1898259ddceda665f0f1b06272ab
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
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.List;
import java.util.Map;
 
 
/**
 * 交割合约Controller
 *
 * @author lucas
 * @version 2023-04-08
 */
@Slf4j
@Api(tags = "【管理后台】交割场控设置")
@RestController
@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 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.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("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("保存交割合约成功");
    }
 
 
}