fix(feature/bill): 修复分页查询错误

This commit is contained in:
vertoryao 2024-01-16 15:20:27 +08:00
parent f0b1b1bfe6
commit 21e6a1c05e
6 changed files with 25 additions and 24 deletions

View File

@ -1,10 +1,9 @@
services:
mysql:
image: 'mysql:latest'
image: 'mysql:8.0.35'
environment:
- 'MYSQL_DATABASE=mydatabase'
- 'MYSQL_PASSWORD=secret'
- 'MYSQL_ROOT_PASSWORD=verysecret'
- 'MYSQL_USER=myuser'
- 'MYSQL_DATABASE=study'
- 'MYSQL_PASSWORD=123123'
- 'MYSQL_ROOT_PASSWORD=123123'
ports:
- '3306'
- '3306:3306'

View File

@ -24,8 +24,6 @@ import java.time.LocalDateTime;
@Component
public class CustomAccessDeniedHandler implements AccessDeniedHandler {
private static final Logger logger = LoggerFactory.getLogger(CustomAccessDeniedHandler.class);
private final ObjectMapper objectMapper;
@Override

View File

@ -15,6 +15,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
/**
* @author harry_yao
@ -31,10 +32,10 @@ public class JpaUserDetailsServiceImpl implements UserDetailsService {
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
User user = userRepo.selectByUsername(username);
List<RoleAuthority> authorities= roleAuthoritiesReposity.selectByRoleId(user.getRoleId());
Set<Authority> authorities1=new HashSet<>();
authorities.stream().forEach(authority ->authorities1.add(Authority.valueOf(authority.getAuthority())));
user.role.authorities=authorities1;
List<RoleAuthority> roleAuthorities= roleAuthoritiesReposity.selectByRoleId(user.getRoleId());
user.role.authorities=roleAuthorities.stream()
.map(i -> Authority.valueOf(i.getAuthority()))
.collect(Collectors.toSet());
@ -42,7 +43,7 @@ public class JpaUserDetailsServiceImpl implements UserDetailsService {
// new UsernameNotFoundException("用户 '" + username + "' 不存在!")
// );
// user.getIdentities().stream().filter(identity -> identity.role.enableState == EnableState.启用)
// .forEach(identity -> Hibernate.initialize(identity.role.authorities));
// .forEach(identity -> Hibernate.initialize(identity.role.roleAuthorities));
return UserDetailsImpl.from(user);
}
}

View File

@ -34,7 +34,6 @@ public class UserDetailsImpl implements UserDetails {
public Set<Authority> authorities;
public static UserDetailsImpl from(User user) {
Set<Authority> authorities = user.role.authorities;
return new UserDetailsImpl(
user.id,
user.username,
@ -42,7 +41,7 @@ public class UserDetailsImpl implements UserDetails {
user.enabled,
user.dept,
user.role,
authorities
user.role.authorities
);
}

View File

@ -11,6 +11,7 @@ import lombok.NoArgsConstructor;
import org.springframework.util.StringUtils;
import java.math.BigDecimal;
import java.util.Objects;
/**
* @author ftz
@ -56,16 +57,19 @@ public class BillQuery {
*/
private String companyName;
/**
* 拼接查询条件
* @return
*/
public LambdaQueryWrapper<Bill> wrapper() {
LambdaQueryWrapper<Bill> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(StringUtils.hasText(this.uuid), Bill::getUuid, this.uuid);
queryWrapper.eq(StringUtils.hasText(String.valueOf(this.userId)), Bill::getUserId, this.userId);
queryWrapper.eq(StringUtils.hasText(this.title), Bill::getTitle, this.title);
queryWrapper.eq(StringUtils.hasText(String.valueOf(this.money)), Bill::getMoney, this.money);
queryWrapper.eq(StringUtils.hasText(String.valueOf(this.status)), Bill::getStatus, this.status);
queryWrapper.eq(StringUtils.hasText(String.valueOf(this.type)), Bill::getType, this.type);
queryWrapper.eq(StringUtils.hasText(this.companyName), Bill::getCompanyName, this.companyName);
queryWrapper.eq(Objects.nonNull(this.userId), Bill::getUserId, this.userId);
queryWrapper.like(StringUtils.hasText(this.title), Bill::getTitle, this.title);
queryWrapper.eq(Objects.nonNull(this.money), Bill::getMoney, this.money);
queryWrapper.eq(Objects.nonNull(this.status), Bill::getStatus, this.status);
queryWrapper.like(Objects.nonNull(this.type), Bill::getType, this.type);
queryWrapper.like(StringUtils.hasText(this.companyName), Bill::getCompanyName, this.companyName);
return queryWrapper;
}
}

View File

@ -9,7 +9,7 @@ mybatis-plus:
spring:
datasource:
url: jdbc:mysql://59.110.238.182:3306/study?useSSL=false&allowPublicKeyRetrieval=true&createDatabaseIfNotExist=true&characterEncoding=utf8&serverTimezone=Hongkong
url: jdbc:mysql://localhost:3306/study?useSSL=false&allowPublicKeyRetrieval=true&createDatabaseIfNotExist=true&characterEncoding=utf8&serverTimezone=Hongkong
username: root
password: 2002
password: 123123
driver-class-name: com.mysql.cj.jdbc.Driver