|
|
|
@ -1,19 +1,29 @@
|
|
|
|
|
package com.tz.platform.user.pc.biz;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.crypto.digest.DigestUtil;
|
|
|
|
|
import com.tz.platform.common.core.base.Result;
|
|
|
|
|
import com.tz.platform.common.core.config.SystemUtil;
|
|
|
|
|
import com.tz.platform.common.core.enmus.UserTypeEnum;
|
|
|
|
|
import com.tz.platform.common.core.tools.StrUtil;
|
|
|
|
|
import com.tz.platform.entity.User;
|
|
|
|
|
import com.tz.platform.repository.UserDao;
|
|
|
|
|
import com.tz.platform.user.pc.bo.UserPageBO;
|
|
|
|
|
import com.tz.platform.user.pc.dto.UserDTO;
|
|
|
|
|
import com.tz.platform.user.pc.dto.UserPageDTO;
|
|
|
|
|
import com.tz.platform.user.pc.vo.GetUserVO;
|
|
|
|
|
import com.tz.platform.user.pc.vo.UserVO;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
|
|
import org.springframework.data.domain.*;
|
|
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
|
|
import javax.persistence.criteria.CriteriaBuilder;
|
|
|
|
|
import javax.persistence.criteria.CriteriaQuery;
|
|
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
|
|
import javax.persistence.criteria.Root;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
|
@Component
|
|
|
|
@ -22,12 +32,59 @@ public class PcUserInfoBiz {
|
|
|
|
|
private UserDao userDao;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Result<UserPageDTO> listPage(Integer pageNo){
|
|
|
|
|
if(pageNo<0){
|
|
|
|
|
pageNo = 0;
|
|
|
|
|
public Result<UserPageDTO> listPage(UserPageBO bo){
|
|
|
|
|
if(bo.getPageNo()<=0){
|
|
|
|
|
bo.setPageNo(0);
|
|
|
|
|
}else{
|
|
|
|
|
bo.setPageNo(bo.getPageNo()-1);
|
|
|
|
|
}
|
|
|
|
|
if(bo.getPageSize() <=0){
|
|
|
|
|
bo.setPageSize(20);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(bo.getUserType()<=0){
|
|
|
|
|
bo.setUserType(UserTypeEnum.USER.getCode());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Pageable pageable = PageRequest.of(bo.getPageNo(),bo.getPageSize());
|
|
|
|
|
User user = new User();
|
|
|
|
|
user.setUserType(bo.getUserType());
|
|
|
|
|
if(StringUtils.hasText(bo.getName())){
|
|
|
|
|
if(bo.getName().matches("\\d+")){
|
|
|
|
|
user.setStudentNo(bo.getName());
|
|
|
|
|
}else{
|
|
|
|
|
user.setSchool(bo.getName());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Pageable pageable = PageRequest.of(pageNo,20);
|
|
|
|
|
Page<User> page = userDao.findAllByUserType(UserTypeEnum.USER.getCode(), pageable);
|
|
|
|
|
ExampleMatcher matcher = ExampleMatcher.matching().withIgnoreNullValues();
|
|
|
|
|
Example<User> example = Example.of(user,matcher);
|
|
|
|
|
Page<User> page = userDao.findAll(example,pageable); // userDao.findAllByUserType(bo.getUserType(), pageable);
|
|
|
|
|
UserPageDTO userPageDTO = new UserPageDTO();
|
|
|
|
|
userPageDTO.setUserPage(page);
|
|
|
|
|
return Result.success(userPageDTO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Result<UserPageDTO> listByStudentNoOrSchool(UserPageBO bo){
|
|
|
|
|
if(bo.getPageNo()<=0){
|
|
|
|
|
bo.setPageNo(0);
|
|
|
|
|
}else{
|
|
|
|
|
bo.setPageNo(bo.getPageNo()-1);
|
|
|
|
|
}
|
|
|
|
|
if(bo.getPageSize() <=0){
|
|
|
|
|
bo.setPageSize(20);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(bo.getUserType()<=0){
|
|
|
|
|
bo.setUserType(UserTypeEnum.USER.getCode());
|
|
|
|
|
}
|
|
|
|
|
Pageable pageable = PageRequest.of(bo.getPageNo(),bo.getPageSize());
|
|
|
|
|
Specification<User> specification = new Specification<User>() {
|
|
|
|
|
@Override
|
|
|
|
|
public Predicate toPredicate(Root<User> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Page<User> page = userDao.findAll(specification,pageable);
|
|
|
|
|
UserPageDTO userPageDTO = new UserPageDTO();
|
|
|
|
|
userPageDTO.setUserPage(page);
|
|
|
|
|
return Result.success(userPageDTO);
|
|
|
|
@ -48,4 +105,77 @@ public class PcUserInfoBiz {
|
|
|
|
|
}
|
|
|
|
|
return Result.success(dto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Result<Long> saveUser(UserVO vo){
|
|
|
|
|
|
|
|
|
|
if(vo.getLevelId() == null||vo.getLevelId()<=0){
|
|
|
|
|
return Result.error("层次不能为空");
|
|
|
|
|
}
|
|
|
|
|
if(vo.getProvinceId() == null||vo.getProvinceId()<=0){
|
|
|
|
|
return Result.error("省份不能为空");
|
|
|
|
|
}
|
|
|
|
|
if(StringUtils.isEmpty(vo.getStudentNo())){
|
|
|
|
|
return Result.error("学号不能为空");
|
|
|
|
|
}
|
|
|
|
|
if(StringUtils.isEmpty(vo.getName())){
|
|
|
|
|
return Result.error("姓名不能为空");
|
|
|
|
|
}
|
|
|
|
|
if(StringUtils.isEmpty(vo.getSchool())){
|
|
|
|
|
return Result.error("学校不能为空");
|
|
|
|
|
}
|
|
|
|
|
User creator = userDao.getById(vo.getUserNo());
|
|
|
|
|
|
|
|
|
|
User user = new User();
|
|
|
|
|
BeanUtils.copyProperties(vo,user);
|
|
|
|
|
user.setGmtCreate(new Date());
|
|
|
|
|
user.setUsername(user.getStudentNo());
|
|
|
|
|
user.setGmtModified(new Date());
|
|
|
|
|
if(user.getId()== null){
|
|
|
|
|
user.setMobileSalt(StrUtil.get32UUID());
|
|
|
|
|
user.setMobilePsw(DigestUtil.sha1Hex(user.getMobileSalt() + SystemUtil.INIT_PASSWORD));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(user.getUserType().equals(UserTypeEnum.ADMIN.getCode())&&creator.getUserType()!=3){
|
|
|
|
|
return Result.error("无权添加该用户");
|
|
|
|
|
}
|
|
|
|
|
user = userDao.save(user);
|
|
|
|
|
|
|
|
|
|
return Result.success(user.getId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Result<String> deleteUser(UserVO vo){
|
|
|
|
|
if(vo.getId()==null){
|
|
|
|
|
return Result.error("无该用户信息");
|
|
|
|
|
}
|
|
|
|
|
userDao.deleteById(vo.getId());
|
|
|
|
|
return Result.success("成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Result<Long> saveAdmin(UserVO vo){
|
|
|
|
|
|
|
|
|
|
if(StringUtils.isEmpty(vo.getName())){
|
|
|
|
|
return Result.error("姓名不能为空");
|
|
|
|
|
}
|
|
|
|
|
if(StringUtils.isEmpty(vo.getUserNo())){
|
|
|
|
|
return Result.error("用户名不能为空");
|
|
|
|
|
}
|
|
|
|
|
if(StringUtils.isEmpty(vo.getPassword())){
|
|
|
|
|
return Result.error("密码不能为空");
|
|
|
|
|
}
|
|
|
|
|
User creator = userDao.getById(vo.getUserNo());
|
|
|
|
|
|
|
|
|
|
User user = new User();
|
|
|
|
|
BeanUtils.copyProperties(vo,user);
|
|
|
|
|
user.setGmtCreate(new Date());
|
|
|
|
|
user.setUsername(user.getStudentNo());
|
|
|
|
|
user.setGmtModified(new Date());
|
|
|
|
|
user.setMobileSalt(StrUtil.get32UUID());
|
|
|
|
|
user.setMobilePsw(DigestUtil.sha1Hex(user.getMobileSalt() + vo.getPassword()));
|
|
|
|
|
if(!user.getUserType().equals(UserTypeEnum.USER.getCode())&&creator.getUserType()!=3){
|
|
|
|
|
return Result.error("无权添加该用户");
|
|
|
|
|
}
|
|
|
|
|
user = userDao.save(user);
|
|
|
|
|
|
|
|
|
|
return Result.success(user.getId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|