소스 검색

导入结算表

lamphua 3 달 전
부모
커밋
b896b57124
1개의 변경된 파일69개의 추가작업 그리고 3개의 파일을 삭제
  1. 69
    3
      oa-back/ruoyi-admin/src/main/java/com/ruoyi/web/controller/oa/CmcSettleController.java

+ 69
- 3
oa-back/ruoyi-admin/src/main/java/com/ruoyi/web/controller/oa/CmcSettleController.java 파일 보기

@@ -1,17 +1,33 @@
1 1
 package com.ruoyi.web.controller.oa;
2 2
 
3
+import java.io.File;
4
+import java.io.FileInputStream;
5
+import java.io.InputStream;
3 6
 import java.math.BigDecimal;
4 7
 import java.text.ParseException;
5 8
 import java.text.SimpleDateFormat;
9
+import java.util.ArrayList;
6 10
 import java.util.Calendar;
7 11
 import java.util.List;
12
+import java.util.Objects;
8 13
 import javax.servlet.http.HttpServletResponse;
9 14
 
10 15
 import com.alibaba.fastjson2.JSONArray;
11 16
 import com.alibaba.fastjson2.JSONObject;
17
+import com.ruoyi.common.utils.SnowFlake;
18
+import com.ruoyi.file.domain.FilesAchievement;
19
+import com.ruoyi.file.domain.FilesStorage;
12 20
 import com.ruoyi.oa.domain.CmcSettle;
13 21
 import com.ruoyi.oa.service.ICmcSettleSummaryService;
22
+import org.apache.poi.hssf.usermodel.HSSFSheet;
23
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
24
+import org.apache.poi.ss.usermodel.CellType;
25
+import org.apache.poi.xssf.usermodel.XSSFCell;
26
+import org.apache.poi.xssf.usermodel.XSSFSheet;
27
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
14 28
 import org.springframework.beans.factory.annotation.Autowired;
29
+import org.springframework.beans.factory.annotation.Value;
30
+import org.springframework.security.access.prepost.PreAuthorize;
15 31
 import org.springframework.web.bind.annotation.GetMapping;
16 32
 import org.springframework.web.bind.annotation.PostMapping;
17 33
 import org.springframework.web.bind.annotation.PutMapping;
@@ -27,6 +43,7 @@ import com.ruoyi.common.enums.BusinessType;
27 43
 import com.ruoyi.oa.service.ICmcSettleService;
28 44
 import com.ruoyi.common.utils.poi.ExcelUtil;
29 45
 import com.ruoyi.common.core.page.TableDataInfo;
46
+import org.springframework.web.multipart.MultipartFile;
30 47
 
31 48
 /**
32 49
  * cmc结算审批Controller
@@ -41,9 +58,8 @@ public class CmcSettleController extends BaseController
41 58
     @Autowired
42 59
     private ICmcSettleService cmcSettleService;
43 60
 
44
-    @Autowired
45
-    private ICmcSettleSummaryService cmcSettleSummaryService;
46
-
61
+    @Value("${cmc.profile}")
62
+    private String profile;
47 63
     /**
48 64
      * 查询cmc结算审批列表
49 65
      */
@@ -67,6 +83,43 @@ public class CmcSettleController extends BaseController
67 83
         util.exportExcel(response, list, "cmc结算审批数据");
68 84
     }
69 85
 
86
+    /**
87
+     * 上传结算excel文件
88
+     */
89
+    @PostMapping("/uploadSheet")
90
+    public AjaxResult uploadSettleSheet(MultipartFile file) throws Exception {
91
+        if (file.isEmpty()) {
92
+            return AjaxResult.error("文件内容为空!");
93
+        }
94
+        else {
95
+            File profilePath = new File(profile + "/upload/导入数据");
96
+            if (!profilePath.exists())
97
+                profilePath.mkdirs();
98
+            File transferFile = new File( profilePath + "/" + file.getOriginalFilename());
99
+            file.transferTo(transferFile);
100
+            InputStream in = new FileInputStream(transferFile);
101
+            XSSFSheet sheetAt = null;
102
+            int rowNumber = 0;
103
+            if (file.getOriginalFilename() != null) {
104
+                sheetAt = new XSSFWorkbook(in).getSheetAt(0);
105
+                rowNumber = sheetAt.getPhysicalNumberOfRows();
106
+            }
107
+            JSONArray jsonArray = new JSONArray();
108
+            JSONObject jsonObject = new JSONObject();
109
+            for (int i = 1; i < rowNumber - 1;) {
110
+                i++;
111
+                jsonObject.put("priceId", getStringCellValue(sheetAt.getRow(i).getCell(0)));
112
+                jsonObject.put("content", getStringCellValue(sheetAt.getRow(i).getCell(1)));
113
+                jsonObject.put("workload", getStringCellValue(sheetAt.getRow(i).getCell(4)));
114
+                jsonObject.put("groundType", getStringCellValue(sheetAt.getRow(i).getCell(5)));
115
+                jsonObject.put("coefficient", getStringCellValue(sheetAt.getRow(i).getCell(6)));
116
+                jsonObject.put("remark", getStringCellValue(sheetAt.getRow(i).getCell(7)));
117
+                jsonArray.add(jsonObject);
118
+            }
119
+            return AjaxResult.success(jsonArray);
120
+        }
121
+    }
122
+
70 123
     /**
71 124
      * 获取cmc结算审批详细信息
72 125
      */
@@ -202,4 +255,17 @@ public class CmcSettleController extends BaseController
202 255
         }
203 256
         typeAmountObject.put("其他结算", oAmount);
204 257
     }
258
+
259
+    public String getStringCellValue(XSSFCell xssfCell) {
260
+        if (xssfCell == null) {
261
+            return "";
262
+        }
263
+        if (xssfCell.getCellType() == CellType.NUMERIC) {
264
+            return String.valueOf(xssfCell.getNumericCellValue());
265
+        } else if (xssfCell.getCellType() == CellType.BOOLEAN) {
266
+            return String.valueOf(xssfCell.getBooleanCellValue());
267
+        } else {
268
+            return xssfCell.getStringCellValue();
269
+        }
270
+    }
205 271
 }

Loading…
취소
저장