fix:bug#I8DLHU

V0.5.x
xiwa 2023-11-03 23:10:03 +08:00
parent 0a90c90498
commit 7217438afb
3 changed files with 31 additions and 20 deletions

View File

@ -7,6 +7,7 @@ import cc.iotkit.data.ICommonData;
import cc.iotkit.data.util.PageBuilder; import cc.iotkit.data.util.PageBuilder;
import cc.iotkit.model.Id; import cc.iotkit.model.Id;
import org.springframework.data.domain.Example; import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
@ -21,7 +22,7 @@ import java.util.Optional;
* @Version: V1.0 * @Version: V1.0
* @Description: * @Description:
*/ */
public interface IJPACommData< T extends Id<ID>, ID> extends ICommonData<T , ID> { public interface IJPACommData<T extends Id<ID>, ID> extends ICommonData<T, ID> {
JpaRepository getBaseRepository(); JpaRepository getBaseRepository();
@ -73,15 +74,15 @@ public interface IJPACommData< T extends Id<ID>, ID> extends ICommonData<T , ID
} }
@Override @Override
default Paging<T> findAll(PageRequest<T> pageRequest) { default Paging<T> findAll(PageRequest<T> pageRequest) {
Example example = genExample(pageRequest.getData()); Example example = genExample(pageRequest.getData());
Page<T> all = null; Page<T> all = null;
if(Objects.isNull(example)){ if (Objects.isNull(example)) {
all = getBaseRepository().findAll(PageBuilder.toPageable(pageRequest)); all = getBaseRepository().findAll(PageBuilder.toPageable(pageRequest));
}else{ } else {
all =getBaseRepository().findAll(example, PageBuilder.toPageable(pageRequest)); all = getBaseRepository().findAll(example, PageBuilder.toPageable(pageRequest));
} }
return PageBuilder.toPaging(all, getTClass()); return PageBuilder.toPaging(all, getTClass());
} }
/** /**
@ -91,11 +92,11 @@ public interface IJPACommData< T extends Id<ID>, ID> extends ICommonData<T , ID
default List<T> findAllByCondition(T data) { default List<T> findAllByCondition(T data) {
Example example = genExample(data); Example example = genExample(data);
List all = null; List all = null;
if(Objects.isNull(example)){ if (Objects.isNull(example)) {
all = getBaseRepository().findAll(); all = getBaseRepository().findAll();
}else{ } else {
all = getBaseRepository().findAll(example); all = getBaseRepository().findAll(example);
} }
return MapstructUtils.convert(all, getTClass()); return MapstructUtils.convert(all, getTClass());
@ -109,7 +110,7 @@ public interface IJPACommData< T extends Id<ID>, ID> extends ICommonData<T , ID
Example example = genExample(data); Example example = genExample(data);
Optional one = getBaseRepository().findOne(example); Optional one = getBaseRepository().findOne(example);
if(one.isPresent()){ if (one.isPresent()) {
return (T) MapstructUtils.convert(one.get(), getTClass()); return (T) MapstructUtils.convert(one.get(), getTClass());
} }
return null; return null;
@ -117,11 +118,12 @@ public interface IJPACommData< T extends Id<ID>, ID> extends ICommonData<T , ID
default Example genExample(T data) { default Example genExample(T data) {
if(Objects.isNull(data)){ if (Objects.isNull(data)) {
return null; return null;
} }
return Example.of(MapstructUtils.convert(data, getJpaRepositoryClass())); return Example.of(MapstructUtils.convert(data, getJpaRepositoryClass()),
ExampleMatcher.matching().withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING)
);
} }
} }

View File

@ -108,7 +108,7 @@ public class SysUserDataImpl implements ISysUserData, IJPACommData<SysUser, Long
convert.setRoles(sysRoles); convert.setRoles(sysRoles);
Long deptId = convert.getDeptId(); Long deptId = convert.getDeptId();
if(deptId==null){ if (deptId == null) {
return convert; return convert;
} }
@ -207,7 +207,7 @@ public class SysUserDataImpl implements ISysUserData, IJPACommData<SysUser, Long
.and(StringUtils.isNotBlank(data.getStatus()), () -> tbSysUser.status.eq(data.getStatus())) .and(StringUtils.isNotBlank(data.getStatus()), () -> tbSysUser.status.eq(data.getStatus()))
.and(Objects.nonNull(data.getDeptId()), () -> tbSysUser.deptId.eq(data.getDeptId())) .and(Objects.nonNull(data.getDeptId()), () -> tbSysUser.deptId.eq(data.getDeptId()))
.and(tbSysUser.delFlag.eq(UserConstants.ROLE_NORMAL)) .and(tbSysUser.delFlag.eq(UserConstants.ROLE_NORMAL))
.and(Objects.nonNull(data.getRoleId()),()-> tbSysRole.id.eq(data.getRoleId())); .and(Objects.nonNull(data.getRoleId()), () -> tbSysRole.id.eq(data.getRoleId()));
QueryResults<TbSysUser> tbSysUserQueryResults = jpaQueryFactory.select(Projections.bean(TbSysUser.class, tbSysUser.id, tbSysUser.deptId, tbSysUser.userName, QueryResults<TbSysUser> tbSysUserQueryResults = jpaQueryFactory.select(Projections.bean(TbSysUser.class, tbSysUser.id, tbSysUser.deptId, tbSysUser.userName,
tbSysUser.nickName, tbSysUser.email, tbSysUser.phonenumber, tbSysUser.createTime)).from(tbSysUser) tbSysUser.nickName, tbSysUser.email, tbSysUser.phonenumber, tbSysUser.createTime)).from(tbSysUser)
@ -244,7 +244,7 @@ public class SysUserDataImpl implements ISysUserData, IJPACommData<SysUser, Long
public Paging<SysUser> selectUnallocatedList(PageRequest<SysUser> to) { public Paging<SysUser> selectUnallocatedList(PageRequest<SysUser> to) {
SysUser data = to.getData(); SysUser data = to.getData();
PredicateBuilder builder = PredicateBuilder.instance(); PredicateBuilder builder = PredicateBuilder.instance();
if(Objects.nonNull(data)){ if (Objects.nonNull(data)) {
builder.and(StringUtils.isNotBlank(data.getPhonenumber()), () -> tbSysUser.phonenumber.like(data.getPhonenumber())) builder.and(StringUtils.isNotBlank(data.getPhonenumber()), () -> tbSysUser.phonenumber.like(data.getPhonenumber()))
.and(StringUtils.isNotBlank(data.getUserName()), () -> tbSysUser.userName.like(data.getUserName())) .and(StringUtils.isNotBlank(data.getUserName()), () -> tbSysUser.userName.like(data.getUserName()))
.and(StringUtils.isNotBlank(data.getStatus()), () -> tbSysUser.status.eq(data.getStatus())) .and(StringUtils.isNotBlank(data.getStatus()), () -> tbSysUser.status.eq(data.getStatus()))
@ -303,9 +303,9 @@ public class SysUserDataImpl implements ISysUserData, IJPACommData<SysUser, Long
} }
return PredicateBuilder.instance() return PredicateBuilder.instance()
.and(ObjectUtil.isNotNull(user.getId()), () -> tbSysUser.id.eq(user.getId())) .and(ObjectUtil.isNotNull(user.getId()), () -> tbSysUser.id.eq(user.getId()))
.and(StringUtils.isNotEmpty(user.getUserName()), () -> tbSysUser.userName.like(user.getUserName())) .and(StringUtils.isNotEmpty(user.getUserName()), () -> tbSysUser.userName.like("%" + user.getUserName() + "%"))
.and(StringUtils.isNotEmpty(user.getStatus()), () -> tbSysUser.status.eq(user.getStatus())) .and(StringUtils.isNotEmpty(user.getStatus()), () -> tbSysUser.status.eq(user.getStatus()))
.and(StringUtils.isNotEmpty(user.getPhonenumber()), () -> tbSysUser.phonenumber.like(user.getPhonenumber())) .and(StringUtils.isNotEmpty(user.getPhonenumber()), () -> tbSysUser.phonenumber.like("%" + user.getPhonenumber() + "%"))
.and(ObjectUtil.isNotEmpty(ids), () -> tbSysUser.deptId.in(ids)).build(); .and(ObjectUtil.isNotEmpty(ids), () -> tbSysUser.deptId.in(ids)).build();
} }
} }

View File

@ -9,8 +9,10 @@
*/ */
package cc.iotkit.config; package cc.iotkit.config;
import lombok.extern.slf4j.Slf4j;
import redis.embedded.RedisServer; import redis.embedded.RedisServer;
@Slf4j
public class EmbeddedRedisConfig { public class EmbeddedRedisConfig {
public static boolean embeddedEnable() { public static boolean embeddedEnable() {
@ -28,7 +30,14 @@ public class EmbeddedRedisConfig {
} else { } else {
redisServer = new RedisServer(); redisServer = new RedisServer();
} }
redisServer.start(); try {
redisServer.start();
} catch (Exception e) {
if (e.getMessage().contains("Address already in use")) {
throw new RuntimeException("redis端口被占用请先停止本地的redis服务");
}
log.error("start redis server failed", e);
}
} }
} }