浏览代码

修改风机添加编号判断重复的BUG问题

xusl 8 月之前
父节点
当前提交
3d9fd2da00

+ 54 - 23
ipp-ap/src/views/idp/control/windturbineinfo/index.vue

@@ -104,15 +104,6 @@ export default {
     checkequipmentNo(rule, value, callback) {
       if (value == '') {
         callback(new Error('请输入设备编号'))
-      } else {
-        var s6 = this.tableData
-        for (let i = 0; i < s6.length; i++) {
-          if (this.modId != s6[i].id) {
-            if ((value == s6[i].equipmentNo)) {
-              callback(new Error('设备编号不能重复'))
-            }
-          }
-        }
       }
       callback()
     },
@@ -134,6 +125,9 @@ export default {
       this.tableLoading = true
       getStation().then(response => {
         this.stationList = response.data.data
+        if (this.stationList.length>0){
+          this.stationCode = this.stationList[0].value
+        }
         this.tableLoading = false
       })
       this.dataQuery()
@@ -165,22 +159,59 @@ export default {
       })
     },
     handleUpdate: function (row, index, done, loading) {
-      putObj(row).then(data => {
-        this.$message.success('修改成功')
-        done()
-        this.dataQuery()
-      }).catch(() => {
-        loading();
-      });
+      var queryParams = {
+        stationCode:row.stationCode,
+        equipmentNo:row.equipmentNo
+      }
+      this.$axios.get('/windturbineinfo/findExistEquipmentNo',{params: queryParams}).then((res) => {
+        let resData = res.data.data;
+        if (resData.length>0){
+          if (resData[0].id !=row.id){
+            this.$message.warning('设备编号已存在')
+            loading();
+          }
+          else{
+            putObj(row).then(data => {
+              this.$message.success('修改成功')
+              done()
+              this.dataQuery()
+            }).catch(() => {
+              loading();
+            });
+          }
+        }
+        else{
+          putObj(row).then(data => {
+            this.$message.success('修改成功')
+            done()
+            this.dataQuery()
+          }).catch(() => {
+            loading();
+          });
+        }
+      })
     },
     handleSave: function (row, done, loading) {
-      addObj(row).then(data => {
-        this.$message.success('添加成功')
-        done()
-        this.dataQuery()
-      }).catch(() => {
-        loading();
-      });
+      var queryParams = {
+        stationCode:row.stationCode,
+        equipmentNo:row.equipmentNo
+      }
+      this.$axios.get('/windturbineinfo/findExistEquipmentNo',{params: queryParams}).then((res) => {
+        let resData = res.data.data;
+        if (resData.length>0){
+          this.$message.warning('设备编号已存在')
+          loading();
+        }
+        else{
+          addObj(row).then(data => {
+            this.$message.success('添加成功')
+            done()
+            this.dataQuery()
+          }).catch(() => {
+            loading();
+          });
+        }
+      })
     },
     sizeChange(pageSize) {
       this.page.pageSize = pageSize

+ 16 - 0
ipp-idp/src/main/java/com/jiayue/ipp/idp/controller/WindTurbineInfoController.java

@@ -1,5 +1,6 @@
 package com.jiayue.ipp.idp.controller;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.jiayue.ipp.common.data.entity.ElectricField;
@@ -190,4 +191,19 @@ public class WindTurbineInfoController {
             return R.failed(e.toString());
         }
     }
+
+    /**
+     * 查找设备编号是否存在
+     *
+     * @param stationCode
+     * @return
+     */
+    @GetMapping("/findExistEquipmentNo")
+    public R findExistEquipmentNo(String stationCode,String equipmentNo) {
+        QueryWrapper<WindTurbineInfo> wrapper = new QueryWrapper<>();
+        wrapper.eq("station_code", stationCode);
+        wrapper.eq("equipment_no", equipmentNo);
+        List<WindTurbineInfo> windTurbineInfoList = windTurbineInfoService.list(wrapper);
+        return R.ok(windTurbineInfoList);
+    }
 }