db.py 84 KB

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