重构用户角色类 6

This commit is contained in:
liuchengqian 2023-02-06 11:25:16 +08:00
parent f3bff41275
commit 9f0d962225
6 changed files with 44 additions and 30 deletions

View File

@ -2,7 +2,7 @@ package com.xkrs.common.account;
import com.xkrs.common.encapsulation.OutputEncapsulation; import com.xkrs.common.encapsulation.OutputEncapsulation;
import com.xkrs.common.encapsulation.PromptMessageEnum; 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.straw.service.SysUserService;
import com.xkrs.utils.IpUtil; import com.xkrs.utils.IpUtil;
import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.context.i18n.LocaleContextHolder;
@ -78,7 +78,7 @@ public class JwtLoginFilter extends AbstractAuthenticationProcessingFilter {
} }
//更新用户登录信息 //更新用户登录信息
sysUserService.updateSysUserLogin(auth.getName(), IpUtil.getIpAddr(req)); 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-Origin", "*");
response.setHeader("Access-Control-Allow-Credentials", "false"); response.setHeader("Access-Control-Allow-Credentials", "false");
response.setContentType("application/json"); response.setContentType("application/json");

View File

@ -2,7 +2,7 @@ package com.xkrs.common.account;
import com.xkrs.common.encapsulation.OutputEncapsulation; import com.xkrs.common.encapsulation.OutputEncapsulation;
import com.xkrs.common.encapsulation.PromptMessageEnum; 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.Claims;
import io.jsonwebtoken.Jwts; import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.security.Keys; import io.jsonwebtoken.security.Keys;
@ -52,7 +52,7 @@ public class TokenAuthenticationService {
* @param userName * @param userName
* @param authorities * @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"); Locale locale = new Locale("zh", "CN");
Map map = new HashMap(3); Map map = new HashMap(3);

View File

@ -10,7 +10,6 @@ import com.xkrs.model.qo.SysUserRemarkQo;
import com.xkrs.model.qo.SysUserVipLevelQo; import com.xkrs.model.qo.SysUserVipLevelQo;
import com.xkrs.model.validation.SysUserQoInsert; import com.xkrs.model.validation.SysUserQoInsert;
import com.xkrs.model.validation.SysUserQoUpdate; import com.xkrs.model.validation.SysUserQoUpdate;
import com.xkrs.straw.model.vo.SysUserVo;
import com.xkrs.service.RedisService; import com.xkrs.service.RedisService;
import com.xkrs.sms.SMSHelper; import com.xkrs.sms.SMSHelper;
import com.xkrs.straw.dao.SysUserDao; import com.xkrs.straw.dao.SysUserDao;
@ -22,12 +21,14 @@ import com.xkrs.utils.RandomUtil;
import org.apache.hc.core5.util.TextUtils; import org.apache.hc.core5.util.TextUtils;
import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.BindingResult; import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.persistence.criteria.Predicate;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -275,11 +276,11 @@ public class SysUserController {
if (sysUserEntity == null) { if (sysUserEntity == null) {
return outputEncapsulationObject(PromptMessageEnum.USER_LOGIN_ERROR, "您还没有注册登录,请先注册登录", locale); return outputEncapsulationObject(PromptMessageEnum.USER_LOGIN_ERROR, "您还没有注册登录,请先注册登录", locale);
} }
List<SysUserVo> sysUserVos = sysUserService.selectAllUser(); List<SysUserEntity> sysUserEntityList = sysUserService.selectAllUser();
if (sysUserVos == null || sysUserVos.size() == 0) { if (sysUserEntityList == null || sysUserEntityList.size() == 0) {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时还没有任何用户数据", locale); 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") @GetMapping("/verificationCodeUpdate")
public String verificationCodeUpdate(@RequestParam("phone") String phone) throws Exception { public String verificationCodeUpdate(@RequestParam("phone") String phone) throws Exception {
// SysUserVo sysUserVo = sysUserDao.selectUserByUserName(phone);
// if (sysUserVo == null) { Specification<SysUserEntity> specification = (root, criteriaQuery, criteriaBuilder) -> {
// return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "手机号错误,请使用您注册的手机号", locale); //查询条件集合
// } List<Predicate> predicateList = new ArrayList<>();
// List<AgentOrgEntity> agentOrgList = agentOrgDao.findAll(); predicateList.add(criteriaBuilder.equal(root.get("userName").as(String.class), phone));
// String targetAgentOrgName = FirePointCodeUtils.getTargetAgentOrgName(sysUserVo.getAgentOrgId(), agentOrgList); Predicate[] predicateArray = new Predicate[predicateList.size()];
// String optCode = String.valueOf(RandomUtil.returnCode()); return criteriaBuilder.and(predicateList.toArray(predicateArray));
// redisService.set(phone, optCode, 10, TimeUnit.MINUTES); };
// smsHelper.dispatchSMSCode(targetAgentOrgName, phone, optCode); 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); return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "", locale);
} }

View File

@ -1,6 +1,5 @@
package com.xkrs.straw.dao; package com.xkrs.straw.dao;
import com.xkrs.straw.model.vo.SysUserVo;
import com.xkrs.straw.model.entity.SysUserEntity; import com.xkrs.straw.model.entity.SysUserEntity;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; 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.data.repository.query.Param;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.List;
@Component @Component
public interface SysUserDao extends JpaRepository<SysUserEntity, Long>, JpaSpecificationExecutor<SysUserEntity> { public interface SysUserDao extends JpaRepository<SysUserEntity, Long>, JpaSpecificationExecutor<SysUserEntity> {

View File

@ -1,7 +1,6 @@
package com.xkrs.straw.service; package com.xkrs.straw.service;
import com.xkrs.model.qo.SysUserQo; import com.xkrs.model.qo.SysUserQo;
import com.xkrs.straw.model.vo.SysUserVo;
import com.xkrs.straw.model.entity.SysUserEntity; import com.xkrs.straw.model.entity.SysUserEntity;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -81,7 +80,7 @@ public interface SysUserService {
* *
* @return * @return
*/ */
List<SysUserVo> selectAllUser(); List<SysUserEntity> selectAllUser();
/** /**
* 启用 * 启用
@ -124,7 +123,7 @@ public interface SysUserService {
* @param userName * @param userName
* @return * @return
*/ */
SysUserVo getUserByUserName(String userName); SysUserEntity getUserByUserName(String userName);
/** /**
* 按天数修改账号到期时间 * 按天数修改账号到期时间

View File

@ -4,7 +4,6 @@ import com.xkrs.common.encapsulation.PromptMessageEnum;
import com.xkrs.dao.StreetDao; import com.xkrs.dao.StreetDao;
import com.xkrs.model.entity.StreetEntity; import com.xkrs.model.entity.StreetEntity;
import com.xkrs.model.qo.SysUserQo; import com.xkrs.model.qo.SysUserQo;
import com.xkrs.straw.model.vo.SysUserVo;
import com.xkrs.service.RedisService; import com.xkrs.service.RedisService;
import com.xkrs.straw.dao.RelRoleAuthorityDao; import com.xkrs.straw.dao.RelRoleAuthorityDao;
import com.xkrs.straw.dao.RelUserRoleDao; import com.xkrs.straw.dao.RelUserRoleDao;
@ -18,11 +17,14 @@ import com.xkrs.straw.service.SysUserService;
import com.xkrs.utils.DateTimeUtil; import com.xkrs.utils.DateTimeUtil;
import org.apache.http.util.TextUtils; import org.apache.http.util.TextUtils;
import org.springframework.context.i18n.LocaleContextHolder; 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.security.crypto.keygen.KeyGenerators;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.persistence.criteria.Predicate;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
@ -279,9 +281,8 @@ public class SysUserServiceImpl implements SysUserService {
* @return * @return
*/ */
@Override @Override
public List<SysUserVo> selectAllUser() { public List<SysUserEntity> selectAllUser() {
// return sysUserDao.selectAll(); return sysUserDao.findAll(Sort.by(Sort.Direction.DESC, "id"));
return null;
} }
/** /**
@ -351,9 +352,16 @@ public class SysUserServiceImpl implements SysUserService {
} }
@Override @Override
public SysUserVo getUserByUserName(String userName) { public SysUserEntity getUserByUserName(String userName) {
// return sysUserDao.selectUserByUserName(userName); Specification<SysUserEntity> specification = (root, criteriaQuery, criteriaBuilder) -> {
return null; //查询条件集合
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);
} }
/** /**