xufenglei
2017-12-07 7214ae59e03b79372a923eae8206082efc3fab85
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
package com.moral.service.impl;
 
import javax.annotation.Resource;
 
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
 
import com.moral.common.exception.BusinessException;
import com.moral.common.util.Crypto;
import com.moral.entity.OperateUser;
import com.moral.mapper.OperateUserMapper;
import com.moral.service.OperateUserService;
 
@Service
public class OperateUserServiceImpl implements OperateUserService {
 
    @Resource
    private OperateUserMapper operateUserMapper;
 
    @Override
    public OperateUser getOperateUserByMobile(String mobile) {
        OperateUser operateUser = new OperateUser();
        operateUser.setMobile(mobile);
        return operateUserMapper.selectOne(operateUser);
    }
 
    @Override
    public OperateUser mobileLogin(String mobile, String password) {
        OperateUser operateUser = new OperateUser();
        operateUser.setMobile(mobile);
        operateUser.setPassword(Crypto.md5(password));
        operateUser = operateUserMapper.selectOne(operateUser);
        if (ObjectUtils.isEmpty(operateUser)) {
            throw new BusinessException("用户名或密码错误,登陆失败!");
        }else {
            operateUser.setPassword(password);
            return operateUser;
        }
    }
 
    @Override
    public OperateUser updatePassword(Integer uid, String password, String newPassword) {
        OperateUser operateUser = operateUserMapper.selectByPrimaryKey(uid);
        if (ObjectUtils.isEmpty(operateUser) || !Crypto.md5(password).equals(operateUser.getPassword())) {
            throw new BusinessException("旧密码错误,修改密码失败!");
        }else {
            operateUser.setPassword(Crypto.md5(newPassword));
            operateUserMapper.updateByPrimaryKeySelective(operateUser);
            operateUser.setPassword(newPassword);
            return operateUser;
        }
    }
 
}