zj
2025-05-02 01830e44921b187b448d8cce9c9a46b9ad55af43
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
package project.futures.internal;
 
import java.text.MessageFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.security.providers.encoding.PasswordEncoder;
 
import kernel.exception.BusinessException;
import kernel.util.StringUtils;
import kernel.web.PagedQueryDao;
import project.Constants;
import project.futures.AdminContractManageService;
import project.futures.AdminFuturesParaService;
import project.futures.FuturesPara;
import project.item.AdminItemService;
import project.item.model.Item;
import project.log.LogService;
import project.user.googleauth.GoogleAuthService;
import security.SecUser;
import security.internal.SecUserService;
 
public class AdminContractManageServiceImpl implements AdminContractManageService {
    private Logger logger = LoggerFactory.getLogger(getClass());
    private PagedQueryDao pagedQueryDao;
    private JdbcTemplate jdbcTemplate;
    private AdminItemService adminItemService;
    private AdminFuturesParaService adminFuturesParaService;
    private SecUserService secUserService;
    private LogService logService;
    private PasswordEncoder passwordEncoder;
    protected GoogleAuthService googleAuthService;
 
    public Map<String, String> getFuturesSymbols() {
        List<String> list = this.adminItemService.getSymbols();
        Map<String,String> result = new HashMap<String,String>();
        for(String str:list) {
            result.put(str, str);
        }
        return result;
    }
 
    public String addContractItem(Item entity) {
        if (entity.getId()!=null&&StringUtils.isNotEmpty(entity.getId().toString())) {
            Item item = adminItemService.get(entity.getId().toString());
            if (null == item) {
                logger.info("item is null ,id:{}", entity.getId().toString());
                return "合约产品不存在";
            }
            if (null != entity.getDecimals())
                item.setDecimals(entity.getDecimals());
            item.setName(entity.getName());
            this.adminItemService.update(item);
            return "";
        }
        if (this.adminItemService.checkSymbolExit(entity.getSymbol()))
            return "合约代码已经存在";
        entity.setMarket(Item.DELIVERY_CONTRACT);// 合约
        this.adminItemService.save(entity);            
        return "";
    }
 
    public String addFutures(FuturesPara entity,String ip,String operaUsername,String loginSafeword) {
        SecUser sec = this.secUserService.findUserByLoginName(operaUsername);
        checkLoginSafeword(sec,operaUsername,loginSafeword);
        String logContent = "ip:"+ip;
        if (entity.getId()!=null && StringUtils.isNotEmpty(entity.getId().toString())) {
            FuturesPara futuresById = this.adminFuturesParaService.getById(entity.getId());
            if (null == futuresById) {
                logger.info("futures is null ,id:{}", entity.getId());
                return "合约参数不存在";
            }
            logContent += MessageFormat.format(",管理员修改交割参数,币种:{0},原时间长度:{1},原时间单位:{2},原最低购买金额:{3},原手续费:{4},原浮动最小收益率:{5},原浮动最大收益率:{6}", 
                    futuresById.getSymbol(),futuresById.getTimeNum(),futuresById.getTimeUnit(),futuresById.getUnit_amount(),futuresById.getUnit_fee(),futuresById.getProfit_ratio(),futuresById.getProfit_ratio_max());
            BeanUtils.copyProperties(entity, futuresById);// 是否做用户控制
            this.adminFuturesParaService.update(futuresById);
            logContent += MessageFormat.format(",新时间长度:{0},新时间单位:{1},新最低购买金额:{2},新手续费:{3},新浮动最小收益率:{4},新浮动最大收益率:{5}", 
                    futuresById.getTimeNum(),futuresById.getTimeUnit(),futuresById.getUnit_amount(),futuresById.getUnit_fee(),futuresById.getProfit_ratio(),futuresById.getProfit_ratio_max());
            saveLog(sec,operaUsername,logContent);
            return "";
        }
        logContent += MessageFormat.format(",管理员新增交割参数,币种:{0},时间长度:{1},时间单位:{2},最低购买金额:{3},手续费:{4},浮动最小收益率:{5},浮动最大收益率:{6}", 
                entity.getSymbol(),entity.getTimeNum(),entity.getTimeUnit(),entity.getUnit_amount(),entity.getUnit_fee(),entity.getProfit_ratio(),entity.getProfit_ratio_max());
        this.adminFuturesParaService.add(entity);
        saveLog(sec,operaUsername,logContent);
        return "";
    }
 
    public void deleteFuturesPara(String id,String ip,String operaUsername,String loginSafeword,String superGoogleAuthCode) {
        googleAuthService.checkSuperGoogleAuthCode(superGoogleAuthCode);
        SecUser sec = this.secUserService.findUserByLoginName(operaUsername);
        checkLoginSafeword(sec,operaUsername,loginSafeword);
        
        FuturesPara entity = this.adminFuturesParaService.getById(id);
        if(null == entity ) {
            throw new BusinessException("交易参数不存在");
        }
        String logContent = "ip:"+ip;
        logContent += MessageFormat.format(",管理员删除交割参数,币种:{0},时间长度:{1},时间单位:{2},最低购买金额:{3},手续费:{4},浮动最小收益率:{5},浮动最大收益率:{6}", 
                entity.getSymbol(),entity.getTimeNum(),entity.getTimeUnit(),entity.getUnit_amount(),entity.getUnit_fee(),entity.getProfit_ratio(),entity.getProfit_ratio_max());
        this.adminFuturesParaService.delete(entity);
        saveLog(sec,operaUsername,logContent);
    }
 
    /**
     * 验证登录人资金密码
     * @param operatorUsername
     * @param loginSafeword
     */
    protected void checkLoginSafeword(SecUser secUser,String operatorUsername,String loginSafeword) {
//        SecUser sec = this.secUserService.findUserByLoginName(operatorUsername);
        String sysSafeword = secUser.getSafeword();
        String safeword_md5 = passwordEncoder.encodePassword(loginSafeword, operatorUsername);
        if (!safeword_md5.equals(sysSafeword)) {
            throw new BusinessException("登录人资金密码错误");
        }
        
    }
    public void saveLog(SecUser secUser, String operator,String context) {
        project.log.Log log = new project.log.Log();
        log.setCategory(Constants.LOG_CATEGORY_OPERATION);
        log.setOperator(operator);
        log.setUsername(secUser.getUsername());
        log.setPartyId(secUser.getPartyId());
        log.setLog(context);
        log.setCreateTime(new Date());
        logService.saveSync(log);
    }    
    public PagedQueryDao getPagedQueryDao() {
        return pagedQueryDao;
    }
 
    public void setPagedQueryDao(PagedQueryDao pagedQueryDao) {
        this.pagedQueryDao = pagedQueryDao;
    }
 
    public JdbcTemplate getJdbcTemplate() {
        return jdbcTemplate;
    }
 
    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }
 
    public AdminItemService getAdminItemService() {
        return adminItemService;
    }
 
    public void setAdminItemService(AdminItemService adminItemService) {
        this.adminItemService = adminItemService;
    }
    
    public void setAdminFuturesParaService(AdminFuturesParaService adminFuturesParaService) {
        this.adminFuturesParaService = adminFuturesParaService;
    }
 
    public void setSecUserService(SecUserService secUserService) {
        this.secUserService = secUserService;
    }
 
    public void setLogService(LogService logService) {
        this.logService = logService;
    }
 
    public void setPasswordEncoder(PasswordEncoder passwordEncoder) {
        this.passwordEncoder = passwordEncoder;
    }
 
    public void setGoogleAuthService(GoogleAuthService googleAuthService) {
        this.googleAuthService = googleAuthService;
    }
    
    
}