db.py 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003
  1. import xml.etree.ElementTree as ET
  2. from subdir import service
  3. from bson.objectid import ObjectId
  4. import uuid
  5. def getDingercj_(root, bh, bt, qdbm, debm):
  6. result = [["ID", "人材机编码", "名称", "规格型号", "单位", "单价", "产地",
  7. "供应厂商", "人材机类别", "甲供标志", "含量", "合价", "暂估价标志", "主要材料标志", "主材标志", "设备标志" ]]
  8. #result.append(["ming cheng", "jin e", "zan gu jia", "anquan wenming fei", "guifei"])
  9. item = None
  10. for child in root:
  11. if child.tag == "Dxgcxx":
  12. for child1 in child:
  13. Dwgcbh = child1.attrib["Dwgcbh"]
  14. if Dwgcbh == bh:
  15. item = child1
  16. break
  17. ##result.append([child.attrib["Dxgcmc"], child.attrib["Je"], child.attrib["Zgj"], child.attrib["Aqwmf"], child.attrib["Gf"]])
  18. Fywj = None
  19. for child in item:
  20. if child.tag == 'Qdxm':
  21. Fywj= child
  22. break
  23. Rcjhz = None
  24. for child in item:
  25. if child.tag == 'Rcjhz':
  26. Rcjhz = child
  27. break
  28. kv = {}
  29. for entry in Rcjhz:
  30. kv[entry.attrib["RcjId"]]=entry
  31. container = None
  32. for child in Fywj:
  33. ##child is mx
  34. if child.tag == "QdBt":
  35. if child.attrib["Mc"] == bt:
  36. container = child
  37. break
  38. if not container:
  39. container = Fywj
  40. zimu = None
  41. for child in container:
  42. if child.attrib["Qdbm"] == qdbm:
  43. zimu = child
  44. break
  45. box = None
  46. if not zimu:
  47. return result
  48. for child in zimu:
  49. if child.tag == "Qdxdezj":
  50. box = child
  51. break
  52. hlmx_parent = None
  53. for child in box:
  54. if child.attrib["Debm"] == debm:
  55. for grandchild in child:
  56. if grandchild.tag == "Qdxdercjhl":
  57. hlmx_parent = grandchild
  58. for child in hlmx_parent:
  59. result.append([child.attrib["RcjId"],
  60. kv[child.attrib["RcjId"]].attrib["RcjBm"],
  61. kv[child.attrib["RcjId"]].attrib["Mc"],
  62. kv[child.attrib["RcjId"]].attrib["Ggxh"],
  63. kv[child.attrib["RcjId"]].attrib["Dw"],
  64. kv[child.attrib["RcjId"]].attrib["Dj"],
  65. kv[child.attrib["RcjId"]].attrib["Cd"],
  66. kv[child.attrib["RcjId"]].attrib["Gycs"],
  67. kv[child.attrib["RcjId"]].attrib["Rcjlb"],
  68. kv[child.attrib["RcjId"]].attrib["Jgbz"],
  69. child.attrib["Rcjhl"], child.attrib["Rcjhj"], "",
  70. "", "", ""
  71. ])
  72. return result
  73. def getQingdanrcj_(root, bh, bt, bm):
  74. result = [["ID", "人材机编码", "名称", "规格型号", "单位", "单价", "产地",
  75. "供应厂商", "人材机类别", "甲供标志", "含量", "合价", "暂估价标志", "主要材料标志", "主材标志", "设备标志" ]]
  76. #result.append(["ming cheng", "jin e", "zan gu jia", "anquan wenming fei", "guifei"])
  77. item = None
  78. for child in root:
  79. if child.tag == "Dxgcxx":
  80. for child1 in child:
  81. Dwgcbh = child1.attrib["Dwgcbh"]
  82. if Dwgcbh == bh:
  83. item = child1
  84. break
  85. ##result.append([child.attrib["Dxgcmc"], child.attrib["Je"], child.attrib["Zgj"], child.attrib["Aqwmf"], child.attrib["Gf"]])
  86. Fywj = None
  87. for child in item:
  88. if child.tag == 'Qdxm':
  89. Fywj= child
  90. break
  91. Rcjhz = None
  92. for child in item:
  93. if child.tag == 'Rcjhz':
  94. Rcjhz = child
  95. break
  96. kv = {}
  97. for entry in Rcjhz:
  98. kv[entry.attrib["RcjId"]]=entry
  99. container = None
  100. for child in Fywj:
  101. ##child is mx
  102. if child.tag == "QdBt":
  103. if child.attrib["Mc"] == bt:
  104. container = child
  105. break
  106. if not container:
  107. container = Fywj
  108. zimu = None
  109. for child in container:
  110. if child.attrib["Qdbm"] == bm:
  111. zimu = child
  112. break
  113. box = None
  114. if not zimu:
  115. return result
  116. for child in zimu:
  117. if child.tag == "Qdxrcjhl":
  118. box = child
  119. break
  120. for child in box:
  121. result.append([child.attrib["RcjId"],
  122. kv[child.attrib["RcjId"]].attrib["RcjBm"],
  123. kv[child.attrib["RcjId"]].attrib["Mc"],
  124. kv[child.attrib["RcjId"]].attrib["Ggxh"],
  125. kv[child.attrib["RcjId"]].attrib["Dw"],
  126. kv[child.attrib["RcjId"]].attrib["Dj"],
  127. kv[child.attrib["RcjId"]].attrib["Cd"],
  128. kv[child.attrib["RcjId"]].attrib["Gycs"],
  129. kv[child.attrib["RcjId"]].attrib["Rcjlb"],
  130. kv[child.attrib["RcjId"]].attrib["Jgbz"],
  131. child.attrib["Rcjhl"], child.attrib["Rcjhj"], child.attrib["Zgjbz"],
  132. child.attrib["Zyclbz"], child.attrib["Zcbz"], child.attrib["Sbbz"]
  133. ])
  134. return result
  135. def getDjcsDingercj_(root, bh, bt, qdbm, debm):
  136. result = [["ID", "人材机编码", "名称", "规格型号", "单位", "单价", "产地",
  137. "供应厂商", "人材机类别", "甲供标志", "含量", "合价", "暂估价标志", "主要材料标志", "主材标志", "设备标志" ]]
  138. #result.append(["ming cheng", "jin e", "zan gu jia", "anquan wenming fei", "guifei"])
  139. item = None
  140. for child in root:
  141. if child.tag == "Dxgcxx":
  142. for child1 in child:
  143. Dwgcbh = child1.attrib["Dwgcbh"]
  144. if Dwgcbh == bh:
  145. item = child1
  146. break
  147. ##result.append([child.attrib["Dxgcmc"], child.attrib["Je"], child.attrib["Zgj"], child.attrib["Aqwmf"], child.attrib["Gf"]])
  148. Fywj = None
  149. for child in item:
  150. if child.tag == 'Csxm':
  151. Fywj= child
  152. break
  153. Rcjhz = None
  154. for child in item:
  155. if child.tag == 'Rcjhz':
  156. Rcjhz = child
  157. break
  158. kv = {}
  159. for entry in Rcjhz:
  160. kv[entry.attrib["RcjId"]]=entry
  161. container = None
  162. for child in Fywj:
  163. if child.tag == "DjCs":
  164. container = child
  165. break
  166. zimu = None
  167. for child in container:
  168. if child.attrib["Bm"] == qdbm:
  169. zimu = child
  170. break
  171. box = None
  172. if not zimu:
  173. return result
  174. for child in zimu:
  175. if child.tag == "Csxdezj":
  176. box = child
  177. break
  178. hlmx_parent = None
  179. for child in box:
  180. if child.attrib["Debm"] == debm:
  181. for grandchild in child:
  182. if grandchild.tag == "Csxdercjhl":
  183. hlmx_parent = grandchild
  184. for child in hlmx_parent:
  185. result.append([child.attrib["RcjId"],
  186. kv[child.attrib["RcjId"]].attrib["RcjBm"],
  187. kv[child.attrib["RcjId"]].attrib["Mc"],
  188. kv[child.attrib["RcjId"]].attrib["Ggxh"],
  189. kv[child.attrib["RcjId"]].attrib["Dw"],
  190. kv[child.attrib["RcjId"]].attrib["Dj"],
  191. kv[child.attrib["RcjId"]].attrib["Cd"],
  192. kv[child.attrib["RcjId"]].attrib["Gycs"],
  193. kv[child.attrib["RcjId"]].attrib["Rcjlb"],
  194. kv[child.attrib["RcjId"]].attrib["Jgbz"],
  195. child.attrib["Rcjhl"], child.attrib["Rcjhj"], "",
  196. "", "", ""
  197. ])
  198. return result
  199. def getDjcsQingdanrcj_(root, bh, bt, bm):
  200. result = [["ID", "人材机编码", "名称", "规格型号", "单位", "单价", "产地",
  201. "供应厂商", "人材机类别", "甲供标志", "含量", "合价", "暂估价标志", "主要材料标志", "主材标志", "设备标志" ]]
  202. #result.append(["ming cheng", "jin e", "zan gu jia", "anquan wenming fei", "guifei"])
  203. item = None
  204. for child in root:
  205. if child.tag == "Dxgcxx":
  206. for child1 in child:
  207. Dwgcbh = child1.attrib["Dwgcbh"]
  208. if Dwgcbh == bh:
  209. item = child1
  210. break
  211. ##result.append([child.attrib["Dxgcmc"], child.attrib["Je"], child.attrib["Zgj"], child.attrib["Aqwmf"], child.attrib["Gf"]])
  212. Fywj = None
  213. for child in item:
  214. if child.tag == 'Csxm':
  215. Fywj= child
  216. break
  217. hl_parent = None
  218. for child in Fywj:
  219. if child.tag == "DjCs":
  220. hl_parent = child
  221. Rcjhz = None
  222. for child in item:
  223. if child.tag == 'Rcjhz':
  224. Rcjhz = child
  225. break
  226. kv = {}
  227. for entry in Rcjhz:
  228. kv[entry.attrib["RcjId"]]=entry
  229. zimu = None
  230. for child in hl_parent:
  231. if child.attrib["Bm"] == bm:
  232. zimu = child
  233. break
  234. box = None
  235. if not zimu:
  236. return result
  237. for child in zimu:
  238. if child.tag == "Csxrcjhl":
  239. box = child
  240. break
  241. for child in box:
  242. result.append([child.attrib["RcjId"],
  243. kv[child.attrib["RcjId"]].attrib["RcjBm"],
  244. kv[child.attrib["RcjId"]].attrib["Mc"],
  245. kv[child.attrib["RcjId"]].attrib["Ggxh"],
  246. kv[child.attrib["RcjId"]].attrib["Dw"],
  247. kv[child.attrib["RcjId"]].attrib["Dj"],
  248. kv[child.attrib["RcjId"]].attrib["Cd"],
  249. kv[child.attrib["RcjId"]].attrib["Gycs"],
  250. kv[child.attrib["RcjId"]].attrib["Rcjlb"],
  251. kv[child.attrib["RcjId"]].attrib["Jgbz"],
  252. child.attrib["Rcjhl"], child.attrib["Rcjhj"], child.attrib["Zgjbz"],
  253. child.attrib["Zyclbz"], child.attrib["Zcbz"], child.attrib["Sbbz"]
  254. ])
  255. return result
  256. async def resolve(manager, websocket, data, client):
  257. tree = ET.parse("data/" + data)
  258. root = tree.getroot()
  259. print(root)
  260. Dwgcbh = []
  261. jingjibiao = {}
  262. jingjibiao["BiaoDuanNO"] = root.attrib["BiaoDuanNO"]
  263. jingjibiao["Jsfs"] = root.attrib["Jsfs"]
  264. jingjibiao["Version"] = root.attrib["Version"]
  265. jingjibiao["Xmmc"] = root.attrib["Xmmc"]
  266. jingjibiao["Dxgcxx"] = []
  267. for child in root:
  268. if child.tag == "ZhaoBiaoXx":
  269. jingjibiao["ZhaoBiaoXx"] = {}
  270. jingjibiao["ZhaoBiaoXx"]["BzTime"] = child.attrib["BzTime"]
  271. jingjibiao["ZhaoBiaoXx"]["Bzr"] = child.attrib["Bzr"]
  272. jingjibiao["ZhaoBiaoXx"]["FhTime"] = child.attrib["FhTime"]
  273. jingjibiao["ZhaoBiaoXx"]["Fhr"] = child.attrib["Fhr"]
  274. jingjibiao["ZhaoBiaoXx"]["Zbr"] = child.attrib["Zbr"]
  275. jingjibiao["ZhaoBiaoXx"]["ZbrDb"] = child.attrib["ZbrDb"]
  276. jingjibiao["ZhaoBiaoXx"]["Zxr"] = child.attrib["Zxr"]
  277. jingjibiao["ZhaoBiaoXx"]["ZxrDb"] = child.attrib["ZxrDb"]
  278. elif child.tag == "TouBiaoXx":
  279. jingjibiao["TouBiaoXx"] = {}
  280. jingjibiao["TouBiaoXx"]["Zbr"] = child.attrib["Zbr"]
  281. jingjibiao["TouBiaoXx"]["Tbr"] = child.attrib["Tbr"]
  282. jingjibiao["TouBiaoXx"]["TbrDb"] = child.attrib["TbrDb"]
  283. jingjibiao["TouBiaoXx"]["Bzr"] = child.attrib["Bzr"]
  284. jingjibiao["TouBiaoXx"]["BzTime"] = child.attrib["BzTime"]
  285. jingjibiao["TouBiaoXx"]["Tbzj"] = child.attrib["Tbzj"]
  286. jingjibiao["TouBiaoXx"]["Zgj"] = child.attrib["Zgj"]
  287. jingjibiao["TouBiaoXx"]["Aqwmf"] = child.attrib["Aqwmf"]
  288. jingjibiao["TouBiaoXx"]["Gf"] = child.attrib["Gf"]
  289. elif child.tag == "Dxgcxx":
  290. Dxgcxx = {}
  291. Dxgcxx["Aqwmf"] = child.attrib["Aqwmf"]
  292. Dxgcxx["Dxgcbh"] = child.attrib["Dxgcbh"]
  293. Dxgcxx["Dxgcmc"] = child.attrib["Dxgcmc"]
  294. Dxgcxx["Gf"] = child.attrib["Gf"]
  295. Dxgcxx["Je"] = child.attrib["Je"]
  296. Dxgcxx["Zgj"] = child.attrib["Zgj"]
  297. Dxgcxx["Dwgc"] = []
  298. for grandchild in child:
  299. if grandchild.tag == "Dwgcxx":
  300. Dwgcxx = {}
  301. Dwgcxx["DogNum"] = grandchild.attrib["DogNum"]
  302. Dwgcxx["Dwgcbh"] = grandchild.attrib["Dwgcbh"]
  303. Dwgcbh.append({"bh": grandchild.attrib["Dwgcbh"], "num": grandchild.attrib["DogNum"]})
  304. Dwgcxx["Dwgcmc"] = grandchild.attrib["Dwgcmc"]
  305. Dwgcxx["MachineKey"] = grandchild.attrib["MachineKey"]
  306. Dwgcxx["SoftName"] = grandchild.attrib["SoftName"]
  307. Dwgcxx["SoftNum"] = grandchild.attrib["SoftNum"]
  308. Dwgcxx["Zylb"] = grandchild.attrib["Zylb"]
  309. Dxgcxx["Dwgc"].append(Dwgcxx)
  310. jingjibiao["Dxgcxx"].append(Dxgcxx)
  311. db = client["baojia"]
  312. collection = db["jingjibiao"]
  313. biao_id = (await collection.insert_one(jingjibiao)).inserted_id
  314. biao_id = str(biao_id)
  315. collection = db["Dwgc"]
  316. for entry in Dwgcbh:
  317. bjhz = service.getBjhz(root, entry["bh"])###array which contains __children
  318. gfsj = service.getGfsj(root, entry["bh"])##array which contains __children
  319. qtxm = service.getQtxm(root, entry["bh"])##array which contains __children
  320. zlje = service.getZlje(root, entry["bh"])
  321. jrg = service.getJrg(root, entry["bh"])
  322. zcbfwf = service.getZcbfwf(root, entry["bh"])
  323. fbrgycl = service.getFbrgycl(root, entry["bh"])
  324. rcjhz = service.getRcjhz(root, entry["bh"])
  325. zjcs = service.getZjcs(root, entry["bh"])
  326. qdbt = service.getQdxm(root, entry["bh"])
  327. Dwgc = {}
  328. Dwgc["bjhz"] = bjhz
  329. Dwgc["gfsj"] = gfsj
  330. Dwgc["qtxm"] = qtxm
  331. Dwgc["zlje"] = zlje
  332. Dwgc["jrg"] = jrg
  333. Dwgc["zcbfwf"] = zcbfwf
  334. Dwgc["fbrgycl"] = fbrgycl
  335. Dwgc["rcjhz"] = rcjhz
  336. Dwgc["zjcs"] = zjcs
  337. Dwgc["qdbt"] = qdbt
  338. Dwgc["DogNum"] = entry["num"]
  339. Dwgc["Dwgcbh"] = entry["bh"]
  340. Dwgc["biao_id"] = biao_id
  341. await collection.insert_one(Dwgc)
  342. collection = db["Djcs"]
  343. for entry in Dwgcbh:
  344. djcs = service.getDjcs(root, entry["bh"])
  345. for cs in djcs:
  346. cs["DogNum"] = entry["num"]
  347. cs["Dwgcbh"] = entry["bh"]
  348. cs["biao_id"] = entry["biao_id"]
  349. rcj = getDjcsQingdanrcj_(root, entry["bh"], "", cs['清单编码'])
  350. cs["rcj"] = rcj
  351. if "__children" in cs:
  352. children = cs["__children"]
  353. for child in children:
  354. dercj = getDjcsDingercj_(root, entry["bh"], "", cs["清单编码"], child["清单编码"])
  355. child["dercj"] = dercj
  356. child['fuzhuEnable'] = False
  357. await collection.insert_one(cs)
  358. collection = db["qdxm"]
  359. for entry in Dwgcbh:
  360. bts = service.getQdxm(root, entry["bh"])
  361. for bt in bts:
  362. qdmx = service.getQdmx(root, entry["bh"], bt)
  363. for qd in qdmx:
  364. qd["DogNum"] = entry["num"]
  365. qd["Dwgcbh"] = entry["bh"]
  366. qd["biao_id"] = biao_id
  367. qd["bt"] = bt
  368. rcj = getQingdanrcj_(root, entry["bh"], bt, qd["清单编码"])
  369. qd["rcj"] = rcj
  370. if "__children" in qd:
  371. children = qd["__children"]
  372. for child in children:
  373. dercj = getDingercj_(root, entry["bh"], bt, qd["清单编码"], child["清单编码"])
  374. child["dercj"] = dercj
  375. child['fuzhuEnable'] = False
  376. await collection.insert_one(qd)
  377. collection = db["qufei"]
  378. document = jingjibiao
  379. dxgc = document['Dxgcxx']
  380. result = []
  381. for entry in dxgc:
  382. newone = {"名称" : entry['Dxgcmc'], "工程类型":"", "工程类别": "", "管理费(%)": "", "利润(%)": "","备注":"", "key" : str(uuid.uuid4()) }
  383. children = []
  384. for dwgc in entry['Dwgc']:
  385. children.append({"名称" : dwgc['Dwgcmc'], "工程类型":"", "工程类别": "", "管理费(%)": "", "利润(%)": "","备注":"", "key" : dwgc['Dwgcbh']})
  386. newone["children"] = children
  387. result.append(newone)
  388. await collection.insert_one({"biao_id": biao_id, "qufei": [{
  389. "名称" : document['Xmmc'], "工程类型":"", "工程类别": "", "管理费(%)": "", "利润(%)": "","备注":"", "key" : str(uuid.uuid4()), "children" : result
  390. }]})
  391. await manager.send_personal_message(f"You wrote: {data}", websocket)
  392. async def list_files(client):
  393. db = client["baojia"]
  394. collection = db["jingjibiao"]
  395. result = []
  396. async for post in collection.find():
  397. result.append([str(post['_id']), post["Xmmc"]])
  398. return result
  399. def getDwgc(id, Zylb):
  400. result = []
  401. #result.append(["ming cheng", "jin e", "zan gu jia", "anquan wenming fei", "guifei"])
  402. ##result.append([child.attrib["Dxgcmc"], child.attrib["Je"], child.attrib["Zgj"], child.attrib["Aqwmf"], child.attrib["Gf"]])
  403. id = id + "Zylb" + Zylb
  404. result.append({"id": id + "bao jia hui zong", "label": "报价汇总表"})
  405. result.append({"id": id + "gui fei shui jin", "label": "规费税金"})
  406. result.append({"id": id + "qing dan xiang mu", "label": "清单项目"})
  407. result.append({"id": id + "cuo shi xiang mu", "label": "措施项目"})
  408. result.append({"id": id +"qi ta xiang mu", "label": "其他项目"})
  409. result.append({"id": id +"zan lie jin e", "label": "暂列金额"})
  410. result.append({"id": id +"cai liao zan gu jia", "label": "材料暂估价"})
  411. result.append({"id": id + "zhuan ye gong cheng zan gu jia", "label": "专业工程暂估价"})
  412. result.append({"id": id + "ji ri gong", "label": "计日工"})
  413. result.append({"id": id + "zong cheng bao fu wu fei", "label": "总承包服务费"})
  414. result.append({"id": id + "zong jia xiang mu jin du kuan zhi fu fen jie", "label": "总价项目进度款支付分解"})
  415. result.append({"id": id + "fa bao ren gong ying cai liao", "label": "发包人供应材料"})
  416. result.append({"id": id + "cheng bao ren gong ying cai liao", "label": "承包人供应材料"})
  417. result.append({"id": id + "ren cai ji hui zong", "label": "人材机汇总"})
  418. return result
  419. async def getOutline(client, id):
  420. db = client["baojia"]
  421. collection = db["jingjibiao"]
  422. document = await collection.find_one({'_id': ObjectId(id)})
  423. result = []
  424. if 'TouBiaoXx' in document:
  425. result.append({"id" : "TouBiaoXx", "label" : "投标信息" })
  426. if 'Dxgcxx' in document:
  427. Dxgcxx = document["Dxgcxx"]
  428. for dxgc in Dxgcxx:
  429. result2 = []
  430. Dwgc = dxgc["Dwgc"]
  431. for grandchild in Dwgc:
  432. result2.append({"id" : grandchild['Dwgcbh'], "Zylb":grandchild['Zylb'], "label": grandchild["Dwgcmc"], "children" : getDwgc(grandchild['Dwgcbh'], grandchild['Zylb'])})
  433. result.append({"id" : dxgc['Dxgcbh'], "label" : dxgc['Dxgcmc'], "children" : result2})
  434. return result
  435. async def getDetail(client, id):
  436. db = client["baojia"]
  437. collection = db["jingjibiao"]
  438. document = await collection.find_one({'_id': ObjectId(id)})
  439. result = []
  440. result.append(["名称", "金额", "暂估价", "安全文明施工费", "规费"])
  441. if 'TouBiaoXx' in document:
  442. toubiaoxx = document["TouBiaoXx"]
  443. result.append([toubiaoxx["Zbr"], toubiaoxx["Tbzj"], toubiaoxx["Zgj"], toubiaoxx["Aqwmf"], toubiaoxx["Gf"]])
  444. if 'Dxgcxx' in document:
  445. Dxgcxx = document["Dxgcxx"]
  446. for dxgc in Dxgcxx:
  447. result.append([dxgc["Dxgcmc"], dxgc["Je"], dxgc["Zgj"], dxgc["Aqwmf"], dxgc["Gf"]])
  448. return result
  449. async def getBjhz(client, objectid, id):
  450. db = client["baojia"]
  451. collection = db["Dwgc"]
  452. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  453. return document['bjhz']
  454. async def getGfsj(client, objectid, id):
  455. db = client["baojia"]
  456. collection = db["Dwgc"]
  457. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  458. return document['gfsj']
  459. async def getQtxm(client, objectid, id):
  460. db = client["baojia"]
  461. collection = db["Dwgc"]
  462. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  463. return document['qtxm']
  464. async def getZlje(client, objectid, id):
  465. db = client["baojia"]
  466. collection = db["Dwgc"]
  467. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  468. return document['zlje']
  469. async def getJrg(client, objectid, id):
  470. db = client["baojia"]
  471. collection = db["Dwgc"]
  472. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  473. return document['jrg']
  474. async def getZcbfwf(client, objectid, id):
  475. db = client["baojia"]
  476. collection = db["Dwgc"]
  477. document = await collection.find_one({"Dwgcbh": id, "biao_id": objectid})
  478. return document['zcbfwf']
  479. async def getFbrgycl(client, objectid, id):
  480. db = client["baojia"]
  481. collection = db["Dwgc"]
  482. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  483. return document['fbrgycl']
  484. async def getRcjhz(client, objectid, id):
  485. db = client["baojia"]
  486. collection = db["Dwgc"]
  487. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  488. return document['rcjhz']
  489. async def getZjcs(client, objectid, id):
  490. db = client["baojia"]
  491. collection = db["Dwgc"]
  492. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  493. return document['zjcs']
  494. async def getDjcs(client, objectid, id):
  495. db = client["baojia"]
  496. collection = db["Djcs"]
  497. result = []
  498. async for post in collection.find({"Dwgcbh": id, "biao_id": objectid}):
  499. ##post["ID"] = post["_id"]
  500. del post["_id"]
  501. ##print( post["rcj"])
  502. ## del post["DogNum"]
  503. result.append(post)
  504. return result
  505. async def getDjcsQingdanrcj(client, name, bh, bt, bm):
  506. db = client["baojia"]
  507. collection = db["Djcs"]
  508. document = await collection.find_one({ "Dwgcbh": bh, "清单编码": bm, "biao_id": name})
  509. result = document["rcj"]
  510. return result
  511. async def getDjcsDingercj(client, name, bh, bt, qdbm, debm):
  512. db = client["baojia"]
  513. collection = db["Djcs"]
  514. document = await collection.find_one({"Dwgcbh": bh, "清单编码": qdbm, "biao_id": name})
  515. children = document["__children"]
  516. result = []
  517. for child in children:
  518. if child["清单编码"] == debm:
  519. result = child["dercj"]
  520. return result
  521. async def getQdxm(client, name, bh):
  522. db = client["baojia"]
  523. collection = db["Dwgc"]
  524. document = await collection.find_one({'biao_id': name, "Dwgcbh": bh})
  525. if document:
  526. return document['qdbt']
  527. else:
  528. return []
  529. async def getQdmx(client, name, bh, bt):
  530. db = client["baojia"]
  531. collection = db["qdxm"]
  532. result = []
  533. async for post in collection.find({'biao_id': name, "Dwgcbh": bh, "bt": bt}):
  534. ##post["ID"] = post["_id"]
  535. del post["_id"]
  536. #del post["rcj"]
  537. #del post["DogNum"]
  538. result.append(post)
  539. return result
  540. async def getQingdanrcj(client, name, bh, bt, bm):
  541. db = client["baojia"]
  542. collection = db["qdxm"]
  543. document = await collection.find_one({ "Dwgcbh": bh, "清单编码": bm, "biao_id": name, "bt": bt})
  544. result = document["rcj"]
  545. return result
  546. async def getDingercj(client, name, bh, bt, qdbm, debm):
  547. db = client["baojia"]
  548. collection = db["qdxm"]
  549. document = await collection.find_one({"Dwgcbh": bh, "清单编码": qdbm, "biao_id": name, "bt": bt})
  550. result = []
  551. if "__children" in document:
  552. children = document["__children"]
  553. for child in children:
  554. if child["清单编码"] == debm:
  555. result = child["dercj"]
  556. return result
  557. async def getQufei(client, id):
  558. db = client["baojia"]
  559. collection = db["qufei"]
  560. document = await collection.find_one({'biao_id': id})
  561. return document['qufei']
  562. async def save(client, data):
  563. db = client["baojia"]
  564. collection = db["qdxm"]
  565. for entry in data:
  566. entry["__children"] = entry["_children"]
  567. del entry["_children"]
  568. await collection.replace_one({"biao_id": entry["biao_id"], "Dwgcbh": entry["Dwgcbh"], "bt": entry["bt"], "清单编码": entry["清单编码"]}, entry)
  569. return {"result": "ok"}
  570. async def savedjcs(client, data):
  571. db = client["baojia"]
  572. collection = db["Djcs"]
  573. for entry in data:
  574. entry["__children"] = entry["_children"]
  575. del entry["_children"]
  576. await collection.replace_one({"biao_id": entry["biao_id"], "Dwgcbh": entry["Dwgcbh"], "清单编码": entry["清单编码"]}, entry)
  577. return {"result": "ok"}
  578. async def applyFL(client, id, data):
  579. db = client["baojia"]
  580. collection = db["qufei"]
  581. await collection.replace_one({"biao_id": id}, {"biao_id": id, "qufei": data})
  582. collection = db['qdxm']
  583. xm = data[0]
  584. for dxgc in xm["children"]:
  585. for dwgc in dxgc["children"]:
  586. bh = dwgc['key']
  587. glf = float(dwgc['管理费(%)'])
  588. lr = float(dwgc['利润(%)'])
  589. bz = dwgc['备注']
  590. ##print(bh+glf+lr+bz)
  591. async for post in collection.find({'biao_id': id, "Dwgcbh": bh}):
  592. rgfs = float(post['人工费'])
  593. clfs = float(post['材料费'])
  594. jxfs = float(post['机械费'])
  595. sl = float(post['数量'])
  596. if rgfs < 0.0001 and clfs < 0.0001 and jxfs < 0.0001:
  597. continue
  598. ##danxiang = False
  599. for child in post['__children']:##一条定额
  600. bm = child['清单编码']
  601. if bm.startswith("D"):
  602. ##danxiang = True
  603. continue
  604. rgf = float(child['人工费'])
  605. clf = float(child['材料费'])
  606. jxf = float(child['机械费'])
  607. zhdj = float(child['综合单价'])
  608. sl_ = float(child['数量'])
  609. if len(bz) == 0:
  610. ##常规计算
  611. child['管理费'] = (rgf + jxf) * glf / float(100)
  612. child['利润'] = (rgf + jxf) * lr / float(100)
  613. child['综合单价'] = rgf + clf + jxf + child['管理费'] + child['利润']
  614. child['合价'] = sl * sl_ * child['综合单价']
  615. else:
  616. child['管理费'] = (rgf) * glf / float(100)
  617. child['利润'] = (rgf) * lr / float(100)
  618. child['综合单价'] = rgf + clf + jxf + child['管理费'] + child['利润']
  619. child['合价'] = sl * sl_ * child['综合单价']
  620. if True:
  621. post['管理费'] = 0
  622. post['利润'] = 0
  623. for entry in post['__children']:
  624. post['管理费'] = post['管理费'] + float(entry['管理费']) * float(entry['数量'])
  625. post['利润'] = post['利润'] + float(entry['利润']) * float(entry['数量'])
  626. post['管理费'] = str(post['管理费'])
  627. post['利润'] = str(post['利润'])
  628. post['综合单价'] = str(float(post['人工费']) + float(post['材料费']) + float(post['机械费']) + float(post['管理费']) + float(post['利润']))
  629. post['合价'] = str(float(post['综合单价']) * float(post['数量']))
  630. await collection.replace_one({'_id': post['_id']}, post )
  631. collection = db['Djcs']
  632. for dxgc in xm["children"]:
  633. for dwgc in dxgc["children"]:
  634. bh = dwgc['key']
  635. glf = float(dwgc['管理费(%)'])
  636. lr = float(dwgc['利润(%)'])
  637. bz = dwgc['备注']
  638. ##print(bh+glf+lr+bz)
  639. async for post in collection.find({'biao_id': id, "Dwgcbh": bh}):
  640. rgfs = float(post['人工费'])
  641. clfs = float(post['材料费'])
  642. jxfs = float(post['机械费'])
  643. sl = float(post['数量'])
  644. if rgfs < 0.0001 and clfs < 0.0001 and jxfs < 0.0001:
  645. continue
  646. ##danxiang = False##一般有单项定额的,清单就一条定额,就是这个单项定额
  647. for child in post['__children']:
  648. bm = child['清单编码']
  649. if bm.startswith("D"):
  650. ##danxiang = True
  651. continue
  652. rgf = float(child['人工费'])
  653. clf = float(child['材料费'])
  654. jxf = float(child['机械费'])
  655. zhdj = float(child['综合单价'])
  656. sl_ = float(child['数量'])
  657. if len(bz) == 0:
  658. ##常规计算
  659. child['管理费'] = (rgf + jxf) * glf / float(100)
  660. child['利润'] = (rgf + jxf) * lr / float(100)
  661. child['综合单价'] = rgf + clf + jxf + child['管理费'] + child['利润']
  662. child['合价'] = sl * sl_ * child['综合单价']
  663. else:
  664. child['管理费'] = (rgf) * glf / float(100)
  665. child['利润'] = (rgf) * lr / float(100)
  666. child['综合单价'] = rgf + clf + jxf + child['管理费'] + child['利润']
  667. child['合价'] = sl * sl_ * child['综合单价']
  668. if True:
  669. post['管理费'] = 0
  670. post['利润'] = 0
  671. for entry in post['__children']:
  672. post['管理费'] = post['管理费'] + float(entry['管理费']) * float(entry['数量'])
  673. post['利润'] = post['利润'] + float(entry['利润']) * float(entry['数量'])
  674. post['管理费'] = str(post['管理费'])
  675. post['利润'] = str(post['利润'])
  676. post['综合单价'] = str(float(post['人工费']) + float(post['材料费']) + float(post['机械费']) + float(post['管理费']) + float(post['利润']))
  677. post['合价'] = str(float(post['综合单价']) * float(post['数量']))
  678. await collection.replace_one({'_id': post['_id']}, post )
  679. return {"result": "ok"}
  680. async def tiaojia(client, biao_id, bh, bm, jiage, glf, lr, bz):
  681. db = client["baojia"]
  682. collection = db["qdxm"]
  683. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}):
  684. children = post["__children"]
  685. qdsl = post['数量']
  686. hit = False
  687. for entry in children:###对一条定额,调价
  688. hitde = False
  689. dercj = entry["dercj"]
  690. dergf = 0
  691. declf = 0
  692. dejxf = 0
  693. for i in range(1, len(dercj)):
  694. rcj = dercj[i]
  695. if rcj[1] == bm:
  696. hit = True
  697. hitde = True
  698. rcj[5] = jiage
  699. hanliang = rcj[10]
  700. rcj[11] = str(float(jiage) * float(hanliang))
  701. if int(rcj[8]) == 1:
  702. dergf = dergf + float(rcj[11])
  703. elif int(rcj[8]) == 2:
  704. declf = declf + float(rcj[11])
  705. elif int(rcj[8]) == 3:
  706. dejxf = dejxf + float(rcj[11])
  707. if hitde:
  708. entry['人工费'] = str(dergf)
  709. entry['辅材费'] = str(declf)
  710. entry['材料费'] = str(declf)
  711. entry['机械费'] = str(dejxf)
  712. if bm.startswith("D"):
  713. entry['管理费'] = '0'
  714. entry['利润'] = '0'
  715. elif bz == 0:
  716. entry['管理费'] = str((dergf + dejxf) * float(glf) / float(100))
  717. entry['利润'] = str((dergf + dejxf) * float(lr) / float(100))
  718. else:
  719. entry['管理费'] = str((dergf) * float(glf) / float(100))
  720. entry['利润'] = str((dergf) * float(lr) / float(100))
  721. entry['综合单价'] = str(float(entry['人工费']) + float(entry['材料费']) + float(entry['机械费']) + float(entry['管理费']) + float(entry['利润']))
  722. entry['合价'] = str(float(entry['综合单价']) * float(entry['数量']) * float(qdsl))
  723. if hit:
  724. ##调整清单
  725. qdrcj = post['rcj']
  726. qdrgf = 0
  727. qdclf = 0
  728. qdjxf = 0
  729. for i in range(1, len(qdrcj)):
  730. entry = qdrcj[i]
  731. if entry[1] == bm:
  732. entry[5] = jiage
  733. hanliang = entry[10]
  734. entry[11] = str(float(jiage) * float(hanliang))
  735. if int(entry[8]) == 1:
  736. qdrgf = qdrgf + float(entry[11])
  737. elif int(entry[8]) == 2:
  738. qdclf = qdclf + float(entry[11])
  739. elif int(entry[8]) == 3:
  740. qdjxf = qdjxf + float(entry[11])
  741. post['人工费'] = str(qdrgf)
  742. post['辅材费'] = str(qdclf)
  743. post['材料费'] = str(qdclf)
  744. post['机械费'] = str(qdjxf)
  745. post['管理费'] = 0
  746. post['利润'] = 0
  747. for entry in children:
  748. post['管理费'] = post['管理费'] + float(entry['管理费']) * float(entry['数量'])
  749. post['利润'] = post['利润'] + float(entry['利润']) * float(entry['数量'])
  750. post['管理费'] = str(post['管理费'])
  751. post['利润'] = str(post['利润'])
  752. post['综合单价'] = str(float(post['人工费']) + float(post['材料费']) + float(post['机械费']) + float(post['管理费']) + float(post['利润']))
  753. post['合价'] = str(float(post['综合单价']) * float(qdsl))
  754. await collection.replace_one({'_id': post['_id']}, post )
  755. collection = db["Djcs"]
  756. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}):
  757. children = post["__children"]
  758. qdsl = post['数量']
  759. hit = False
  760. for entry in children:###对一条定额,调价
  761. hitde = False
  762. dercj = entry["dercj"]
  763. dergf = 0
  764. declf = 0
  765. dejxf = 0
  766. for i in range(1, len(dercj)):
  767. rcj = dercj[i]
  768. if rcj[1] == bm:
  769. hit = True
  770. hitde = True
  771. rcj[5] = jiage
  772. hanliang = rcj[10]
  773. rcj[11] = str(float(jiage) * float(hanliang))
  774. if int(rcj[8]) == 1:
  775. dergf = dergf + float(rcj[11])
  776. elif int(rcj[8]) == 2:
  777. declf = declf + float(rcj[11])
  778. elif int(rcj[8]) == 3:
  779. dejxf = dejxf + float(rcj[11])
  780. if hitde:
  781. entry['人工费'] = str(dergf)
  782. entry['辅材费'] = str(declf)
  783. entry['材料费'] = str(declf)
  784. entry['机械费'] = str(dejxf)
  785. if bm.startswith("D"):
  786. entry['管理费'] = '0'
  787. entry['利润'] = '0'
  788. elif bz == 0:
  789. entry['管理费'] = str((dergf + dejxf) * float(glf) / float(100))
  790. entry['利润'] = str((dergf + dejxf) * float(lr) / float(100))
  791. else:
  792. entry['管理费'] = str((dergf) * float(glf) / float(100))
  793. entry['利润'] = str((dergf) * float(lr) / float(100))
  794. entry['综合单价'] = str(float(entry['人工费']) + float(entry['材料费']) + float(entry['机械费']) + float(entry['管理费']) + float(entry['利润']))
  795. entry['合价'] = str(float(entry['综合单价']) * float(entry['数量']) * float(qdsl))
  796. if hit:
  797. ##调整清单
  798. qdrcj = post['rcj']
  799. qdrgf = 0
  800. qdclf = 0
  801. qdjxf = 0
  802. for i in range(1, len(qdrcj)):
  803. entry = qdrcj[i]
  804. if entry[1] == bm:
  805. entry[5] = jiage
  806. hanliang = entry[10]
  807. entry[11] = str(float(jiage) * float(hanliang))
  808. if int(entry[8]) == 1:
  809. qdrgf = qdrgf + float(entry[11])
  810. elif int(entry[8]) == 2:
  811. qdclf = qdclf + float(entry[11])
  812. elif int(entry[8]) == 3:
  813. qdjxf = qdjxf + float(entry[11])
  814. post['人工费'] = str(qdrgf)
  815. post['辅材费'] = str(qdclf)
  816. post['材料费'] = str(qdclf)
  817. post['机械费'] = str(qdjxf)
  818. post['管理费'] = 0
  819. post['利润'] = 0
  820. for entry in children:
  821. post['管理费'] = post['管理费'] + float(entry['管理费']) * float(entry['数量'])
  822. post['利润'] = post['利润'] + float(entry['利润']) * float(entry['数量'])
  823. post['管理费'] = str(post['管理费'])
  824. post['利润'] = str(post['利润'])
  825. post['综合单价'] = str(float(post['人工费']) + float(post['材料费']) + float(post['机械费']) + float(post['管理费']) + float(post['利润']))
  826. post['合价'] = str(float(post['综合单价']) * float(qdsl))
  827. await collection.replace_one({'_id': post['_id']}, post )