db.py 82 KB

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