浏览代码

add cache layer

Xiaopeng Zhang 6 月之前
父节点
当前提交
7b81c68d72
共有 3 个文件被更改,包括 128 次插入104 次删除
  1. 122 103
      front/src/Service.js
  2. 2 1
      front/src/editor.js
  3. 4 0
      front/src/utils.js

+ 122 - 103
front/src/Service.js

@@ -1,7 +1,39 @@
+import {copy} from './utils';
 class Service{
+    
+    constructor() {
+        this.cache = [];
+    }
+    
     ip() {
         return "http://127.0.0.1"
     }
+
+    processQingdanmingxi(mingxi) {
+        this.cache = copy(mingxi);
+        for(let i = 0; i < this.cache.length; i++) {
+            let zimu = this.cache[i];
+            if (!zimu.hasOwnProperty("__children")) {
+                zimu["__children"] = [];
+            }
+            if (!zimu.hasOwnProperty("rcj")) {
+                zimu["rcj"] = [["ID", "人材机编码", "名称", "规格型号", "单位", "单价", "产地", 
+                "供应厂商", "人材机类别", "甲供标志", "含量", "合价", "暂估价标志", "主要材料标志", "主材标志", "设备标志" ]];
+            }
+
+        }
+        for(let i = 0; i < this.cache.length; i++) {
+            let zimu = this.cache[i];
+            for(let j = 0; j < zimu["__children"].length; j++) {
+                let de = zimu["__children"][j];
+                if (!de.hasOwnProperty("dercj")) {
+                    de["dercj"] = [["ID", "人材机编码", "名称", "规格型号", "单位", "单价", "产地", 
+                    "供应厂商", "人材机类别", "甲供标志", "含量", "合价", "暂估价标志", "主要材料标志", "主材标志", "设备标志" ]];
+                }
+            }
+        }
+
+    }
     async generateOutline(name) {
         const response = await fetch(this.ip().concat( ":8000/outline"), {
             method : "POST",
@@ -426,7 +458,12 @@ class Service{
         }
     }
 
+
+    /////////////////////////////////////qingdan//////////////////////////////////////
+
     async generateQingdanmingxi(name, bh, bt) {
+        if (this.cache.length == 0 || this.cache[0]["biao_id"] != name || this.cache[0]["Dwgcbh"] != bh ||
+        this.cache[0]["bt"] != bt) {
         const response = await fetch(this.ip().concat(":8000/qingdanmingxi/"), {
             method : "POST",
             headers: {
@@ -445,122 +482,104 @@ class Service{
             console.error('error');
         } else {
             const data = await response.json();
+            this.processQingdanmingxi(data);
             return data;
         }
-    }
-
-    async generateQingdanTuijian(name, bh, bt, bm) {
-        const response = await fetch(this.ip().concat( ":8000/qingdantuijian/"), {
-            method : "POST",
-            headers: {
-                "Content-type": "application/json"
-            },
-            body: JSON.stringify(
-                {
-                    "bh": bh,
-                    "bt": bt,
-                    "bm": bm,
-                    "name": name
-                }
-            )
-        });
-        if (!response.ok) {
-            //const error = await response.json();
-            console.error('error');
         } else {
-            const data = await response.json();
-            return data;
+            return copy(this.cache);
         }
     }
+
+
     async generateQingdanrcj(name, bh, bt, bm) {
-        const response = await fetch(this.ip().concat( ":8000/qingdanrcj/"), {
-            method : "POST",
-            headers: {
-                "Content-type": "application/json"
-            },
-            body: JSON.stringify(
-                {
-                    "bh": bh,
-                    "bt": bt,
-                    "bm": bm,
-                    "name": name
-                }
-            )
-        });
-        if (!response.ok) {
-            //const error = await response.json();
-            console.error('error');
-        } else {
-            const data = await response.json();
-            return data;
+        if (bt == "Djcs") {
+            const response = await fetch(this.ip().concat( ":8000/qingdanrcj/"), {
+                method : "POST",
+                headers: {
+                    "Content-type": "application/json"
+                },
+                body: JSON.stringify(
+                    {
+                        "bh": bh,
+                        "bt": bt,
+                        "bm": bm,
+                        "name": name
+                    }
+                )
+            });
+            if (!response.ok) {
+                //const error = await response.json();
+                console.error('error');
+            } else {
+                const data = await response.json();
+                return data;
+            }
         }
+        let qd = this.cache.filter(x=>x["清单编码"] == bm)[0];
+        return qd["rcj"];
+        
     }
     async generateDingercj(name, bh, bt, qdbm, debm, danwei) {
-        const response = await fetch(this.ip().concat( ":8000/dingercj/"), {
-            method : "POST",
-            headers: {
-                "Content-type": "application/json"
-            },
-            body: JSON.stringify(
-                {
-                    "bh": bh,
-                    "bt": bt,
-                    "qdbm": qdbm,
-                    "debm" : debm,
-                    "name": name
-                }
-            )
-        });
-        if (!response.ok) {
-            //const error = await response.json();
-            console.error('error');
-        } else {
-            const data = await response.json();
-            if (data.length == 0) {
-                return  [
-                    [
-                        "ID",
-                        "人材机编码",
-                        "名称",
-                        "规格型号",
-                        "单位",
-                        "单价",
-                        "产地",
-                        "供应厂商",
-                        "人材机类别",
-                        "甲供标志",
-                        "含量",
-                        "合价",
-                        "暂估价标志",
-                        "主要材料标志",
-                        "主材标志",
-                        "设备标志"
-                    ],
-                    [
-                        "",
-                        debm,
-                        "",
-                        "",
-                        danwei,
-                        "",//danjia
-                        "",//chandi
-                        "",//gongyingchangshang
-                        "2",//rencaijileibie
-                        "false",//jiagong
-                        "1",//hanliang
-                        "=F2*K2",//hejia
-                        "",
-                        "",
-                        "",
-                        ""
-                    ]
-                ];
-            }
-            else {
+        if (bt == 'Djcs') {
+            const response = await fetch(this.ip().concat( ":8000/dingercj/"), {
+                method : "POST",
+                headers: {
+                    "Content-type": "application/json"
+                },
+                body: JSON.stringify(
+                    {
+                        "bh": bh,
+                        "bt": bt,
+                        "qdbm": qdbm,
+                        "debm" : debm,
+                        "name": name
+                    }
+                )
+            });
+            if (!response.ok) {
+                //const error = await response.json();
+                console.error('error');
+            } else {
+                const data = await response.json();
                 return data;
             }
         }
+        let qd = this.cache.filter(x=>x["清单编码"] == qdbm)[0];
+        let de = qd["__children"].filter(x=>x["清单编码"]==debm)[0];
+        return de["dercj"];
+        
+        
+          
+          
+        
     }
+
+
+/////////////////////////////end of qingdan////////////////////////////////////
+
+async generateQingdanTuijian(name, bh, bt, bm) {
+    const response = await fetch(this.ip().concat( ":8000/qingdantuijian/"), {
+        method : "POST",
+        headers: {
+            "Content-type": "application/json"
+        },
+        body: JSON.stringify(
+            {
+                "bh": bh,
+                "bt": bt,
+                "bm": bm,
+                "name": name
+            }
+        )
+    });
+    if (!response.ok) {
+        //const error = await response.json();
+        console.error('error');
+    } else {
+        const data = await response.json();
+        return data;
+    }
+}
     async generateZjcs(name, bh) {
         const response = await fetch(this.ip().concat( ":8000/zjcs/"), {
             method : "POST",

+ 2 - 1
front/src/editor.js

@@ -1,6 +1,6 @@
 
 import {danxiangdinge_index} from './utils';
-
+import Service from './Service';
 
 function copy(input) {
     return JSON.parse(JSON.stringify(input));
@@ -139,6 +139,7 @@ export const danxiangdinge = (hotRef, selectedRow, detailRef) => {
             }
        );
        detailRef.current = newData;
+       //Service.updateCache(newData);
        return [true, newData];
 
     } else {

+ 4 - 0
front/src/utils.js

@@ -21,4 +21,8 @@ export const danxiangdinge_index = (data) => {
 
     
   };
+export const copy = (input) => {
+    return JSON.parse(JSON.stringify(input));
+};
+