peternameyakj
2024-10-15 19d0fd2c0e7860e2d5d075f926df0d190ebb34cc
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
package project.user.internal;
 
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
 
import org.springframework.security.providers.encoding.PasswordEncoder;
 
import kernel.exception.BusinessException;
import kernel.util.StringUtils;
import kernel.web.ApplicationUtil;
import kernel.web.Page;
import project.party.PartyService;
import project.party.model.Party;
import project.party.recom.UserRecomService;
import project.tip.TipService;
import project.user.AdminUserSafewordApplyService;
import project.user.UserSafewordApply;
import project.user.UserSafewordApplyService;
import project.user.kyc.Kyc;
import project.user.kyc.KycService;
import security.SecUser;
import security.internal.SecUserService;
 
@SuppressWarnings("rawtypes")
public class AdminUserSafewordApplyServiceImpl implements AdminUserSafewordApplyService {
    
    private TipService tipService;
    
    protected KycService kycService;
    
    protected PartyService partyService;
    
    private SecUserService secUserService;
    
    private PasswordEncoder passwordEncoder;
    
    protected UserRecomService userRecomService;
    
    protected UserSafewordApplyService userSafewordApplyService;
 
    @Override
    public Page pagedQuery(int pageNo, int pageSize, String name_para, Integer status_para, String rolename_para,String checkedPartyId, Integer operate) {
        if (pageNo <= 0) pageNo = 1;
        Page page = new Page(pageNo, pageSize, Integer.MAX_VALUE);
        
        StringBuilder sqlBuilder=new StringBuilder("SELECT party.UUID partyId, party.USERCODE usercode, party.USERNAME username, party.ROLENAME rolename, party.USER_LEVEL user_level,");
        sqlBuilder.append("kyc.UUID kyc_id, kyc.IDNAME kyc_idname, kyc.NAME kyc_name, kyc.IDIMG_1 kyc_idimg_1, kyc.IDIMG_2 kyc_idimg_2,kyc.IDIMG_3 kyc_idimg_3, kyc.STATUS kyc_status,");
        sqlBuilder.append("apply.UUID id, apply.IDCARD_PATH_FRONT idimg_1, apply.IDCARD_PATH_BACK idimg_2, apply.IDCARD_PATH_HOLD idimg_3,apply.MSG msg, apply.STATUS status,");
        sqlBuilder.append("apply.CREATE_TIME create_time, apply.OPERATE operate, apply.REMARK remark FROM T_USER_SAFEWORD_APPLY apply ");
        sqlBuilder.append("LEFT JOIN T_KYC kyc ON kyc.PARTY_ID=apply.PARTY_ID LEFT JOIN PAT_PARTY party ON kyc.PARTY_ID=party.UUID WHERE 1=1 ");
        ArrayList<Object> params=new ArrayList<Object>();
        
        if (!StringUtils.isNullOrEmpty(checkedPartyId)) {
            List<String> checkedList = this.userRecomService.findChildren(checkedPartyId);
            checkedList.add(checkedPartyId);
            sqlBuilder.append("AND FIND_IN_SET(party.UUID,?) ");
            params.add(String.join(",",checkedList));
        }
 
        if (status_para != null) {
            sqlBuilder.append("AND apply.STATUS=? ");
            params.add(status_para);
        }
        
        if (!StringUtils.isNullOrEmpty(rolename_para)) {
            sqlBuilder.append("AND party.ROLENAME=? ");
            params.add(rolename_para);
        }
        
        if (!StringUtils.isNullOrEmpty(name_para)) {
            sqlBuilder.append("AND (party.USERNAME LIKE ? OR party.USERCODE LIKE ?) ");
            params.add("%"+name_para+"%");
            params.add("%"+name_para+"%");
        }
        
        if (operate != null) {
            sqlBuilder.append("AND apply.OPERATE=? ");
            params.add(operate);
        }
        
        sqlBuilder.append("ORDER BY apply.CREATE_TIME DESC LIMIT ?,?");
        params.add(page.getFirstElementNumber());
        params.add(pageSize);
        
        List<HashMap> list=ApplicationUtil.executeDQL(sqlBuilder.toString(),params.toArray(new Object[params.size()]),HashMap.class);
        page.setElements(list);
        return page;
    }
 
    @Override
    public void savePassed(String id, String operatorUsername, String safeword) {
        UserSafewordApply apply = this.userSafewordApplyService.findById(id);
        
        if (null == apply) {
            throw new BusinessException("申请不存在,或请刷新重试");
        }
        
        if (apply.getStatus() != 1) {
            throw new BusinessException("当前申请已处理");
        }
        
        if (!Arrays.asList(0, 1, 2, 3).contains(apply.getOperate())) {
            throw new BusinessException("操作类型不正确");
        }
        
        this.checkLoginSafeword(operatorUsername, safeword);
        
        Kyc kyc = this.kycService.get(apply.getPartyId().toString());
        if (null == kyc || kyc.getStatus() != 2) {
            throw new BusinessException("认证尚未通过,无法重置");
        }
        
        apply.setApply_time(new Date());
        apply.setStatus(2);
        
        this.userSafewordApplyService.update(apply);
                
        Party party = this.partyService.cachePartyBy(apply.getPartyId(), false);
                
        // 操作类型 operate:     0/修改资金密码;1/取消谷歌绑定;2/取消手机绑定;3/取消邮箱绑定;
        switch (apply.getOperate()) {
            case 0:
                party.setSafeword(apply.getSafeword());
                this.partyService.update(party);
                break;
            case 1:
                SecUser secUser = this.secUserService.findUserByLoginName(party.getUsername());
                if (null == secUser) {
                    throw new BusinessException("用户不存在");
                }
                if (!secUser.isGoogle_auth_bind()) {
                    throw new BusinessException("用户未绑定,无需解绑");
                }                
                secUser.setGoogle_auth_bind(false);
                this.secUserService.update(secUser);
                break;
            case 2:
                party.setPhone_authority(false);
                this.partyService.update(party);
                break;
            case 3:
                party.setEmail_authority(false);
                this.partyService.update(party);
                break;
        }
        
        this.tipService.deleteTip(apply.getId().toString());
    }
 
    @Override
    public void saveFailed(String id, String msg) {
        UserSafewordApply apply = this.userSafewordApplyService.findById(id);
        
        if (null == apply) {
            throw new BusinessException("申请不存在,或请刷新重试");
        }
        
        if (apply.getStatus() != 1) {
            throw new BusinessException("当前申请已处理");
        }
        
        Kyc kyc = this.kycService.get(apply.getPartyId().toString());
        if (null == kyc || kyc.getStatus() != 2) {
            throw new BusinessException("认证尚未通过,无法重置");
        }
        
        apply.setApply_time(new Date());
        apply.setStatus(3);
        apply.setMsg(msg);
        
        this.userSafewordApplyService.update(apply);
        
        this.tipService.deleteTip(apply.getId().toString());
    }
 
    /**
     * 验证登录人资金密码
     * 
     * @param operatorUsername
     * @param loginSafeword
     */
    private void checkLoginSafeword(String operatorUsername, String loginSafeword) {
        SecUser sec = this.secUserService.findUserByLoginName(operatorUsername);
        String sysSafeword = sec.getSafeword();
        String safeword_md5 = passwordEncoder.encodePassword(loginSafeword, operatorUsername);
        if (!safeword_md5.equals(sysSafeword)) {
            throw new BusinessException("登录人资金密码错误");
        }
 
    }
 
    public void setPartyService(PartyService partyService) {
        this.partyService = partyService;
    }
 
    public void setUserRecomService(UserRecomService userRecomService) {
        this.userRecomService = userRecomService;
    }
 
    public void setKycService(KycService kycService) {
        this.kycService = kycService;
    }
 
    public void setUserSafewordApplyService(UserSafewordApplyService userSafewordApplyService) {
        this.userSafewordApplyService = userSafewordApplyService;
    }
 
    public void setPasswordEncoder(PasswordEncoder passwordEncoder) {
        this.passwordEncoder = passwordEncoder;
    }
 
    public void setSecUserService(SecUserService secUserService) {
        this.secUserService = secUserService;
    }
 
    public void setTipService(TipService tipService) {
        this.tipService = tipService;
    }
}