cy
2022-06-21 129904537f66509f97b285e7eb4f42b3dc349dd0
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
package cn.ksource.web.facade.loginuser;
 
import java.util.HashMap;
import java.util.Map;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import cn.ksource.core.dao.BaseDao;
import cn.ksource.core.dao.SqlParameter;
import cn.ksource.core.util.JsonUtil;
import cn.ksource.core.util.StringUtil;
import cn.ksource.core.web.PasswordEncoder;
 
@Service("loginUserFacade")
public class LoginUserFacadeImpl implements LoginUserFacade {
    
    @Autowired
    private BaseDao baseDao;
    
    @Override
    public String updateUserPwd(String userId, String oldPassword,String newPassword) {
        Map map = new HashMap();
        if(!(StringUtil.notEmpty(newPassword)&&StringUtil.isPasswordReg(newPassword)&&StringUtil.notEmpty(oldPassword)&&StringUtil.isPasswordReg(oldPassword))) {
            map.put("status", "0");
            map.put("msg", "密码由6-18位的字母,数字,下划线组成");
            return JsonUtil.map2Json(map);
        }
        oldPassword = oldPassword.trim();
        newPassword = newPassword.trim();
        String sql = "SELECT COUNT(ID) FROM GG_USER WHERE ID = :userId AND PASSWORD = :password";
        int count = baseDao.queryForInteger(sql,new SqlParameter("userId",userId).addValue("password", PasswordEncoder.encode(oldPassword)));
        if(count == 0) {
            map.put("status", "0");
            map.put("msg", "原密码输入错误!");
            return JsonUtil.map2Json(map);
        }
        String updateSql = "UPDATE GG_USER SET PASSWORD = :newPassword WHERE ID = :userId";
        baseDao.execute(updateSql, new SqlParameter("newPassword",PasswordEncoder.encode(newPassword)).addValue("userId", userId));
        map.put("status", "1");
        return JsonUtil.map2Json(map);
    }
    
    @Override
    public String updateUserMobile(String userId, String mobile) {
        
        String sql = "UPDATE GG_USER SET SJHM = :phone,ISPHONE = 2 WHERE ID = :userId";
        baseDao.execute(sql, new SqlParameter("phone",mobile).addValue("userId", userId));
        
        return "1";
    }
 
    @Override
    public boolean isPhone(String userId, String mobile) {
        String selectSql = "SELECT COUNT(1) FROM GG_USER WHERE ID = :userId AND SJHM = :phone AND ISPHONE = 2";
        Integer count = baseDao.queryForInteger(selectSql,new SqlParameter("userId",userId).addValue("phone", mobile));
        if(count>0){
            return false;
        }else{
            return true;
        }
    }
 
    @Override
    public boolean isEmail(String userId, String email) {
        String selectSql = "SELECT COUNT(1) FROM GG_USER WHERE ID = :userId AND EMAIL = :phone AND ISEMAIL = 2";
        Integer count = baseDao.queryForInteger(selectSql,new SqlParameter("userId",userId).addValue("phone", email));
        if(count>0){
            return false;
        }else{
            return true;
        }
    }
 
    @Override
    public String updateUserEmail(String userId, String email) {
        String sql = "UPDATE GG_USER SET EMAIL = :email,ISEMAIL = 2 WHERE ID = :userId";
        baseDao.execute(sql, new SqlParameter("email",email).addValue("userId", userId));
        
        return "1";
    }
 
    @Override
    public int getUserByPwd(String userId, String pwd) {
        String sql = "SELECT COUNT(ID) FROM GG_USER WHERE ID = :userId AND PASSWORD = :password";
        int count = baseDao.queryForInteger(sql,new SqlParameter("userId",userId).addValue("password", PasswordEncoder.encode(pwd)));
        return count;
    }
 
}