| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411 |
- import xml.etree.ElementTree as ET
- from subdir import service
- from bson.objectid import ObjectId
- from pymongo import AsyncMongoClient
- import asyncio
- def getDingercj_(root, bh, bt, qdbm, debm):
- result = [["ID", "人材机编码", "名称", "规格型号", "单位", "单价", "产地",
- "供应厂商", "人材机类别", "甲供标志", "含量", "合价", "暂估价标志", "主要材料标志", "主材标志", "设备标志" ]]
- #result.append(["ming cheng", "jin e", "zan gu jia", "anquan wenming fei", "guifei"])
- item = None
- for child in root:
-
- if child.tag == "Dxgcxx":
- for child1 in child:
- Dwgcbh = child1.attrib["Dwgcbh"]
- if Dwgcbh == bh:
- item = child1
- break
- ##result.append([child.attrib["Dxgcmc"], child.attrib["Je"], child.attrib["Zgj"], child.attrib["Aqwmf"], child.attrib["Gf"]])
- Fywj = None
- for child in item:
- if child.tag == 'Qdxm':
- Fywj= child
- break
- Rcjhz = None
- for child in item:
- if child.tag == 'Rcjhz':
- Rcjhz = child
- break
- kv = {}
- for entry in Rcjhz:
- kv[entry.attrib["RcjId"]]=entry
- container = None
- for child in Fywj:
- ##child is mx
- if child.tag == "QdBt":
- if child.attrib["Mc"] == bt:
- container = child
- break
- if not container:
- container = Fywj
- zimu = None
- for child in container:
- if child.attrib["Qdbm"] == qdbm:
- zimu = child
- break
- box = None
- if not zimu:
- return result
- for child in zimu:
- if child.tag == "Qdxdezj":
- box = child
- break
- hlmx_parent = None
- for child in box:
- if child.attrib["Debm"] == debm:
- for grandchild in child:
- if grandchild.tag == "Qdxdercjhl":
- hlmx_parent = grandchild
- for child in hlmx_parent:
- result.append([child.attrib["RcjId"],
- kv[child.attrib["RcjId"]].attrib["RcjBm"],
- kv[child.attrib["RcjId"]].attrib["Mc"],
- kv[child.attrib["RcjId"]].attrib["Ggxh"],
- kv[child.attrib["RcjId"]].attrib["Dw"],
- kv[child.attrib["RcjId"]].attrib["Dj"],
- kv[child.attrib["RcjId"]].attrib["Cd"],
- kv[child.attrib["RcjId"]].attrib["Gycs"],
- kv[child.attrib["RcjId"]].attrib["Rcjlb"],
- kv[child.attrib["RcjId"]].attrib["Jgbz"],
- child.attrib["Rcjhl"], child.attrib["Rcjhj"], "",
- "", "", ""
- ])
- return result
- def getQingdanrcj_(root, bh, bt, bm):
- result = [["ID", "人材机编码", "名称", "规格型号", "单位", "单价", "产地",
- "供应厂商", "人材机类别", "甲供标志", "含量", "合价", "暂估价标志", "主要材料标志", "主材标志", "设备标志" ]]
- #result.append(["ming cheng", "jin e", "zan gu jia", "anquan wenming fei", "guifei"])
- item = None
- for child in root:
-
- if child.tag == "Dxgcxx":
- for child1 in child:
- Dwgcbh = child1.attrib["Dwgcbh"]
- if Dwgcbh == bh:
- item = child1
- break
- ##result.append([child.attrib["Dxgcmc"], child.attrib["Je"], child.attrib["Zgj"], child.attrib["Aqwmf"], child.attrib["Gf"]])
- Fywj = None
- for child in item:
- if child.tag == 'Qdxm':
- Fywj= child
- break
- Rcjhz = None
- for child in item:
- if child.tag == 'Rcjhz':
- Rcjhz = child
- break
- kv = {}
- for entry in Rcjhz:
- kv[entry.attrib["RcjId"]]=entry
- container = None
- for child in Fywj:
- ##child is mx
- if child.tag == "QdBt":
- if child.attrib["Mc"] == bt:
- container = child
- break
- if not container:
- container = Fywj
- zimu = None
- for child in container:
- if child.attrib["Qdbm"] == bm:
- zimu = child
- break
- box = None
- if not zimu:
- return result
- for child in zimu:
- if child.tag == "Qdxrcjhl":
- box = child
- break
- for child in box:
- result.append([child.attrib["RcjId"],
- kv[child.attrib["RcjId"]].attrib["RcjBm"],
- kv[child.attrib["RcjId"]].attrib["Mc"],
- kv[child.attrib["RcjId"]].attrib["Ggxh"],
- kv[child.attrib["RcjId"]].attrib["Dw"],
- kv[child.attrib["RcjId"]].attrib["Dj"],
- kv[child.attrib["RcjId"]].attrib["Cd"],
- kv[child.attrib["RcjId"]].attrib["Gycs"],
- kv[child.attrib["RcjId"]].attrib["Rcjlb"],
- kv[child.attrib["RcjId"]].attrib["Jgbz"],
- child.attrib["Rcjhl"], child.attrib["Rcjhj"], child.attrib["Zgjbz"],
- child.attrib["Zyclbz"], child.attrib["Zcbz"], child.attrib["Sbbz"]
- ])
- return result
- def getDjcsDingercj_(root, bh, bt, qdbm, debm):
- result = [["ID", "人材机编码", "名称", "规格型号", "单位", "单价", "产地",
- "供应厂商", "人材机类别", "甲供标志", "含量", "合价", "暂估价标志", "主要材料标志", "主材标志", "设备标志" ]]
- #result.append(["ming cheng", "jin e", "zan gu jia", "anquan wenming fei", "guifei"])
- item = None
- for child in root:
-
- if child.tag == "Dxgcxx":
- for child1 in child:
- Dwgcbh = child1.attrib["Dwgcbh"]
- if Dwgcbh == bh:
- item = child1
- break
- ##result.append([child.attrib["Dxgcmc"], child.attrib["Je"], child.attrib["Zgj"], child.attrib["Aqwmf"], child.attrib["Gf"]])
- Fywj = None
- for child in item:
- if child.tag == 'Csxm':
- Fywj= child
- break
- Rcjhz = None
- for child in item:
- if child.tag == 'Rcjhz':
- Rcjhz = child
- break
- kv = {}
- for entry in Rcjhz:
- kv[entry.attrib["RcjId"]]=entry
- container = None
- for child in Fywj:
- if child.tag == "DjCs":
- container = child
- break
- zimu = None
- for child in container:
- if child.attrib["Bm"] == qdbm:
- zimu = child
- break
- box = None
- if not zimu:
- return result
- for child in zimu:
- if child.tag == "Csxdezj":
- box = child
- break
- hlmx_parent = None
- for child in box:
- if child.attrib["Debm"] == debm:
- for grandchild in child:
- if grandchild.tag == "Csxdercjhl":
- hlmx_parent = grandchild
- for child in hlmx_parent:
- result.append([child.attrib["RcjId"],
- kv[child.attrib["RcjId"]].attrib["RcjBm"],
- kv[child.attrib["RcjId"]].attrib["Mc"],
- kv[child.attrib["RcjId"]].attrib["Ggxh"],
- kv[child.attrib["RcjId"]].attrib["Dw"],
- kv[child.attrib["RcjId"]].attrib["Dj"],
- kv[child.attrib["RcjId"]].attrib["Cd"],
- kv[child.attrib["RcjId"]].attrib["Gycs"],
- kv[child.attrib["RcjId"]].attrib["Rcjlb"],
- kv[child.attrib["RcjId"]].attrib["Jgbz"],
- child.attrib["Rcjhl"], child.attrib["Rcjhj"], "",
- "", "", ""
- ])
- return result
- def getDjcsQingdanrcj_(root, bh, bt, bm):
- result = [["ID", "人材机编码", "名称", "规格型号", "单位", "单价", "产地",
- "供应厂商", "人材机类别", "甲供标志", "含量", "合价", "暂估价标志", "主要材料标志", "主材标志", "设备标志" ]]
- #result.append(["ming cheng", "jin e", "zan gu jia", "anquan wenming fei", "guifei"])
- item = None
- for child in root:
-
- if child.tag == "Dxgcxx":
- for child1 in child:
- Dwgcbh = child1.attrib["Dwgcbh"]
- if Dwgcbh == bh:
- item = child1
- break
- ##result.append([child.attrib["Dxgcmc"], child.attrib["Je"], child.attrib["Zgj"], child.attrib["Aqwmf"], child.attrib["Gf"]])
- Fywj = None
- for child in item:
- if child.tag == 'Csxm':
- Fywj= child
- break
- hl_parent = None
- for child in Fywj:
- if child.tag == "DjCs":
- hl_parent = child
- Rcjhz = None
- for child in item:
- if child.tag == 'Rcjhz':
- Rcjhz = child
- break
- kv = {}
- for entry in Rcjhz:
- kv[entry.attrib["RcjId"]]=entry
- zimu = None
- for child in hl_parent:
- if child.attrib["Bm"] == bm:
- zimu = child
- break
- box = None
- if not zimu:
- return result
- for child in zimu:
- if child.tag == "Csxrcjhl":
- box = child
- break
- for child in box:
- result.append([child.attrib["RcjId"],
- kv[child.attrib["RcjId"]].attrib["RcjBm"],
- kv[child.attrib["RcjId"]].attrib["Mc"],
- kv[child.attrib["RcjId"]].attrib["Ggxh"],
- kv[child.attrib["RcjId"]].attrib["Dw"],
- kv[child.attrib["RcjId"]].attrib["Dj"],
- kv[child.attrib["RcjId"]].attrib["Cd"],
- kv[child.attrib["RcjId"]].attrib["Gycs"],
- kv[child.attrib["RcjId"]].attrib["Rcjlb"],
- kv[child.attrib["RcjId"]].attrib["Jgbz"],
- child.attrib["Rcjhl"], child.attrib["Rcjhj"], child.attrib["Zgjbz"],
- child.attrib["Zyclbz"], child.attrib["Zcbz"], child.attrib["Sbbz"]
- ])
- return result
- client = AsyncMongoClient()
- async def resolve(data):
- tree = ET.parse( data)
- root = tree.getroot()
- print(root)
- Dwgcbh = []
- jingjibiao = {}
- jingjibiao["BiaoDuanNO"] = root.attrib["BiaoDuanNO"]
- jingjibiao["Jsfs"] = root.attrib["Jsfs"]
- jingjibiao["Version"] = root.attrib["Version"]
- jingjibiao["Xmmc"] = root.attrib["Xmmc"]
- jingjibiao["Dxgcxx"] = []
- for child in root:
- if child.tag == "ZhaoBiaoXx":
- jingjibiao["ZhaoBiaoXx"] = {}
- jingjibiao["ZhaoBiaoXx"]["BzTime"] = child.attrib["BzTime"]
- jingjibiao["ZhaoBiaoXx"]["Bzr"] = child.attrib["Bzr"]
- jingjibiao["ZhaoBiaoXx"]["FhTime"] = child.attrib["FhTime"]
- jingjibiao["ZhaoBiaoXx"]["Fhr"] = child.attrib["Fhr"]
- jingjibiao["ZhaoBiaoXx"]["Zbr"] = child.attrib["Zbr"]
- jingjibiao["ZhaoBiaoXx"]["ZbrDb"] = child.attrib["ZbrDb"]
- jingjibiao["ZhaoBiaoXx"]["Zxr"] = child.attrib["Zxr"]
- jingjibiao["ZhaoBiaoXx"]["ZxrDb"] = child.attrib["ZxrDb"]
- elif child.tag == "TouBiaoXx":
- jingjibiao["TouBiaoXx"] = {}
- jingjibiao["TouBiaoXx"]["Zbr"] = child.attrib["Zbr"]
- jingjibiao["TouBiaoXx"]["Tbr"] = child.attrib["Tbr"]
- jingjibiao["TouBiaoXx"]["TbrDb"] = child.attrib["TbrDb"]
- jingjibiao["TouBiaoXx"]["Bzr"] = child.attrib["Bzr"]
- jingjibiao["TouBiaoXx"]["BzTime"] = child.attrib["BzTime"]
- jingjibiao["TouBiaoXx"]["Tbzj"] = child.attrib["Tbzj"]
- jingjibiao["TouBiaoXx"]["Zgj"] = child.attrib["Zgj"]
- jingjibiao["TouBiaoXx"]["Aqwmf"] = child.attrib["Aqwmf"]
- jingjibiao["TouBiaoXx"]["Gf"] = child.attrib["Gf"]
- elif child.tag == "Dxgcxx":
- Dxgcxx = {}
- Dxgcxx["Aqwmf"] = child.attrib["Aqwmf"]
- Dxgcxx["Dxgcbh"] = child.attrib["Dxgcbh"]
- Dxgcxx["Dxgcmc"] = child.attrib["Dxgcmc"]
- Dxgcxx["Gf"] = child.attrib["Gf"]
- Dxgcxx["Je"] = child.attrib["Je"]
- Dxgcxx["Zgj"] = child.attrib["Zgj"]
- Dxgcxx["Dwgc"] = []
- for grandchild in child:
- if grandchild.tag == "Dwgcxx":
- Dwgcxx = {}
- Dwgcxx["DogNum"] = grandchild.attrib["DogNum"]
- Dwgcxx["Dwgcbh"] = grandchild.attrib["Dwgcbh"]
- Dwgcbh.append({"bh": grandchild.attrib["Dwgcbh"], "num": grandchild.attrib["DogNum"]})
- Dwgcxx["Dwgcmc"] = grandchild.attrib["Dwgcmc"]
- Dwgcxx["MachineKey"] = grandchild.attrib["MachineKey"]
- Dwgcxx["SoftName"] = grandchild.attrib["SoftName"]
- Dwgcxx["SoftNum"] = grandchild.attrib["SoftNum"]
- Dwgcxx["Zylb"] = grandchild.attrib["Zylb"]
- Dxgcxx["Dwgc"].append(Dwgcxx)
- jingjibiao["Dxgcxx"].append(Dxgcxx)
- db = client["baojia"]
- collection = db["jingjibiao"]
- ##await collection.insert_one(jingjibiao)
- biao_id = (await collection.insert_one(jingjibiao)).inserted_id
- biao_id = str(biao_id)
- collection = db["Dwgc"]
- for entry in Dwgcbh:
- bjhz = service.getBjhz(root, entry["bh"])###array which contains __children
- gfsj = service.getGfsj(root, entry["bh"])##array which contains __children
- qtxm = service.getQtxm(root, entry["bh"])##array which contains __children
- zlje = service.getZlje(root, entry["bh"])
- jrg = service.getJrg(root, entry["bh"])
- zcbfwf = service.getZcbfwf(root, entry["bh"])
- fbrgycl = service.getFbrgycl(root, entry["bh"])
- rcjhz = service.getRcjhz(root, entry["bh"])
- zjcs = service.getZjcs(root, entry["bh"])
- qdbt = service.getQdxm(root, entry["bh"])
- Dwgc = {}
- Dwgc["bjhz"] = bjhz
- Dwgc["gfsj"] = gfsj
- Dwgc["qtxm"] = qtxm
- Dwgc["zlje"] = zlje
- Dwgc["jrg"] = jrg
- Dwgc["zcbfwf"] = zcbfwf
- Dwgc["fbrgycl"] = fbrgycl
- Dwgc["rcjhz"] = rcjhz
- Dwgc["zjcs"] = zjcs
- Dwgc["qdbt"] = qdbt
- Dwgc["DogNum"] = entry["num"]
- Dwgc["Dwgcbh"] = entry["bh"]
- Dwgc["biao_id"] = biao_id
- await collection.insert_one(Dwgc)
- collection = db["Djcs"]
- for entry in Dwgcbh:
-
- djcs = service.getDjcs(root, entry["bh"])
- for cs in djcs:
- cs["DogNum"] = entry["num"]
- cs["Dwgcbh"] = entry["bh"]
- cs["biao_id"] = biao_id
- rcj = getDjcsQingdanrcj_(root, entry["bh"], "", cs['清单编码'])
- cs["rcj"] = rcj
- if "__children" in cs:
- children = cs["__children"]
- for child in children:
- dercj = getDjcsDingercj_(root, entry["bh"], "", cs["清单编码"], child["清单编码"])
- child["dercj"] = dercj
- await collection.insert_one(cs)
- collection = db["qdxm"]
- for entry in Dwgcbh:
-
- bts = service.getQdxm(root, entry["bh"])
- for bt in bts:
-
- qdmx = service.getQdmx(root, entry["bh"], bt)
- for qd in qdmx:
- qd["DogNum"] = entry["num"]
- qd["Dwgcbh"] = entry["bh"]
- qd["biao_id"] = biao_id
- qd["bt"] = bt
- rcj = getQingdanrcj_(root, entry["bh"], bt, qd["清单编码"])
- qd["rcj"] = rcj
- if "__children" in qd:
- children = qd["__children"]
- for child in children:
- dercj = getDingercj_(root, entry["bh"], bt, qd["清单编码"], child["清单编码"])
- child["dercj"] = dercj
- await collection.insert_one(qd)
- import os
- ttt = []
- for root, dirs, files in os.walk("/Users/xiaopengzhang/Downloads/qingdan/data", topdown=False):
- for name in files:
- ##print(os.path.join(root, name))
- file_data = os.path.join(root, name)
- ttt.append(file_data)
- asyncio.run(resolve(ttt[2]))
|