|
@@ -1,20 +1,12 @@
|
|
|
package cn.iselab.mooctest.user.service.impl;
|
|
|
|
|
|
-import cn.iselab.mooctest.user.dao.UserDao;
|
|
|
+import cn.iselab.mooctest.user.mapper.UserMapper;
|
|
|
import cn.iselab.mooctest.user.model.User;
|
|
|
import cn.iselab.mooctest.user.service.UserService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.data.jpa.domain.Specification;
|
|
|
-import org.springframework.data.jpa.domain.Specifications;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import javax.persistence.criteria.CriteriaBuilder;
|
|
|
-import javax.persistence.criteria.CriteriaQuery;
|
|
|
-import javax.persistence.criteria.Predicate;
|
|
|
-import javax.persistence.criteria.Root;
|
|
|
-import java.lang.reflect.Field;
|
|
|
import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* @author sean
|
|
@@ -24,57 +16,45 @@ import java.util.Map;
|
|
|
public class UserServiceImpl implements UserService {
|
|
|
|
|
|
@Autowired
|
|
|
- private UserDao userDao;
|
|
|
+ private UserMapper userMapper;
|
|
|
|
|
|
@Override
|
|
|
public User findByEmail(String email) {
|
|
|
- return userDao.findByEmail(email);
|
|
|
+ return userMapper.findByEmail(email);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public User findByMobile(String mobile) {
|
|
|
- return userDao.findByMobile(mobile);
|
|
|
+ return userMapper.findByMobile(mobile);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public User register(User user) {
|
|
|
- return userDao.save(user);
|
|
|
+ String email = user.getEmail();
|
|
|
+ userMapper.insert(user);
|
|
|
+ user = userMapper.findByEmail(email);
|
|
|
+ return user;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public User findById(Long userId) {
|
|
|
- return userDao.findById(userId);
|
|
|
+ return userMapper.findById(userId);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public User update(User user) {
|
|
|
- return userDao.save(user);
|
|
|
+ userMapper.updateAddress(user);
|
|
|
+ userMapper.updateAvailability(user);
|
|
|
+ userMapper.updateEmail(user);
|
|
|
+ userMapper.updateMobile(user);
|
|
|
+ userMapper.updatePassword(user);
|
|
|
+ userMapper.updatePhotoUrl(user);
|
|
|
+ userMapper.updateName(user);
|
|
|
+ return userMapper.findById(user.getId());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<User> findByCondition(Map<String, String> condition) {
|
|
|
- Specification<User> where = Specifications.where(getUserWhereClause(condition));
|
|
|
- return userDao.findAll(where);
|
|
|
- }
|
|
|
-
|
|
|
- private Specification<User> getUserWhereClause(Map<String, String> condition) {
|
|
|
- return new Specification<User>() {
|
|
|
- @Override
|
|
|
- public Predicate toPredicate(Root<User> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
|
|
|
- Predicate predicate = cb.disjunction();
|
|
|
-
|
|
|
- Field[] fields = User.class.getDeclaredFields();
|
|
|
- for (Field field : fields) {
|
|
|
- String fieldName = field.getName();
|
|
|
- if (condition.containsKey(fieldName)) {
|
|
|
- predicate.getExpressions().add(
|
|
|
- cb.like(root.get(fieldName), "%" + condition.get(fieldName) + "%")
|
|
|
- );
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return predicate;
|
|
|
- }
|
|
|
- };
|
|
|
+ public List<User> findByFuzzyName(String name) {
|
|
|
+ return userMapper.findByFuzzyName(name);
|
|
|
}
|
|
|
}
|