|
@@ -1,18 +1,32 @@
|
|
|
package com.jiayue.biz.controller;
|
|
|
|
|
|
-import com.jiayue.biz.domain.ElectricStation;
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.jiayue.biz.domain.*;
|
|
|
import com.jiayue.biz.dto.StationInfoDto;
|
|
|
import com.jiayue.biz.service.ElectricStationService;
|
|
|
import com.jiayue.biz.service.StationInfoService;
|
|
|
+import com.jiayue.biz.util.CommonUtil;
|
|
|
import com.jiayue.common.core.controller.BaseController;
|
|
|
import com.jiayue.common.core.domain.AjaxResult;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping("/dataQuery/electricStation")
|
|
|
@AllArgsConstructor
|
|
|
+@Slf4j
|
|
|
public class ElectricStationController extends BaseController {
|
|
|
private final ElectricStationService electricStationService;
|
|
|
|
|
@@ -44,4 +58,78 @@ public class ElectricStationController extends BaseController {
|
|
|
return AjaxResult.success("200") ;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新场站风机坐标数据
|
|
|
+ *
|
|
|
+ * @param file
|
|
|
+ * @param projectNo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @PostMapping("/fantowerFile")
|
|
|
+ public AjaxResult uploadProjectFile(@RequestParam("file") MultipartFile file, @RequestParam("stationId") String stationId) {
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 得到上传文件后缀
|
|
|
+ String originalName = file.getOriginalFilename();
|
|
|
+ String fileUrl = CommonUtil.getRealPath() + File.separator + "fantowerFile" + File.separator;
|
|
|
+
|
|
|
+ // 复制文件
|
|
|
+ File targetFile = new File(fileUrl, originalName);
|
|
|
+ if (targetFile.exists()) {
|
|
|
+ FileUtils.delete(targetFile);
|
|
|
+ }
|
|
|
+ FileUtils.writeByteArrayToFile(targetFile, file.getBytes());
|
|
|
+
|
|
|
+ log.info("坐标文件上传成功:{} ,更新记录信息", fileUrl + originalName);
|
|
|
+
|
|
|
+ //读取上传文件的内容
|
|
|
+
|
|
|
+ List<String> fileStrList = FileUtil.readLines(targetFile, StandardCharsets.UTF_8);
|
|
|
+ if (null == fileStrList || fileStrList.isEmpty()) {
|
|
|
+ return success("读取文件内容为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ String stationCode = fileStrList.get(0).split(" ")[1];
|
|
|
+ if(!stationId.equals(stationCode)){
|
|
|
+ return error("读取文件内容不正确,填写的场站ID:" + stationCode + ",与选择的场站编号不符合");
|
|
|
+ }
|
|
|
+ StationInfo stationInfo = stationInfoService.getOneStationInfoByCode(stationCode);
|
|
|
+ //风机型号
|
|
|
+ String fjTypeStr = fileStrList.get(1);
|
|
|
+ if (fjTypeStr.startsWith("fengji")) {
|
|
|
+ log.info("上传文件风机型号信息:{}", fjTypeStr);
|
|
|
+ String fjType = fjTypeStr.substring(6);
|
|
|
+ log.info("上传文件风机型号:{}", fjType);
|
|
|
+ List<FanTower> fanTowerList = new ArrayList<>();
|
|
|
+ for (int i = 2; i < fileStrList.size(); i++) {
|
|
|
+ String fjStr = fileStrList.get(i);
|
|
|
+ if (StrUtil.isNotBlank(fjStr)) {
|
|
|
+ if(fjStr.startsWith("fengji")){
|
|
|
+ fjType = fjStr.split(" ")[1];
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String[] fjStrArr = fjStr.split("\t");
|
|
|
+ FanTower fanTower = new FanTower();
|
|
|
+ fanTower.setId(fjStrArr[0]);
|
|
|
+ fanTower.setFanModel(fjType);
|
|
|
+ fanTower.setFanName(fjStrArr[1]);
|
|
|
+ fanTower.setLongitudeFan(fjStrArr[2].trim());
|
|
|
+ fanTower.setLatitudeFan(fjStrArr[3].trim());
|
|
|
+ fanTowerList.add(fanTower);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ stationInfo.setFanTowerList(fanTowerList);
|
|
|
+ } else {
|
|
|
+ return success("读取文件内容不正确,未填写风机型号信息");
|
|
|
+ }
|
|
|
+
|
|
|
+ stationInfoService.saveStation(stationInfo);
|
|
|
+ log.info("根据上传文件内容更新项目信息完成");
|
|
|
+ } catch (IOException e) {
|
|
|
+ logger.error("保存文件到服务器(本地)失败", e);
|
|
|
+ }
|
|
|
+
|
|
|
+ return success("文件上传成功");
|
|
|
+ }
|
|
|
}
|