|
|
|
@ -45,7 +45,7 @@ public class UserService {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private UserDao userDao;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private IdWorker idWorker;
|
|
|
|
|
|
|
|
|
@ -55,7 +55,6 @@ public class UserService {
|
|
|
|
|
@Autowired
|
|
|
|
|
private RabbitTemplate rabbitTemplate;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private BCryptPasswordEncoder encoder;
|
|
|
|
|
|
|
|
|
@ -65,7 +64,6 @@ public class UserService {
|
|
|
|
|
@Autowired
|
|
|
|
|
private JwtUtil jwtUtil;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* token解析示例
|
|
|
|
|
*/
|
|
|
|
@ -73,22 +71,22 @@ public class UserService {
|
|
|
|
|
|
|
|
|
|
String userid = (String) request.getAttribute("userid");
|
|
|
|
|
String mobile = (String) request.getAttribute("mobile");
|
|
|
|
|
System.out.println("用户ID"+userid);
|
|
|
|
|
System.out.println("手机号"+mobile);
|
|
|
|
|
System.out.println("用户ID" + userid);
|
|
|
|
|
System.out.println("手机号" + mobile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询全部列表
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public List<User> findAll() {
|
|
|
|
|
return userDao.findAll();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 条件查询+分页
|
|
|
|
|
*
|
|
|
|
|
* @param whereMap
|
|
|
|
|
* @param page
|
|
|
|
|
* @param size
|
|
|
|
@ -96,13 +94,13 @@ public class UserService {
|
|
|
|
|
*/
|
|
|
|
|
public Page<User> findSearch(Map whereMap, int page, int size) {
|
|
|
|
|
Specification<User> specification = createSpecification(whereMap);
|
|
|
|
|
PageRequest pageRequest = PageRequest.of(page-1, size);
|
|
|
|
|
PageRequest pageRequest = PageRequest.of(page - 1, size);
|
|
|
|
|
return userDao.findAll(specification, pageRequest);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 条件查询
|
|
|
|
|
*
|
|
|
|
|
* @param whereMap
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
@ -113,6 +111,7 @@ public class UserService {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据ID查询实体
|
|
|
|
|
*
|
|
|
|
|
* @param id
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
@ -122,13 +121,14 @@ public class UserService {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 增加
|
|
|
|
|
*
|
|
|
|
|
* @param user
|
|
|
|
|
*/
|
|
|
|
|
public void add(User user) {
|
|
|
|
|
user.setId( idWorker.nextId()+"" );
|
|
|
|
|
user.setFanscount(0); //粉丝数
|
|
|
|
|
user.setFollowcount(0); //关注数
|
|
|
|
|
user.setOnline(0L); //在线时长
|
|
|
|
|
user.setId(idWorker.nextId() + "");
|
|
|
|
|
user.setFanscount(0); // 粉丝数
|
|
|
|
|
user.setFollowcount(0); // 关注数
|
|
|
|
|
user.setOnline(0L); // 在线时长
|
|
|
|
|
user.setRegdate(new Date());
|
|
|
|
|
user.setUpdatedate(new Date());
|
|
|
|
|
user.setLastdate(new Date());
|
|
|
|
@ -139,6 +139,7 @@ public class UserService {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改
|
|
|
|
|
*
|
|
|
|
|
* @param user
|
|
|
|
|
*/
|
|
|
|
|
public void update(User user) {
|
|
|
|
@ -147,12 +148,13 @@ public class UserService {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除
|
|
|
|
|
*
|
|
|
|
|
* @param id
|
|
|
|
|
*/
|
|
|
|
|
public void deleteById(String id) {
|
|
|
|
|
|
|
|
|
|
String token = (String) request.getAttribute("claims_admin");
|
|
|
|
|
if (token==null || "".equals(token)) {
|
|
|
|
|
if (token == null || "".equals(token)) {
|
|
|
|
|
throw new RuntimeException("权限不足");
|
|
|
|
|
}
|
|
|
|
|
userDao.deleteById(id);
|
|
|
|
@ -160,6 +162,7 @@ public class UserService {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 动态条件构建
|
|
|
|
|
*
|
|
|
|
|
* @param searchMap
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
@ -170,106 +173,111 @@ public class UserService {
|
|
|
|
|
@Override
|
|
|
|
|
public Predicate toPredicate(Root<User> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
|
|
|
|
|
List<Predicate> predicateList = new ArrayList<Predicate>();
|
|
|
|
|
// ID
|
|
|
|
|
if (searchMap.get("id")!=null && !"".equals(searchMap.get("id"))) {
|
|
|
|
|
predicateList.add(cb.like(root.get("id").as(String.class), "%"+(String)searchMap.get("id")+"%"));
|
|
|
|
|
}
|
|
|
|
|
// 手机号码
|
|
|
|
|
if (searchMap.get("mobile")!=null && !"".equals(searchMap.get("mobile"))) {
|
|
|
|
|
predicateList.add(cb.like(root.get("mobile").as(String.class), "%"+(String)searchMap.get("mobile")+"%"));
|
|
|
|
|
}
|
|
|
|
|
// 用户名
|
|
|
|
|
if (searchMap.get("loginname")!=null && !"".equals(searchMap.get("loginname"))) {
|
|
|
|
|
predicateList.add(cb.like(root.get("loginname").as(String.class), "%"+(String)searchMap.get("loginname")+"%"));
|
|
|
|
|
}
|
|
|
|
|
// 密码
|
|
|
|
|
if (searchMap.get("password")!=null && !"".equals(searchMap.get("password"))) {
|
|
|
|
|
predicateList.add(cb.like(root.get("password").as(String.class), "%"+(String)searchMap.get("password")+"%"));
|
|
|
|
|
}
|
|
|
|
|
// 昵称
|
|
|
|
|
if (searchMap.get("nickname")!=null && !"".equals(searchMap.get("nickname"))) {
|
|
|
|
|
predicateList.add(cb.like(root.get("nickname").as(String.class), "%"+(String)searchMap.get("nickname")+"%"));
|
|
|
|
|
}
|
|
|
|
|
// 性别
|
|
|
|
|
if (searchMap.get("sex")!=null && !"".equals(searchMap.get("sex"))) {
|
|
|
|
|
predicateList.add(cb.like(root.get("sex").as(String.class), "%"+(String)searchMap.get("sex")+"%"));
|
|
|
|
|
}
|
|
|
|
|
// 头像
|
|
|
|
|
if (searchMap.get("avatar")!=null && !"".equals(searchMap.get("avatar"))) {
|
|
|
|
|
predicateList.add(cb.like(root.get("avatar").as(String.class), "%"+(String)searchMap.get("avatar")+"%"));
|
|
|
|
|
}
|
|
|
|
|
// E-Mail
|
|
|
|
|
if (searchMap.get("email")!=null && !"".equals(searchMap.get("email"))) {
|
|
|
|
|
predicateList.add(cb.like(root.get("email").as(String.class), "%"+(String)searchMap.get("email")+"%"));
|
|
|
|
|
}
|
|
|
|
|
// 兴趣
|
|
|
|
|
if (searchMap.get("interest")!=null && !"".equals(searchMap.get("interest"))) {
|
|
|
|
|
predicateList.add(cb.like(root.get("interest").as(String.class), "%"+(String)searchMap.get("interest")+"%"));
|
|
|
|
|
}
|
|
|
|
|
// 个性
|
|
|
|
|
if (searchMap.get("personality")!=null && !"".equals(searchMap.get("personality"))) {
|
|
|
|
|
predicateList.add(cb.like(root.get("personality").as(String.class), "%"+(String)searchMap.get("personality")+"%"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return cb.and( predicateList.toArray(new Predicate[predicateList.size()]));
|
|
|
|
|
// ID
|
|
|
|
|
if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) {
|
|
|
|
|
predicateList
|
|
|
|
|
.add(cb.like(root.get("id").as(String.class), "%" + (String) searchMap.get("id") + "%"));
|
|
|
|
|
}
|
|
|
|
|
// 手机号码
|
|
|
|
|
if (searchMap.get("mobile") != null && !"".equals(searchMap.get("mobile"))) {
|
|
|
|
|
predicateList.add(
|
|
|
|
|
cb.like(root.get("mobile").as(String.class), "%" + (String) searchMap.get("mobile") + "%"));
|
|
|
|
|
}
|
|
|
|
|
// 用户名
|
|
|
|
|
if (searchMap.get("loginname") != null && !"".equals(searchMap.get("loginname"))) {
|
|
|
|
|
predicateList.add(cb.like(root.get("loginname").as(String.class),
|
|
|
|
|
"%" + (String) searchMap.get("loginname") + "%"));
|
|
|
|
|
}
|
|
|
|
|
// 密码
|
|
|
|
|
if (searchMap.get("password") != null && !"".equals(searchMap.get("password"))) {
|
|
|
|
|
predicateList.add(cb.like(root.get("password").as(String.class),
|
|
|
|
|
"%" + (String) searchMap.get("password") + "%"));
|
|
|
|
|
}
|
|
|
|
|
// 昵称
|
|
|
|
|
if (searchMap.get("nickname") != null && !"".equals(searchMap.get("nickname"))) {
|
|
|
|
|
predicateList.add(cb.like(root.get("nickname").as(String.class),
|
|
|
|
|
"%" + (String) searchMap.get("nickname") + "%"));
|
|
|
|
|
}
|
|
|
|
|
// 性别
|
|
|
|
|
if (searchMap.get("sex") != null && !"".equals(searchMap.get("sex"))) {
|
|
|
|
|
predicateList
|
|
|
|
|
.add(cb.like(root.get("sex").as(String.class), "%" + (String) searchMap.get("sex") + "%"));
|
|
|
|
|
}
|
|
|
|
|
// 头像
|
|
|
|
|
if (searchMap.get("avatar") != null && !"".equals(searchMap.get("avatar"))) {
|
|
|
|
|
predicateList.add(
|
|
|
|
|
cb.like(root.get("avatar").as(String.class), "%" + (String) searchMap.get("avatar") + "%"));
|
|
|
|
|
}
|
|
|
|
|
// E-Mail
|
|
|
|
|
if (searchMap.get("email") != null && !"".equals(searchMap.get("email"))) {
|
|
|
|
|
predicateList.add(
|
|
|
|
|
cb.like(root.get("email").as(String.class), "%" + (String) searchMap.get("email") + "%"));
|
|
|
|
|
}
|
|
|
|
|
// 兴趣
|
|
|
|
|
if (searchMap.get("interest") != null && !"".equals(searchMap.get("interest"))) {
|
|
|
|
|
predicateList.add(cb.like(root.get("interest").as(String.class),
|
|
|
|
|
"%" + (String) searchMap.get("interest") + "%"));
|
|
|
|
|
}
|
|
|
|
|
// 个性
|
|
|
|
|
if (searchMap.get("personality") != null && !"".equals(searchMap.get("personality"))) {
|
|
|
|
|
predicateList.add(cb.like(root.get("personality").as(String.class),
|
|
|
|
|
"%" + (String) searchMap.get("personality") + "%"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return cb.and(predicateList.toArray(new Predicate[predicateList.size()]));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void sendSms(String deviceId,String mobile) {
|
|
|
|
|
public void sendSms(String mobile) {
|
|
|
|
|
// 生成6位数字随机数
|
|
|
|
|
String checkcode = RandomStringUtils.randomNumeric(6);
|
|
|
|
|
// 向缓存中放一份
|
|
|
|
|
String redisKey=Constants.REDIS_KEY_MOBILE_CHECK_CODE+deviceId;
|
|
|
|
|
redisTemplate.opsForValue().set(redisKey,checkcode,15, TimeUnit.MINUTES);
|
|
|
|
|
String redisKey = Constants.REDIS_KEY_MOBILE_CHECK_CODE + mobile;
|
|
|
|
|
redisTemplate.opsForValue().set(redisKey, checkcode, 15, TimeUnit.MINUTES);
|
|
|
|
|
|
|
|
|
|
// 向用户发一份
|
|
|
|
|
Map<String,String> map = new HashMap<>();
|
|
|
|
|
map.put("mobile",mobile);
|
|
|
|
|
map.put("checkcode",checkcode);
|
|
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
|
|
map.put("mobile", mobile);
|
|
|
|
|
map.put("checkcode", checkcode);
|
|
|
|
|
// rabbitTemplate.convertAndSend("sms",map);
|
|
|
|
|
|
|
|
|
|
// 在控制台放一份(方便测试)
|
|
|
|
|
|
|
|
|
|
System.out.println("验证码是:"+checkcode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
System.out.println("验证码是:" + checkcode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public User login(String mobile, String password) {
|
|
|
|
|
// User user = userDao.findByLoginname(loginname);
|
|
|
|
|
User user = userDao.findByMobile(mobile);
|
|
|
|
|
if (user!=null && encoder.matches(password,user.getPassword())) {
|
|
|
|
|
if (user != null && encoder.matches(password, user.getPassword())) {
|
|
|
|
|
return user;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void updatefanscountandfollowcount(int x, String userid, String friendid) {
|
|
|
|
|
userDao.updatefanscount(x,friendid);
|
|
|
|
|
userDao.updatefollowcount(x,userid);
|
|
|
|
|
}
|
|
|
|
|
public User loginOrRegister(String deviceId, String deviceBrand,String mobile) {
|
|
|
|
|
User user = userDao.findByMobile(mobile);
|
|
|
|
|
if(null==user) {
|
|
|
|
|
user=new User();
|
|
|
|
|
user.setId(String.valueOf(idWorker.nextId()));
|
|
|
|
|
user.setMobile(mobile);
|
|
|
|
|
user.setNickname("雀乐"+NickNameUtil.getRandomNickName());
|
|
|
|
|
//user.setDeviceId(deviceId);
|
|
|
|
|
//user.setDeviceBrand(deviceBrand);
|
|
|
|
|
userDao.save(user);
|
|
|
|
|
}
|
|
|
|
|
// else {
|
|
|
|
|
// User updateUser = new User();
|
|
|
|
|
// updateUser.setLastdate(new Date());
|
|
|
|
|
// updateUser.setDeviceId(deviceId);
|
|
|
|
|
// updateUser.setDeviceBrand(deviceBrand);
|
|
|
|
|
// userDao.updateById(updateUser,user.getId());
|
|
|
|
|
// }
|
|
|
|
|
return user;
|
|
|
|
|
}
|
|
|
|
|
public void updatefanscountandfollowcount(int x, String userid, String friendid) {
|
|
|
|
|
userDao.updatefanscount(x, friendid);
|
|
|
|
|
userDao.updatefollowcount(x, userid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public User loginOrRegister(String mobile) {
|
|
|
|
|
User user = userDao.findByMobile(mobile);
|
|
|
|
|
if (null == user) {
|
|
|
|
|
user = new User();
|
|
|
|
|
user.setId(String.valueOf(idWorker.nextId()));
|
|
|
|
|
user.setMobile(mobile);
|
|
|
|
|
user.setNickname("雀乐" + NickNameUtil.getRandomNickName());
|
|
|
|
|
userDao.save(user);
|
|
|
|
|
} else {
|
|
|
|
|
user.setLastdate(new Date());
|
|
|
|
|
userDao.save(user);
|
|
|
|
|
}
|
|
|
|
|
return user;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public User findByMobile(String mobile) {
|
|
|
|
|
User user = userDao.findByMobile(mobile);
|
|
|
|
|
return user;
|
|
|
|
|