1.update cms user request

main
Gary 10 months ago
parent 97211e90ba
commit eed892928b

@ -10,8 +10,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import com.luoo.user.dto.UserQueryReq;
import com.luoo.user.pojo.UserInfo; import com.luoo.user.pojo.UserInfo;
import com.luoo.user.service.UserInfoService; import com.luoo.user.service.UserInfoService;
import annotation.GlobalInterceptor;
import annotation.VerifyParam; import annotation.VerifyParam;
import api.PageResult; import api.PageResult;
import api.Result; import api.Result;
@ -58,36 +61,13 @@ public class CMSUserController {
public Result<UserInfo> findById(@PathVariable String id) { public Result<UserInfo> findById(@PathVariable String id) {
return Result.success(userInfoService.findById(id)); return Result.success(userInfoService.findById(id));
} }
/**
* +
*
* @param searchMap
* @param page
* @param size
* @return
*/
@ApiOperation(value = "分页+多条件查询") @ApiOperation(value = "分页+多条件查询")
@ApiImplicitParams({ @ApiImplicitParam(name = "searchMap", value = "查询条件封装", required = true), @GetMapping("/search")
@ApiImplicitParam(name = "page", value = "页码", required = true), @GlobalInterceptor
@ApiImplicitParam(name = "size", value = "页大小", required = true)}) public Result<PageResult<UserInfo>> findSearch(@VerifyParam(required = true) UserQueryReq userQueryReq) {
@PostMapping("/search/{page}/{size}") Page<UserInfo> pageList =userInfoService.findSearch(userQueryReq);
public Result<PageResult<UserInfo>> findSearch(@RequestBody Map searchMap, @PathVariable int page, return Result.success(new PageResult<UserInfo>(pageList.getTotalElements(),pageList.getContent()));
@PathVariable int size) {
Page<UserInfo> pageList = userInfoService.findSearch(searchMap, page, size);
return Result.success(new PageResult<UserInfo>(pageList.getTotalElements(), pageList.getContent()));
}
/**
*
*
* @param searchMap
* @return
*/
@ApiOperation(value = "根据条件查询")
@PostMapping("/search")
public Result<List<UserInfo>> findSearch(@RequestBody Map searchMap) {
return Result.success(userInfoService.findSearch(searchMap));
} }
/** /**
@ -117,15 +97,15 @@ public class CMSUserController {
/** /**
* UserInfoidsUserInfo * UserInfoidsUserInfo
*
* @param ids * @param ids
* @return * @return
*/ */
@ApiOperation(value = "通过UserInfo用户ids批量查询UserInfo") @ApiOperation(value = "通过UserInfo用户ids批量查询UserInfo")
@ApiImplicitParams({ @ApiImplicitParams({ @ApiImplicitParam(name = "ids", value = "多个id以','分隔", required = true) })
@ApiImplicitParam(name = "ids", value = "多个id以','分隔", required = true) })
@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.orderByField(idList));
} }
} }

@ -0,0 +1,46 @@
package com.luoo.user.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import annotation.VerifyParam;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.util.Date;
/**
* app
*/
@Data
public class UserQueryReq {
@ApiModelProperty(value = "用户ID")
private String id;
@ApiModelProperty(value = "手机号码")
private String mobile;
@ApiModelProperty(value = "昵称")
private String nickName;
@ApiModelProperty(value = "用户标识1:贡献者 2:官方 3: 音乐人")
private String badge;
@ApiModelProperty(value = "账号状态 0:停用 1:正常")
private Integer status;
@ApiModelProperty(value = "在线状态 0:离线 1:在线")
private Integer onlineStatus;
@ApiModelProperty(value = "注册时间-开始")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createDateStart;
@ApiModelProperty(value = "注册时间-结束")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createDateEnd;
@ApiModelProperty(value = "分页: 页码", example = "1")
@VerifyParam(required = true)
private Integer pageNum = 1;
@ApiModelProperty(value = "分页: 每页数量", example = "10")
@VerifyParam(required = true)
private Integer pageSize = 10;
}

@ -63,6 +63,8 @@ public class UserInfo implements Serializable {
/** /**
* *
*/ */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date birthday; private Date birthday;
/** /**
* *

@ -9,6 +9,7 @@ import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root; import javax.persistence.criteria.Root;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -25,7 +26,7 @@ import util.IdWorker;
import constants.Constants; import constants.Constants;
import com.luoo.user.dao.UserInfoDao; import com.luoo.user.dao.UserInfoDao;
import com.luoo.user.pojo.Admin; import com.luoo.user.dto.UserQueryReq;
import com.luoo.user.pojo.UserInfo; import com.luoo.user.pojo.UserInfo;
import com.luoo.user.util.NickNameUtil; import com.luoo.user.util.NickNameUtil;
@ -82,31 +83,6 @@ public class UserInfoService {
return userInfoDao.findAll(); return userInfoDao.findAll();
} }
/**
* +
*
* @param whereMap
* @param page
* @param size
* @return
*/
public Page<UserInfo> findSearch(Map whereMap, int page, int size) {
Specification<UserInfo> specification = createSpecification(whereMap);
PageRequest pageRequest = PageRequest.of(page - 1, size);
return userInfoDao.findAll(specification, pageRequest);
}
/**
*
*
* @param whereMap
* @return
*/
public List<UserInfo> findSearch(Map whereMap) {
Specification<UserInfo> specification = createSpecification(whereMap);
return userInfoDao.findAll(specification);
}
/** /**
* ID * ID
* *
@ -141,76 +117,6 @@ public class UserInfoService {
userInfoDao.deleteById(id); userInfoDao.deleteById(id);
} }
/**
*
*
* @param searchMap
* @return
*/
private Specification<UserInfo> createSpecification(Map searchMap) {
return new Specification<UserInfo>() {
@Override
public Predicate toPredicate(Root<UserInfo> 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()]));
}
};
}
public void sendSms(String deviceId, String mobile) { public void sendSms(String deviceId, String mobile) {
// 生成6位数字随机数 // 生成6位数字随机数
@ -315,4 +221,61 @@ public class UserInfoService {
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) {
Specification<UserInfo> specification = createUserInfoSpecification(queryReq);
PageRequest pageRequest = PageRequest.of(queryReq.getPageNum()-1, queryReq.getPageSize());
Page<UserInfo> userInfoPage = userInfoDao.findAll(specification, pageRequest);
return userInfoPage.map(this::updateAvatarPath);
}
private UserInfo updateAvatarPath(UserInfo userInfo) {
if (null != userInfo.getAvatar()) {
userInfo.setAvatar(Constants.RESOURCE_PREFIX + userInfo.getAvatar());
}
return userInfo;
}
public Page<UserInfo> findSearch(UserQueryReq queryReq, int page, int size) {
Specification<UserInfo> specification = createUserInfoSpecification(queryReq);
PageRequest pageRequest = PageRequest.of(page - 1, size);
return userInfoDao.findAll(specification, pageRequest);
}
private Specification<UserInfo> createUserInfoSpecification(UserQueryReq queryReq) {
return (root, criteriaQuery, criteriaBuilder) -> {
List<Predicate> predicateList = new ArrayList<>();
if(StringUtils.isNotBlank(queryReq.getId())){
predicateList.add(criteriaBuilder.equal(root.get("id"), queryReq.getId()));
}
if(StringUtils.isNotBlank(queryReq.getMobile())){
predicateList.add(criteriaBuilder.equal(root.get("mobile").as(String.class), queryReq.getMobile()));
}
if(StringUtils.isNotBlank(queryReq.getNickName())){
predicateList.add(criteriaBuilder.like(root.get("nickName"), '%'+queryReq.getNickName()+'%'));
}
if(StringUtils.isNotBlank(queryReq.getBadge())){
predicateList.add(criteriaBuilder.equal(root.get("badge").as(String.class), queryReq.getBadge()));
}
if(Objects.nonNull(queryReq.getStatus())){
predicateList.add(criteriaBuilder.equal(root.get("status").as(Integer.class), queryReq.getStatus()));
}
/*
* if(Objects.nonNull(queryReq.getOnlineStatus())){
* predicateList.add(criteriaBuilder.equal(root.get("onlineStatus").as(Integer.
* class), queryReq.getOnlineStatus())); }
*/
if(Objects.nonNull(queryReq.getCreateDateStart())){
predicateList.add(criteriaBuilder.greaterThanOrEqualTo(root.get("joinTime").as(Date.class),
queryReq.getCreateDateStart()));
}
if(Objects.nonNull(queryReq.getCreateDateEnd())){
predicateList.add(criteriaBuilder.lessThanOrEqualTo(root.get("joinTime").as(Date.class),
queryReq.getCreateDateEnd()));
}
Predicate[] predicates = new Predicate[predicateList.size()];
return criteriaBuilder.and(predicateList.toArray(predicates));
};
}
} }

Loading…
Cancel
Save