From feb0827efacb7b327163f1ac9764b2e805019a10 Mon Sep 17 00:00:00 2001 From: lihongjie0209 Date: Fri, 19 Apr 2024 16:02:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../acAppointment/dto/AcAppointmentDto.java | 7 +- .../coal/coalBlend/dto/CoalBlendRequest.java | 9 -- .../coal/common/CollectionUtils.java | 22 +++ .../cn/lihongjie/coal/common/JpaUtils.java | 128 +++++++++++++++++- .../entity/DepartmentViewEntity.java | 44 ------ .../department/mapper/DepartmentMapper.java | 3 - .../repository/DepartmentRepository.java | 20 +++ .../repository/DepartmentViewRepository.java | 13 -- .../department/service/DepartmentService.java | 64 +++++---- .../employee/entity/EmpFamilyMemberVO.java | 14 +- .../dto/CreateEmployeeRecordDto.java | 10 +- .../jobPost/entity/JobPostViewEntity.java | 28 ---- .../coal/jobPost/mapper/JobPostMapper.java | 2 - .../jobPost/repository/JobPostRepository.java | 17 +++ .../repository/JobPostViewRepository.java | 12 -- .../coal/jobPost/service/JobPostService.java | 36 +++-- .../pdcDeviceData/dto/PdcDeviceDataDto.java | 63 ++++++++- .../entity/PdcDeviceDataEntity.java | 2 +- .../service/PdcDeviceRealTimeDataService.java | 3 +- .../coal/product/dto/CreateProductDto.java | 10 +- .../coal/product/dto/UpdateProductDto.java | 10 +- .../dict/enum/pdcDeviceSuplierDict.groovy | 17 --- 22 files changed, 320 insertions(+), 214 deletions(-) delete mode 100644 src/main/java/cn/lihongjie/coal/department/entity/DepartmentViewEntity.java delete mode 100644 src/main/java/cn/lihongjie/coal/department/repository/DepartmentViewRepository.java delete mode 100644 src/main/java/cn/lihongjie/coal/jobPost/entity/JobPostViewEntity.java delete mode 100644 src/main/java/cn/lihongjie/coal/jobPost/repository/JobPostViewRepository.java delete mode 100644 src/main/resources/scripts/dict/enum/pdcDeviceSuplierDict.groovy diff --git a/src/main/java/cn/lihongjie/coal/acAppointment/dto/AcAppointmentDto.java b/src/main/java/cn/lihongjie/coal/acAppointment/dto/AcAppointmentDto.java index b06a3c2c..ccf7af95 100644 --- a/src/main/java/cn/lihongjie/coal/acAppointment/dto/AcAppointmentDto.java +++ b/src/main/java/cn/lihongjie/coal/acAppointment/dto/AcAppointmentDto.java @@ -5,15 +5,11 @@ import cn.lihongjie.coal.base.dto.OrgCommonDto; import cn.lihongjie.coal.common.DictCode; import cn.lihongjie.coal.pojoProcessor.DictTranslate; -import io.hypersistence.utils.hibernate.type.array.ListArrayType; - import jakarta.persistence.ManyToOne; import lombok.Data; import org.hibernate.annotations.Comment; -import org.hibernate.annotations.Formula; -import org.hibernate.annotations.Type; import java.util.List; @@ -42,8 +38,7 @@ public class AcAppointmentDto extends OrgCommonDto { @Comment("事由") private String reason; - @Formula("(select array_agg(d.id) from t_ac_device_data d where d.plate_no = plate_no and d.pass_time between start_time and end_time)") - @Type(ListArrayType.class) + private List acDeviceDataIds; diff --git a/src/main/java/cn/lihongjie/coal/coalBlend/dto/CoalBlendRequest.java b/src/main/java/cn/lihongjie/coal/coalBlend/dto/CoalBlendRequest.java index 2285d022..9634b4b2 100644 --- a/src/main/java/cn/lihongjie/coal/coalBlend/dto/CoalBlendRequest.java +++ b/src/main/java/cn/lihongjie/coal/coalBlend/dto/CoalBlendRequest.java @@ -8,7 +8,6 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.Data; import org.hibernate.annotations.Comment; -import org.hibernate.annotations.Formula; import java.util.HashMap; import java.util.List; @@ -36,14 +35,6 @@ public class CoalBlendRequest { @Comment("煤类型") private String coalType; - @Formula( - "(select i.name\n" - + "from t_dictionary d,\n" - + " t_dictionary_item i\n" - + "where d.id = i.dictionary_id\n" - + " and d.code = 'coalBlend.coalType'\n" - + " and i.code = coal_type)") - private String coalTypeName; public Map getConstraintMap() { if (constraintMap == null) { diff --git a/src/main/java/cn/lihongjie/coal/common/CollectionUtils.java b/src/main/java/cn/lihongjie/coal/common/CollectionUtils.java index d05f505a..a4bbcacd 100644 --- a/src/main/java/cn/lihongjie/coal/common/CollectionUtils.java +++ b/src/main/java/cn/lihongjie/coal/common/CollectionUtils.java @@ -176,4 +176,26 @@ public class CollectionUtils { return new BigDecimal(o.toString()); } + + public static List toList(Object o) { + + if (o == null) { + return new ArrayList<>(); + } + if (o instanceof List) { + return (List) o; + } + + if (o instanceof Collection) { + return new ArrayList<>((Collection) o); + } + + // if object is array + if (o.getClass().isArray()) { + return Arrays.asList((T[]) o); + } + + + return new ArrayList<>(); + } } diff --git a/src/main/java/cn/lihongjie/coal/common/JpaUtils.java b/src/main/java/cn/lihongjie/coal/common/JpaUtils.java index 5e1505e4..b3da132d 100644 --- a/src/main/java/cn/lihongjie/coal/common/JpaUtils.java +++ b/src/main/java/cn/lihongjie/coal/common/JpaUtils.java @@ -1,22 +1,61 @@ package cn.lihongjie.coal.common; +import cn.lihongjie.coal.base.dto.BaseDto; +import cn.lihongjie.coal.base.entity.BaseEntity; + import com.google.common.base.CaseFormat; import jakarta.persistence.Tuple; import jakarta.persistence.TupleElement; +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; + +import org.apache.commons.lang3.ObjectUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.reflect.FieldUtils; +import org.apache.poi.ss.formula.functions.T; +import org.springframework.core.convert.ConversionService; + +import java.lang.reflect.Field; import java.util.*; import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; +@Slf4j public class JpaUtils { public static Function underscoreToCamelCase = (String name) -> CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name); + public static Function idGetter = (Object obj) -> { + if (obj == null) { + return null; + } + if (obj instanceof Map) { + return ((Map) obj).get("id").toString(); + } + + if (obj instanceof BaseEntity){ + return ((BaseEntity) obj).getId(); + } + if (obj instanceof BaseDto){ + return ((BaseDto) obj).getId(); + } + + try{ + return FieldUtils.readField(obj, "id", true).toString(); + }catch (Exception e){ + return null; + } + + }; + + public static List> convertTuplesToMap(List tuples) { return convertTuplesToMap(tuples, Function.identity(), Function.identity()); } - public static Function handleArray = (Object value) -> { if (value == null) { @@ -24,10 +63,9 @@ public class JpaUtils { } if (value.getClass().isArray()) { - Object[] objects = (Object[]) value; - if (objects.length == 0 || (objects.length == 1 && objects[0] == null) ) { + if (objects.length == 0 || (objects.length == 1 && objects[0] == null)) { return new ArrayList<>(); } @@ -37,6 +75,90 @@ public class JpaUtils { } }; + public static void mergeMapToPojo( + Iterable pojos, + Iterable maps, + ConversionService conversionService) { + + + mergeMapToPojo(pojos, x -> idGetter.apply(x), maps, "id", conversionService); + + + } + + @SneakyThrows + public static void mergeMapToPojo( + Iterable pojos, + Function pojoIdGetter, + Iterable maps, + String mapKey, + ConversionService conversionService) { + + if (ObjectUtils.isEmpty(maps)) { + return; + } + + if (ObjectUtils.isEmpty(pojos)) { + return; + } + + Map pojoMap = + StreamSupport.stream(pojos.spliterator(), false) + .collect(Collectors.toMap(pojoIdGetter, Function.identity())); + + Map mapMap = + StreamSupport.stream(maps.spliterator(), false) + .collect(Collectors.toMap(e -> (ID) e.get(mapKey), Function.identity())); + Map> fieldMapCache = new HashMap<>(); + + for (ID id : mapMap.keySet()) { + + T pojo = pojoMap.get(id); + + if (pojo == null) { + continue; + } + + var fields = + fieldMapCache.computeIfAbsent( + pojo.getClass(), + cls -> + FieldUtils.getAllFieldsList(cls).stream() + .collect(Collectors.toMap(e -> e.getName(), e -> e))); + + Map map = mapMap.get(id); + + for (Object key : map.keySet()) { + + if (StringUtils.equals(key.toString(), mapKey)){ + continue; + } + + String fieldName = key.toString(); + Object value = map.get(key); + if (!fields.containsKey(fieldName)) { + + fieldName = underscoreToCamelCase.apply(fieldName); + } + + if (!fields.containsKey(fieldName)) { + + log.info( + "field {}/{} not found in class {}", + key, + fieldName, + pojo.getClass().getName()); + continue; + } + + Field field = fields.get(fieldName); + + FieldUtils.writeField( + field, pojo, conversionService.convert(value, field.getType()), true); + } + } + } + public static List> convertTuplesToMap( List tuples, Function keyMapper) { return convertTuplesToMap(tuples, keyMapper, Function.identity()); diff --git a/src/main/java/cn/lihongjie/coal/department/entity/DepartmentViewEntity.java b/src/main/java/cn/lihongjie/coal/department/entity/DepartmentViewEntity.java deleted file mode 100644 index a2c78a3f..00000000 --- a/src/main/java/cn/lihongjie/coal/department/entity/DepartmentViewEntity.java +++ /dev/null @@ -1,44 +0,0 @@ -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 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 childrenEmpIds; - - @Type(ListArrayType.class) - @Formula("(select array_agg(e.id) from t_employee e where e.department_id = id)") - private List selfEmpIds; - - @OneToMany(mappedBy = "parent", cascade = CascadeType.ALL) - private List children; - - @ManyToOne private DepartmentViewEntity parent; -} diff --git a/src/main/java/cn/lihongjie/coal/department/mapper/DepartmentMapper.java b/src/main/java/cn/lihongjie/coal/department/mapper/DepartmentMapper.java index db575293..29675108 100644 --- a/src/main/java/cn/lihongjie/coal/department/mapper/DepartmentMapper.java +++ b/src/main/java/cn/lihongjie/coal/department/mapper/DepartmentMapper.java @@ -6,7 +6,6 @@ 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; @@ -34,7 +33,5 @@ public interface DepartmentMapper DepartmentTreeDto toTreeDtoExcludeChildren(DepartmentEntity departmentEntity); - DepartmentDto toDto(DepartmentViewEntity view); - DepartmentTreeDto toTreeDto(DepartmentViewEntity de); } diff --git a/src/main/java/cn/lihongjie/coal/department/repository/DepartmentRepository.java b/src/main/java/cn/lihongjie/coal/department/repository/DepartmentRepository.java index 3f8cf890..d45cded3 100644 --- a/src/main/java/cn/lihongjie/coal/department/repository/DepartmentRepository.java +++ b/src/main/java/cn/lihongjie/coal/department/repository/DepartmentRepository.java @@ -3,10 +3,30 @@ package cn.lihongjie.coal.department.repository; import cn.lihongjie.coal.base.dao.BaseRepository; import cn.lihongjie.coal.department.entity.DepartmentEntity; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import java.util.List; +import java.util.Map; + @Repository public interface DepartmentRepository extends BaseRepository { DepartmentEntity findByNameAndOrganizationId(String name, String organizationId); + + @Query( + value = """ + + + + select d.id as id, + (select array_agg(e.id) from t_employee e where e.department_id = any(self_and_children_ids('t_department', d.id, true))) as all_emp_ids, + (select array_agg(e.id) from t_employee e where e.department_id = any(self_and_children_ids('t_department', d.id, false))) as children_emp_ids, + (select array_agg(e.id) from t_employee e where e.department_id = d.id) as self_emp_ids + + from t_department d where d.id in :ids + +""", nativeQuery = true) + List empIds(@Param("ids") List ids); } diff --git a/src/main/java/cn/lihongjie/coal/department/repository/DepartmentViewRepository.java b/src/main/java/cn/lihongjie/coal/department/repository/DepartmentViewRepository.java deleted file mode 100644 index df242ad7..00000000 --- a/src/main/java/cn/lihongjie/coal/department/repository/DepartmentViewRepository.java +++ /dev/null @@ -1,13 +0,0 @@ -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 { - - DepartmentEntity findByNameAndOrganizationId(String name, String organizationId); -} diff --git a/src/main/java/cn/lihongjie/coal/department/service/DepartmentService.java b/src/main/java/cn/lihongjie/coal/department/service/DepartmentService.java index 0910c8a7..3ebd904a 100644 --- a/src/main/java/cn/lihongjie/coal/department/service/DepartmentService.java +++ b/src/main/java/cn/lihongjie/coal/department/service/DepartmentService.java @@ -4,6 +4,7 @@ import cn.lihongjie.coal.base.dto.CommonQuery; import cn.lihongjie.coal.base.dto.IdRequest; import cn.lihongjie.coal.base.service.BaseService; import cn.lihongjie.coal.common.Ctx; +import cn.lihongjie.coal.common.JpaUtils; import cn.lihongjie.coal.common.TreeUtils; import cn.lihongjie.coal.dbFunctions.DbFunctionService; import cn.lihongjie.coal.department.dto.CreateDepartmentDto; @@ -11,10 +12,8 @@ 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; @@ -33,6 +32,7 @@ import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import java.util.stream.StreamSupport; @@ -94,17 +94,19 @@ class DepartmentService extends BaseService getRoots(CommonQuery request) { if (CollectionUtils.isEmpty(request.getItems())){ - List roots = this.departmentViewRepository.findAll( (root, query, criteriaBuilder) -> criteriaBuilder.isNull(root.get("parent"))); - return roots.stream().map(de -> this.mapper.toTreeDto(de)).collect(Collectors.toList()); + List roots = this.repository.findAll( (root, query, criteriaBuilder) -> criteriaBuilder.isNull(root.get("parent"))); + return addEmpIds( + roots.stream() + .map(de -> this.mapper.toTreeDto(de)) + .collect(Collectors.toList())); }else { - Page page = - departmentViewRepository.findAll( + Page page = + repository.findAll( request.specification(conversionService), PageRequest.of( request.getPageNo(), @@ -117,36 +119,46 @@ class DepartmentService extends BaseService selfAndParent = this.findAllByIds(selfAndParentIds).stream().map(x -> (this.mapper.toTreeDtoExcludeChildren(x))).collect(Collectors.toList()); - - return StreamSupport.stream( - TreeUtils.buildTreeFromList( - selfAndParent, - DepartmentTreeDto::getId, - x -> x.getParent(), - (x, y) -> { - if (x.getChildren() == null) { - x.setChildren(new ArrayList<>()); - } - x.getChildren().add(y); - return null; - }) - .spliterator(), - false) - .collect(Collectors.toList()); + return addEmpIds( + StreamSupport.stream( + TreeUtils.buildTreeFromList( + selfAndParent, + DepartmentTreeDto::getId, + x -> x.getParent(), + (x, y) -> { + if (x.getChildren() == null) { + x.setChildren(new ArrayList<>()); + } + x.getChildren().add(y); + return null; + }) + .spliterator(), + false) + .collect(Collectors.toList())); } + } + + private List addEmpIds(List collect) { + + List maps = repository.empIds( + cn.lihongjie.coal.common.CollectionUtils.map(collect, DepartmentTreeDto::getId)); + + + JpaUtils.mergeMapToPojo(collect, maps, conversionService); + return collect; } public Page list(CommonQuery query) { - Page page = + Page page = - departmentViewRepository.findAll( + repository.findAll( query.specification(conversionService), PageRequest.of( query.getPageNo(), diff --git a/src/main/java/cn/lihongjie/coal/employee/entity/EmpFamilyMemberVO.java b/src/main/java/cn/lihongjie/coal/employee/entity/EmpFamilyMemberVO.java index 5d88f816..bdded608 100644 --- a/src/main/java/cn/lihongjie/coal/employee/entity/EmpFamilyMemberVO.java +++ b/src/main/java/cn/lihongjie/coal/employee/entity/EmpFamilyMemberVO.java @@ -1,11 +1,13 @@ package cn.lihongjie.coal.employee.entity; +import cn.lihongjie.coal.common.DictCode; +import cn.lihongjie.coal.pojoProcessor.DictTranslate; + import jakarta.persistence.Embeddable; import lombok.Data; import org.hibernate.annotations.Comment; -import org.hibernate.annotations.Formula; import java.util.*; @@ -18,15 +20,9 @@ public class EmpFamilyMemberVO { @Comment("关系") private String relation; - @Formula( - "(select i.name\n" - + "from t_dictionary d,\n" - + " t_dictionary_item i\n" - + "where d.id = i.dictionary_id\n" - + " and d.code = 'emp.familyMember.relation'\n" - + " and i.code = relation)") - private String relationName; + @DictTranslate(dictKey = DictCode.EMP_FAMILYMEMBER_RELATION) + private String relationName; private String phone; diff --git a/src/main/java/cn/lihongjie/coal/employeeRecord/dto/CreateEmployeeRecordDto.java b/src/main/java/cn/lihongjie/coal/employeeRecord/dto/CreateEmployeeRecordDto.java index 329c5e36..ba34a04d 100644 --- a/src/main/java/cn/lihongjie/coal/employeeRecord/dto/CreateEmployeeRecordDto.java +++ b/src/main/java/cn/lihongjie/coal/employeeRecord/dto/CreateEmployeeRecordDto.java @@ -7,7 +7,6 @@ import jakarta.persistence.ManyToOne; import lombok.Data; import org.hibernate.annotations.Comment; -import org.hibernate.annotations.Formula; @Data public class CreateEmployeeRecordDto extends OrgCommonDto { @@ -21,14 +20,7 @@ public class CreateEmployeeRecordDto extends OrgCommonDto { @Comment("记录类型") private String recordType; - @Formula( - "(select i.name\n" - + "from t_dictionary d,\n" - + " t_dictionary_item i\n" - + "where d.id = i.dictionary_id\n" - + " and d.code = 'emp.record.type'\n" - + " and i.code = record_type)") - private String recordTypeName; + diff --git a/src/main/java/cn/lihongjie/coal/jobPost/entity/JobPostViewEntity.java b/src/main/java/cn/lihongjie/coal/jobPost/entity/JobPostViewEntity.java deleted file mode 100644 index 381b3761..00000000 --- a/src/main/java/cn/lihongjie/coal/jobPost/entity/JobPostViewEntity.java +++ /dev/null @@ -1,28 +0,0 @@ -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 selfEmpIds; - - - -} diff --git a/src/main/java/cn/lihongjie/coal/jobPost/mapper/JobPostMapper.java b/src/main/java/cn/lihongjie/coal/jobPost/mapper/JobPostMapper.java index bf4c8622..d43d8c3b 100644 --- a/src/main/java/cn/lihongjie/coal/jobPost/mapper/JobPostMapper.java +++ b/src/main/java/cn/lihongjie/coal/jobPost/mapper/JobPostMapper.java @@ -5,7 +5,6 @@ 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; @@ -18,5 +17,4 @@ public interface JobPostMapper extends BaseMapper { - JobPostDto toDto(JobPostViewEntity view); } diff --git a/src/main/java/cn/lihongjie/coal/jobPost/repository/JobPostRepository.java b/src/main/java/cn/lihongjie/coal/jobPost/repository/JobPostRepository.java index f76c601d..8ce20b56 100644 --- a/src/main/java/cn/lihongjie/coal/jobPost/repository/JobPostRepository.java +++ b/src/main/java/cn/lihongjie/coal/jobPost/repository/JobPostRepository.java @@ -3,9 +3,26 @@ package cn.lihongjie.coal.jobPost.repository; import cn.lihongjie.coal.base.dao.BaseRepository; import cn.lihongjie.coal.jobPost.entity.JobPostEntity; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import java.util.List; +import java.util.Map; + @Repository public interface JobPostRepository extends BaseRepository { JobPostEntity findByNameAndOrganizationId(String name, String organizationId); + + + @Query( + """ +select e.jobPost.id as id, array_agg(e.id) as empIds from EmployeeEntity e + where e.jobPost.id in :ids + group by e.jobPost.id +""") + List getSelfEmpIds(@Param("ids") List ids); + + record JobPostEmpDto(String id, List empIds) { + } } diff --git a/src/main/java/cn/lihongjie/coal/jobPost/repository/JobPostViewRepository.java b/src/main/java/cn/lihongjie/coal/jobPost/repository/JobPostViewRepository.java deleted file mode 100644 index d0e55c34..00000000 --- a/src/main/java/cn/lihongjie/coal/jobPost/repository/JobPostViewRepository.java +++ /dev/null @@ -1,12 +0,0 @@ -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 { - JobPostEntity findByNameAndOrganizationId(String name, String organizationId); -} diff --git a/src/main/java/cn/lihongjie/coal/jobPost/service/JobPostService.java b/src/main/java/cn/lihongjie/coal/jobPost/service/JobPostService.java index df34c8e9..a2fd48eb 100644 --- a/src/main/java/cn/lihongjie/coal/jobPost/service/JobPostService.java +++ b/src/main/java/cn/lihongjie/coal/jobPost/service/JobPostService.java @@ -2,16 +2,16 @@ package cn.lihongjie.coal.jobPost.service; import cn.lihongjie.coal.base.dto.CommonQuery; import cn.lihongjie.coal.base.dto.IdRequest; +import cn.lihongjie.coal.base.entity.BaseEntity; import cn.lihongjie.coal.base.service.BaseService; +import cn.lihongjie.coal.common.CollectionUtils; import cn.lihongjie.coal.common.Ctx; 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; @@ -23,19 +23,19 @@ import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; +import java.util.Map; + @Service @Slf4j @Transactional -public -class JobPostService extends BaseService { +public class JobPostService extends BaseService { @Autowired private JobPostRepository repository; @Autowired private JobPostMapper mapper; @Autowired private ConversionService conversionService; - @Autowired JobPostViewRepository jobPostViewRepository; - public JobPostDto create(CreateJobPostDto request) { JobPostEntity entity = mapper.toEntity(request); @@ -63,22 +63,34 @@ class JobPostService extends BaseService { } public Page list(CommonQuery query) { - Page page = - jobPostViewRepository.findAll( + Page page = + repository.findAll( query.specification(conversionService), PageRequest.of( query.getPageNo(), query.getPageSize(), Sort.by(query.getOrders()))); - return page.map(this.mapper::toDto); + Page page1 = page.map(this.mapper::toDto); + List selfEmpIds = + repository.getSelfEmpIds(CollectionUtils.map(page.getContent(), BaseEntity::getId)); + + page1.forEach( + x -> { + selfEmpIds.stream() + .filter(y -> y.get("id").equals(x.getId())) + .findFirst() + .ifPresent( + y -> x.setSelfEmpIds(CollectionUtils.toList(y.get("empIds")))); + }); + return page1; } public JobPostDto findByName(String name) { - JobPostEntity post = repository.findByNameAndOrganizationId(name, Ctx.currentUser().getOrganizationId()); - - return mapper.toDto(post); + JobPostEntity post = + repository.findByNameAndOrganizationId(name, Ctx.currentUser().getOrganizationId()); + return mapper.toDto(post); } } diff --git a/src/main/java/cn/lihongjie/coal/pdcDeviceData/dto/PdcDeviceDataDto.java b/src/main/java/cn/lihongjie/coal/pdcDeviceData/dto/PdcDeviceDataDto.java index 7fb2fa47..74ee8dee 100644 --- a/src/main/java/cn/lihongjie/coal/pdcDeviceData/dto/PdcDeviceDataDto.java +++ b/src/main/java/cn/lihongjie/coal/pdcDeviceData/dto/PdcDeviceDataDto.java @@ -1,8 +1,69 @@ package cn.lihongjie.coal.pdcDeviceData.dto; import cn.lihongjie.coal.base.dto.OrgCommonDto; +import cn.lihongjie.coal.pdcDevice.dto.PdcDeviceDto; + +import jakarta.persistence.ManyToOne; import lombok.Data; +import org.hibernate.annotations.Comment; + +import java.time.LocalDateTime; + @Data -public class PdcDeviceDataDto extends OrgCommonDto {} +public class PdcDeviceDataDto extends OrgCommonDto { + + @ManyToOne + private PdcDeviceDto device; + + private LocalDateTime time; + + @Comment("modbus地址") + private String modbusUId; + + @Comment("总累计量") + private Double totalData; + + @Comment("月累计量") + private Double monthData; + + @Comment("日累计量") + private Double dayData; + + @Comment("班累计量") + private Double classData; + + @Comment(" 批累计量") + private Double batchData; + + @Comment("定值累计量") + private Double fixedData; + + @Comment("瞬时流量") + private Double flowData; + + @Comment("瞬时速度") + private Double speedData; + + @Comment("当前负荷") + private Double loadData; + + @Comment("控制输出") + private Double outputData; + + @Comment("故障状态") + private Double faultData; + + @Comment("故障信息") + private String faultInfo; + + @Comment("净重") + private Double netData; + + @Comment("过程数据1") + private Double process1Data; + + @Comment("过程数据2") + private Double process2Data; +} diff --git a/src/main/java/cn/lihongjie/coal/pdcDeviceData/entity/PdcDeviceDataEntity.java b/src/main/java/cn/lihongjie/coal/pdcDeviceData/entity/PdcDeviceDataEntity.java index b9dd7f41..c97b1827 100644 --- a/src/main/java/cn/lihongjie/coal/pdcDeviceData/entity/PdcDeviceDataEntity.java +++ b/src/main/java/cn/lihongjie/coal/pdcDeviceData/entity/PdcDeviceDataEntity.java @@ -73,6 +73,6 @@ public class PdcDeviceDataEntity extends OrgCommonEntity { private Double process2Data; - private Boolean saved; +// private Boolean saved; } diff --git a/src/main/java/cn/lihongjie/coal/pdcDeviceRealTimeData/service/PdcDeviceRealTimeDataService.java b/src/main/java/cn/lihongjie/coal/pdcDeviceRealTimeData/service/PdcDeviceRealTimeDataService.java index f918a196..d3ab9ede 100644 --- a/src/main/java/cn/lihongjie/coal/pdcDeviceRealTimeData/service/PdcDeviceRealTimeDataService.java +++ b/src/main/java/cn/lihongjie/coal/pdcDeviceRealTimeData/service/PdcDeviceRealTimeDataService.java @@ -122,7 +122,8 @@ public class PdcDeviceRealTimeDataService with tmp1 as ( - select d.device_id as device_id, max(coal_type) as coal_type, max(total_data) - min(total_data) as time_total from t_pdc_device_data d + select d.device_id as device_id, max(p.coal_type) as coal_type, max(total_data) - min(total_data) as time_total from t_pdc_device_data d + left join t_pdc_device p on d.device_id = p.id where d.organization_id = :organizationId and d.time >= :startTime and d.time <= :endTime diff --git a/src/main/java/cn/lihongjie/coal/product/dto/CreateProductDto.java b/src/main/java/cn/lihongjie/coal/product/dto/CreateProductDto.java index 20fdcf70..2a803b31 100644 --- a/src/main/java/cn/lihongjie/coal/product/dto/CreateProductDto.java +++ b/src/main/java/cn/lihongjie/coal/product/dto/CreateProductDto.java @@ -5,7 +5,6 @@ import cn.lihongjie.coal.base.dto.OrgCommonDto; import lombok.Data; import org.hibernate.annotations.Comment; -import org.hibernate.annotations.Formula; @Data public class CreateProductDto extends OrgCommonDto { @@ -14,12 +13,5 @@ public class CreateProductDto extends OrgCommonDto { @Comment("煤源类型") private String coalType; - @Formula( - "(select i.name\n" - + "from t_dictionary d,\n" - + " t_dictionary_item i\n" - + "where d.id = i.dictionary_id\n" - + " and d.code = 'coal.type'\n" - + " and i.code = coal_type)") - private String coalTypeName; + } diff --git a/src/main/java/cn/lihongjie/coal/product/dto/UpdateProductDto.java b/src/main/java/cn/lihongjie/coal/product/dto/UpdateProductDto.java index 617fc23f..1cdc76e0 100644 --- a/src/main/java/cn/lihongjie/coal/product/dto/UpdateProductDto.java +++ b/src/main/java/cn/lihongjie/coal/product/dto/UpdateProductDto.java @@ -5,19 +5,11 @@ import cn.lihongjie.coal.base.dto.OrgCommonDto; import lombok.Data; import org.hibernate.annotations.Comment; -import org.hibernate.annotations.Formula; @Data public class UpdateProductDto extends OrgCommonDto { @Comment("煤源类型") private String coalType; - @Formula( - "(select i.name\n" - + "from t_dictionary d,\n" - + " t_dictionary_item i\n" - + "where d.id = i.dictionary_id\n" - + " and d.code = 'coal.type'\n" - + " and i.code = coal_type)") - private String coalTypeName; + } diff --git a/src/main/resources/scripts/dict/enum/pdcDeviceSuplierDict.groovy b/src/main/resources/scripts/dict/enum/pdcDeviceSuplierDict.groovy deleted file mode 100644 index ade3ea25..00000000 --- a/src/main/resources/scripts/dict/enum/pdcDeviceSuplierDict.groovy +++ /dev/null @@ -1,17 +0,0 @@ - -package scripts.dict - -import cn.lihongjie.coal.base.dto.CommonQuery -import cn.lihongjie.coal.pdcDeviceSuplier.controller.PdcDeviceSuplierController -import org.springframework.context.ApplicationContext - -ApplicationContext ioc = ioc - -def controller = ioc.getBean(PdcDeviceSuplierController.class) - - - - -return controller.list(new CommonQuery()) - -