From bb39d248cd507a688ab39c23486eecdb72ce561c Mon Sep 17 00:00:00 2001 From: xia Date: Fri, 24 Jun 2022 16:36:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=A1=A3=E6=A1=88=E6=A8=A1?= =?UTF-8?q?=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + .../controller/ArchivesController.java | 120 ++++++++++++- .../archives/domain/vo/ArchivesDetailsVO.java | 14 ++ .../archives/service/ArchivesService.java | 16 +- .../archives/service/dto/ArchivesDTO.java | 4 + .../service/impl/ArchivesCaseServiceImpl.java | 8 +- .../service/impl/ArchivesServiceImpl.java | 158 ++++++++++++++++-- .../storeroom/modules/common/ExcelUtil.java | 80 +++++++++ .../ArchivesDictionaryRepository.java | 11 +- .../repository/ArchivesTypeRepository.java | 3 + .../service/impl/ArchivesDictionaryImpl.java | 3 - 11 files changed, 394 insertions(+), 24 deletions(-) create mode 100644 archives/src/main/java/com/storeroom/modules/archives/domain/vo/ArchivesDetailsVO.java create mode 100644 archives/src/main/java/com/storeroom/modules/common/ExcelUtil.java diff --git a/.gitignore b/.gitignore index 4db2a73..c55893f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /.idea target +archives/src/main/java/com/storeroom/modules/dictionary/repository/ArchivesDictionaryRepository.java.rej 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 362fa52..725e8d6 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 @@ -1,17 +1,34 @@ package com.storeroom.modules.archives.controller; +import com.storeroom.annotaion.rest.AnonymousGetMapping; import com.storeroom.modules.archives.service.ArchivesService; import com.storeroom.modules.archives.service.dto.ArchivesDTO; import com.storeroom.modules.archives.service.dto.ArchivesFileDTO; +import com.storeroom.modules.common.ArchivesTypeEnum; +import com.storeroom.modules.common.ExcelUtil; +import com.storeroom.modules.dictionary.domain.ArchivesDictionary; +import com.storeroom.modules.dictionary.service.ArchivesTypeService; +import com.storeroom.modules.dictionary.service.dto.ArchivesTypeDTO; import com.storeroom.modules.dictionary.service.dto.FieldDTO; import com.storeroom.utils.ApiResponse; import com.storeroom.utils.SecurityUtils; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; import lombok.RequiredArgsConstructor; +import lombok.SneakyThrows; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.springframework.beans.factory.annotation.Value; import org.springframework.data.domain.Pageable; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletResponse; +import java.io.File; +import java.io.OutputStream; +import java.util.List; +import java.util.stream.Collectors; @RestController @RequiredArgsConstructor @@ -19,7 +36,12 @@ import org.springframework.web.bind.annotation.*; @RequestMapping("/api/archives") public class ArchivesController { + @Value("${file.windows.path}") +// @Value("${file.linux.path}") + private String prefixPath; + private final ArchivesService archivesService; + private final ArchivesTypeService archivesTypeService; @ApiOperation("档案列表") @GetMapping("/initArchivesViewTable") @@ -32,9 +54,19 @@ public class ArchivesController { @ApiOperation("档案列表") @GetMapping("/initArchivesView") public ApiResponse initArchivesView( - String categoryId,String parentsId,String query,Integer archivesState,boolean isdel,Pageable page + String categoryId,String parentsId,String query,Integer archivesState,String archiveYear,String department, + String retention,String securityClass,String organizationMatter,boolean isdel,Pageable page + ){ + return ApiResponse.success(archivesService.initArchivesView(categoryId,parentsId,query,archivesState, + archiveYear,department,retention,securityClass,organizationMatter,isdel,page)); + } + + @ApiOperation("档案详情") + @GetMapping("/archivesDetails") + public ApiResponse archivesDetails( + String categoryId,String archivesId ){ - return ApiResponse.success(archivesService.initArchivesView(categoryId,parentsId,query,archivesState,isdel,page)); + return ApiResponse.success(archivesService.archiveDetails(categoryId,archivesId)); } @ApiOperation("档案预编辑") @@ -82,7 +114,7 @@ public class ArchivesController { public ApiResponse deleteFile( @Validated @RequestBody ArchivesFileDTO dto ){ - return ApiResponse.success(archivesService.deleteFile(dto)); + return ApiResponse.success(archivesService.deleteFile(dto,prefixPath)); } @ApiOperation("档案删除") @@ -94,6 +126,14 @@ public class ArchivesController { return ApiResponse.success(archivesService.delete(dto)); } + @ApiOperation("档案还原") + @PostMapping("/reduction") + public ApiResponse reduction( + @Validated @RequestBody ArchivesDTO dto + ){ + return ApiResponse.success(archivesService.reduction(dto)); + } + @ApiOperation("档案回收站删除") @PostMapping("/completelyDelete") public ApiResponse completelyDelete( @@ -102,4 +142,78 @@ public class ArchivesController { return ApiResponse.success(archivesService.completelyDelete(dto)); } + @ApiOperation("根据门类导出数据") + @GetMapping("/exportArchives") +// @AnonymousGetMapping("/exportArchives") + @ResponseBody + public void exportArchives( + HttpServletResponse response, + String categoryId,String parentsId,Pageable page + ){ + ArchivesTypeDTO archivesType = archivesTypeService.findById(categoryId); + String fileNames = archivesType.getCnName(); + List showColumns = (List) archivesService.initArchivesViewTable(categoryId); + List fields = showColumns.stream().map(archivesDictionary -> { + return archivesDictionary.getFieldCnName(); + }).collect(Collectors.toList()); + fields.add(0,"序号"); + if(archivesType.getIsType() == ArchivesTypeEnum.project.getCode()){ + fields.add(1,"案卷"); + }else if(archivesType.getIsType() == ArchivesTypeEnum.archives.getCode()){ + fields.add(1,"卷内"); + }else{ + fields.add(1,"文件"); + } + fields.add("标签");fields.add("装盒");fields.add("入库");fields.add("借阅"); + String[] title = fields.toArray((new String[fields.size()])); + List list = archivesService.exportArchivesData(categoryId,parentsId,page); + String [][] content = new String[list.size()][]; + for(int i = 0;i uploadFile( + @ApiParam(value = "文件流", required = true, allowMultiple = true) @RequestParam("file") MultipartFile file, + @ApiParam(value = "门类id,必填") @RequestParam(required = false) @Validated String categoryId + ){ + //根据门类id查询门类所有父级 + String categoryIdAs = archivesService.getcategoryAllParentsId(categoryId); + String[] categoryIds = categoryIdAs.split(","); + String path = ""; + for(int i = categoryIds.length-1;i>=0;i--){ + path += categoryIds[i] + "/"; + } + String originalFilename = file.getOriginalFilename(); +// String fileType = originalFilename.substring(originalFilename.lastIndexOf("."), originalFilename.length());//file.getContentType(); + path = path + originalFilename; + File dest = new File(prefixPath +path); + // 判断文件父目录是否存在 + if (!dest.getParentFile().exists()) { + dest.getParentFile().mkdirs(); + } + // 保存文件 + file.transferTo(dest); + return ApiResponse.success("/"+path); + } + } diff --git a/archives/src/main/java/com/storeroom/modules/archives/domain/vo/ArchivesDetailsVO.java b/archives/src/main/java/com/storeroom/modules/archives/domain/vo/ArchivesDetailsVO.java new file mode 100644 index 0000000..7442f36 --- /dev/null +++ b/archives/src/main/java/com/storeroom/modules/archives/domain/vo/ArchivesDetailsVO.java @@ -0,0 +1,14 @@ +package com.storeroom.modules.archives.domain.vo; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class ArchivesDetailsVO { + + private String fieldName; + private String fieldCnName; + private Object context; + +} 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 71f6689..88050e3 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 @@ -1,15 +1,23 @@ package com.storeroom.modules.archives.service; +import com.storeroom.modules.archives.domain.vo.ArchivesDetailsVO; import com.storeroom.modules.archives.service.dto.ArchivesDTO; import com.storeroom.modules.archives.service.dto.ArchivesFileDTO; import com.storeroom.utils.ApiResponse; import org.springframework.data.domain.Pageable; +import java.util.List; + public interface ArchivesService { //初始化档案列表标题 Object initArchivesViewTable(String categoryId); //初始化档案列表 - Object initArchivesView(String categoryId,String parentsId, String query,Integer archivesState, boolean isdel,Pageable page); + Object initArchivesView(String categoryId,String parentsId, String query,Integer archivesState,String archiveYear,String department, + String retention,String securityClass,String organizationMatter, boolean isdel,Pageable page); + //根据门类id 档案id 获取显示档案详情信息 + List archiveDetails(String categoryId,String archivesId); + //导出档案数据 + List exportArchivesData(String categoryId,String archivesId,Pageable page); //预编辑档案 初始化信息 Object doedit(String categoryId,String archivesId); //档案编辑 判断值是否超昂福 @@ -21,9 +29,13 @@ public interface ArchivesService { //编辑档案附件 Object editFile(ArchivesFileDTO dto); //删除档案附件 - Object deleteFile(ArchivesFileDTO dto); + Object deleteFile(ArchivesFileDTO dto,String prefixPath); //档案删除进回收站 Object delete(ArchivesDTO dto); + //档案从回收站还原 + Object reduction(ArchivesDTO dto); //档案回收站删除 Object completelyDelete(ArchivesDTO dto); + //根据门类id获取所有父级id + String getcategoryAllParentsId(String categoryId); } diff --git a/archives/src/main/java/com/storeroom/modules/archives/service/dto/ArchivesDTO.java b/archives/src/main/java/com/storeroom/modules/archives/service/dto/ArchivesDTO.java index e73c54d..1be6c67 100644 --- a/archives/src/main/java/com/storeroom/modules/archives/service/dto/ArchivesDTO.java +++ b/archives/src/main/java/com/storeroom/modules/archives/service/dto/ArchivesDTO.java @@ -23,6 +23,10 @@ public class ArchivesDTO { @JsonProperty("categoryId") private String categoryId; + @JSONField(name="parentsId") + @JsonProperty("parentsId") + private String parentsId; + @JSONField(name="delMan") @JsonProperty("delMan") private String delMan; 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 4102194..f978aaf 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 @@ -92,15 +92,15 @@ public class ArchivesCaseServiceImpl implements ArchivesCaseService { ArchivesCase archivesCase = null; if(!StringUtils.isEmpty(dto.getId())){ archivesCase = caseRepository.findById(dto.getId()).get(); - archivesCase.setTid(""); - archivesCase.setBarcode(""); - archivesCase.setFolderLocation(""); - archivesCase.setFolderLocationDetails(""); }else{ archivesCase = new ArchivesCase(); archivesCase.setId(NanoIdUtils.randomNanoId()); archivesCase.setCaseType(0); archivesCase.setDepositNum(0); + archivesCase.setTid(""); + archivesCase.setBarcode(""); + archivesCase.setFolderLocation(""); + archivesCase.setFolderLocationDetails(""); } archivesCase.setCaseName(dto.getCaseName()); archivesCase.setBarcode(dto.getBarcode()); 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 40025f6..04b5ccb 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 @@ -3,6 +3,7 @@ package com.storeroom.modules.archives.service.impl; import cn.hutool.json.JSONArray; import cn.hutool.json.JSONObject; import com.storeroom.modules.archives.domain.ArchivesSummary; +import com.storeroom.modules.archives.domain.vo.ArchivesDetailsVO; import com.storeroom.modules.archives.repository.ArchivesSummaryRepository; import com.storeroom.modules.archives.service.ArchivesService; import com.storeroom.modules.archives.service.dto.ArchivesDTO; @@ -24,6 +25,7 @@ import org.springframework.transaction.annotation.Transactional; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; +import java.io.File; import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; @@ -47,7 +49,9 @@ public class ArchivesServiceImpl implements ArchivesService { } @Override - public Object initArchivesView(String categoryId,String parentsId, String query,Integer archivesState, boolean isdel,Pageable page) { + public Object initArchivesView(String categoryId,String parentsId, String query,Integer archivesState, + String archiveYear,String department,String retention,String securityClass,String organizationMatter, + boolean isdel,Pageable page) { Optional optional = archivesTypeRepository.findById(categoryId); if(!optional.isPresent()) return "未查询到到门类信息!"; @@ -74,12 +78,18 @@ public class ArchivesServiceImpl implements ArchivesService { String[] splits = obj.toString().split(":"); quertOrder += splits[0].trim()+" "+splits[1].trim() +","; } - String additional = isdel ? " t where is_delete_time is not null " : " where is_delete_time is null "; + String additional = isdel ? " t where is_delete_time is not null " : " t where is_delete_time is null "; String queryparentsId = StringUtils.isEmpty(parentsId) ? " " : " and parent_id = '"+parentsId+"' "; + additional = StringUtils.isEmpty(archiveYear) ? archiveYear : additional + " and archive_year = '"+archiveYear+"'"; + additional = StringUtils.isEmpty(department) ? department : additional + " and department = '"+department+"'"; + additional = StringUtils.isEmpty(retention) ? retention : additional + " and retention = '"+retention+"'"; + additional = StringUtils.isEmpty(securityClass) ? securityClass : additional + " and security_class = '"+securityClass+"'"; + additional = StringUtils.isEmpty(organizationMatter) ? organizationMatter : additional + " and organization_matter = '"+organizationMatter+"'"; additional = StringUtils.isEmpty(query) ? additional : additional + " and (maintitle like '%"+query+"%' or archive_no like '%"+query+"%' or archive_year like '%"+query+"%') "; + if(objects.length > 0) quertOrder = " order by " + quertOrder.substring(0,quertOrder.length()-1); @@ -95,14 +105,81 @@ public class ArchivesServiceImpl implements ArchivesService { } returnlist.add(map); } - return PageUtil.toPage(returnlist,count); + List yearGroup = entityManager.createNativeQuery("select archive_year from "+queryTable+additional+queryparentsId + +" and archive_year is not null group by archive_year order by archive_year asc").getResultList(); + JSONObject object = new JSONObject(); + object.put("list",PageUtil.toPage(returnlist,count)); + object.put("yearGroup",yearGroup); + return object; + } + + @Override + public List archiveDetails(String categoryId, String archivesId) { + List returnVo = new ArrayList<>(); + ArchivesType archivesType = archivesTypeRepository.findById(categoryId).get(); + List queryFields = archivesDictionaryRepository.findDisPlayField(categoryId); + List queryCnFields = archivesDictionaryRepository.findDisPlayCnField(categoryId); + String queryField = queryFields.stream().map(String::valueOf).collect(Collectors.joining(",")); + String queryTable = archivesType.getEnName(); + String appendQuery = ",tid,(select group_concat(case_name) from archives_case t inner join archives_case_cartoning t1 on t.id = t1.case_id where archives_id = z.id)," + + "folder_location,borrow_type,barcode "; + List list = entityManager.createNativeQuery("select "+queryField+appendQuery+" from "+queryTable + " z where z.id = '"+archivesId+"'").getResultList(); + queryFields.add("tid");queryCnFields.add("TID"); + queryFields.add("case_name");queryCnFields.add("盒名称"); + queryFields.add("folder_location");queryCnFields.add("库房位置"); + queryFields.add("borrow_type");queryCnFields.add("借阅状态"); + queryFields.add("barcode");queryCnFields.add("条形码"); + for(int i = 0;i exportArchivesData(String categoryId, String archivesId,Pageable page) { + ArchivesType archivesType = archivesTypeRepository.findById(categoryId).get(); + List queryFields = archivesDictionaryRepository.findDisPlayField(categoryId); + String queryField = queryFields.stream().map(String::valueOf).collect(Collectors.joining(",")); + String queryTable = archivesType.getEnName(); + String quertOrder = ""; + String prependQuery = ""; + if(archivesType.getIsType() == ArchivesTypeEnum.project.getCode() || archivesType.getIsType() == ArchivesTypeEnum.archives.getCode()){ + String childrenTable = archivesTypeRepository.findEnNameByPid(archivesType.getId()); + prependQuery = StringUtils.isEmpty(childrenTable) ? "0," :"(select count(1) from "+childrenTable+" c where c.parent_id = t.id),"; + }else{ + prependQuery = "(select count(1) from file_"+queryTable+" c where c.archive_id = t.id),"; + } + Sort sort = page.getSort(); + Object[] objects = sort.get().toArray(); + for(Object obj:objects){ + String[] splits = obj.toString().split(":"); + quertOrder += splits[0].trim()+" "+splits[1].trim() +","; + } + + String appendQuery = ",if(tid is null||LENGTH(trim(tid))=0,'未绑','已绑')"+ + ",if(case_no is null||LENGTH(trim(case_no))=0,'未装','已装')"+ + ",'未入'"+ + ",'未借'"; + String additional = " t where is_delete_time is null "; + String queryparentsId = StringUtils.isEmpty(archivesId) ? " " : " and parent_id = '"+archivesId+"' "; + + if(objects.length > 0) + quertOrder = " order by " + quertOrder.substring(0,quertOrder.length()-1); + + List list = entityManager.createNativeQuery("select "+prependQuery+queryField+appendQuery+" from "+queryTable+additional+queryparentsId+quertOrder).getResultList(); + return list; } @Override public Object doedit(String categoryId,String archivesId) { JSONObject json = new JSONObject(); List allFiled = archivesDictionaryRepository.findAllByCategoryIdOrderByIsSequenceAsc(categoryId); - List showFiled = archivesDictionaryRepository.findAllByCategoryIdAndIsInputOrderByIsSequenceAsc(categoryId,true); + List showFiled = archivesDictionaryRepository.findAllByCategoryIdAndIsTypeAndIsInputOrderByIsSequenceAsc(categoryId,2,true); ArchivesDictionary showappendFiled = archivesDictionaryRepository.findFirstByCategoryIdAndFieldName(categoryId,"barcode"); showFiled.add(showappendFiled); if(!StringUtils.isEmpty(archivesId)){ @@ -151,7 +228,7 @@ public class ArchivesServiceImpl implements ArchivesService { ArchivesSummary archivesSummary = new ArchivesSummary(); JSONObject json = new JSONObject(dto.getJsonString()); ArchivesType archivesType = archivesTypeRepository.findById(dto.getCategoryId()).get(); - List showFiled = archivesDictionaryRepository.findAllByCategoryIdAndIsInputOrderByIsSequenceAsc(dto.getCategoryId(),true); + List showFiled = archivesDictionaryRepository.findAllByCategoryIdAndIsTypeAndIsInputOrderByIsSequenceAsc(dto.getCategoryId(),2,true); List filedNameList = new ArrayList<>(); String insertFiled = "category_id,category_name,"; String insertValue = "'"+dto.getCategoryId()+"','"+archivesType.getCnName()+"',"; @@ -159,13 +236,13 @@ public class ArchivesServiceImpl implements ArchivesService { for(ArchivesDictionary archivesDictionary:showFiled){ filedNameList.add(archivesDictionary.getFieldName()); //是否必填 - if(archivesDictionary.getIsRequired()){ + if(null != archivesDictionary.getIsRequired() && archivesDictionary.getIsRequired()){ if(null == json.get(archivesDictionary.getFieldName()) || "null".equals(json.get(archivesDictionary.getFieldName())) || "".equals(json.get(archivesDictionary.getFieldName()))){ return ApiResponse.error(50001,archivesDictionary.getFieldName()+"不可为空!"); } } //是否重复 - if(archivesDictionary.getIsRepeat()){ + if(null != archivesDictionary.getIsRepeat() && archivesDictionary.getIsRepeat()){ //判断是否为空 if(null != json.get(archivesDictionary.getFieldName()) && !"".equals(json.get(archivesDictionary.getFieldName())) && !"null".equals(json.get(archivesDictionary.getFieldName()))){ String thissql = "select id,"+archivesDictionary.getFieldName()+" from "+archivesType.getEnName()+" where "+ @@ -198,9 +275,15 @@ public class ArchivesServiceImpl implements ArchivesService { insertFiled = insertFiled.length() != 0 ? insertFiled.substring(0,insertFiled.length()-1) : ""; insertValue = insertValue.length() != 0 ? insertValue.substring(0,insertValue.length()-1) : ""; updateValue = updateValue.length() != 0 ? updateValue.substring(0,updateValue.length()-1) : ""; - insertFiled = "id,"+insertFiled; + insertFiled = "id,create_time,"+insertFiled; + if(!StringUtils.isEmpty(dto.getParentsId())){ + insertFiled = insertFiled + ",parent_id "; + insertValue = insertValue + ",'"+dto.getParentsId()+"' "; + updateValue = updateValue + ",parent_id='"+dto.getParentsId()+"' "; + } String insertId = NanoIdUtils.randomNanoId(); - insertValue = "'"+insertId+"',"+insertValue; + String now = sdf.format(new Date()); + insertValue = "'"+insertId+"','"+now+"',"+insertValue; String sql = StringUtils.isEmpty(dto.getId()) ? "insert into " + archivesType.getEnName() + "(" + insertFiled +") values ("+insertValue+")" : "update "+archivesType.getEnName() +" set "+updateValue+" where id = '"+dto.getId()+"'"; int result = entityManager.createNativeQuery(sql).executeUpdate(); @@ -329,12 +412,23 @@ public class ArchivesServiceImpl implements ArchivesService { @Override @Transactional(rollbackFor = Exception.class) - public Object deleteFile(ArchivesFileDTO dto) { + public Object deleteFile(ArchivesFileDTO dto,String prefixPath) { ArchivesType archivesType = archivesTypeRepository.findById(dto.getCategoryId()).get(); String ids = dto.getIds().stream().map(String::valueOf).collect(Collectors.joining("','")); ids = ids.length() > 0 ? "'"+ids+"'" : ids; - String sql = "delete from "+archivesType.getEnName()+" where id in ("+ids+")"; +// ids.replaceAll("\"",""); + String queryPath = "select file_path from file_" + archivesType.getEnName() + " where id in ("+ids+")"; + List list = entityManager.createNativeQuery(queryPath).getResultList(); + String sql = "delete from file_"+archivesType.getEnName()+" where id in ("+ids+")"; int result = entityManager.createNativeQuery(sql).executeUpdate(); + for(String paths : list){ + if(!StringUtils.isEmpty(paths)){ + File file = new File(prefixPath + paths); + if(file.isFile() && file.exists()){ + file.delete(); + } + } + } return result; } @@ -350,6 +444,34 @@ public class ArchivesServiceImpl implements ArchivesService { return result; } + @Override + @Transactional(rollbackFor = Exception.class) + public Object reduction(ArchivesDTO dto) { + List ids = dto.getIds(); + int success = 0; + ArchivesType archivesType = archivesTypeRepository.findById(dto.getCategoryId()).get(); + List fieldNames = archivesDictionaryRepository.findFieldNameByCategoryIdAndIsTypeAndIsRepeat(dto.getCategoryId(),2,true); + for(String id:ids){ + boolean isRepeat = true; + for(String fieldName:fieldNames){ + String querysql = "select id from "+archivesType.getEnName()+" where is_delete_time is null and "+fieldName+ + "= (select "+fieldName+" from "+archivesType.getEnName()+" where id = '"+id+"')"; + List list = entityManager.createNativeQuery(querysql).getResultList(); + if(list.size()>0){ + isRepeat = false; + } + } + //当没有重复 + if(isRepeat){ + String sql = "update " + archivesType.getEnName() + " set is_delete_time = null,is_delete_man = null " + + "where id = '"+id+"'"; + int result = entityManager.createNativeQuery(sql).executeUpdate(); + success += result; + } + } + return "成功还原"+success+"条数据"; + } + @Override @Transactional(rollbackFor = Exception.class) public Object completelyDelete(ArchivesDTO dto) { @@ -365,4 +487,18 @@ public class ArchivesServiceImpl implements ArchivesService { } return result+","+result1; } + + @Override + public String getcategoryAllParentsId(String categoryId) { + List categoryIds = new ArrayList<>(); + String thisCategoryId = categoryId; + categoryIds.add(thisCategoryId); + do{ + thisCategoryId = archivesTypeRepository.findPidById(thisCategoryId); + if(!StringUtils.isEmpty(thisCategoryId)){ + categoryIds.add(thisCategoryId); + } + }while(thisCategoryId!=null); + return categoryIds.stream().map(String::valueOf).collect(Collectors.joining(",")); + } } diff --git a/archives/src/main/java/com/storeroom/modules/common/ExcelUtil.java b/archives/src/main/java/com/storeroom/modules/common/ExcelUtil.java new file mode 100644 index 0000000..c9515b9 --- /dev/null +++ b/archives/src/main/java/com/storeroom/modules/common/ExcelUtil.java @@ -0,0 +1,80 @@ +package com.storeroom.modules.common; + +import org.apache.poi.hssf.usermodel.*; +import org.apache.poi.ss.usermodel.CellStyle; +import org.apache.poi.ss.usermodel.HorizontalAlignment; +import org.apache.poi.ss.usermodel.VerticalAlignment; + +import javax.servlet.http.HttpServletResponse; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; + +public class ExcelUtil { + + /** + * 导出Excel + * @param sheetName sheet名称 + * @param title 标题 + * @param values 内容 + * @param wb HSSFWorkbook对象 + * @return + */ + public static HSSFWorkbook getHSSFWorkbook(String sheetName,String []title,String [][]values, HSSFWorkbook wb){ + + // 第一步,创建一个HSSFWorkbook,对应一个Excel文件 + if(wb == null){ + wb = new HSSFWorkbook(); + } + + // 第二步,在workbook中添加一个sheet,对应Excel文件中的sheet + HSSFSheet sheet = wb.createSheet(sheetName); + + // 第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制 + HSSFRow row = sheet.createRow(0); + + // 第四步,创建单元格,并设置值表头 设置表头居中 + HSSFCellStyle style = wb.createCellStyle(); + style.setAlignment(HorizontalAlignment.CENTER); // 创建一个居中格式 + style.setVerticalAlignment(VerticalAlignment.CENTER); + + //声明列对象 + HSSFCell cell = null; + + //创建标题 + for(int i=0;i findDisPlayField(String categoryId); + @Query(nativeQuery = true, + value = "select field_cn_name from archives_dictionary where category_id = ?1 and is_display is true order by display_order asc") + List findDisPlayCnField(String categoryId); + List findAllByCategoryIdAndIsTypeOrderByIsSequenceAsc(String categoryId,Integer isType); - List findAllByCategoryIdAndIsInputOrderByIsSequenceAsc(String categoryId, boolean isInput); + List findAllByCategoryIdAndIsTypeAndIsInputOrderByIsSequenceAsc(String categoryId,Integer isType, boolean isInput); + + List findAllByCategoryIdAndIsTypeAndIsRepeat(String categoryId,Integer isType,boolean isRepeat); + + @Query("select fieldName from ArchivesDictionary where categoryId = ?1 and isType = ?2 and isRepeat = ?3") + List findFieldNameByCategoryIdAndIsTypeAndIsRepeat(String categoryId,Integer isType,boolean isRepeat); List findAllByCategoryIdOrderByIsSequenceAsc(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 59a5faf..a168cc4 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 @@ -12,6 +12,9 @@ public interface ArchivesTypeRepository extends JpaRepository findByCnName(String cn); + @Query("select pid from ArchivesType where id = ?1") + String findPidById(String id); + @Query("select enName from ArchivesType where pid = ?1") String findEnNameByPid(String pid); } 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 7259a9f..d1d16a3 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,11 +3,8 @@ 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.service.ArchivesDictionaryService; -import com.storeroom.modules.dictionary.service.ArchivesTypeService; -import com.storeroom.modules.dictionary.service.DynamicTableService; import com.storeroom.modules.dictionary.service.dto.*; import com.storeroom.modules.dictionary.service.mapstruct.ArchivesDictionaryMapper; import com.storeroom.utils.NanoIdUtils;