From 8c5c4e5949beca142e3b015f04d24416d71822fa Mon Sep 17 00:00:00 2001 From: xia Date: Tue, 30 Aug 2022 15:16:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=97=A8=E7=B1=BB=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/ArchivesCaseRepository.java | 6 +- .../repository/BorrowArchivesRepository.java | 8 +-- .../service/impl/ArchivesServiceImpl.java | 6 +- .../ArchivesDictrionaryController.java | 7 +++ .../controller/FieldController.java | 2 +- .../dictionary/domain/ArchivesType.java | 4 +- .../ArchivesDictionaryRepository.java | 15 +++-- .../repository/ArchivesTypeRepository.java | 8 +++ .../service/ArchivesDictionaryService.java | 3 + .../dictionary/service/FieldService.java | 2 +- .../service/impl/ArchivesDictionaryImpl.java | 57 +++++++++++++------ .../service/impl/ArchivesTypeServiceImpl.java | 43 +++++++++++++- .../service/impl/FieldServiceImpl.java | 3 +- 13 files changed, 126 insertions(+), 38 deletions(-) diff --git a/archives/src/main/java/com/storeroom/modules/archives/repository/ArchivesCaseRepository.java b/archives/src/main/java/com/storeroom/modules/archives/repository/ArchivesCaseRepository.java index f996656..1c7c11f 100644 --- a/archives/src/main/java/com/storeroom/modules/archives/repository/ArchivesCaseRepository.java +++ b/archives/src/main/java/com/storeroom/modules/archives/repository/ArchivesCaseRepository.java @@ -126,11 +126,7 @@ public interface ArchivesCaseRepository extends JpaRepository> readyCollectConfirm(List caseIds); @Query(nativeQuery = true, - value = "SELECT group_concat(DISTINCT CONCAT( room.NAME, ' ', di.device_name, ' ', ace.folder_location_details)) " + - "FROM archives_case_cartoning acc INNER JOIN archives_case ace ON acc.case_id = ace.id " + - "INNER JOIN device_archives_tag dat ON ace.folder_location = dat.position " + - "INNER JOIN device_info di ON dat.device_info_id = di.id " + - "INNER JOIN storeroom room ON room.id = di.storeroom_id WHERE ace.id = ?1 ") + value = "SELECT ace.folder_location_details FROM archives_case ace WHERE ace.id = ?1 ") String findLocationDetailsByCaseId(String caseId); @Query(nativeQuery = true, diff --git a/archives/src/main/java/com/storeroom/modules/archives/repository/BorrowArchivesRepository.java b/archives/src/main/java/com/storeroom/modules/archives/repository/BorrowArchivesRepository.java index aee5df4..313c5cf 100644 --- a/archives/src/main/java/com/storeroom/modules/archives/repository/BorrowArchivesRepository.java +++ b/archives/src/main/java/com/storeroom/modules/archives/repository/BorrowArchivesRepository.java @@ -157,18 +157,18 @@ public interface BorrowArchivesRepository extends JpaRepository> waitBorrow1(); @Query(nativeQuery = true, - value = "select concat(br.borrower_name,'已登记,请及时处理') as title,ba.update_time from borrow_archives ba " + + value = "select concat('借出确认:',br.borrower_name,'档案已登记,请及时处理') as title,ba.update_time from borrow_archives ba " + "inner join borrow_bill_archives bba on ba.id = bba.ba_id inner join borrow_bill bbl on bba.bill_id = bbl.id " + "inner join borrower br on bbl.borrower_id = br.id where ba.borrow_type = 2 order by ba.update_time desc") List> waitBorrow2(); @Query(nativeQuery = true, - value = "select concat(maintitle,'档案已逾期,请及时处理') as title,ba.update_time from borrow_archives ba inner join borrow_bill_archives bba on ba.id = bba.ba_id inner join borrow_bill bbl on bba.bill_id = bbl.id where ba.borrow_type = 3 and bbl.borrow_end <= now() order by ba.update_time desc") + value = "select concat('逾期警告:',maintitle,'档案已逾期,请及时处理') as title,ba.update_time from borrow_archives ba inner join borrow_bill_archives bba on ba.id = bba.ba_id inner join borrow_bill bbl on bba.bill_id = bbl.id where ba.borrow_type = 3 and bbl.borrow_end <= now() order by ba.update_time desc") List> waitBorrow4(); @Query(nativeQuery = true, - value = "select concat(maintitle,'档案已到归还时间,请及时处理') as title,ba.update_time from borrow_archives ba inner join borrow_bill_archives bba on ba.id = bba.ba_id inner join borrow_bill bbl on bba.bill_id = bbl.id where ba.borrow_type = 3 and bbl.borrow_end >= now() and TIMESTAMPDIFF(hour,now(),bbl.borrow_end) <= 24 order by ba.update_time desc") + value = "select concat('即将到期:',maintitle,'档案即将到期,请及时处理') as title,ba.update_time from borrow_archives ba inner join borrow_bill_archives bba on ba.id = bba.ba_id inner join borrow_bill bbl on bba.bill_id = bbl.id where ba.borrow_type = 3 and bbl.borrow_end >= now() and TIMESTAMPDIFF(hour,now(),bbl.borrow_end) <= 24 order by ba.update_time desc") List> waitBorrow3(); diff --git a/archives/src/main/java/com/storeroom/modules/archives/service/impl/ArchivesServiceImpl.java b/archives/src/main/java/com/storeroom/modules/archives/service/impl/ArchivesServiceImpl.java index 7897b2a..82d9d6f 100644 --- a/archives/src/main/java/com/storeroom/modules/archives/service/impl/ArchivesServiceImpl.java +++ b/archives/src/main/java/com/storeroom/modules/archives/service/impl/ArchivesServiceImpl.java @@ -674,7 +674,7 @@ public class ArchivesServiceImpl implements ArchivesService { //若删除为项目 if(archivesType.getIsType() == 2){ //获取档案表名 -// ArchivesType archivesType_3 = archivesTypeRepository.findByPid(archivesType.getId()); + ArchivesType archivesType_3 = archivesTypeRepository.findByPid(archivesType.getId()); //获取该项目下所有案卷id String query3sql = "select id from "+archivesType.getEnName()+" where parent_id in ('"+ids.stream().map(String::valueOf).collect(Collectors.joining("','"))+"')"; List list3 = entityManager.createNativeQuery(query3sql).getResultList(); @@ -684,6 +684,8 @@ public class ArchivesServiceImpl implements ArchivesService { +"' where id in ('"+list3.stream().map(String::valueOf).collect(Collectors.joining("','"))+"')"; //获取卷内表名 String enName_4 = archivesTypeRepository.findEnNameByPid(archivesType.getId()); + if(null == enName_4) + return result; String query4sql = "select id from "+enName_4+" where parent_id in ('"+list3.stream().map(String::valueOf).collect(Collectors.joining("','"))+"')"; List list4 = entityManager.createNativeQuery(query4sql).getResultList(); //删除卷内 @@ -710,6 +712,8 @@ public class ArchivesServiceImpl implements ArchivesService { //若删除为案卷 }else if(archivesType.getIsType() == 3){ String enName_4 = archivesTypeRepository.findEnNameByPid(archivesType.getId()); + if(null == enName_4) + return result; String update4sql = "update " + enName_4 + " set is_delete_time = '" +delTime+"',is_delete_man='"+dto.getDelMan() +"' where parent_id in ('"+ids.stream().map(String::valueOf).collect(Collectors.joining("','"))+"')"; diff --git a/archives/src/main/java/com/storeroom/modules/dictionary/controller/ArchivesDictrionaryController.java b/archives/src/main/java/com/storeroom/modules/dictionary/controller/ArchivesDictrionaryController.java index fb90047..e4b30c7 100644 --- a/archives/src/main/java/com/storeroom/modules/dictionary/controller/ArchivesDictrionaryController.java +++ b/archives/src/main/java/com/storeroom/modules/dictionary/controller/ArchivesDictrionaryController.java @@ -75,6 +75,13 @@ public class ArchivesDictrionaryController { if (StringUtils.isEmpty(arcdicDto.getDictionaryConfigId().getId()) || arcdicDto.getDictionaryConfigId().getId().equals("null")) { arcdicDto.setDictionaryConfigId(null); } + boolean isFieldRepeat = arcdicService.isFieldRepeat(arcdicDto.getCategoryId(),arcdicDto.getFieldName(),arcdicDto.getId()); + if(!isFieldRepeat) + throw new BaseException("字段标识不能重复"); + boolean isFieldCnRepeat = arcdicService.isFieldCnRepeat(arcdicDto.getCategoryId(),arcdicDto.getFieldCnName(),arcdicDto.getId()); + if(!isFieldCnRepeat) + throw new BaseException("字段名称不能重复"); + arcdicService.update(arcdicDto); return ApiResponse.success(ResponseStatus.SUCCESS); } diff --git a/archives/src/main/java/com/storeroom/modules/dictionary/controller/FieldController.java b/archives/src/main/java/com/storeroom/modules/dictionary/controller/FieldController.java index 13f028a..7ed5f02 100644 --- a/archives/src/main/java/com/storeroom/modules/dictionary/controller/FieldController.java +++ b/archives/src/main/java/com/storeroom/modules/dictionary/controller/FieldController.java @@ -28,7 +28,7 @@ public class FieldController { public ApiResponse edit( @Validated @RequestBody FieldDTO dto ){ - String returnCode = fieldService.edit(dto,"test"); + String returnCode = fieldService.edit(dto); return returnCode != null ? ApiResponse.error(ResponseStatus.FIELD_REPEAT) : ApiResponse.success(dto.getId() == null ? ResponseStatus.SUCCESS : HttpStatus.NO_CONTENT); } diff --git a/archives/src/main/java/com/storeroom/modules/dictionary/domain/ArchivesType.java b/archives/src/main/java/com/storeroom/modules/dictionary/domain/ArchivesType.java index 7c00fbf..6717d15 100644 --- a/archives/src/main/java/com/storeroom/modules/dictionary/domain/ArchivesType.java +++ b/archives/src/main/java/com/storeroom/modules/dictionary/domain/ArchivesType.java @@ -59,8 +59,8 @@ public class ArchivesType extends BaseEntity implements Serializable { @Column(name = "is_type_metic") @ApiModelProperty(value = "是否为模板档案") - @JSONField(ordinal = 7) - private Boolean isTypeMetic; +// @JSONField(ordinal = 7) + private boolean isTypeMetic; @Column(name = "remark") diff --git a/archives/src/main/java/com/storeroom/modules/dictionary/repository/ArchivesDictionaryRepository.java b/archives/src/main/java/com/storeroom/modules/dictionary/repository/ArchivesDictionaryRepository.java index 4617972..d584f06 100644 --- a/archives/src/main/java/com/storeroom/modules/dictionary/repository/ArchivesDictionaryRepository.java +++ b/archives/src/main/java/com/storeroom/modules/dictionary/repository/ArchivesDictionaryRepository.java @@ -1,10 +1,13 @@ package com.storeroom.modules.dictionary.repository; import com.storeroom.modules.dictionary.domain.ArchivesDictionary; +import org.apache.commons.compress.harmony.pack200.Archive; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; +import org.springframework.transaction.annotation.Transactional; import java.util.List; @@ -20,6 +23,10 @@ public interface ArchivesDictionaryRepository extends JpaRepository findAllByCategoryIdAndIsTypeOrderByIsSequenceAsc(String categoryId,Integer isType); + ArchivesDictionary findFirstByCategoryIdAndFieldNameAndFieldCnName(String categoryId, String fieldName, String fieldCnName); + ArchivesDictionary findFirstByCategoryIdAndFieldName(String categoryId, String fieldName); + ArchivesDictionary findFirstByCategoryIdAndFieldCnName(String categoryId, String fieldCnName); + List findAllByCategoryIdAndIsTypeAndIsInputOrderByIsSequenceAsc(String categoryId,Integer isType, boolean isInput); List findAllByCategoryIdAndIsTypeAndIsRepeat(String categoryId,Integer isType,boolean isRepeat); @@ -62,10 +69,6 @@ public interface ArchivesDictionaryRepository extends JpaRepository querybyName(String fName, String fcName); - - - ArchivesDictionary findFirstByCategoryIdAndFieldName(String categoryId,String fieldName); - /** * 查询字段隐藏状态 * @param state @@ -73,5 +76,9 @@ public interface ArchivesDictionaryRepository extends JpaRepository findByIsDisplayAndCategoryId(Boolean state,String categoryId); + @Modifying + @Transactional(rollbackFor = Exception.class) + @Query(nativeQuery = true,value = "delete from archives_dictionary where category_id = ?1") + void deleteByCategoryId(String categoryId); } diff --git a/archives/src/main/java/com/storeroom/modules/dictionary/repository/ArchivesTypeRepository.java b/archives/src/main/java/com/storeroom/modules/dictionary/repository/ArchivesTypeRepository.java index eb7863d..c6718c5 100644 --- a/archives/src/main/java/com/storeroom/modules/dictionary/repository/ArchivesTypeRepository.java +++ b/archives/src/main/java/com/storeroom/modules/dictionary/repository/ArchivesTypeRepository.java @@ -26,4 +26,12 @@ public interface ArchivesTypeRepository extends JpaRepository getAll(ArchivesDicStateDTO archivesDicStateDTO); + boolean isFieldRepeat(String categoryId,String fieldName,String id); + boolean isFieldCnRepeat(String categoryId,String fieldCnName,String id); + /** * 通过id 查询字段数据 diff --git a/archives/src/main/java/com/storeroom/modules/dictionary/service/FieldService.java b/archives/src/main/java/com/storeroom/modules/dictionary/service/FieldService.java index c4a01e9..0cf48ce 100644 --- a/archives/src/main/java/com/storeroom/modules/dictionary/service/FieldService.java +++ b/archives/src/main/java/com/storeroom/modules/dictionary/service/FieldService.java @@ -12,7 +12,7 @@ import java.util.List; public interface FieldService { //编辑字段信息 - String edit(FieldDTO dto,String userName); + String edit(FieldDTO dto); //分类获取字段数据 List findGroupType(Integer isType); //获取自动生成表字段 diff --git a/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesDictionaryImpl.java b/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesDictionaryImpl.java index 018b45b..580fa79 100644 --- a/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesDictionaryImpl.java +++ b/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesDictionaryImpl.java @@ -63,6 +63,26 @@ public class ArchivesDictionaryImpl implements ArchivesDictionaryService { return dtoList; } + @Override + public boolean isFieldRepeat(String categoryId, String fieldName, String id) { + ArchivesDictionary archivesDictionary = archivesDictionaryRepository.findFirstByCategoryIdAndFieldName(categoryId,fieldName); + if(archivesDictionary == null) + return true; + if(archivesDictionary.getId().equals(id)) + return true; + return false; + } + + @Override + public boolean isFieldCnRepeat(String categoryId, String fieldCnName, String id) { + ArchivesDictionary archivesDictionary = archivesDictionaryRepository.findFirstByCategoryIdAndFieldCnName(categoryId,fieldCnName); + if(archivesDictionary == null) + return true; + if(archivesDictionary.getId().equals(id)) + return true; + return false; + } + @Override public ArchivesDictionaryDTO findById(String adId) { return archivesDictionaryMapper.toDto(archivesDictionaryRepository.findById(adId).orElseGet(ArchivesDictionary::new)); @@ -114,25 +134,27 @@ public class ArchivesDictionaryImpl implements ArchivesDictionaryService { @Transactional public void create(ArchivesDictionaryDTO arcdicDto) { ArchivesDictionary arc = archivesDictionaryMapper.toEntity(arcdicDto); - List arc1 = archivesDictionaryRepository.querybyName(arc.getFieldName(), arc.getFieldCnName()); - if (arc1.size() == 0) { - arc.setId(NanoIdUtils.randomNanoId()); - arc.setIsInput(true); - archivesDictionaryRepository.save(arc); - - String colType = arcdicDto.getIsDataType() == 1?"varchar":"int"; - colType = colType+"("+arcdicDto.getIsColumnLength()+") "; - String adddefault = " "; - if(!StringUtils.isEmpty(arcdicDto.getIsDefaultValue())){ - adddefault = " default "; - adddefault = arcdicDto.getIsDataType() == 2 ? adddefault+arcdicDto.getIsDefaultValue() : adddefault+"'"+arcdicDto.getIsDefaultValue()+"'"; - } - ArchivesType archivesType = archivesTypeRepository.findById(arcdicDto.getCategoryId()).get(); - String sql = "alter table "+archivesType.getEnName()+" add "+arc.getFieldName()+" "+colType+adddefault+" comment '"+arc.getFieldCnName()+"'"; - entityManager.createNativeQuery(sql).executeUpdate(); - } else { + ArchivesDictionary fieldName = archivesDictionaryRepository.findFirstByCategoryIdAndFieldName(arcdicDto.getCategoryId(),arcdicDto.getFieldName()); + ArchivesDictionary fieldCnName = archivesDictionaryRepository.findFirstByCategoryIdAndFieldCnName(arcdicDto.getCategoryId(),arcdicDto.getFieldCnName()); + + if(fieldName != null) + throw new BaseException("字段标识不能重复"); + if(fieldCnName!=null) throw new BaseException("字段名称不能重复"); + + arc.setId(NanoIdUtils.randomNanoId()); + arc.setIsInput(true); + archivesDictionaryRepository.save(arc); + String colType = arcdicDto.getIsDataType() == 1?"varchar":"int"; + colType = colType+"("+arcdicDto.getIsColumnLength()+") "; + String adddefault = " "; + if(!StringUtils.isEmpty(arcdicDto.getIsDefaultValue())){ + adddefault = " default "; + adddefault = arcdicDto.getIsDataType() == 2 ? adddefault+arcdicDto.getIsDefaultValue() : adddefault+"'"+arcdicDto.getIsDefaultValue()+"'"; } + ArchivesType archivesType = archivesTypeRepository.findById(arcdicDto.getCategoryId()).get(); + String sql = "alter table "+archivesType.getEnName()+" add "+arc.getFieldName()+" "+colType+adddefault+" comment '"+arc.getFieldCnName()+"'"; + entityManager.createNativeQuery(sql).executeUpdate(); } @Override @@ -236,6 +258,7 @@ public class ArchivesDictionaryImpl implements ArchivesDictionaryService { archivesDisplaySmallDTOS.forEach(item -> { ArchivesDictionary archivesDictionary = archivesDictionaryRepository.findById(item.getId()).orElseGet(ArchivesDictionary::new); if (archivesDictionary != null) { + archivesDictionary.setQueue(item.getQueue()); archivesDictionary.setDisplayOrderBy(item.getDisplayOrderBy()); archivesDictionaryRepository.save(archivesDictionary); } else { diff --git a/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesTypeServiceImpl.java b/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesTypeServiceImpl.java index e798ba1..20c9210 100644 --- a/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesTypeServiceImpl.java +++ b/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesTypeServiceImpl.java @@ -3,6 +3,7 @@ package com.storeroom.modules.dictionary.service.impl; import com.storeroom.exception.BaseException; import com.storeroom.modules.common.ArchivesTypeEnum; import com.storeroom.modules.dictionary.domain.ArchivesType; +import com.storeroom.modules.dictionary.repository.ArchivesDictionaryRepository; import com.storeroom.modules.dictionary.repository.ArchivesTypeRepository; import com.storeroom.modules.dictionary.service.ArchivesTypeService; import com.storeroom.modules.dictionary.service.DynamicTableService; @@ -32,6 +33,7 @@ public class ArchivesTypeServiceImpl implements ArchivesTypeService { private final ArchivesTypeMapper archivesTypeMapper; private final ArchivesTypeRepository archivesTypeRepository; private final DynamicTableService dynamicTableService; + private final ArchivesDictionaryRepository archivesDictionaryRepository; @Override @@ -88,7 +90,7 @@ public class ArchivesTypeServiceImpl implements ArchivesTypeService { at2.setPid(at1.getPid()); at2.setIsType(at1.getIsType()); at2.setIsType(at1.getIsType()); - at2.setIsTypeMetic(at1.getIsTypeMetic()); + at2.setTypeMetic(at1.isTypeMetic()); at2.setCategorySeq(at1.getCategorySeq()); at2.setRemark(at1.getRemark()); archivesTypeRepository.save(at2); @@ -99,9 +101,48 @@ public class ArchivesTypeServiceImpl implements ArchivesTypeService { @Transactional(rollbackFor = Exception.class) public void delete(String id) { ArchivesType archivesType=archivesTypeRepository.findById(id).orElseGet(ArchivesType::new); + if(archivesType.isTypeMetic()) + throw new BaseException("系统门类不可删除"); + + Integer count = archivesTypeRepository.findContextCount(archivesType.getId()); + if(count!=0) + throw new BaseException("该门类存在档案信息,不可删除"); + + //查询子类 + if(archivesType.getIsType()!=ArchivesTypeEnum.files.getCode() && archivesType.getIsType() != ArchivesTypeEnum.inChive.getCode()) + { + Integer sonCount = archivesTypeRepository.findSonContextCount(archivesType.getId()); + if(sonCount>0) + throw new BaseException("该门类其子级门类存在档案信息,不可删除"); + } + String tableName = archivesType.getEnName(); dynamicTableService.DeleteTable(tableName); archivesTypeRepository.deleteById(id); + archivesDictionaryRepository.deleteByCategoryId(id); + if(archivesType.getIsType()==ArchivesTypeEnum.files.getCode() || archivesType.getIsType() == ArchivesTypeEnum.inChive.getCode()) + dynamicTableService.DeleteTable("file_"+tableName); + + Set sonIds = this.findSonCategoryIds(archivesType.getId(),new HashSet()); + for(ArchivesType thisType:sonIds){ + String tableName1 = thisType.getEnName(); + dynamicTableService.DeleteTable(tableName1); + archivesTypeRepository.deleteById(thisType.getId()); + archivesDictionaryRepository.deleteByCategoryId(thisType.getId()); + if(archivesType.getIsType()==ArchivesTypeEnum.files.getCode() || archivesType.getIsType() == ArchivesTypeEnum.inChive.getCode()) + dynamicTableService.DeleteTable("file_"+tableName1); + } + } + + public Set findSonCategoryIds(String categoryIds,Set setIds){ + if(StringUtils.isEmpty(categoryIds)) + return setIds; + List list = archivesTypeRepository.findAllByPid(categoryIds); + for(ArchivesType archivesType:list){ + setIds.add(archivesType); + this.findSonCategoryIds(archivesType.getId(),setIds); + } + return setIds; } @Override diff --git a/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/FieldServiceImpl.java b/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/FieldServiceImpl.java index 0aba84c..07b062a 100644 --- a/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/FieldServiceImpl.java +++ b/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/FieldServiceImpl.java @@ -21,14 +21,13 @@ public class FieldServiceImpl implements FieldService { private final FieldRepository fieldRepository; @Override - public String edit(FieldDTO dto, String userName) { + public String edit(FieldDTO dto) { Field field = new Field(); if(null != dto.getId()){ field = fieldRepository.findById(dto.getId()).get(); }else{ String newId = NanoIdUtils.randomNanoId(); field.setId(newId); - field.setCreateBy(userName); } String origId = fieldRepository.findIdFirstByFieldName(dto.getFieldName()); if(null != origId && !origId.equals(dto.getId())){