Explorar el Código

`传感器台账`

wenhongquan hace 2 años
padre
commit
66a088c1e7

+ 9 - 0
ruoyi-system/src/main/java/com/ruoyi/data/service/impl/TblSensorServiceImpl.java

@@ -76,6 +76,15 @@ public class TblSensorServiceImpl implements ITblSensorService {
         if(bo.getParams()!=null && bo.getParams().get("notypes")!=null){
         if(bo.getParams()!=null && bo.getParams().get("notypes")!=null){
             lqw.notIn(TblSensor::getProtocalType, Arrays.stream(bo.getParams().get("notypes").toString().split(",")).map(i->Long.parseLong(i)).collect(Collectors.toList()));
             lqw.notIn(TblSensor::getProtocalType, Arrays.stream(bo.getParams().get("notypes").toString().split(",")).map(i->Long.parseLong(i)).collect(Collectors.toList()));
         }
         }
+        if(bo.getParams()!=null && bo.getParams().get("deviceids")!=null){
+            lqw.in(TblSensor::getDeviceId, Arrays.stream(bo.getParams().get("deviceids").toString().split(",")).map(i->Long.parseLong(i)).collect(Collectors.toList()));
+        }
+        if(bo.getParams()!=null && bo.getParams().get("sn")!=null){
+            lqw.like(TblSensor::getSn, "%"+bo.getParams().get("sn")+"%");
+        }
+        if(bo.getParams()!=null && bo.getParams().get("desc")!=null){
+            lqw.like(TblSensor::getSensorDesc, "%"+bo.getParams().get("desc")+"%");
+        }
         return lqw;
         return lqw;
     }
     }
 
 

+ 2 - 0
ruoyi-ui-vue3/src/utils/ruoyi.js

@@ -174,6 +174,7 @@ export function handleTree(data, id, parentId, children) {
       childrenListMap[parentId] = [];
       childrenListMap[parentId] = [];
     }
     }
     nodeIds[d[config.id]] = d;
     nodeIds[d[config.id]] = d;
+    d["spread"]= true;
     childrenListMap[parentId].push(d);
     childrenListMap[parentId].push(d);
   }
   }
 
 
@@ -194,6 +195,7 @@ export function handleTree(data, id, parentId, children) {
     }
     }
     if (o[config.childrenList]) {
     if (o[config.childrenList]) {
       for (let c of o[config.childrenList]) {
       for (let c of o[config.childrenList]) {
+        c["spread"]= true;
         adaptToChildrenList(c);
         adaptToChildrenList(c);
       }
       }
     }
     }

+ 180 - 58
ruoyi-ui-vue3/src/views/device/sensordash/index.vue

@@ -6,7 +6,7 @@
           <template #header>
           <template #header>
             <div class="card-header">
             <div class="card-header">
               <span>设备区域</span>
               <span>设备区域</span>
-              <div>
+              <div style="display: none">
                 <el-button type="primary" >
                 <el-button type="primary" >
                   添加
                   添加
                 </el-button>
                 </el-button>
@@ -21,7 +21,11 @@
               v-model:selectedKey="selectedKey"
               v-model:selectedKey="selectedKey"
               @node-click="handleClick"
               @node-click="handleClick"
             >
             >
+              <template #title="{ data }">
+                {{ data.name }}
+              </template>
             </LayTree>
             </LayTree>
+
           </div>
           </div>
         </el-card>
         </el-card>
       </el-col>
       </el-col>
@@ -38,9 +42,9 @@
                   align-items: center;
                   align-items: center;
                 "
                 "
               >
               >
-                <div style="font-size: 12px; width: 100px;">监测点编号:</div>
+                <div style="font-size: 12px; width: 100px;">传感器编号:</div>
                 <el-input
                 <el-input
-                  v-model="searchform.devicename"
+                  v-model="searchform.sn"
                   placeholder="请输入"
                   placeholder="请输入"
                 ></el-input>
                 ></el-input>
               </div>
               </div>
@@ -54,14 +58,14 @@
               >
               >
                 <div style="font-size: 12px; width: 80px;margin-right: 10px;text-align: right;">描述:</div>
                 <div style="font-size: 12px; width: 80px;margin-right: 10px;text-align: right;">描述:</div>
                 <el-input
                 <el-input
-                  v-model="searchform.devicename"
+                  v-model="searchform.desc"
                   placeholder="请输入"
                   placeholder="请输入"
                 ></el-input>
                 ></el-input>
               </div>
               </div>
             </div>
             </div>
             <div>
             <div>
-              <el-button type="primary" plain>重置</el-button>
-              <el-button type="primary">搜索</el-button>
+              <el-button type="primary" plain @click="initdata">重置</el-button>
+              <el-button type="primary" @click="getalldata">搜索</el-button>
             </div>
             </div>
           </div>
           </div>
         </el-card>
         </el-card>
@@ -72,19 +76,16 @@
               <span>传感器台账</span>
               <span>传感器台账</span>
               <div>
               <div>
                 <el-button type="primary" @click="goadd">添加</el-button>
                 <el-button type="primary" @click="goadd">添加</el-button>
-                <el-button type="danger">批量删除</el-button>
-                <el-button type="primary" plain>显示字段</el-button>
+                <el-button type="danger" @click="deleteall">批量删除</el-button>
+                <el-button type="primary" plain  @click="ziduanshow=true">显示字段</el-button>
               </div>
               </div>
             </div></template>
             </div></template>
 
 
           <el-row>
           <el-row>
             <el-col :span="24" style="padding-left: 10px">
             <el-col :span="24" style="padding-left: 10px">
-              <el-table :data="devicetabledata" :border="true">
-                <el-table-column label="传感器编号"></el-table-column>
-                <el-table-column label="传感器名称"></el-table-column>
-                <el-table-column label="描述"></el-table-column>
-                <el-table-column label="状态"></el-table-column>
-                <el-table-column label="类型"></el-table-column>
+              <el-table :data="devicetabledata" ref="tableref" :border="true">
+                <el-table-column type="selection" width="55" />
+                <el-table-column v-for="item in cloumdata.filter(i=>i.visible)" :prop="item.prop" :label="item.label" ></el-table-column>
 
 
                 <el-table-column label="操作">
                 <el-table-column label="操作">
                   <template #default="scope">
                   <template #default="scope">
@@ -108,7 +109,7 @@
                           <el-icon><VideoPlay /></el-icon>
                           <el-icon><VideoPlay /></el-icon>
                         </el-tooltip>
                         </el-tooltip>
                       </el-button>
                       </el-button>
-                      <el-popconfirm title="确定删除该标签?">
+                      <el-popconfirm title="确定删除该传感器?" @confirm="deleterow(scope.row)">
                         <template #reference>
                         <template #reference>
                           <el-button link
                           <el-button link
                           ><el-tooltip effect="dark" content="删除"
                           ><el-tooltip effect="dark" content="删除"
@@ -128,7 +129,10 @@
                              small
                              small
                              background
                              background
                              layout="prev, pager, next"
                              layout="prev, pager, next"
-                             :total="50"
+                             :total="pagedata.total"
+                             :page-size="pagedata.size"
+                             :current-page="pagedata.current"
+                             @current-change="onchangepage"
                              class="mt-4"
                              class="mt-4"
               />
               />
             </el-col>
             </el-col>
@@ -197,80 +201,197 @@
       </template>
       </template>
     </el-dialog>
     </el-dialog>
 
 
+    <el-dialog
+      title="字段显示"
+      v-model="ziduanshow"
+      width="50%"
+      @close="ziduanshow = false"
+    >
+      <div style="display: flex;flex-wrap: wrap;align-content: center;justify-content: center;align-items: center;">
+        <el-checkbox v-for="item in cloumdata" v-model="item.visible" :label="item.label" size="large" />
+      </div>
 
 
+    </el-dialog>
   </div>
   </div>
 </template>
 </template>
 
 
-<script setup lang="ts" name="Units">
+<script setup>
 import {ref} from "vue";
 import {ref} from "vue";
-import { LayTree } from "@layui/layui-vue";
+import {LayTree} from "@layui/layui-vue";
 import "@layui/layui-vue/lib/index.css";
 import "@layui/layui-vue/lib/index.css";
 import {useRoute, useRouter} from "vue-router";
 import {useRoute, useRouter} from "vue-router";
+import {listEquipmentOrganizational} from "@/api/data/equipmentOrganizational"
+import {listEquipmentSbook} from "@/api/data/equipmentSbook"
+import {listSensor,delSensor,addSensor,updateSensor} from "@/api/data/sensor"
+import {delGateway} from "@/api/data/gateway";
+import {ElMessage, ElMessageBox} from "element-plus";
+
+const {proxy} = getCurrentInstance();
+const {protocal_type, sensor_type, sensor_status} = proxy.useDict("protocal_type", "sensor_type", "sensor_status");
 
 
 
 
 const route = useRoute();
 const route = useRoute();
 const router = useRouter();
 const router = useRouter();
+const ziduanshow = ref(false);
+
+const tableref  = ref(null);
+
+const cloumdata = ref([
+  {label: '传感器编号', prop: 'sn', visible: true},
+  {label: '传感器名称', prop: 'name', visible: true},
+  {label: '描述', prop: 'sensorDesc', visible: true},
+  {label: '状态', prop: 'statusname', visible: true},
+  {label: '类型', prop: 'sensorType', visible: true},
+])
 
 
 
 
-const goadd = ()=>{
+const onchangepage = (page) => {
+  pagedata.value.current = page;
+  getalldata();
+}
+const pagedata = ref({
+  total:0,
+  size:10,
+  current:1
+});
+
+
+const deleterow =(item)=>{
+  delSensor(item.id).then((res)=>{
+    ElMessage.success("删除成功");
+    getalldata();
+  })
+}
+
+const deleteall = ()=>{
+  let selected =  tableref.value.getSelectionRows();
+  if(selected.length==0) {
+    ElMessage.warning("请选择要删除的行");
+    return;
+  }
+
+  if (selected.length > 0) {
+    ElMessageBox.confirm(
+      `是否删除${selected.length}条数据`,
+      "警告",
+      {
+        confirmButtonText: "确认",
+        cancelButtonText: "取消",
+        type: 'warning',
+      }
+    ).then(() => {
+
+      delSensor(selected.map(i => i.id).join(",")).then((res) => {
+        ElMessage.success("删除成功");
+        getalldata();
+      })
+
+    });
+  }
+
+}
+
+
+const initdata = ()=>{
+  searchform.value.sn = '';
+  searchform.value.desc = '';
+  pagedata.value = {
+    total:0,
+    size:10,
+    current:1
+  }
+}
+
+const goadd = () => {
   router.push("/device/sensordash/add")
   router.push("/device/sensordash/add")
 }
 }
 
 
+
+
+const currentnode = ref(null);
+const getalldata = () => {
+  const getdeviceid = (node) => {
+    if (node.children) {
+      return node.children.map(item => {
+        return getdeviceid(item);
+      }).join(",")
+    } else {
+      if ((node.id + "").indexOf("device") > -1) {
+        return node.id;
+      } else {
+        return "";
+      }
+    }
+  }
+  let deviceids = getdeviceid(currentnode.value).split(",").filter(i => i != "").join(",");
+  if (deviceids != "") {
+    deviceids = deviceids.replaceAll("device_", "")
+    listSensor({...pagedata, params: {deviceids: deviceids,...searchform.value}}).then(res => {
+      const {rows,total,page,size} = res;
+      pagedata.value = {total:total,current:page, size:10};
+      devicetabledata.value = rows.map(item => {
+        try{
+          var statusname = sensor_status.value.find(i => i.value == item.status).label;
+          item["statusname"] = statusname;
+        }catch (e) {
+
+        }
+        return item;
+      });
+    })
+  }else{
+    pagedata.value = {total:0,current:1, size:10};
+    devicetabledata.value=[];
+  }
+}
+
 const handleClick = (node) => {
 const handleClick = (node) => {
-  console.log("Click Node:" + JSON.stringify(node));
+  //循环获取子的id
+  currentnode.value = node;
+  getalldata();
 };
 };
 const selectedKey = ref(4);
 const selectedKey = ref(4);
-const data = ref([
-  {
-    title: "集团公司",
-    id: 1,
-    checked: true,
-    spread: true,
-    children: [
-      {
-        title: "示范项目",
-        id: 2,
-        spread: true,
-        children: [
-          {
-            title: "监测站",
-            id: 4,
-            href: "https://www.layui.com/",
-          },
-          {
-            title: "用能区域",
-            id: 5,
-            href: "https://www.layui.com/",
-          },
-
-        ],
-      },
-      {
-        title: "虚拟项目",
-        id: 3,
-        href: "https://www.layui.com/",
-      },
+const data = ref([]);
+
+
+const getTreedata = () => {
+  listEquipmentOrganizational({pageSize: 10000}).then(res => {
+    const {rows, total, page, size} = res;
+    //获取设备数据
+    listEquipmentSbook({page: 1, pageSize: 100000}).then(res1 => {
+      res1.rows.forEach(item => {
+        item["parentId"] = item.equipmentTreeId;
+        item["id"] = "device_" + item.id;
+        rows.push(item);
+        data.value = proxy.handleTree(rows, "id", "parentId");
+      })
+    })
+  })
+}
+getTreedata();
 
 
-    ],
-  },
-]);
 
 
-const devicetabledata = ref([1]);
+const devicetabledata = ref([]);
 const searchform = ref({
 const searchform = ref({
-  devicename: "",
-  devicesn:""
+  sn: "",
+  desc: ""
 });
 });
 
 
 
 
 const cdbdshow = ref(false);
 const cdbdshow = ref(false);
-const cdbd = ()=>{
+const cdbd = () => {
   cdbdshow.value = true;
   cdbdshow.value = true;
 }
 }
 
 
 
 
-
 </script>
 </script>
 
 
+<style lang="scss">
+.layui-tree .layui-this .layui-tree-txt {
+  color: #038de0 !important;
+}
+</style>
+
 <style lang="scss" scoped>
 <style lang="scss" scoped>
 .card-header {
 .card-header {
   display: flex;
   display: flex;
@@ -278,6 +399,7 @@ const cdbd = ()=>{
   justify-content: space-between;
   justify-content: space-between;
 }
 }
 
 
+
 .tree {
 .tree {
   *,
   *,
   *:before,
   *:before,