瀏覽代碼

导入结算表

lamphua 5 月之前
父節點
當前提交
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
 package com.ruoyi.web.controller.oa;
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
 import java.math.BigDecimal;
6
 import java.math.BigDecimal;
4
 import java.text.ParseException;
7
 import java.text.ParseException;
5
 import java.text.SimpleDateFormat;
8
 import java.text.SimpleDateFormat;
9
+import java.util.ArrayList;
6
 import java.util.Calendar;
10
 import java.util.Calendar;
7
 import java.util.List;
11
 import java.util.List;
12
+import java.util.Objects;
8
 import javax.servlet.http.HttpServletResponse;
13
 import javax.servlet.http.HttpServletResponse;
9
 
14
 
10
 import com.alibaba.fastjson2.JSONArray;
15
 import com.alibaba.fastjson2.JSONArray;
11
 import com.alibaba.fastjson2.JSONObject;
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
 import com.ruoyi.oa.domain.CmcSettle;
20
 import com.ruoyi.oa.domain.CmcSettle;
13
 import com.ruoyi.oa.service.ICmcSettleSummaryService;
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
 import org.springframework.beans.factory.annotation.Autowired;
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
 import org.springframework.web.bind.annotation.GetMapping;
31
 import org.springframework.web.bind.annotation.GetMapping;
16
 import org.springframework.web.bind.annotation.PostMapping;
32
 import org.springframework.web.bind.annotation.PostMapping;
17
 import org.springframework.web.bind.annotation.PutMapping;
33
 import org.springframework.web.bind.annotation.PutMapping;
27
 import com.ruoyi.oa.service.ICmcSettleService;
43
 import com.ruoyi.oa.service.ICmcSettleService;
28
 import com.ruoyi.common.utils.poi.ExcelUtil;
44
 import com.ruoyi.common.utils.poi.ExcelUtil;
29
 import com.ruoyi.common.core.page.TableDataInfo;
45
 import com.ruoyi.common.core.page.TableDataInfo;
46
+import org.springframework.web.multipart.MultipartFile;
30
 
47
 
31
 /**
48
 /**
32
  * cmc结算审批Controller
49
  * cmc结算审批Controller
41
     @Autowired
58
     @Autowired
42
     private ICmcSettleService cmcSettleService;
59
     private ICmcSettleService cmcSettleService;
43
 
60
 
44
-    @Autowired
45
-    private ICmcSettleSummaryService cmcSettleSummaryService;
46
-
61
+    @Value("${cmc.profile}")
62
+    private String profile;
47
     /**
63
     /**
48
      * 查询cmc结算审批列表
64
      * 查询cmc结算审批列表
49
      */
65
      */
67
         util.exportExcel(response, list, "cmc结算审批数据");
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
      * 获取cmc结算审批详细信息
124
      * 获取cmc结算审批详细信息
72
      */
125
      */
202
         }
255
         }
203
         typeAmountObject.put("其他结算", oAmount);
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…
取消
儲存