Browse Source

更新档案模块

master
xia 3 years ago
parent
commit
bb39d248cd
  1. 1
      .gitignore
  2. 120
      archives/src/main/java/com/storeroom/modules/archives/controller/ArchivesController.java
  3. 14
      archives/src/main/java/com/storeroom/modules/archives/domain/vo/ArchivesDetailsVO.java
  4. 16
      archives/src/main/java/com/storeroom/modules/archives/service/ArchivesService.java
  5. 4
      archives/src/main/java/com/storeroom/modules/archives/service/dto/ArchivesDTO.java
  6. 8
      archives/src/main/java/com/storeroom/modules/archives/service/impl/ArchivesCaseServiceImpl.java
  7. 158
      archives/src/main/java/com/storeroom/modules/archives/service/impl/ArchivesServiceImpl.java
  8. 80
      archives/src/main/java/com/storeroom/modules/common/ExcelUtil.java
  9. 11
      archives/src/main/java/com/storeroom/modules/dictionary/repository/ArchivesDictionaryRepository.java
  10. 3
      archives/src/main/java/com/storeroom/modules/dictionary/repository/ArchivesTypeRepository.java
  11. 3
      archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesDictionaryImpl.java

1
.gitignore

@ -1,2 +1,3 @@
/.idea
target
archives/src/main/java/com/storeroom/modules/dictionary/repository/ArchivesDictionaryRepository.java.rej

120
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<Object> 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<Object> 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<Object> 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<Object> reduction(
@Validated @RequestBody ArchivesDTO dto
){
return ApiResponse.success(archivesService.reduction(dto));
}
@ApiOperation("档案回收站删除")
@PostMapping("/completelyDelete")
public ApiResponse<Object> 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<ArchivesDictionary> showColumns = (List<ArchivesDictionary>) archivesService.initArchivesViewTable(categoryId);
List<String> 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<Object[]> list = archivesService.exportArchivesData(categoryId,parentsId,page);
String [][] content = new String[list.size()][];
for(int i = 0;i<list.size();i++){
content[i] = new String[title.length];
content[i][0] = (i+1)+"";
Object[] obj = list.get(i);
for(int j=0;j<obj.length;j++){
content[i][j+1] = obj[j]+"";
}
}
HSSFWorkbook wb = ExcelUtil.getHSSFWorkbook("sheet",title,content,null);
try {
ExcelUtil.setResponseHeader(response, fileNames);
OutputStream os = response.getOutputStream();
wb.write(os);
os.flush();
os.close();
} catch (Exception e) {
e.printStackTrace();
}
}
@SneakyThrows
@ApiOperation("上传档案附件")
@PostMapping(value = "/uploadFile", consumes = "multipart/*", headers = "content-type=multipart/form-data")
// @PostMapping("/uploadFile")
public ApiResponse<Object> 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);
}
}

14
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;
}

16
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<ArchivesDetailsVO> archiveDetails(String categoryId,String archivesId);
//导出档案数据
List<Object[]> 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);
}

4
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;

8
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());

158
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<ArchivesType> 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<Object[]> 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<ArchivesDetailsVO> archiveDetails(String categoryId, String archivesId) {
List<ArchivesDetailsVO> returnVo = new ArrayList<>();
ArchivesType archivesType = archivesTypeRepository.findById(categoryId).get();
List<String> queryFields = archivesDictionaryRepository.findDisPlayField(categoryId);
List<String> 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<Object[]> 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<queryFields.size();i++){
Object[] obj = list.get(0);
ArchivesDetailsVO vo = new ArchivesDetailsVO();
vo.setFieldName(queryFields.get(i));
vo.setFieldCnName(queryCnFields.get(i));
vo.setContext(obj[i]);
returnVo.add(vo);
}
return returnVo;
}
@Override
public List<Object[]> exportArchivesData(String categoryId, String archivesId,Pageable page) {
ArchivesType archivesType = archivesTypeRepository.findById(categoryId).get();
List<String> 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<Object[]> 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<ArchivesDictionary> allFiled = archivesDictionaryRepository.findAllByCategoryIdOrderByIsSequenceAsc(categoryId);
List<ArchivesDictionary> showFiled = archivesDictionaryRepository.findAllByCategoryIdAndIsInputOrderByIsSequenceAsc(categoryId,true);
List<ArchivesDictionary> 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<ArchivesDictionary> showFiled = archivesDictionaryRepository.findAllByCategoryIdAndIsInputOrderByIsSequenceAsc(dto.getCategoryId(),true);
List<ArchivesDictionary> showFiled = archivesDictionaryRepository.findAllByCategoryIdAndIsTypeAndIsInputOrderByIsSequenceAsc(dto.getCategoryId(),2,true);
List<String> 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<String> 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<String> ids = dto.getIds();
int success = 0;
ArchivesType archivesType = archivesTypeRepository.findById(dto.getCategoryId()).get();
List<String> 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<Object[]> 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<String> 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(","));
}
}

80
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<title.length;i++){
cell = row.createCell(i);
cell.setCellValue(title[i]);
cell.setCellStyle(style);
}
//创建内容
for(int i=0;i<values.length;i++){
row = sheet.createRow(i + 1);
for(int j=0;j<values[i].length;j++){
HSSFCell newCell = row.createCell(j);
//将内容按顺序赋给对应的列对象
newCell.setCellValue(values[i][j]);
newCell.setCellStyle(style);
}
}
return wb;
}
//发送响应流方法
public static void setResponseHeader(HttpServletResponse response, String fileName) {
try {
try {
fileName = new String(fileName.getBytes(),"UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
response.setContentType("application/octet-stream;charset=UTF-8");
response.setHeader("Content-Disposition", "attachment;filename="+ URLEncoder.encode(fileName,"utf-8")+".xls");
response.addHeader("Pargam", "no-cache");
response.addHeader("Cache-Control", "no-cache");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}

11
archives/src/main/java/com/storeroom/modules/dictionary/repository/ArchivesDictionaryRepository.java

@ -14,9 +14,18 @@ public interface ArchivesDictionaryRepository extends JpaRepository<ArchivesDict
value = "select field_name from archives_dictionary where category_id = ?1 and is_display is true order by display_order asc")
List<String> 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<String> findDisPlayCnField(String categoryId);
List<ArchivesDictionary> findAllByCategoryIdAndIsTypeOrderByIsSequenceAsc(String categoryId,Integer isType);
List<ArchivesDictionary> findAllByCategoryIdAndIsInputOrderByIsSequenceAsc(String categoryId, boolean isInput);
List<ArchivesDictionary> findAllByCategoryIdAndIsTypeAndIsInputOrderByIsSequenceAsc(String categoryId,Integer isType, boolean isInput);
List<ArchivesDictionary> findAllByCategoryIdAndIsTypeAndIsRepeat(String categoryId,Integer isType,boolean isRepeat);
@Query("select fieldName from ArchivesDictionary where categoryId = ?1 and isType = ?2 and isRepeat = ?3")
List<String> findFieldNameByCategoryIdAndIsTypeAndIsRepeat(String categoryId,Integer isType,boolean isRepeat);
List<ArchivesDictionary> findAllByCategoryIdOrderByIsSequenceAsc(String categoryId);

3
archives/src/main/java/com/storeroom/modules/dictionary/repository/ArchivesTypeRepository.java

@ -12,6 +12,9 @@ public interface ArchivesTypeRepository extends JpaRepository<ArchivesType, Stri
List<ArchivesType> 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);
}

3
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;

Loading…
Cancel
Save