From c6f0904a410db01869641960628d4066af326039 Mon Sep 17 00:00:00 2001 From: xia Date: Thu, 25 Aug 2022 16:17:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=A1=A3=E6=A1=88=E7=9B=92?= =?UTF-8?q?=E3=80=81=E9=97=A8=E7=B1=BB=E5=AD=97=E6=AE=B5=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=88=A0=E9=99=A4bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ArchivesController.java | 18 +++++++++++++ .../repository/ArchivesSummaryRepository.java | 7 ++++- .../archives/service/ArchivesService.java | 4 +++ .../service/impl/ArchivesCaseServiceImpl.java | 2 +- .../service/impl/ArchivesServiceImpl.java | 27 ++++++++++++++++--- .../service/impl/ArchivesDictionaryImpl.java | 23 ++++++++++++++++ 6 files changed, 75 insertions(+), 6 deletions(-) diff --git a/archives/src/main/java/com/storeroom/modules/archives/controller/ArchivesController.java b/archives/src/main/java/com/storeroom/modules/archives/controller/ArchivesController.java index aed50af..0337c73 100644 --- a/archives/src/main/java/com/storeroom/modules/archives/controller/ArchivesController.java +++ b/archives/src/main/java/com/storeroom/modules/archives/controller/ArchivesController.java @@ -203,6 +203,23 @@ public class ArchivesController { return ApiResponse.success(archivesService.completelyDelete(dto)); } + @ApiOperation("门类下档案数") + @GetMapping("/countByCategory") + public ApiResponse countByCategory( + String categoryId + ){ + return ApiResponse.success(archivesService.countByCategory(categoryId)); + } + + @ApiOperation("删除门类所有档案(总表)") + @PostMapping("/deleteByCategory") + public ApiResponse deleteByCategory( + @Validated @RequestBody ArchivesDTO dto + ){ + archivesService.deleteByCategory(dto.getCategoryId()); + return ApiResponse.success(true); + } + @ApiOperation("档案类别数量统计") @GetMapping("/initArchivesTypeNum") public ApiResponse initArchivesTypeNum(Integer year) @@ -214,6 +231,7 @@ public class ArchivesController { @GetMapping("/initArchivesTypeStatistics") public ApiResponse initArchivesTypeStatistics(String yearMonth) { + yearMonth = StringUtils.isEmpty(yearMonth) ? null : yearMonth; return ApiResponse.success(archivesService.initArchivesTypeStatistics(yearMonth)); } diff --git a/archives/src/main/java/com/storeroom/modules/archives/repository/ArchivesSummaryRepository.java b/archives/src/main/java/com/storeroom/modules/archives/repository/ArchivesSummaryRepository.java index 340a9b2..4a5f88d 100644 --- a/archives/src/main/java/com/storeroom/modules/archives/repository/ArchivesSummaryRepository.java +++ b/archives/src/main/java/com/storeroom/modules/archives/repository/ArchivesSummaryRepository.java @@ -201,7 +201,7 @@ public interface ArchivesSummaryRepository extends JpaRepository> initArchivesSearchRanking(String yearMonth); + @Modifying + @Transactional(rollbackFor = Exception.class) + @Query(nativeQuery = true,value = "delete from archives_summary where category_id = ?1") + void deleteByCategoryId(String categoryId); + } diff --git a/archives/src/main/java/com/storeroom/modules/archives/service/ArchivesService.java b/archives/src/main/java/com/storeroom/modules/archives/service/ArchivesService.java index c337cb4..f12229d 100644 --- a/archives/src/main/java/com/storeroom/modules/archives/service/ArchivesService.java +++ b/archives/src/main/java/com/storeroom/modules/archives/service/ArchivesService.java @@ -53,6 +53,10 @@ public interface ArchivesService { Object delete(ArchivesDTO dto); //档案从回收站还原 Object reduction(ArchivesDTO dto); + //根据门类获取档案数量 + Object countByCategory(String categoryId); + //根据门类删除总表档案 + void deleteByCategory(String categoryId); //档案回收站删除 Object completelyDelete(ArchivesDTO dto); //根据门类id获取所有父级id diff --git a/archives/src/main/java/com/storeroom/modules/archives/service/impl/ArchivesCaseServiceImpl.java b/archives/src/main/java/com/storeroom/modules/archives/service/impl/ArchivesCaseServiceImpl.java index a94eb6f..db7fb3c 100644 --- a/archives/src/main/java/com/storeroom/modules/archives/service/impl/ArchivesCaseServiceImpl.java +++ b/archives/src/main/java/com/storeroom/modules/archives/service/impl/ArchivesCaseServiceImpl.java @@ -461,7 +461,7 @@ public class ArchivesCaseServiceImpl implements ArchivesCaseService { List r = new ArrayList(); for(String caseId:caseIds){ Integer borrowType = caseRepository.findBorrowCase(caseId); - if(null != borrowType && borrowType != 4){ + if(null != borrowType && borrowType != 4 && borrowType != -1){ r.add(caseId); } } 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 2f404b0..7897b2a 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,16 +674,16 @@ 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_3.getEnName()+" where parent_id in ('"+ids.stream().map(String::valueOf).collect(Collectors.joining("','"))+"')"; + 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(); if(null != list3 && list3.size()!=0){ //删除案卷 - String update3sql = "update " + archivesType_3.getEnName() + " set is_delete_time = '" +delTime+"',is_delete_man='"+dto.getDelMan() + String update3sql = "update " + archivesType.getEnName() + " set is_delete_time = '" +delTime+"',is_delete_man='"+dto.getDelMan() +"' where id in ('"+list3.stream().map(String::valueOf).collect(Collectors.joining("','"))+"')"; //获取卷内表名 - String enName_4 = archivesTypeRepository.findEnNameByPid(archivesType_3.getId()); + String enName_4 = archivesTypeRepository.findEnNameByPid(archivesType.getId()); 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(); //删除卷内 @@ -904,6 +904,25 @@ public class ArchivesServiceImpl implements ArchivesService { return success; } + @Override + public Object countByCategory(String categoryId) { + Optional optional = archivesTypeRepository.findById(categoryId); + if(!optional.isPresent()) + return 0; + String sql = "select count(1) from " +optional.get().getEnName() +" where is_delete_time is null"; + List list = entityManager.createNativeQuery(sql).getResultList(); + if(list == null || list.size()==0) + return 0; + + return list.get(0); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void deleteByCategory(String categoryId) { + archivesSummaryRepository.deleteByCategoryId(categoryId); + } + @Override @Transactional(rollbackFor = Exception.class) public Object completelyDelete(ArchivesDTO dto) { 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 f5a1e7a..018b45b 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 @@ -3,16 +3,21 @@ package com.storeroom.modules.dictionary.service.impl; import com.storeroom.exception.BaseException; import com.storeroom.modules.dictionary.domain.ArchivesDictionary; +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.ArchivesDictionaryService; import com.storeroom.modules.dictionary.service.dto.*; import com.storeroom.modules.dictionary.service.mapstruct.ArchivesDictionaryMapper; import com.storeroom.utils.NanoIdUtils; +import com.storeroom.utils.StringUtils; import com.storeroom.utils.ValidationUtil; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; import java.util.ArrayList; import java.util.Comparator; import java.util.List; @@ -22,6 +27,9 @@ import java.util.Set; @RequiredArgsConstructor public class ArchivesDictionaryImpl implements ArchivesDictionaryService { + @PersistenceContext + EntityManager entityManager; + private final ArchivesTypeRepository archivesTypeRepository; private final ArchivesDictionaryRepository archivesDictionaryRepository; private final ArchivesDictionaryMapper archivesDictionaryMapper; @@ -111,6 +119,17 @@ public class ArchivesDictionaryImpl implements ArchivesDictionaryService { 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 { throw new BaseException("字段名称不能重复"); } @@ -119,7 +138,11 @@ public class ArchivesDictionaryImpl implements ArchivesDictionaryService { @Override @Transactional public void delete(String id) { + ArchivesDictionary archivesDictionary = archivesDictionaryRepository.findById(id).get(); + ArchivesType archivesType = archivesTypeRepository.findById(archivesDictionary.getCategoryId()).get(); archivesDictionaryRepository.deleteById(id); + String sql = "alter table "+archivesType.getEnName()+" DROP COLUMN "+archivesDictionary.getFieldName(); + entityManager.createNativeQuery(sql).executeUpdate(); } @Override