db.py 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300
  1. import xml.etree.ElementTree as ET
  2. from subdir import service, util
  3. from bson.objectid import ObjectId
  4. import uuid
  5. ###############helper##################
  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. ######################end of helper ########################
  258. async def resolve(manager, websocket, data, client):
  259. tree = ET.parse("data/" + 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. biao_id = (await collection.insert_one(jingjibiao)).inserted_id
  316. biao_id = str(biao_id)
  317. collection = db["Dwgc"]
  318. for entry in Dwgcbh:
  319. bjhz = service.getBjhz(root, entry["bh"])###array which contains __children
  320. gfsj = service.getGfsj(root, entry["bh"])##array which contains __children
  321. qtxm = service.getQtxm(root, entry["bh"])##array which contains __children
  322. zlje = service.getZlje(root, entry["bh"])
  323. jrg = service.getJrg(root, entry["bh"])
  324. zcbfwf = service.getZcbfwf(root, entry["bh"])
  325. fbrgycl = service.getFbrgycl(root, entry["bh"])
  326. rcjhz = service.getRcjhz(root, entry["bh"])
  327. zjcs = service.getZjcs(root, entry["bh"])
  328. qdbt = service.getQdxm(root, entry["bh"])
  329. zygczgj = service.getZygczgj(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['zygczgj'] = zygczgj
  337. Dwgc["zcbfwf"] = zcbfwf
  338. Dwgc["fbrgycl"] = fbrgycl
  339. Dwgc["rcjhz"] = rcjhz
  340. Dwgc["zjcs"] = zjcs
  341. Dwgc["qdbt"] = qdbt
  342. Dwgc["DogNum"] = entry["num"]
  343. Dwgc["Dwgcbh"] = entry["bh"]
  344. Dwgc["biao_id"] = biao_id
  345. await collection.insert_one(Dwgc)
  346. collection = db["Djcs"]
  347. for entry in Dwgcbh:
  348. djcs = service.getDjcs(root, entry["bh"])
  349. for cs in djcs:
  350. cs["DogNum"] = entry["num"]
  351. cs["Dwgcbh"] = entry["bh"]
  352. cs["biao_id"] = entry["biao_id"]
  353. rcj = getDjcsQingdanrcj_(root, entry["bh"], "", cs['清单编码'])
  354. cs["rcj"] = rcj
  355. if "__children" in cs:
  356. children = cs["__children"]
  357. for child in children:
  358. dercj = getDjcsDingercj_(root, entry["bh"], "", cs["清单编码"], child["清单编码"])
  359. child["dercj"] = dercj
  360. child['fuzhuEnable'] = False
  361. await collection.insert_one(cs)
  362. collection = db["qdxm"]
  363. for entry in Dwgcbh:
  364. bts = service.getQdxm(root, entry["bh"])
  365. for bt in bts:
  366. qdmx = service.getQdmx(root, entry["bh"], bt)
  367. for qd in qdmx:
  368. qd["DogNum"] = entry["num"]
  369. qd["Dwgcbh"] = entry["bh"]
  370. qd["biao_id"] = biao_id
  371. qd["bt"] = bt
  372. rcj = getQingdanrcj_(root, entry["bh"], bt, qd["清单编码"])
  373. qd["rcj"] = rcj
  374. if "__children" in qd:
  375. children = qd["__children"]
  376. for child in children:
  377. dercj = getDingercj_(root, entry["bh"], bt, qd["清单编码"], child["清单编码"])
  378. child["dercj"] = dercj
  379. child['fuzhuEnable'] = False
  380. await collection.insert_one(qd)
  381. collection = db["qufei"]
  382. document = jingjibiao
  383. dxgc = document['Dxgcxx']
  384. result = []
  385. for entry in dxgc:
  386. newone = {"名称" : entry['Dxgcmc'], "工程类型":"", "工程类别": "", "管理费(%)": "", "利润(%)": "","备注":"", "key" : str(uuid.uuid4()) }
  387. children = []
  388. for dwgc in entry['Dwgc']:
  389. children.append({"名称" : dwgc['Dwgcmc'], "工程类型":"", "工程类别": "", "管理费(%)": "", "利润(%)": "","备注":"", "key" : dwgc['Dwgcbh']})
  390. newone["children"] = children
  391. result.append(newone)
  392. await collection.insert_one({"biao_id": biao_id, "qufei": [{
  393. "名称" : document['Xmmc'], "工程类型":"", "工程类别": "", "管理费(%)": "", "利润(%)": "","备注":"", "key" : str(uuid.uuid4()), "children" : result
  394. }]})
  395. await manager.send_personal_message(f"You wrote: {data}", websocket)
  396. async def list_files(client):
  397. db = client["baojia"]
  398. collection = db["jingjibiao"]
  399. result = []
  400. async for post in collection.find():
  401. result.append([str(post['_id']), post["Xmmc"]])
  402. return result
  403. def getDwgc(id, Zylb):
  404. result = []
  405. #result.append(["ming cheng", "jin e", "zan gu jia", "anquan wenming fei", "guifei"])
  406. ##result.append([child.attrib["Dxgcmc"], child.attrib["Je"], child.attrib["Zgj"], child.attrib["Aqwmf"], child.attrib["Gf"]])
  407. id = id + "Zylb" + Zylb
  408. result.append({"id": id + "bao jia hui zong", "label": "报价汇总表"})
  409. result.append({"id": id + "gui fei shui jin", "label": "规费税金"})
  410. result.append({"id": id + "qing dan xiang mu", "label": "清单项目"})
  411. result.append({"id": id + "cuo shi xiang mu", "label": "措施项目"})
  412. result.append({"id": id +"qi ta xiang mu", "label": "其他项目"})
  413. result.append({"id": id +"zan lie jin e", "label": "暂列金额"})
  414. result.append({"id": id +"cai liao zan gu jia", "label": "材料暂估价"})
  415. result.append({"id": id + "zhuan ye gong cheng zan gu jia", "label": "专业工程暂估价"})
  416. result.append({"id": id + "ji ri gong", "label": "计日工"})
  417. result.append({"id": id + "zong cheng bao fu wu fei", "label": "总承包服务费"})
  418. result.append({"id": id + "zong jia xiang mu jin du kuan zhi fu fen jie", "label": "总价项目进度款支付分解"})
  419. result.append({"id": id + "fa bao ren gong ying cai liao", "label": "发包人供应材料"})
  420. result.append({"id": id + "cheng bao ren gong ying cai liao", "label": "承包人供应材料"})
  421. result.append({"id": id + "ren cai ji hui zong", "label": "人材机汇总"})
  422. return result
  423. async def getOutline(client, id):
  424. db = client["baojia"]
  425. collection = db["jingjibiao"]
  426. document = await collection.find_one({'_id': ObjectId(id)})
  427. result = []
  428. if 'TouBiaoXx' in document:
  429. result.append({"id" : "TouBiaoXx", "label" : "投标信息" })
  430. if 'Dxgcxx' in document:
  431. Dxgcxx = document["Dxgcxx"]
  432. for dxgc in Dxgcxx:
  433. result2 = []
  434. Dwgc = dxgc["Dwgc"]
  435. for grandchild in Dwgc:
  436. result2.append({"id" : grandchild['Dwgcbh'], "Zylb":grandchild['Zylb'], "label": grandchild["Dwgcmc"], "children" : getDwgc(grandchild['Dwgcbh'], grandchild['Zylb'])})
  437. result.append({"id" : dxgc['Dxgcbh'], "label" : dxgc['Dxgcmc'], "children" : result2})
  438. return result
  439. async def getDetail(client, id):
  440. db = client["baojia"]
  441. collection = db["jingjibiao"]
  442. document = await collection.find_one({'_id': ObjectId(id)})
  443. result = []
  444. result.append(["名称", "金额", "暂估价", "安全文明施工费", "规费"])
  445. if 'TouBiaoXx' in document:
  446. toubiaoxx = document["TouBiaoXx"]
  447. result.append([toubiaoxx["Zbr"], toubiaoxx["Tbzj"], toubiaoxx["Zgj"], toubiaoxx["Aqwmf"], toubiaoxx["Gf"]])
  448. if 'Dxgcxx' in document:
  449. Dxgcxx = document["Dxgcxx"]
  450. for dxgc in Dxgcxx:
  451. result.append([dxgc["Dxgcmc"], dxgc["Je"], dxgc["Zgj"], dxgc["Aqwmf"], dxgc["Gf"]])
  452. return result
  453. async def getBjhz(client, objectid, id):
  454. db = client["baojia"]
  455. collection = db["Dwgc"]
  456. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  457. return document['bjhz']
  458. async def getGfsj(client, objectid, id):
  459. db = client["baojia"]
  460. collection = db["Dwgc"]
  461. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  462. return document['gfsj']
  463. async def getQtxm(client, objectid, id):
  464. db = client["baojia"]
  465. collection = db["Dwgc"]
  466. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  467. return document['qtxm']
  468. async def getZygczgj(client, objectid, id):
  469. db = client["baojia"]
  470. collection = db["Dwgc"]
  471. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  472. return document['zygczgj']
  473. async def getZlje(client, objectid, id):
  474. db = client["baojia"]
  475. collection = db["Dwgc"]
  476. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  477. return document['zlje']
  478. async def getJrg(client, objectid, id):
  479. db = client["baojia"]
  480. collection = db["Dwgc"]
  481. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  482. return document['jrg']
  483. async def getZcbfwf(client, objectid, id):
  484. db = client["baojia"]
  485. collection = db["Dwgc"]
  486. document = await collection.find_one({"Dwgcbh": id, "biao_id": objectid})
  487. return document['zcbfwf']
  488. async def getFbrgycl(client, objectid, id):
  489. db = client["baojia"]
  490. collection = db["Dwgc"]
  491. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  492. return document['fbrgycl']
  493. async def getRcjhz(client, objectid, id):
  494. db = client["baojia"]
  495. collection = db["Dwgc"]
  496. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  497. return document['rcjhz']
  498. async def getZjcs(client, objectid, id):
  499. db = client["baojia"]
  500. collection = db["Dwgc"]
  501. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  502. return document['zjcs']
  503. async def getDjcs(client, objectid, id):
  504. db = client["baojia"]
  505. collection = db["Djcs"]
  506. result = []
  507. async for post in collection.find({"Dwgcbh": id, "biao_id": objectid}):
  508. ##post["ID"] = post["_id"]
  509. del post["_id"]
  510. ##print( post["rcj"])
  511. ## del post["DogNum"]
  512. result.append(post)
  513. return result
  514. async def getDjcsQingdanrcj(client, name, bh, bt, bm):
  515. db = client["baojia"]
  516. collection = db["Djcs"]
  517. document = await collection.find_one({ "Dwgcbh": bh, "清单编码": bm, "biao_id": name})
  518. result = document["rcj"]
  519. return result
  520. async def getDjcsDingercj(client, name, bh, bt, qdbm, debm):
  521. db = client["baojia"]
  522. collection = db["Djcs"]
  523. document = await collection.find_one({"Dwgcbh": bh, "清单编码": qdbm, "biao_id": name})
  524. children = document["__children"]
  525. result = []
  526. for child in children:
  527. if child["清单编码"] == debm:
  528. result = child["dercj"]
  529. return result
  530. async def getQdxm(client, name, bh):
  531. db = client["baojia"]
  532. collection = db["Dwgc"]
  533. document = await collection.find_one({'biao_id': name, "Dwgcbh": bh})
  534. if document:
  535. return document['qdbt']
  536. else:
  537. return []
  538. async def getQdmx(client, name, bh, bt):
  539. db = client["baojia"]
  540. collection = db["qdxm"]
  541. result = []
  542. async for post in collection.find({'biao_id': name, "Dwgcbh": bh, "bt": bt}):
  543. ##post["ID"] = post["_id"]
  544. del post["_id"]
  545. #del post["rcj"]
  546. #del post["DogNum"]
  547. result.append(post)
  548. return result
  549. async def getQingdanrcj(client, name, bh, bt, bm):
  550. db = client["baojia"]
  551. collection = db["qdxm"]
  552. document = await collection.find_one({ "Dwgcbh": bh, "清单编码": bm, "biao_id": name, "bt": bt})
  553. result = document["rcj"]
  554. return result
  555. async def getDingercj(client, name, bh, bt, qdbm, debm):
  556. db = client["baojia"]
  557. collection = db["qdxm"]
  558. document = await collection.find_one({"Dwgcbh": bh, "清单编码": qdbm, "biao_id": name, "bt": bt})
  559. result = []
  560. if "__children" in document:
  561. children = document["__children"]
  562. for child in children:
  563. if child["清单编码"] == debm:
  564. result = child["dercj"]
  565. return result
  566. async def getQufei(client, id):
  567. db = client["baojia"]
  568. collection = db["qufei"]
  569. document = await collection.find_one({'biao_id': id})
  570. return document['qufei']
  571. async def searchde(client, zhuanye, text):
  572. db = client["dinge"]
  573. collection = db["de-collection"]
  574. result = []
  575. async for post in collection.find({'$text': {"$search": "\"" + text + "\""}, "zhuanye": zhuanye}):
  576. result.append(post["DEBH"] + " " + post['GCLMC'] )
  577. if len(result) > 10:
  578. break
  579. return result
  580. ##################################editor##########################
  581. async def updatezjcs(client, id, bh, mc, fl):
  582. db = client["baojia"]
  583. collection = db["Dwgc"]
  584. document = await collection.find_one({'biao_id': id, 'Dwgcbh': bh}, {'rcjhz': 0})
  585. zjcs = document['zjcs']
  586. for entry in zjcs:
  587. if entry['名称'] == mc:
  588. entry['费率'] = fl
  589. entry['金额'] = str(float(entry['计算基数']) * float(fl) / float(100))
  590. await collection.update_one({'biao_id': id, "Dwgcbh": bh}, {'$set': {'zjcs': zjcs}})
  591. async def save(client, data):
  592. db = client["baojia"]
  593. collection = db["qdxm"]
  594. biao_id = None
  595. bh = None
  596. for entry in data:
  597. entry["__children"] = entry["_children"]
  598. del entry["_children"]
  599. biao_id = entry['biao_id']
  600. bh = entry['Dwgcbh']
  601. await collection.replace_one({"biao_id": entry["biao_id"], "Dwgcbh": entry["Dwgcbh"], "bt": entry["bt"], "清单编码": entry["清单编码"]}, entry)
  602. if not biao_id:
  603. return {"result" : "ok"}
  604. rcjhz = []
  605. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  606. qdrcj = post['rcj'][1:]
  607. for entry in qdrcj:
  608. entry[10] = float(entry[10]) * float(post['数量'])
  609. rcjhz = rcjhz + qdrcj
  610. collection = db["Djcs"]
  611. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  612. qdrcj = post['rcj'][1:]
  613. for entry in qdrcj:
  614. entry[10] = float(entry[10]) * float(post['数量'])
  615. rcjhz = rcjhz + qdrcj
  616. newHuizong = util.huizongrcj(rcjhz)
  617. collection = db["Dwgc"]
  618. await collection.update_one({'biao_id': biao_id, 'Dwgcbh': bh}, {'$set': {'rcjhz' : newHuizong}})
  619. await zongjiaDwgc(client, biao_id, bh)
  620. return {"result": "ok"}
  621. async def savedjcs(client, data):
  622. db = client["baojia"]
  623. collection = db["Djcs"]
  624. biao_id = None
  625. bh = None
  626. for entry in data:
  627. entry["__children"] = entry["_children"]
  628. del entry["_children"]
  629. biao_id = entry['biao_id']
  630. bh = entry['Dwgcbh']
  631. await collection.replace_one({"biao_id": entry["biao_id"], "Dwgcbh": entry["Dwgcbh"], "清单编码": entry["清单编码"]}, entry)
  632. if not biao_id:
  633. return {"result" : "ok"}
  634. rcjhz = []
  635. collection = db["qdxm"]
  636. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  637. qdrcj = post['rcj'][1:]
  638. for entry in qdrcj:
  639. entry[10] = float(entry[10]) * float(post['数量'])
  640. rcjhz = rcjhz + qdrcj
  641. collection = db["Djcs"]
  642. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  643. qdrcj = post['rcj'][1:]
  644. for entry in qdrcj:
  645. entry[10] = float(entry[10]) * float(post['数量'])
  646. rcjhz = rcjhz + qdrcj
  647. newHuizong = util.huizongrcj(rcjhz)
  648. collection = db["Dwgc"]
  649. await collection.update_one({'biao_id': biao_id, 'Dwgcbh': bh}, {'$set': {'rcjhz' : newHuizong}})
  650. await zongjiaDwgc(client, biao_id, bh)
  651. return {"result": "ok"}
  652. async def applyFL(client, id, data):
  653. db = client["baojia"]
  654. collection = db["qufei"]
  655. await collection.replace_one({"biao_id": id}, {"biao_id": id, "qufei": data})
  656. collection = db['qdxm']
  657. xm = data[0]
  658. for dxgc in xm["children"]:
  659. for dwgc in dxgc["children"]:
  660. bh = dwgc['key']
  661. glf = float(dwgc['管理费(%)'])
  662. lr = float(dwgc['利润(%)'])
  663. bz = dwgc['备注']
  664. ##print(bh+glf+lr+bz)
  665. async for post in collection.find({'biao_id': id, "Dwgcbh": bh}):
  666. rgfs = float(post['人工费'])
  667. clfs = float(post['材料费'])
  668. jxfs = float(post['机械费'])
  669. sl = float(post['数量'])
  670. if rgfs < 0.0001 and clfs < 0.0001 and jxfs < 0.0001:
  671. continue
  672. ##danxiang = False
  673. for child in post['__children']:##一条定额
  674. bm = child['清单编码']
  675. if bm.startswith("D"):
  676. ##danxiang = True
  677. continue
  678. rgf = float(child['人工费'])
  679. clf = float(child['材料费'])
  680. jxf = float(child['机械费'])
  681. zhdj = float(child['综合单价'])
  682. sl_ = float(child['数量'])
  683. if len(bz) == 0:
  684. ##常规计算
  685. child['管理费'] = (rgf + jxf) * glf / float(100)
  686. child['利润'] = (rgf + jxf) * lr / float(100)
  687. child['综合单价'] = rgf + clf + jxf + child['管理费'] + child['利润']
  688. child['合价'] = sl * sl_ * child['综合单价']
  689. else:
  690. child['管理费'] = (rgf) * glf / float(100)
  691. child['利润'] = (rgf) * lr / float(100)
  692. child['综合单价'] = rgf + clf + jxf + child['管理费'] + child['利润']
  693. child['合价'] = sl * sl_ * child['综合单价']
  694. if True:
  695. post['管理费'] = 0
  696. post['利润'] = 0
  697. for entry in post['__children']:
  698. post['管理费'] = post['管理费'] + float(entry['管理费']) * float(entry['数量'])
  699. post['利润'] = post['利润'] + float(entry['利润']) * float(entry['数量'])
  700. post['管理费'] = str(post['管理费'])
  701. post['利润'] = str(post['利润'])
  702. post['综合单价'] = str(float(post['人工费']) + float(post['材料费']) + float(post['机械费']) + float(post['管理费']) + float(post['利润']))
  703. post['合价'] = str(float(post['综合单价']) * float(post['数量']))
  704. await collection.replace_one({'_id': post['_id']}, post )
  705. collection = db['Djcs']
  706. for dxgc in xm["children"]:
  707. for dwgc in dxgc["children"]:
  708. bh = dwgc['key']
  709. glf = float(dwgc['管理费(%)'])
  710. lr = float(dwgc['利润(%)'])
  711. bz = dwgc['备注']
  712. ##print(bh+glf+lr+bz)
  713. async for post in collection.find({'biao_id': id, "Dwgcbh": bh}):
  714. rgfs = float(post['人工费'])
  715. clfs = float(post['材料费'])
  716. jxfs = float(post['机械费'])
  717. sl = float(post['数量'])
  718. if rgfs < 0.0001 and clfs < 0.0001 and jxfs < 0.0001:
  719. continue
  720. ##danxiang = False##一般有单项定额的,清单就一条定额,就是这个单项定额
  721. for child in post['__children']:
  722. bm = child['清单编码']
  723. if bm.startswith("D"):
  724. ##danxiang = True
  725. continue
  726. rgf = float(child['人工费'])
  727. clf = float(child['材料费'])
  728. jxf = float(child['机械费'])
  729. zhdj = float(child['综合单价'])
  730. sl_ = float(child['数量'])
  731. if len(bz) == 0:
  732. ##常规计算
  733. child['管理费'] = (rgf + jxf) * glf / float(100)
  734. child['利润'] = (rgf + jxf) * lr / float(100)
  735. child['综合单价'] = rgf + clf + jxf + child['管理费'] + child['利润']
  736. child['合价'] = sl * sl_ * child['综合单价']
  737. else:
  738. child['管理费'] = (rgf) * glf / float(100)
  739. child['利润'] = (rgf) * lr / float(100)
  740. child['综合单价'] = rgf + clf + jxf + child['管理费'] + child['利润']
  741. child['合价'] = sl * sl_ * child['综合单价']
  742. if True:
  743. post['管理费'] = 0
  744. post['利润'] = 0
  745. for entry in post['__children']:
  746. post['管理费'] = post['管理费'] + float(entry['管理费']) * float(entry['数量'])
  747. post['利润'] = post['利润'] + float(entry['利润']) * float(entry['数量'])
  748. post['管理费'] = str(post['管理费'])
  749. post['利润'] = str(post['利润'])
  750. post['综合单价'] = str(float(post['人工费']) + float(post['材料费']) + float(post['机械费']) + float(post['管理费']) + float(post['利润']))
  751. post['合价'] = str(float(post['综合单价']) * float(post['数量']))
  752. await collection.replace_one({'_id': post['_id']}, post )
  753. for dxgc in xm["children"]:
  754. for dwgc in dxgc["children"]:
  755. bh = dwgc['key']
  756. await zongjiaDwgc(client, id, bh)
  757. return {"result": "ok"}
  758. async def tiaojia(client, biao_id, bh, bm, mingcheng, danwei, jiage, glf, lr, bz):
  759. db = client["baojia"]
  760. collection = db["qdxm"]
  761. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}):
  762. if "__children" not in post:
  763. ##print(post)
  764. continue
  765. children = post["__children"]
  766. qdsl = post['数量']
  767. hit = False
  768. for entry in children:###对一条定额,调价
  769. hitde = False
  770. dercj = entry["dercj"]
  771. dergf = 0
  772. declf = 0
  773. dejxf = 0
  774. for i in range(1, len(dercj)):
  775. rcj = dercj[i]
  776. if rcj[1] == bm and rcj[2] == mingcheng and rcj[4] == danwei:
  777. hit = True
  778. hitde = True
  779. rcj[5] = jiage
  780. hanliang = rcj[10]
  781. rcj[11] = str(float(jiage) * float(hanliang))
  782. if int(rcj[8]) == 1:
  783. dergf = dergf + float(rcj[11])
  784. elif int(rcj[8]) == 2:
  785. declf = declf + float(rcj[11])
  786. elif int(rcj[8]) == 3:
  787. dejxf = dejxf + float(rcj[11])
  788. if hitde:
  789. entry['人工费'] = str(dergf)
  790. entry['辅材费'] = str(declf)
  791. entry['材料费'] = str(declf)
  792. entry['机械费'] = str(dejxf)
  793. if bm.startswith("D"):
  794. entry['管理费'] = '0'
  795. entry['利润'] = '0'
  796. elif bz == 0:
  797. entry['管理费'] = str((dergf + dejxf) * float(glf) / float(100))
  798. entry['利润'] = str((dergf + dejxf) * float(lr) / float(100))
  799. else:
  800. entry['管理费'] = str((dergf) * float(glf) / float(100))
  801. entry['利润'] = str((dergf) * float(lr) / float(100))
  802. entry['综合单价'] = str(float(entry['人工费']) + float(entry['材料费']) + float(entry['机械费']) + float(entry['管理费']) + float(entry['利润']))
  803. entry['合价'] = str(float(entry['综合单价']) * float(entry['数量']) * float(qdsl))
  804. if hit:
  805. ##调整清单
  806. qdrcj = post['rcj']
  807. qdrgf = 0
  808. qdclf = 0
  809. qdjxf = 0
  810. for i in range(1, len(qdrcj)):
  811. entry = qdrcj[i]
  812. if entry[1] == bm and entry[2] == mingcheng and entry[4] == danwei:
  813. entry[5] = jiage
  814. hanliang = entry[10]
  815. entry[11] = str(float(jiage) * float(hanliang))
  816. if int(entry[8]) == 1:
  817. qdrgf = qdrgf + float(entry[11])
  818. elif int(entry[8]) == 2:
  819. qdclf = qdclf + float(entry[11])
  820. elif int(entry[8]) == 3:
  821. qdjxf = qdjxf + float(entry[11])
  822. post['人工费'] = str(qdrgf)
  823. post['辅材费'] = str(qdclf)
  824. post['材料费'] = str(qdclf)
  825. post['机械费'] = str(qdjxf)
  826. post['管理费'] = 0
  827. post['利润'] = 0
  828. for entry in children:
  829. post['管理费'] = post['管理费'] + float(entry['管理费']) * float(entry['数量'])
  830. post['利润'] = post['利润'] + float(entry['利润']) * float(entry['数量'])
  831. post['管理费'] = str(post['管理费'])
  832. post['利润'] = str(post['利润'])
  833. post['综合单价'] = str(float(post['人工费']) + float(post['材料费']) + float(post['机械费']) + float(post['管理费']) + float(post['利润']))
  834. post['合价'] = str(float(post['综合单价']) * float(qdsl))
  835. print(post)
  836. await collection.replace_one({'_id': post['_id']}, post )
  837. collection = db["Djcs"]
  838. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}):
  839. children = post["__children"]
  840. qdsl = post['数量']
  841. hit = False
  842. for entry in children:###对一条定额,调价
  843. hitde = False
  844. dercj = entry["dercj"]
  845. dergf = 0
  846. declf = 0
  847. dejxf = 0
  848. for i in range(1, len(dercj)):
  849. rcj = dercj[i]
  850. if rcj[1] == bm and rcj[2] == mingcheng and rcj[4] == danwei:
  851. hit = True
  852. hitde = True
  853. rcj[5] = jiage
  854. hanliang = rcj[10]
  855. rcj[11] = str(float(jiage) * float(hanliang))
  856. if int(rcj[8]) == 1:
  857. dergf = dergf + float(rcj[11])
  858. elif int(rcj[8]) == 2:
  859. declf = declf + float(rcj[11])
  860. elif int(rcj[8]) == 3:
  861. dejxf = dejxf + float(rcj[11])
  862. if hitde:
  863. entry['人工费'] = str(dergf)
  864. entry['辅材费'] = str(declf)
  865. entry['材料费'] = str(declf)
  866. entry['机械费'] = str(dejxf)
  867. if bm.startswith("D"):
  868. entry['管理费'] = '0'
  869. entry['利润'] = '0'
  870. elif bz == 0:
  871. entry['管理费'] = str((dergf + dejxf) * float(glf) / float(100))
  872. entry['利润'] = str((dergf + dejxf) * float(lr) / float(100))
  873. else:
  874. entry['管理费'] = str((dergf) * float(glf) / float(100))
  875. entry['利润'] = str((dergf) * float(lr) / float(100))
  876. entry['综合单价'] = str(float(entry['人工费']) + float(entry['材料费']) + float(entry['机械费']) + float(entry['管理费']) + float(entry['利润']))
  877. entry['合价'] = str(float(entry['综合单价']) * float(entry['数量']) * float(qdsl))
  878. if hit:
  879. ##调整清单
  880. qdrcj = post['rcj']
  881. qdrgf = 0
  882. qdclf = 0
  883. qdjxf = 0
  884. for i in range(1, len(qdrcj)):
  885. entry = qdrcj[i]
  886. if entry[1] == bm and entry[2] == mingcheng and entry[4] == danwei:
  887. entry[5] = jiage
  888. hanliang = entry[10]
  889. entry[11] = str(float(jiage) * float(hanliang))
  890. if int(entry[8]) == 1:
  891. qdrgf = qdrgf + float(entry[11])
  892. elif int(entry[8]) == 2:
  893. qdclf = qdclf + float(entry[11])
  894. elif int(entry[8]) == 3:
  895. qdjxf = qdjxf + float(entry[11])
  896. post['人工费'] = str(qdrgf)
  897. post['辅材费'] = str(qdclf)
  898. post['材料费'] = str(qdclf)
  899. post['机械费'] = str(qdjxf)
  900. post['管理费'] = 0
  901. post['利润'] = 0
  902. for entry in children:
  903. post['管理费'] = post['管理费'] + float(entry['管理费']) * float(entry['数量'])
  904. post['利润'] = post['利润'] + float(entry['利润']) * float(entry['数量'])
  905. post['管理费'] = str(post['管理费'])
  906. post['利润'] = str(post['利润'])
  907. post['综合单价'] = str(float(post['人工费']) + float(post['材料费']) + float(post['机械费']) + float(post['管理费']) + float(post['利润']))
  908. post['合价'] = str(float(post['综合单价']) * float(qdsl))
  909. await collection.replace_one({'_id': post['_id']}, post )
  910. collection = db["Dwgc"]
  911. document = await collection.find_one({'biao_id': biao_id, "Dwgcbh": bh})
  912. hz = document['rcjhz']
  913. for entry in hz:
  914. if entry[1] == bm and entry[2] == mingcheng and entry[4] == danwei:
  915. entry[6] = jiage
  916. entry[7] = float(jiage) * float(entry[5])
  917. await collection.update_one({'biao_id': biao_id, "Dwgcbh": bh}, {'$set': {'rcjhz': hz}})
  918. await zongjiaDwgc(client, biao_id, bh)
  919. def bjhz_template():
  920. result = []
  921. result.append({'序号': '1', '名称': '分部分项工程', '金额': '0', '暂估价': '0', '类别' : '1', '__children': [
  922. {'序号': '1.1', '名称': '人工费', '金额': '0', '暂估价': '0', '类别' : '1.1'},
  923. {'序号': '1.2', '名称': '材料费', '金额': '0', '暂估价': '0', '类别' : '1.2'},
  924. {'序号': '1.3', '名称': '施工机具使用费', '金额': '0', '暂估价': '0', '类别' : '1.3'},
  925. {'序号': '1.4', '名称': '企业管理费', '金额': '0', '暂估价': '0', '类别' : '1.4'},
  926. {'序号': '1.5', '名称': '利润', '金额': '0', '暂估价': '0', '类别' : '1.5'}
  927. ]})
  928. result.append({'序号': '2', '名称': '措施项目', '金额': '0', '暂估价': '0', '类别' : '2', '__children': [
  929. {'序号': '2.1', '名称': '单价措施项目费', '金额': '0', '暂估价': '0', '类别' : '2.1'},
  930. {'序号': '2.2', '名称': '总价措施项目费', '金额': '0', '暂估价': '0', '类别' : '2.2', '__children' : [
  931. {'序号': '2.2.1', '名称': '其中:安全文明施工措施费', '金额': '0', '暂估价': '0', '类别' : '2.2.1'},]
  932. }
  933. ]})
  934. result.append({'序号': '3', '名称': '其他项目', '金额': '0', '暂估价': '0', '类别' : '3', '__children': [
  935. {'序号': '3.1', '名称': '其中:暂列金额', '金额': '0', '暂估价': '0', '类别' : '3.1'},
  936. {'序号': '3.2', '名称': '其中:专业工程暂估价', '金额': '0', '暂估价': '0', '类别' : '3.2'},
  937. {'序号': '3.3', '名称': '其中:计日工', '金额': '0', '暂估价': '0', '类别' : '3.3'},
  938. {'序号': '3.4', '名称': '其中:总承包服务费', '金额': '0', '暂估价': '0', '类别' : '3.4'},
  939. ]})
  940. result.append({'序号': '4', '名称': '规费', '金额': '0', '暂估价': '0', '类别' : '4', })
  941. result.append({'序号': '5', '名称': '税金', '金额': '0', '暂估价': '0', '类别' : '5', })
  942. result.append({'序号': '6', '名称': '工程造价', '金额': '0', '暂估价': '0', '类别' : '6', })
  943. return result
  944. async def zongjiaDwgc(client, biao_id, bh):
  945. db = client["baojia"]
  946. collection = db["qdxm"]
  947. qd_sum = 0
  948. djcs_sum = 0
  949. rgf_sum = 0
  950. clf_sum = 0
  951. jxf_sum = 0
  952. glf_sum = 0
  953. lr_sum = 0
  954. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  955. qd_sum = qd_sum + float(post['合价'])
  956. rgf_sum = rgf_sum + float(post['数量']) * float(post['人工费'])
  957. clf_sum = clf_sum + float(post['数量']) * float(post['材料费'])
  958. jxf_sum = jxf_sum + float(post['数量']) * float(post['机械费'])
  959. glf_sum = glf_sum + float(post['数量']) * float(post['管理费'])
  960. lr_sum = lr_sum + float(post['数量']) * float(post['利润'])
  961. collection = db["Djcs"]
  962. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  963. djcs_sum = djcs_sum + float(post['合价'])
  964. sum = qd_sum + djcs_sum
  965. collection = db['Dwgc']
  966. document = await collection.find_one({'biao_id': biao_id, "Dwgcbh": bh}, {'rcjhz': 0})
  967. zjcs = document['zjcs']
  968. def process(n):
  969. n['计算基数'] = str(sum)
  970. n['金额'] = float(sum) * float(n['费率']) / float(100)
  971. if "__children" in n:
  972. for entry in n['__children']:
  973. entry['计算基数'] = str(sum)
  974. entry['金额'] = float(sum) * float(entry['费率']) / float(100)
  975. return n
  976. result = [process(item) for item in zjcs]
  977. for entry in result:
  978. if '安全文明施工' in entry['名称']:
  979. sum_ = 0
  980. for child in entry['__children']:
  981. sum_ = sum_ + float(child['金额'])
  982. entry['金额'] = str(sum_)
  983. entry['计算基数'] = str(sum_)
  984. zjcs_sum = 0
  985. for entry in result:
  986. zjcs_sum = zjcs_sum + float(entry['金额'])
  987. qtxm = document['qtxm']
  988. qtxm_sum = 0
  989. for entry in qtxm:
  990. qtxm_sum = qtxm_sum + float(entry['金额'])
  991. gfsj = document['gfsj']
  992. gf_sum = 0
  993. sj_sum = 0
  994. for item in gfsj:
  995. if item['名称'] == '规费':
  996. child = item['__children']
  997. for children in child:
  998. children['取费基数'] = str(sum + zjcs_sum + qtxm_sum)
  999. children['金额'] = str(float(sum + zjcs_sum + qtxm_sum) * float(children['费率']) / float(100))
  1000. gf_sum = gf_sum + float(children['金额'])
  1001. for item in gfsj:
  1002. if item['名称'] == '规费':
  1003. item['取费基数'] = str(gf_sum)
  1004. item['金额'] = str(gf_sum)
  1005. for item in gfsj:
  1006. if item['名称'] == '税金':
  1007. item['取费基数'] = str(sum + zjcs_sum + qtxm_sum + gf_sum)
  1008. item['金额'] = float(item['取费基数']) * float(item['费率']) / float(100)
  1009. sj_sum = float(item['金额'])
  1010. for item in gfsj:
  1011. if item['名称'] == '合计':
  1012. item['取费基数'] = str(sj_sum + gf_sum)
  1013. item['金额'] = item['取费基数']
  1014. qtxm = document['qtxm']
  1015. zlje = 0
  1016. zygczgj = 0
  1017. jrg = 0
  1018. zcbfwf = 0
  1019. clzgj = 0
  1020. for entry in qtxm:
  1021. if entry['序号'] == '1':
  1022. zlje = entry['金额']
  1023. if entry['序号'] == '3':
  1024. jrg = entry['金额']
  1025. if entry['序号'] == '4':
  1026. zcbfwf = entry['金额']
  1027. if entry['序号'] == '2':
  1028. for child in entry['__children']:
  1029. if child['序号'] == '2.2':
  1030. zygczgj = child['金额']
  1031. if child['序号'] == '2.1':
  1032. clzgj = child['金额']
  1033. qtxm_sum = zlje + zygczgj + jrg + zcbfwf + clzgj
  1034. bjhz = bjhz_template()
  1035. for entry in bjhz:
  1036. if entry['序号'] == '1':
  1037. entry['金额'] = qd_sum
  1038. for child in entry['__children']:
  1039. if child['序号'] == '1.1':
  1040. child['金额'] = str(rgf_sum)
  1041. if child['序号'] == '1.2':
  1042. child['金额'] = str(clf_sum)
  1043. if child['序号'] == '1.3':
  1044. child['金额'] = str(jxf_sum)
  1045. if child['序号'] == '1.4':
  1046. child['金额'] = str(glf_sum)
  1047. if child['序号'] == '1.5':
  1048. child['金额'] = str(lr_sum)
  1049. if entry['序号'] == '2':
  1050. entry['金额'] = str(djcs_sum + zjcs_sum)
  1051. for child in entry['__children']:
  1052. if child['序号'] == '2.1':
  1053. child['金额'] = str(djcs_sum)
  1054. if child['序号'] == '2.2':
  1055. child['金额'] = str(zjcs_sum)
  1056. for grandchild in child['__children']:
  1057. if grandchild['序号'] == '2.2.1':
  1058. grandchild['金额'] = str(sum_)
  1059. if entry['序号'] == '3':
  1060. entry['金额'] = str(qtxm_sum)
  1061. if entry['序号'] == '4':
  1062. entry['金额'] = str(gf_sum)
  1063. if entry['序号'] == '5':
  1064. entry['金额'] = str(sj_sum)
  1065. if entry['序号'] == '6':
  1066. entry['金额'] = str(float(qd_sum) + float(djcs_sum) + float(zjcs_sum) + float(qtxm_sum) + float(gf_sum) + float(sj_sum))
  1067. await collection.update_one({'biao_id': biao_id, "Dwgcbh": bh}, {'$set': {'zjcs': result, 'gfsj' : gfsj, 'bjhz': bjhz}})