重构用户角色类 6
This commit is contained in:
parent
f3bff41275
commit
9f0d962225
@ -2,7 +2,7 @@ package com.xkrs.common.account;
|
||||
|
||||
import com.xkrs.common.encapsulation.OutputEncapsulation;
|
||||
import com.xkrs.common.encapsulation.PromptMessageEnum;
|
||||
import com.xkrs.straw.model.vo.SysUserVo;
|
||||
import com.xkrs.straw.model.entity.SysUserEntity;
|
||||
import com.xkrs.straw.service.SysUserService;
|
||||
import com.xkrs.utils.IpUtil;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
@ -78,7 +78,7 @@ public class JwtLoginFilter extends AbstractAuthenticationProcessingFilter {
|
||||
}
|
||||
//更新用户登录信息
|
||||
sysUserService.updateSysUserLogin(auth.getName(), IpUtil.getIpAddr(req));
|
||||
SysUserVo userByUserName = sysUserService.getUserByUserName(auth.getName());
|
||||
SysUserEntity userByUserName = sysUserService.getUserByUserName(auth.getName());
|
||||
response.setHeader("Access-Control-Allow-Origin", "*");
|
||||
response.setHeader("Access-Control-Allow-Credentials", "false");
|
||||
response.setContentType("application/json");
|
||||
|
@ -2,7 +2,7 @@ package com.xkrs.common.account;
|
||||
|
||||
import com.xkrs.common.encapsulation.OutputEncapsulation;
|
||||
import com.xkrs.common.encapsulation.PromptMessageEnum;
|
||||
import com.xkrs.straw.model.vo.SysUserVo;
|
||||
import com.xkrs.straw.model.entity.SysUserEntity;
|
||||
import io.jsonwebtoken.Claims;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.security.Keys;
|
||||
@ -52,7 +52,7 @@ public class TokenAuthenticationService {
|
||||
* @param userName
|
||||
* @param authorities
|
||||
*/
|
||||
static void addAuthentication(HttpServletResponse response, String userName, Collection<? extends GrantedAuthority> authorities, SysUserVo sysUserEntity) {
|
||||
static void addAuthentication(HttpServletResponse response, String userName, Collection<? extends GrantedAuthority> authorities, SysUserEntity sysUserEntity) {
|
||||
|
||||
Locale locale = new Locale("zh", "CN");
|
||||
Map map = new HashMap(3);
|
||||
|
@ -10,7 +10,6 @@ import com.xkrs.model.qo.SysUserRemarkQo;
|
||||
import com.xkrs.model.qo.SysUserVipLevelQo;
|
||||
import com.xkrs.model.validation.SysUserQoInsert;
|
||||
import com.xkrs.model.validation.SysUserQoUpdate;
|
||||
import com.xkrs.straw.model.vo.SysUserVo;
|
||||
import com.xkrs.service.RedisService;
|
||||
import com.xkrs.sms.SMSHelper;
|
||||
import com.xkrs.straw.dao.SysUserDao;
|
||||
@ -22,12 +21,14 @@ import com.xkrs.utils.RandomUtil;
|
||||
import org.apache.hc.core5.util.TextUtils;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -275,11 +276,11 @@ public class SysUserController {
|
||||
if (sysUserEntity == null) {
|
||||
return outputEncapsulationObject(PromptMessageEnum.USER_LOGIN_ERROR, "您还没有注册登录,请先注册登录", locale);
|
||||
}
|
||||
List<SysUserVo> sysUserVos = sysUserService.selectAllUser();
|
||||
if (sysUserVos == null || sysUserVos.size() == 0) {
|
||||
List<SysUserEntity> sysUserEntityList = sysUserService.selectAllUser();
|
||||
if (sysUserEntityList == null || sysUserEntityList.size() == 0) {
|
||||
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时还没有任何用户数据", locale);
|
||||
}
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, sysUserVos, locale);
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, sysUserEntityList, locale);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -380,15 +381,24 @@ public class SysUserController {
|
||||
*/
|
||||
@GetMapping("/verificationCodeUpdate")
|
||||
public String verificationCodeUpdate(@RequestParam("phone") String phone) throws Exception {
|
||||
// SysUserVo sysUserVo = sysUserDao.selectUserByUserName(phone);
|
||||
// if (sysUserVo == null) {
|
||||
// return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "手机号错误,请使用您注册的手机号", locale);
|
||||
// }
|
||||
// List<AgentOrgEntity> agentOrgList = agentOrgDao.findAll();
|
||||
// String targetAgentOrgName = FirePointCodeUtils.getTargetAgentOrgName(sysUserVo.getAgentOrgId(), agentOrgList);
|
||||
// String optCode = String.valueOf(RandomUtil.returnCode());
|
||||
// redisService.set(phone, optCode, 10, TimeUnit.MINUTES);
|
||||
// smsHelper.dispatchSMSCode(targetAgentOrgName, phone, optCode);
|
||||
|
||||
Specification<SysUserEntity> specification = (root, criteriaQuery, criteriaBuilder) -> {
|
||||
//查询条件集合
|
||||
List<Predicate> predicateList = new ArrayList<>();
|
||||
predicateList.add(criteriaBuilder.equal(root.get("userName").as(String.class), phone));
|
||||
Predicate[] predicateArray = new Predicate[predicateList.size()];
|
||||
return criteriaBuilder.and(predicateList.toArray(predicateArray));
|
||||
};
|
||||
List<SysUserEntity> sysUserEntityList = sysUserDao.findAll(specification, Sort.by(Sort.Direction.DESC, "id"));
|
||||
if (sysUserEntityList.size() == 0) {
|
||||
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "手机号错误,请使用您注册的手机号", locale);
|
||||
}
|
||||
SysUserEntity sysUserEntity = sysUserEntityList.get(0);
|
||||
List<AgentOrgEntity> agentOrgList = agentOrgDao.findAll();
|
||||
String targetAgentOrgName = FirePointCodeUtils.getTargetAgentOrgName(sysUserEntity.getAgentOrgId(), agentOrgList);
|
||||
String optCode = String.valueOf(RandomUtil.returnCode());
|
||||
redisService.set(phone, optCode, 10, TimeUnit.MINUTES);
|
||||
smsHelper.dispatchSMSCode(targetAgentOrgName, phone, optCode);
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "", locale);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.xkrs.straw.dao;
|
||||
|
||||
import com.xkrs.straw.model.vo.SysUserVo;
|
||||
import com.xkrs.straw.model.entity.SysUserEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
@ -9,8 +8,6 @@ import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public interface SysUserDao extends JpaRepository<SysUserEntity, Long>, JpaSpecificationExecutor<SysUserEntity> {
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.xkrs.straw.service;
|
||||
|
||||
import com.xkrs.model.qo.SysUserQo;
|
||||
import com.xkrs.straw.model.vo.SysUserVo;
|
||||
import com.xkrs.straw.model.entity.SysUserEntity;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@ -81,7 +80,7 @@ public interface SysUserService {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<SysUserVo> selectAllUser();
|
||||
List<SysUserEntity> selectAllUser();
|
||||
|
||||
/**
|
||||
* 启用
|
||||
@ -124,7 +123,7 @@ public interface SysUserService {
|
||||
* @param userName
|
||||
* @return
|
||||
*/
|
||||
SysUserVo getUserByUserName(String userName);
|
||||
SysUserEntity getUserByUserName(String userName);
|
||||
|
||||
/**
|
||||
* 按天数修改账号到期时间
|
||||
|
@ -4,7 +4,6 @@ import com.xkrs.common.encapsulation.PromptMessageEnum;
|
||||
import com.xkrs.dao.StreetDao;
|
||||
import com.xkrs.model.entity.StreetEntity;
|
||||
import com.xkrs.model.qo.SysUserQo;
|
||||
import com.xkrs.straw.model.vo.SysUserVo;
|
||||
import com.xkrs.service.RedisService;
|
||||
import com.xkrs.straw.dao.RelRoleAuthorityDao;
|
||||
import com.xkrs.straw.dao.RelUserRoleDao;
|
||||
@ -18,11 +17,14 @@ import com.xkrs.straw.service.SysUserService;
|
||||
import com.xkrs.utils.DateTimeUtil;
|
||||
import org.apache.http.util.TextUtils;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.security.crypto.keygen.KeyGenerators;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
@ -279,9 +281,8 @@ public class SysUserServiceImpl implements SysUserService {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<SysUserVo> selectAllUser() {
|
||||
// return sysUserDao.selectAll();
|
||||
return null;
|
||||
public List<SysUserEntity> selectAllUser() {
|
||||
return sysUserDao.findAll(Sort.by(Sort.Direction.DESC, "id"));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -351,9 +352,16 @@ public class SysUserServiceImpl implements SysUserService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysUserVo getUserByUserName(String userName) {
|
||||
// return sysUserDao.selectUserByUserName(userName);
|
||||
return null;
|
||||
public SysUserEntity getUserByUserName(String userName) {
|
||||
Specification<SysUserEntity> specification = (root, criteriaQuery, criteriaBuilder) -> {
|
||||
//查询条件集合
|
||||
List<Predicate> predicateList = new ArrayList<>();
|
||||
predicateList.add(criteriaBuilder.equal(root.get("userName").as(String.class), userName));
|
||||
Predicate[] predicateArray = new Predicate[predicateList.size()];
|
||||
return criteriaBuilder.and(predicateList.toArray(predicateArray));
|
||||
};
|
||||
List<SysUserEntity> sysUserEntityList = sysUserDao.findAll(specification, Sort.by(Sort.Direction.DESC, "id"));
|
||||
return sysUserEntityList.get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user