xufenglei
2017-12-07 dba72443e05e7b0a52ee85bfd9f4641aebc42c60
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
package com.moral.service.impl;
 
import java.util.List;
 
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;
 
import tk.mybatis.mapper.entity.Example;
 
@Service
public class OperateUserServiceImpl implements OperateUserService {
 
    @Resource
    private OperateUserMapper operateUserMapper;
 
    @Override
    public List<OperateUser> getUserList(String mobile) {
        Example example = new Example(OperateUser.class);
        example.or().andEqualTo("mobile", mobile);
        return operateUserMapper.selectByExample(example);
    }
 
    @Override
    public OperateUser mobileLogin(String mobile, String password) {
        Example example = new Example(OperateUser.class);
        example.or().andEqualTo("mobile", mobile).andEqualTo("password", Crypto.md5(password));
        List<OperateUser> operateUsers = operateUserMapper.selectByExample(example);
        if (ObjectUtils.isEmpty(operateUsers) || operateUsers.size() > 1) {
            throw new BusinessException("用户名或密码错误,登陆失败!");
        }else {
            OperateUser operateUser = operateUsers.get(0);
            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;
        }
    }
 
}