db.py 84 KB

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