db.py 85 KB

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