|
@@ -1,11 +1,15 @@
|
|
|
package com.goldenwater.web.controller.yjjt;
|
|
package com.goldenwater.web.controller.yjjt;
|
|
|
|
|
|
|
|
|
|
+import com.goldenwater.common.config.RuoYiConfig;
|
|
|
import com.goldenwater.common.core.controller.BaseController;
|
|
import com.goldenwater.common.core.controller.BaseController;
|
|
|
import com.goldenwater.common.core.domain.AjaxResult;
|
|
import com.goldenwater.common.core.domain.AjaxResult;
|
|
|
import com.goldenwater.common.core.page.TableDataInfo;
|
|
import com.goldenwater.common.core.page.TableDataInfo;
|
|
|
|
|
+import com.goldenwater.common.utils.file.FileUploadUtils;
|
|
|
import com.goldenwater.common.utils.poi.ExcelImportHelper;
|
|
import com.goldenwater.common.utils.poi.ExcelImportHelper;
|
|
|
import com.goldenwater.common.utils.poi.ExcelUtil;
|
|
import com.goldenwater.common.utils.poi.ExcelUtil;
|
|
|
|
|
+import com.goldenwater.yjjt.domain.YjjtFile;
|
|
|
import com.goldenwater.yjjt.domain.YjjtSlData;
|
|
import com.goldenwater.yjjt.domain.YjjtSlData;
|
|
|
|
|
+import com.goldenwater.yjjt.service.IYjjtFileService;
|
|
|
import com.goldenwater.yjjt.service.IYjjtSlDataService;
|
|
import com.goldenwater.yjjt.service.IYjjtSlDataService;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
@@ -16,7 +20,9 @@ import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
import jakarta.annotation.Resource;
|
|
import jakarta.annotation.Resource;
|
|
|
|
|
+
|
|
|
import java.io.InputStream;
|
|
import java.io.InputStream;
|
|
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
|
@RestController
|
|
@RestController
|
|
@@ -27,6 +33,9 @@ public class YjjtSlDataController extends BaseController {
|
|
|
@Resource
|
|
@Resource
|
|
|
private IYjjtSlDataService yjjtSlDataService;
|
|
private IYjjtSlDataService yjjtSlDataService;
|
|
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private IYjjtFileService yjjtFileService;
|
|
|
|
|
+
|
|
|
@GetMapping("/list")
|
|
@GetMapping("/list")
|
|
|
@Operation(summary = "查询水量数据列表", description = "查询水量数据列表")
|
|
@Operation(summary = "查询水量数据列表", description = "查询水量数据列表")
|
|
|
@PreAuthorize("@ss.hasPermi('yjjtgl:sl:list')")
|
|
@PreAuthorize("@ss.hasPermi('yjjtgl:sl:list')")
|
|
@@ -53,20 +62,38 @@ public class YjjtSlDataController extends BaseController {
|
|
|
@PostMapping("/upload")
|
|
@PostMapping("/upload")
|
|
|
@Operation(summary = "上传水量数据", description = "上传水量数据Excel文件,使用第三行作为列名")
|
|
@Operation(summary = "上传水量数据", description = "上传水量数据Excel文件,使用第三行作为列名")
|
|
|
@PreAuthorize("@ss.hasPermi('yjjtgl:sl:upload')")
|
|
@PreAuthorize("@ss.hasPermi('yjjtgl:sl:upload')")
|
|
|
- public AjaxResult upload(@Parameter(description = "Excel文件") @RequestParam("file") MultipartFile file,
|
|
|
|
|
- @Parameter(description = "业务类型(JS/SH/ZJ)") @RequestParam("bizType") String bizType) {
|
|
|
|
|
|
|
+ public AjaxResult upload(@Parameter(description = "Excel文件") @RequestParam("file") MultipartFile file) {
|
|
|
try {
|
|
try {
|
|
|
|
|
+ // 上传文件到服务器
|
|
|
|
|
+ String filePath = RuoYiConfig.getUploadPath();
|
|
|
|
|
+ String fileName = FileUploadUtils.upload(filePath, file);
|
|
|
|
|
+ // 获取文件的后缀名
|
|
|
|
|
+ String suffixName = fileName.substring(fileName.lastIndexOf(".") + 1);
|
|
|
InputStream inputStream = file.getInputStream();
|
|
InputStream inputStream = file.getInputStream();
|
|
|
// 使用ExcelImportHelper解析,第三行(索引2)作为列名
|
|
// 使用ExcelImportHelper解析,第三行(索引2)作为列名
|
|
|
List<YjjtSlData> dataList = ExcelImportHelper.importExcel(inputStream, YjjtSlData.class, 2);
|
|
List<YjjtSlData> dataList = ExcelImportHelper.importExcel(inputStream, YjjtSlData.class, 2);
|
|
|
-
|
|
|
|
|
- String addvcd = bizType.toUpperCase();
|
|
|
|
|
for (YjjtSlData data : dataList) {
|
|
for (YjjtSlData data : dataList) {
|
|
|
- data.setAddvcd(addvcd);
|
|
|
|
|
|
|
+ data.setId(new Date().getTime());
|
|
|
data.setCreateBy(getUsername());
|
|
data.setCreateBy(getUsername());
|
|
|
|
|
+ data.setUpdateBy(getUsername());
|
|
|
}
|
|
}
|
|
|
|
|
+ yjjtSlDataService.importSlData(dataList);
|
|
|
|
|
+
|
|
|
|
|
+ // 保存文件信息到 yjjt_file 表
|
|
|
|
|
+ YjjtFile yjjtFile = new YjjtFile();
|
|
|
|
|
+ yjjtFile.setId(new Date().getTime());
|
|
|
|
|
+ yjjtFile.setFileViewname(file.getOriginalFilename());
|
|
|
|
|
+ yjjtFile.setFileSavename(fileName);
|
|
|
|
|
+ yjjtFile.setFilePath(filePath);
|
|
|
|
|
+ yjjtFile.setFileSize(file.getSize());
|
|
|
|
|
+ yjjtFile.setFileType(suffixName);
|
|
|
|
|
+ yjjtFile.setBizType("SL");
|
|
|
|
|
+ yjjtFile.setUploadBy(getUsername());
|
|
|
|
|
+ yjjtFile.setUploadTime(new Date());
|
|
|
|
|
+ yjjtFile.setStatus("0");
|
|
|
|
|
+ yjjtFile.setCreateBy(getUsername());
|
|
|
|
|
+ yjjtFileService.insertYjjtFile(yjjtFile);
|
|
|
|
|
|
|
|
- yjjtSlDataService.importSlData(dataList, bizType);
|
|
|
|
|
return AjaxResult.success("上传成功,共导入" + dataList.size() + "条数据");
|
|
return AjaxResult.success("上传成功,共导入" + dataList.size() + "条数据");
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
logger.error("上传水量数据失败", e);
|
|
logger.error("上传水量数据失败", e);
|