db.py 95 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210
  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, key):
  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 and child.attrib['key'] == key:
  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, key):
  68. if bt == 'Default':
  69. return getDingercj_default(root, bh, bt, qdbm, debm, key)
  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 and child.attrib['key'] == key:
  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, key):
  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 and child.attrib['key'] == key:
  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 '10000F' in entry[1]:
  389. result.append({
  390. "id": str(uuid.uuid4()),
  391. "主材标志": "true",
  392. "主要材料标志": "true",
  393. "产地": "",
  394. "人材机类别": "2",
  395. "人材机编码": entry[1],
  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["清单编码"], child['key'])
  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["清单编码"], child['key'])
  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. ###################################build xml file##################################
  595. async def build(client, root, id):
  596. db = client["baojia"]
  597. collection = db["jingjibiao"]
  598. document = await collection.find_one({'_id': ObjectId(id)})
  599. root.set('BiaoDuanNO', document['BiaoDuanNO'])
  600. root.set('Jsfs', document['Jsfs'])
  601. root.set('Version', document['Version'])
  602. root.set('Xmmc', document['Xmmc'])
  603. TouBiaoXx = ET.SubElement(root, 'TouBiaoXx')
  604. ##{'Tbzj' : '', 'Zgj' : '', 'Aqwmf' : '', 'Gf' : '' }
  605. TouBiaoXx.set('Tbzj', roundstr(document['TouBiaoXx']['Tbzj']))
  606. TouBiaoXx.set('Zgj', roundstr(document['TouBiaoXx']['Zgj']))
  607. TouBiaoXx.set('Aqwmf', roundstr(document['TouBiaoXx']['Aqwmf']))
  608. TouBiaoXx.set('Gf', roundstr(document['TouBiaoXx']['Gf']))
  609. if 'Zbr' in document['TouBiaoXx']:
  610. TouBiaoXx.set('Zbr', str(document['TouBiaoXx']['Zbr']))
  611. if 'Tbr' in document['TouBiaoXx']:
  612. TouBiaoXx.set('Tbr', str(document['TouBiaoXx']['Tbr']))
  613. if 'TbrDb' in document['TouBiaoXx']:
  614. TouBiaoXx.set('TbrDb', str(document['TouBiaoXx']['TbrDb']))
  615. if 'Bzr' in document['TouBiaoXx']:
  616. TouBiaoXx.set('Bzr', str(document['TouBiaoXx']['Bzr']))
  617. if 'BzTime' in document['TouBiaoXx']:
  618. TouBiaoXx.set('BzTime', str(document['TouBiaoXx']['BzTime']))
  619. for item in document['Dxgcxx']:
  620. Dxgcxx = ET.SubElement(root, 'Dxgcxx')
  621. Dxgcxx.set('Dxgcbh', str(item['Dxgcbh']))
  622. Dxgcxx.set('Dxgcmc', str(item['Dxgcmc']))
  623. Dxgcxx.set('Je', roundstr(item['Je']))
  624. Dxgcxx.set('Zgj', roundstr(item['Zgj']))
  625. Dxgcxx.set('Aqwmf', roundstr(item['Aqwmf']))
  626. Dxgcxx.set('Gf', roundstr(item['Gf']))
  627. for entry in item['Dwgc']:
  628. Dwgcxx = ET.SubElement(Dxgcxx, 'Dwgcxx')
  629. Dwgcxx.set('Dwgcbh', str(entry['Dwgcbh']))
  630. Dwgcxx.set('Dwgcmc', str(entry['Dwgcmc']))
  631. Dwgcxx.set('Zylb', str(entry['Zylb']))
  632. Dwgcxx.set('SoftName', str(entry['SoftName']))
  633. Dwgcxx.set('SoftNum', str(entry['SoftNum']))
  634. Dwgcxx.set('DogNum', str(entry['DogNum']))
  635. Dwgcxx.set('MachineKey', str(entry['MachineKey']))
  636. collection = db["Dwgc"]
  637. Dwgc = await collection.find_one({'biao_id': id, "Dwgcbh": entry['Dwgcbh']})
  638. bjhz = dfs(Dwgc['bjhz'])
  639. gfsj = dfs2(Dwgc['gfsj'])
  640. qtxm = dfs3(Dwgc['qtxm'])
  641. zlje = Dwgc['zlje']
  642. zygczgj = Dwgc['zygczgj']
  643. jrg = Dwgc['jrg']
  644. zcbfwf = Dwgc['zcbfwf']
  645. fbrgycl = Dwgc['fbrgycl']
  646. rcjhz = Dwgc['rcjhz']
  647. zjcs = Dwgc['zjcs']
  648. qdbt = Dwgc['qdbt']
  649. ########################################Fywj##########################
  650. Fywj = ET.SubElement(Dwgcxx, 'Fywj')
  651. for bjhz_ in bjhz:
  652. FywjMx = ET.SubElement(Fywj, 'FywjMx')
  653. FywjMx.set('Xh', str(bjhz_[0]))
  654. FywjMx.set('Mc', str(bjhz_[1]))
  655. FywjMx.set('Je', roundstr(bjhz_[2]))
  656. FywjMx.set('Zgj', roundstr(bjhz_[3]))
  657. FywjMx.set('Fyxlb', str(bjhz_[4]))
  658. ########################################Gfsj##########################
  659. Gfsj = ET.SubElement(Dwgcxx, 'Gfsj')
  660. for gfsj_ in gfsj:
  661. GfsjMx = ET.SubElement(Gfsj, 'GfsjMx')
  662. GfsjMx.set('Xh', str(gfsj_[0]))
  663. GfsjMx.set('Mc', str(gfsj_[1]))
  664. GfsjMx.set('Qfjs', roundstr(gfsj_[2]))
  665. GfsjMx.set('Jsjc', str(gfsj_[3]))
  666. GfsjMx.set('Fl', str(gfsj_[4]))
  667. GfsjMx.set('Je', roundstr(gfsj_[5]))
  668. GfsjMx.set('Fyxlb', str(gfsj_[6]))
  669. ########################################Qdxm##########################
  670. Qdxm = ET.SubElement(Dwgcxx, 'Qdxm')
  671. if 'Default' in qdbt:
  672. collection = db["qdxm"]
  673. before_sort = []
  674. async for post in collection.find({"biao_id": id, "Dwgcbh": entry['Dwgcbh'], 'bt': 'Default'}):
  675. before_sort.append(post)
  676. after_sort = sorted(before_sort, key=lambda x: int(x['序号']))
  677. for qdmx in after_sort:
  678. Qdmx = ET.SubElement(Qdxm, 'Qdmx')
  679. Qdmx.set('Xh', str(qdmx['序号']))
  680. Qdmx.set('Qdbm', str(qdmx['清单编码']))
  681. Qdmx.set('Mc', str(qdmx['名称']))
  682. Qdmx.set('Xmtz', str(qdmx['项目特征']))
  683. Qdmx.set('Jsgz', str(qdmx['计算规则']))
  684. Qdmx.set('Dw', str(qdmx['单位']))
  685. Qdmx.set('Sl', roundstr4(qdmx['数量']))
  686. Qdmx.set('Zhdj', roundstr4(qdmx['综合单价']))
  687. Qdmx.set('Zhhj', roundstr4(qdmx['合价']))
  688. Qdmx.set('Rgf', roundstr4(qdmx['人工费']))
  689. Qdmx.set('Zcf', roundstr4(qdmx['主材费']))
  690. Qdmx.set('Sbf', roundstr4(qdmx['设备费']))
  691. Qdmx.set('Fcf', roundstr4(qdmx['辅材费']))
  692. Qdmx.set('Clf', roundstr4(qdmx['材料费']))
  693. Qdmx.set('Jxf', roundstr4(qdmx['机械费']))
  694. Qdmx.set('Glf', roundstr4(qdmx['管理费']))
  695. Qdmx.set('Lr', roundstr4(qdmx['利润']))
  696. Qdmx.set('Zgj', roundstr4(qdmx['暂估价']))
  697. Qdmx.set('Zgr', roundstr4(qdmx['综合人工工日']))
  698. Qdmx.set('Bz', str(qdmx['备注']))
  699. Qdxdezj = ET.SubElement(Qdmx, 'Qdxdezj')
  700. if '__children' in qdmx:
  701. for child in qdmx['__children']:
  702. QdxdezjMx = ET.SubElement(Qdxdezj, 'QdxdezjMx')
  703. QdxdezjMx.set('Debm', str(child['清单编码']))
  704. QdxdezjMx.set('Mc', str(child['名称']))
  705. QdxdezjMx.set('Dw', str(child['单位']))
  706. QdxdezjMx.set('DwQdSl', roundstr4(child['数量']))
  707. QdxdezjMx.set('Dj', roundstr4(child['综合单价']))
  708. QdxdezjMx.set('Hj', roundstr4(child['合价']))
  709. QdxdezjMx.set('Rgf', roundstr4(child['人工费']))
  710. QdxdezjMx.set('Zcf', roundstr4(child['主材费']))
  711. QdxdezjMx.set('Sbf', roundstr4(child['设备费']))
  712. QdxdezjMx.set('Fcf', roundstr4(child['辅材费']))
  713. QdxdezjMx.set('Clf', roundstr4(child['材料费']))
  714. QdxdezjMx.set('Jxf', roundstr4(child['机械费']))
  715. QdxdezjMx.set('Glf', roundstr4(child['管理费']))
  716. QdxdezjMx.set('Lr', roundstr4(child['利润']))
  717. Qdxdercjhl = ET.SubElement(QdxdezjMx, 'Qdxdercjhl')
  718. for i in range(len(child['dercj'])):
  719. if i == 0:
  720. pass
  721. else:
  722. QdxdercjhlMx = ET.SubElement(Qdxdercjhl, 'QdxdercjhlMx')
  723. QdxdercjhlMx.set('RcjId', util.indexrcj(rcjhz, child['dercj'][i]))
  724. QdxdercjhlMx.set('Rcjhl', roundstr4(child['dercj'][i][10]))
  725. QdxdercjhlMx.set('Rcjhj', roundstr4(child['dercj'][i][11]))
  726. Qdxrcjhl = ET.SubElement(Qdmx, 'Qdxrcjhl')
  727. for i in range(len(qdmx['rcj'])):
  728. if i == 0:
  729. pass
  730. else:
  731. QdxrcjhlMx = ET.SubElement(Qdxrcjhl, 'QdxrcjhlMx')
  732. QdxrcjhlMx.set('RcjId', util.indexrcj(rcjhz, qdmx['rcj'][i]))
  733. ##str(djcs['rcj'][i][0]))
  734. QdxrcjhlMx.set('Rcjhl', roundstr4(qdmx['rcj'][i][10]))
  735. QdxrcjhlMx.set('Rcjhj', roundstr4(qdmx['rcj'][i][11]))
  736. QdxrcjhlMx.set('Zgjbz', str(qdmx['rcj'][i][12]))
  737. QdxrcjhlMx.set('Zyclbz', str(qdmx['rcj'][i][13]))
  738. QdxrcjhlMx.set('Zcbz', str(qdmx['rcj'][i][14]))
  739. QdxrcjhlMx.set('Sbbz', str(qdmx['rcj'][i][15]))
  740. qdbt_addition = Dwgc['qdbt_addition']
  741. for bt in qdbt_addition:
  742. QdBt = ET.SubElement(Qdxm, 'QdBt')
  743. QdBt.set('Xh', bt['Xh'])
  744. QdBt.set('Mc', bt['Mc'])
  745. QdBt.set('Je', roundstr(bt['Je']))
  746. QdBt.set('Zgj', roundstr(bt['Zgj']))
  747. QdBt.set('Bz', bt['Bz'])
  748. collection = db["qdxm"]
  749. before_sort = []
  750. async for post in collection.find({"biao_id": id, "Dwgcbh": entry['Dwgcbh'], 'bt': bt['Mc']}):
  751. before_sort.append(post)
  752. after_sort = sorted(before_sort, key=lambda x: int(x['序号']))
  753. for qdmx in after_sort:
  754. Qdmx = ET.SubElement(QdBt, 'Qdmx')
  755. Qdmx.set('Xh', str(qdmx['序号']))
  756. Qdmx.set('Qdbm', str(qdmx['清单编码']))
  757. Qdmx.set('Mc', str(qdmx['名称']))
  758. Qdmx.set('Xmtz', str(qdmx['项目特征']))
  759. Qdmx.set('Jsgz', str(qdmx['计算规则']))
  760. Qdmx.set('Dw', str(qdmx['单位']))
  761. Qdmx.set('Sl', roundstr4(qdmx['数量']))
  762. Qdmx.set('Zhdj', roundstr4(qdmx['综合单价']))
  763. Qdmx.set('Zhhj', roundstr4(qdmx['合价']))
  764. Qdmx.set('Rgf', roundstr4(qdmx['人工费']))
  765. Qdmx.set('Zcf', roundstr4(qdmx['主材费']))
  766. Qdmx.set('Sbf', roundstr4(qdmx['设备费']))
  767. Qdmx.set('Fcf', roundstr4(qdmx['辅材费']))
  768. Qdmx.set('Clf', roundstr4(qdmx['材料费']))
  769. Qdmx.set('Jxf', roundstr4(qdmx['机械费']))
  770. Qdmx.set('Glf', roundstr4(qdmx['管理费']))
  771. Qdmx.set('Lr', roundstr4(qdmx['利润']))
  772. Qdmx.set('Zgj', roundstr4(qdmx['暂估价']))
  773. Qdmx.set('Zgr', roundstr4(qdmx['综合人工工日']))
  774. Qdmx.set('Bz', str(qdmx['备注']))
  775. Qdxdezj = ET.SubElement(Qdmx, 'Qdxdezj')
  776. if '__children' in qdmx:
  777. for child in qdmx['__children']:
  778. QdxdezjMx = ET.SubElement(Qdxdezj, 'QdxdezjMx')
  779. QdxdezjMx.set('Debm', str(child['清单编码']))
  780. QdxdezjMx.set('Mc', str(child['名称']))
  781. QdxdezjMx.set('Dw', str(child['单位']))
  782. QdxdezjMx.set('DwQdSl', roundstr4(child['数量']))
  783. QdxdezjMx.set('Dj', roundstr4(child['综合单价']))
  784. QdxdezjMx.set('Hj', roundstr4(child['合价']))
  785. QdxdezjMx.set('Rgf', roundstr4(child['人工费']))
  786. QdxdezjMx.set('Zcf', roundstr4(child['主材费']))
  787. QdxdezjMx.set('Sbf', roundstr4(child['设备费']))
  788. QdxdezjMx.set('Fcf', roundstr4(child['辅材费']))
  789. QdxdezjMx.set('Clf', roundstr4(child['材料费']))
  790. QdxdezjMx.set('Jxf', roundstr4(child['机械费']))
  791. QdxdezjMx.set('Glf', roundstr4(child['管理费']))
  792. QdxdezjMx.set('Lr', roundstr4(child['利润']))
  793. Qdxdercjhl = ET.SubElement(QdxdezjMx, 'Qdxdercjhl')
  794. for i in range(len(child['dercj'])):
  795. if i == 0:
  796. pass
  797. else:
  798. QdxdercjhlMx = ET.SubElement(Qdxdercjhl, 'QdxdercjhlMx')
  799. QdxdercjhlMx.set('RcjId', util.indexrcj(rcjhz, child['dercj'][i]))
  800. QdxdercjhlMx.set('Rcjhl', roundstr4(child['dercj'][i][10]))
  801. QdxdercjhlMx.set('Rcjhj', roundstr4(child['dercj'][i][11]))
  802. Qdxrcjhl = ET.SubElement(Qdmx, 'Qdxrcjhl')
  803. for i in range(len(qdmx['rcj'])):
  804. if i == 0:
  805. pass
  806. else:
  807. QdxrcjhlMx = ET.SubElement(Qdxrcjhl, 'QdxrcjhlMx')
  808. QdxrcjhlMx.set('RcjId', util.indexrcj(rcjhz, qdmx['rcj'][i]))
  809. ##str(djcs['rcj'][i][0]))
  810. QdxrcjhlMx.set('Rcjhl', roundstr4(qdmx['rcj'][i][10]))
  811. QdxrcjhlMx.set('Rcjhj', roundstr4(qdmx['rcj'][i][11]))
  812. QdxrcjhlMx.set('Zgjbz', str(qdmx['rcj'][i][12]))
  813. QdxrcjhlMx.set('Zyclbz', str(qdmx['rcj'][i][13]))
  814. QdxrcjhlMx.set('Zcbz', str(qdmx['rcj'][i][14]))
  815. QdxrcjhlMx.set('Sbbz', str(qdmx['rcj'][i][15]))
  816. ########################################Csxm##########################
  817. Csxm = ET.SubElement(Dwgcxx, 'Csxm')
  818. ZjCs = ET.SubElement(Csxm, 'ZjCs')
  819. for zjcs_ in zjcs:
  820. ZjCsMx = ET.SubElement(ZjCs, 'ZjCsMx')
  821. ZjCsMx.set('Xh', str(zjcs_['序号']))
  822. ZjCsMx.set('Bm', str(zjcs_['清单编码']))
  823. ZjCsMx.set('Mc', str(zjcs_['名称']))
  824. ZjCsMx.set('Js', roundstr(zjcs_['计算基数']))
  825. ZjCsMx.set('Jsjc', str(zjcs_['计算基础']))
  826. ZjCsMx.set('Fl', str(zjcs_['费率']))
  827. ZjCsMx.set('Je', roundstr(zjcs_['金额']))
  828. ZjCsMx.set('Xmlb', str(zjcs_['项目类别']))
  829. if '__children' in zjcs_:
  830. AqwmfMx = ET.SubElement(ZjCsMx, 'AqwmfMx')
  831. AqwmfMx.set('Mc', str(zjcs_['__children'][0]['名称']))
  832. AqwmfMx.set('Js', roundstr(zjcs_['__children'][0]['计算基数']))
  833. AqwmfMx.set('Jsjc', str(zjcs_['__children'][0]['计算基础']))
  834. AqwmfMx.set('Fl', str(zjcs_['__children'][0]['费率']))
  835. AqwmfMx.set('Je', roundstr(zjcs_['__children'][0]['金额']))
  836. AqwmfMx.set('Xmlb', str(zjcs_['__children'][0]['项目类别']))
  837. AqwmfMx = ET.SubElement(ZjCsMx, 'AqwmfMx')
  838. AqwmfMx.set('Mc', str(zjcs_['__children'][1]['名称']))
  839. AqwmfMx.set('Js', roundstr(zjcs_['__children'][1]['计算基数']))
  840. AqwmfMx.set('Jsjc', str(zjcs_['__children'][1]['计算基础']))
  841. AqwmfMx.set('Fl', str(zjcs_['__children'][1]['费率']))
  842. AqwmfMx.set('Je', roundstr(zjcs_['__children'][1]['金额']))
  843. AqwmfMx.set('Xmlb', str(zjcs_['__children'][1]['项目类别']))
  844. AqwmfMx = ET.SubElement(ZjCsMx, 'AqwmfMx')
  845. AqwmfMx.set('Mc', str(zjcs_['__children'][2]['名称']))
  846. AqwmfMx.set('Js', roundstr(zjcs_['__children'][2]['计算基数']))
  847. AqwmfMx.set('Jsjc', str(zjcs_['__children'][2]['计算基础']))
  848. AqwmfMx.set('Fl', str(zjcs_['__children'][2]['费率']))
  849. AqwmfMx.set('Je', roundstr(zjcs_['__children'][2]['金额']))
  850. AqwmfMx.set('Xmlb', str(zjcs_['__children'][2]['项目类别']))
  851. DjCs = ET.SubElement(Csxm, 'DjCs')
  852. collection = db["Djcs"]
  853. before_sort = []
  854. async for post in collection.find({"biao_id": id, "Dwgcbh": entry['Dwgcbh']}):
  855. before_sort.append(post)
  856. after_sort = sorted(before_sort, key=lambda x: int(x['序号']))
  857. for djcs in after_sort:
  858. DjCsMx = ET.SubElement(DjCs, 'DjCsMx')
  859. DjCsMx.set('Xh', str(djcs['序号']))
  860. DjCsMx.set('Bm', str(djcs['清单编码']))
  861. DjCsMx.set('Mc', str(djcs['名称']))
  862. DjCsMx.set('Xmtz', str(djcs['项目特征']))
  863. DjCsMx.set('Jsgz', str(djcs['计算规则']))
  864. DjCsMx.set('Dw', str(djcs['单位']))
  865. DjCsMx.set('Sl', roundstr4(djcs['数量']))
  866. DjCsMx.set('Zhdj', roundstr4(djcs['综合单价']))
  867. DjCsMx.set('Zhhj', roundstr4(djcs['合价']))
  868. DjCsMx.set('Rgf', roundstr4(djcs['人工费']))
  869. DjCsMx.set('Zcf', roundstr4(djcs['主材费']))
  870. DjCsMx.set('Sbf', roundstr4(djcs['设备费']))
  871. DjCsMx.set('Fcf', roundstr4(djcs['辅材费']))
  872. DjCsMx.set('Clf', roundstr4(djcs['材料费']))
  873. DjCsMx.set('Jxf', roundstr4(djcs['机械费']))
  874. DjCsMx.set('Glf', roundstr4(djcs['管理费']))
  875. DjCsMx.set('Lr', roundstr4(djcs['利润']))
  876. DjCsMx.set('Zgj', roundstr4(djcs['暂估价']))
  877. DjCsMx.set('Zgr', roundstr4(djcs['综合人工工日']))
  878. Csxdezj = ET.SubElement(DjCsMx, 'Csxdezj')
  879. if '__children' in djcs:
  880. for child in djcs['__children']:
  881. CsxdezjMx = ET.SubElement(Csxdezj, 'CsxdezjMx')
  882. CsxdezjMx.set('Debm', str(child['清单编码']))
  883. CsxdezjMx.set('Mc', str(child['名称']))
  884. CsxdezjMx.set('Dw', str(child['单位']))
  885. CsxdezjMx.set('DwQdSl', roundstr4(child['数量']))
  886. CsxdezjMx.set('Dj', roundstr4(child['综合单价']))
  887. CsxdezjMx.set('Hj', roundstr4(child['合价']))
  888. CsxdezjMx.set('Rgf', roundstr4(child['人工费']))
  889. CsxdezjMx.set('Zcf', roundstr4(child['主材费']))
  890. CsxdezjMx.set('Sbf', roundstr4(child['设备费']))
  891. CsxdezjMx.set('Fcf', roundstr4(child['辅材费']))
  892. CsxdezjMx.set('Clf', roundstr4(child['材料费']))
  893. CsxdezjMx.set('Jxf', roundstr4(child['机械费']))
  894. CsxdezjMx.set('Glf', roundstr4(child['管理费']))
  895. CsxdezjMx.set('Lr', roundstr4(child['利润']))
  896. Csxdercjhl = ET.SubElement(CsxdezjMx, 'Csxdercjhl')
  897. for i in range(len(child['dercj'])):
  898. if i == 0:
  899. pass
  900. else:
  901. CsxdercjhlMx = ET.SubElement(Csxdercjhl, 'CsxdercjhlMx')
  902. CsxdercjhlMx.set('RcjId', util.indexrcj(rcjhz, child['dercj'][i]))
  903. CsxdercjhlMx.set('Rcjhl', roundstr4(child['dercj'][i][10]))
  904. CsxdercjhlMx.set('Rcjhj', roundstr4(child['dercj'][i][11]))
  905. Csxrcjhl = ET.SubElement(DjCsMx, 'Csxrcjhl')
  906. for i in range(len(djcs['rcj'])):
  907. if i == 0:
  908. pass
  909. else:
  910. CsxrcjhlMx = ET.SubElement(Csxrcjhl, 'CsxrcjhlMx')
  911. CsxrcjhlMx.set('RcjId', util.indexrcj(rcjhz, djcs['rcj'][i]))
  912. ##str(djcs['rcj'][i][0]))
  913. CsxrcjhlMx.set('Rcjhl', roundstr4(djcs['rcj'][i][10]))
  914. CsxrcjhlMx.set('Rcjhj', roundstr4(djcs['rcj'][i][11]))
  915. CsxrcjhlMx.set('Zgjbz', str(djcs['rcj'][i][12]))
  916. CsxrcjhlMx.set('Zyclbz', str(djcs['rcj'][i][13]))
  917. CsxrcjhlMx.set('Zcbz', str(djcs['rcj'][i][14]))
  918. CsxrcjhlMx.set('Sbbz', str(djcs['rcj'][i][15]))
  919. ########################################Qtxm##########################
  920. Qtxm = ET.SubElement(Dwgcxx, 'Qtxm')
  921. for qtxm_ in qtxm:
  922. QtxmMx = ET.SubElement(Qtxm, 'QtxmMx')
  923. QtxmMx.set('Xh', str(qtxm_[0]))
  924. QtxmMx.set('Mc', str(qtxm_[1]))
  925. QtxmMx.set('Je', roundstr(qtxm_[2]))
  926. QtxmMx.set('Xmlb', str(qtxm_[3]))
  927. QtxmMx.set('Bz', str(qtxm_[4]))
  928. Zlje = ET.SubElement(Dwgcxx, 'Zlje')
  929. for i in range(len(zlje)):
  930. ZljeMx = ET.SubElement(Zlje, 'ZljeMx')
  931. ZljeMx.set('Xh', str(zlje[i]['序号']))
  932. ZljeMx.set('Mc', str(zlje[i]['名称']))
  933. ZljeMx.set('Dw', str(zlje[i]['单位']))
  934. ZljeMx.set('Zdje', roundstr(zlje[i]['暂定金额']))
  935. ZljeMx.set('Bz', str(zlje[i]['备注']))
  936. Clzg = ET.SubElement(Dwgcxx, 'Clzg')
  937. Zygczg = ET.SubElement(Dwgcxx, 'Zygczg')
  938. for zygczgj_ in zygczgj:
  939. ZygczgMx = ET.SubElement(Zygczg, 'ZygczgMx')
  940. ZygczgMx.set('Xh', str(zygczgj_['序号']))
  941. ZygczgMx.set('Mc', str(zygczgj_['名称']))
  942. ZygczgMx.set('Gcnr', str(zygczgj_['工程内容']))
  943. ZygczgMx.set('Je', roundstr(zygczgj_['金额']))
  944. ZygczgMx.set('Bz', str(zygczgj_['备注']))
  945. Jrg = ET.SubElement(Dwgcxx, 'Jrg')
  946. for jrg_ in jrg:
  947. JrgBt = ET.SubElement(Jrg, 'JrgBt')
  948. JrgBt.set('Xh', str(jrg_['序号']))
  949. JrgBt.set('Mc', str(jrg_['名称']))
  950. JrgBt.set('Je', roundstr(jrg_['金额']))
  951. JrgBt.set('Lb', str(jrg_['类别']))
  952. Zcbfwf = ET.SubElement(Dwgcxx, 'Zcbfwf')
  953. for zcbfwf_ in zcbfwf:
  954. ZcbfwfMx = ET.SubElement(Zcbfwf, 'ZcbfwfMx')
  955. ZcbfwfMx.set('Xh', str(zcbfwf_['序号']))
  956. ZcbfwfMx.set('Mc', str(zcbfwf_['名称']))
  957. ZcbfwfMx.set('Xmjz', roundstr(zcbfwf_['项目价值']))
  958. ZcbfwfMx.set('Fwnr', str(zcbfwf_['服务内容']))
  959. ZcbfwfMx.set('Jsjc', str(zcbfwf_['计算基础']))
  960. ZcbfwfMx.set('Fl', str(zcbfwf_['费率']))
  961. ZcbfwfMx.set('Je', roundstr(zcbfwf_['金额']))
  962. Zjxmjdkzffj = ET.SubElement(Dwgcxx, 'Zjxmjdkzffj')
  963. Fbrgycl = ET.SubElement(Dwgcxx, 'Fbrgycl')
  964. for fbrgycl_ in fbrgycl:
  965. FbrgyclMx = ET.SubElement(Fbrgycl, 'FbrgyclMx')
  966. FbrgyclMx.set('Xh', str(fbrgycl_['序号']))
  967. FbrgyclMx.set('RcjId', util.indexrcj(rcjhz, [fbrgycl_['序号'], fbrgycl_['材料编号'], fbrgycl_['名称'], fbrgycl_['规格型号'], fbrgycl_['单位']]))
  968. FbrgyclMx.set('Clbh', str(fbrgycl_['材料编号']))
  969. FbrgyclMx.set('Mc', str(fbrgycl_['名称']))
  970. FbrgyclMx.set('Ggxh', str(fbrgycl_['规格型号']))
  971. FbrgyclMx.set('Dw', str(fbrgycl_['单位']))
  972. FbrgyclMx.set('Sl', roundstr4(fbrgycl_['数量']))
  973. FbrgyclMx.set('Dj', roundstr4(fbrgycl_['单价']))
  974. FbrgyclMx.set('Hj', roundstr4(fbrgycl_['合价']))
  975. FbrgyclMx.set('Jhfs', str(fbrgycl_['交货方式']))
  976. FbrgyclMx.set('Sddd', str(fbrgycl_['送达地点']))
  977. FbrgyclMx.set('Bz', str(fbrgycl_['备注']))
  978. Cbrgycl = ET.SubElement(Dwgcxx, 'Cbrgycl')
  979. Rcjhz = ET.SubElement(Dwgcxx, 'Rcjhz')
  980. for i in range(len(rcjhz)):
  981. if i == 0:
  982. pass
  983. else:
  984. RcjhzMx = ET.SubElement(Rcjhz, 'RcjhzMx')
  985. RcjhzMx.set('RcjId', str(i))
  986. RcjhzMx.set('RcjBm', str(rcjhz[i][1]))
  987. RcjhzMx.set('Mc', str(rcjhz[i][2]))
  988. RcjhzMx.set('Ggxh', str(rcjhz[i][3]))
  989. RcjhzMx.set('Dw', str(rcjhz[i][4]))
  990. RcjhzMx.set('Sl', roundstr4(rcjhz[i][5]))
  991. RcjhzMx.set('Dj', roundstr4(rcjhz[i][6]))
  992. RcjhzMx.set('Hj', roundstr4(rcjhz[i][7]))
  993. RcjhzMx.set('Cd', str(rcjhz[i][8]))
  994. RcjhzMx.set('Gycs', str(rcjhz[i][9]))
  995. RcjhzMx.set('Rcjlb', str(rcjhz[i][10]))
  996. RcjhzMx.set('Zyclbz', str(rcjhz[i][11]))
  997. RcjhzMx.set('Zcbz', str(rcjhz[i][12]))
  998. RcjhzMx.set('Sbbz', str(rcjhz[i][13]))
  999. RcjhzMx.set('Jgbz', str(rcjhz[i][14]))
  1000. RcjhzMx.set('Zgjbz', str(rcjhz[i][15]))
  1001. ############################end of build xml file#################################
  1002. async def delete_files(client, id):
  1003. db = client["baojia"]
  1004. collection = db["jingjibiao"]
  1005. result = []
  1006. await collection.update_one({'_id': ObjectId(id)}, {'$set': {'visible': False}})
  1007. return result
  1008. async def list_files(client):
  1009. db = client["baojia"]
  1010. collection = db["jingjibiao"]
  1011. result = []
  1012. async for post in collection.find({"visible": True}):
  1013. result.append([str(post['_id']), post["Xmmc"], post['created'] if 'created' in post else ""])
  1014. return result
  1015. def getDwgc(id, Zylb):
  1016. result = []
  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. del post["_id"]
  1125. result.append(post)
  1126. return result
  1127. async def getDjcsQingdanrcj(client, name, bh, bt, bm):
  1128. db = client["baojia"]
  1129. collection = db["Djcs"]
  1130. document = await collection.find_one({ "Dwgcbh": bh, "清单编码": bm, "biao_id": name})
  1131. result = document["rcj"]
  1132. return result
  1133. async def getDjcsDingercj(client, name, bh, bt, qdbm, debm):
  1134. db = client["baojia"]
  1135. collection = db["Djcs"]
  1136. document = await collection.find_one({"Dwgcbh": bh, "清单编码": qdbm, "biao_id": name})
  1137. children = document["__children"]
  1138. result = []
  1139. for child in children:
  1140. if child["清单编码"] == debm:
  1141. result = child["dercj"]
  1142. return result
  1143. async def getQdxm(client, name, bh):
  1144. db = client["baojia"]
  1145. collection = db["Dwgc"]
  1146. document = await collection.find_one({'biao_id': name, "Dwgcbh": bh})
  1147. if document:
  1148. return document['qdbt']
  1149. else:
  1150. return []
  1151. async def getQdmx(client, name, bh, bt):
  1152. db = client["baojia"]
  1153. collection = db["qdxm"]
  1154. result = []
  1155. if bt == 'ALL':
  1156. async for post in collection.find({'biao_id': name, "Dwgcbh": bh,}):
  1157. del post["_id"]
  1158. result.append(post)
  1159. else:
  1160. async for post in collection.find({'biao_id': name, "Dwgcbh": bh, "bt": bt}):
  1161. del post["_id"]
  1162. result.append(post)
  1163. return result
  1164. async def getQingdanrcj(client, name, bh, bt, bm):
  1165. db = client["baojia"]
  1166. collection = db["qdxm"]
  1167. document = await collection.find_one({ "Dwgcbh": bh, "清单编码": bm, "biao_id": name, "bt": bt})
  1168. result = document["rcj"]
  1169. return result
  1170. async def getDingercj(client, name, bh, bt, qdbm, debm):
  1171. db = client["baojia"]
  1172. collection = db["qdxm"]
  1173. document = await collection.find_one({"Dwgcbh": bh, "清单编码": qdbm, "biao_id": name, "bt": bt})
  1174. result = []
  1175. if "__children" in document:
  1176. children = document["__children"]
  1177. for child in children:
  1178. if child["清单编码"] == debm:
  1179. result = child["dercj"]
  1180. return result
  1181. async def getQufei(client, id):
  1182. db = client["baojia"]
  1183. collection = db["qufei"]
  1184. document = await collection.find_one({'biao_id': id})
  1185. return document['qufei']
  1186. async def searchde(client, zhuanye, text):
  1187. db = client["dinge"]
  1188. collection = db["de-collection"]
  1189. result = []
  1190. async for post in collection.find({'$text': {"$search": "\"" + text + "\""}, "zhuanye": zhuanye}):
  1191. result.append(post["DEBH"] + " " + post['GCLMC'] )
  1192. if len(result) > 10:
  1193. break
  1194. return result
  1195. async def getJiagongcai(client, id):
  1196. db = client["baojia"]
  1197. collection = db["Dwgc"]
  1198. result = []
  1199. async for post in collection.find({'biao_id': id}, {'rcjhz': 0}):
  1200. for entry in post['fbrgycl']:
  1201. result.append(entry)
  1202. return result
  1203. ##################################editor_code##########################
  1204. def bjhz_template():
  1205. result = []
  1206. result.append({'序号': '1', '名称': '分部分项工程', '金额': '0', '暂估价': '0', '类别' : '1', '__children': [
  1207. {'序号': '1.1', '名称': '人工费', '金额': '0', '暂估价': '0', '类别' : '1.1'},
  1208. {'序号': '1.2', '名称': '材料费', '金额': '0', '暂估价': '0', '类别' : '1.2'},
  1209. {'序号': '1.3', '名称': '施工机具使用费', '金额': '0', '暂估价': '0', '类别' : '1.3'},
  1210. {'序号': '1.4', '名称': '企业管理费', '金额': '0', '暂估价': '0', '类别' : '1.4'},
  1211. {'序号': '1.5', '名称': '利润', '金额': '0', '暂估价': '0', '类别' : '1.5'}
  1212. ]})
  1213. result.append({'序号': '2', '名称': '措施项目', '金额': '0', '暂估价': '0', '类别' : '2', '__children': [
  1214. {'序号': '2.1', '名称': '单价措施项目费', '金额': '0', '暂估价': '0', '类别' : '2.1'},
  1215. {'序号': '2.2', '名称': '总价措施项目费', '金额': '0', '暂估价': '0', '类别' : '2.2', '__children' : [
  1216. {'序号': '2.2.1', '名称': '其中:安全文明施工措施费', '金额': '0', '暂估价': '0', '类别' : '2.2.1'},]
  1217. }
  1218. ]})
  1219. result.append({'序号': '3', '名称': '其他项目', '金额': '0', '暂估价': '0', '类别' : '3', '__children': [
  1220. {'序号': '3.1', '名称': '其中:暂列金额', '金额': '0', '暂估价': '0', '类别' : '3.1'},
  1221. {'序号': '3.2', '名称': '其中:专业工程暂估价', '金额': '0', '暂估价': '0', '类别' : '3.2'},
  1222. {'序号': '3.3', '名称': '其中:计日工', '金额': '0', '暂估价': '0', '类别' : '3.3'},
  1223. {'序号': '3.4', '名称': '其中:总承包服务费', '金额': '0', '暂估价': '0', '类别' : '3.4'},
  1224. ]})
  1225. result.append({'序号': '4', '名称': '规费', '金额': '0', '暂估价': '0', '类别' : '4', })
  1226. result.append({'序号': '5', '名称': '税金', '金额': '0', '暂估价': '0', '类别' : '5', })
  1227. result.append({'序号': '6', '名称': '工程造价', '金额': '0', '暂估价': '0', '类别' : '6', })
  1228. return result
  1229. async def zongjiaDwgc(client, biao_id, bh):
  1230. db = client["baojia"]
  1231. djcs_sum = 0###单价措施汇总
  1232. collection = db["Djcs"]
  1233. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  1234. djcs_sum = djcs_sum + float(post['合价'])
  1235. collection = db['Dwgc']
  1236. document = await collection.find_one({'biao_id': biao_id, "Dwgcbh": bh}, {'rcjhz': 0})
  1237. qdbt = document['qdbt']
  1238. qdbt_addition = document['qdbt_addition']
  1239. bts = {}
  1240. distinguish = True
  1241. for item in qdbt_addition:
  1242. bts[item['Mc']] = 0
  1243. collection = db["qdxm"]
  1244. qd_sum = 0###清单汇总
  1245. rgf_sum = 0
  1246. clf_sum = 0
  1247. jxf_sum = 0
  1248. glf_sum = 0
  1249. lr_sum = 0
  1250. fbrgycl_sum = 0
  1251. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  1252. qd_sum = qd_sum + float(post['合价'])
  1253. rgf_sum = rgf_sum + float(post['数量']) * float(post['人工费'])
  1254. clf_sum = clf_sum + float(post['数量']) * float(post['材料费'])
  1255. jxf_sum = jxf_sum + float(post['数量']) * float(post['机械费'])
  1256. glf_sum = glf_sum + float(post['数量']) * float(post['管理费'])
  1257. lr_sum = lr_sum + float(post['数量']) * float(post['利润'])
  1258. if distinguish and post['bt'] in bts:
  1259. bts[post['bt']] = bts[post['bt']] + float(post['合价'])
  1260. sum = qd_sum + djcs_sum##作为总价措施和后续费用计算的的计算基础
  1261. fbrgycl = document['fbrgycl']
  1262. for entry in fbrgycl:
  1263. fbrgycl_sum = fbrgycl_sum + float(entry['合价'])
  1264. zjcs = document['zjcs']
  1265. def process(n):
  1266. n['计算基数'] = str(sum)
  1267. n['金额'] = float(sum) * float(n['费率']) / float(100)
  1268. if "__children" in n:
  1269. for entry in n['__children']:
  1270. entry['计算基数'] = str(sum)
  1271. entry['金额'] = float(sum) * float(entry['费率']) / float(100)
  1272. return n
  1273. ##目标数据,会存到数据库
  1274. result = [process(item) for item in zjcs]
  1275. for entry in result:
  1276. if '安全文明施工' in entry['名称']:
  1277. sum_ = 0
  1278. for child in entry['__children']:
  1279. sum_ = sum_ + float(child['金额'])
  1280. entry['金额'] = str(sum_)
  1281. entry['计算基数'] = str(sum_)
  1282. zjcs_sum = 0###总价措施汇总
  1283. for entry in result:
  1284. zjcs_sum = zjcs_sum + float(entry['金额'])
  1285. qtxm = document['qtxm']##dwgc qtxm
  1286. qtxm_sum = 0###其他项目汇总, 为了计算规费税金,其他项目本身不会改变
  1287. for entry in qtxm:
  1288. qtxm_sum = qtxm_sum + float(entry['金额'])
  1289. gfsj = document['gfsj']
  1290. gf_sum = 0###规费税金汇总
  1291. sj_sum = 0
  1292. for item in gfsj:
  1293. if item['名称'] == '规费':
  1294. child = item['__children']
  1295. for children in child:
  1296. children['取费基数'] = str(sum + zjcs_sum + qtxm_sum)
  1297. children['金额'] = str(float(sum + zjcs_sum + qtxm_sum) * float(children['费率']) / float(100))
  1298. gf_sum = gf_sum + float(children['金额'])
  1299. for item in gfsj:
  1300. if item['名称'] == '规费':
  1301. item['取费基数'] = str(gf_sum)
  1302. item['金额'] = str(gf_sum)
  1303. for item in gfsj:
  1304. if item['名称'] == '税金':
  1305. item['取费基数'] = str(sum + zjcs_sum + qtxm_sum + gf_sum - fbrgycl_sum / float(1.01))
  1306. item['金额'] = float(item['取费基数']) * float(item['费率']) / float(100)
  1307. sj_sum = float(item['金额'])
  1308. for item in gfsj:
  1309. if item['名称'] == '合计':
  1310. item['取费基数'] = str(sj_sum + gf_sum)
  1311. item['金额'] = item['取费基数']
  1312. qtxm = document['qtxm']
  1313. zlje = 0
  1314. zygczgj = 0
  1315. jrg = 0
  1316. zcbfwf = 0
  1317. clzgj = 0
  1318. for entry in qtxm:
  1319. if entry['序号'] == '1':
  1320. zlje = entry['金额']
  1321. if entry['序号'] == '3':
  1322. jrg = entry['金额']
  1323. if entry['序号'] == '4':
  1324. zcbfwf = entry['金额']
  1325. if entry['序号'] == '2':
  1326. for child in entry['__children']:
  1327. if child['序号'] == '2.2':
  1328. zygczgj = child['金额']
  1329. if child['序号'] == '2.1':
  1330. clzgj = child['金额']
  1331. ###重新算了一遍其他项目汇总
  1332. qtxm_sum = float(zlje) + float(zygczgj) + float(jrg) + float(zcbfwf) + float(clzgj)
  1333. bjhz = bjhz_template()
  1334. for entry in bjhz:
  1335. if entry['序号'] == '1':
  1336. entry['金额'] = qd_sum
  1337. for child in entry['__children']:
  1338. if child['序号'] == '1.1':
  1339. child['金额'] = str(rgf_sum)
  1340. if child['序号'] == '1.2':
  1341. child['金额'] = str(clf_sum)
  1342. if child['序号'] == '1.3':
  1343. child['金额'] = str(jxf_sum)
  1344. if child['序号'] == '1.4':
  1345. child['金额'] = str(glf_sum)
  1346. if child['序号'] == '1.5':
  1347. child['金额'] = str(lr_sum)
  1348. if entry['序号'] == '2':
  1349. entry['金额'] = str(djcs_sum + zjcs_sum)
  1350. for child in entry['__children']:
  1351. if child['序号'] == '2.1':
  1352. child['金额'] = str(djcs_sum)
  1353. if child['序号'] == '2.2':
  1354. child['金额'] = str(zjcs_sum)
  1355. for grandchild in child['__children']:
  1356. if grandchild['序号'] == '2.2.1':
  1357. grandchild['金额'] = str(sum_)
  1358. if entry['序号'] == '3':
  1359. entry['金额'] = str(qtxm_sum)
  1360. if entry['序号'] == '4':
  1361. entry['金额'] = str(gf_sum)
  1362. if entry['序号'] == '5':
  1363. entry['金额'] = str(sj_sum)
  1364. if entry['序号'] == '6':
  1365. entry['金额'] = str(float(qd_sum) + float(djcs_sum) + float(zjcs_sum) + float(qtxm_sum) + float(gf_sum) + float(sj_sum))
  1366. collection = db['Dwgc']
  1367. if distinguish:
  1368. for entry in qdbt_addition:
  1369. entry['Je'] = str(bts[entry['Mc']])
  1370. await collection.update_one({'biao_id': biao_id, "Dwgcbh": bh}, {'$set': {'zjcs': result, 'gfsj' : gfsj, 'bjhz': bjhz, 'qdbt_addition' : qdbt_addition}})
  1371. async def tbxx(client, biao_id):
  1372. db = client["baojia"]
  1373. collection = db["jingjibiao"]
  1374. document = await collection.find_one({'_id': ObjectId(biao_id)})
  1375. dxgcxx = document['Dxgcxx']
  1376. tbxx = document['TouBiaoXx']
  1377. tbxx['Tbzj'] = '0'
  1378. tbxx['Zgj'] = '0'
  1379. tbxx['Aqwmf'] = '0'
  1380. tbxx['Gf'] = '0'
  1381. dwdx = {}##单位工程映射单项工程
  1382. for dxgc in dxgcxx:
  1383. dxgc['Aqwmf'] = '0'
  1384. dxgc['Gf'] = '0'
  1385. dxgc['Je'] = '0'
  1386. dxgc['Zgj'] = '0'
  1387. mc = dxgc['Dxgcmc']
  1388. Dwgc = dxgc['Dwgc']
  1389. for dwgc in Dwgc:
  1390. Dwgcbh = dwgc['Dwgcbh']
  1391. dwdx[Dwgcbh] = dxgc
  1392. collection = db['Dwgc']
  1393. async for post in collection.find({'biao_id': biao_id}):
  1394. bh = post['Dwgcbh']
  1395. dx = dwdx[bh]
  1396. bjhz = post['bjhz']
  1397. if len(bjhz) == 0:
  1398. pass
  1399. else:
  1400. qtxm = post['qtxm']
  1401. dx['Aqwmf'] = str(float(dx['Aqwmf']) + float(bjhz[1]['__children'][1]['__children'][0]['金额']))
  1402. dx['Gf'] = str(float(dx['Gf']) + float(bjhz[3]['金额']))
  1403. dx['Je'] = str(float(dx['Je']) + float(bjhz[5]['金额']))
  1404. dx['Zgj']= str(float(dx['Zgj']) + float(qtxm[1]['金额']))
  1405. for dxgc in dxgcxx:
  1406. tbxx['Tbzj'] = str(float(tbxx['Tbzj']) + float(dxgc['Je']))
  1407. tbxx['Zgj'] = str(float(tbxx['Zgj']) + float(dxgc['Zgj']))
  1408. tbxx['Aqwmf'] = str(float(tbxx['Aqwmf']) + float(dxgc['Aqwmf']))
  1409. tbxx['Gf'] = str(float(tbxx['Gf']) + float(dxgc['Gf']))
  1410. collection = db["jingjibiao"]
  1411. await collection.update_one({'_id': ObjectId(biao_id)}, {'$set': {'Dxgcxx': dxgcxx, 'TouBiaoXx' : tbxx}})
  1412. async def updatezjcs(client, id, bh, mc, fl):
  1413. db = client["baojia"]
  1414. collection = db["Dwgc"]
  1415. document = await collection.find_one({'biao_id': id, 'Dwgcbh': bh}, {'rcjhz': 0})
  1416. zjcs = document['zjcs']
  1417. for entry in zjcs:
  1418. if entry['名称'] == mc:
  1419. entry['费率'] = fl
  1420. entry['金额'] = str(float(entry['计算基数']) * float(fl) / float(100))
  1421. await collection.update_one({'biao_id': id, "Dwgcbh": bh}, {'$set': {'zjcs': zjcs}})
  1422. await zongjiaDwgc(client, id, bh)
  1423. await tbxx(client, id)
  1424. #################保存清单项#############################
  1425. async def save(client, data):
  1426. db = client["baojia"]
  1427. collection = db["qdxm"]
  1428. biao_id = None
  1429. bh = None
  1430. for entry in data:
  1431. entry["__children"] = entry["_children"]
  1432. del entry["_children"]
  1433. biao_id = entry['biao_id']
  1434. bh = entry['Dwgcbh']
  1435. await collection.replace_one({"biao_id": entry["biao_id"], "Dwgcbh": entry["Dwgcbh"], "bt": entry["bt"], "清单编码": entry["清单编码"]}, entry)
  1436. if not biao_id:
  1437. return {"result" : "ok"}
  1438. rcjhz = []
  1439. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  1440. qdrcj = post['rcj'][1:]
  1441. for entry in qdrcj:
  1442. print(entry[4])
  1443. if entry[4] != '%':
  1444. entry[10] = float(entry[10]) * float(post['数量'])
  1445. rcjhz = rcjhz + qdrcj
  1446. collection = db["Djcs"]
  1447. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  1448. qdrcj = post['rcj'][1:]
  1449. for entry in qdrcj:
  1450. print(entry[4])
  1451. if entry[4] != '%':
  1452. entry[10] = float(entry[10]) * float(post['数量'])
  1453. rcjhz = rcjhz + qdrcj
  1454. newHuizong = util.huizongrcj(rcjhz)
  1455. collection = db["Dwgc"]
  1456. document = await collection.find_one({'biao_id': biao_id,'Dwgcbh': bh})
  1457. fbrgycl = document['fbrgycl']
  1458. for entry in fbrgycl:
  1459. id = entry['材料编号']
  1460. for entry2 in newHuizong:
  1461. if entry2[1] == id:
  1462. entry['数量'] = entry2[5]
  1463. entry['合价'] = entry2[7]
  1464. await collection.update_one({'biao_id': biao_id, 'Dwgcbh': bh}, {'$set': {'rcjhz' : newHuizong, 'fbrgycl': fbrgycl}})
  1465. await zongjiaDwgc(client, biao_id, bh)
  1466. await tbxx(client, biao_id)
  1467. return {"result": "ok"}
  1468. async def savedjcs(client, data):
  1469. db = client["baojia"]
  1470. collection = db["Djcs"]
  1471. biao_id = None
  1472. bh = None
  1473. for entry in data:
  1474. entry["__children"] = entry["_children"]
  1475. del entry["_children"]
  1476. biao_id = entry['biao_id']
  1477. bh = entry['Dwgcbh']
  1478. await collection.replace_one({"biao_id": entry["biao_id"], "Dwgcbh": entry["Dwgcbh"], "清单编码": entry["清单编码"]}, entry)
  1479. if not biao_id:
  1480. return {"result" : "ok"}
  1481. rcjhz = []
  1482. collection = db["qdxm"]
  1483. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  1484. qdrcj = post['rcj'][1:]
  1485. for entry in qdrcj:
  1486. if entry[4] != '%':
  1487. entry[10] = float(entry[10]) * float(post['数量'])
  1488. rcjhz = rcjhz + qdrcj
  1489. collection = db["Djcs"]
  1490. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  1491. qdrcj = post['rcj'][1:]
  1492. for entry in qdrcj:
  1493. if entry[4] != '%':
  1494. entry[10] = float(entry[10]) * float(post['数量'])
  1495. rcjhz = rcjhz + qdrcj
  1496. newHuizong = util.huizongrcj(rcjhz)
  1497. collection = db["Dwgc"]
  1498. document = await collection.find_one({'biao_id': biao_id,'Dwgcbh': bh})
  1499. fbrgycl = document['fbrgycl']
  1500. for entry in fbrgycl:
  1501. id = entry['材料编号']
  1502. for entry2 in newHuizong:
  1503. if entry2[1] == id:
  1504. entry['数量'] = entry2[5]
  1505. entry['合价'] = entry2[7]
  1506. await collection.update_one({'biao_id': biao_id, 'Dwgcbh': bh}, {'$set': {'rcjhz' : newHuizong, 'fbrgycl': fbrgycl}})
  1507. await zongjiaDwgc(client, biao_id, bh)
  1508. await tbxx(client, biao_id)
  1509. return {"result": "ok"}
  1510. async def applyFL(client, id, data):
  1511. db = client["baojia"]
  1512. collection = db["qufei"]
  1513. await collection.replace_one({"biao_id": id}, {"biao_id": id, "qufei": data})
  1514. collection = db['qdxm']
  1515. xm = data[0]
  1516. for dxgc in xm["children"]:
  1517. for dwgc in dxgc["children"]:
  1518. bh = dwgc['key']
  1519. glf = float(dwgc['管理费(%)'])
  1520. lr = float(dwgc['利润(%)'])
  1521. bz = dwgc['备注']
  1522. ##print(bh+glf+lr+bz)
  1523. async for post in collection.find({'biao_id': id, "Dwgcbh": bh}):
  1524. rgfs = float(post['人工费'])
  1525. clfs = float(post['材料费'])
  1526. jxfs = float(post['机械费'])
  1527. sl = float(post['数量'])
  1528. if rgfs < 0.0001 and clfs < 0.0001 and jxfs < 0.0001:
  1529. continue
  1530. ##danxiang = False
  1531. for child in post['__children']:##一条定额
  1532. bm = child['清单编码']
  1533. if bm.startswith("D"):
  1534. ##danxiang = True
  1535. continue
  1536. rgf = float(child['人工费'])
  1537. clf = float(child['材料费'])
  1538. jxf = float(child['机械费'])
  1539. zhdj = float(child['综合单价'])
  1540. sl_ = float(child['数量'])
  1541. if len(bz) == 0:
  1542. ##常规计算
  1543. child['管理费'] = (rgf + jxf) * glf / float(100)
  1544. child['利润'] = (rgf + jxf) * lr / float(100)
  1545. child['综合单价'] = rgf + clf + jxf + child['管理费'] + child['利润']
  1546. child['合价'] = sl * sl_ * child['综合单价']
  1547. else:
  1548. child['管理费'] = (rgf) * glf / float(100)
  1549. child['利润'] = (rgf) * lr / float(100)
  1550. child['综合单价'] = rgf + clf + jxf + child['管理费'] + child['利润']
  1551. child['合价'] = sl * sl_ * child['综合单价']
  1552. if True:
  1553. post['管理费'] = 0
  1554. post['利润'] = 0
  1555. for entry in post['__children']:
  1556. post['管理费'] = post['管理费'] + float(entry['管理费']) * float(entry['数量'])
  1557. post['利润'] = post['利润'] + float(entry['利润']) * float(entry['数量'])
  1558. post['管理费'] = str(post['管理费'])
  1559. post['利润'] = str(post['利润'])
  1560. post['综合单价'] = str(float(post['人工费']) + float(post['材料费']) + float(post['机械费']) + float(post['管理费']) + float(post['利润']))
  1561. post['合价'] = str(float(post['综合单价']) * float(post['数量']))
  1562. await collection.replace_one({'_id': post['_id']}, post )
  1563. collection = db['Djcs']
  1564. for dxgc in xm["children"]:
  1565. for dwgc in dxgc["children"]:
  1566. bh = dwgc['key']
  1567. glf = float(dwgc['管理费(%)'])
  1568. lr = float(dwgc['利润(%)'])
  1569. bz = dwgc['备注']
  1570. ##print(bh+glf+lr+bz)
  1571. async for post in collection.find({'biao_id': id, "Dwgcbh": bh}):
  1572. rgfs = float(post['人工费'])
  1573. clfs = float(post['材料费'])
  1574. jxfs = float(post['机械费'])
  1575. sl = float(post['数量'])
  1576. if rgfs < 0.0001 and clfs < 0.0001 and jxfs < 0.0001:
  1577. continue
  1578. ##danxiang = False##一般有单项定额的,清单就一条定额,就是这个单项定额
  1579. for child in post['__children']:
  1580. bm = child['清单编码']
  1581. if bm.startswith("D"):
  1582. ##danxiang = True
  1583. continue
  1584. rgf = float(child['人工费'])
  1585. clf = float(child['材料费'])
  1586. jxf = float(child['机械费'])
  1587. zhdj = float(child['综合单价'])
  1588. sl_ = float(child['数量'])
  1589. if len(bz) == 0:
  1590. ##常规计算
  1591. child['管理费'] = (rgf + jxf) * glf / float(100)
  1592. child['利润'] = (rgf + jxf) * lr / float(100)
  1593. child['综合单价'] = rgf + clf + jxf + child['管理费'] + child['利润']
  1594. child['合价'] = sl * sl_ * child['综合单价']
  1595. else:
  1596. child['管理费'] = (rgf) * glf / float(100)
  1597. child['利润'] = (rgf) * lr / float(100)
  1598. child['综合单价'] = rgf + clf + jxf + child['管理费'] + child['利润']
  1599. child['合价'] = sl * sl_ * child['综合单价']
  1600. if True:
  1601. post['管理费'] = 0
  1602. post['利润'] = 0
  1603. for entry in post['__children']:
  1604. post['管理费'] = post['管理费'] + float(entry['管理费']) * float(entry['数量'])
  1605. post['利润'] = post['利润'] + float(entry['利润']) * float(entry['数量'])
  1606. post['管理费'] = str(post['管理费'])
  1607. post['利润'] = str(post['利润'])
  1608. post['综合单价'] = str(float(post['人工费']) + float(post['材料费']) + float(post['机械费']) + float(post['管理费']) + float(post['利润']))
  1609. post['合价'] = str(float(post['综合单价']) * float(post['数量']))
  1610. await collection.replace_one({'_id': post['_id']}, post )
  1611. for dxgc in xm["children"]:
  1612. for dwgc in dxgc["children"]:
  1613. bh = dwgc['key']
  1614. await zongjiaDwgc(client, id, bh)
  1615. await tbxx(client, id)
  1616. return {"result": "ok"}
  1617. ###人材机汇总页面调价
  1618. async def tiaojia(client, biao_id, bh, bm, mingcheng, danwei, jiage, glf, lr, bz):
  1619. db = client["baojia"]
  1620. rcjhz = []
  1621. collection = db["qdxm"]
  1622. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}):
  1623. if "__children" not in post:
  1624. ##print(post)
  1625. continue
  1626. children = post["__children"]
  1627. qdsl = post['数量']
  1628. hit = False##清单级别
  1629. for entry in children:###对一条定额,调价
  1630. hitde = False
  1631. dercj = entry["dercj"]
  1632. dergf = 0
  1633. declf = 0
  1634. dezcf = 0
  1635. dejxf = 0
  1636. for i in range(1, len(dercj)):
  1637. rcj = dercj[i]
  1638. if rcj[1] == bm and rcj[2] == mingcheng and rcj[4] == danwei:
  1639. hit = True
  1640. hitde = True
  1641. rcj[5] = jiage
  1642. hanliang = rcj[10]
  1643. rcj[11] = str(float(jiage) * float(hanliang))
  1644. if int(rcj[8]) == 1:##rcjlb
  1645. dergf = dergf + float(rcj[11])
  1646. elif int(rcj[8]) == 2:
  1647. declf = declf + float(rcj[11])
  1648. if rcj[14] == 'true' :
  1649. dezcf = dezcf + float(rcj[11])
  1650. elif int(rcj[8]) == 3:
  1651. dejxf = dejxf + float(rcj[11])
  1652. if hitde:
  1653. entry['人工费'] = str(dergf)
  1654. entry['辅材费'] = str(declf - dezcf)
  1655. entry['主材费'] = str(dezcf)
  1656. entry['材料费'] = str(declf)
  1657. entry['机械费'] = str(dejxf)
  1658. if bm.startswith("D"):
  1659. entry['管理费'] = '0'
  1660. entry['利润'] = '0'
  1661. elif bz == 0:
  1662. entry['管理费'] = str((dergf + dejxf) * float(glf) / float(100))
  1663. entry['利润'] = str((dergf + dejxf) * float(lr) / float(100))
  1664. else:
  1665. entry['管理费'] = str((dergf) * float(glf) / float(100))
  1666. entry['利润'] = str((dergf) * float(lr) / float(100))
  1667. entry['综合单价'] = str(float(entry['人工费']) + float(entry['材料费']) + float(entry['机械费']) + float(entry['管理费']) + float(entry['利润']))
  1668. entry['合价'] = str(float(entry['综合单价']) * float(entry['数量']) * float(qdsl))
  1669. if hit:
  1670. post['综合单价'] = 0
  1671. post['合价'] = 0
  1672. post['人工费'] = 0
  1673. post['主材费'] = 0
  1674. post['设备费'] = 0
  1675. post['辅材费'] = 0
  1676. post['材料费'] = 0
  1677. post['机械费'] = 0
  1678. post['管理费'] = 0
  1679. post['利润'] = 0
  1680. for i in range(len(post["__children"])):
  1681. if len(post["__children"][i]['azfytag']) > 0:
  1682. continue
  1683. post['综合单价'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['综合单价'])
  1684. post['合价'] += float(post['__children'][i]['合价'])
  1685. post['人工费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['人工费'])
  1686. post['主材费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['主材费'])
  1687. post['设备费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['设备费'])
  1688. post['辅材费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['辅材费'])
  1689. post['材料费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['材料费'])
  1690. post['机械费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['机械费'])
  1691. post['管理费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['管理费'])
  1692. post['利润'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['利润'])
  1693. ##处理安装费用
  1694. ##console.log(qd["_children"].length);
  1695. for i in range(len(post["__children"])):
  1696. ##console.log(i);
  1697. if len(post["__children"][i]['azfytag']) > 0:
  1698. tag = post["__children"][i]['azfytag']
  1699. if tag[0] == '人工费':
  1700. current_rgf = post['人工费']
  1701. added = float(current_rgf) * float(tag[1]) / float(100)
  1702. added_rgf = added * float(tag[2]) / float(100)
  1703. added_clf = added * float(tag[3]) / float(100)
  1704. added_jxf = added * float(tag[4]) / float(100)
  1705. post["__children"][i]['人工费'] = added_rgf
  1706. post["__children"][i]['辅材费'] = added_clf
  1707. post["__children"][i]['材料费'] = added_clf
  1708. post["__children"][i]['机械费'] = added_jxf
  1709. if bz == 0:
  1710. ##changuiqufei
  1711. post["__children"][i]['管理费'] = (added_rgf + added_jxf) * float(glf) / float(100)
  1712. post["__children"][i]['利润'] = (added_rgf + added_jxf) * float(lr) / float(100)
  1713. else:
  1714. post["__children"][i]['管理费'] = (added_rgf) * float(glf) / float(100)
  1715. post["__children"][i]['利润'] = (added_rgf) * float(lr) / float(100)
  1716. post["__children"][i]['综合单价'] = post["__children"][i]['人工费'] + post["__children"][i]['材料费'] + post["__children"][i]['机械费'] + post["__children"][i]['管理费'] + post["__children"][i]['利润']
  1717. post["__children"][i]['合价'] = post["__children"][i]['综合单价'] * float(post["__children"][i]['数量']) * float(post['数量'])
  1718. dercj = post["__children"][i]['dercj']
  1719. for j in range(1, len(dercj)):
  1720. dercj[j][11] = float(added) * float(dercj[j][10]) / float(100)
  1721. if tag[0] == '人工费+机械费':
  1722. current_rgf = post['人工费'] + post['机械费']
  1723. added = float(current_rgf) * float(tag[1]) / float(100)
  1724. added_rgf = added * float(tag[2]) / float(100)
  1725. added_clf = added * float(tag[3]) / float(100)
  1726. added_jxf = added * float(tag[4]) / float(100)
  1727. post["__children"][i]['人工费'] = added_rgf
  1728. post["__children"][i]['辅材费'] = added_clf
  1729. post["__children"][i]['材料费'] = added_clf
  1730. post["__children"][i]['机械费'] = added_jxf
  1731. if bz == 0:
  1732. ###changuiqufei
  1733. post["__children"][i]['管理费'] = (added_rgf + added_jxf) * float(glf) / float(100)
  1734. post["__children"][i]['利润'] = (added_rgf + added_jxf) * float(lr) / float(100)
  1735. else:
  1736. post["__children"][i]['管理费'] = (added_rgf) * float(glf) / float(100)
  1737. post["__children"][i]['利润'] = (added_rgf) * float(lr) / float(100)
  1738. post["__children"][i]['综合单价'] = post["__children"][i]['人工费'] + post["__children"][i]['材料费'] + post["__children"][i]['机械费'] + post["__children"][i]['管理费'] + post["__children"][i]['利润']
  1739. post["__children"][i]['合价'] = post["__children"][i]['综合单价'] * float(post["__children"][i]['数量']) * float(post["数量"])
  1740. dercj = post["__children"][i]['dercj']
  1741. for j in range(1, len(dercj)):
  1742. dercj[j][11] = float(added) * float(dercj[j][10]) / float(100)
  1743. qdrcj = []
  1744. for i in range(len(post["__children"])):
  1745. dercj = post["__children"][i]['dercj']
  1746. sl = post["__children"][i]['数量']
  1747. for entry in dercj:
  1748. if '000FE' in entry[1] and entry[4] == '%': ##azfy
  1749. qdrcj.append(entry)
  1750. elif '00EXP001' in entry[1] and entry[4] == '%': ##回程费
  1751. qdrcj.append(entry)
  1752. elif '99EXP007' in entry[1] and entry[4] == '%': ##回程费
  1753. qdrcj.append(entry)
  1754. elif '31130104' in entry[1] and entry[4] == '%': ##回程费
  1755. qdrcj.append(entry)
  1756. elif entry[10] != '含量':
  1757. entry[10] = float(sl) * float(entry[10])
  1758. qdrcj.append(entry)
  1759. post["rcj"] = util.huizongrcj_order(qdrcj)
  1760. post['综合单价'] = 0
  1761. post['合价'] = 0
  1762. post['人工费'] = 0
  1763. post['主材费'] = 0
  1764. post['设备费'] = 0
  1765. post['辅材费'] = 0
  1766. post['材料费'] = 0
  1767. post['机械费'] = 0
  1768. post['管理费'] = 0
  1769. post['利润'] = 0
  1770. for i in range(len(post["__children"])):
  1771. post['综合单价'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['综合单价'])
  1772. post['合价'] += float(post['__children'][i]['合价'])
  1773. post['人工费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['人工费'])
  1774. post['主材费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['主材费'])
  1775. post['设备费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['设备费'])
  1776. post['辅材费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['辅材费'])
  1777. post['材料费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['材料费'])
  1778. post['机械费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['机械费'])
  1779. post['管理费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['管理费'])
  1780. post['利润'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['利润'])
  1781. await collection.replace_one({'_id': post['_id']}, post )
  1782. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  1783. qdrcj = post['rcj'][1:]
  1784. for entry in qdrcj:
  1785. if entry[4] != '%':
  1786. entry[10] = float(entry[10]) * float(post['数量'])
  1787. rcjhz = rcjhz + qdrcj
  1788. collection = db["Djcs"]
  1789. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}):
  1790. if "__children" not in post:
  1791. ##print(post)
  1792. continue
  1793. children = post["__children"]
  1794. qdsl = post['数量']
  1795. hit = False
  1796. for entry in children:###对一条定额,调价
  1797. hitde = False
  1798. dercj = entry["dercj"]
  1799. dergf = 0
  1800. declf = 0
  1801. dejxf = 0
  1802. for i in range(1, len(dercj)):
  1803. rcj = dercj[i]
  1804. if rcj[1] == bm and rcj[2] == mingcheng and rcj[4] == danwei:
  1805. hit = True
  1806. hitde = True
  1807. rcj[5] = jiage
  1808. hanliang = rcj[10]
  1809. rcj[11] = str(float(jiage) * float(hanliang))
  1810. if int(rcj[8]) == 1:
  1811. dergf = dergf + float(rcj[11])
  1812. elif int(rcj[8]) == 2:
  1813. declf = declf + float(rcj[11])
  1814. elif int(rcj[8]) == 3:
  1815. dejxf = dejxf + float(rcj[11])
  1816. if hitde:
  1817. for i in range(1, len(dercj)):
  1818. rcj = dercj[i]
  1819. if rcj[1] == '00EXP001' and rcj[4] == '%':##//回程费占人工费
  1820. rcj[11] = float(rcj[10]) * dergf / float(100)
  1821. if rcj[1] == '99EXP007' and rcj[4] == '%':##//回程费占机械费
  1822. rcj[11] = float(rcj[10]) * dejxf / float(100)
  1823. if rcj[1] == '31130104' and rcj[4] == '%':##//回程费占材料费
  1824. rcj[11] = float(rcj[10]) * declf / float(100)
  1825. dergf = 0
  1826. declf = 0
  1827. dejxf = 0
  1828. for i in range(1, len(dercj)):
  1829. rcj = dercj[i]
  1830. if int(rcj[8]) == 1:
  1831. dergf = dergf + float(rcj[11])
  1832. elif int(rcj[8]) == 2:
  1833. declf = declf + float(rcj[11])
  1834. elif int(rcj[8]) == 3:
  1835. dejxf = dejxf + float(rcj[11])
  1836. entry['人工费'] = str(dergf)
  1837. entry['辅材费'] = str(declf)
  1838. entry['材料费'] = str(declf)
  1839. entry['机械费'] = str(dejxf)
  1840. if bm.startswith("D"):
  1841. entry['管理费'] = '0'
  1842. entry['利润'] = '0'
  1843. elif bz == 0:
  1844. entry['管理费'] = str((dergf + dejxf) * float(glf) / float(100))
  1845. entry['利润'] = str((dergf + dejxf) * float(lr) / float(100))
  1846. else:
  1847. entry['管理费'] = str((dergf) * float(glf) / float(100))
  1848. entry['利润'] = str((dergf) * float(lr) / float(100))
  1849. entry['综合单价'] = str(float(entry['人工费']) + float(entry['材料费']) + float(entry['机械费']) + float(entry['管理费']) + float(entry['利润']))
  1850. entry['合价'] = str(float(entry['综合单价']) * float(entry['数量']) * float(qdsl))
  1851. if hit:
  1852. qdrcj = []
  1853. for i in range(len(post["__children"])):
  1854. dercj = post["__children"][i]['dercj']
  1855. sl = post["__children"][i]['数量']
  1856. for entry in dercj:
  1857. if '000FE' in entry[1] and entry[4] == '%': ##azfy
  1858. qdrcj.append(entry)
  1859. elif '00EXP001' in entry[1] and entry[4] == '%': ##回程费
  1860. qdrcj.append(entry)
  1861. elif '99EXP007' in entry[1] and entry[4] == '%': ##回程费
  1862. qdrcj.append(entry)
  1863. elif '31130104' in entry[1] and entry[4] == '%': ##回程费
  1864. qdrcj.append(entry)
  1865. elif entry[10] != '含量':
  1866. entry[10] = float(sl) * float(entry[10])
  1867. qdrcj.append(entry)
  1868. post["rcj"] = util.huizongrcj_order(qdrcj)
  1869. post['综合单价'] = 0
  1870. post['合价'] = 0
  1871. post['人工费'] = 0
  1872. post['主材费'] = 0
  1873. post['设备费'] = 0
  1874. post['辅材费'] = 0
  1875. post['材料费'] = 0
  1876. post['机械费'] = 0
  1877. post['管理费'] = 0
  1878. post['利润'] = 0
  1879. for i in range(len(post["__children"])):
  1880. post['综合单价'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['综合单价'])
  1881. post['合价'] += float(post['__children'][i]['合价'])
  1882. post['人工费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['人工费'])
  1883. post['主材费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['主材费'])
  1884. post['设备费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['设备费'])
  1885. post['辅材费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['辅材费'])
  1886. post['材料费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['材料费'])
  1887. post['机械费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['机械费'])
  1888. post['管理费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['管理费'])
  1889. post['利润'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['利润'])
  1890. await collection.replace_one({'_id': post['_id']}, post )
  1891. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  1892. qdrcj = post['rcj'][1:]
  1893. for entry in qdrcj:
  1894. if entry[4] != '%':
  1895. entry[10] = float(entry[10]) * float(post['数量'])
  1896. rcjhz = rcjhz + qdrcj
  1897. newHuizong = util.huizongrcj(rcjhz)
  1898. collection = db["Dwgc"]
  1899. document = await collection.find_one({'biao_id': biao_id,'Dwgcbh': bh})
  1900. fbrgycl = document['fbrgycl']
  1901. for entry in fbrgycl:
  1902. id = entry['材料编号']
  1903. for entry2 in newHuizong:
  1904. if entry2[1] == id:
  1905. entry['数量'] = entry2[5]
  1906. entry['合价'] = entry2[7]
  1907. await collection.update_one({'biao_id': biao_id, "Dwgcbh": bh}, {'$set': {'rcjhz': newHuizong, 'fbrgycl': fbrgycl}})
  1908. await zongjiaDwgc(client, biao_id, bh)
  1909. await tbxx(client, biao_id)
  1910. return newHuizong