db.py 84 KB

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