From a4248be7b973ebb927409630faf9c0a6cb6e5ce2 Mon Sep 17 00:00:00 2001 From: xia Date: Thu, 28 Jul 2022 16:24:14 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=96=B0=E5=A2=9E=E5=80=9F=E9=98=85=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E5=AF=BC=E5=87=BA=202.=E6=96=B0=E5=A2=9E=E6=A1=A3?= =?UTF-8?q?=E6=A1=88=E5=9C=A8=E5=BA=93=E3=80=81=E5=80=9F=E9=98=85=E7=8A=B6?= =?UTF-8?q?=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../archives/controller/BorrowController.java | 27 ++++- .../repository/BorrowArchivesRepository.java | 24 ++-- .../service/impl/ArchivesServiceImpl.java | 18 ++- .../service/impl/BorrowServiceImpl.java | 13 ++- .../storeroom/modules/common/ExcelUtil.java | 103 +++++++++++++++++- 5 files changed, 167 insertions(+), 18 deletions(-) diff --git a/archives/src/main/java/com/storeroom/modules/archives/controller/BorrowController.java b/archives/src/main/java/com/storeroom/modules/archives/controller/BorrowController.java index 0ef8af7..ab3039a 100644 --- a/archives/src/main/java/com/storeroom/modules/archives/controller/BorrowController.java +++ b/archives/src/main/java/com/storeroom/modules/archives/controller/BorrowController.java @@ -12,14 +12,19 @@ import com.storeroom.utils.ApiResponse; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.springframework.data.domain.Pageable; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; +import java.io.OutputStream; import java.sql.Time; import java.sql.Timestamp; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; import java.util.List; @RestController @@ -28,6 +33,8 @@ import java.util.List; @RequestMapping("/api/borrow") public class BorrowController { + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); + private final BorrowService borrowService; @ApiOperation("判断借阅流程管理在线离线") @@ -222,12 +229,26 @@ public class BorrowController { HttpServletResponse response, @RequestParam("orderNos") List orderNos ){ + response.setContentType("text/html;charset=UTF-8"); + response.setCharacterEncoding("UTF-8"); List bills = new ArrayList<>(); for(String orderNo:orderNos){ - bills.add(borrowService.initBillDetailsByOrderNo(orderNo)); + BorrowBillDetailsVO vo = borrowService.initBillDetailsByOrderNo(orderNo); + if(null!=vo){ + bills.add(vo); + } + } + bills.removeAll(Collections.singleton(null)); + XSSFWorkbook wb = ExcelUtil.createBorrowerExcel("借还记录",bills); + try { + ExcelUtil.setResponseHeader(response, "借还记录"+format.format(new Date())+".xls"); + OutputStream os = response.getOutputStream(); + wb.write(os); + os.flush(); + os.close(); + } catch (Exception e) { + e.printStackTrace(); } - ExcelUtil.createBorrowerExcel("测试",bills); - } 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 cbc8d09..4fe5379 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 @@ -47,6 +47,16 @@ public interface BorrowArchivesRepository extends JpaRepository rbIds,Integer borrowType); + @Modifying + @Query(nativeQuery = true, + value = "update borrow_archives set borrow_type = ?2,start_time = now() where id in (select ba_id from borrow_bill_archives where bill_id in ?1)") + void billBorrowConfirm(List rbIds,Integer borrowType); + + @Modifying + @Query(nativeQuery = true, + value = "update borrow_archives set borrow_type = ?2,end_time = now() where id in ?1 ") + void archivesReturnConfirm(List rbIds,Integer borrowType); + @Modifying @Query(nativeQuery = true, value = "delete from borrow_archives where id in (select ba_id from borrow_bill_archives where bill_id in ?1)") @@ -97,8 +107,8 @@ public interface BorrowArchivesRepository extends JpaRepository> initBorrowLog(String orderNo, String borrowerName, String phone, String archiveNo,String folderLocationDetails, String caseName, String barcode, String tid,Integer borrowType,String maintitle, Pageable page); 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 92afbf9..e6710bb 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 @@ -85,6 +85,22 @@ public class ArchivesServiceImpl implements ArchivesService { appendQuery = ",(select count(1) from file_"+queryTable+" c where c.archive_id = t.id) "; } + String isStorageQuery = " "; + String isBorrowQuery = " "; + //是否入库 + if(archivesType.getIsType()!=ArchivesTypeEnum.project.getCode()){ + queryFields.add("is_storage"); + //文件级/案卷级 + if(archivesType.getIsType() == ArchivesTypeEnum.archives.getCode() || archivesType.getIsType() == ArchivesTypeEnum.files.getCode()){ + queryFields.add("is_borrow"); + isStorageQuery = ",(select ace.storage_type from archives_case_cartoning acc inner join archives_case ace on acc.case_id = ace.id where acc.parent_id = t.id limit 0,1) as is_storage "; + isBorrowQuery = ",(select ba.borrow_type from borrow_archives ba where ba.borrow_type != 4 and ba.archives_id = t.id) as is_borrow "; + } + if(archivesType.getIsType() == ArchivesTypeEnum.inChive.getCode()){ + isStorageQuery = ",(select ace.storage_type from archives_case_cartoning acc inner join archives_case ace on acc.case_id = ace.id where acc.archives_id = t.id) as is_storage "; + } + } + Sort sort = page.getSort(); Object[] objects = sort.get().toArray(); for(Object obj:objects){ @@ -111,7 +127,7 @@ public class ArchivesServiceImpl implements ArchivesService { List countList = entityManager.createNativeQuery("select count(1) from "+queryTable+additional+queryparentsId).getResultList(); Object count = countList.get(0); - List list = entityManager.createNativeQuery("select "+queryField+appendQuery+" from "+queryTable+additional+queryparentsId+quertOrder + List list = entityManager.createNativeQuery("select "+queryField+appendQuery+isStorageQuery+isBorrowQuery+" from "+queryTable+additional+queryparentsId+quertOrder +" limit "+page.getPageNumber()*page.getPageSize()+","+page.getPageSize()).getResultList(); List returnlist = new ArrayList<>(); for(Object[] objs:list){ diff --git a/archives/src/main/java/com/storeroom/modules/archives/service/impl/BorrowServiceImpl.java b/archives/src/main/java/com/storeroom/modules/archives/service/impl/BorrowServiceImpl.java index 572fbd9..0bcb1b5 100644 --- a/archives/src/main/java/com/storeroom/modules/archives/service/impl/BorrowServiceImpl.java +++ b/archives/src/main/java/com/storeroom/modules/archives/service/impl/BorrowServiceImpl.java @@ -117,6 +117,9 @@ public class BorrowServiceImpl implements BorrowService { public BorrowBillDetailsVO initBillDetailsByOrderNo(String orderNo) { BorrowBillDetailsVO vo = new BorrowBillDetailsVO(); BorrowBill bill = borrowBillRepository.findBillById(orderNo); + if(null == bill){ + return null; + } BeanUtils.copyProperties(bill,vo); vo.setBorrower(borrowerRepository.findByBorrowerId(bill.getBorrowerId())); vo.setBorrowArchives(borrowArchivesRepository.initArchivesByOrderNo(orderNo)); @@ -163,14 +166,14 @@ public class BorrowServiceImpl implements BorrowService { @Override public Object readyBorrowShowTid(List orderNos) { - Map map = new HashMap<>(); +// Map map = new HashMap<>(); //根据单据号获取有标签的档案基本信息 List> archives = borrowBillRepository.findArchivesTidByOrderNos(orderNos); //根据单据号获取所有有标签的盒信息 // List> cases = borrowBillRepository.findCaseidByOrderNos(orderNos); - map.put("archives",archives); +// map.put("archives",archives); // map.put("cases",cases); - return map; + return archives; } @Override @@ -183,7 +186,7 @@ public class BorrowServiceImpl implements BorrowService { @Transactional public Object billBorrowConfirm(List orderNos) { //更改清单内档案状态 - borrowArchivesRepository.updateAllTypeByOrderNos(orderNos,3); + borrowArchivesRepository.billBorrowConfirm(orderNos,3); //更改清单状态 borrowBillRepository.updateBorrowTypeByOrderNos(orderNos,3); return orderNos.size(); @@ -209,7 +212,7 @@ public class BorrowServiceImpl implements BorrowService { public Object archivesReturnConfirm(List rbIds) { try { //更新关联档案状态 - borrowArchivesRepository.updateAllTypeByRbIds(rbIds,4); + borrowArchivesRepository.archivesReturnConfirm(rbIds,4); //根据关联档案id获取相关所有单据 List orderNos = borrowBillRepository.findOrderIdsByRbId(rbIds); //更新相关单据状态 diff --git a/archives/src/main/java/com/storeroom/modules/common/ExcelUtil.java b/archives/src/main/java/com/storeroom/modules/common/ExcelUtil.java index b42f366..27e042a 100644 --- a/archives/src/main/java/com/storeroom/modules/common/ExcelUtil.java +++ b/archives/src/main/java/com/storeroom/modules/common/ExcelUtil.java @@ -1,20 +1,28 @@ package com.storeroom.modules.common; +import com.storeroom.modules.archives.domain.BorrowArchives; import com.storeroom.modules.archives.domain.vo.BorrowBillDetailsVO; import org.apache.poi.hssf.usermodel.*; import org.apache.poi.ss.usermodel.BorderStyle; import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.HorizontalAlignment; import org.apache.poi.ss.usermodel.VerticalAlignment; +import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.xssf.usermodel.*; import javax.servlet.http.HttpServletResponse; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; +import java.sql.Timestamp; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.List; public class ExcelUtil { + private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + private static SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); + /** * 导出Excel * @param sheetName sheet名称 @@ -97,15 +105,106 @@ public class ExcelUtil { textStyle.setBorderBottom(BorderStyle.THIN); textStyle.setBorderRight(BorderStyle.THIN); textStyle.setBorderLeft(BorderStyle.THIN); + textStyle.setBorderTop(BorderStyle.THIN); textStyle.setFont(dataSetFont); // 数据内容对齐方式:居中 textStyle.setAlignment(HorizontalAlignment.CENTER); + textStyle.setVerticalAlignment(VerticalAlignment.CENTER); //行 int index = 0; + String[] billTitle = {"单据号","借阅人","所属部门","证件类型","证件号码","电话号码","借阅目的","借阅日期","操作时间","借阅状态"}; + String[] archivesTitle = {"序号","门类名称","题名","档号","盒名称","","存放位置","","借阅状态"}; + for(BorrowBillDetailsVO vo:bills){ + //清单title + XSSFRow billTitleRow = sheet.createRow(index); + List borrowArchives = vo.getBorrowArchives(); + for(int i = 0;i= new Timestamp(System.currentTimeMillis()).getTime()){ + showBorrowType = "待归还"; + }else if(borrowType==3 && vo.getBorrowEnd().getTime() < new Timestamp(System.currentTimeMillis()).getTime()){ + showBorrowType = "逾期"; + }else if(borrowType == 4){ + showBorrowType = "已归还"; + } + XSSFCell billValueCell9 = billValueRow.createCell(9);billValueCell9.setCellValue(showBorrowType);billValueCell9.setCellStyle(textStyle); + + + Integer billRowStart = index; + if(null!=borrowArchives && borrowArchives.size()!=0){ + index++; + XSSFRow archivesTitleRow = sheet.createRow(index); + XSSFCell cell0 = archivesTitleRow.createCell(0);cell0.setCellStyle(textStyle); + for(int i = 0;i= new Timestamp(System.currentTimeMillis()).getTime()){ + showBorrowArchiType = "待归还"; + }else if(borrowArchiType==3 && borrowArchive.getEndTime().getTime() < new Timestamp(System.currentTimeMillis()).getTime()){ + showBorrowArchiType = "逾期"; + }else if(borrowArchiType == 4){ + showBorrowArchiType = "已归还"; + } + XSSFCell baValueCell9 = archivesValueRow.createCell(9);baValueCell9.setCellValue(showBorrowArchiType);baValueCell9.setCellStyle(textStyle); + sheet.addMergedRegion(new CellRangeAddress(index, index, 5, 6)); + sheet.addMergedRegion(new CellRangeAddress(index, index, 7, 8)); + } + + Integer billRowEnd = index; + sheet.addMergedRegion(new CellRangeAddress(billRowStart, billRowEnd, 0, 0)); - - + } + index++; + XSSFRow nullRow = sheet.createRow(index); + index++; + } + //自适应单元格 + for (int i = 0; i < sheet.getLastRowNum(); i++) { + sheet.autoSizeColumn(i); + sheet.setColumnWidth(i, sheet.getColumnWidth(i) * 17 / 10); + } return workbook; }