新版仿ok交易所-后端
1
zj
20 hours ago 640ccb9229224642515527daf87f308a7aa9bdf4
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
package com.yami.trading.admin.facade;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yami.trading.bean.future.domain.ProfitLossConfig;
import com.yami.trading.bean.future.dto.ProfitLossConfigDTO;
import com.yami.trading.bean.future.query.ProfitLossConfigQuery;
import com.yami.trading.bean.model.Log;
import com.yami.trading.bean.model.User;
import com.yami.trading.common.constants.Constants;
import com.yami.trading.service.future.ProfitLossConfigService;
import com.yami.trading.service.system.LogService;
import com.yami.trading.service.user.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import java.util.Date;
 
@Component
@Slf4j
public class ProfitAndLossConfigServiceFacade {
    @Autowired
    private UserService userService;
    @Autowired
    private LogService logService;
    @Autowired
    private ProfitLossConfigService profitLossConfigService;
 
    public IPage<ProfitLossConfigDTO> listRecord(Page<ProfitLossConfig> page, ProfitLossConfigQuery query) {
        return profitLossConfigService.listRecord(page, query);
    }
 
    public ProfitLossConfig getById(String id) {
        return profitLossConfigService.getById(id);
    }
 
    public void save(ProfitLossConfig entity, String operaterUsername) {
        ProfitLossConfig profitAndLossConfig = profitLossConfigService.findByPartyId(entity.getPartyId());
        // 如果存在则更新
        if (profitAndLossConfig != null) {
            profitAndLossConfig.setRemark(entity.getRemark());
            profitAndLossConfig.setType(entity.getType());
            profitLossConfigService.updateById(profitAndLossConfig);
        } else {
            profitLossConfigService.save(entity);
        }
 
        String type = "";
 
        if("profit".equals(entity.getType())) {
            type = "盈利";
        }
        if("loss".equals(entity.getType())) {
            type = "亏损";
        }
        if("buy_profit".equals(entity.getType())) {
            type = "买多盈利";
        }
        if("sell_profit".equals(entity.getType())) {
            type = "买空盈利";
        }
        if("buy_profit_sell_loss".equals(entity.getType())) {
            type = "买多盈利并且买空亏损";
        }
        if("sell_profit_buy_loss".equals(entity.getType())) {
            type = "买空盈利并且买多亏损";
        }
 
        User party = this.userService.getById(entity.getPartyId());
        Log log = new Log();
        log.setCategory(Constants.LOG_CATEGORY_OPERATION);
        log.setOperator(operaterUsername);
        log.setUsername(party.getUserName());
        log.setUserId(entity.getPartyId());
        log.setCreateTime(new Date());
        log.setLog("管理员手动添加场控交割状态。操作类型[" + type + "]。");
        this.logService.save(log);
    }
 
    public void update(ProfitLossConfig entity,String Operater_username) {
        profitLossConfigService.updateById(entity);
 
        String type = "";
 
        if("profit".equals(entity.getType())) {
            type = "盈利";
        }
        if("loss".equals(entity.getType())) {
            type = "亏损";
        }
        if("buy_profit".equals(entity.getType())) {
            type = "买多盈利";
        }
        if("sell_profit".equals(entity.getType())) {
            type = "买空盈利";
        }
        if("buy_profit_sell_loss".equals(entity.getType())) {
            type = "买多盈利并且买空亏损";
        }
        if("sell_profit_buy_loss".equals(entity.getType())) {
            type = "买空盈利并且买多亏损";
        }
        User party = this.userService.getById(entity.getPartyId());
        Log log = new Log();
        log.setCategory(Constants.LOG_CATEGORY_OPERATION);
        log.setOperator(Operater_username);
        log.setUsername(party.getUserName());
        log.setUserId(entity.getPartyId());
        log.setCreateTime(new Date());
        log.setLog("管理员手动修改场控交割状态。修改后操作类型为[" + type + "]。");
        this.logService.save(log);
    }
 
    public void delete(String id,String operaterUsername) {
        ProfitLossConfig entity = profitLossConfigService.getById(id);
        if(entity == null){
            log.error("ProfitLossConfig id 为 {} 不存在", id );
            return;
        }
        profitLossConfigService.removeById(id);
        User party = userService.getById(entity.getPartyId());
        Log log = new Log();
        log.setCategory(Constants.LOG_CATEGORY_OPERATION);
        log.setOperator(operaterUsername);
        log.setUsername(party.getUserName());
        log.setUserId(entity.getPartyId());
        log.setCreateTime(new Date());
        log.setLog("管理员手动删除场控交割状态");
        this.logService.save(log);
    }
}