db.py 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191
  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. async def zongjiaDwgc(client, biao_id, bh):
  920. db = client["baojia"]
  921. collection = db["qdxm"]
  922. sum = 0
  923. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  924. sum = sum + float(post['合价'])
  925. collection = db["Djcs"]
  926. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  927. sum = sum + float(post['合价'])
  928. collection = db['Dwgc']
  929. document = await collection.find_one({'biao_id': biao_id, "Dwgcbh": bh}, {'rcjhz': 0})
  930. zjcs = document['zjcs']
  931. def process(n):
  932. n['计算基数'] = str(sum)
  933. n['金额'] = float(sum) * float(n['费率']) / float(100)
  934. if "__children" in n:
  935. for entry in n['__children']:
  936. entry['计算基数'] = str(sum)
  937. entry['金额'] = float(sum) * float(entry['费率']) / float(100)
  938. return n
  939. result = [process(item) for item in zjcs]
  940. for entry in result:
  941. if '安全文明施工' in entry['名称']:
  942. sum_ = 0
  943. for child in entry['__children']:
  944. sum_ = sum_ + float(child['金额'])
  945. entry['金额'] = str(sum_)
  946. entry['计算基数'] = str(sum_)
  947. zjcs_sum = 0
  948. for entry in result:
  949. zjcs_sum = zjcs_sum + float(entry['金额'])
  950. qtxm = document['qtxm']
  951. qtxm_sum = 0
  952. for entry in qtxm:
  953. qtxm_sum = qtxm_sum + float(entry['金额'])
  954. gfsj = document['gfsj']
  955. gf_sum = 0
  956. sj_sum = 0
  957. for item in gfsj:
  958. if item['名称'] == '规费':
  959. child = item['__children']
  960. for children in child:
  961. children['取费基数'] = str(sum + zjcs_sum + qtxm_sum)
  962. children['金额'] = str(float(sum + zjcs_sum + qtxm_sum) * float(children['费率']) / float(100))
  963. gf_sum = gf_sum + float(children['金额'])
  964. for item in gfsj:
  965. if item['名称'] == '规费':
  966. item['取费基数'] = str(gf_sum)
  967. item['金额'] = str(gf_sum)
  968. for item in gfsj:
  969. if item['名称'] == '税金':
  970. item['取费基数'] = str(sum + zjcs_sum + qtxm_sum + gf_sum)
  971. item['金额'] = float(item['取费基数']) * float(item['费率']) / float(100)
  972. sj_sum = float(item['金额'])
  973. for item in gfsj:
  974. if item['名称'] == '合计':
  975. item['取费基数'] = str(sj_sum + gf_sum)
  976. item['金额'] = item['取费基数']
  977. await collection.update_one({'biao_id': biao_id, "Dwgcbh": bh}, {'$set': {'zjcs': result, 'gfsj' : gfsj}})