|
@@ -1,17 +1,26 @@
|
|
|
package com.gyee.power.fitting.controller.fj;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.gyee.power.fitting.common.config.GyeeConfig;
|
|
|
+import com.gyee.power.fitting.common.constants.Constants;
|
|
|
import com.gyee.power.fitting.common.result.JsonResult;
|
|
|
import com.gyee.power.fitting.common.result.ResultCode;
|
|
|
+import com.gyee.power.fitting.common.spring.InitialRunner;
|
|
|
+import com.gyee.power.fitting.common.util.DateUtil;
|
|
|
import com.gyee.power.fitting.common.util.FileUtil;
|
|
|
+import com.gyee.power.fitting.common.util.NumberUtil;
|
|
|
import com.gyee.power.fitting.model.Powerfittinganalysis;
|
|
|
import com.gyee.power.fitting.service.PowerfittinganalysisService;
|
|
|
import com.gyee.power.fitting.service.custom.curve.DataPrepareService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
@@ -24,6 +33,8 @@ import java.util.*;
|
|
|
public class DataPrepareController {
|
|
|
|
|
|
@Resource
|
|
|
+ private GyeeConfig config;
|
|
|
+ @Resource
|
|
|
private DataPrepareService prepareService;
|
|
|
@Resource
|
|
|
private PowerfittinganalysisService powerService;
|
|
@@ -82,4 +93,42 @@ public class DataPrepareController {
|
|
|
Powerfittinganalysis obj = powerService.getById(id);
|
|
|
FileUtil.download(obj.getPath(), response);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 文件导入
|
|
|
+ */
|
|
|
+ @PostMapping("upload")
|
|
|
+ public JSONObject dataImport(@RequestParam("file") MultipartFile[] files, HttpServletRequest request,
|
|
|
+ String station, int interval, long st, long et){
|
|
|
+ if (Objects.isNull(files) || files.length < 1){
|
|
|
+ return JsonResult.error(ResultCode.ERROR_FILE_BLANK);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Powerfittinganalysis> list = new ArrayList<>();
|
|
|
+ for (MultipartFile file : files){
|
|
|
+ String[] name = file.getOriginalFilename().split("_");
|
|
|
+ String fileName = config.getFilePathPrepare() + name[0] + "_" + name[1] + "_" + name[2] + "_" + System.currentTimeMillis() / 1000 + ".csv";
|
|
|
+ Powerfittinganalysis obj = new Powerfittinganalysis();
|
|
|
+ obj.setStation(name[0] + "_" + name[1]);
|
|
|
+ obj.setStationcn(station);
|
|
|
+ obj.setWindturbine(name[2]);
|
|
|
+ obj.setCode(name[2]);
|
|
|
+ obj.setTime(DateUtil.format(st, DateUtil.YYYY_MM_DD_CHN) + "-" + DateUtil.format(et, DateUtil.YYYY_MM_DD_CHN));
|
|
|
+ obj.setInterval(NumberUtil.toNum(interval));
|
|
|
+ obj.setPath(fileName);
|
|
|
+ obj.setType(Constants.DATA_PREPARE);
|
|
|
+ obj.setInterp(interval);
|
|
|
+ obj.setCreatetime(DateUtil.parseStrtoDate(DateUtil.format(st, DateUtil.DATE_TIME_PATTERN), DateUtil.DATE_TIME_PATTERN));
|
|
|
+ list.add(obj);
|
|
|
+ try {
|
|
|
+ File dest = new File(fileName);
|
|
|
+ file.transferTo(dest);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return JsonResult.error(ResultCode.ERROR_DATA_TYPE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ powerService.saveBatch(list);
|
|
|
+ return JsonResult.success(ResultCode.SUCCESS);
|
|
|
+ }
|
|
|
}
|