db.py 83 KB

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