diff --git a/archives/src/main/java/com/storeroom/modules/archives/controller/StorageController.java b/archives/src/main/java/com/storeroom/modules/archives/controller/StorageController.java index 9ff8013..053704a 100644 --- a/archives/src/main/java/com/storeroom/modules/archives/controller/StorageController.java +++ b/archives/src/main/java/com/storeroom/modules/archives/controller/StorageController.java @@ -1,14 +1,19 @@ package com.storeroom.modules.archives.controller; import com.storeroom.modules.archives.service.ArchivesCaseService; +import com.storeroom.modules.archives.service.ArchivesService; +import com.storeroom.modules.archives.service.dto.CaseDTO; +import com.storeroom.modules.archives.service.dto.CollectDTO; import com.storeroom.utils.ApiResponse; +import com.storeroom.utils.enums.ResponseStatus; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Pageable; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.List; @RestController @RequiredArgsConstructor @@ -17,6 +22,7 @@ import org.springframework.web.bind.annotation.RestController; public class StorageController { private final ArchivesCaseService caseService; + private final ArchivesService archivesService; @ApiOperation("可入库盒列表") @GetMapping("/readyInto") @@ -34,6 +40,34 @@ public class StorageController { return ApiResponse.success(caseService.alReadyInto(caseName,archiveNo,title,location,page)); } + @ApiOperation("初始化档案装盒信息") + @GetMapping("/initCaseByArchives") + public ApiResponse initCaseByArchives( + String archivesId + ){ + return ApiResponse.success(caseService.initCaseByArchives(archivesId)); + } + + @ApiOperation("根据层架位id判断是否被占用") + @GetMapping("/isOccupy") + public ApiResponse isOccupy( + String shelfId + ){ + return ApiResponse.success(archivesService.isShelfOccupy(shelfId)); + } + @ApiOperation("入库") + @PostMapping("/collect") + public ApiResponse collect( + @Validated @RequestBody List dtos + ){ + if(null == dtos || dtos.size()==0) + return ApiResponse.error(ResponseStatus.DEVICE_IS_NULL); + String device = dtos.get(0).getDeviceId(); + //判断设备是否有回调 + boolean isCallback = false; + Integer result = caseService.collect(isCallback,dtos); + return ApiResponse.success(result); + } } diff --git a/archives/src/main/java/com/storeroom/modules/archives/domain/ArchivesCase.java b/archives/src/main/java/com/storeroom/modules/archives/domain/ArchivesCase.java index a0116b3..99a3ef4 100644 --- a/archives/src/main/java/com/storeroom/modules/archives/domain/ArchivesCase.java +++ b/archives/src/main/java/com/storeroom/modules/archives/domain/ArchivesCase.java @@ -38,6 +38,10 @@ public class ArchivesCase extends BaseEntity implements Serializable { @ApiModelProperty(value = "条形码") private String barcode; + @Column(name = "shelf_id") + @ApiModelProperty(value = "层架位id") + private String shelfId; + @Column(name = "folder_location") @ApiModelProperty(value = "存放位置") private String folderLocation; @@ -51,7 +55,7 @@ public class ArchivesCase extends BaseEntity implements Serializable { private Integer depositNum; @Column(name = "storage_type") - @ApiModelProperty(value = "入库状态 0.未入 1.待入 2.已入") + @ApiModelProperty(value = "入库状态 0.未入 1.待入 2.已入 3.待出") private Integer storageType; @Column(name = "storage_time") diff --git a/archives/src/main/java/com/storeroom/modules/archives/domain/ArchivesCaseCartoning.java b/archives/src/main/java/com/storeroom/modules/archives/domain/ArchivesCaseCartoning.java index e0a109d..3c48902 100644 --- a/archives/src/main/java/com/storeroom/modules/archives/domain/ArchivesCaseCartoning.java +++ b/archives/src/main/java/com/storeroom/modules/archives/domain/ArchivesCaseCartoning.java @@ -34,4 +34,8 @@ public class ArchivesCaseCartoning extends BaseEntity implements Serializable { @Column(name = "category_id") private String categoryId; + @ApiModelProperty(value = "父id") + @Column(name = "parent_id") + private String parentId; + } diff --git a/archives/src/main/java/com/storeroom/modules/archives/domain/ArchivesSummary.java b/archives/src/main/java/com/storeroom/modules/archives/domain/ArchivesSummary.java index 51ad576..b320e33 100644 --- a/archives/src/main/java/com/storeroom/modules/archives/domain/ArchivesSummary.java +++ b/archives/src/main/java/com/storeroom/modules/archives/domain/ArchivesSummary.java @@ -105,6 +105,10 @@ public class ArchivesSummary extends BaseEntity implements Serializable { @ApiModelProperty(value = "档案盒名称") private String caseName; + @Column(name = "shelf_id") + @ApiModelProperty(value = "层架位id") + private String shelfId; + @Column(name = "folder_location") @ApiModelProperty(value = "存放位置") private String folderLocation; 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 7be9eff..93cbdff 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 @@ -24,21 +24,21 @@ public interface ArchivesCaseRepository extends JpaRepository readyIntoCase(String caseName, String tid,String barcode, Pageable page); @Query(nativeQuery = true, - value = "SELECT asum.archives_id as archivesId,asum.child as child,asum.category_type as categoryType,asum.category_name as categoryName," + - "asum.fonds_no as fondsNo,asum.archive_no as archiveNo,asum.archive_year as archiveYear,asum.maintitle as maintitle," + - "asum.security_class as securityClass,asum.department as department,ace.case_name as caseName," + - "dct.area_No + '-' + di.device_name + '-' + dat.position as seat,ace.storage_time as storageTime " + + value = "SELECT asum.archives_id as archivesId,ace.storage_type as storageType,asum.child as child,asum.category_type as categoryType," + + "asum.category_name as categoryName,asum.fonds_no as fondsNo,asum.archive_no as archiveNo,asum.archive_year as archiveYear," + + "asum.maintitle as maintitle,asum.security_class as securityClass,asum.department as department,ace.case_name as caseName," + + "CONCAT(room.name ,'-' , di.device_name , '-' , dat.position_name) as seat,ace.storage_time as storageTime " + "FROM archives_case ace " + "INNER JOIN archives_case_cartoning acc ON ace.id = acc.case_id " + "INNER JOIN archives_summary asum ON acc.archives_id = asum.archives_id " + "INNER JOIN device_archives_tag dat on asum.shelf_id = dat.id " + - "INNER JOIN dese_cabinet dct on dat.device_info_id = dct.device_info_id " + - "INNER JOIN device_info di on dct.device_info_id = di.id " + - "WHERE ace.storage_type = 2 " + + "INNER JOIN device_info di ON dat.device_info_id = di.id " + + "INNER JOIN storeroom room ON di.storeroom_id = room.id " + + "WHERE ace.storage_type >= 2 " + "AND if(?1 is null,1=1,ace.case_name like ?1) " + "AND if(?2 is null,1=1,asum.archive_no like ?2) " + "AND if(?3 is null,1=1,asum.maintitle like ?3) " + - "AND if(?4 is null,1=1,find_in_set(?4,dct.area_No + '-' + di.device_name + '-' + dat.position)) ") + "AND if(?4 is null,1=1,CONCAT(room.name ,'-' , di.device_name , '-' , dat.position_name) like ?4) ") Page> alReadyInto(String caseName, String archiveNo, String title, String location, Pageable page); @@ -71,5 +71,9 @@ public interface ArchivesCaseRepository extends JpaRepository findAllByCaseName(String caseName); List findAllByBarcode(String barcode); + @Query(nativeQuery = true, + value = "select ac.* from archives_case ac inner join archives_case_cartoning acc on ac.id=acc.case_id where acc.parent_id = ?1 group by ac.id ") + List initCaseByArchives(String archivesId); + } 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 fa24679..8c93946 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 @@ -50,7 +50,10 @@ public interface ArchivesSummaryRepository extends JpaRepository findAllByCaseNoLike(String caseId); List findAllByCaseNoAndCategoryType(String caseId,Integer categoryType); + List findAllByCaseNoLikeAndCategoryType(String caseId,Integer categoryType); + Integer countAllByShelfId(String shelfId); } diff --git a/archives/src/main/java/com/storeroom/modules/archives/service/ArchivesCaseService.java b/archives/src/main/java/com/storeroom/modules/archives/service/ArchivesCaseService.java index e41b69d..663e1d1 100644 --- a/archives/src/main/java/com/storeroom/modules/archives/service/ArchivesCaseService.java +++ b/archives/src/main/java/com/storeroom/modules/archives/service/ArchivesCaseService.java @@ -3,6 +3,7 @@ package com.storeroom.modules.archives.service; import com.storeroom.modules.archives.domain.ArchivesCaseCartoning; import com.storeroom.modules.archives.service.dto.ArchivesCaseCartoningDTO; import com.storeroom.modules.archives.service.dto.CaseDTO; +import com.storeroom.modules.archives.service.dto.CollectDTO; import org.springframework.data.domain.Pageable; import java.util.List; @@ -37,5 +38,8 @@ public interface ArchivesCaseService { Object readyIntoCase(String tid, String caseName,String barcode, Pageable page); //查看已入库列表 Object alReadyInto(String caseName,String archiveNo,String title,String location, Pageable page); - + //根据档案初始化装盒信息 + Object initCaseByArchives(String archivesId); + //入库 + Integer collect(boolean isCallback,List dtos); } 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 f0672c0..b854a36 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 @@ -45,4 +45,6 @@ public interface ArchivesService { Object completelyDelete(ArchivesDTO dto); //根据门类id获取所有父级id String getcategoryAllParentsId(String categoryId); + //根据层架位id判断是否被占用 + boolean isShelfOccupy(String shelfId); } diff --git a/archives/src/main/java/com/storeroom/modules/archives/service/dto/CollectDTO.java b/archives/src/main/java/com/storeroom/modules/archives/service/dto/CollectDTO.java new file mode 100644 index 0000000..1363593 --- /dev/null +++ b/archives/src/main/java/com/storeroom/modules/archives/service/dto/CollectDTO.java @@ -0,0 +1,20 @@ +package com.storeroom.modules.archives.service.dto; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class CollectDTO { + //设备id + private String deviceId; + //盒id + private String caseId; + //架id + private String shelfId; + //架编码 + private String position; + //架名称 + private String positionName; + +} 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 a7b7421..3045e75 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 @@ -10,6 +10,7 @@ import com.storeroom.modules.archives.service.ArchivesCaseService; import com.storeroom.modules.archives.service.dto.ArchivesCaseCartoningDTO; import com.storeroom.modules.archives.domain.vo.ArchivesCaseVO; import com.storeroom.modules.archives.service.dto.CaseDTO; +import com.storeroom.modules.archives.service.dto.CollectDTO; import com.storeroom.modules.common.ArchivesTypeEnum; import com.storeroom.modules.dictionary.domain.ArchivesType; import com.storeroom.modules.dictionary.repository.ArchivesTypeRepository; @@ -62,7 +63,7 @@ public class ArchivesCaseServiceImpl implements ArchivesCaseService { return true; } }else{ - if(!caseId.equals(caseList.get(0).getId())){ + if(caseList.size()!=0 && !caseId.equals(caseList.get(0).getId())){ return true; } } @@ -200,6 +201,7 @@ public class ArchivesCaseServiceImpl implements ArchivesCaseService { caseIds.add(archivesCaseCartoning.getCaseId()); caseNames.add(archivesCaseCartoning.getCaseName()); BeanUtils.copyProperties(archivesCaseCartoning,Cartoning); + Cartoning.setParentId(archivesCaseCartoning.getArchivesParentsId()); return Cartoning; }).collect(Collectors.toList()); archivesCaseCartonings = archivesCaseCartoningRepository.saveAllAndFlush(archivesCaseCartonings); @@ -285,21 +287,24 @@ public class ArchivesCaseServiceImpl implements ArchivesCaseService { ArchivesCase archivesCase = caseRepository.findById(caseId).get(); List editArchivesSummaries = new ArrayList<>(); List archivesIds = new ArrayList<>(); + List oneCaseIds = new ArrayList<>(); Set caseIds = new HashSet<>(); String categoryId = ""; + String caseIdLike = "%"+caseId+"%"; //文件类型档案盒 if(archivesCase.getCaseType()==1){ - List archivesSummaries = archivesSummaryRepository.findAllByCaseNoAndCategoryType(caseId, ArchivesTypeEnum.files.getCode()); + List archivesSummaries = archivesSummaryRepository.findAllByCaseNoLikeAndCategoryType(caseIdLike, ArchivesTypeEnum.files.getCode()); for(ArchivesSummary archivesSummary:archivesSummaries){ categoryId = archivesSummary.getCategoryId(); archivesIds.add(archivesSummary.getArchivesId()); archivesSummary.setCaseNo(null); + archivesSummary.setCaseName(null); editArchivesSummaries.add(archivesSummary); } caseIds.add(archivesCase.getId()); //案卷类型盒 }else if(archivesCase.getCaseType()==2){ - List archivesSummaries = archivesSummaryRepository.findAllByCaseNoAndCategoryType(caseId,ArchivesTypeEnum.inChive.getCode()); + List archivesSummaries = archivesSummaryRepository.findAllByCaseNoLikeAndCategoryType(caseIdLike,ArchivesTypeEnum.inChive.getCode()); for(ArchivesSummary archivesSummary:archivesSummaries){ categoryId = archivesSummary.getCategoryId(); archivesIds.add(archivesSummary.getArchivesId()); @@ -309,10 +314,25 @@ public class ArchivesCaseServiceImpl implements ArchivesCaseService { archivesSummary.setUpdateTime(new Timestamp(System.currentTimeMillis())); editArchivesSummaries.add(archivesSummary); } + + List archivesSummariesP = archivesSummaryRepository.findAllByCaseNoLikeAndCategoryType(caseIdLike,ArchivesTypeEnum.archives.getCode()); + for(ArchivesSummary archivesSummary:archivesSummariesP){ + String caseNos = archivesSummary.getCaseNo(); + String[] caseNoss = caseNos.split(","); + for(String cn : caseNoss){ + caseIds.add(cn); + } + archivesSummary.setCaseNo(null); + archivesSummary.setCaseName(null); + archivesSummary.setUpdateTime(new Timestamp(System.currentTimeMillis())); + editArchivesSummaries.add(archivesSummary); + } + if(caseIds.size()>1) { for (String thisCaseId : caseIds) { if(!caseId.equals(thisCaseId)){ - for (ArchivesSummary thisSummary : archivesSummaries) { + List additional = archivesSummaryRepository.findAllByCaseNoAndCategoryType(thisCaseId,ArchivesTypeEnum.inChive.getCode()); + for (ArchivesSummary thisSummary : additional) { if (thisCaseId.equals(thisSummary.getCaseNo())) { thisSummary.setCaseNo(null); thisSummary.setCaseName(null); @@ -322,6 +342,7 @@ public class ArchivesCaseServiceImpl implements ArchivesCaseService { } } caseRepository.cartoning(thisCaseId,0,0); + oneCaseIds.add(thisCaseId); result = result+1; } } @@ -336,13 +357,20 @@ public class ArchivesCaseServiceImpl implements ArchivesCaseService { //清空具体档案表盒信息 for(String archivesId:archivesIds){ //若为案卷 - if(archivesType.getIsType() == 2){ + if(archivesType.getIsType() == 4){ ArchivesType archivesTypeP = archivesTypeRepository.findById(archivesType.getPid()).get(); - String sonsql = "update " +archivesTypeP.getEnName() + " set case_no = null where parent_id = '"+archivesId+"'"; + String sonsql = "update " +archivesTypeP.getEnName() + " set case_no = null where id = (select parent_id from "+archivesType.getEnName() + +" where id = '"+archivesId+"')"; entityManager.createNativeQuery(sonsql).executeUpdate(); } String sql = "update " +archivesType.getEnName() + " set case_no = null where id = '"+archivesId+"'"; entityManager.createNativeQuery(sql).executeUpdate(); + + if(oneCaseIds.size()!=0){ + String oneCase = oneCaseIds.size()==1?oneCaseIds.get(0) : oneCaseIds.stream().map(String::valueOf).collect(Collectors.joining("','")); + String onesql = "update " +archivesType.getEnName() + " set case_no = null where case_no in ('"+oneCase+"')"; + entityManager.createNativeQuery(onesql).executeUpdate(); + } } archivesCaseCartoningRepository.deleteByCaseId(Arrays.asList(caseIds.toArray())); caseRepository.cartoning(caseId,0,0); @@ -385,4 +413,53 @@ public class ArchivesCaseServiceImpl implements ArchivesCaseService { Page> pageCase = caseRepository.alReadyInto(caseName,archiveNo,title,location,page); return PageUtil.toPage(pageCase); } + + @Override + public Object initCaseByArchives(String archivesId) { + return caseRepository.initCaseByArchives(archivesId); + } + + @Override + public Integer collect(boolean isCallback, List dtos) { + List cases = new ArrayList<>(); + Set archices = new HashSet<>(); + for (CollectDTO dto : dtos){ + ArchivesCase thisCase = caseRepository.findById(dto.getCaseId()).get(); + thisCase.setShelfId(dto.getShelfId()); + thisCase.setFolderLocation(dto.getPosition()); + thisCase.setFolderLocationDetails(dto.getPositionName()); + thisCase.setStorageType(isCallback ? 1:2); + cases.add(thisCase); + + List thisSummarys = archivesSummaryRepository.findAllByCaseNoLike(dto.getCaseId()); + for(ArchivesSummary summary : thisSummarys){ + String summaryCaseIds = summary.getCaseNo(); + String[] caseIds = summaryCaseIds.split(","); + String newShelfId = "";String newLocation = "";String newLocationName=""; + Integer resultOk = 0; + for (String caseId : caseIds){ + for(CollectDTO dto1 : dtos){ + if(caseId.equals(dto1.getCaseId())){ + newShelfId += dto1.getShelfId() + ","; + newLocation += dto1.getPosition() + ","; + newLocationName += dto1.getPositionName()+","; + resultOk++; + } + } + } + if(resultOk>1){ + newShelfId = newShelfId.substring(0,newShelfId.length()-1); + newLocation = newLocation.substring(0,newLocation.length()-1); + newLocationName = newLocationName.substring(0,newLocationName.length()-1); + } + summary.setShelfId(newShelfId); + summary.setFolderLocation(newLocation); + summary.setFolderLocationDetails(newLocationName); + archices.add(summary); + } + } + caseRepository.saveAllAndFlush(cases); + archivesSummaryRepository.saveAllAndFlush(archices); + return cases.size(); + } } 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 952f72e..e16c738 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 @@ -371,12 +371,12 @@ public class ArchivesServiceImpl implements ArchivesService { archivesSummary.setArchivesId(insertId); archivesSummary.setChild(0); //如果有父级 - if(!StringUtils.isEmpty(dto.getParentsId())){ - ArchivesType archivesTypeP = archivesTypeRepository.findByPid(archivesType.getId()); + if(!StringUtils.isEmpty(dto.getParentsId()) && !"0".equals(dto.getParentsId())){ + ArchivesType archivesTypeP = archivesTypeRepository.findById(archivesType.getPid()).get(); entityManager.createNativeQuery("update "+archivesTypeP.getEnName()+" set child = (select count(1) from " - +archivesType.getEnName()+"where parent_id ='"+dto.getParentsId()+"') where id = '"+dto.getParentsId()+"'").executeUpdate(); + +archivesType.getEnName()+" where parent_id ='"+dto.getParentsId()+"') where id = '"+dto.getParentsId()+"'").executeUpdate(); entityManager.createNativeQuery("update archives_summary set child = (select count(1) from " - +archivesType.getEnName()+"where parent_id ='"+dto.getParentsId()+"') where archives_id = '"+dto.getParentsId()+"'").executeUpdate(); + +archivesType.getEnName()+" where parent_id ='"+dto.getParentsId()+"') where archives_id = '"+dto.getParentsId()+"'").executeUpdate(); } } @@ -556,8 +556,8 @@ public class ArchivesServiceImpl implements ArchivesService { archivesSummaryRepository.saveAndFlush(archivesSummary); //修改父级 - Optional optional = archivesTypeRepository.findById(archivesType.getId()); - if(optional.isPresent()) { + Optional optional = archivesTypeRepository.findById(archivesType.getPid()); + if(optional.isPresent() && 1 != optional.get().getIsType()) { ArchivesType archivesTypeP = optional.get(); String updateChild = "update " + archivesTypeP.getEnName() + " set child = (select count(1) from " + archivesType.getEnName() + " where parent_id = (select parent_id from " + archivesType.getEnName() + " where id = '" + id @@ -673,8 +673,8 @@ public class ArchivesServiceImpl implements ArchivesService { archivesSummaryRepository.saveAndFlush(archivesSummary); //修改父级 - Optional optional = archivesTypeRepository.findById(archivesType.getId()); - if(optional.isPresent()){ + Optional optional = archivesTypeRepository.findById(archivesType.getPid()); + if(optional.isPresent() && 1 != optional.get().getIsType()){ ArchivesType archivesTypeP = optional.get(); String updateChild = "update "+archivesTypeP.getEnName()+" set child = (select count(1) from "+archivesType.getEnName() +" where parent_id = (select parent_id from "+archivesType.getEnName()+" where id = '"+id @@ -919,4 +919,10 @@ public class ArchivesServiceImpl implements ArchivesService { }while(thisCategoryId!=null); return categoryIds.stream().map(String::valueOf).collect(Collectors.joining(",")); } + + @Override + public boolean isShelfOccupy(String shelfId) { + Integer count = archivesSummaryRepository.countAllByShelfId(shelfId); + return count==0 ? false:true; + } } diff --git a/common/src/main/java/com/storeroom/utils/enums/ResponseStatus.java b/common/src/main/java/com/storeroom/utils/enums/ResponseStatus.java index bae754d..b888396 100644 --- a/common/src/main/java/com/storeroom/utils/enums/ResponseStatus.java +++ b/common/src/main/java/com/storeroom/utils/enums/ResponseStatus.java @@ -22,7 +22,9 @@ public enum ResponseStatus { //Field重复 FIELD_REPEAT(5001,"当前字段重复"), //当前标签已被绑定 - LABEL_BOUND(6201,"当前标签已被绑定"); + LABEL_BOUND(6201,"当前标签已被绑定"), + //设备 为空 + DEVICE_IS_NULL(7001,"找不到当前设备");