性能优化

This commit is contained in:
2024-04-05 14:25:20 +08:00
parent 9178825cdb
commit fd34756748
20 changed files with 154 additions and 66 deletions

View File

@@ -0,0 +1,9 @@
package cn.lihongjie.coal.annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import java.util.*;
@Retention(java.lang.annotation.RetentionPolicy.RUNTIME)
@Target({java.lang.annotation.ElementType.TYPE})
public @interface ViewEntity {}

View File

@@ -39,12 +39,10 @@ public class CoalWashingDailyAnalysisDto extends OrgCommonDto {
private String archiveStatusName;
@ElementCollection
@Comment("用户手动录入的记录")
@CollectionTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private List<CoalWashingDailyAnalysisItemVo> inputItems;
@ElementCollection
@Comment("用户手动录入的快浮记录")
@CollectionTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private List<CoalWashingDailyAnalysisKFItemVo> kfItems;
@@ -54,7 +52,6 @@ public class CoalWashingDailyAnalysisDto extends OrgCommonDto {
// private List<CoalWashingDailyAnalysisItemVo> rollingAvgItems;
@ElementCollection
@Comment("参数配置")
@CollectionTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private List<CoalWashingDailyAnalysisParamVo> paramsInfo;

View File

@@ -26,12 +26,10 @@ public class CreateCoalWashingDailyAnalysisDto extends OrgCommonDto {
private LocalDate date;
@ElementCollection
@Comment("用户手动录入的记录")
@CollectionTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private List<CoalWashingDailyAnalysisItemVo> inputItems;
@ElementCollection
@Comment("用户手动录入的快浮记录")
@CollectionTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private List<CoalWashingDailyAnalysisKFItemVo> kfItems;
@@ -41,7 +39,6 @@ public class CreateCoalWashingDailyAnalysisDto extends OrgCommonDto {
// private List<CoalWashingDailyAnalysisItemVo> rollingAvgItems;
@ElementCollection
@Comment("参数配置")
@CollectionTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private List<CoalWashingDailyAnalysisParamVo> paramsInfo;

View File

@@ -26,12 +26,10 @@ public class UpdateCoalWashingDailyAnalysisDto extends OrgCommonDto {
private LocalDate date;
@ElementCollection
@Comment("用户手动录入的记录")
@CollectionTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private List<CoalWashingDailyAnalysisItemVo> inputItems;
@ElementCollection
@Comment("用户手动录入的快浮记录")
@CollectionTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private List<CoalWashingDailyAnalysisKFItemVo> kfItems;
@@ -41,7 +39,6 @@ public class UpdateCoalWashingDailyAnalysisDto extends OrgCommonDto {
// private List<CoalWashingDailyAnalysisItemVo> rollingAvgItems;
@ElementCollection
@Comment("参数配置")
@CollectionTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private List<CoalWashingDailyAnalysisParamVo> paramsInfo;

View File

@@ -45,12 +45,10 @@ public class CoalWashingDailyAnalysisEntity extends OrgCommonEntity {
private LocalDate date;
@ElementCollection
@Comment("用户手动录入的记录")
@CollectionTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private List<CoalWashingDailyAnalysisItemVo> inputItems;
@ElementCollection
@Comment("用户手动录入的快浮记录")
@CollectionTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private List<CoalWashingDailyAnalysisKFItemVo> kfItems;
@@ -60,7 +58,6 @@ public class CoalWashingDailyAnalysisEntity extends OrgCommonEntity {
// private List<CoalWashingDailyAnalysisItemVo> rollingAvgItems;
@ElementCollection
@Comment("参数配置")
@CollectionTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private List<CoalWashingDailyAnalysisParamVo> paramsInfo;

View File

@@ -2,16 +2,12 @@ package cn.lihongjie.coal.department.entity;
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
import io.hypersistence.utils.hibernate.type.array.ListArrayType;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.Formula;
import org.hibernate.annotations.Type;
import java.util.List;
@@ -22,17 +18,7 @@ import java.util.List;
public class DepartmentEntity extends OrgCommonEntity {
@Type(ListArrayType.class)
@Formula("(select array_agg(e.id) from t_employee e where e.department_id = any(self_and_children_ids('t_department', id, true)))")
private List<String> allEmpIds;
@Type(ListArrayType.class)
@Formula("(select array_agg(e.id) from t_employee e where e.department_id = any(self_and_children_ids('t_department', id, false)))")
private List<String> childrenEmpIds;
@Type(ListArrayType.class)
@Formula("(select array_agg(e.id) from t_employee e where e.department_id = id)")
private List<String> selfEmpIds;

View File

@@ -0,0 +1,44 @@
package cn.lihongjie.coal.department.entity;
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
import io.hypersistence.utils.hibernate.type.array.ListArrayType;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.Formula;
import org.hibernate.annotations.Subselect;
import org.hibernate.annotations.Type;
import java.util.List;
@Comment("部门信息")
@Getter
@Setter
@Subselect("select * from t_department")
@Entity
public class DepartmentViewEntity extends OrgCommonEntity {
@Type(ListArrayType.class)
@Formula(
"(select array_agg(e.id) from t_employee e where e.department_id = any(self_and_children_ids('t_department', id, true)))")
private List<String> allEmpIds;
@Type(ListArrayType.class)
@Formula(
"(select array_agg(e.id) from t_employee e where e.department_id = any(self_and_children_ids('t_department', id, false)))")
private List<String> childrenEmpIds;
@Type(ListArrayType.class)
@Formula("(select array_agg(e.id) from t_employee e where e.department_id = id)")
private List<String> selfEmpIds;
@OneToMany(mappedBy = "parent", cascade = CascadeType.ALL)
private List<DepartmentViewEntity> children;
@ManyToOne private DepartmentViewEntity parent;
}

View File

@@ -6,6 +6,7 @@ import cn.lihongjie.coal.department.dto.DepartmentDto;
import cn.lihongjie.coal.department.dto.DepartmentTreeDto;
import cn.lihongjie.coal.department.dto.UpdateDepartmentDto;
import cn.lihongjie.coal.department.entity.DepartmentEntity;
import cn.lihongjie.coal.department.entity.DepartmentViewEntity;
import org.mapstruct.*;
import org.mapstruct.control.DeepClone;
@@ -31,4 +32,9 @@ public interface DepartmentMapper
@Mapping(target = "children", ignore = true)
})
DepartmentTreeDto toTreeDtoExcludeChildren(DepartmentEntity departmentEntity);
DepartmentDto toDto(DepartmentViewEntity view);
DepartmentTreeDto toTreeDto(DepartmentViewEntity de);
}

View File

@@ -0,0 +1,13 @@
package cn.lihongjie.coal.department.repository;
import cn.lihongjie.coal.base.dao.BaseRepository;
import cn.lihongjie.coal.department.entity.DepartmentEntity;
import cn.lihongjie.coal.department.entity.DepartmentViewEntity;
import org.springframework.stereotype.Repository;
@Repository
public interface DepartmentViewRepository extends BaseRepository<DepartmentViewEntity> {
DepartmentEntity findByNameAndOrganizationId(String name, String organizationId);
}

View File

@@ -11,10 +11,14 @@ import cn.lihongjie.coal.department.dto.DepartmentDto;
import cn.lihongjie.coal.department.dto.DepartmentTreeDto;
import cn.lihongjie.coal.department.dto.UpdateDepartmentDto;
import cn.lihongjie.coal.department.entity.DepartmentEntity;
import cn.lihongjie.coal.department.entity.DepartmentViewEntity;
import cn.lihongjie.coal.department.mapper.DepartmentMapper;
import cn.lihongjie.coal.department.repository.DepartmentRepository;
import cn.lihongjie.coal.department.repository.DepartmentViewRepository;
import jakarta.annotation.PostConstruct;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import lombok.extern.slf4j.Slf4j;
@@ -77,14 +81,30 @@ class DepartmentService extends BaseService<DepartmentEntity, DepartmentReposito
@Autowired DbFunctionService dbFunctionService;
@PersistenceContext EntityManager entityManager;
public List<DepartmentTreeDto> getTreeByIds(IdRequest id) {
if (id.getIds().isEmpty()) {
return new ArrayList<>();
}
List<DepartmentEntity> roots = this.repository.findAll((root, query, criteriaBuilder) -> root.get("id").in(id.getIds()));
return roots.stream().map(de -> this.mapper.toTreeDto(de)).collect(Collectors.toList());
}
@Autowired
DepartmentViewRepository departmentViewRepository;
public List<DepartmentTreeDto> getRoots(CommonQuery request) {
if (CollectionUtils.isEmpty(request.getItems())){
List<DepartmentEntity> roots = this.repository.findAll( (root, query, criteriaBuilder) -> criteriaBuilder.isNull(root.get("parent")));
List<DepartmentViewEntity> roots = this.departmentViewRepository.findAll( (root, query, criteriaBuilder) -> criteriaBuilder.isNull(root.get("parent")));
return roots.stream().map(de -> this.mapper.toTreeDto(de)).collect(Collectors.toList());
}else {
Page<DepartmentEntity> page =
repository.findAll(
Page<DepartmentViewEntity> page =
departmentViewRepository.findAll(
request.specification(conversionService),
PageRequest.of(
request.getPageNo(),
@@ -121,23 +141,12 @@ class DepartmentService extends BaseService<DepartmentEntity, DepartmentReposito
}
public List<DepartmentTreeDto> getTreeByIds(IdRequest id) {
if (id.getIds().isEmpty()) {
return new ArrayList<>();
}
List<DepartmentEntity> roots = this.repository.findAll((root, query, criteriaBuilder) -> root.get("id").in(id.getIds()));
return roots.stream().map(de -> this.mapper.toTreeDto(de)).collect(Collectors.toList());
}
public Page<DepartmentDto> list(CommonQuery query) {
Page<DepartmentEntity> page =
repository.findAll(
Page<DepartmentViewEntity> page =
departmentViewRepository.findAll(
query.specification(conversionService),
PageRequest.of(
query.getPageNo(),

View File

@@ -77,11 +77,9 @@ public class CreateEmployeeDto extends OrgCommonDto {
private List<EmpFamilyMemberVO> familyMembers;
@ElementCollection
@Comment("员工证件信息")
private List<EmpCertVO> certs;
@ElementCollection
@Comment("员工车辆信息")
private List<EmpCarVO> cars;
@Comment("养老保险基数")

View File

@@ -118,11 +118,9 @@ public class EmployeeDto extends OrgCommonDto {
private List<EmpFamilyMemberVO> familyMembers;
@ElementCollection
@Comment("员工证件信息")
private List<EmpCertVO> certs;
@ElementCollection
@Comment("员工车辆信息")
private List<EmpCarVO> cars;

View File

@@ -83,11 +83,9 @@ public class UpdateEmployeeDto extends OrgCommonDto {
@ElementCollection
@Comment("员工证件信息")
private List<EmpCertVO> certs;
@ElementCollection
@Comment("员工车辆信息")
private List<EmpCarVO> cars;
@Comment("养老保险基数")
private Double insurance1Base;

View File

@@ -145,18 +145,15 @@ public class EmployeeEntity extends OrgCommonEntity {
@ElementCollection
@Comment("家庭成员")
private List<EmpFamilyMemberVO> familyMembers;
@ElementCollection
@Comment("员工证件信息")
private List<EmpCertVO> certs;
@ElementCollection
@Comment("员工车辆信息")
private List<EmpCarVO> cars;
/**

View File

@@ -2,17 +2,10 @@ package cn.lihongjie.coal.jobPost.entity;
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
import io.hypersistence.utils.hibernate.type.array.ListArrayType;
import jakarta.persistence.Entity;
import lombok.Data;
import org.hibernate.annotations.Formula;
import org.hibernate.annotations.Type;
import java.util.List;
@Data
@Entity
public class JobPostEntity extends OrgCommonEntity {
@@ -20,7 +13,5 @@ public class JobPostEntity extends OrgCommonEntity {
@Type(ListArrayType.class)
@Formula("(select array_agg(e.id) from t_employee e where e.job_post_id = id)")
private List<String> selfEmpIds;
}

View File

@@ -0,0 +1,28 @@
package cn.lihongjie.coal.jobPost.entity;
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
import io.hypersistence.utils.hibernate.type.array.ListArrayType;
import jakarta.persistence.Entity;
import lombok.Data;
import org.hibernate.annotations.Formula;
import org.hibernate.annotations.Subselect;
import org.hibernate.annotations.Type;
import java.util.List;
@Data
@Subselect("select * from t_job_post")
@Entity
public class JobPostViewEntity extends OrgCommonEntity {
@Type(ListArrayType.class)
@Formula("(select array_agg(e.id) from t_employee e where e.job_post_id = id)")
private List<String> selfEmpIds;
}

View File

@@ -5,6 +5,7 @@ import cn.lihongjie.coal.jobPost.dto.CreateJobPostDto;
import cn.lihongjie.coal.jobPost.dto.JobPostDto;
import cn.lihongjie.coal.jobPost.dto.UpdateJobPostDto;
import cn.lihongjie.coal.jobPost.entity.JobPostEntity;
import cn.lihongjie.coal.jobPost.entity.JobPostViewEntity;
import org.mapstruct.Mapper;
import org.mapstruct.control.DeepClone;
@@ -14,4 +15,8 @@ import org.mapstruct.control.DeepClone;
uses = {cn.lihongjie.coal.base.mapper.CommonMapper.class, cn.lihongjie.coal.base.mapper.CommonEntityMapper.class},
mappingControl = DeepClone.class)
public interface JobPostMapper
extends BaseMapper<JobPostEntity, JobPostDto, CreateJobPostDto, UpdateJobPostDto> {}
extends BaseMapper<JobPostEntity, JobPostDto, CreateJobPostDto, UpdateJobPostDto> {
JobPostDto toDto(JobPostViewEntity view);
}

View File

@@ -0,0 +1,12 @@
package cn.lihongjie.coal.jobPost.repository;
import cn.lihongjie.coal.base.dao.BaseRepository;
import cn.lihongjie.coal.jobPost.entity.JobPostEntity;
import cn.lihongjie.coal.jobPost.entity.JobPostViewEntity;
import org.springframework.stereotype.Repository;
@Repository
public interface JobPostViewRepository extends BaseRepository<JobPostViewEntity> {
JobPostEntity findByNameAndOrganizationId(String name, String organizationId);
}

View File

@@ -8,8 +8,10 @@ import cn.lihongjie.coal.jobPost.dto.CreateJobPostDto;
import cn.lihongjie.coal.jobPost.dto.JobPostDto;
import cn.lihongjie.coal.jobPost.dto.UpdateJobPostDto;
import cn.lihongjie.coal.jobPost.entity.JobPostEntity;
import cn.lihongjie.coal.jobPost.entity.JobPostViewEntity;
import cn.lihongjie.coal.jobPost.mapper.JobPostMapper;
import cn.lihongjie.coal.jobPost.repository.JobPostRepository;
import cn.lihongjie.coal.jobPost.repository.JobPostViewRepository;
import lombok.extern.slf4j.Slf4j;
@@ -32,6 +34,8 @@ class JobPostService extends BaseService<JobPostEntity, JobPostRepository> {
@Autowired private ConversionService conversionService;
@Autowired JobPostViewRepository jobPostViewRepository;
public JobPostDto create(CreateJobPostDto request) {
JobPostEntity entity = mapper.toEntity(request);
@@ -59,8 +63,8 @@ class JobPostService extends BaseService<JobPostEntity, JobPostRepository> {
}
public Page<JobPostDto> list(CommonQuery query) {
Page<JobPostEntity> page =
repository.findAll(
Page<JobPostViewEntity> page =
jobPostViewRepository.findAll(
query.specification(conversionService),
PageRequest.of(
query.getPageNo(),

View File

@@ -23,6 +23,8 @@ public class HibernateConfig {
@Autowired Environment environment;
@Bean
HibernatePropertiesCustomizer hibernatePropertiesCustomizer() {
return new HibernatePropertiesCustomizer() {