可正常启动
This commit is contained in:
parent
130ff8b592
commit
00de9c57cb
@ -4,9 +4,8 @@ import com.qqchen.deploy.backend.dto.RoleDTO;
|
|||||||
import com.qqchen.deploy.backend.entity.Role;
|
import com.qqchen.deploy.backend.entity.Role;
|
||||||
import com.qqchen.deploy.backend.framework.converter.BaseConverter;
|
import com.qqchen.deploy.backend.framework.converter.BaseConverter;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
import org.mapstruct.ReportingPolicy;
|
|
||||||
|
|
||||||
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
@Mapper(config = BaseConverter.class)
|
||||||
public interface RoleConverter extends BaseConverter<Role, RoleDTO> {
|
public interface RoleConverter extends BaseConverter<Role, RoleDTO> {
|
||||||
// MapStruct 会自动实现必要的方法
|
// MapStruct 会自动实现所有方法
|
||||||
}
|
}
|
||||||
@ -2,10 +2,11 @@ package com.qqchen.deploy.backend.converter;
|
|||||||
|
|
||||||
import com.qqchen.deploy.backend.dto.TenantDTO;
|
import com.qqchen.deploy.backend.dto.TenantDTO;
|
||||||
import com.qqchen.deploy.backend.entity.Tenant;
|
import com.qqchen.deploy.backend.entity.Tenant;
|
||||||
import com.qqchen.deploy.backend.framework.converter.AbstractConverter;
|
|
||||||
import com.qqchen.deploy.backend.framework.converter.BaseConverter;
|
import com.qqchen.deploy.backend.framework.converter.BaseConverter;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
|
|
||||||
|
|
||||||
@Mapper(config = BaseConverter.class)
|
@Mapper(config = BaseConverter.class)
|
||||||
public abstract class TenantConverter extends AbstractConverter<Tenant, TenantDTO> implements BaseConverter<Tenant, TenantDTO> {
|
public interface TenantConverter extends BaseConverter<Tenant, TenantDTO> {
|
||||||
|
// MapStruct 会自动实现所有方法
|
||||||
}
|
}
|
||||||
@ -1,11 +1,11 @@
|
|||||||
package com.qqchen.deploy.backend.converter;
|
package com.qqchen.deploy.backend.converter;
|
||||||
|
|
||||||
import com.qqchen.deploy.backend.framework.converter.AbstractConverter;
|
|
||||||
import com.qqchen.deploy.backend.framework.converter.BaseConverter;
|
import com.qqchen.deploy.backend.framework.converter.BaseConverter;
|
||||||
import com.qqchen.deploy.backend.entity.User;
|
import com.qqchen.deploy.backend.entity.User;
|
||||||
import com.qqchen.deploy.backend.dto.UserDTO;
|
import com.qqchen.deploy.backend.dto.UserDTO;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
|
|
||||||
@Mapper(config = BaseConverter.class)
|
@Mapper(config = BaseConverter.class)
|
||||||
public abstract class UserConverter extends AbstractConverter<User, UserDTO> implements BaseConverter<User, UserDTO> {
|
public interface UserConverter extends BaseConverter<User, UserDTO> {
|
||||||
|
// MapStruct 会自动实现所有方法
|
||||||
}
|
}
|
||||||
@ -11,5 +11,6 @@ import java.lang.annotation.Target;
|
|||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public @interface QueryField {
|
public @interface QueryField {
|
||||||
String field() default ""; // 实体类中的字段名
|
String field() default ""; // 实体类中的字段名
|
||||||
|
|
||||||
QueryType type() default QueryType.EQUAL; // 查询方式
|
QueryType type() default QueryType.EQUAL; // 查询方式
|
||||||
}
|
}
|
||||||
@ -1,29 +0,0 @@
|
|||||||
package com.qqchen.deploy.backend.framework.converter;
|
|
||||||
|
|
||||||
import com.qqchen.deploy.backend.framework.domain.Entity;
|
|
||||||
import com.qqchen.deploy.backend.framework.dto.BaseDTO;
|
|
||||||
import org.springframework.core.GenericTypeResolver;
|
|
||||||
|
|
||||||
public abstract class AbstractConverter<T extends Entity<?>, D extends BaseDTO> {
|
|
||||||
|
|
||||||
private final Class<T> entityClass;
|
|
||||||
private final Class<D> dtoClass;
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
protected AbstractConverter() {
|
|
||||||
Class<?>[] genericTypes = GenericTypeResolver.resolveTypeArguments(getClass(), AbstractConverter.class);
|
|
||||||
if (genericTypes == null || genericTypes.length < 2) {
|
|
||||||
throw new IllegalStateException("Could not resolve generic types");
|
|
||||||
}
|
|
||||||
this.entityClass = (Class<T>) genericTypes[0];
|
|
||||||
this.dtoClass = (Class<D>) genericTypes[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
public Class<T> getEntityClass() {
|
|
||||||
return entityClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Class<D> getDtoClass() {
|
|
||||||
return dtoClass;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -59,5 +59,4 @@ public interface BaseConverter<T extends Entity<?>, D extends BaseDTO> {
|
|||||||
.map(this::toEntity)
|
.map(this::toEntity)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1,5 +1,6 @@
|
|||||||
package com.qqchen.deploy.backend.framework.repository;
|
package com.qqchen.deploy.backend.framework.repository;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import com.qqchen.deploy.backend.framework.domain.Entity;
|
import com.qqchen.deploy.backend.framework.domain.Entity;
|
||||||
import jakarta.persistence.LockModeType;
|
import jakarta.persistence.LockModeType;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
@ -17,14 +18,12 @@ import java.util.List;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
@NoRepositoryBean
|
@NoRepositoryBean
|
||||||
public interface IBaseRepository<T extends Entity<ID>, ID extends Serializable>
|
public interface IBaseRepository<T extends Entity<ID>, ID extends Serializable>
|
||||||
extends JpaRepository<T, ID>, QuerydslPredicateExecutor<T> {
|
extends JpaRepository<T, ID>, QuerydslPredicateExecutor<T> {
|
||||||
// extends JpaRepository<T, ID>, QuerydslPredicateExecutor<T>, JpaSpecificationExecutor<T> {
|
|
||||||
|
|
||||||
|
|
||||||
|
// 基础查询方法
|
||||||
@Override
|
@Override
|
||||||
@Query("select e from #{#entityName} e where e.deleted = false")
|
@Query("select e from #{#entityName} e where e.deleted = false")
|
||||||
List<T> findAll();
|
List<T> findAll();
|
||||||
@ -33,6 +32,7 @@ public interface IBaseRepository<T extends Entity<ID>, ID extends Serializable>
|
|||||||
@Query("select e from #{#entityName} e where e.id = ?1 and e.deleted = false")
|
@Query("select e from #{#entityName} e where e.id = ?1 and e.deleted = false")
|
||||||
Optional<T> findById(ID id);
|
Optional<T> findById(ID id);
|
||||||
|
|
||||||
|
// 逻辑删除
|
||||||
@Override
|
@Override
|
||||||
default void delete(T entity) {
|
default void delete(T entity) {
|
||||||
entity.setDeleted(true);
|
entity.setDeleted(true);
|
||||||
@ -46,12 +46,18 @@ public interface IBaseRepository<T extends Entity<ID>, ID extends Serializable>
|
|||||||
|
|
||||||
// 批量操作
|
// 批量操作
|
||||||
@Modifying
|
@Modifying
|
||||||
@Query("update #{#entityName} e set e.deleted = true where e.id in ?1")
|
@Query("update #{#entityName} e set e.deleted = true where e.id in :ids")
|
||||||
void logicDeleteByIds(Collection<ID> ids);
|
void batchDelete(@Param("ids") Collection<ID> ids);
|
||||||
|
|
||||||
// @Modifying
|
@Modifying
|
||||||
// @Query("update #{#entityName} e set e.enabled = ?2 where e.id in ?1")
|
@Query("UPDATE #{#entityName} e SET e.updateTime = :updateTime, " +
|
||||||
// void updateEnabledByIds(Collection<ID> ids, boolean enabled);
|
"e.updateBy = :updateBy, e.version = e.version + 1 " +
|
||||||
|
"WHERE e.id IN :ids")
|
||||||
|
void batchUpdate(
|
||||||
|
@Param("ids") Collection<ID> ids,
|
||||||
|
@Param("updateTime") LocalDateTime updateTime,
|
||||||
|
@Param("updateBy") String updateBy
|
||||||
|
);
|
||||||
|
|
||||||
// 快速查询方法
|
// 快速查询方法
|
||||||
Optional<T> findByIdAndDeletedFalse(ID id);
|
Optional<T> findByIdAndDeletedFalse(ID id);
|
||||||
@ -60,105 +66,37 @@ public interface IBaseRepository<T extends Entity<ID>, ID extends Serializable>
|
|||||||
|
|
||||||
boolean existsByIdAndDeletedFalse(ID id);
|
boolean existsByIdAndDeletedFalse(ID id);
|
||||||
|
|
||||||
// 自定义查询
|
// 条件查询
|
||||||
@Query("select e from #{#entityName} e where e.deleted = false and " +
|
@Query("select e from #{#entityName} e where e.deleted = false and " +
|
||||||
"(?1 is null or e.createTime >= ?1) and " +
|
"(:start is null or e.createTime >= :start) and " +
|
||||||
"(?2 is null or e.createTime <= ?2)")
|
"(:end is null or e.createTime <= :end)")
|
||||||
List<T> findByCreateTimeBetween(LocalDateTime start, LocalDateTime end);
|
List<T> findByCreateTimeBetween(
|
||||||
|
@Param("start") LocalDateTime start,
|
||||||
|
@Param("end") LocalDateTime end
|
||||||
|
);
|
||||||
|
|
||||||
@Query("select e from #{#entityName} e where e.deleted = false and " +
|
@Query("select e from #{#entityName} e where e.deleted = false and " +
|
||||||
"(?1 is null or e.createBy = ?1)")
|
"(:creator is null or e.createBy = :creator)")
|
||||||
List<T> findByCreateBy(String creator);
|
List<T> findByCreateBy(@Param("creator") String creator);
|
||||||
|
|
||||||
|
@Query("select e from #{#entityName} e where e.deleted = false " +
|
||||||
|
"order by e.createTime desc")
|
||||||
|
List<T> findLatest(Pageable pageable);
|
||||||
|
|
||||||
// 统计方法
|
// 统计方法
|
||||||
@Query("select count(e) from #{#entityName} e where e.deleted = false")
|
@Query("select count(e) from #{#entityName} e where e.deleted = false")
|
||||||
long countNonDeleted();
|
long countNonDeleted();
|
||||||
|
|
||||||
// @Query("select count(e) from #{#entityName} e where e.deleted = false and e.enabled = ?1")
|
// QueryDSL支持
|
||||||
// long countByEnabled(boolean enabled);
|
|
||||||
|
|
||||||
// 高级查询
|
|
||||||
@Query("select e from #{#entityName} e where e.deleted = false " +
|
|
||||||
"order by e.createTime desc")
|
|
||||||
List<T> findLatest(Pageable pageable);
|
|
||||||
|
|
||||||
@Query("select distinct e.createBy from #{#entityName} e where e.deleted = false")
|
|
||||||
List<String> findAllCreators();
|
|
||||||
|
|
||||||
// 批量更新
|
|
||||||
@Modifying
|
|
||||||
@Query("update #{#entityName} e set e.updateBy = ?2, e.updateTime = ?3 where e.id in ?1")
|
|
||||||
void updateAuditInfo(Collection<ID> ids, String updateBy, LocalDateTime updateTime);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据条件查询并排序
|
|
||||||
*/
|
|
||||||
default List<T> findAllByCondition(com.querydsl.core.types.Predicate predicate, Sort sort) {
|
default List<T> findAllByCondition(com.querydsl.core.types.Predicate predicate, Sort sort) {
|
||||||
Iterable<T> iterable = findAll(predicate, sort);
|
return Lists.newArrayList(findAll(predicate, sort));
|
||||||
List<T> result = new ArrayList<>();
|
|
||||||
iterable.forEach(result::add);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 批量保存并返回保存的实体
|
// 乐观锁支持
|
||||||
default List<T> saveAllAndReturn(Iterable<T> entities) {
|
|
||||||
return saveAll(entities);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据条件查询并排序
|
|
||||||
* 使用QueryDSL的Predicate进行条件查询
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
Iterable<T> findAll(com.querydsl.core.types.Predicate predicate);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
Iterable<T> findAll(com.querydsl.core.types.Predicate predicate, Sort sort);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 提供一个默认的转换方法
|
|
||||||
*/
|
|
||||||
default List<T> findAllAndConvert(com.querydsl.core.types.Predicate predicate, Sort sort) {
|
|
||||||
Iterable<T> iterable = findAll(predicate, sort);
|
|
||||||
List<T> result = new ArrayList<>();
|
|
||||||
iterable.forEach(result::add);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 批量插入优化
|
|
||||||
@Modifying
|
|
||||||
@Query(value = "INSERT INTO #{#entityName} (id, create_time, create_by) VALUES (:id, :createTime, :createBy)",
|
|
||||||
nativeQuery = true)
|
|
||||||
void batchInsert(
|
|
||||||
@Param("id") ID id,
|
|
||||||
@Param("createTime") LocalDateTime createTime,
|
|
||||||
@Param("createBy") String createBy
|
|
||||||
);
|
|
||||||
|
|
||||||
// 批量更新优化
|
|
||||||
@Modifying
|
|
||||||
@Query("UPDATE #{#entityName} e SET e.updateTime = :updateTime, e.updateBy = :updateBy WHERE e.id IN :ids")
|
|
||||||
void batchUpdate(
|
|
||||||
@Param("ids") Collection<ID> ids,
|
|
||||||
@Param("updateTime") LocalDateTime updateTime,
|
|
||||||
@Param("updateBy") String updateBy
|
|
||||||
);
|
|
||||||
|
|
||||||
// 批量逻辑删除优化
|
|
||||||
@Modifying
|
|
||||||
@Query("UPDATE #{#entityName} e SET e.deleted = true, e.updateTime = :updateTime, e.updateBy = :updateBy WHERE e.id IN :ids")
|
|
||||||
void batchLogicDelete(
|
|
||||||
@Param("ids") Collection<ID> ids,
|
|
||||||
@Param("updateTime") LocalDateTime updateTime,
|
|
||||||
@Param("updateBy") String updateBy
|
|
||||||
);
|
|
||||||
|
|
||||||
// 添加悲观锁查询
|
|
||||||
@Lock(LockModeType.PESSIMISTIC_WRITE)
|
@Lock(LockModeType.PESSIMISTIC_WRITE)
|
||||||
@Query("SELECT e FROM #{#entityName} e WHERE e.id = :id AND e.deleted = false")
|
@Query("SELECT e FROM #{#entityName} e WHERE e.id = :id AND e.deleted = false")
|
||||||
Optional<T> findByIdWithLock(@Param("id") ID id);
|
Optional<T> findByIdWithLock(@Param("id") ID id);
|
||||||
|
|
||||||
// 批量更新时添加版本控制
|
|
||||||
@Modifying
|
@Modifying
|
||||||
@Query("UPDATE #{#entityName} e SET e.updateTime = :updateTime, " +
|
@Query("UPDATE #{#entityName} e SET e.updateTime = :updateTime, " +
|
||||||
"e.updateBy = :updateBy, e.version = e.version + 1 " +
|
"e.updateBy = :updateBy, e.version = e.version + 1 " +
|
||||||
|
|||||||
@ -23,7 +23,9 @@ import org.springframework.security.web.authentication.UsernamePasswordAuthentic
|
|||||||
public class SecurityConfig {
|
public class SecurityConfig {
|
||||||
|
|
||||||
private final CustomAuthenticationEntryPoint authenticationEntryPoint;
|
private final CustomAuthenticationEntryPoint authenticationEntryPoint;
|
||||||
|
|
||||||
private final UserDetailsService userDetailsService;
|
private final UserDetailsService userDetailsService;
|
||||||
|
|
||||||
private final JwtTokenUtil jwtTokenUtil;
|
private final JwtTokenUtil jwtTokenUtil;
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|||||||
@ -13,7 +13,7 @@ spring:
|
|||||||
show-sql: true
|
show-sql: true
|
||||||
properties:
|
properties:
|
||||||
hibernate:
|
hibernate:
|
||||||
format_sql: false
|
format_sql: true
|
||||||
use_sql_comments: true
|
use_sql_comments: true
|
||||||
dialect: org.hibernate.dialect.MySQL8Dialect
|
dialect: org.hibernate.dialect.MySQL8Dialect
|
||||||
jdbc:
|
jdbc:
|
||||||
@ -36,8 +36,10 @@ logging:
|
|||||||
org.springframework.web: DEBUG
|
org.springframework.web: DEBUG
|
||||||
org.springframework.context.i18n: DEBUG
|
org.springframework.context.i18n: DEBUG
|
||||||
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping: TRACE
|
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping: TRACE
|
||||||
org.hibernate.type.descriptor.sql.BasicBinder: TRACE
|
org.hibernate.SQL: DEBUG
|
||||||
org.hibernate.type.descriptor.sql: TRACE
|
org.hibernate.type.descriptor.sql: TRACE
|
||||||
|
org.hibernate.type.descriptor.sql.BasicBinder: TRACE
|
||||||
|
org.hibernate.orm.jdbc.bind: TRACE
|
||||||
com.qqchen.deploy.backend.framework.utils.EntityPathResolver: DEBUG
|
com.qqchen.deploy.backend.framework.utils.EntityPathResolver: DEBUG
|
||||||
com.qqchen.deploy.backend: DEBUG
|
com.qqchen.deploy.backend: DEBUG
|
||||||
jwt:
|
jwt:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user