db.py 83 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056
  1. import xml.etree.ElementTree as ET
  2. from subdir import service, util
  3. from bson.objectid import ObjectId
  4. import uuid
  5. from datetime import datetime
  6. ###############helper##################
  7. def getDingercj_default(root, bh, bt, qdbm, debm):
  8. result = [["ID", "人材机编码", "名称", "规格型号", "单位", "单价", "产地",
  9. "供应厂商", "人材机类别", "甲供标志", "含量", "合价", "暂估价标志", "主要材料标志", "主材标志", "设备标志" ]]
  10. #result.append(["ming cheng", "jin e", "zan gu jia", "anquan wenming fei", "guifei"])
  11. item = None
  12. for child in root:
  13. if child.tag == "Dxgcxx":
  14. for child1 in child:
  15. Dwgcbh = child1.attrib["Dwgcbh"]
  16. if Dwgcbh == bh:
  17. item = child1
  18. break
  19. ##result.append([child.attrib["Dxgcmc"], child.attrib["Je"], child.attrib["Zgj"], child.attrib["Aqwmf"], child.attrib["Gf"]])
  20. Fywj = None
  21. for child in item:
  22. if child.tag == 'Qdxm':
  23. Fywj= child
  24. break
  25. Rcjhz = None
  26. for child in item:
  27. if child.tag == 'Rcjhz':
  28. Rcjhz = child
  29. break
  30. kv = {}
  31. for entry in Rcjhz:
  32. kv[entry.attrib["RcjId"]]=entry
  33. container = None
  34. for child in Fywj:
  35. ##child is mx
  36. if child.tag == "Qdmx" and child.attrib["Qdbm"] == qdbm:
  37. zimu = child
  38. break
  39. box = None
  40. if not zimu:
  41. return result
  42. for child in zimu:
  43. if child.tag == "Qdxdezj":
  44. box = child
  45. break
  46. hlmx_parent = None
  47. for child in box:
  48. if child.attrib["Debm"] == debm:
  49. for grandchild in child:
  50. if grandchild.tag == "Qdxdercjhl":
  51. hlmx_parent = grandchild
  52. for child in hlmx_parent:
  53. result.append([child.attrib["RcjId"],
  54. kv[child.attrib["RcjId"]].attrib["RcjBm"],
  55. kv[child.attrib["RcjId"]].attrib["Mc"],
  56. kv[child.attrib["RcjId"]].attrib["Ggxh"],
  57. kv[child.attrib["RcjId"]].attrib["Dw"],
  58. kv[child.attrib["RcjId"]].attrib["Dj"],
  59. kv[child.attrib["RcjId"]].attrib["Cd"],
  60. kv[child.attrib["RcjId"]].attrib["Gycs"],
  61. kv[child.attrib["RcjId"]].attrib["Rcjlb"],
  62. kv[child.attrib["RcjId"]].attrib["Jgbz"],
  63. child.attrib["Rcjhl"], child.attrib["Rcjhj"], "",
  64. "", "", ""
  65. ])
  66. return result
  67. def getDingercj_(root, bh, bt, qdbm, debm):
  68. if bt == 'Default':
  69. return getDingercj_default(root, bh, bt, qdbm, debm)
  70. result = [["ID", "人材机编码", "名称", "规格型号", "单位", "单价", "产地",
  71. "供应厂商", "人材机类别", "甲供标志", "含量", "合价", "暂估价标志", "主要材料标志", "主材标志", "设备标志" ]]
  72. #result.append(["ming cheng", "jin e", "zan gu jia", "anquan wenming fei", "guifei"])
  73. item = None
  74. for child in root:
  75. if child.tag == "Dxgcxx":
  76. for child1 in child:
  77. Dwgcbh = child1.attrib["Dwgcbh"]
  78. if Dwgcbh == bh:
  79. item = child1
  80. break
  81. ##result.append([child.attrib["Dxgcmc"], child.attrib["Je"], child.attrib["Zgj"], child.attrib["Aqwmf"], child.attrib["Gf"]])
  82. Fywj = None
  83. for child in item:
  84. if child.tag == 'Qdxm':
  85. Fywj= child
  86. break
  87. Rcjhz = None
  88. for child in item:
  89. if child.tag == 'Rcjhz':
  90. Rcjhz = child
  91. break
  92. kv = {}
  93. for entry in Rcjhz:
  94. kv[entry.attrib["RcjId"]]=entry
  95. container = None
  96. for child in Fywj:
  97. ##child is mx
  98. if child.tag == "QdBt":
  99. if child.attrib["Mc"] == bt:
  100. count = 0
  101. for grandchild in child:
  102. count = count + 1
  103. if count > 0:
  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"] == qdbm:
  111. zimu = child
  112. break
  113. box = None
  114. if not zimu:
  115. return result
  116. for child in zimu:
  117. if child.tag == "Qdxdezj":
  118. box = child
  119. break
  120. hlmx_parent = None
  121. for child in box:
  122. if child.attrib["Debm"] == debm:
  123. for grandchild in child:
  124. if grandchild.tag == "Qdxdercjhl":
  125. hlmx_parent = grandchild
  126. for child in hlmx_parent:
  127. result.append([child.attrib["RcjId"],
  128. kv[child.attrib["RcjId"]].attrib["RcjBm"],
  129. kv[child.attrib["RcjId"]].attrib["Mc"],
  130. kv[child.attrib["RcjId"]].attrib["Ggxh"],
  131. kv[child.attrib["RcjId"]].attrib["Dw"],
  132. kv[child.attrib["RcjId"]].attrib["Dj"],
  133. kv[child.attrib["RcjId"]].attrib["Cd"],
  134. kv[child.attrib["RcjId"]].attrib["Gycs"],
  135. kv[child.attrib["RcjId"]].attrib["Rcjlb"],
  136. kv[child.attrib["RcjId"]].attrib["Jgbz"],
  137. child.attrib["Rcjhl"], child.attrib["Rcjhj"], "",
  138. "", "", ""
  139. ])
  140. return result
  141. def getQingdanrcj_default(root, bh, bt, bm):
  142. result = [["ID", "人材机编码", "名称", "规格型号", "单位", "单价", "产地",
  143. "供应厂商", "人材机类别", "甲供标志", "含量", "合价", "暂估价标志", "主要材料标志", "主材标志", "设备标志" ]]
  144. #result.append(["ming cheng", "jin e", "zan gu jia", "anquan wenming fei", "guifei"])
  145. item = None
  146. for child in root:
  147. if child.tag == "Dxgcxx":
  148. for child1 in child:
  149. Dwgcbh = child1.attrib["Dwgcbh"]
  150. if Dwgcbh == bh:
  151. item = child1
  152. break
  153. ##result.append([child.attrib["Dxgcmc"], child.attrib["Je"], child.attrib["Zgj"], child.attrib["Aqwmf"], child.attrib["Gf"]])
  154. Fywj = None
  155. for child in item:
  156. if child.tag == 'Qdxm':
  157. Fywj= child
  158. break
  159. Rcjhz = None
  160. for child in item:
  161. if child.tag == 'Rcjhz':
  162. Rcjhz = child
  163. break
  164. kv = {}
  165. for entry in Rcjhz:
  166. kv[entry.attrib["RcjId"]]=entry
  167. container = None
  168. for child in Fywj:
  169. ##child is mx
  170. if child.tag == "Qdmx" and child.attrib["Qdbm"] == bm:
  171. zimu = child
  172. break
  173. box = None
  174. if not zimu:
  175. return result
  176. for child in zimu:
  177. if child.tag == "Qdxrcjhl":
  178. box = child
  179. break
  180. for child in box:
  181. result.append([child.attrib["RcjId"],
  182. kv[child.attrib["RcjId"]].attrib["RcjBm"],
  183. kv[child.attrib["RcjId"]].attrib["Mc"],
  184. kv[child.attrib["RcjId"]].attrib["Ggxh"],
  185. kv[child.attrib["RcjId"]].attrib["Dw"],
  186. kv[child.attrib["RcjId"]].attrib["Dj"],
  187. kv[child.attrib["RcjId"]].attrib["Cd"],
  188. kv[child.attrib["RcjId"]].attrib["Gycs"],
  189. kv[child.attrib["RcjId"]].attrib["Rcjlb"],
  190. kv[child.attrib["RcjId"]].attrib["Jgbz"],
  191. child.attrib["Rcjhl"], child.attrib["Rcjhj"], child.attrib["Zgjbz"],
  192. child.attrib["Zyclbz"], child.attrib["Zcbz"], child.attrib["Sbbz"]
  193. ])
  194. return result
  195. def getQingdanrcj_(root, bh, bt, bm):
  196. if bt == 'Default':
  197. return getQingdanrcj_default(root, bh, bt, bm)
  198. result = [["ID", "人材机编码", "名称", "规格型号", "单位", "单价", "产地",
  199. "供应厂商", "人材机类别", "甲供标志", "含量", "合价", "暂估价标志", "主要材料标志", "主材标志", "设备标志" ]]
  200. #result.append(["ming cheng", "jin e", "zan gu jia", "anquan wenming fei", "guifei"])
  201. item = None
  202. for child in root:
  203. if child.tag == "Dxgcxx":
  204. for child1 in child:
  205. Dwgcbh = child1.attrib["Dwgcbh"]
  206. if Dwgcbh == bh:
  207. item = child1
  208. break
  209. ##result.append([child.attrib["Dxgcmc"], child.attrib["Je"], child.attrib["Zgj"], child.attrib["Aqwmf"], child.attrib["Gf"]])
  210. Fywj = None
  211. for child in item:
  212. if child.tag == 'Qdxm':
  213. Fywj= child
  214. break
  215. Rcjhz = None
  216. for child in item:
  217. if child.tag == 'Rcjhz':
  218. Rcjhz = child
  219. break
  220. kv = {}
  221. for entry in Rcjhz:
  222. kv[entry.attrib["RcjId"]]=entry
  223. container = None
  224. for child in Fywj:
  225. ##child is mx
  226. if child.tag == "QdBt":
  227. if child.attrib["Mc"] == bt:
  228. count = 0
  229. for grandchild in child:
  230. count = count +1
  231. if count > 0:
  232. container = child
  233. break
  234. if container == None:
  235. container = Fywj
  236. zimu = None
  237. for child in container:
  238. if child.attrib["Qdbm"] == bm:
  239. zimu = child
  240. break
  241. box = None
  242. if not zimu:
  243. return result
  244. for child in zimu:
  245. if child.tag == "Qdxrcjhl":
  246. box = child
  247. break
  248. for child in box:
  249. result.append([child.attrib["RcjId"],
  250. kv[child.attrib["RcjId"]].attrib["RcjBm"],
  251. kv[child.attrib["RcjId"]].attrib["Mc"],
  252. kv[child.attrib["RcjId"]].attrib["Ggxh"],
  253. kv[child.attrib["RcjId"]].attrib["Dw"],
  254. kv[child.attrib["RcjId"]].attrib["Dj"],
  255. kv[child.attrib["RcjId"]].attrib["Cd"],
  256. kv[child.attrib["RcjId"]].attrib["Gycs"],
  257. kv[child.attrib["RcjId"]].attrib["Rcjlb"],
  258. kv[child.attrib["RcjId"]].attrib["Jgbz"],
  259. child.attrib["Rcjhl"], child.attrib["Rcjhj"], child.attrib["Zgjbz"],
  260. child.attrib["Zyclbz"], child.attrib["Zcbz"], child.attrib["Sbbz"]
  261. ])
  262. return result
  263. def getDjcsDingercj_(root, bh, bt, qdbm, debm):
  264. result = [["ID", "人材机编码", "名称", "规格型号", "单位", "单价", "产地",
  265. "供应厂商", "人材机类别", "甲供标志", "含量", "合价", "暂估价标志", "主要材料标志", "主材标志", "设备标志" ]]
  266. #result.append(["ming cheng", "jin e", "zan gu jia", "anquan wenming fei", "guifei"])
  267. item = None
  268. for child in root:
  269. if child.tag == "Dxgcxx":
  270. for child1 in child:
  271. Dwgcbh = child1.attrib["Dwgcbh"]
  272. if Dwgcbh == bh:
  273. item = child1
  274. break
  275. ##result.append([child.attrib["Dxgcmc"], child.attrib["Je"], child.attrib["Zgj"], child.attrib["Aqwmf"], child.attrib["Gf"]])
  276. Fywj = None
  277. for child in item:
  278. if child.tag == 'Csxm':
  279. Fywj= child
  280. break
  281. Rcjhz = None
  282. for child in item:
  283. if child.tag == 'Rcjhz':
  284. Rcjhz = child
  285. break
  286. kv = {}
  287. for entry in Rcjhz:
  288. kv[entry.attrib["RcjId"]]=entry
  289. container = None
  290. for child in Fywj:
  291. if child.tag == "DjCs":
  292. container = child
  293. break
  294. zimu = None
  295. for child in container:
  296. if child.attrib["Bm"] == qdbm:
  297. zimu = child
  298. break
  299. box = None
  300. if not zimu:
  301. return result
  302. for child in zimu:
  303. if child.tag == "Csxdezj":
  304. box = child
  305. break
  306. hlmx_parent = None
  307. for child in box:
  308. if child.attrib["Debm"] == debm:
  309. for grandchild in child:
  310. if grandchild.tag == "Csxdercjhl":
  311. hlmx_parent = grandchild
  312. for child in hlmx_parent:
  313. result.append([child.attrib["RcjId"],
  314. kv[child.attrib["RcjId"]].attrib["RcjBm"],
  315. kv[child.attrib["RcjId"]].attrib["Mc"],
  316. kv[child.attrib["RcjId"]].attrib["Ggxh"],
  317. kv[child.attrib["RcjId"]].attrib["Dw"],
  318. kv[child.attrib["RcjId"]].attrib["Dj"],
  319. kv[child.attrib["RcjId"]].attrib["Cd"],
  320. kv[child.attrib["RcjId"]].attrib["Gycs"],
  321. kv[child.attrib["RcjId"]].attrib["Rcjlb"],
  322. kv[child.attrib["RcjId"]].attrib["Jgbz"],
  323. child.attrib["Rcjhl"], child.attrib["Rcjhj"], "",
  324. "", "", ""
  325. ])
  326. return result
  327. def getDjcsQingdanrcj_(root, bh, bt, bm):
  328. result = [["ID", "人材机编码", "名称", "规格型号", "单位", "单价", "产地",
  329. "供应厂商", "人材机类别", "甲供标志", "含量", "合价", "暂估价标志", "主要材料标志", "主材标志", "设备标志" ]]
  330. #result.append(["ming cheng", "jin e", "zan gu jia", "anquan wenming fei", "guifei"])
  331. item = None
  332. for child in root:
  333. if child.tag == "Dxgcxx":
  334. for child1 in child:
  335. Dwgcbh = child1.attrib["Dwgcbh"]
  336. if Dwgcbh == bh:
  337. item = child1
  338. break
  339. ##result.append([child.attrib["Dxgcmc"], child.attrib["Je"], child.attrib["Zgj"], child.attrib["Aqwmf"], child.attrib["Gf"]])
  340. Fywj = None
  341. for child in item:
  342. if child.tag == 'Csxm':
  343. Fywj= child
  344. break
  345. hl_parent = None
  346. for child in Fywj:
  347. if child.tag == "DjCs":
  348. hl_parent = child
  349. Rcjhz = None
  350. for child in item:
  351. if child.tag == 'Rcjhz':
  352. Rcjhz = child
  353. break
  354. kv = {}
  355. for entry in Rcjhz:
  356. kv[entry.attrib["RcjId"]]=entry
  357. zimu = None
  358. for child in hl_parent:
  359. if child.attrib["Bm"] == bm:
  360. zimu = child
  361. break
  362. box = None
  363. if not zimu:
  364. return result
  365. for child in zimu:
  366. if child.tag == "Csxrcjhl":
  367. box = child
  368. break
  369. for child in box:
  370. result.append([child.attrib["RcjId"],
  371. kv[child.attrib["RcjId"]].attrib["RcjBm"],
  372. kv[child.attrib["RcjId"]].attrib["Mc"],
  373. kv[child.attrib["RcjId"]].attrib["Ggxh"],
  374. kv[child.attrib["RcjId"]].attrib["Dw"],
  375. kv[child.attrib["RcjId"]].attrib["Dj"],
  376. kv[child.attrib["RcjId"]].attrib["Cd"],
  377. kv[child.attrib["RcjId"]].attrib["Gycs"],
  378. kv[child.attrib["RcjId"]].attrib["Rcjlb"],
  379. kv[child.attrib["RcjId"]].attrib["Jgbz"],
  380. child.attrib["Rcjhl"], child.attrib["Rcjhj"], child.attrib["Zgjbz"],
  381. child.attrib["Zyclbz"], child.attrib["Zcbz"], child.attrib["Sbbz"]
  382. ])
  383. return result
  384. ######################end of helper ########################
  385. async def resolve(data, client):
  386. root = ET.fromstring(data)
  387. print(root)
  388. Dwgcbh = []
  389. jingjibiao = {}
  390. jingjibiao['visible'] = False
  391. jingjibiao['created'] = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
  392. jingjibiao["BiaoDuanNO"] = root.attrib["BiaoDuanNO"]
  393. jingjibiao["Jsfs"] = root.attrib["Jsfs"]
  394. jingjibiao["Version"] = root.attrib["Version"]
  395. jingjibiao["Xmmc"] = root.attrib["Xmmc"]
  396. jingjibiao["Dxgcxx"] = []
  397. for child in root:
  398. if child.tag == "ZhaoBiaoXx":
  399. jingjibiao["ZhaoBiaoXx"] = {}
  400. jingjibiao["ZhaoBiaoXx"]["BzTime"] = child.attrib["BzTime"]
  401. jingjibiao["ZhaoBiaoXx"]["Bzr"] = child.attrib["Bzr"]
  402. jingjibiao["ZhaoBiaoXx"]["FhTime"] = child.attrib["FhTime"]
  403. jingjibiao["ZhaoBiaoXx"]["Fhr"] = child.attrib["Fhr"]
  404. jingjibiao["ZhaoBiaoXx"]["Zbr"] = child.attrib["Zbr"]
  405. jingjibiao["ZhaoBiaoXx"]["ZbrDb"] = child.attrib["ZbrDb"]
  406. jingjibiao["ZhaoBiaoXx"]["Zxr"] = child.attrib["Zxr"]
  407. jingjibiao["ZhaoBiaoXx"]["ZxrDb"] = child.attrib["ZxrDb"]
  408. elif child.tag == "TouBiaoXx":
  409. jingjibiao["TouBiaoXx"] = {}
  410. jingjibiao["TouBiaoXx"]["Zbr"] = child.attrib["Zbr"]
  411. jingjibiao["TouBiaoXx"]["Tbr"] = child.attrib["Tbr"]
  412. jingjibiao["TouBiaoXx"]["TbrDb"] = child.attrib["TbrDb"]
  413. jingjibiao["TouBiaoXx"]["Bzr"] = child.attrib["Bzr"]
  414. jingjibiao["TouBiaoXx"]["BzTime"] = child.attrib["BzTime"]
  415. jingjibiao["TouBiaoXx"]["Tbzj"] = child.attrib["Tbzj"]
  416. jingjibiao["TouBiaoXx"]["Zgj"] = child.attrib["Zgj"]
  417. jingjibiao["TouBiaoXx"]["Aqwmf"] = child.attrib["Aqwmf"]
  418. jingjibiao["TouBiaoXx"]["Gf"] = child.attrib["Gf"]
  419. elif child.tag == "Dxgcxx":
  420. Dxgcxx = {}
  421. Dxgcxx["Aqwmf"] = child.attrib["Aqwmf"]
  422. Dxgcxx["Dxgcbh"] = child.attrib["Dxgcbh"]
  423. Dxgcxx["Dxgcmc"] = child.attrib["Dxgcmc"]
  424. Dxgcxx["Gf"] = child.attrib["Gf"]
  425. Dxgcxx["Je"] = child.attrib["Je"]
  426. Dxgcxx["Zgj"] = child.attrib["Zgj"]
  427. Dxgcxx["Dwgc"] = []
  428. for grandchild in child:
  429. if grandchild.tag == "Dwgcxx":
  430. Dwgcxx = {}
  431. Dwgcxx["DogNum"] = grandchild.attrib["DogNum"]
  432. Dwgcxx["Dwgcbh"] = grandchild.attrib["Dwgcbh"]
  433. Dwgcbh.append({"bh": grandchild.attrib["Dwgcbh"], "num": grandchild.attrib["DogNum"]})
  434. Dwgcxx["Dwgcmc"] = grandchild.attrib["Dwgcmc"]
  435. Dwgcxx["MachineKey"] = grandchild.attrib["MachineKey"]
  436. Dwgcxx["SoftName"] = grandchild.attrib["SoftName"]
  437. Dwgcxx["SoftNum"] = grandchild.attrib["SoftNum"]
  438. Dwgcxx["Zylb"] = grandchild.attrib["Zylb"]
  439. Dxgcxx["Dwgc"].append(Dwgcxx)
  440. jingjibiao["Dxgcxx"].append(Dxgcxx)
  441. if not 'TouBiaoXx' in jingjibiao:
  442. jingjibiao['TouBiaoXx'] = {'Tbzj' : '', 'Zgj' : '', 'Aqwmf' : '', 'Gf' : '' }
  443. db = client["baojia"]
  444. collection = db["jingjibiao"]
  445. biao_id = (await collection.insert_one(jingjibiao)).inserted_id
  446. biao_id = str(biao_id)
  447. collection = db["Dwgc"]
  448. for entry in Dwgcbh:
  449. bjhz = service.getBjhz(root, entry["bh"])###array which contains __children
  450. gfsj = service.getGfsj(root, entry["bh"])##array which contains __children
  451. qtxm = service.getQtxm(root, entry["bh"])##array which contains __children
  452. zlje = service.getZlje(root, entry["bh"])
  453. jrg = service.getJrg(root, entry["bh"])
  454. zcbfwf = service.getZcbfwf(root, entry["bh"])
  455. fbrgycl = service.getFbrgycl(root, entry["bh"])
  456. rcjhz = service.getRcjhz(root, entry["bh"])
  457. zjcs = service.getZjcs(root, entry["bh"])
  458. qdbt = service.getQdxm(root, entry["bh"])
  459. qdbt_addition = service.getQdxm_addition(root, entry["bh"])
  460. zygczgj = service.getZygczgj(root, entry["bh"])
  461. Dwgc = {}
  462. Dwgc["bjhz"] = bjhz
  463. Dwgc["gfsj"] = gfsj
  464. Dwgc["qtxm"] = qtxm
  465. Dwgc["zlje"] = zlje
  466. Dwgc["jrg"] = jrg
  467. Dwgc['zygczgj'] = zygczgj
  468. Dwgc["zcbfwf"] = zcbfwf
  469. Dwgc["fbrgycl"] = fbrgycl
  470. Dwgc["rcjhz"] = rcjhz
  471. Dwgc["zjcs"] = zjcs
  472. Dwgc["qdbt"] = qdbt
  473. Dwgc['qdbt_addition'] = qdbt_addition
  474. Dwgc["DogNum"] = entry["num"]
  475. Dwgc["Dwgcbh"] = entry["bh"]
  476. Dwgc["biao_id"] = biao_id
  477. await collection.insert_one(Dwgc)
  478. collection = db["Djcs"]
  479. for entry in Dwgcbh:
  480. djcs = service.getDjcs(root, entry["bh"])
  481. for cs in djcs:
  482. cs["DogNum"] = entry["num"]
  483. cs["Dwgcbh"] = entry["bh"]
  484. cs["biao_id"] = biao_id
  485. rcj = getDjcsQingdanrcj_(root, entry["bh"], "", cs['清单编码'])
  486. cs["rcj"] = rcj
  487. if "__children" in cs:
  488. children = cs["__children"]
  489. for child in children:
  490. dercj = getDjcsDingercj_(root, entry["bh"], "", cs["清单编码"], child["清单编码"])
  491. child["dercj"] = dercj
  492. child['fuzhuEnable'] = False
  493. await collection.insert_one(cs)
  494. collection = db["qdxm"]
  495. for entry in Dwgcbh:
  496. bts = service.getQdxm(root, entry["bh"])
  497. for bt in bts:
  498. if bt == 'Default':
  499. qdmx = service.getQdmx_default(root, entry["bh"], bt)
  500. else:
  501. qdmx = service.getQdmx(root, entry["bh"], bt)
  502. for qd in qdmx:
  503. qd["DogNum"] = entry["num"]
  504. qd["Dwgcbh"] = entry["bh"]
  505. qd["biao_id"] = biao_id
  506. qd["bt"] = bt
  507. rcj = getQingdanrcj_(root, entry["bh"], bt, qd["清单编码"])
  508. qd["rcj"] = rcj
  509. if "__children" in qd:
  510. children = qd["__children"]
  511. for child in children:
  512. dercj = getDingercj_(root, entry["bh"], bt, qd["清单编码"], child["清单编码"])
  513. child["dercj"] = dercj
  514. child['fuzhuEnable'] = False
  515. await collection.insert_one(qd)
  516. collection = db["qufei"]
  517. document = jingjibiao
  518. dxgc = document['Dxgcxx']
  519. result = []
  520. for entry in dxgc:
  521. newone = {"名称" : entry['Dxgcmc'], "工程类型":"", "工程类别": "", "管理费(%)": "", "利润(%)": "","备注":"", "key" : str(uuid.uuid4()) }
  522. children = []
  523. for dwgc in entry['Dwgc']:
  524. children.append({"名称" : dwgc['Dwgcmc'], "工程类型":"", "工程类别": "", "管理费(%)": "", "利润(%)": "","备注":"", "key" : dwgc['Dwgcbh']})
  525. newone["children"] = children
  526. result.append(newone)
  527. await collection.insert_one({"biao_id": biao_id, "qufei": [{
  528. "名称" : document['Xmmc'], "工程类型":"", "工程类别": "", "管理费(%)": "", "利润(%)": "","备注":"", "key" : str(uuid.uuid4()), "children" : result
  529. }]})
  530. collection = db["jingjibiao"]
  531. await collection.update_one({'_id': ObjectId(biao_id)}, {'$set': {'visible': True}})
  532. def dfs(items):
  533. result = []
  534. for entry in items:
  535. result.append([entry['序号'], entry['名称'], entry['金额'], entry['暂估价'], entry['类别']])
  536. if '__children' in entry:
  537. result_ = dfs(entry['__children'])
  538. for r in result_:
  539. result.append(r)
  540. return result
  541. def dfs2(items):
  542. result = []
  543. for entry in items:
  544. result.append([entry['序号'], entry['名称'], entry['取费基数'], entry['计算基础'], entry['费率'], entry['金额'], entry['类别']])
  545. if '__children' in entry:
  546. result_ = dfs2(entry['__children'])
  547. for r in result_:
  548. result.append(r)
  549. return result
  550. def dfs3(items):
  551. result = []
  552. for entry in items:
  553. result.append([entry['序号'], entry['名称'], entry['金额'], entry['项目类别'], entry['备注']])
  554. if '__children' in entry:
  555. result_ = dfs3(entry['__children'])
  556. for r in result_:
  557. result.append(r)
  558. return result
  559. def roundstr(input):
  560. a = float(input)
  561. b = round(a, 2)
  562. return str(b)
  563. def roundstr4(input):
  564. a = float(input)
  565. b = round(a, 4)
  566. return str(b)
  567. async def build(client, root, id):
  568. db = client["baojia"]
  569. collection = db["jingjibiao"]
  570. document = await collection.find_one({'_id': ObjectId(id)})
  571. root.set('BiaoDuanNO', document['BiaoDuanNO'])
  572. root.set('Jsfs', document['Jsfs'])
  573. root.set('Version', document['Version'])
  574. root.set('Xmmc', document['Xmmc'])
  575. TouBiaoXx = ET.SubElement(root, 'TouBiaoXx')
  576. ##{'Tbzj' : '', 'Zgj' : '', 'Aqwmf' : '', 'Gf' : '' }
  577. TouBiaoXx.set('Tbzj', roundstr(document['TouBiaoXx']['Tbzj']))
  578. TouBiaoXx.set('Zgj', roundstr(document['TouBiaoXx']['Zgj']))
  579. TouBiaoXx.set('Aqwmf', roundstr(document['TouBiaoXx']['Aqwmf']))
  580. TouBiaoXx.set('Gf', roundstr(document['TouBiaoXx']['Gf']))
  581. if 'Zbr' in document['TouBiaoXx']:
  582. TouBiaoXx.set('Zbr', str(document['TouBiaoXx']['Zbr']))
  583. if 'Tbr' in document['TouBiaoXx']:
  584. TouBiaoXx.set('Tbr', str(document['TouBiaoXx']['Tbr']))
  585. if 'TbrDb' in document['TouBiaoXx']:
  586. TouBiaoXx.set('TbrDb', str(document['TouBiaoXx']['TbrDb']))
  587. if 'Bzr' in document['TouBiaoXx']:
  588. TouBiaoXx.set('Bzr', str(document['TouBiaoXx']['Bzr']))
  589. if 'BzTime' in document['TouBiaoXx']:
  590. TouBiaoXx.set('BzTime', str(document['TouBiaoXx']['BzTime']))
  591. for item in document['Dxgcxx']:
  592. Dxgcxx = ET.SubElement(root, 'Dxgcxx')
  593. Dxgcxx.set('Dxgcbh', str(item['Dxgcbh']))
  594. Dxgcxx.set('Dxgcmc', str(item['Dxgcmc']))
  595. Dxgcxx.set('Je', roundstr(item['Je']))
  596. Dxgcxx.set('Zgj', roundstr(item['Zgj']))
  597. Dxgcxx.set('Aqwmf', roundstr(item['Aqwmf']))
  598. Dxgcxx.set('Gf', roundstr(item['Gf']))
  599. for entry in item['Dwgc']:
  600. Dwgcxx = ET.SubElement(Dxgcxx, 'Dwgcxx')
  601. Dwgcxx.set('Dwgcbh', str(entry['Dwgcbh']))
  602. Dwgcxx.set('Dwgcmc', str(entry['Dwgcmc']))
  603. Dwgcxx.set('Zylb', str(entry['Zylb']))
  604. Dwgcxx.set('SoftName', str(entry['SoftName']))
  605. Dwgcxx.set('SoftNum', str(entry['SoftNum']))
  606. Dwgcxx.set('DogNum', str(entry['DogNum']))
  607. Dwgcxx.set('MachineKey', str(entry['MachineKey']))
  608. collection = db["Dwgc"]
  609. Dwgc = await collection.find_one({'biao_id': id, "Dwgcbh": entry['Dwgcbh']})
  610. bjhz = dfs(Dwgc['bjhz'])
  611. gfsj = dfs2(Dwgc['gfsj'])
  612. qtxm = dfs3(Dwgc['qtxm'])
  613. zlje = Dwgc['zlje']
  614. zygczgj = Dwgc['zygczgj']
  615. jrg = Dwgc['jrg']
  616. zcbfwf = Dwgc['zcbfwf']
  617. fbrgycl = Dwgc['fbrgycl']
  618. rcjhz = Dwgc['rcjhz']
  619. zjcs = Dwgc['zjcs']
  620. qdbt = Dwgc['qdbt']
  621. ########################################Fywj##########################
  622. Fywj = ET.SubElement(Dwgcxx, 'Fywj')
  623. for bjhz_ in bjhz:
  624. FywjMx = ET.SubElement(Fywj, 'FywjMx')
  625. FywjMx.set('Xh', str(bjhz_[0]))
  626. FywjMx.set('Mc', str(bjhz_[1]))
  627. FywjMx.set('Je', roundstr(bjhz_[2]))
  628. FywjMx.set('Zgj', roundstr(bjhz_[3]))
  629. FywjMx.set('Fyxlb', str(bjhz_[4]))
  630. ########################################Gfsj##########################
  631. Gfsj = ET.SubElement(Dwgcxx, 'Gfsj')
  632. for gfsj_ in gfsj:
  633. GfsjMx = ET.SubElement(Gfsj, 'GfsjMx')
  634. GfsjMx.set('Xh', str(gfsj_[0]))
  635. GfsjMx.set('Mc', str(gfsj_[1]))
  636. GfsjMx.set('Qfjs', roundstr(gfsj_[2]))
  637. GfsjMx.set('Jsjc', str(gfsj_[3]))
  638. GfsjMx.set('Fl', str(gfsj_[4]))
  639. GfsjMx.set('Je', roundstr(gfsj_[5]))
  640. GfsjMx.set('Fyxlb', str(gfsj_[6]))
  641. ########################################Qdxm##########################
  642. Qdxm = ET.SubElement(Dwgcxx, 'Qdxm')
  643. if 'Default' in qdbt:
  644. collection = db["qdxm"]
  645. before_sort = []
  646. async for post in collection.find({"biao_id": id, "Dwgcbh": entry['Dwgcbh'], 'bt': 'Default'}):
  647. before_sort.append(post)
  648. after_sort = sorted(before_sort, key=lambda x: int(x['序号']))
  649. for qdmx in after_sort:
  650. Qdmx = ET.SubElement(Qdxm, 'Qdmx')
  651. Qdmx.set('Xh', str(qdmx['序号']))
  652. Qdmx.set('Qdbm', str(qdmx['清单编码']))
  653. Qdmx.set('Mc', str(qdmx['名称']))
  654. Qdmx.set('Xmtz', str(qdmx['项目特征']))
  655. Qdmx.set('Jsgz', str(qdmx['计算规则']))
  656. Qdmx.set('Dw', str(qdmx['单位']))
  657. Qdmx.set('Sl', roundstr4(qdmx['数量']))
  658. Qdmx.set('Zhdj', roundstr4(qdmx['综合单价']))
  659. Qdmx.set('Zhhj', roundstr4(qdmx['合价']))
  660. Qdmx.set('Rgf', roundstr4(qdmx['人工费']))
  661. Qdmx.set('Zcf', roundstr4(qdmx['主材费']))
  662. Qdmx.set('Sbf', roundstr4(qdmx['设备费']))
  663. Qdmx.set('Fcf', roundstr4(qdmx['辅材费']))
  664. Qdmx.set('Clf', roundstr4(qdmx['材料费']))
  665. Qdmx.set('Jxf', roundstr4(qdmx['机械费']))
  666. Qdmx.set('Glf', roundstr4(qdmx['管理费']))
  667. Qdmx.set('Lr', roundstr4(qdmx['利润']))
  668. Qdmx.set('Zgj', roundstr4(qdmx['暂估价']))
  669. Qdmx.set('Zgr', roundstr4(qdmx['综合人工工日']))
  670. Qdmx.set('Bz', str(qdmx['备注']))
  671. Qdxdezj = ET.SubElement(Qdmx, 'Qdxdezj')
  672. if '__children' in qdmx:
  673. for child in qdmx['__children']:
  674. QdxdezjMx = ET.SubElement(Qdxdezj, 'QdxdezjMx')
  675. QdxdezjMx.set('Debm', str(child['清单编码']))
  676. QdxdezjMx.set('Mc', str(child['名称']))
  677. QdxdezjMx.set('Dw', str(child['单位']))
  678. QdxdezjMx.set('DwQdSl', roundstr4(child['数量']))
  679. QdxdezjMx.set('Dj', roundstr4(child['综合单价']))
  680. QdxdezjMx.set('Hj', roundstr4(child['合价']))
  681. QdxdezjMx.set('Rgf', roundstr4(child['人工费']))
  682. QdxdezjMx.set('Zcf', roundstr4(child['主材费']))
  683. QdxdezjMx.set('Sbf', roundstr4(child['设备费']))
  684. QdxdezjMx.set('Fcf', roundstr4(child['辅材费']))
  685. QdxdezjMx.set('Clf', roundstr4(child['材料费']))
  686. QdxdezjMx.set('Jxf', roundstr4(child['机械费']))
  687. QdxdezjMx.set('Glf', roundstr4(child['管理费']))
  688. QdxdezjMx.set('Lr', roundstr4(child['利润']))
  689. Qdxdercjhl = ET.SubElement(QdxdezjMx, 'Qdxdercjhl')
  690. for i in range(len(child['dercj'])):
  691. if i == 0:
  692. pass
  693. else:
  694. QdxdercjhlMx = ET.SubElement(Qdxdercjhl, 'QdxdercjhlMx')
  695. QdxdercjhlMx.set('RcjId', util.indexrcj(rcjhz, child['dercj'][i]))
  696. QdxdercjhlMx.set('Rcjhl', roundstr4(child['dercj'][i][10]))
  697. QdxdercjhlMx.set('Rcjhj', roundstr4(child['dercj'][i][11]))
  698. Qdxrcjhl = ET.SubElement(Qdmx, 'Qdxrcjhl')
  699. for i in range(len(qdmx['rcj'])):
  700. if i == 0:
  701. pass
  702. else:
  703. QdxrcjhlMx = ET.SubElement(Qdxrcjhl, 'QdxrcjhlMx')
  704. QdxrcjhlMx.set('RcjId', util.indexrcj(rcjhz, qdmx['rcj'][i]))
  705. ##str(djcs['rcj'][i][0]))
  706. QdxrcjhlMx.set('Rcjhl', roundstr4(qdmx['rcj'][i][10]))
  707. QdxrcjhlMx.set('Rcjhj', roundstr4(qdmx['rcj'][i][11]))
  708. QdxrcjhlMx.set('Zgjbz', str(qdmx['rcj'][i][12]))
  709. QdxrcjhlMx.set('Zyclbz', str(qdmx['rcj'][i][13]))
  710. QdxrcjhlMx.set('Zcbz', str(qdmx['rcj'][i][14]))
  711. QdxrcjhlMx.set('Sbbz', str(qdmx['rcj'][i][15]))
  712. qdbt_addition = Dwgc['qdbt_addition']
  713. for bt in qdbt_addition:
  714. QdBt = ET.SubElement(Qdxm, 'QdBt')
  715. QdBt.set('Xh', bt['Xh'])
  716. QdBt.set('Mc', bt['Mc'])
  717. QdBt.set('Je', roundstr(bt['Je']))
  718. QdBt.set('Zgj', roundstr(bt['Zgj']))
  719. QdBt.set('Bz', bt['Bz'])
  720. collection = db["qdxm"]
  721. before_sort = []
  722. async for post in collection.find({"biao_id": id, "Dwgcbh": entry['Dwgcbh'], 'bt': bt['Mc']}):
  723. before_sort.append(post)
  724. after_sort = sorted(before_sort, key=lambda x: int(x['序号']))
  725. for qdmx in after_sort:
  726. Qdmx = ET.SubElement(QdBt, 'Qdmx')
  727. Qdmx.set('Xh', str(qdmx['序号']))
  728. Qdmx.set('Qdbm', str(qdmx['清单编码']))
  729. Qdmx.set('Mc', str(qdmx['名称']))
  730. Qdmx.set('Xmtz', str(qdmx['项目特征']))
  731. Qdmx.set('Jsgz', str(qdmx['计算规则']))
  732. Qdmx.set('Dw', str(qdmx['单位']))
  733. Qdmx.set('Sl', roundstr4(qdmx['数量']))
  734. Qdmx.set('Zhdj', roundstr4(qdmx['综合单价']))
  735. Qdmx.set('Zhhj', roundstr4(qdmx['合价']))
  736. Qdmx.set('Rgf', roundstr4(qdmx['人工费']))
  737. Qdmx.set('Zcf', roundstr4(qdmx['主材费']))
  738. Qdmx.set('Sbf', roundstr4(qdmx['设备费']))
  739. Qdmx.set('Fcf', roundstr4(qdmx['辅材费']))
  740. Qdmx.set('Clf', roundstr4(qdmx['材料费']))
  741. Qdmx.set('Jxf', roundstr4(qdmx['机械费']))
  742. Qdmx.set('Glf', roundstr4(qdmx['管理费']))
  743. Qdmx.set('Lr', roundstr4(qdmx['利润']))
  744. Qdmx.set('Zgj', roundstr4(qdmx['暂估价']))
  745. Qdmx.set('Zgr', roundstr4(qdmx['综合人工工日']))
  746. Qdmx.set('Bz', str(qdmx['备注']))
  747. Qdxdezj = ET.SubElement(Qdmx, 'Qdxdezj')
  748. if '__children' in qdmx:
  749. for child in qdmx['__children']:
  750. QdxdezjMx = ET.SubElement(Qdxdezj, 'QdxdezjMx')
  751. QdxdezjMx.set('Debm', str(child['清单编码']))
  752. QdxdezjMx.set('Mc', str(child['名称']))
  753. QdxdezjMx.set('Dw', str(child['单位']))
  754. QdxdezjMx.set('DwQdSl', roundstr4(child['数量']))
  755. QdxdezjMx.set('Dj', roundstr4(child['综合单价']))
  756. QdxdezjMx.set('Hj', roundstr4(child['合价']))
  757. QdxdezjMx.set('Rgf', roundstr4(child['人工费']))
  758. QdxdezjMx.set('Zcf', roundstr4(child['主材费']))
  759. QdxdezjMx.set('Sbf', roundstr4(child['设备费']))
  760. QdxdezjMx.set('Fcf', roundstr4(child['辅材费']))
  761. QdxdezjMx.set('Clf', roundstr4(child['材料费']))
  762. QdxdezjMx.set('Jxf', roundstr4(child['机械费']))
  763. QdxdezjMx.set('Glf', roundstr4(child['管理费']))
  764. QdxdezjMx.set('Lr', roundstr4(child['利润']))
  765. Qdxdercjhl = ET.SubElement(QdxdezjMx, 'Qdxdercjhl')
  766. for i in range(len(child['dercj'])):
  767. if i == 0:
  768. pass
  769. else:
  770. QdxdercjhlMx = ET.SubElement(Qdxdercjhl, 'QdxdercjhlMx')
  771. QdxdercjhlMx.set('RcjId', util.indexrcj(rcjhz, child['dercj'][i]))
  772. QdxdercjhlMx.set('Rcjhl', roundstr4(child['dercj'][i][10]))
  773. QdxdercjhlMx.set('Rcjhj', roundstr4(child['dercj'][i][11]))
  774. Qdxrcjhl = ET.SubElement(Qdmx, 'Qdxrcjhl')
  775. for i in range(len(qdmx['rcj'])):
  776. if i == 0:
  777. pass
  778. else:
  779. QdxrcjhlMx = ET.SubElement(Qdxrcjhl, 'QdxrcjhlMx')
  780. QdxrcjhlMx.set('RcjId', util.indexrcj(rcjhz, qdmx['rcj'][i]))
  781. ##str(djcs['rcj'][i][0]))
  782. QdxrcjhlMx.set('Rcjhl', roundstr4(qdmx['rcj'][i][10]))
  783. QdxrcjhlMx.set('Rcjhj', roundstr4(qdmx['rcj'][i][11]))
  784. QdxrcjhlMx.set('Zgjbz', str(qdmx['rcj'][i][12]))
  785. QdxrcjhlMx.set('Zyclbz', str(qdmx['rcj'][i][13]))
  786. QdxrcjhlMx.set('Zcbz', str(qdmx['rcj'][i][14]))
  787. QdxrcjhlMx.set('Sbbz', str(qdmx['rcj'][i][15]))
  788. ########################################Csxm##########################
  789. Csxm = ET.SubElement(Dwgcxx, 'Csxm')
  790. ZjCs = ET.SubElement(Csxm, 'ZjCs')
  791. for zjcs_ in zjcs:
  792. ZjCsMx = ET.SubElement(ZjCs, 'ZjCsMx')
  793. ZjCsMx.set('Xh', str(zjcs_['序号']))
  794. ZjCsMx.set('Bm', str(zjcs_['清单编码']))
  795. ZjCsMx.set('Mc', str(zjcs_['名称']))
  796. ZjCsMx.set('Js', roundstr(zjcs_['计算基数']))
  797. ZjCsMx.set('Jsjc', str(zjcs_['计算基础']))
  798. ZjCsMx.set('Fl', str(zjcs_['费率']))
  799. ZjCsMx.set('Je', roundstr(zjcs_['金额']))
  800. ZjCsMx.set('Xmlb', str(zjcs_['项目类别']))
  801. if '__children' in zjcs_:
  802. AqwmfMx = ET.SubElement(ZjCsMx, 'AqwmfMx')
  803. AqwmfMx.set('Mc', str(zjcs_['__children'][0]['名称']))
  804. AqwmfMx.set('Js', roundstr(zjcs_['__children'][0]['计算基数']))
  805. AqwmfMx.set('Jsjc', str(zjcs_['__children'][0]['计算基础']))
  806. AqwmfMx.set('Fl', str(zjcs_['__children'][0]['费率']))
  807. AqwmfMx.set('Je', roundstr(zjcs_['__children'][0]['金额']))
  808. AqwmfMx.set('Xmlb', str(zjcs_['__children'][0]['项目类别']))
  809. AqwmfMx = ET.SubElement(ZjCsMx, 'AqwmfMx')
  810. AqwmfMx.set('Mc', str(zjcs_['__children'][1]['名称']))
  811. AqwmfMx.set('Js', roundstr(zjcs_['__children'][1]['计算基数']))
  812. AqwmfMx.set('Jsjc', str(zjcs_['__children'][1]['计算基础']))
  813. AqwmfMx.set('Fl', str(zjcs_['__children'][1]['费率']))
  814. AqwmfMx.set('Je', roundstr(zjcs_['__children'][1]['金额']))
  815. AqwmfMx.set('Xmlb', str(zjcs_['__children'][1]['项目类别']))
  816. AqwmfMx = ET.SubElement(ZjCsMx, 'AqwmfMx')
  817. AqwmfMx.set('Mc', str(zjcs_['__children'][2]['名称']))
  818. AqwmfMx.set('Js', roundstr(zjcs_['__children'][2]['计算基数']))
  819. AqwmfMx.set('Jsjc', str(zjcs_['__children'][2]['计算基础']))
  820. AqwmfMx.set('Fl', str(zjcs_['__children'][2]['费率']))
  821. AqwmfMx.set('Je', roundstr(zjcs_['__children'][2]['金额']))
  822. AqwmfMx.set('Xmlb', str(zjcs_['__children'][2]['项目类别']))
  823. DjCs = ET.SubElement(Csxm, 'DjCs')
  824. collection = db["Djcs"]
  825. before_sort = []
  826. async for post in collection.find({"biao_id": id, "Dwgcbh": entry['Dwgcbh']}):
  827. before_sort.append(post)
  828. after_sort = sorted(before_sort, key=lambda x: int(x['序号']))
  829. for djcs in after_sort:
  830. DjCsMx = ET.SubElement(DjCs, 'DjCsMx')
  831. DjCsMx.set('Xh', str(djcs['序号']))
  832. DjCsMx.set('Bm', str(djcs['清单编码']))
  833. DjCsMx.set('Mc', str(djcs['名称']))
  834. DjCsMx.set('Xmtz', str(djcs['项目特征']))
  835. DjCsMx.set('Jsgz', str(djcs['计算规则']))
  836. DjCsMx.set('Dw', str(djcs['单位']))
  837. DjCsMx.set('Sl', roundstr4(djcs['数量']))
  838. DjCsMx.set('Zhdj', roundstr4(djcs['综合单价']))
  839. DjCsMx.set('Zhhj', roundstr4(djcs['合价']))
  840. DjCsMx.set('Rgf', roundstr4(djcs['人工费']))
  841. DjCsMx.set('Zcf', roundstr4(djcs['主材费']))
  842. DjCsMx.set('Sbf', roundstr4(djcs['设备费']))
  843. DjCsMx.set('Fcf', roundstr4(djcs['辅材费']))
  844. DjCsMx.set('Clf', roundstr4(djcs['材料费']))
  845. DjCsMx.set('Jxf', roundstr4(djcs['机械费']))
  846. DjCsMx.set('Glf', roundstr4(djcs['管理费']))
  847. DjCsMx.set('Lr', roundstr4(djcs['利润']))
  848. DjCsMx.set('Zgj', roundstr4(djcs['暂估价']))
  849. DjCsMx.set('Zgr', roundstr4(djcs['综合人工工日']))
  850. Csxdezj = ET.SubElement(DjCsMx, 'Csxdezj')
  851. if '__children' in djcs:
  852. for child in djcs['__children']:
  853. CsxdezjMx = ET.SubElement(Csxdezj, 'CsxdezjMx')
  854. CsxdezjMx.set('Debm', str(child['清单编码']))
  855. CsxdezjMx.set('Mc', str(child['名称']))
  856. CsxdezjMx.set('Dw', str(child['单位']))
  857. CsxdezjMx.set('DwQdSl', roundstr4(child['数量']))
  858. CsxdezjMx.set('Dj', roundstr4(child['综合单价']))
  859. CsxdezjMx.set('Hj', roundstr4(child['合价']))
  860. CsxdezjMx.set('Rgf', roundstr4(child['人工费']))
  861. CsxdezjMx.set('Zcf', roundstr4(child['主材费']))
  862. CsxdezjMx.set('Sbf', roundstr4(child['设备费']))
  863. CsxdezjMx.set('Fcf', roundstr4(child['辅材费']))
  864. CsxdezjMx.set('Clf', roundstr4(child['材料费']))
  865. CsxdezjMx.set('Jxf', roundstr4(child['机械费']))
  866. CsxdezjMx.set('Glf', roundstr4(child['管理费']))
  867. CsxdezjMx.set('Lr', roundstr4(child['利润']))
  868. Csxdercjhl = ET.SubElement(CsxdezjMx, 'Csxdercjhl')
  869. for i in range(len(child['dercj'])):
  870. if i == 0:
  871. pass
  872. else:
  873. CsxdercjhlMx = ET.SubElement(Csxdercjhl, 'CsxdercjhlMx')
  874. CsxdercjhlMx.set('RcjId', util.indexrcj(rcjhz, child['dercj'][i]))
  875. CsxdercjhlMx.set('Rcjhl', roundstr4(child['dercj'][i][10]))
  876. CsxdercjhlMx.set('Rcjhj', roundstr4(child['dercj'][i][11]))
  877. Csxrcjhl = ET.SubElement(DjCsMx, 'Csxrcjhl')
  878. for i in range(len(djcs['rcj'])):
  879. if i == 0:
  880. pass
  881. else:
  882. CsxrcjhlMx = ET.SubElement(Csxrcjhl, 'CsxrcjhlMx')
  883. CsxrcjhlMx.set('RcjId', util.indexrcj(rcjhz, djcs['rcj'][i]))
  884. ##str(djcs['rcj'][i][0]))
  885. CsxrcjhlMx.set('Rcjhl', roundstr4(djcs['rcj'][i][10]))
  886. CsxrcjhlMx.set('Rcjhj', roundstr4(djcs['rcj'][i][11]))
  887. CsxrcjhlMx.set('Zgjbz', str(djcs['rcj'][i][12]))
  888. CsxrcjhlMx.set('Zyclbz', str(djcs['rcj'][i][13]))
  889. CsxrcjhlMx.set('Zcbz', str(djcs['rcj'][i][14]))
  890. CsxrcjhlMx.set('Sbbz', str(djcs['rcj'][i][15]))
  891. ########################################Qtxm##########################
  892. Qtxm = ET.SubElement(Dwgcxx, 'Qtxm')
  893. for qtxm_ in qtxm:
  894. QtxmMx = ET.SubElement(Qtxm, 'QtxmMx')
  895. QtxmMx.set('Xh', str(qtxm_[0]))
  896. QtxmMx.set('Mc', str(qtxm_[1]))
  897. QtxmMx.set('Je', roundstr(qtxm_[2]))
  898. QtxmMx.set('Xmlb', str(qtxm_[3]))
  899. QtxmMx.set('Bz', str(qtxm_[4]))
  900. Zlje = ET.SubElement(Dwgcxx, 'Zlje')
  901. for i in range(len(zlje)):
  902. ZljeMx = ET.SubElement(Zlje, 'ZljeMx')
  903. ZljeMx.set('Xh', str(zlje[i]['序号']))
  904. ZljeMx.set('Mc', str(zlje[i]['名称']))
  905. ZljeMx.set('Dw', str(zlje[i]['单位']))
  906. ZljeMx.set('Zdje', roundstr(zlje[i]['暂定金额']))
  907. ZljeMx.set('Bz', str(zlje[i]['备注']))
  908. Clzg = ET.SubElement(Dwgcxx, 'Clzg')
  909. Zygczg = ET.SubElement(Dwgcxx, 'Zygczg')
  910. for zygczgj_ in zygczgj:
  911. ZygczgMx = ET.SubElement(Zygczg, 'ZygczgMx')
  912. ZygczgMx.set('Xh', str(zygczgj_['序号']))
  913. ZygczgMx.set('Mc', str(zygczgj_['名称']))
  914. ZygczgMx.set('Gcnr', str(zygczgj_['工程内容']))
  915. ZygczgMx.set('Je', roundstr(zygczgj_['金额']))
  916. ZygczgMx.set('Bz', str(zygczgj_['备注']))
  917. Jrg = ET.SubElement(Dwgcxx, 'Jrg')
  918. for jrg_ in jrg:
  919. JrgBt = ET.SubElement(Jrg, 'JrgBt')
  920. JrgBt.set('Xh', str(jrg_['序号']))
  921. JrgBt.set('Mc', str(jrg_['名称']))
  922. JrgBt.set('Je', roundstr(jrg_['金额']))
  923. JrgBt.set('Lb', str(jrg_['类别']))
  924. Zcbfwf = ET.SubElement(Dwgcxx, 'Zcbfwf')
  925. for zcbfwf_ in zcbfwf:
  926. ZcbfwfMx = ET.SubElement(Zcbfwf, 'ZcbfwfMx')
  927. ZcbfwfMx.set('Xh', str(zcbfwf_['序号']))
  928. ZcbfwfMx.set('Mc', str(zcbfwf_['名称']))
  929. ZcbfwfMx.set('Xmjz', roundstr(zcbfwf_['项目价值']))
  930. ZcbfwfMx.set('Fwnr', str(zcbfwf_['服务内容']))
  931. ZcbfwfMx.set('Jsjc', str(zcbfwf_['计算基础']))
  932. ZcbfwfMx.set('Fl', str(zcbfwf_['费率']))
  933. ZcbfwfMx.set('Je', roundstr(zcbfwf_['金额']))
  934. Zjxmjdkzffj = ET.SubElement(Dwgcxx, 'Zjxmjdkzffj')
  935. Fbrgycl = ET.SubElement(Dwgcxx, 'Fbrgycl')
  936. for fbrgycl_ in fbrgycl:
  937. FbrgyclMx = ET.SubElement(Fbrgycl, 'FbrgyclMx')
  938. FbrgyclMx.set('Xh', str(fbrgycl_['序号']))
  939. FbrgyclMx.set('RcjId', util.indexrcj(rcjhz, [fbrgycl_['序号'], fbrgycl_['材料编号'], fbrgycl_['名称'], fbrgycl_['规格型号'], fbrgycl_['单位']]))
  940. FbrgyclMx.set('Clbh', str(fbrgycl_['材料编号']))
  941. FbrgyclMx.set('Mc', str(fbrgycl_['名称']))
  942. FbrgyclMx.set('Ggxh', str(fbrgycl_['规格型号']))
  943. FbrgyclMx.set('Dw', str(fbrgycl_['单位']))
  944. FbrgyclMx.set('Sl', roundstr4(fbrgycl_['数量']))
  945. FbrgyclMx.set('Dj', roundstr4(fbrgycl_['单价']))
  946. FbrgyclMx.set('Hj', roundstr4(fbrgycl_['合价']))
  947. FbrgyclMx.set('Jhfs', str(fbrgycl_['交货方式']))
  948. FbrgyclMx.set('Sddd', str(fbrgycl_['送达地点']))
  949. FbrgyclMx.set('Bz', str(fbrgycl_['备注']))
  950. Cbrgycl = ET.SubElement(Dwgcxx, 'Cbrgycl')
  951. Rcjhz = ET.SubElement(Dwgcxx, 'Rcjhz')
  952. for i in range(len(rcjhz)):
  953. if i == 0:
  954. pass
  955. else:
  956. RcjhzMx = ET.SubElement(Rcjhz, 'RcjhzMx')
  957. RcjhzMx.set('RcjId', str(i))
  958. RcjhzMx.set('RcjBm', str(rcjhz[i][1]))
  959. RcjhzMx.set('Mc', str(rcjhz[i][2]))
  960. RcjhzMx.set('Ggxh', str(rcjhz[i][3]))
  961. RcjhzMx.set('Dw', str(rcjhz[i][4]))
  962. RcjhzMx.set('Sl', roundstr4(rcjhz[i][5]))
  963. RcjhzMx.set('Dj', roundstr4(rcjhz[i][6]))
  964. RcjhzMx.set('Hj', roundstr4(rcjhz[i][7]))
  965. RcjhzMx.set('Cd', str(rcjhz[i][8]))
  966. RcjhzMx.set('Gycs', str(rcjhz[i][9]))
  967. RcjhzMx.set('Rcjlb', str(rcjhz[i][10]))
  968. RcjhzMx.set('Zyclbz', str(rcjhz[i][11]))
  969. RcjhzMx.set('Zcbz', str(rcjhz[i][12]))
  970. RcjhzMx.set('Sbbz', str(rcjhz[i][13]))
  971. RcjhzMx.set('Jgbz', str(rcjhz[i][14]))
  972. RcjhzMx.set('Zgjbz', str(rcjhz[i][15]))
  973. async def delete_files(client, id):
  974. db = client["baojia"]
  975. collection = db["jingjibiao"]
  976. result = []
  977. await collection.update_one({'_id': ObjectId(id)}, {'$set': {'visible': False}})
  978. return result
  979. async def list_files(client):
  980. db = client["baojia"]
  981. collection = db["jingjibiao"]
  982. result = []
  983. async for post in collection.find({"visible": True}):
  984. result.append([str(post['_id']), post["Xmmc"], post['created'] if 'created' in post else ""])
  985. return result
  986. def getDwgc(id, Zylb):
  987. result = []
  988. #result.append(["ming cheng", "jin e", "zan gu jia", "anquan wenming fei", "guifei"])
  989. ##result.append([child.attrib["Dxgcmc"], child.attrib["Je"], child.attrib["Zgj"], child.attrib["Aqwmf"], child.attrib["Gf"]])
  990. id = id + "Zylb" + Zylb
  991. result.append({"id": id + "bao jia hui zong", "label": "报价汇总表"})
  992. result.append({"id": id + "gui fei shui jin", "label": "规费税金"})
  993. result.append({"id": id + "qing dan xiang mu", "label": "清单项目"})
  994. result.append({"id": id + "cuo shi xiang mu", "label": "措施项目"})
  995. result.append({"id": id +"qi ta xiang mu", "label": "其他项目"})
  996. result.append({"id": id +"zan lie jin e", "label": "暂列金额"})
  997. result.append({"id": id +"cai liao zan gu jia", "label": "材料暂估价"})
  998. result.append({"id": id + "zhuan ye gong cheng zan gu jia", "label": "专业工程暂估价"})
  999. result.append({"id": id + "ji ri gong", "label": "计日工"})
  1000. result.append({"id": id + "zong cheng bao fu wu fei", "label": "总承包服务费"})
  1001. result.append({"id": id + "zong jia xiang mu jin du kuan zhi fu fen jie", "label": "总价项目进度款支付分解"})
  1002. result.append({"id": id + "fa bao ren gong ying cai liao", "label": "发包人供应材料"})
  1003. result.append({"id": id + "cheng bao ren gong ying cai liao", "label": "承包人供应材料"})
  1004. result.append({"id": id + "ren cai ji hui zong", "label": "人材机汇总"})
  1005. return result
  1006. async def getOutline(client, id):
  1007. db = client["baojia"]
  1008. collection = db["jingjibiao"]
  1009. document = await collection.find_one({'_id': ObjectId(id)})
  1010. result = []
  1011. if 'TouBiaoXx' in document:
  1012. result.append({"id" : "TouBiaoXx", "label" : "投标信息" })
  1013. if 'Dxgcxx' in document:
  1014. Dxgcxx = document["Dxgcxx"]
  1015. for dxgc in Dxgcxx:
  1016. result2 = []
  1017. Dwgc = dxgc["Dwgc"]
  1018. for grandchild in Dwgc:
  1019. result2.append({"id" : grandchild['Dwgcbh'], "Zylb":grandchild['Zylb'], "label": grandchild["Dwgcmc"], "children" : getDwgc(grandchild['Dwgcbh'], grandchild['Zylb'])})
  1020. result.append({"id" : dxgc['Dxgcbh'], "label" : dxgc['Dxgcmc'], "children" : result2})
  1021. return result
  1022. async def getDetail(client, id):
  1023. db = client["baojia"]
  1024. collection = db["jingjibiao"]
  1025. document = await collection.find_one({'_id': ObjectId(id)})
  1026. result = []
  1027. ##result.append(["名称", "金额", "暂估价", "安全文明施工费", "规费"])
  1028. if 'TouBiaoXx' in document:
  1029. toubiaoxx = document["TouBiaoXx"]
  1030. result.append({'名称': '投标总价', '金额' : toubiaoxx["Tbzj"], '暂估价': toubiaoxx["Zgj"], '安全文明施工费': toubiaoxx["Aqwmf"], '规费' : toubiaoxx["Gf"], '_children': []})
  1031. if 'Dxgcxx' in document:
  1032. Dxgcxx = document["Dxgcxx"]
  1033. for dxgc in Dxgcxx:
  1034. result[0]['_children'].append({'名称' :dxgc["Dxgcmc"], '金额' : dxgc["Je"], '暂估价' : dxgc["Zgj"],'安全文明施工费' : dxgc["Aqwmf"], '规费' : dxgc["Gf"]})
  1035. return result
  1036. else:
  1037. if 'Dxgcxx' in document:
  1038. Dxgcxx = document["Dxgcxx"]
  1039. for dxgc in Dxgcxx:
  1040. result.append({'名称' :dxgc["Dxgcmc"], '金额' : dxgc["Je"], '暂估价' : dxgc["Zgj"],'安全文明施工费' : dxgc["Aqwmf"], '规费' : dxgc["Gf"]})
  1041. return result
  1042. async def getBjhz(client, objectid, id):
  1043. db = client["baojia"]
  1044. collection = db["Dwgc"]
  1045. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  1046. return document['bjhz']
  1047. async def getGfsj(client, objectid, id):
  1048. db = client["baojia"]
  1049. collection = db["Dwgc"]
  1050. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  1051. return document['gfsj']
  1052. async def getQtxm(client, objectid, id):
  1053. db = client["baojia"]
  1054. collection = db["Dwgc"]
  1055. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  1056. return document['qtxm']
  1057. async def getZygczgj(client, objectid, id):
  1058. db = client["baojia"]
  1059. collection = db["Dwgc"]
  1060. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  1061. return document['zygczgj']
  1062. async def getZlje(client, objectid, id):
  1063. db = client["baojia"]
  1064. collection = db["Dwgc"]
  1065. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  1066. return document['zlje']
  1067. async def getJrg(client, objectid, id):
  1068. db = client["baojia"]
  1069. collection = db["Dwgc"]
  1070. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  1071. return document['jrg']
  1072. async def getZcbfwf(client, objectid, id):
  1073. db = client["baojia"]
  1074. collection = db["Dwgc"]
  1075. document = await collection.find_one({"Dwgcbh": id, "biao_id": objectid})
  1076. return document['zcbfwf']
  1077. async def getFbrgycl(client, objectid, id):
  1078. db = client["baojia"]
  1079. collection = db["Dwgc"]
  1080. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  1081. return document['fbrgycl']
  1082. async def getRcjhz(client, objectid, id):
  1083. db = client["baojia"]
  1084. collection = db["Dwgc"]
  1085. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  1086. return document['rcjhz']
  1087. async def getZjcs(client, objectid, id):
  1088. db = client["baojia"]
  1089. collection = db["Dwgc"]
  1090. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  1091. return document['zjcs']
  1092. async def getDjcs(client, objectid, id):
  1093. db = client["baojia"]
  1094. collection = db["Djcs"]
  1095. result = []
  1096. async for post in collection.find({"Dwgcbh": id, "biao_id": objectid}):
  1097. ##post["ID"] = post["_id"]
  1098. del post["_id"]
  1099. ##print( post["rcj"])
  1100. ## del post["DogNum"]
  1101. result.append(post)
  1102. return result
  1103. async def getDjcsQingdanrcj(client, name, bh, bt, bm):
  1104. db = client["baojia"]
  1105. collection = db["Djcs"]
  1106. document = await collection.find_one({ "Dwgcbh": bh, "清单编码": bm, "biao_id": name})
  1107. result = document["rcj"]
  1108. return result
  1109. async def getDjcsDingercj(client, name, bh, bt, qdbm, debm):
  1110. db = client["baojia"]
  1111. collection = db["Djcs"]
  1112. document = await collection.find_one({"Dwgcbh": bh, "清单编码": qdbm, "biao_id": name})
  1113. children = document["__children"]
  1114. result = []
  1115. for child in children:
  1116. if child["清单编码"] == debm:
  1117. result = child["dercj"]
  1118. return result
  1119. async def getQdxm(client, name, bh):
  1120. db = client["baojia"]
  1121. collection = db["Dwgc"]
  1122. document = await collection.find_one({'biao_id': name, "Dwgcbh": bh})
  1123. if document:
  1124. return document['qdbt']
  1125. else:
  1126. return []
  1127. async def getQdmx(client, name, bh, bt):
  1128. db = client["baojia"]
  1129. collection = db["qdxm"]
  1130. result = []
  1131. async for post in collection.find({'biao_id': name, "Dwgcbh": bh, "bt": bt}):
  1132. ##post["ID"] = post["_id"]
  1133. del post["_id"]
  1134. #del post["rcj"]
  1135. #del post["DogNum"]
  1136. result.append(post)
  1137. return result
  1138. async def getQingdanrcj(client, name, bh, bt, bm):
  1139. db = client["baojia"]
  1140. collection = db["qdxm"]
  1141. document = await collection.find_one({ "Dwgcbh": bh, "清单编码": bm, "biao_id": name, "bt": bt})
  1142. result = document["rcj"]
  1143. return result
  1144. async def getDingercj(client, name, bh, bt, qdbm, debm):
  1145. db = client["baojia"]
  1146. collection = db["qdxm"]
  1147. document = await collection.find_one({"Dwgcbh": bh, "清单编码": qdbm, "biao_id": name, "bt": bt})
  1148. result = []
  1149. if "__children" in document:
  1150. children = document["__children"]
  1151. for child in children:
  1152. if child["清单编码"] == debm:
  1153. result = child["dercj"]
  1154. return result
  1155. async def getQufei(client, id):
  1156. db = client["baojia"]
  1157. collection = db["qufei"]
  1158. document = await collection.find_one({'biao_id': id})
  1159. return document['qufei']
  1160. async def searchde(client, zhuanye, text):
  1161. db = client["dinge"]
  1162. collection = db["de-collection"]
  1163. result = []
  1164. async for post in collection.find({'$text': {"$search": "\"" + text + "\""}, "zhuanye": zhuanye}):
  1165. result.append(post["DEBH"] + " " + post['GCLMC'] )
  1166. if len(result) > 10:
  1167. break
  1168. return result
  1169. ##################################editor##########################
  1170. async def updatezjcs(client, id, bh, mc, fl):
  1171. db = client["baojia"]
  1172. collection = db["Dwgc"]
  1173. document = await collection.find_one({'biao_id': id, 'Dwgcbh': bh}, {'rcjhz': 0})
  1174. zjcs = document['zjcs']
  1175. for entry in zjcs:
  1176. if entry['名称'] == mc:
  1177. entry['费率'] = fl
  1178. entry['金额'] = str(float(entry['计算基数']) * float(fl) / float(100))
  1179. await collection.update_one({'biao_id': id, "Dwgcbh": bh}, {'$set': {'zjcs': zjcs}})
  1180. async def save(client, data):
  1181. db = client["baojia"]
  1182. collection = db["qdxm"]
  1183. biao_id = None
  1184. bh = None
  1185. for entry in data:
  1186. entry["__children"] = entry["_children"]
  1187. del entry["_children"]
  1188. biao_id = entry['biao_id']
  1189. bh = entry['Dwgcbh']
  1190. await collection.replace_one({"biao_id": entry["biao_id"], "Dwgcbh": entry["Dwgcbh"], "bt": entry["bt"], "清单编码": entry["清单编码"]}, entry)
  1191. if not biao_id:
  1192. return {"result" : "ok"}
  1193. rcjhz = []
  1194. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  1195. qdrcj = post['rcj'][1:]
  1196. for entry in qdrcj:
  1197. entry[10] = float(entry[10]) * float(post['数量'])
  1198. rcjhz = rcjhz + qdrcj
  1199. collection = db["Djcs"]
  1200. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  1201. qdrcj = post['rcj'][1:]
  1202. for entry in qdrcj:
  1203. entry[10] = float(entry[10]) * float(post['数量'])
  1204. rcjhz = rcjhz + qdrcj
  1205. newHuizong = util.huizongrcj(rcjhz)
  1206. collection = db["Dwgc"]
  1207. await collection.update_one({'biao_id': biao_id, 'Dwgcbh': bh}, {'$set': {'rcjhz' : newHuizong}})
  1208. await zongjiaDwgc(client, biao_id, bh)
  1209. await tbxx(client, biao_id)
  1210. return {"result": "ok"}
  1211. async def savedjcs(client, data):
  1212. db = client["baojia"]
  1213. collection = db["Djcs"]
  1214. biao_id = None
  1215. bh = None
  1216. for entry in data:
  1217. entry["__children"] = entry["_children"]
  1218. del entry["_children"]
  1219. biao_id = entry['biao_id']
  1220. bh = entry['Dwgcbh']
  1221. await collection.replace_one({"biao_id": entry["biao_id"], "Dwgcbh": entry["Dwgcbh"], "清单编码": entry["清单编码"]}, entry)
  1222. if not biao_id:
  1223. return {"result" : "ok"}
  1224. rcjhz = []
  1225. collection = db["qdxm"]
  1226. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  1227. qdrcj = post['rcj'][1:]
  1228. for entry in qdrcj:
  1229. entry[10] = float(entry[10]) * float(post['数量'])
  1230. rcjhz = rcjhz + qdrcj
  1231. collection = db["Djcs"]
  1232. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  1233. qdrcj = post['rcj'][1:]
  1234. for entry in qdrcj:
  1235. entry[10] = float(entry[10]) * float(post['数量'])
  1236. rcjhz = rcjhz + qdrcj
  1237. newHuizong = util.huizongrcj(rcjhz)
  1238. collection = db["Dwgc"]
  1239. await collection.update_one({'biao_id': biao_id, 'Dwgcbh': bh}, {'$set': {'rcjhz' : newHuizong}})
  1240. await zongjiaDwgc(client, biao_id, bh)
  1241. await tbxx(client, biao_id)
  1242. return {"result": "ok"}
  1243. async def applyFL(client, id, data):
  1244. db = client["baojia"]
  1245. collection = db["qufei"]
  1246. await collection.replace_one({"biao_id": id}, {"biao_id": id, "qufei": data})
  1247. collection = db['qdxm']
  1248. xm = data[0]
  1249. for dxgc in xm["children"]:
  1250. for dwgc in dxgc["children"]:
  1251. bh = dwgc['key']
  1252. glf = float(dwgc['管理费(%)'])
  1253. lr = float(dwgc['利润(%)'])
  1254. bz = dwgc['备注']
  1255. ##print(bh+glf+lr+bz)
  1256. async for post in collection.find({'biao_id': id, "Dwgcbh": bh}):
  1257. rgfs = float(post['人工费'])
  1258. clfs = float(post['材料费'])
  1259. jxfs = float(post['机械费'])
  1260. sl = float(post['数量'])
  1261. if rgfs < 0.0001 and clfs < 0.0001 and jxfs < 0.0001:
  1262. continue
  1263. ##danxiang = False
  1264. for child in post['__children']:##一条定额
  1265. bm = child['清单编码']
  1266. if bm.startswith("D"):
  1267. ##danxiang = True
  1268. continue
  1269. rgf = float(child['人工费'])
  1270. clf = float(child['材料费'])
  1271. jxf = float(child['机械费'])
  1272. zhdj = float(child['综合单价'])
  1273. sl_ = float(child['数量'])
  1274. if len(bz) == 0:
  1275. ##常规计算
  1276. child['管理费'] = (rgf + jxf) * glf / float(100)
  1277. child['利润'] = (rgf + jxf) * lr / float(100)
  1278. child['综合单价'] = rgf + clf + jxf + child['管理费'] + child['利润']
  1279. child['合价'] = sl * sl_ * child['综合单价']
  1280. else:
  1281. child['管理费'] = (rgf) * glf / float(100)
  1282. child['利润'] = (rgf) * lr / float(100)
  1283. child['综合单价'] = rgf + clf + jxf + child['管理费'] + child['利润']
  1284. child['合价'] = sl * sl_ * child['综合单价']
  1285. if True:
  1286. post['管理费'] = 0
  1287. post['利润'] = 0
  1288. for entry in post['__children']:
  1289. post['管理费'] = post['管理费'] + float(entry['管理费']) * float(entry['数量'])
  1290. post['利润'] = post['利润'] + float(entry['利润']) * float(entry['数量'])
  1291. post['管理费'] = str(post['管理费'])
  1292. post['利润'] = str(post['利润'])
  1293. post['综合单价'] = str(float(post['人工费']) + float(post['材料费']) + float(post['机械费']) + float(post['管理费']) + float(post['利润']))
  1294. post['合价'] = str(float(post['综合单价']) * float(post['数量']))
  1295. await collection.replace_one({'_id': post['_id']}, post )
  1296. collection = db['Djcs']
  1297. for dxgc in xm["children"]:
  1298. for dwgc in dxgc["children"]:
  1299. bh = dwgc['key']
  1300. glf = float(dwgc['管理费(%)'])
  1301. lr = float(dwgc['利润(%)'])
  1302. bz = dwgc['备注']
  1303. ##print(bh+glf+lr+bz)
  1304. async for post in collection.find({'biao_id': id, "Dwgcbh": bh}):
  1305. rgfs = float(post['人工费'])
  1306. clfs = float(post['材料费'])
  1307. jxfs = float(post['机械费'])
  1308. sl = float(post['数量'])
  1309. if rgfs < 0.0001 and clfs < 0.0001 and jxfs < 0.0001:
  1310. continue
  1311. ##danxiang = False##一般有单项定额的,清单就一条定额,就是这个单项定额
  1312. for child in post['__children']:
  1313. bm = child['清单编码']
  1314. if bm.startswith("D"):
  1315. ##danxiang = True
  1316. continue
  1317. rgf = float(child['人工费'])
  1318. clf = float(child['材料费'])
  1319. jxf = float(child['机械费'])
  1320. zhdj = float(child['综合单价'])
  1321. sl_ = float(child['数量'])
  1322. if len(bz) == 0:
  1323. ##常规计算
  1324. child['管理费'] = (rgf + jxf) * glf / float(100)
  1325. child['利润'] = (rgf + jxf) * lr / float(100)
  1326. child['综合单价'] = rgf + clf + jxf + child['管理费'] + child['利润']
  1327. child['合价'] = sl * sl_ * child['综合单价']
  1328. else:
  1329. child['管理费'] = (rgf) * glf / float(100)
  1330. child['利润'] = (rgf) * lr / float(100)
  1331. child['综合单价'] = rgf + clf + jxf + child['管理费'] + child['利润']
  1332. child['合价'] = sl * sl_ * child['综合单价']
  1333. if True:
  1334. post['管理费'] = 0
  1335. post['利润'] = 0
  1336. for entry in post['__children']:
  1337. post['管理费'] = post['管理费'] + float(entry['管理费']) * float(entry['数量'])
  1338. post['利润'] = post['利润'] + float(entry['利润']) * float(entry['数量'])
  1339. post['管理费'] = str(post['管理费'])
  1340. post['利润'] = str(post['利润'])
  1341. post['综合单价'] = str(float(post['人工费']) + float(post['材料费']) + float(post['机械费']) + float(post['管理费']) + float(post['利润']))
  1342. post['合价'] = str(float(post['综合单价']) * float(post['数量']))
  1343. await collection.replace_one({'_id': post['_id']}, post )
  1344. for dxgc in xm["children"]:
  1345. for dwgc in dxgc["children"]:
  1346. bh = dwgc['key']
  1347. await zongjiaDwgc(client, id, bh)
  1348. await tbxx(client, id)
  1349. return {"result": "ok"}
  1350. async def tiaojia(client, biao_id, bh, bm, mingcheng, danwei, jiage, glf, lr, bz):
  1351. db = client["baojia"]
  1352. collection = db["qdxm"]
  1353. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}):
  1354. if "__children" not in post:
  1355. ##print(post)
  1356. continue
  1357. children = post["__children"]
  1358. qdsl = post['数量']
  1359. hit = False
  1360. for entry in children:###对一条定额,调价
  1361. hitde = False
  1362. dercj = entry["dercj"]
  1363. dergf = 0
  1364. declf = 0
  1365. dejxf = 0
  1366. for i in range(1, len(dercj)):
  1367. rcj = dercj[i]
  1368. if rcj[1] == bm and rcj[2] == mingcheng and rcj[4] == danwei:
  1369. hit = True
  1370. hitde = True
  1371. rcj[5] = jiage
  1372. hanliang = rcj[10]
  1373. rcj[11] = str(float(jiage) * float(hanliang))
  1374. if int(rcj[8]) == 1:
  1375. dergf = dergf + float(rcj[11])
  1376. elif int(rcj[8]) == 2:
  1377. declf = declf + float(rcj[11])
  1378. elif int(rcj[8]) == 3:
  1379. dejxf = dejxf + float(rcj[11])
  1380. if hitde:
  1381. entry['人工费'] = str(dergf)
  1382. entry['辅材费'] = str(declf)
  1383. entry['材料费'] = str(declf)
  1384. entry['机械费'] = str(dejxf)
  1385. if bm.startswith("D"):
  1386. entry['管理费'] = '0'
  1387. entry['利润'] = '0'
  1388. elif bz == 0:
  1389. entry['管理费'] = str((dergf + dejxf) * float(glf) / float(100))
  1390. entry['利润'] = str((dergf + dejxf) * float(lr) / float(100))
  1391. else:
  1392. entry['管理费'] = str((dergf) * float(glf) / float(100))
  1393. entry['利润'] = str((dergf) * float(lr) / float(100))
  1394. entry['综合单价'] = str(float(entry['人工费']) + float(entry['材料费']) + float(entry['机械费']) + float(entry['管理费']) + float(entry['利润']))
  1395. entry['合价'] = str(float(entry['综合单价']) * float(entry['数量']) * float(qdsl))
  1396. if hit:
  1397. ##调整清单
  1398. qdrcj = post['rcj']
  1399. qdrgf = 0
  1400. qdclf = 0
  1401. qdjxf = 0
  1402. for i in range(1, len(qdrcj)):
  1403. entry = qdrcj[i]
  1404. if entry[1] == bm and entry[2] == mingcheng and entry[4] == danwei:
  1405. entry[5] = jiage
  1406. hanliang = entry[10]
  1407. entry[11] = str(float(jiage) * float(hanliang))
  1408. if int(entry[8]) == 1:
  1409. qdrgf = qdrgf + float(entry[11])
  1410. elif int(entry[8]) == 2:
  1411. qdclf = qdclf + float(entry[11])
  1412. elif int(entry[8]) == 3:
  1413. qdjxf = qdjxf + float(entry[11])
  1414. post['人工费'] = str(qdrgf)
  1415. post['辅材费'] = str(qdclf)
  1416. post['材料费'] = str(qdclf)
  1417. post['机械费'] = str(qdjxf)
  1418. post['管理费'] = 0
  1419. post['利润'] = 0
  1420. for entry in children:
  1421. post['管理费'] = post['管理费'] + float(entry['管理费']) * float(entry['数量'])
  1422. post['利润'] = post['利润'] + float(entry['利润']) * float(entry['数量'])
  1423. post['管理费'] = str(post['管理费'])
  1424. post['利润'] = str(post['利润'])
  1425. post['综合单价'] = str(float(post['人工费']) + float(post['材料费']) + float(post['机械费']) + float(post['管理费']) + float(post['利润']))
  1426. post['合价'] = str(float(post['综合单价']) * float(qdsl))
  1427. print(post)
  1428. await collection.replace_one({'_id': post['_id']}, post )
  1429. collection = db["Djcs"]
  1430. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}):
  1431. children = post["__children"]
  1432. qdsl = post['数量']
  1433. hit = False
  1434. for entry in children:###对一条定额,调价
  1435. hitde = False
  1436. dercj = entry["dercj"]
  1437. dergf = 0
  1438. declf = 0
  1439. dejxf = 0
  1440. for i in range(1, len(dercj)):
  1441. rcj = dercj[i]
  1442. if rcj[1] == bm and rcj[2] == mingcheng and rcj[4] == danwei:
  1443. hit = True
  1444. hitde = True
  1445. rcj[5] = jiage
  1446. hanliang = rcj[10]
  1447. rcj[11] = str(float(jiage) * float(hanliang))
  1448. if int(rcj[8]) == 1:
  1449. dergf = dergf + float(rcj[11])
  1450. elif int(rcj[8]) == 2:
  1451. declf = declf + float(rcj[11])
  1452. elif int(rcj[8]) == 3:
  1453. dejxf = dejxf + float(rcj[11])
  1454. if hitde:
  1455. entry['人工费'] = str(dergf)
  1456. entry['辅材费'] = str(declf)
  1457. entry['材料费'] = str(declf)
  1458. entry['机械费'] = str(dejxf)
  1459. if bm.startswith("D"):
  1460. entry['管理费'] = '0'
  1461. entry['利润'] = '0'
  1462. elif bz == 0:
  1463. entry['管理费'] = str((dergf + dejxf) * float(glf) / float(100))
  1464. entry['利润'] = str((dergf + dejxf) * float(lr) / float(100))
  1465. else:
  1466. entry['管理费'] = str((dergf) * float(glf) / float(100))
  1467. entry['利润'] = str((dergf) * float(lr) / float(100))
  1468. entry['综合单价'] = str(float(entry['人工费']) + float(entry['材料费']) + float(entry['机械费']) + float(entry['管理费']) + float(entry['利润']))
  1469. entry['合价'] = str(float(entry['综合单价']) * float(entry['数量']) * float(qdsl))
  1470. if hit:
  1471. ##调整清单
  1472. qdrcj = post['rcj']
  1473. qdrgf = 0
  1474. qdclf = 0
  1475. qdjxf = 0
  1476. for i in range(1, len(qdrcj)):
  1477. entry = qdrcj[i]
  1478. if entry[1] == bm and entry[2] == mingcheng and entry[4] == danwei:
  1479. entry[5] = jiage
  1480. hanliang = entry[10]
  1481. entry[11] = str(float(jiage) * float(hanliang))
  1482. if int(entry[8]) == 1:
  1483. qdrgf = qdrgf + float(entry[11])
  1484. elif int(entry[8]) == 2:
  1485. qdclf = qdclf + float(entry[11])
  1486. elif int(entry[8]) == 3:
  1487. qdjxf = qdjxf + float(entry[11])
  1488. post['人工费'] = str(qdrgf)
  1489. post['辅材费'] = str(qdclf)
  1490. post['材料费'] = str(qdclf)
  1491. post['机械费'] = str(qdjxf)
  1492. post['管理费'] = 0
  1493. post['利润'] = 0
  1494. for entry in children:
  1495. post['管理费'] = post['管理费'] + float(entry['管理费']) * float(entry['数量'])
  1496. post['利润'] = post['利润'] + float(entry['利润']) * float(entry['数量'])
  1497. post['管理费'] = str(post['管理费'])
  1498. post['利润'] = str(post['利润'])
  1499. post['综合单价'] = str(float(post['人工费']) + float(post['材料费']) + float(post['机械费']) + float(post['管理费']) + float(post['利润']))
  1500. post['合价'] = str(float(post['综合单价']) * float(qdsl))
  1501. await collection.replace_one({'_id': post['_id']}, post )
  1502. collection = db["Dwgc"]
  1503. document = await collection.find_one({'biao_id': biao_id, "Dwgcbh": bh})
  1504. hz = document['rcjhz']
  1505. for entry in hz:
  1506. if entry[1] == bm and entry[2] == mingcheng and entry[4] == danwei:
  1507. entry[6] = jiage
  1508. entry[7] = float(jiage) * float(entry[5])
  1509. await collection.update_one({'biao_id': biao_id, "Dwgcbh": bh}, {'$set': {'rcjhz': hz}})
  1510. await zongjiaDwgc(client, biao_id, bh)
  1511. await tbxx(client, biao_id)
  1512. def bjhz_template():
  1513. result = []
  1514. result.append({'序号': '1', '名称': '分部分项工程', '金额': '0', '暂估价': '0', '类别' : '1', '__children': [
  1515. {'序号': '1.1', '名称': '人工费', '金额': '0', '暂估价': '0', '类别' : '1.1'},
  1516. {'序号': '1.2', '名称': '材料费', '金额': '0', '暂估价': '0', '类别' : '1.2'},
  1517. {'序号': '1.3', '名称': '施工机具使用费', '金额': '0', '暂估价': '0', '类别' : '1.3'},
  1518. {'序号': '1.4', '名称': '企业管理费', '金额': '0', '暂估价': '0', '类别' : '1.4'},
  1519. {'序号': '1.5', '名称': '利润', '金额': '0', '暂估价': '0', '类别' : '1.5'}
  1520. ]})
  1521. result.append({'序号': '2', '名称': '措施项目', '金额': '0', '暂估价': '0', '类别' : '2', '__children': [
  1522. {'序号': '2.1', '名称': '单价措施项目费', '金额': '0', '暂估价': '0', '类别' : '2.1'},
  1523. {'序号': '2.2', '名称': '总价措施项目费', '金额': '0', '暂估价': '0', '类别' : '2.2', '__children' : [
  1524. {'序号': '2.2.1', '名称': '其中:安全文明施工措施费', '金额': '0', '暂估价': '0', '类别' : '2.2.1'},]
  1525. }
  1526. ]})
  1527. result.append({'序号': '3', '名称': '其他项目', '金额': '0', '暂估价': '0', '类别' : '3', '__children': [
  1528. {'序号': '3.1', '名称': '其中:暂列金额', '金额': '0', '暂估价': '0', '类别' : '3.1'},
  1529. {'序号': '3.2', '名称': '其中:专业工程暂估价', '金额': '0', '暂估价': '0', '类别' : '3.2'},
  1530. {'序号': '3.3', '名称': '其中:计日工', '金额': '0', '暂估价': '0', '类别' : '3.3'},
  1531. {'序号': '3.4', '名称': '其中:总承包服务费', '金额': '0', '暂估价': '0', '类别' : '3.4'},
  1532. ]})
  1533. result.append({'序号': '4', '名称': '规费', '金额': '0', '暂估价': '0', '类别' : '4', })
  1534. result.append({'序号': '5', '名称': '税金', '金额': '0', '暂估价': '0', '类别' : '5', })
  1535. result.append({'序号': '6', '名称': '工程造价', '金额': '0', '暂估价': '0', '类别' : '6', })
  1536. return result
  1537. async def tbxx(client, biao_id):
  1538. db = client["baojia"]
  1539. collection = db["jingjibiao"]
  1540. document = await collection.find_one({'_id': ObjectId(biao_id)})
  1541. dxgcxx = document['Dxgcxx']
  1542. tbxx = document['TouBiaoXx']
  1543. tbxx['Tbzj'] = '0'
  1544. tbxx['Zgj'] = '0'
  1545. tbxx['Aqwmf'] = '0'
  1546. tbxx['Gf'] = '0'
  1547. dwdx = {}##单位工程映射单项工程
  1548. for dxgc in dxgcxx:
  1549. dxgc['Aqwmf'] = '0'
  1550. dxgc['Gf'] = '0'
  1551. dxgc['Je'] = '0'
  1552. dxgc['Zgj'] = '0'
  1553. mc = dxgc['Dxgcmc']
  1554. Dwgc = dxgc['Dwgc']
  1555. for dwgc in Dwgc:
  1556. Dwgcbh = dwgc['Dwgcbh']
  1557. dwdx[Dwgcbh] = dxgc
  1558. collection = db['Dwgc']
  1559. async for post in collection.find({'biao_id': biao_id}):
  1560. bh = post['Dwgcbh']
  1561. dx = dwdx[bh]
  1562. bjhz = post['bjhz']
  1563. print('######################################################')
  1564. print(bjhz)
  1565. if len(bjhz) == 0:
  1566. pass
  1567. else:
  1568. qtxm = post['qtxm']
  1569. dx['Aqwmf'] = str(float(dx['Aqwmf']) + float(bjhz[1]['__children'][1]['__children'][0]['金额']))
  1570. dx['Gf'] = str(float(dx['Gf']) + float(bjhz[3]['金额']))
  1571. dx['Je'] = str(float(dx['Je']) + float(bjhz[5]['金额']))
  1572. dx['Zgj']= str(float(dx['Zgj']) + float(qtxm[1]['金额']))
  1573. for dxgc in dxgcxx:
  1574. tbxx['Tbzj'] = str(float(tbxx['Tbzj']) + float(dxgc['Je']))
  1575. tbxx['Zgj'] = str(float(tbxx['Zgj']) + float(dxgc['Zgj']))
  1576. tbxx['Aqwmf'] = str(float(tbxx['Aqwmf']) + float(dxgc['Aqwmf']))
  1577. tbxx['Gf'] = str(float(tbxx['Gf']) + float(dxgc['Gf']))
  1578. collection = db["jingjibiao"]
  1579. await collection.update_one({'_id': ObjectId(biao_id)}, {'$set': {'Dxgcxx': dxgcxx, 'TouBiaoXx' : tbxx}})
  1580. async def zongjiaDwgc(client, biao_id, bh):
  1581. db = client["baojia"]
  1582. djcs_sum = 0
  1583. collection = db["Djcs"]
  1584. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  1585. djcs_sum = djcs_sum + float(post['合价'])
  1586. collection = db['Dwgc']
  1587. document = await collection.find_one({'biao_id': biao_id, "Dwgcbh": bh}, {'rcjhz': 0})
  1588. qdbt = document['qdbt']
  1589. qdbt_addition = document['qdbt_addition']
  1590. bts = {}
  1591. distinguish = True
  1592. for item in qdbt_addition:
  1593. bts[item['Mc']] = 0
  1594. collection = db["qdxm"]
  1595. qd_sum = 0
  1596. rgf_sum = 0
  1597. clf_sum = 0
  1598. jxf_sum = 0
  1599. glf_sum = 0
  1600. lr_sum = 0
  1601. fbrgycl_sum = 0
  1602. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  1603. qd_sum = qd_sum + float(post['合价'])
  1604. rgf_sum = rgf_sum + float(post['数量']) * float(post['人工费'])
  1605. clf_sum = clf_sum + float(post['数量']) * float(post['材料费'])
  1606. jxf_sum = jxf_sum + float(post['数量']) * float(post['机械费'])
  1607. glf_sum = glf_sum + float(post['数量']) * float(post['管理费'])
  1608. lr_sum = lr_sum + float(post['数量']) * float(post['利润'])
  1609. if distinguish and post['bt'] in bts:
  1610. bts[post['bt']] = bts[post['bt']] + float(post['合价'])
  1611. sum = qd_sum + djcs_sum
  1612. fbrgycl = document['fbrgycl']
  1613. for entry in fbrgycl:
  1614. fbrgycl_sum = fbrgycl_sum + float(entry['合价'])
  1615. zjcs = document['zjcs']
  1616. def process(n):
  1617. n['计算基数'] = str(sum)
  1618. n['金额'] = float(sum) * float(n['费率']) / float(100)
  1619. if "__children" in n:
  1620. for entry in n['__children']:
  1621. entry['计算基数'] = str(sum)
  1622. entry['金额'] = float(sum) * float(entry['费率']) / float(100)
  1623. return n
  1624. result = [process(item) for item in zjcs]
  1625. for entry in result:
  1626. if '安全文明施工' in entry['名称']:
  1627. sum_ = 0
  1628. for child in entry['__children']:
  1629. sum_ = sum_ + float(child['金额'])
  1630. entry['金额'] = str(sum_)
  1631. entry['计算基数'] = str(sum_)
  1632. zjcs_sum = 0
  1633. for entry in result:
  1634. zjcs_sum = zjcs_sum + float(entry['金额'])
  1635. qtxm = document['qtxm']##dwgc qtxm
  1636. qtxm_sum = 0
  1637. for entry in qtxm:
  1638. qtxm_sum = qtxm_sum + float(entry['金额'])
  1639. gfsj = document['gfsj']
  1640. gf_sum = 0
  1641. sj_sum = 0
  1642. for item in gfsj:
  1643. if item['名称'] == '规费':
  1644. child = item['__children']
  1645. for children in child:
  1646. children['取费基数'] = str(sum + zjcs_sum + qtxm_sum)
  1647. children['金额'] = str(float(sum + zjcs_sum + qtxm_sum) * float(children['费率']) / float(100))
  1648. gf_sum = gf_sum + float(children['金额'])
  1649. for item in gfsj:
  1650. if item['名称'] == '规费':
  1651. item['取费基数'] = str(gf_sum)
  1652. item['金额'] = str(gf_sum)
  1653. for item in gfsj:
  1654. if item['名称'] == '税金':
  1655. item['取费基数'] = str(sum + zjcs_sum + qtxm_sum + gf_sum - fbrgycl_sum / float(1.01))
  1656. item['金额'] = float(item['取费基数']) * float(item['费率']) / float(100)
  1657. sj_sum = float(item['金额'])
  1658. for item in gfsj:
  1659. if item['名称'] == '合计':
  1660. item['取费基数'] = str(sj_sum + gf_sum)
  1661. item['金额'] = item['取费基数']
  1662. qtxm = document['qtxm']
  1663. zlje = 0
  1664. zygczgj = 0
  1665. jrg = 0
  1666. zcbfwf = 0
  1667. clzgj = 0
  1668. for entry in qtxm:
  1669. if entry['序号'] == '1':
  1670. zlje = entry['金额']
  1671. if entry['序号'] == '3':
  1672. jrg = entry['金额']
  1673. if entry['序号'] == '4':
  1674. zcbfwf = entry['金额']
  1675. if entry['序号'] == '2':
  1676. for child in entry['__children']:
  1677. if child['序号'] == '2.2':
  1678. zygczgj = child['金额']
  1679. if child['序号'] == '2.1':
  1680. clzgj = child['金额']
  1681. qtxm_sum = float(zlje) + float(zygczgj) + float(jrg) + float(zcbfwf) + float(clzgj)
  1682. bjhz = bjhz_template()
  1683. for entry in bjhz:
  1684. if entry['序号'] == '1':
  1685. entry['金额'] = qd_sum
  1686. for child in entry['__children']:
  1687. if child['序号'] == '1.1':
  1688. child['金额'] = str(rgf_sum)
  1689. if child['序号'] == '1.2':
  1690. child['金额'] = str(clf_sum)
  1691. if child['序号'] == '1.3':
  1692. child['金额'] = str(jxf_sum)
  1693. if child['序号'] == '1.4':
  1694. child['金额'] = str(glf_sum)
  1695. if child['序号'] == '1.5':
  1696. child['金额'] = str(lr_sum)
  1697. if entry['序号'] == '2':
  1698. entry['金额'] = str(djcs_sum + zjcs_sum)
  1699. for child in entry['__children']:
  1700. if child['序号'] == '2.1':
  1701. child['金额'] = str(djcs_sum)
  1702. if child['序号'] == '2.2':
  1703. child['金额'] = str(zjcs_sum)
  1704. for grandchild in child['__children']:
  1705. if grandchild['序号'] == '2.2.1':
  1706. grandchild['金额'] = str(sum_)
  1707. if entry['序号'] == '3':
  1708. entry['金额'] = str(qtxm_sum)
  1709. if entry['序号'] == '4':
  1710. entry['金额'] = str(gf_sum)
  1711. if entry['序号'] == '5':
  1712. entry['金额'] = str(sj_sum)
  1713. if entry['序号'] == '6':
  1714. entry['金额'] = str(float(qd_sum) + float(djcs_sum) + float(zjcs_sum) + float(qtxm_sum) + float(gf_sum) + float(sj_sum))
  1715. collection = db['Dwgc']
  1716. if distinguish:
  1717. for entry in qdbt_addition:
  1718. entry['Je'] = str(bts[entry['Mc']])
  1719. await collection.update_one({'biao_id': biao_id, "Dwgcbh": bh}, {'$set': {'zjcs': result, 'gfsj' : gfsj, 'bjhz': bjhz, 'qdbt_addition' : qdbt_addition}})