Quellcode durchsuchen

1.场站修改页面新增上传测风塔坐标数据

tt vor 1 Jahr
Ursprung
Commit
fd7e99751c

+ 89 - 1
neim-biz/src/main/java/com/jiayue/biz/controller/ElectricStationController.java

@@ -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("文件上传成功");
+    }
 }

+ 1 - 0
neim-biz/src/main/java/com/jiayue/biz/service/StationInfoService.java

@@ -25,4 +25,5 @@ public interface StationInfoService {
     //删除
    void delStationInfo(StationInfoDto stationInfoDto);
 
+    StationInfo getOneStationInfoByCode(String stationCode);
 }

+ 7 - 0
neim-biz/src/main/java/com/jiayue/biz/service/impl/StationInfoServiceImpl.java

@@ -102,6 +102,13 @@ public class StationInfoServiceImpl implements StationInfoService {
         this.del(stationInfoDto.getId());
     }
 
+    @Override
+    public StationInfo getOneStationInfoByCode(String stationCode) {
+
+            return mongoTemplate.findOne(new Query(Criteria.where("stationBasicInfo.stationId").is(stationCode)), StationInfo.class);
+
+    }
+
 
     //保存
     public void saveStationInfo(StationInfoDto stationInfoDto) {

+ 9 - 0
neim-ui/src/api/biz/dataQuery/electricStation.js

@@ -42,3 +42,12 @@ export function delElectricStation(data) {
     data: data
   })
 }
+
+//上传场站风机坐标
+export function uploadStationFanTowerFile(data) {
+  return request({
+    url: '/dataQuery/electricStation/fantowerFile',
+    method: 'post',
+    data: data
+  })
+}

+ 48 - 1
neim-ui/src/views/dataQuery/electrucStation/index.vue

@@ -142,6 +142,22 @@
       <div slot="footer" class="dialog-footer">
         <el-button type="primary" @click="submitForm">确 定</el-button>
         <el-button @click="cancel">取 消</el-button>
+        <el-upload
+          :http-request="dataUpload"
+          :before-upload="beforeUpload"
+          class="el-upload-button"
+          action=""
+          ref="upload"
+        >
+          <el-button
+            @click="row=scope.row"
+            slot="trigger"
+            type="text"
+            size="mini"
+            icon="el-icon-upload2"
+          >上传风机坐标
+          </el-button>
+        </el-upload>
       </div>
     </el-dialog>
   </div>
@@ -153,7 +169,8 @@ import {
   listElectricStation,
   addElectricStation,
   updateElectricStation,
-  delElectricStation
+  delElectricStation,
+  uploadStationFanTowerFile
 } from "@/api/biz/dataQuery/electricStation";
 import {listAllDisabled} from "@/api/biz/dataQuery/windTowerStatusInfo";
 import {infoList} from "@/api/biz/dataQuery/weatherStationInfo";
@@ -250,6 +267,36 @@ export default {
     this.getWeatherStationInfo()
   },
   methods: {
+    beforeUpload(file) {
+      const isLt2M = file.size / 1024 / 1024 < 1024 // 这里做文件大小限制
+      if (!isLt2M) {
+        this.$message({
+          message: '上传文件大小不能超过1020M!',
+          type: 'warning'
+        })
+      }
+
+      return isLt2M
+    },
+    dataUpload(item) {
+      this.fullscreenLoading = true
+      const formData = new FormData()
+      formData.append('file', item.file)
+      formData.append("stationId", this.form.stationId)
+      uploadStationFanTowerFile(formData).then((response) => {
+
+        this.fullscreenLoading = false
+        this.open = false
+        console.log(response)
+        if (response && response.code === 200) {
+          this.getList()
+          this.$message.success(response.msg)
+        } else {
+          this.$message.error(response.msg)
+        }
+        this.$refs.upload.clearFiles()
+      })
+    },
     getWeatherStationInfo() {
       infoList().then(res => {
         this.gEquipment = res.data

+ 9 - 3
neim-ui/src/views/largeScreenPage/Subpage/stationInfo.vue

@@ -223,10 +223,16 @@ export default {
     },
     getInfo() {
       stationInfo({stationId: this.station.id}).then(res => {
-        // console.log(res.data)
+         console.log(res.data)
         let data = res.data
         this.dataInfo = data.modelT
-        this.wdSum = this.dataInfo ? this.dataInfo[0].wdSum : ''
+        if(this.dataInfo){
+          if (this.dataInfo[0] === undefined) {
+            this.wdSum =  ''
+          }else {
+            this.wdSum =  this.dataInfo[0].wdSum
+          }
+        }
         if (data.latitude === undefined) {
           this.coordinates = []
         } else {
@@ -255,7 +261,7 @@ export default {
         if (err.msg === 'Index: 0, Size: 0') {
           console.log('此场站没有风机与测风塔')
         } else {
-          console.log('场站信息获取异常:' + err.msg)
+          console.log('场站信息获取异常:' , err)
         }
 
       })