test.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. import xml.etree.ElementTree as ET
  2. from subdir import service
  3. from bson.objectid import ObjectId
  4. from pymongo import AsyncMongoClient
  5. import asyncio
  6. def getDingercj_(root, bh, bt, qdbm, debm):
  7. result = [["ID", "人材机编码", "名称", "规格型号", "单位", "单价", "产地",
  8. "供应厂商", "人材机类别", "甲供标志", "含量", "合价", "暂估价标志", "主要材料标志", "主材标志", "设备标志" ]]
  9. #result.append(["ming cheng", "jin e", "zan gu jia", "anquan wenming fei", "guifei"])
  10. item = None
  11. for child in root:
  12. if child.tag == "Dxgcxx":
  13. for child1 in child:
  14. Dwgcbh = child1.attrib["Dwgcbh"]
  15. if Dwgcbh == bh:
  16. item = child1
  17. break
  18. ##result.append([child.attrib["Dxgcmc"], child.attrib["Je"], child.attrib["Zgj"], child.attrib["Aqwmf"], child.attrib["Gf"]])
  19. Fywj = None
  20. for child in item:
  21. if child.tag == 'Qdxm':
  22. Fywj= child
  23. break
  24. Rcjhz = None
  25. for child in item:
  26. if child.tag == 'Rcjhz':
  27. Rcjhz = child
  28. break
  29. kv = {}
  30. for entry in Rcjhz:
  31. kv[entry.attrib["RcjId"]]=entry
  32. container = None
  33. for child in Fywj:
  34. ##child is mx
  35. if child.tag == "QdBt":
  36. if child.attrib["Mc"] == bt:
  37. container = child
  38. break
  39. if not container:
  40. container = Fywj
  41. zimu = None
  42. for child in container:
  43. if child.attrib["Qdbm"] == qdbm:
  44. zimu = child
  45. break
  46. box = None
  47. if not zimu:
  48. return result
  49. for child in zimu:
  50. if child.tag == "Qdxdezj":
  51. box = child
  52. break
  53. hlmx_parent = None
  54. for child in box:
  55. if child.attrib["Debm"] == debm:
  56. for grandchild in child:
  57. if grandchild.tag == "Qdxdercjhl":
  58. hlmx_parent = grandchild
  59. for child in hlmx_parent:
  60. result.append([child.attrib["RcjId"],
  61. kv[child.attrib["RcjId"]].attrib["RcjBm"],
  62. kv[child.attrib["RcjId"]].attrib["Mc"],
  63. kv[child.attrib["RcjId"]].attrib["Ggxh"],
  64. kv[child.attrib["RcjId"]].attrib["Dw"],
  65. kv[child.attrib["RcjId"]].attrib["Dj"],
  66. kv[child.attrib["RcjId"]].attrib["Cd"],
  67. kv[child.attrib["RcjId"]].attrib["Gycs"],
  68. kv[child.attrib["RcjId"]].attrib["Rcjlb"],
  69. kv[child.attrib["RcjId"]].attrib["Jgbz"],
  70. child.attrib["Rcjhl"], child.attrib["Rcjhj"], "",
  71. "", "", ""
  72. ])
  73. return result
  74. def getQingdanrcj_(root, bh, bt, bm):
  75. result = [["ID", "人材机编码", "名称", "规格型号", "单位", "单价", "产地",
  76. "供应厂商", "人材机类别", "甲供标志", "含量", "合价", "暂估价标志", "主要材料标志", "主材标志", "设备标志" ]]
  77. #result.append(["ming cheng", "jin e", "zan gu jia", "anquan wenming fei", "guifei"])
  78. item = None
  79. for child in root:
  80. if child.tag == "Dxgcxx":
  81. for child1 in child:
  82. Dwgcbh = child1.attrib["Dwgcbh"]
  83. if Dwgcbh == bh:
  84. item = child1
  85. break
  86. ##result.append([child.attrib["Dxgcmc"], child.attrib["Je"], child.attrib["Zgj"], child.attrib["Aqwmf"], child.attrib["Gf"]])
  87. Fywj = None
  88. for child in item:
  89. if child.tag == 'Qdxm':
  90. Fywj= child
  91. break
  92. Rcjhz = None
  93. for child in item:
  94. if child.tag == 'Rcjhz':
  95. Rcjhz = child
  96. break
  97. kv = {}
  98. for entry in Rcjhz:
  99. kv[entry.attrib["RcjId"]]=entry
  100. container = None
  101. for child in Fywj:
  102. ##child is mx
  103. if child.tag == "QdBt":
  104. if child.attrib["Mc"] == bt:
  105. container = child
  106. break
  107. if not container:
  108. container = Fywj
  109. zimu = None
  110. for child in container:
  111. if child.attrib["Qdbm"] == bm:
  112. zimu = child
  113. break
  114. box = None
  115. if not zimu:
  116. return result
  117. for child in zimu:
  118. if child.tag == "Qdxrcjhl":
  119. box = child
  120. break
  121. for child in box:
  122. result.append([child.attrib["RcjId"],
  123. kv[child.attrib["RcjId"]].attrib["RcjBm"],
  124. kv[child.attrib["RcjId"]].attrib["Mc"],
  125. kv[child.attrib["RcjId"]].attrib["Ggxh"],
  126. kv[child.attrib["RcjId"]].attrib["Dw"],
  127. kv[child.attrib["RcjId"]].attrib["Dj"],
  128. kv[child.attrib["RcjId"]].attrib["Cd"],
  129. kv[child.attrib["RcjId"]].attrib["Gycs"],
  130. kv[child.attrib["RcjId"]].attrib["Rcjlb"],
  131. kv[child.attrib["RcjId"]].attrib["Jgbz"],
  132. child.attrib["Rcjhl"], child.attrib["Rcjhj"], child.attrib["Zgjbz"],
  133. child.attrib["Zyclbz"], child.attrib["Zcbz"], child.attrib["Sbbz"]
  134. ])
  135. return result
  136. def getDjcsDingercj_(root, bh, bt, qdbm, debm):
  137. result = [["ID", "人材机编码", "名称", "规格型号", "单位", "单价", "产地",
  138. "供应厂商", "人材机类别", "甲供标志", "含量", "合价", "暂估价标志", "主要材料标志", "主材标志", "设备标志" ]]
  139. #result.append(["ming cheng", "jin e", "zan gu jia", "anquan wenming fei", "guifei"])
  140. item = None
  141. for child in root:
  142. if child.tag == "Dxgcxx":
  143. for child1 in child:
  144. Dwgcbh = child1.attrib["Dwgcbh"]
  145. if Dwgcbh == bh:
  146. item = child1
  147. break
  148. ##result.append([child.attrib["Dxgcmc"], child.attrib["Je"], child.attrib["Zgj"], child.attrib["Aqwmf"], child.attrib["Gf"]])
  149. Fywj = None
  150. for child in item:
  151. if child.tag == 'Csxm':
  152. Fywj= child
  153. break
  154. Rcjhz = None
  155. for child in item:
  156. if child.tag == 'Rcjhz':
  157. Rcjhz = child
  158. break
  159. kv = {}
  160. for entry in Rcjhz:
  161. kv[entry.attrib["RcjId"]]=entry
  162. container = None
  163. for child in Fywj:
  164. if child.tag == "DjCs":
  165. container = child
  166. break
  167. zimu = None
  168. for child in container:
  169. if child.attrib["Bm"] == qdbm:
  170. zimu = child
  171. break
  172. box = None
  173. if not zimu:
  174. return result
  175. for child in zimu:
  176. if child.tag == "Csxdezj":
  177. box = child
  178. break
  179. hlmx_parent = None
  180. for child in box:
  181. if child.attrib["Debm"] == debm:
  182. for grandchild in child:
  183. if grandchild.tag == "Csxdercjhl":
  184. hlmx_parent = grandchild
  185. for child in hlmx_parent:
  186. result.append([child.attrib["RcjId"],
  187. kv[child.attrib["RcjId"]].attrib["RcjBm"],
  188. kv[child.attrib["RcjId"]].attrib["Mc"],
  189. kv[child.attrib["RcjId"]].attrib["Ggxh"],
  190. kv[child.attrib["RcjId"]].attrib["Dw"],
  191. kv[child.attrib["RcjId"]].attrib["Dj"],
  192. kv[child.attrib["RcjId"]].attrib["Cd"],
  193. kv[child.attrib["RcjId"]].attrib["Gycs"],
  194. kv[child.attrib["RcjId"]].attrib["Rcjlb"],
  195. kv[child.attrib["RcjId"]].attrib["Jgbz"],
  196. child.attrib["Rcjhl"], child.attrib["Rcjhj"], "",
  197. "", "", ""
  198. ])
  199. return result
  200. def getDjcsQingdanrcj_(root, bh, bt, bm):
  201. result = [["ID", "人材机编码", "名称", "规格型号", "单位", "单价", "产地",
  202. "供应厂商", "人材机类别", "甲供标志", "含量", "合价", "暂估价标志", "主要材料标志", "主材标志", "设备标志" ]]
  203. #result.append(["ming cheng", "jin e", "zan gu jia", "anquan wenming fei", "guifei"])
  204. item = None
  205. for child in root:
  206. if child.tag == "Dxgcxx":
  207. for child1 in child:
  208. Dwgcbh = child1.attrib["Dwgcbh"]
  209. if Dwgcbh == bh:
  210. item = child1
  211. break
  212. ##result.append([child.attrib["Dxgcmc"], child.attrib["Je"], child.attrib["Zgj"], child.attrib["Aqwmf"], child.attrib["Gf"]])
  213. Fywj = None
  214. for child in item:
  215. if child.tag == 'Csxm':
  216. Fywj= child
  217. break
  218. hl_parent = None
  219. for child in Fywj:
  220. if child.tag == "DjCs":
  221. hl_parent = child
  222. Rcjhz = None
  223. for child in item:
  224. if child.tag == 'Rcjhz':
  225. Rcjhz = child
  226. break
  227. kv = {}
  228. for entry in Rcjhz:
  229. kv[entry.attrib["RcjId"]]=entry
  230. zimu = None
  231. for child in hl_parent:
  232. if child.attrib["Bm"] == bm:
  233. zimu = child
  234. break
  235. box = None
  236. if not zimu:
  237. return result
  238. for child in zimu:
  239. if child.tag == "Csxrcjhl":
  240. box = child
  241. break
  242. for child in box:
  243. result.append([child.attrib["RcjId"],
  244. kv[child.attrib["RcjId"]].attrib["RcjBm"],
  245. kv[child.attrib["RcjId"]].attrib["Mc"],
  246. kv[child.attrib["RcjId"]].attrib["Ggxh"],
  247. kv[child.attrib["RcjId"]].attrib["Dw"],
  248. kv[child.attrib["RcjId"]].attrib["Dj"],
  249. kv[child.attrib["RcjId"]].attrib["Cd"],
  250. kv[child.attrib["RcjId"]].attrib["Gycs"],
  251. kv[child.attrib["RcjId"]].attrib["Rcjlb"],
  252. kv[child.attrib["RcjId"]].attrib["Jgbz"],
  253. child.attrib["Rcjhl"], child.attrib["Rcjhj"], child.attrib["Zgjbz"],
  254. child.attrib["Zyclbz"], child.attrib["Zcbz"], child.attrib["Sbbz"]
  255. ])
  256. return result
  257. client = AsyncMongoClient()
  258. async def resolve(data):
  259. tree = ET.parse( data)
  260. root = tree.getroot()
  261. print(root)
  262. Dwgcbh = []
  263. jingjibiao = {}
  264. jingjibiao["BiaoDuanNO"] = root.attrib["BiaoDuanNO"]
  265. jingjibiao["Jsfs"] = root.attrib["Jsfs"]
  266. jingjibiao["Version"] = root.attrib["Version"]
  267. jingjibiao["Xmmc"] = root.attrib["Xmmc"]
  268. jingjibiao["Dxgcxx"] = []
  269. for child in root:
  270. if child.tag == "ZhaoBiaoXx":
  271. jingjibiao["ZhaoBiaoXx"] = {}
  272. jingjibiao["ZhaoBiaoXx"]["BzTime"] = child.attrib["BzTime"]
  273. jingjibiao["ZhaoBiaoXx"]["Bzr"] = child.attrib["Bzr"]
  274. jingjibiao["ZhaoBiaoXx"]["FhTime"] = child.attrib["FhTime"]
  275. jingjibiao["ZhaoBiaoXx"]["Fhr"] = child.attrib["Fhr"]
  276. jingjibiao["ZhaoBiaoXx"]["Zbr"] = child.attrib["Zbr"]
  277. jingjibiao["ZhaoBiaoXx"]["ZbrDb"] = child.attrib["ZbrDb"]
  278. jingjibiao["ZhaoBiaoXx"]["Zxr"] = child.attrib["Zxr"]
  279. jingjibiao["ZhaoBiaoXx"]["ZxrDb"] = child.attrib["ZxrDb"]
  280. elif child.tag == "TouBiaoXx":
  281. jingjibiao["TouBiaoXx"] = {}
  282. jingjibiao["TouBiaoXx"]["Zbr"] = child.attrib["Zbr"]
  283. jingjibiao["TouBiaoXx"]["Tbr"] = child.attrib["Tbr"]
  284. jingjibiao["TouBiaoXx"]["TbrDb"] = child.attrib["TbrDb"]
  285. jingjibiao["TouBiaoXx"]["Bzr"] = child.attrib["Bzr"]
  286. jingjibiao["TouBiaoXx"]["BzTime"] = child.attrib["BzTime"]
  287. jingjibiao["TouBiaoXx"]["Tbzj"] = child.attrib["Tbzj"]
  288. jingjibiao["TouBiaoXx"]["Zgj"] = child.attrib["Zgj"]
  289. jingjibiao["TouBiaoXx"]["Aqwmf"] = child.attrib["Aqwmf"]
  290. jingjibiao["TouBiaoXx"]["Gf"] = child.attrib["Gf"]
  291. elif child.tag == "Dxgcxx":
  292. Dxgcxx = {}
  293. Dxgcxx["Aqwmf"] = child.attrib["Aqwmf"]
  294. Dxgcxx["Dxgcbh"] = child.attrib["Dxgcbh"]
  295. Dxgcxx["Dxgcmc"] = child.attrib["Dxgcmc"]
  296. Dxgcxx["Gf"] = child.attrib["Gf"]
  297. Dxgcxx["Je"] = child.attrib["Je"]
  298. Dxgcxx["Zgj"] = child.attrib["Zgj"]
  299. Dxgcxx["Dwgc"] = []
  300. for grandchild in child:
  301. if grandchild.tag == "Dwgcxx":
  302. Dwgcxx = {}
  303. Dwgcxx["DogNum"] = grandchild.attrib["DogNum"]
  304. Dwgcxx["Dwgcbh"] = grandchild.attrib["Dwgcbh"]
  305. Dwgcbh.append({"bh": grandchild.attrib["Dwgcbh"], "num": grandchild.attrib["DogNum"]})
  306. Dwgcxx["Dwgcmc"] = grandchild.attrib["Dwgcmc"]
  307. Dwgcxx["MachineKey"] = grandchild.attrib["MachineKey"]
  308. Dwgcxx["SoftName"] = grandchild.attrib["SoftName"]
  309. Dwgcxx["SoftNum"] = grandchild.attrib["SoftNum"]
  310. Dwgcxx["Zylb"] = grandchild.attrib["Zylb"]
  311. Dxgcxx["Dwgc"].append(Dwgcxx)
  312. jingjibiao["Dxgcxx"].append(Dxgcxx)
  313. db = client["baojia"]
  314. collection = db["jingjibiao"]
  315. ##await collection.insert_one(jingjibiao)
  316. biao_id = (await collection.insert_one(jingjibiao)).inserted_id
  317. biao_id = str(biao_id)
  318. collection = db["Dwgc"]
  319. for entry in Dwgcbh:
  320. bjhz = service.getBjhz(root, entry["bh"])###array which contains __children
  321. gfsj = service.getGfsj(root, entry["bh"])##array which contains __children
  322. qtxm = service.getQtxm(root, entry["bh"])##array which contains __children
  323. zlje = service.getZlje(root, entry["bh"])
  324. jrg = service.getJrg(root, entry["bh"])
  325. zcbfwf = service.getZcbfwf(root, entry["bh"])
  326. fbrgycl = service.getFbrgycl(root, entry["bh"])
  327. rcjhz = service.getRcjhz(root, entry["bh"])
  328. zjcs = service.getZjcs(root, entry["bh"])
  329. qdbt = service.getQdxm(root, entry["bh"])
  330. Dwgc = {}
  331. Dwgc["bjhz"] = bjhz
  332. Dwgc["gfsj"] = gfsj
  333. Dwgc["qtxm"] = qtxm
  334. Dwgc["zlje"] = zlje
  335. Dwgc["jrg"] = jrg
  336. Dwgc["zcbfwf"] = zcbfwf
  337. Dwgc["fbrgycl"] = fbrgycl
  338. Dwgc["rcjhz"] = rcjhz
  339. Dwgc["zjcs"] = zjcs
  340. Dwgc["qdbt"] = qdbt
  341. Dwgc["DogNum"] = entry["num"]
  342. Dwgc["Dwgcbh"] = entry["bh"]
  343. Dwgc["biao_id"] = biao_id
  344. await collection.insert_one(Dwgc)
  345. collection = db["Djcs"]
  346. for entry in Dwgcbh:
  347. djcs = service.getDjcs(root, entry["bh"])
  348. for cs in djcs:
  349. cs["DogNum"] = entry["num"]
  350. cs["Dwgcbh"] = entry["bh"]
  351. cs["biao_id"] = biao_id
  352. rcj = getDjcsQingdanrcj_(root, entry["bh"], "", cs['清单编码'])
  353. cs["rcj"] = rcj
  354. if "__children" in cs:
  355. children = cs["__children"]
  356. for child in children:
  357. dercj = getDjcsDingercj_(root, entry["bh"], "", cs["清单编码"], child["清单编码"])
  358. child["dercj"] = dercj
  359. await collection.insert_one(cs)
  360. collection = db["qdxm"]
  361. for entry in Dwgcbh:
  362. bts = service.getQdxm(root, entry["bh"])
  363. for bt in bts:
  364. qdmx = service.getQdmx(root, entry["bh"], bt)
  365. for qd in qdmx:
  366. qd["DogNum"] = entry["num"]
  367. qd["Dwgcbh"] = entry["bh"]
  368. qd["biao_id"] = biao_id
  369. qd["bt"] = bt
  370. rcj = getQingdanrcj_(root, entry["bh"], bt, qd["清单编码"])
  371. qd["rcj"] = rcj
  372. if "__children" in qd:
  373. children = qd["__children"]
  374. for child in children:
  375. dercj = getDingercj_(root, entry["bh"], bt, qd["清单编码"], child["清单编码"])
  376. child["dercj"] = dercj
  377. child['fuzhuEnable'] = False
  378. await collection.insert_one(qd)
  379. import os
  380. ttt = []
  381. for root, dirs, files in os.walk("/Users/xiaopengzhang/Downloads/qingdan/data", topdown=False):
  382. for name in files:
  383. ##print(os.path.join(root, name))
  384. file_data = os.path.join(root, name)
  385. ttt.append(file_data)
  386. asyncio.run(resolve(ttt[2]))