From 93a16e3707b870856594e89b950174b64bb7d6cd Mon Sep 17 00:00:00 2001
From: whycxzp <perryhsu@163.com>
Date: 星期三, 01 三月 2023 10:55:34 +0800
Subject: [PATCH] ecr提交前一步执行原文件存储

---
 src/main/java/com/whyc/service/SoftwareService.java |   48 ++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 44 insertions(+), 4 deletions(-)

diff --git a/src/main/java/com/whyc/service/SoftwareService.java b/src/main/java/com/whyc/service/SoftwareService.java
index 0fd23d9..ea3cae5 100644
--- a/src/main/java/com/whyc/service/SoftwareService.java
+++ b/src/main/java/com/whyc/service/SoftwareService.java
@@ -9,7 +9,6 @@
 import com.whyc.dto.FileDirPath;
 import com.whyc.dto.Response;
 import com.whyc.mapper.SoftwareMapper;
-import com.whyc.pojo.AttachLock;
 import com.whyc.pojo.DocUser;
 import com.whyc.pojo.Software;
 import com.whyc.util.ActionUtil;
@@ -53,6 +52,13 @@
         //鍙栫涓�涓猻heet琛�
         Sheet sheet = workbook.getSheetAt(0);
         int lastRowNum = sheet.getLastRowNum();
+        //鏍″噯lastRowNum
+        for (int i = 8; i <= lastRowNum; i++) {
+            if(sheet.getRow(i).getCell(1).getStringCellValue().equals("鍙戝竷璇存槑")){
+                lastRowNum = i;
+                break;
+            }
+        }
         //鍥哄畾5鍒�
         short cellNum = 5;
         //鍙栧浐瀹氶儴鍒嗗��
@@ -101,7 +107,23 @@
             //鍙栫3鍒�,绗�5鍒�
             Cell cell = sheet.getRow(8 + i).getCell(2);
             cell.setCellType(Cell.CELL_TYPE_STRING);
-            software.setApplyMaterialCode(cell.getStringCellValue());
+            String stringCellValue = cell.getStringCellValue();
+            if(!stringCellValue.equals("")) {
+                int length = stringCellValue.length();
+                if (length == 9) {
+                    stringCellValue = "0" + stringCellValue;
+                } else if (length < 9) {
+                    int centerZeroNum = 10 - length - 1;
+                    StringBuilder centerZeroStr = new StringBuilder();
+                    for (int j = 0; j < centerZeroNum; j++) {
+                        centerZeroStr.append("0");
+                    }
+                    String strFront = stringCellValue.substring(0, 3);
+                    String strBehind = stringCellValue.substring(3);
+                    stringCellValue = "0" + strFront + centerZeroStr + strBehind;
+                }
+            }
+            software.setApplyMaterialCode(stringCellValue);
             software.setApplyModel(sheet.getRow(8+i).getCell(4).getStringCellValue());
 
             softwareList.add(software);
@@ -136,10 +158,12 @@
         wrapper.eq("id",id);
         wrapper.last("limit 1");
         Software software=mapper.selectOne(wrapper);
+
+        String filename=software.getFileUrl().substring(software.getFileUrl().lastIndexOf("\\")+1);
         try {
             // 杞爜闃叉涔辩爜
             //resp.addHeader("Content-Disposition", "attachment;filename=" + new String(softwareName.getBytes("UTF-8"), "ISO8859-1"));
-            resp.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode ( software.getFileName()+".zip", "utf-8"));
+            resp.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode (filename, "utf-8"));
             OutputStream out = resp.getOutputStream();
             FileInputStream in = new FileInputStream(fileDirName+File.separator+software.getFileUrl());
             int len=0;
@@ -163,7 +187,8 @@
         logService.recordOperationLog(docUser.getId(),docUser.getName(), UserOperation.TYPE_DOWNLOAD.getType(),new Date(),terminalIp,opreationMsg,operationDetail);
     }
 
-    public Response upload(MultipartFile file1, MultipartFile file2, List<Software> softwareList) throws IOException {
+    @Transactional
+    public Response upload(MultipartFile file1, MultipartFile file2, String fontUpdateTime, List<Software> softwareList) throws IOException {
         String file1Name = file1.getOriginalFilename();
         String file2Name = file2.getOriginalFilename();
         Software software = softwareList.get(0);
@@ -191,13 +216,27 @@
         file2.transferTo(new File(softwareDir+File.separator+file2Name));
         //璁剧疆璺緞
         for (Software software1:softwareList){
+            software1.setFontUpdateTime(fontUpdateTime);
             software1.setFileUrl(softwareHttpUrl+File.separator+file1Name);
             software1.setExcelUrl(softwareHttpUrl+File.separator+file2Name);
             software1.setCreateTime(date);
         }
+        //閿佸畾鍘熸潵鐨勬墍鏈夌増鏈�:鏍规嵁鐗堝彿鍜岃蒋浠剁被鍨�
+        List<String> materialCodeList = softwareList.stream().map(Software::getApplyMaterialCode).collect(Collectors.toList());
+        lockByBoardNumberAndTypeAndMaterialCode(software.getBoardNumber(),software.getType(),materialCodeList);
         //鍐欏叆鏁版嵁搴�
         insertBatch(softwareList);
         return new Response().set(1,true,"涓婁紶瀹屾垚");
+    }
+
+    private void lockByBoardNumberAndTypeAndMaterialCode(String boardNumber, String type, List<String> materialCodeList) {
+        UpdateWrapper<Software> update = Wrappers.update();
+        update.set("lock_flag",1)
+                .set("local_reason","杞欢鐗堟湰鍗囩骇")
+                .eq("board_number",boardNumber)
+                .eq("type",type)
+                .in("apply_material_code",materialCodeList);
+        mapper.update(null,update);
     }
 
     private Software getByFilename(String fileName) {
@@ -248,4 +287,5 @@
         int flag=mapper.update(null,uwrapper);
         return new Response().set(1,flag>0,"閿佸畾/瑙i攣鎴愬姛");
     }
+
 }

--
Gitblit v1.9.1