1.update avatar path in cms getUserById

main
Gary 12 months ago
parent 15cebc3e42
commit aeaa2a5a0d

@ -3,7 +3,6 @@ package com.luoo.user.controller;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -59,7 +58,7 @@ public class CMSUserController {
@ApiOperation(value = "根据ID查询") @ApiOperation(value = "根据ID查询")
@GetMapping("/{id}") @GetMapping("/{id}")
public Result<UserInfo> findById(@PathVariable String id) { public Result<UserInfo> findById(@PathVariable String id) {
return Result.success(userInfoService.findById(id)); return Result.success(userInfoService.cmsFindById(id));
} }
@ApiOperation(value = "分页+多条件查询") @ApiOperation(value = "分页+多条件查询")
@ -106,6 +105,6 @@ public class CMSUserController {
@GetMapping("/ids/{ids}") @GetMapping("/ids/{ids}")
public Result<List<UserInfo>> orderByField(@PathVariable @VerifyParam(required = true) String ids) { public Result<List<UserInfo>> orderByField(@PathVariable @VerifyParam(required = true) String ids) {
List<String> idList = Arrays.stream(ids.split(",")).map(String::trim).collect(Collectors.toList()); List<String> idList = Arrays.stream(ids.split(",")).map(String::trim).collect(Collectors.toList());
return Result.success(userInfoService.orderByField(idList)); return Result.success(userInfoService.cmsOrderByField(idList));
} }
} }

@ -2,6 +2,7 @@ package com.luoo.user.service;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
@ -93,7 +94,6 @@ public class UserInfoService {
return userInfoDao.getById(id); return userInfoDao.getById(id);
} }
/** /**
* *
* *
@ -117,7 +117,6 @@ public class UserInfoService {
userInfoDao.deleteById(id); userInfoDao.deleteById(id);
} }
public void sendSms(String deviceId, String mobile) { public void sendSms(String deviceId, String mobile) {
// 生成6位数字随机数 // 生成6位数字随机数
String checkcode = RandomStringUtils.randomNumeric(6); String checkcode = RandomStringUtils.randomNumeric(6);
@ -129,7 +128,7 @@ public class UserInfoService {
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
map.put("mobile", mobile); map.put("mobile", mobile);
map.put("checkcode", checkcode); map.put("checkcode", checkcode);
rabbitTemplate.convertAndSend("sms",map); rabbitTemplate.convertAndSend("sms", map);
// 在控制台放一份(方便测试) // 在控制台放一份(方便测试)
@ -173,20 +172,21 @@ public class UserInfoService {
} }
public String autoLogin(String authorization, String deviceId, String deviceBrand, String ip) { public String autoLogin(String authorization, String deviceId, String deviceBrand, String ip) {
UserLoginDto userLoginDto=jwtUtil.getUserLoginDto(authorization); UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(authorization);
if (null==userLoginDto) { if (null == userLoginDto) {
return null; return null;
} }
UserInfo userInfo = userInfoDao.findById(userLoginDto.getUserId()).get(); UserInfo userInfo = userInfoDao.findById(userLoginDto.getUserId()).get();
if (!UserStatusEnum.ENABLE.getStatus().equals(userInfo.getStatus())) { if (!UserStatusEnum.ENABLE.getStatus().equals(userInfo.getStatus())) {
return null; return null;
} }
userInfo.setLastLoginTime(new Date()); userInfo.setLastLoginTime(new Date());
userInfo.setLastLoginIp(ip); userInfo.setLastLoginIp(ip);
userInfo.setLastUseDeviceId(deviceId); userInfo.setLastUseDeviceId(deviceId);
userInfo.setLastUseDeviceBrand(deviceBrand); userInfo.setLastUseDeviceBrand(deviceBrand);
userInfoDao.save(userInfo); userInfoDao.save(userInfo);
return Constants.TOKEN_PREFIX+jwtUtil.createJWT(userLoginDto.getUserId(), userInfo.getNickName(), userLoginDto.getRoles(),userLoginDto.getAvatar()); return Constants.TOKEN_PREFIX + jwtUtil.createJWT(userLoginDto.getUserId(), userInfo.getNickName(),
userLoginDto.getRoles(), userLoginDto.getAvatar());
} }
public long countByNickName(String nickName) { public long countByNickName(String nickName) {
@ -199,11 +199,11 @@ public class UserInfoService {
user = userInfo; user = userInfo;
user.setId(String.valueOf(idWorker.nextId())); user.setId(String.valueOf(idWorker.nextId()));
user.setNickName("雀乐-" + NickNameUtil.getRandomNickName()); user.setNickName("雀乐-" + NickNameUtil.getRandomNickName());
Date curDate = new Date(); Date curDate = new Date();
user.setJoinTime(curDate); user.setJoinTime(curDate);
user.setLastLoginTime(curDate); user.setLastLoginTime(curDate);
user.setStatus(UserStatusEnum.ENABLE.getStatus()); user.setStatus(UserStatusEnum.ENABLE.getStatus());
user.setAvatar(Constants.DEFAULT_USER_AVATAR); user.setAvatar(Constants.DEFAULT_USER_AVATAR);
} else { } else {
user.setLastUseDeviceId(userInfo.getLastUseDeviceId()); user.setLastUseDeviceId(userInfo.getLastUseDeviceId());
user.setLastUseDeviceBrand(userInfo.getLastUseDeviceBrand()); user.setLastUseDeviceBrand(userInfo.getLastUseDeviceBrand());
@ -211,51 +211,58 @@ public class UserInfoService {
} }
user.setLastLoginTime(new Date()); user.setLastLoginTime(new Date());
userInfoDao.save(user); userInfoDao.save(user);
return Constants.TOKEN_PREFIX+jwtUtil.createJWT(user.getId(),user.getNickName(),Constants.TOKEN_ROLE_APP_USER,user.getAvatar()); return Constants.TOKEN_PREFIX
+ jwtUtil.createJWT(user.getId(), user.getNickName(), Constants.TOKEN_ROLE_APP_USER, user.getAvatar());
} }
public List<UserInfo> orderByField(List<String> idList) { public List<UserInfo> orderByField(List<String> idList) {
return userInfoDao.orderByField(idList); return userInfoDao.orderByField(idList);
} }
public List<UserInfo> cmsOrderByField(List<String> idList) {
return orderByField(idList).stream().map(this::updateAvatarPath).collect(Collectors.toList());
}
public List<SimpleUser> getSimpleUserOrderByField(List<String> idList) { public List<SimpleUser> getSimpleUserOrderByField(List<String> idList) {
return userInfoDao.getSimpleUserOrderByField(idList); return userInfoDao.getSimpleUserOrderByField(idList);
} }
public Page<UserInfo> findSearch(UserQueryReq queryReq) { public Page<UserInfo> findSearch(UserQueryReq queryReq) {
Specification<UserInfo> specification = createUserInfoSpecification(queryReq); Specification<UserInfo> specification = createUserInfoSpecification(queryReq);
PageRequest pageRequest = PageRequest.of(queryReq.getPageNum()-1, queryReq.getPageSize()); PageRequest pageRequest = PageRequest.of(queryReq.getPageNum() - 1, queryReq.getPageSize());
Page<UserInfo> userInfoPage = userInfoDao.findAll(specification, pageRequest); Page<UserInfo> userInfoPage = userInfoDao.findAll(specification, pageRequest);
return userInfoPage.map(this::updateAvatarPath); return userInfoPage.map(this::updateAvatarPath);
} }
private UserInfo updateAvatarPath(UserInfo userInfo) { private UserInfo updateAvatarPath(UserInfo userInfo) {
if (null != userInfo.getAvatar()) { if (null != userInfo && null != userInfo.getAvatar()) {
userInfo.setAvatar(Constants.RESOURCE_PREFIX + userInfo.getAvatar()); userInfo.setAvatar(Constants.RESOURCE_PREFIX + userInfo.getAvatar());
} }
return userInfo; return userInfo;
} }
public Page<UserInfo> findSearch(UserQueryReq queryReq, int page, int size) { public Page<UserInfo> findSearch(UserQueryReq queryReq, int page, int size) {
Specification<UserInfo> specification = createUserInfoSpecification(queryReq); Specification<UserInfo> specification = createUserInfoSpecification(queryReq);
PageRequest pageRequest = PageRequest.of(page - 1, size); PageRequest pageRequest = PageRequest.of(page - 1, size);
return userInfoDao.findAll(specification, pageRequest); return userInfoDao.findAll(specification, pageRequest);
} }
private Specification<UserInfo> createUserInfoSpecification(UserQueryReq queryReq) { private Specification<UserInfo> createUserInfoSpecification(UserQueryReq queryReq) {
return (root, criteriaQuery, criteriaBuilder) -> { return (root, criteriaQuery, criteriaBuilder) -> {
List<Predicate> predicateList = new ArrayList<>(); List<Predicate> predicateList = new ArrayList<>();
if(StringUtils.isNotBlank(queryReq.getId())){ if (StringUtils.isNotBlank(queryReq.getId())) {
predicateList.add(criteriaBuilder.equal(root.get("id"), queryReq.getId())); predicateList.add(criteriaBuilder.equal(root.get("id"), queryReq.getId()));
} }
if(StringUtils.isNotBlank(queryReq.getMobile())){ if (StringUtils.isNotBlank(queryReq.getMobile())) {
predicateList.add(criteriaBuilder.equal(root.get("mobile").as(String.class), queryReq.getMobile())); predicateList.add(criteriaBuilder.equal(root.get("mobile").as(String.class), queryReq.getMobile()));
} }
if(StringUtils.isNotBlank(queryReq.getNickName())){ if (StringUtils.isNotBlank(queryReq.getNickName())) {
predicateList.add(criteriaBuilder.like(root.get("nickName"), '%'+queryReq.getNickName()+'%')); predicateList.add(criteriaBuilder.like(root.get("nickName"), '%' + queryReq.getNickName() + '%'));
} }
if(StringUtils.isNotBlank(queryReq.getBadge())){ if (StringUtils.isNotBlank(queryReq.getBadge())) {
predicateList.add(criteriaBuilder.equal(root.get("badge").as(String.class), queryReq.getBadge())); predicateList.add(criteriaBuilder.equal(root.get("badge").as(String.class), queryReq.getBadge()));
} }
if(Objects.nonNull(queryReq.getStatus())){ if (Objects.nonNull(queryReq.getStatus())) {
predicateList.add(criteriaBuilder.equal(root.get("status").as(Integer.class), queryReq.getStatus())); predicateList.add(criteriaBuilder.equal(root.get("status").as(Integer.class), queryReq.getStatus()));
} }
/* /*
@ -263,12 +270,12 @@ public class UserInfoService {
* predicateList.add(criteriaBuilder.equal(root.get("onlineStatus").as(Integer. * predicateList.add(criteriaBuilder.equal(root.get("onlineStatus").as(Integer.
* class), queryReq.getOnlineStatus())); } * class), queryReq.getOnlineStatus())); }
*/ */
if(Objects.nonNull(queryReq.getCreateDateStart())){ if (Objects.nonNull(queryReq.getCreateDateStart())) {
predicateList.add(criteriaBuilder.greaterThanOrEqualTo(root.get("joinTime").as(Date.class), predicateList.add(criteriaBuilder.greaterThanOrEqualTo(root.get("joinTime").as(Date.class),
queryReq.getCreateDateStart())); queryReq.getCreateDateStart()));
} }
if(Objects.nonNull(queryReq.getCreateDateEnd())){ if (Objects.nonNull(queryReq.getCreateDateEnd())) {
predicateList.add(criteriaBuilder.lessThanOrEqualTo(root.get("joinTime").as(Date.class), predicateList.add(criteriaBuilder.lessThanOrEqualTo(root.get("joinTime").as(Date.class),
queryReq.getCreateDateEnd())); queryReq.getCreateDateEnd()));
} }
@ -277,5 +284,8 @@ public class UserInfoService {
}; };
} }
public UserInfo cmsFindById(String id) {
return updateAvatarPath(userInfoDao.getById(id));
}
} }

Loading…
Cancel
Save