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
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
package project.user.internal;
 
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import org.apache.commons.collections.CollectionUtils;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.security.providers.encoding.PasswordEncoder;
 
import kernel.bo.RecordObjectMapper;
import kernel.exception.BusinessException;
import kernel.util.DateUtils;
import kernel.util.StringUtils;
import kernel.web.ApplicationUtil;
import project.Constants;
import project.tip.TipConstants;
import project.tip.TipService;
import project.user.UserSafewordApply;
import project.user.UserSafewordApplyService;
import project.user.kyc.Kyc;
import project.user.kyc.KycService;
import security.SaltSigureUtils;
import util.Strings;
 
public class UserSafewordApplyServiceImpl implements UserSafewordApplyService {
 
    private JdbcTemplate jdbcTemplate;
    private PasswordEncoder passwordEncoder;
    private KycService kycService;
    private TipService tipService;
 
    public void save(UserSafewordApply entity) {
        Object[] jdbcParams = ApplicationUtil.getInsertStatement(entity);
        String insertUserSql = (String)jdbcParams[0];
        Object[] sqlParameters = (Object[])jdbcParams[1];
        jdbcTemplate.update(insertUserSql, sqlParameters);
    }
 
    public void update(UserSafewordApply entity) {
        Object[] jdbcParams = ApplicationUtil.getUpdateStatement(entity, "WHERE UUID=?", new Object[] {entity.getId()});
        String updateUserSql = (String)jdbcParams[0];
        Object[] sqlParameters = (Object[])jdbcParams[1];
        jdbcTemplate.update(updateUserSql, sqlParameters);
    }
 
    public void delete(String id) {
        UserSafewordApply entity = findById(id);
        jdbcTemplate.update("DELETE FROM T_USER_SAFEWORD_APPLY WHERE UUID=?", entity.getId());
    }
 
    public UserSafewordApply findById(String id) {
        List<UserSafewordApply> list = jdbcTemplate.query("SELECT * FROM T_USER_SAFEWORD_APPLY WHERE UUID=?", 
                RecordObjectMapper.newInstance(UserSafewordApply.class), id);
        if (null != list && list.size() > 0) {
            return list.get(0);
        }
        return null;
    }
 
    public List<UserSafewordApply> findByPartyId(String partyId) {
        List<UserSafewordApply> list = jdbcTemplate.query("SELECT * FROM T_USER_SAFEWORD_APPLY WHERE PARTY_ID=? ORDER BY CREATE_TIME DESC ", 
                RecordObjectMapper.newInstance(UserSafewordApply.class), partyId);
        return list;
    }
    
    /**
     * 尚未通过的申请
     */
    public UserSafewordApply findByPartyIdNoPass(String partyId, Integer operate) {
        List<UserSafewordApply> list = jdbcTemplate.query("SELECT * FROM T_USER_SAFEWORD_APPLY WHERE PARTY_ID=? AND OPERATE =? AND STATUS = 2 ORDER BY CREATE_TIME DESC ", 
                RecordObjectMapper.newInstance(UserSafewordApply.class), partyId, operate);
        return CollectionUtils.isEmpty(list) ? null : list.get(0);
    }
    
    /**
     * 人工重置  操作类型 operate:     0/修改资金密码;1/取消谷歌绑定;2/取消手机绑定;3/取消邮箱绑定;
     */
    public void saveApply(String partyId, String idcard_path_front, String idcard_path_back, String idcard_path_hold, String safeword, 
            String safeword_confirm, Integer operate, String remark) {
        
        if (null == operate || !Arrays.asList(0, 1, 2, 3).contains(operate)) {
            throw new BusinessException("操作类型不正确");
        }
        
        // 操作类型 operate:     0/修改资金密码;
        if (0 == operate.intValue()) {
 
            if (StringUtils.isEmptyString(safeword)) {
                throw new BusinessException("资金密码不能为空");
            }
 
            if (safeword.length() != 6 || !Strings.isNumber(safeword)) {
                throw new BusinessException("资金密码不符合设定");
            }
 
            if (StringUtils.isEmptyString(safeword_confirm)) {
                throw new BusinessException("资金密码确认不能为空");
            }
            
            if (!safeword.equals(safeword_confirm)) {
                throw new BusinessException("两次输入的资金密码不相同");
            }
        }
        
//        if (StringUtils.isEmptyString(idcard_path_front)) {
//            throw new BusinessException("请上传证件照正面");
//        }
//        
//        if (StringUtils.isEmptyString(idcard_path_back)) {
//            throw new BusinessException("请上传证件照反面");
//        }
//        
//        if (StringUtils.isEmptyString(idcard_path_hold)) {
//            throw new BusinessException("请上传手持证件照");
//        }
        
//        // 操作类型 operate:     0/修改资金密码;
//        if (0 == operate.intValue()) {
            Kyc kyc = this.kycService.get(partyId);
            if (null == kyc || kyc.getStatus() != 2) {
                throw new BusinessException(401, "实名认证尚未通过,无法重置");
            }
//        }
        
        UserSafewordApply apply = this.findByPartyIdNoPass(partyId, operate);
        if (null == apply) {
            apply = new UserSafewordApply();
            apply.setCreate_time(new Date());
        } else if (apply.getStatus() == 0) {
            throw new BusinessException("您的申请之前已提交过");
        }
        
        // 操作类型 operate:     0/修改资金密码;
        if (0 == operate.intValue()) {
            String safewordMd5 = this.passwordEncoder.encodePassword(safeword, SaltSigureUtils.saltfigure);
            apply.setSafeword(safewordMd5);
        } else {
            apply.setSafeword("");
        }
        
        apply.setIdcard_path_front(idcard_path_front);
        apply.setIdcard_path_back(idcard_path_back);
        apply.setIdcard_path_hold(idcard_path_hold);
        apply.setOperate(operate);
        apply.setRemark(remark);
        apply.setPartyId(partyId);
        apply.setStatus(1);
        
        if (null == apply.getId()) {
            this.save(apply);
        } else {
            this.update(apply);
        }
        
        this.tipService.saveTip(apply.getId().toString(), TipConstants.USER_SAFEWORD_APPLY);
    }
 
    public Map<String, Object> bindOne(UserSafewordApply apply) {
        
        Map<String, Object> result = new HashMap<String, Object>();
        
        String idcard_path_front_path = "";
        String idcard_path_back_path = "";
        String idcard_path_hold_path = "";
        
        if (!StringUtils.isNullOrEmpty(apply.getIdcard_path_front())) {
            idcard_path_front_path = Constants.WEB_URL + "/public/showimg!showImg.action?imagePath="
                    + apply.getIdcard_path_front();
        }
        result.put("idcard_path_front", apply.getIdcard_path_front());
        result.put("idcard_path_front_path", idcard_path_front_path);
 
        if (!StringUtils.isNullOrEmpty(apply.getIdcard_path_back())) {
            idcard_path_back_path = Constants.WEB_URL + "/public/showimg!showImg.action?imagePath="
                    + apply.getIdcard_path_back();
        }
        result.put("idcard_path_back", apply.getIdcard_path_back());
        result.put("idcard_path_back_path", idcard_path_back_path);
        
        if (!StringUtils.isNullOrEmpty(apply.getIdcard_path_hold())) {
            idcard_path_hold_path = Constants.WEB_URL + "/public/showimg!showImg.action?imagePath="
                    + apply.getIdcard_path_hold();
        } else {
            idcard_path_hold_path = Constants.WEB_URL + "/public/showimg!showImg.action?imagePath=qr/id_img3.jpg";
        }
        result.put("idcard_path_hold", apply.getIdcard_path_hold());
        result.put("idcard_path_hold_path", idcard_path_hold_path);
        
        result.put("id", apply.getId());
        result.put("create_time", DateUtils.format(apply.getCreate_time(), DateUtils.DF_yyyyMMddHHmmss));
        result.put("msg", apply.getMsg());
        result.put("apply_time", DateUtils.format(apply.getApply_time(), DateUtils.DF_yyyyMMddHHmmss));
        result.put("status", apply.getStatus());
        result.put("operate", apply.getOperate());
        result.put("remark", apply.getRemark());
        
        return result;
    }
 
    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }
 
    public void setPasswordEncoder(PasswordEncoder passwordEncoder) {
        this.passwordEncoder = passwordEncoder;
    }
 
    public void setKycService(KycService kycService) {
        this.kycService = kycService;
    }
 
    public void setTipService(TipService tipService) {
        this.tipService = tipService;
    }
 
}