db.py 94 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169
  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. def getRcjbc(rcj):
  386. result = []
  387. for entry in rcj:
  388. if entry[1] == '410000F':
  389. result.append({
  390. "id": str(uuid.uuid4()),
  391. "主材标志": "true",
  392. "主要材料标志": "true",
  393. "产地": "",
  394. "人材机类别": "2",
  395. "人材机编码": "410000F",
  396. "供应厂商": "",
  397. "单价": entry[5],
  398. "单位": entry[4],
  399. "名称": entry[2],
  400. "含量": entry[10],
  401. "暂估价标志": "",
  402. "甲供标志": "",
  403. "规格型号": "",
  404. "设备标志": ""
  405. })
  406. return result
  407. ######################end of helper ########################
  408. async def resolve(data, client):
  409. root = ET.fromstring(data)
  410. print(root)
  411. Dwgcbh = []
  412. jingjibiao = {}
  413. jingjibiao['visible'] = False
  414. jingjibiao['created'] = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
  415. jingjibiao["BiaoDuanNO"] = root.attrib["BiaoDuanNO"]
  416. jingjibiao["Jsfs"] = root.attrib["Jsfs"]
  417. jingjibiao["Version"] = root.attrib["Version"]
  418. jingjibiao["Xmmc"] = root.attrib["Xmmc"]
  419. jingjibiao["Dxgcxx"] = []
  420. for child in root:
  421. if child.tag == "ZhaoBiaoXx":
  422. jingjibiao["ZhaoBiaoXx"] = {}
  423. jingjibiao["ZhaoBiaoXx"]["BzTime"] = child.attrib["BzTime"]
  424. jingjibiao["ZhaoBiaoXx"]["Bzr"] = child.attrib["Bzr"]
  425. jingjibiao["ZhaoBiaoXx"]["FhTime"] = child.attrib["FhTime"]
  426. jingjibiao["ZhaoBiaoXx"]["Fhr"] = child.attrib["Fhr"]
  427. jingjibiao["ZhaoBiaoXx"]["Zbr"] = child.attrib["Zbr"]
  428. jingjibiao["ZhaoBiaoXx"]["ZbrDb"] = child.attrib["ZbrDb"]
  429. jingjibiao["ZhaoBiaoXx"]["Zxr"] = child.attrib["Zxr"]
  430. jingjibiao["ZhaoBiaoXx"]["ZxrDb"] = child.attrib["ZxrDb"]
  431. elif child.tag == "TouBiaoXx":
  432. jingjibiao["TouBiaoXx"] = {}
  433. jingjibiao["TouBiaoXx"]["Zbr"] = child.attrib["Zbr"]
  434. jingjibiao["TouBiaoXx"]["Tbr"] = child.attrib["Tbr"]
  435. jingjibiao["TouBiaoXx"]["TbrDb"] = child.attrib["TbrDb"]
  436. jingjibiao["TouBiaoXx"]["Bzr"] = child.attrib["Bzr"]
  437. jingjibiao["TouBiaoXx"]["BzTime"] = child.attrib["BzTime"]
  438. jingjibiao["TouBiaoXx"]["Tbzj"] = child.attrib["Tbzj"]
  439. jingjibiao["TouBiaoXx"]["Zgj"] = child.attrib["Zgj"]
  440. jingjibiao["TouBiaoXx"]["Aqwmf"] = child.attrib["Aqwmf"]
  441. jingjibiao["TouBiaoXx"]["Gf"] = child.attrib["Gf"]
  442. elif child.tag == "Dxgcxx":
  443. Dxgcxx = {}
  444. Dxgcxx["Aqwmf"] = child.attrib["Aqwmf"]
  445. Dxgcxx["Dxgcbh"] = child.attrib["Dxgcbh"]
  446. Dxgcxx["Dxgcmc"] = child.attrib["Dxgcmc"]
  447. Dxgcxx["Gf"] = child.attrib["Gf"]
  448. Dxgcxx["Je"] = child.attrib["Je"]
  449. Dxgcxx["Zgj"] = child.attrib["Zgj"]
  450. Dxgcxx["Dwgc"] = []
  451. for grandchild in child:
  452. if grandchild.tag == "Dwgcxx":
  453. Dwgcxx = {}
  454. Dwgcxx["DogNum"] = grandchild.attrib["DogNum"]
  455. Dwgcxx["Dwgcbh"] = grandchild.attrib["Dwgcbh"]
  456. Dwgcbh.append({"bh": grandchild.attrib["Dwgcbh"], "num": grandchild.attrib["DogNum"]})
  457. Dwgcxx["Dwgcmc"] = grandchild.attrib["Dwgcmc"]
  458. Dwgcxx["MachineKey"] = grandchild.attrib["MachineKey"]
  459. Dwgcxx["SoftName"] = grandchild.attrib["SoftName"]
  460. Dwgcxx["SoftNum"] = grandchild.attrib["SoftNum"]
  461. Dwgcxx["Zylb"] = grandchild.attrib["Zylb"]
  462. Dxgcxx["Dwgc"].append(Dwgcxx)
  463. jingjibiao["Dxgcxx"].append(Dxgcxx)
  464. if not 'TouBiaoXx' in jingjibiao:
  465. jingjibiao['TouBiaoXx'] = {'Tbzj' : '', 'Zgj' : '', 'Aqwmf' : '', 'Gf' : '' }
  466. db = client["baojia"]
  467. collection = db["jingjibiao"]
  468. biao_id = (await collection.insert_one(jingjibiao)).inserted_id
  469. biao_id = str(biao_id)
  470. collection = db["Dwgc"]
  471. for entry in Dwgcbh:
  472. bjhz = service.getBjhz(root, entry["bh"])###array which contains __children
  473. gfsj = service.getGfsj(root, entry["bh"])##array which contains __children
  474. qtxm = service.getQtxm(root, entry["bh"])##array which contains __children
  475. zlje = service.getZlje(root, entry["bh"])
  476. jrg = service.getJrg(root, entry["bh"])
  477. zcbfwf = service.getZcbfwf(root, entry["bh"])
  478. fbrgycl = service.getFbrgycl(root, entry["bh"])
  479. rcjhz = service.getRcjhz(root, entry["bh"])
  480. zjcs = service.getZjcs(root, entry["bh"])
  481. qdbt = service.getQdxm(root, entry["bh"])
  482. qdbt_addition = service.getQdxm_addition(root, entry["bh"])
  483. zygczgj = service.getZygczgj(root, entry["bh"])
  484. Dwgc = {}
  485. Dwgc["bjhz"] = bjhz
  486. Dwgc["gfsj"] = gfsj
  487. Dwgc["qtxm"] = qtxm
  488. Dwgc["zlje"] = zlje
  489. Dwgc["jrg"] = jrg
  490. Dwgc['zygczgj'] = zygczgj
  491. Dwgc["zcbfwf"] = zcbfwf
  492. Dwgc["fbrgycl"] = fbrgycl
  493. Dwgc["rcjhz"] = rcjhz
  494. Dwgc["zjcs"] = zjcs
  495. Dwgc["qdbt"] = qdbt
  496. Dwgc['qdbt_addition'] = qdbt_addition
  497. Dwgc["DogNum"] = entry["num"]
  498. Dwgc["Dwgcbh"] = entry["bh"]
  499. Dwgc["biao_id"] = biao_id
  500. await collection.insert_one(Dwgc)
  501. collection = db["Djcs"]
  502. for entry in Dwgcbh:
  503. djcs = service.getDjcs(root, entry["bh"])
  504. for cs in djcs:
  505. cs["DogNum"] = entry["num"]
  506. cs["Dwgcbh"] = entry["bh"]
  507. cs["biao_id"] = biao_id
  508. rcj = getDjcsQingdanrcj_(root, entry["bh"], "", cs['清单编码'])
  509. cs["rcj"] = rcj
  510. if "__children" in cs:
  511. children = cs["__children"]
  512. for child in children:
  513. dercj = getDjcsDingercj_(root, entry["bh"], "", cs["清单编码"], child["清单编码"])
  514. child["dercj"] = dercj
  515. child['fuzhuEnable'] = False
  516. child['yuban'] = []
  517. await collection.insert_one(cs)
  518. collection = db["qdxm"]
  519. for entry in Dwgcbh:
  520. bts = service.getQdxm(root, entry["bh"])
  521. for bt in bts:
  522. if bt == 'Default':
  523. qdmx = service.getQdmx_default(root, entry["bh"], bt)
  524. else:
  525. qdmx = service.getQdmx(root, entry["bh"], bt)
  526. for qd in qdmx:
  527. qd["DogNum"] = entry["num"]
  528. qd["Dwgcbh"] = entry["bh"]
  529. qd["biao_id"] = biao_id
  530. qd["bt"] = bt
  531. rcj = getQingdanrcj_(root, entry["bh"], bt, qd["清单编码"])
  532. qd["rcj"] = rcj
  533. if "__children" in qd:
  534. children = qd["__children"]
  535. for child in children:
  536. dercj = getDingercj_(root, entry["bh"], bt, qd["清单编码"], child["清单编码"])
  537. child["dercj"] = dercj
  538. child['fuzhuEnable'] = False
  539. child['yuban'] = []
  540. child['rcjbc'] = getRcjbc(dercj)
  541. child['azfytag'] = []###常规定额
  542. await collection.insert_one(qd)
  543. collection = db["qufei"]
  544. document = jingjibiao
  545. dxgc = document['Dxgcxx']
  546. result = []
  547. for entry in dxgc:
  548. newone = {"名称" : entry['Dxgcmc'], "工程类型":"", "工程类别": "", "管理费(%)": "", "利润(%)": "","备注":"", "key" : str(uuid.uuid4()) }
  549. children = []
  550. for dwgc in entry['Dwgc']:
  551. children.append({"名称" : dwgc['Dwgcmc'], "工程类型":"", "工程类别": "", "管理费(%)": "", "利润(%)": "","备注":"", "key" : dwgc['Dwgcbh']})
  552. newone["children"] = children
  553. result.append(newone)
  554. await collection.insert_one({"biao_id": biao_id, "qufei": [{
  555. "名称" : document['Xmmc'], "工程类型":"", "工程类别": "", "管理费(%)": "", "利润(%)": "","备注":"", "key" : str(uuid.uuid4()), "children" : result
  556. }]})
  557. collection = db["jingjibiao"]
  558. await collection.update_one({'_id': ObjectId(biao_id)}, {'$set': {'visible': True}})
  559. def dfs(items):
  560. result = []
  561. for entry in items:
  562. result.append([entry['序号'], entry['名称'], entry['金额'], entry['暂估价'], entry['类别']])
  563. if '__children' in entry:
  564. result_ = dfs(entry['__children'])
  565. for r in result_:
  566. result.append(r)
  567. return result
  568. def dfs2(items):
  569. result = []
  570. for entry in items:
  571. result.append([entry['序号'], entry['名称'], entry['取费基数'], entry['计算基础'], entry['费率'], entry['金额'], entry['类别']])
  572. if '__children' in entry:
  573. result_ = dfs2(entry['__children'])
  574. for r in result_:
  575. result.append(r)
  576. return result
  577. def dfs3(items):
  578. result = []
  579. for entry in items:
  580. result.append([entry['序号'], entry['名称'], entry['金额'], entry['项目类别'], entry['备注']])
  581. if '__children' in entry:
  582. result_ = dfs3(entry['__children'])
  583. for r in result_:
  584. result.append(r)
  585. return result
  586. def roundstr(input):
  587. a = float(input)
  588. b = round(a, 2)
  589. return str(b)
  590. def roundstr4(input):
  591. a = float(input)
  592. b = round(a, 4)
  593. return str(b)
  594. ###################################build xml file##################################
  595. async def build(client, root, id):
  596. db = client["baojia"]
  597. collection = db["jingjibiao"]
  598. document = await collection.find_one({'_id': ObjectId(id)})
  599. root.set('BiaoDuanNO', document['BiaoDuanNO'])
  600. root.set('Jsfs', document['Jsfs'])
  601. root.set('Version', document['Version'])
  602. root.set('Xmmc', document['Xmmc'])
  603. TouBiaoXx = ET.SubElement(root, 'TouBiaoXx')
  604. ##{'Tbzj' : '', 'Zgj' : '', 'Aqwmf' : '', 'Gf' : '' }
  605. TouBiaoXx.set('Tbzj', roundstr(document['TouBiaoXx']['Tbzj']))
  606. TouBiaoXx.set('Zgj', roundstr(document['TouBiaoXx']['Zgj']))
  607. TouBiaoXx.set('Aqwmf', roundstr(document['TouBiaoXx']['Aqwmf']))
  608. TouBiaoXx.set('Gf', roundstr(document['TouBiaoXx']['Gf']))
  609. if 'Zbr' in document['TouBiaoXx']:
  610. TouBiaoXx.set('Zbr', str(document['TouBiaoXx']['Zbr']))
  611. if 'Tbr' in document['TouBiaoXx']:
  612. TouBiaoXx.set('Tbr', str(document['TouBiaoXx']['Tbr']))
  613. if 'TbrDb' in document['TouBiaoXx']:
  614. TouBiaoXx.set('TbrDb', str(document['TouBiaoXx']['TbrDb']))
  615. if 'Bzr' in document['TouBiaoXx']:
  616. TouBiaoXx.set('Bzr', str(document['TouBiaoXx']['Bzr']))
  617. if 'BzTime' in document['TouBiaoXx']:
  618. TouBiaoXx.set('BzTime', str(document['TouBiaoXx']['BzTime']))
  619. for item in document['Dxgcxx']:
  620. Dxgcxx = ET.SubElement(root, 'Dxgcxx')
  621. Dxgcxx.set('Dxgcbh', str(item['Dxgcbh']))
  622. Dxgcxx.set('Dxgcmc', str(item['Dxgcmc']))
  623. Dxgcxx.set('Je', roundstr(item['Je']))
  624. Dxgcxx.set('Zgj', roundstr(item['Zgj']))
  625. Dxgcxx.set('Aqwmf', roundstr(item['Aqwmf']))
  626. Dxgcxx.set('Gf', roundstr(item['Gf']))
  627. for entry in item['Dwgc']:
  628. Dwgcxx = ET.SubElement(Dxgcxx, 'Dwgcxx')
  629. Dwgcxx.set('Dwgcbh', str(entry['Dwgcbh']))
  630. Dwgcxx.set('Dwgcmc', str(entry['Dwgcmc']))
  631. Dwgcxx.set('Zylb', str(entry['Zylb']))
  632. Dwgcxx.set('SoftName', str(entry['SoftName']))
  633. Dwgcxx.set('SoftNum', str(entry['SoftNum']))
  634. Dwgcxx.set('DogNum', str(entry['DogNum']))
  635. Dwgcxx.set('MachineKey', str(entry['MachineKey']))
  636. collection = db["Dwgc"]
  637. Dwgc = await collection.find_one({'biao_id': id, "Dwgcbh": entry['Dwgcbh']})
  638. bjhz = dfs(Dwgc['bjhz'])
  639. gfsj = dfs2(Dwgc['gfsj'])
  640. qtxm = dfs3(Dwgc['qtxm'])
  641. zlje = Dwgc['zlje']
  642. zygczgj = Dwgc['zygczgj']
  643. jrg = Dwgc['jrg']
  644. zcbfwf = Dwgc['zcbfwf']
  645. fbrgycl = Dwgc['fbrgycl']
  646. rcjhz = Dwgc['rcjhz']
  647. zjcs = Dwgc['zjcs']
  648. qdbt = Dwgc['qdbt']
  649. ########################################Fywj##########################
  650. Fywj = ET.SubElement(Dwgcxx, 'Fywj')
  651. for bjhz_ in bjhz:
  652. FywjMx = ET.SubElement(Fywj, 'FywjMx')
  653. FywjMx.set('Xh', str(bjhz_[0]))
  654. FywjMx.set('Mc', str(bjhz_[1]))
  655. FywjMx.set('Je', roundstr(bjhz_[2]))
  656. FywjMx.set('Zgj', roundstr(bjhz_[3]))
  657. FywjMx.set('Fyxlb', str(bjhz_[4]))
  658. ########################################Gfsj##########################
  659. Gfsj = ET.SubElement(Dwgcxx, 'Gfsj')
  660. for gfsj_ in gfsj:
  661. GfsjMx = ET.SubElement(Gfsj, 'GfsjMx')
  662. GfsjMx.set('Xh', str(gfsj_[0]))
  663. GfsjMx.set('Mc', str(gfsj_[1]))
  664. GfsjMx.set('Qfjs', roundstr(gfsj_[2]))
  665. GfsjMx.set('Jsjc', str(gfsj_[3]))
  666. GfsjMx.set('Fl', str(gfsj_[4]))
  667. GfsjMx.set('Je', roundstr(gfsj_[5]))
  668. GfsjMx.set('Fyxlb', str(gfsj_[6]))
  669. ########################################Qdxm##########################
  670. Qdxm = ET.SubElement(Dwgcxx, 'Qdxm')
  671. if 'Default' in qdbt:
  672. collection = db["qdxm"]
  673. before_sort = []
  674. async for post in collection.find({"biao_id": id, "Dwgcbh": entry['Dwgcbh'], 'bt': 'Default'}):
  675. before_sort.append(post)
  676. after_sort = sorted(before_sort, key=lambda x: int(x['序号']))
  677. for qdmx in after_sort:
  678. Qdmx = ET.SubElement(Qdxm, 'Qdmx')
  679. Qdmx.set('Xh', str(qdmx['序号']))
  680. Qdmx.set('Qdbm', str(qdmx['清单编码']))
  681. Qdmx.set('Mc', str(qdmx['名称']))
  682. Qdmx.set('Xmtz', str(qdmx['项目特征']))
  683. Qdmx.set('Jsgz', str(qdmx['计算规则']))
  684. Qdmx.set('Dw', str(qdmx['单位']))
  685. Qdmx.set('Sl', roundstr4(qdmx['数量']))
  686. Qdmx.set('Zhdj', roundstr4(qdmx['综合单价']))
  687. Qdmx.set('Zhhj', roundstr4(qdmx['合价']))
  688. Qdmx.set('Rgf', roundstr4(qdmx['人工费']))
  689. Qdmx.set('Zcf', roundstr4(qdmx['主材费']))
  690. Qdmx.set('Sbf', roundstr4(qdmx['设备费']))
  691. Qdmx.set('Fcf', roundstr4(qdmx['辅材费']))
  692. Qdmx.set('Clf', roundstr4(qdmx['材料费']))
  693. Qdmx.set('Jxf', roundstr4(qdmx['机械费']))
  694. Qdmx.set('Glf', roundstr4(qdmx['管理费']))
  695. Qdmx.set('Lr', roundstr4(qdmx['利润']))
  696. Qdmx.set('Zgj', roundstr4(qdmx['暂估价']))
  697. Qdmx.set('Zgr', roundstr4(qdmx['综合人工工日']))
  698. Qdmx.set('Bz', str(qdmx['备注']))
  699. Qdxdezj = ET.SubElement(Qdmx, 'Qdxdezj')
  700. if '__children' in qdmx:
  701. for child in qdmx['__children']:
  702. QdxdezjMx = ET.SubElement(Qdxdezj, 'QdxdezjMx')
  703. QdxdezjMx.set('Debm', str(child['清单编码']))
  704. QdxdezjMx.set('Mc', str(child['名称']))
  705. QdxdezjMx.set('Dw', str(child['单位']))
  706. QdxdezjMx.set('DwQdSl', roundstr4(child['数量']))
  707. QdxdezjMx.set('Dj', roundstr4(child['综合单价']))
  708. QdxdezjMx.set('Hj', roundstr4(child['合价']))
  709. QdxdezjMx.set('Rgf', roundstr4(child['人工费']))
  710. QdxdezjMx.set('Zcf', roundstr4(child['主材费']))
  711. QdxdezjMx.set('Sbf', roundstr4(child['设备费']))
  712. QdxdezjMx.set('Fcf', roundstr4(child['辅材费']))
  713. QdxdezjMx.set('Clf', roundstr4(child['材料费']))
  714. QdxdezjMx.set('Jxf', roundstr4(child['机械费']))
  715. QdxdezjMx.set('Glf', roundstr4(child['管理费']))
  716. QdxdezjMx.set('Lr', roundstr4(child['利润']))
  717. Qdxdercjhl = ET.SubElement(QdxdezjMx, 'Qdxdercjhl')
  718. for i in range(len(child['dercj'])):
  719. if i == 0:
  720. pass
  721. else:
  722. QdxdercjhlMx = ET.SubElement(Qdxdercjhl, 'QdxdercjhlMx')
  723. QdxdercjhlMx.set('RcjId', util.indexrcj(rcjhz, child['dercj'][i]))
  724. QdxdercjhlMx.set('Rcjhl', roundstr4(child['dercj'][i][10]))
  725. QdxdercjhlMx.set('Rcjhj', roundstr4(child['dercj'][i][11]))
  726. Qdxrcjhl = ET.SubElement(Qdmx, 'Qdxrcjhl')
  727. for i in range(len(qdmx['rcj'])):
  728. if i == 0:
  729. pass
  730. else:
  731. QdxrcjhlMx = ET.SubElement(Qdxrcjhl, 'QdxrcjhlMx')
  732. QdxrcjhlMx.set('RcjId', util.indexrcj(rcjhz, qdmx['rcj'][i]))
  733. ##str(djcs['rcj'][i][0]))
  734. QdxrcjhlMx.set('Rcjhl', roundstr4(qdmx['rcj'][i][10]))
  735. QdxrcjhlMx.set('Rcjhj', roundstr4(qdmx['rcj'][i][11]))
  736. QdxrcjhlMx.set('Zgjbz', str(qdmx['rcj'][i][12]))
  737. QdxrcjhlMx.set('Zyclbz', str(qdmx['rcj'][i][13]))
  738. QdxrcjhlMx.set('Zcbz', str(qdmx['rcj'][i][14]))
  739. QdxrcjhlMx.set('Sbbz', str(qdmx['rcj'][i][15]))
  740. qdbt_addition = Dwgc['qdbt_addition']
  741. for bt in qdbt_addition:
  742. QdBt = ET.SubElement(Qdxm, 'QdBt')
  743. QdBt.set('Xh', bt['Xh'])
  744. QdBt.set('Mc', bt['Mc'])
  745. QdBt.set('Je', roundstr(bt['Je']))
  746. QdBt.set('Zgj', roundstr(bt['Zgj']))
  747. QdBt.set('Bz', bt['Bz'])
  748. collection = db["qdxm"]
  749. before_sort = []
  750. async for post in collection.find({"biao_id": id, "Dwgcbh": entry['Dwgcbh'], 'bt': bt['Mc']}):
  751. before_sort.append(post)
  752. after_sort = sorted(before_sort, key=lambda x: int(x['序号']))
  753. for qdmx in after_sort:
  754. Qdmx = ET.SubElement(QdBt, 'Qdmx')
  755. Qdmx.set('Xh', str(qdmx['序号']))
  756. Qdmx.set('Qdbm', str(qdmx['清单编码']))
  757. Qdmx.set('Mc', str(qdmx['名称']))
  758. Qdmx.set('Xmtz', str(qdmx['项目特征']))
  759. Qdmx.set('Jsgz', str(qdmx['计算规则']))
  760. Qdmx.set('Dw', str(qdmx['单位']))
  761. Qdmx.set('Sl', roundstr4(qdmx['数量']))
  762. Qdmx.set('Zhdj', roundstr4(qdmx['综合单价']))
  763. Qdmx.set('Zhhj', roundstr4(qdmx['合价']))
  764. Qdmx.set('Rgf', roundstr4(qdmx['人工费']))
  765. Qdmx.set('Zcf', roundstr4(qdmx['主材费']))
  766. Qdmx.set('Sbf', roundstr4(qdmx['设备费']))
  767. Qdmx.set('Fcf', roundstr4(qdmx['辅材费']))
  768. Qdmx.set('Clf', roundstr4(qdmx['材料费']))
  769. Qdmx.set('Jxf', roundstr4(qdmx['机械费']))
  770. Qdmx.set('Glf', roundstr4(qdmx['管理费']))
  771. Qdmx.set('Lr', roundstr4(qdmx['利润']))
  772. Qdmx.set('Zgj', roundstr4(qdmx['暂估价']))
  773. Qdmx.set('Zgr', roundstr4(qdmx['综合人工工日']))
  774. Qdmx.set('Bz', str(qdmx['备注']))
  775. Qdxdezj = ET.SubElement(Qdmx, 'Qdxdezj')
  776. if '__children' in qdmx:
  777. for child in qdmx['__children']:
  778. QdxdezjMx = ET.SubElement(Qdxdezj, 'QdxdezjMx')
  779. QdxdezjMx.set('Debm', str(child['清单编码']))
  780. QdxdezjMx.set('Mc', str(child['名称']))
  781. QdxdezjMx.set('Dw', str(child['单位']))
  782. QdxdezjMx.set('DwQdSl', roundstr4(child['数量']))
  783. QdxdezjMx.set('Dj', roundstr4(child['综合单价']))
  784. QdxdezjMx.set('Hj', roundstr4(child['合价']))
  785. QdxdezjMx.set('Rgf', roundstr4(child['人工费']))
  786. QdxdezjMx.set('Zcf', roundstr4(child['主材费']))
  787. QdxdezjMx.set('Sbf', roundstr4(child['设备费']))
  788. QdxdezjMx.set('Fcf', roundstr4(child['辅材费']))
  789. QdxdezjMx.set('Clf', roundstr4(child['材料费']))
  790. QdxdezjMx.set('Jxf', roundstr4(child['机械费']))
  791. QdxdezjMx.set('Glf', roundstr4(child['管理费']))
  792. QdxdezjMx.set('Lr', roundstr4(child['利润']))
  793. Qdxdercjhl = ET.SubElement(QdxdezjMx, 'Qdxdercjhl')
  794. for i in range(len(child['dercj'])):
  795. if i == 0:
  796. pass
  797. else:
  798. QdxdercjhlMx = ET.SubElement(Qdxdercjhl, 'QdxdercjhlMx')
  799. QdxdercjhlMx.set('RcjId', util.indexrcj(rcjhz, child['dercj'][i]))
  800. QdxdercjhlMx.set('Rcjhl', roundstr4(child['dercj'][i][10]))
  801. QdxdercjhlMx.set('Rcjhj', roundstr4(child['dercj'][i][11]))
  802. Qdxrcjhl = ET.SubElement(Qdmx, 'Qdxrcjhl')
  803. for i in range(len(qdmx['rcj'])):
  804. if i == 0:
  805. pass
  806. else:
  807. QdxrcjhlMx = ET.SubElement(Qdxrcjhl, 'QdxrcjhlMx')
  808. QdxrcjhlMx.set('RcjId', util.indexrcj(rcjhz, qdmx['rcj'][i]))
  809. ##str(djcs['rcj'][i][0]))
  810. QdxrcjhlMx.set('Rcjhl', roundstr4(qdmx['rcj'][i][10]))
  811. QdxrcjhlMx.set('Rcjhj', roundstr4(qdmx['rcj'][i][11]))
  812. QdxrcjhlMx.set('Zgjbz', str(qdmx['rcj'][i][12]))
  813. QdxrcjhlMx.set('Zyclbz', str(qdmx['rcj'][i][13]))
  814. QdxrcjhlMx.set('Zcbz', str(qdmx['rcj'][i][14]))
  815. QdxrcjhlMx.set('Sbbz', str(qdmx['rcj'][i][15]))
  816. ########################################Csxm##########################
  817. Csxm = ET.SubElement(Dwgcxx, 'Csxm')
  818. ZjCs = ET.SubElement(Csxm, 'ZjCs')
  819. for zjcs_ in zjcs:
  820. ZjCsMx = ET.SubElement(ZjCs, 'ZjCsMx')
  821. ZjCsMx.set('Xh', str(zjcs_['序号']))
  822. ZjCsMx.set('Bm', str(zjcs_['清单编码']))
  823. ZjCsMx.set('Mc', str(zjcs_['名称']))
  824. ZjCsMx.set('Js', roundstr(zjcs_['计算基数']))
  825. ZjCsMx.set('Jsjc', str(zjcs_['计算基础']))
  826. ZjCsMx.set('Fl', str(zjcs_['费率']))
  827. ZjCsMx.set('Je', roundstr(zjcs_['金额']))
  828. ZjCsMx.set('Xmlb', str(zjcs_['项目类别']))
  829. if '__children' in zjcs_:
  830. AqwmfMx = ET.SubElement(ZjCsMx, 'AqwmfMx')
  831. AqwmfMx.set('Mc', str(zjcs_['__children'][0]['名称']))
  832. AqwmfMx.set('Js', roundstr(zjcs_['__children'][0]['计算基数']))
  833. AqwmfMx.set('Jsjc', str(zjcs_['__children'][0]['计算基础']))
  834. AqwmfMx.set('Fl', str(zjcs_['__children'][0]['费率']))
  835. AqwmfMx.set('Je', roundstr(zjcs_['__children'][0]['金额']))
  836. AqwmfMx.set('Xmlb', str(zjcs_['__children'][0]['项目类别']))
  837. AqwmfMx = ET.SubElement(ZjCsMx, 'AqwmfMx')
  838. AqwmfMx.set('Mc', str(zjcs_['__children'][1]['名称']))
  839. AqwmfMx.set('Js', roundstr(zjcs_['__children'][1]['计算基数']))
  840. AqwmfMx.set('Jsjc', str(zjcs_['__children'][1]['计算基础']))
  841. AqwmfMx.set('Fl', str(zjcs_['__children'][1]['费率']))
  842. AqwmfMx.set('Je', roundstr(zjcs_['__children'][1]['金额']))
  843. AqwmfMx.set('Xmlb', str(zjcs_['__children'][1]['项目类别']))
  844. AqwmfMx = ET.SubElement(ZjCsMx, 'AqwmfMx')
  845. AqwmfMx.set('Mc', str(zjcs_['__children'][2]['名称']))
  846. AqwmfMx.set('Js', roundstr(zjcs_['__children'][2]['计算基数']))
  847. AqwmfMx.set('Jsjc', str(zjcs_['__children'][2]['计算基础']))
  848. AqwmfMx.set('Fl', str(zjcs_['__children'][2]['费率']))
  849. AqwmfMx.set('Je', roundstr(zjcs_['__children'][2]['金额']))
  850. AqwmfMx.set('Xmlb', str(zjcs_['__children'][2]['项目类别']))
  851. DjCs = ET.SubElement(Csxm, 'DjCs')
  852. collection = db["Djcs"]
  853. before_sort = []
  854. async for post in collection.find({"biao_id": id, "Dwgcbh": entry['Dwgcbh']}):
  855. before_sort.append(post)
  856. after_sort = sorted(before_sort, key=lambda x: int(x['序号']))
  857. for djcs in after_sort:
  858. DjCsMx = ET.SubElement(DjCs, 'DjCsMx')
  859. DjCsMx.set('Xh', str(djcs['序号']))
  860. DjCsMx.set('Bm', str(djcs['清单编码']))
  861. DjCsMx.set('Mc', str(djcs['名称']))
  862. DjCsMx.set('Xmtz', str(djcs['项目特征']))
  863. DjCsMx.set('Jsgz', str(djcs['计算规则']))
  864. DjCsMx.set('Dw', str(djcs['单位']))
  865. DjCsMx.set('Sl', roundstr4(djcs['数量']))
  866. DjCsMx.set('Zhdj', roundstr4(djcs['综合单价']))
  867. DjCsMx.set('Zhhj', roundstr4(djcs['合价']))
  868. DjCsMx.set('Rgf', roundstr4(djcs['人工费']))
  869. DjCsMx.set('Zcf', roundstr4(djcs['主材费']))
  870. DjCsMx.set('Sbf', roundstr4(djcs['设备费']))
  871. DjCsMx.set('Fcf', roundstr4(djcs['辅材费']))
  872. DjCsMx.set('Clf', roundstr4(djcs['材料费']))
  873. DjCsMx.set('Jxf', roundstr4(djcs['机械费']))
  874. DjCsMx.set('Glf', roundstr4(djcs['管理费']))
  875. DjCsMx.set('Lr', roundstr4(djcs['利润']))
  876. DjCsMx.set('Zgj', roundstr4(djcs['暂估价']))
  877. DjCsMx.set('Zgr', roundstr4(djcs['综合人工工日']))
  878. Csxdezj = ET.SubElement(DjCsMx, 'Csxdezj')
  879. if '__children' in djcs:
  880. for child in djcs['__children']:
  881. CsxdezjMx = ET.SubElement(Csxdezj, 'CsxdezjMx')
  882. CsxdezjMx.set('Debm', str(child['清单编码']))
  883. CsxdezjMx.set('Mc', str(child['名称']))
  884. CsxdezjMx.set('Dw', str(child['单位']))
  885. CsxdezjMx.set('DwQdSl', roundstr4(child['数量']))
  886. CsxdezjMx.set('Dj', roundstr4(child['综合单价']))
  887. CsxdezjMx.set('Hj', roundstr4(child['合价']))
  888. CsxdezjMx.set('Rgf', roundstr4(child['人工费']))
  889. CsxdezjMx.set('Zcf', roundstr4(child['主材费']))
  890. CsxdezjMx.set('Sbf', roundstr4(child['设备费']))
  891. CsxdezjMx.set('Fcf', roundstr4(child['辅材费']))
  892. CsxdezjMx.set('Clf', roundstr4(child['材料费']))
  893. CsxdezjMx.set('Jxf', roundstr4(child['机械费']))
  894. CsxdezjMx.set('Glf', roundstr4(child['管理费']))
  895. CsxdezjMx.set('Lr', roundstr4(child['利润']))
  896. Csxdercjhl = ET.SubElement(CsxdezjMx, 'Csxdercjhl')
  897. for i in range(len(child['dercj'])):
  898. if i == 0:
  899. pass
  900. else:
  901. CsxdercjhlMx = ET.SubElement(Csxdercjhl, 'CsxdercjhlMx')
  902. CsxdercjhlMx.set('RcjId', util.indexrcj(rcjhz, child['dercj'][i]))
  903. CsxdercjhlMx.set('Rcjhl', roundstr4(child['dercj'][i][10]))
  904. CsxdercjhlMx.set('Rcjhj', roundstr4(child['dercj'][i][11]))
  905. Csxrcjhl = ET.SubElement(DjCsMx, 'Csxrcjhl')
  906. for i in range(len(djcs['rcj'])):
  907. if i == 0:
  908. pass
  909. else:
  910. CsxrcjhlMx = ET.SubElement(Csxrcjhl, 'CsxrcjhlMx')
  911. CsxrcjhlMx.set('RcjId', util.indexrcj(rcjhz, djcs['rcj'][i]))
  912. ##str(djcs['rcj'][i][0]))
  913. CsxrcjhlMx.set('Rcjhl', roundstr4(djcs['rcj'][i][10]))
  914. CsxrcjhlMx.set('Rcjhj', roundstr4(djcs['rcj'][i][11]))
  915. CsxrcjhlMx.set('Zgjbz', str(djcs['rcj'][i][12]))
  916. CsxrcjhlMx.set('Zyclbz', str(djcs['rcj'][i][13]))
  917. CsxrcjhlMx.set('Zcbz', str(djcs['rcj'][i][14]))
  918. CsxrcjhlMx.set('Sbbz', str(djcs['rcj'][i][15]))
  919. ########################################Qtxm##########################
  920. Qtxm = ET.SubElement(Dwgcxx, 'Qtxm')
  921. for qtxm_ in qtxm:
  922. QtxmMx = ET.SubElement(Qtxm, 'QtxmMx')
  923. QtxmMx.set('Xh', str(qtxm_[0]))
  924. QtxmMx.set('Mc', str(qtxm_[1]))
  925. QtxmMx.set('Je', roundstr(qtxm_[2]))
  926. QtxmMx.set('Xmlb', str(qtxm_[3]))
  927. QtxmMx.set('Bz', str(qtxm_[4]))
  928. Zlje = ET.SubElement(Dwgcxx, 'Zlje')
  929. for i in range(len(zlje)):
  930. ZljeMx = ET.SubElement(Zlje, 'ZljeMx')
  931. ZljeMx.set('Xh', str(zlje[i]['序号']))
  932. ZljeMx.set('Mc', str(zlje[i]['名称']))
  933. ZljeMx.set('Dw', str(zlje[i]['单位']))
  934. ZljeMx.set('Zdje', roundstr(zlje[i]['暂定金额']))
  935. ZljeMx.set('Bz', str(zlje[i]['备注']))
  936. Clzg = ET.SubElement(Dwgcxx, 'Clzg')
  937. Zygczg = ET.SubElement(Dwgcxx, 'Zygczg')
  938. for zygczgj_ in zygczgj:
  939. ZygczgMx = ET.SubElement(Zygczg, 'ZygczgMx')
  940. ZygczgMx.set('Xh', str(zygczgj_['序号']))
  941. ZygczgMx.set('Mc', str(zygczgj_['名称']))
  942. ZygczgMx.set('Gcnr', str(zygczgj_['工程内容']))
  943. ZygczgMx.set('Je', roundstr(zygczgj_['金额']))
  944. ZygczgMx.set('Bz', str(zygczgj_['备注']))
  945. Jrg = ET.SubElement(Dwgcxx, 'Jrg')
  946. for jrg_ in jrg:
  947. JrgBt = ET.SubElement(Jrg, 'JrgBt')
  948. JrgBt.set('Xh', str(jrg_['序号']))
  949. JrgBt.set('Mc', str(jrg_['名称']))
  950. JrgBt.set('Je', roundstr(jrg_['金额']))
  951. JrgBt.set('Lb', str(jrg_['类别']))
  952. Zcbfwf = ET.SubElement(Dwgcxx, 'Zcbfwf')
  953. for zcbfwf_ in zcbfwf:
  954. ZcbfwfMx = ET.SubElement(Zcbfwf, 'ZcbfwfMx')
  955. ZcbfwfMx.set('Xh', str(zcbfwf_['序号']))
  956. ZcbfwfMx.set('Mc', str(zcbfwf_['名称']))
  957. ZcbfwfMx.set('Xmjz', roundstr(zcbfwf_['项目价值']))
  958. ZcbfwfMx.set('Fwnr', str(zcbfwf_['服务内容']))
  959. ZcbfwfMx.set('Jsjc', str(zcbfwf_['计算基础']))
  960. ZcbfwfMx.set('Fl', str(zcbfwf_['费率']))
  961. ZcbfwfMx.set('Je', roundstr(zcbfwf_['金额']))
  962. Zjxmjdkzffj = ET.SubElement(Dwgcxx, 'Zjxmjdkzffj')
  963. Fbrgycl = ET.SubElement(Dwgcxx, 'Fbrgycl')
  964. for fbrgycl_ in fbrgycl:
  965. FbrgyclMx = ET.SubElement(Fbrgycl, 'FbrgyclMx')
  966. FbrgyclMx.set('Xh', str(fbrgycl_['序号']))
  967. FbrgyclMx.set('RcjId', util.indexrcj(rcjhz, [fbrgycl_['序号'], fbrgycl_['材料编号'], fbrgycl_['名称'], fbrgycl_['规格型号'], fbrgycl_['单位']]))
  968. FbrgyclMx.set('Clbh', str(fbrgycl_['材料编号']))
  969. FbrgyclMx.set('Mc', str(fbrgycl_['名称']))
  970. FbrgyclMx.set('Ggxh', str(fbrgycl_['规格型号']))
  971. FbrgyclMx.set('Dw', str(fbrgycl_['单位']))
  972. FbrgyclMx.set('Sl', roundstr4(fbrgycl_['数量']))
  973. FbrgyclMx.set('Dj', roundstr4(fbrgycl_['单价']))
  974. FbrgyclMx.set('Hj', roundstr4(fbrgycl_['合价']))
  975. FbrgyclMx.set('Jhfs', str(fbrgycl_['交货方式']))
  976. FbrgyclMx.set('Sddd', str(fbrgycl_['送达地点']))
  977. FbrgyclMx.set('Bz', str(fbrgycl_['备注']))
  978. Cbrgycl = ET.SubElement(Dwgcxx, 'Cbrgycl')
  979. Rcjhz = ET.SubElement(Dwgcxx, 'Rcjhz')
  980. for i in range(len(rcjhz)):
  981. if i == 0:
  982. pass
  983. else:
  984. RcjhzMx = ET.SubElement(Rcjhz, 'RcjhzMx')
  985. RcjhzMx.set('RcjId', str(i))
  986. RcjhzMx.set('RcjBm', str(rcjhz[i][1]))
  987. RcjhzMx.set('Mc', str(rcjhz[i][2]))
  988. RcjhzMx.set('Ggxh', str(rcjhz[i][3]))
  989. RcjhzMx.set('Dw', str(rcjhz[i][4]))
  990. RcjhzMx.set('Sl', roundstr4(rcjhz[i][5]))
  991. RcjhzMx.set('Dj', roundstr4(rcjhz[i][6]))
  992. RcjhzMx.set('Hj', roundstr4(rcjhz[i][7]))
  993. RcjhzMx.set('Cd', str(rcjhz[i][8]))
  994. RcjhzMx.set('Gycs', str(rcjhz[i][9]))
  995. RcjhzMx.set('Rcjlb', str(rcjhz[i][10]))
  996. RcjhzMx.set('Zyclbz', str(rcjhz[i][11]))
  997. RcjhzMx.set('Zcbz', str(rcjhz[i][12]))
  998. RcjhzMx.set('Sbbz', str(rcjhz[i][13]))
  999. RcjhzMx.set('Jgbz', str(rcjhz[i][14]))
  1000. RcjhzMx.set('Zgjbz', str(rcjhz[i][15]))
  1001. ############################end of build xml file#################################
  1002. async def delete_files(client, id):
  1003. db = client["baojia"]
  1004. collection = db["jingjibiao"]
  1005. result = []
  1006. await collection.update_one({'_id': ObjectId(id)}, {'$set': {'visible': False}})
  1007. return result
  1008. async def list_files(client):
  1009. db = client["baojia"]
  1010. collection = db["jingjibiao"]
  1011. result = []
  1012. async for post in collection.find({"visible": True}):
  1013. result.append([str(post['_id']), post["Xmmc"], post['created'] if 'created' in post else ""])
  1014. return result
  1015. def getDwgc(id, Zylb):
  1016. result = []
  1017. id = id + "Zylb" + Zylb
  1018. result.append({"id": id + "bao jia hui zong", "label": "报价汇总表"})
  1019. result.append({"id": id + "gui fei shui jin", "label": "规费税金"})
  1020. result.append({"id": id + "qing dan xiang mu", "label": "清单项目"})
  1021. result.append({"id": id + "cuo shi xiang mu", "label": "措施项目"})
  1022. result.append({"id": id +"qi ta xiang mu", "label": "其他项目"})
  1023. result.append({"id": id +"zan lie jin e", "label": "暂列金额"})
  1024. result.append({"id": id +"cai liao zan gu jia", "label": "材料暂估价"})
  1025. result.append({"id": id + "zhuan ye gong cheng zan gu jia", "label": "专业工程暂估价"})
  1026. result.append({"id": id + "ji ri gong", "label": "计日工"})
  1027. result.append({"id": id + "zong cheng bao fu wu fei", "label": "总承包服务费"})
  1028. result.append({"id": id + "zong jia xiang mu jin du kuan zhi fu fen jie", "label": "总价项目进度款支付分解"})
  1029. result.append({"id": id + "fa bao ren gong ying cai liao", "label": "发包人供应材料"})
  1030. result.append({"id": id + "cheng bao ren gong ying cai liao", "label": "承包人供应材料"})
  1031. result.append({"id": id + "ren cai ji hui zong", "label": "人材机汇总"})
  1032. return result
  1033. async def getOutline(client, id):
  1034. db = client["baojia"]
  1035. collection = db["jingjibiao"]
  1036. document = await collection.find_one({'_id': ObjectId(id)})
  1037. result = []
  1038. if 'TouBiaoXx' in document:
  1039. result.append({"id" : "TouBiaoXx", "label" : "投标信息" })
  1040. if 'Dxgcxx' in document:
  1041. Dxgcxx = document["Dxgcxx"]
  1042. for dxgc in Dxgcxx:
  1043. result2 = []
  1044. Dwgc = dxgc["Dwgc"]
  1045. for grandchild in Dwgc:
  1046. result2.append({"id" : grandchild['Dwgcbh'], "Zylb":grandchild['Zylb'], "label": grandchild["Dwgcmc"], "children" : getDwgc(grandchild['Dwgcbh'], grandchild['Zylb'])})
  1047. result.append({"id" : dxgc['Dxgcbh'], "label" : dxgc['Dxgcmc'], "children" : result2})
  1048. return result
  1049. async def getDetail(client, id):
  1050. db = client["baojia"]
  1051. collection = db["jingjibiao"]
  1052. document = await collection.find_one({'_id': ObjectId(id)})
  1053. result = []
  1054. ##result.append(["名称", "金额", "暂估价", "安全文明施工费", "规费"])
  1055. if 'TouBiaoXx' in document:
  1056. toubiaoxx = document["TouBiaoXx"]
  1057. result.append({'名称': '投标总价', '金额' : toubiaoxx["Tbzj"], '暂估价': toubiaoxx["Zgj"], '安全文明施工费': toubiaoxx["Aqwmf"], '规费' : toubiaoxx["Gf"], '_children': []})
  1058. if 'Dxgcxx' in document:
  1059. Dxgcxx = document["Dxgcxx"]
  1060. for dxgc in Dxgcxx:
  1061. result[0]['_children'].append({'名称' :dxgc["Dxgcmc"], '金额' : dxgc["Je"], '暂估价' : dxgc["Zgj"],'安全文明施工费' : dxgc["Aqwmf"], '规费' : dxgc["Gf"]})
  1062. return result
  1063. else:
  1064. if 'Dxgcxx' in document:
  1065. Dxgcxx = document["Dxgcxx"]
  1066. for dxgc in Dxgcxx:
  1067. result.append({'名称' :dxgc["Dxgcmc"], '金额' : dxgc["Je"], '暂估价' : dxgc["Zgj"],'安全文明施工费' : dxgc["Aqwmf"], '规费' : dxgc["Gf"]})
  1068. return result
  1069. async def getBjhz(client, objectid, id):
  1070. db = client["baojia"]
  1071. collection = db["Dwgc"]
  1072. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  1073. return document['bjhz']
  1074. async def getGfsj(client, objectid, id):
  1075. db = client["baojia"]
  1076. collection = db["Dwgc"]
  1077. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  1078. return document['gfsj']
  1079. async def getQtxm(client, objectid, id):
  1080. db = client["baojia"]
  1081. collection = db["Dwgc"]
  1082. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  1083. return document['qtxm']
  1084. async def getZygczgj(client, objectid, id):
  1085. db = client["baojia"]
  1086. collection = db["Dwgc"]
  1087. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  1088. return document['zygczgj']
  1089. async def getZlje(client, objectid, id):
  1090. db = client["baojia"]
  1091. collection = db["Dwgc"]
  1092. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  1093. return document['zlje']
  1094. async def getJrg(client, objectid, id):
  1095. db = client["baojia"]
  1096. collection = db["Dwgc"]
  1097. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  1098. return document['jrg']
  1099. async def getZcbfwf(client, objectid, id):
  1100. db = client["baojia"]
  1101. collection = db["Dwgc"]
  1102. document = await collection.find_one({"Dwgcbh": id, "biao_id": objectid})
  1103. return document['zcbfwf']
  1104. async def getFbrgycl(client, objectid, id):
  1105. db = client["baojia"]
  1106. collection = db["Dwgc"]
  1107. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  1108. return document['fbrgycl']
  1109. async def getRcjhz(client, objectid, id):
  1110. db = client["baojia"]
  1111. collection = db["Dwgc"]
  1112. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  1113. return document['rcjhz']
  1114. async def getZjcs(client, objectid, id):
  1115. db = client["baojia"]
  1116. collection = db["Dwgc"]
  1117. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  1118. return document['zjcs']
  1119. async def getDjcs(client, objectid, id):
  1120. db = client["baojia"]
  1121. collection = db["Djcs"]
  1122. result = []
  1123. async for post in collection.find({"Dwgcbh": id, "biao_id": objectid}):
  1124. del post["_id"]
  1125. result.append(post)
  1126. return result
  1127. async def getDjcsQingdanrcj(client, name, bh, bt, bm):
  1128. db = client["baojia"]
  1129. collection = db["Djcs"]
  1130. document = await collection.find_one({ "Dwgcbh": bh, "清单编码": bm, "biao_id": name})
  1131. result = document["rcj"]
  1132. return result
  1133. async def getDjcsDingercj(client, name, bh, bt, qdbm, debm):
  1134. db = client["baojia"]
  1135. collection = db["Djcs"]
  1136. document = await collection.find_one({"Dwgcbh": bh, "清单编码": qdbm, "biao_id": name})
  1137. children = document["__children"]
  1138. result = []
  1139. for child in children:
  1140. if child["清单编码"] == debm:
  1141. result = child["dercj"]
  1142. return result
  1143. async def getQdxm(client, name, bh):
  1144. db = client["baojia"]
  1145. collection = db["Dwgc"]
  1146. document = await collection.find_one({'biao_id': name, "Dwgcbh": bh})
  1147. if document:
  1148. return document['qdbt']
  1149. else:
  1150. return []
  1151. async def getQdmx(client, name, bh, bt):
  1152. db = client["baojia"]
  1153. collection = db["qdxm"]
  1154. result = []
  1155. async for post in collection.find({'biao_id': name, "Dwgcbh": bh, "bt": bt}):
  1156. del post["_id"]
  1157. result.append(post)
  1158. return result
  1159. async def getQingdanrcj(client, name, bh, bt, bm):
  1160. db = client["baojia"]
  1161. collection = db["qdxm"]
  1162. document = await collection.find_one({ "Dwgcbh": bh, "清单编码": bm, "biao_id": name, "bt": bt})
  1163. result = document["rcj"]
  1164. return result
  1165. async def getDingercj(client, name, bh, bt, qdbm, debm):
  1166. db = client["baojia"]
  1167. collection = db["qdxm"]
  1168. document = await collection.find_one({"Dwgcbh": bh, "清单编码": qdbm, "biao_id": name, "bt": bt})
  1169. result = []
  1170. if "__children" in document:
  1171. children = document["__children"]
  1172. for child in children:
  1173. if child["清单编码"] == debm:
  1174. result = child["dercj"]
  1175. return result
  1176. async def getQufei(client, id):
  1177. db = client["baojia"]
  1178. collection = db["qufei"]
  1179. document = await collection.find_one({'biao_id': id})
  1180. return document['qufei']
  1181. async def searchde(client, zhuanye, text):
  1182. db = client["dinge"]
  1183. collection = db["de-collection"]
  1184. result = []
  1185. async for post in collection.find({'$text': {"$search": "\"" + text + "\""}, "zhuanye": zhuanye}):
  1186. result.append(post["DEBH"] + " " + post['GCLMC'] )
  1187. if len(result) > 10:
  1188. break
  1189. return result
  1190. ##################################editor_code##########################
  1191. def bjhz_template():
  1192. result = []
  1193. result.append({'序号': '1', '名称': '分部分项工程', '金额': '0', '暂估价': '0', '类别' : '1', '__children': [
  1194. {'序号': '1.1', '名称': '人工费', '金额': '0', '暂估价': '0', '类别' : '1.1'},
  1195. {'序号': '1.2', '名称': '材料费', '金额': '0', '暂估价': '0', '类别' : '1.2'},
  1196. {'序号': '1.3', '名称': '施工机具使用费', '金额': '0', '暂估价': '0', '类别' : '1.3'},
  1197. {'序号': '1.4', '名称': '企业管理费', '金额': '0', '暂估价': '0', '类别' : '1.4'},
  1198. {'序号': '1.5', '名称': '利润', '金额': '0', '暂估价': '0', '类别' : '1.5'}
  1199. ]})
  1200. result.append({'序号': '2', '名称': '措施项目', '金额': '0', '暂估价': '0', '类别' : '2', '__children': [
  1201. {'序号': '2.1', '名称': '单价措施项目费', '金额': '0', '暂估价': '0', '类别' : '2.1'},
  1202. {'序号': '2.2', '名称': '总价措施项目费', '金额': '0', '暂估价': '0', '类别' : '2.2', '__children' : [
  1203. {'序号': '2.2.1', '名称': '其中:安全文明施工措施费', '金额': '0', '暂估价': '0', '类别' : '2.2.1'},]
  1204. }
  1205. ]})
  1206. result.append({'序号': '3', '名称': '其他项目', '金额': '0', '暂估价': '0', '类别' : '3', '__children': [
  1207. {'序号': '3.1', '名称': '其中:暂列金额', '金额': '0', '暂估价': '0', '类别' : '3.1'},
  1208. {'序号': '3.2', '名称': '其中:专业工程暂估价', '金额': '0', '暂估价': '0', '类别' : '3.2'},
  1209. {'序号': '3.3', '名称': '其中:计日工', '金额': '0', '暂估价': '0', '类别' : '3.3'},
  1210. {'序号': '3.4', '名称': '其中:总承包服务费', '金额': '0', '暂估价': '0', '类别' : '3.4'},
  1211. ]})
  1212. result.append({'序号': '4', '名称': '规费', '金额': '0', '暂估价': '0', '类别' : '4', })
  1213. result.append({'序号': '5', '名称': '税金', '金额': '0', '暂估价': '0', '类别' : '5', })
  1214. result.append({'序号': '6', '名称': '工程造价', '金额': '0', '暂估价': '0', '类别' : '6', })
  1215. return result
  1216. async def zongjiaDwgc(client, biao_id, bh):
  1217. db = client["baojia"]
  1218. djcs_sum = 0###单价措施汇总
  1219. collection = db["Djcs"]
  1220. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  1221. djcs_sum = djcs_sum + float(post['合价'])
  1222. collection = db['Dwgc']
  1223. document = await collection.find_one({'biao_id': biao_id, "Dwgcbh": bh}, {'rcjhz': 0})
  1224. qdbt = document['qdbt']
  1225. qdbt_addition = document['qdbt_addition']
  1226. bts = {}
  1227. distinguish = True
  1228. for item in qdbt_addition:
  1229. bts[item['Mc']] = 0
  1230. collection = db["qdxm"]
  1231. qd_sum = 0###清单汇总
  1232. rgf_sum = 0
  1233. clf_sum = 0
  1234. jxf_sum = 0
  1235. glf_sum = 0
  1236. lr_sum = 0
  1237. fbrgycl_sum = 0
  1238. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  1239. qd_sum = qd_sum + float(post['合价'])
  1240. rgf_sum = rgf_sum + float(post['数量']) * float(post['人工费'])
  1241. clf_sum = clf_sum + float(post['数量']) * float(post['材料费'])
  1242. jxf_sum = jxf_sum + float(post['数量']) * float(post['机械费'])
  1243. glf_sum = glf_sum + float(post['数量']) * float(post['管理费'])
  1244. lr_sum = lr_sum + float(post['数量']) * float(post['利润'])
  1245. if distinguish and post['bt'] in bts:
  1246. bts[post['bt']] = bts[post['bt']] + float(post['合价'])
  1247. sum = qd_sum + djcs_sum##作为总价措施和后续费用计算的的计算基础
  1248. fbrgycl = document['fbrgycl']
  1249. for entry in fbrgycl:
  1250. fbrgycl_sum = fbrgycl_sum + float(entry['合价'])
  1251. zjcs = document['zjcs']
  1252. def process(n):
  1253. n['计算基数'] = str(sum)
  1254. n['金额'] = float(sum) * float(n['费率']) / float(100)
  1255. if "__children" in n:
  1256. for entry in n['__children']:
  1257. entry['计算基数'] = str(sum)
  1258. entry['金额'] = float(sum) * float(entry['费率']) / float(100)
  1259. return n
  1260. ##目标数据,会存到数据库
  1261. result = [process(item) for item in zjcs]
  1262. for entry in result:
  1263. if '安全文明施工' in entry['名称']:
  1264. sum_ = 0
  1265. for child in entry['__children']:
  1266. sum_ = sum_ + float(child['金额'])
  1267. entry['金额'] = str(sum_)
  1268. entry['计算基数'] = str(sum_)
  1269. zjcs_sum = 0###总价措施汇总
  1270. for entry in result:
  1271. zjcs_sum = zjcs_sum + float(entry['金额'])
  1272. qtxm = document['qtxm']##dwgc qtxm
  1273. qtxm_sum = 0###其他项目汇总, 为了计算规费税金,其他项目本身不会改变
  1274. for entry in qtxm:
  1275. qtxm_sum = qtxm_sum + float(entry['金额'])
  1276. gfsj = document['gfsj']
  1277. gf_sum = 0###规费税金汇总
  1278. sj_sum = 0
  1279. for item in gfsj:
  1280. if item['名称'] == '规费':
  1281. child = item['__children']
  1282. for children in child:
  1283. children['取费基数'] = str(sum + zjcs_sum + qtxm_sum)
  1284. children['金额'] = str(float(sum + zjcs_sum + qtxm_sum) * float(children['费率']) / float(100))
  1285. gf_sum = gf_sum + float(children['金额'])
  1286. for item in gfsj:
  1287. if item['名称'] == '规费':
  1288. item['取费基数'] = str(gf_sum)
  1289. item['金额'] = str(gf_sum)
  1290. for item in gfsj:
  1291. if item['名称'] == '税金':
  1292. item['取费基数'] = str(sum + zjcs_sum + qtxm_sum + gf_sum - fbrgycl_sum / float(1.01))
  1293. item['金额'] = float(item['取费基数']) * float(item['费率']) / float(100)
  1294. sj_sum = float(item['金额'])
  1295. for item in gfsj:
  1296. if item['名称'] == '合计':
  1297. item['取费基数'] = str(sj_sum + gf_sum)
  1298. item['金额'] = item['取费基数']
  1299. qtxm = document['qtxm']
  1300. zlje = 0
  1301. zygczgj = 0
  1302. jrg = 0
  1303. zcbfwf = 0
  1304. clzgj = 0
  1305. for entry in qtxm:
  1306. if entry['序号'] == '1':
  1307. zlje = entry['金额']
  1308. if entry['序号'] == '3':
  1309. jrg = entry['金额']
  1310. if entry['序号'] == '4':
  1311. zcbfwf = entry['金额']
  1312. if entry['序号'] == '2':
  1313. for child in entry['__children']:
  1314. if child['序号'] == '2.2':
  1315. zygczgj = child['金额']
  1316. if child['序号'] == '2.1':
  1317. clzgj = child['金额']
  1318. ###重新算了一遍其他项目汇总
  1319. qtxm_sum = float(zlje) + float(zygczgj) + float(jrg) + float(zcbfwf) + float(clzgj)
  1320. bjhz = bjhz_template()
  1321. for entry in bjhz:
  1322. if entry['序号'] == '1':
  1323. entry['金额'] = qd_sum
  1324. for child in entry['__children']:
  1325. if child['序号'] == '1.1':
  1326. child['金额'] = str(rgf_sum)
  1327. if child['序号'] == '1.2':
  1328. child['金额'] = str(clf_sum)
  1329. if child['序号'] == '1.3':
  1330. child['金额'] = str(jxf_sum)
  1331. if child['序号'] == '1.4':
  1332. child['金额'] = str(glf_sum)
  1333. if child['序号'] == '1.5':
  1334. child['金额'] = str(lr_sum)
  1335. if entry['序号'] == '2':
  1336. entry['金额'] = str(djcs_sum + zjcs_sum)
  1337. for child in entry['__children']:
  1338. if child['序号'] == '2.1':
  1339. child['金额'] = str(djcs_sum)
  1340. if child['序号'] == '2.2':
  1341. child['金额'] = str(zjcs_sum)
  1342. for grandchild in child['__children']:
  1343. if grandchild['序号'] == '2.2.1':
  1344. grandchild['金额'] = str(sum_)
  1345. if entry['序号'] == '3':
  1346. entry['金额'] = str(qtxm_sum)
  1347. if entry['序号'] == '4':
  1348. entry['金额'] = str(gf_sum)
  1349. if entry['序号'] == '5':
  1350. entry['金额'] = str(sj_sum)
  1351. if entry['序号'] == '6':
  1352. entry['金额'] = str(float(qd_sum) + float(djcs_sum) + float(zjcs_sum) + float(qtxm_sum) + float(gf_sum) + float(sj_sum))
  1353. collection = db['Dwgc']
  1354. if distinguish:
  1355. for entry in qdbt_addition:
  1356. entry['Je'] = str(bts[entry['Mc']])
  1357. await collection.update_one({'biao_id': biao_id, "Dwgcbh": bh}, {'$set': {'zjcs': result, 'gfsj' : gfsj, 'bjhz': bjhz, 'qdbt_addition' : qdbt_addition}})
  1358. async def tbxx(client, biao_id):
  1359. db = client["baojia"]
  1360. collection = db["jingjibiao"]
  1361. document = await collection.find_one({'_id': ObjectId(biao_id)})
  1362. dxgcxx = document['Dxgcxx']
  1363. tbxx = document['TouBiaoXx']
  1364. tbxx['Tbzj'] = '0'
  1365. tbxx['Zgj'] = '0'
  1366. tbxx['Aqwmf'] = '0'
  1367. tbxx['Gf'] = '0'
  1368. dwdx = {}##单位工程映射单项工程
  1369. for dxgc in dxgcxx:
  1370. dxgc['Aqwmf'] = '0'
  1371. dxgc['Gf'] = '0'
  1372. dxgc['Je'] = '0'
  1373. dxgc['Zgj'] = '0'
  1374. mc = dxgc['Dxgcmc']
  1375. Dwgc = dxgc['Dwgc']
  1376. for dwgc in Dwgc:
  1377. Dwgcbh = dwgc['Dwgcbh']
  1378. dwdx[Dwgcbh] = dxgc
  1379. collection = db['Dwgc']
  1380. async for post in collection.find({'biao_id': biao_id}):
  1381. bh = post['Dwgcbh']
  1382. dx = dwdx[bh]
  1383. bjhz = post['bjhz']
  1384. if len(bjhz) == 0:
  1385. pass
  1386. else:
  1387. qtxm = post['qtxm']
  1388. dx['Aqwmf'] = str(float(dx['Aqwmf']) + float(bjhz[1]['__children'][1]['__children'][0]['金额']))
  1389. dx['Gf'] = str(float(dx['Gf']) + float(bjhz[3]['金额']))
  1390. dx['Je'] = str(float(dx['Je']) + float(bjhz[5]['金额']))
  1391. dx['Zgj']= str(float(dx['Zgj']) + float(qtxm[1]['金额']))
  1392. for dxgc in dxgcxx:
  1393. tbxx['Tbzj'] = str(float(tbxx['Tbzj']) + float(dxgc['Je']))
  1394. tbxx['Zgj'] = str(float(tbxx['Zgj']) + float(dxgc['Zgj']))
  1395. tbxx['Aqwmf'] = str(float(tbxx['Aqwmf']) + float(dxgc['Aqwmf']))
  1396. tbxx['Gf'] = str(float(tbxx['Gf']) + float(dxgc['Gf']))
  1397. collection = db["jingjibiao"]
  1398. await collection.update_one({'_id': ObjectId(biao_id)}, {'$set': {'Dxgcxx': dxgcxx, 'TouBiaoXx' : tbxx}})
  1399. async def updatezjcs(client, id, bh, mc, fl):
  1400. db = client["baojia"]
  1401. collection = db["Dwgc"]
  1402. document = await collection.find_one({'biao_id': id, 'Dwgcbh': bh}, {'rcjhz': 0})
  1403. zjcs = document['zjcs']
  1404. for entry in zjcs:
  1405. if entry['名称'] == mc:
  1406. entry['费率'] = fl
  1407. entry['金额'] = str(float(entry['计算基数']) * float(fl) / float(100))
  1408. await collection.update_one({'biao_id': id, "Dwgcbh": bh}, {'$set': {'zjcs': zjcs}})
  1409. await zongjiaDwgc(client, id, bh)
  1410. await tbxx(client, id)
  1411. #################保存清单项#############################
  1412. async def save(client, data):
  1413. db = client["baojia"]
  1414. collection = db["qdxm"]
  1415. biao_id = None
  1416. bh = None
  1417. for entry in data:
  1418. entry["__children"] = entry["_children"]
  1419. del entry["_children"]
  1420. biao_id = entry['biao_id']
  1421. bh = entry['Dwgcbh']
  1422. await collection.replace_one({"biao_id": entry["biao_id"], "Dwgcbh": entry["Dwgcbh"], "bt": entry["bt"], "清单编码": entry["清单编码"]}, entry)
  1423. if not biao_id:
  1424. return {"result" : "ok"}
  1425. rcjhz = []
  1426. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  1427. qdrcj = post['rcj'][1:]
  1428. for entry in qdrcj:
  1429. print(entry[4])
  1430. if entry[4] != '%':
  1431. entry[10] = float(entry[10]) * float(post['数量'])
  1432. rcjhz = rcjhz + qdrcj
  1433. collection = db["Djcs"]
  1434. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  1435. qdrcj = post['rcj'][1:]
  1436. for entry in qdrcj:
  1437. print(entry[4])
  1438. if entry[4] != '%':
  1439. entry[10] = float(entry[10]) * float(post['数量'])
  1440. rcjhz = rcjhz + qdrcj
  1441. newHuizong = util.huizongrcj(rcjhz)
  1442. collection = db["Dwgc"]
  1443. await collection.update_one({'biao_id': biao_id, 'Dwgcbh': bh}, {'$set': {'rcjhz' : newHuizong}})
  1444. await zongjiaDwgc(client, biao_id, bh)
  1445. await tbxx(client, biao_id)
  1446. return {"result": "ok"}
  1447. async def savedjcs(client, data):
  1448. db = client["baojia"]
  1449. collection = db["Djcs"]
  1450. biao_id = None
  1451. bh = None
  1452. for entry in data:
  1453. entry["__children"] = entry["_children"]
  1454. del entry["_children"]
  1455. biao_id = entry['biao_id']
  1456. bh = entry['Dwgcbh']
  1457. await collection.replace_one({"biao_id": entry["biao_id"], "Dwgcbh": entry["Dwgcbh"], "清单编码": entry["清单编码"]}, entry)
  1458. if not biao_id:
  1459. return {"result" : "ok"}
  1460. rcjhz = []
  1461. collection = db["qdxm"]
  1462. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  1463. qdrcj = post['rcj'][1:]
  1464. for entry in qdrcj:
  1465. if entry[4] != '%':
  1466. entry[10] = float(entry[10]) * float(post['数量'])
  1467. rcjhz = rcjhz + qdrcj
  1468. collection = db["Djcs"]
  1469. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  1470. qdrcj = post['rcj'][1:]
  1471. for entry in qdrcj:
  1472. if entry[4] != '%':
  1473. entry[10] = float(entry[10]) * float(post['数量'])
  1474. rcjhz = rcjhz + qdrcj
  1475. newHuizong = util.huizongrcj(rcjhz)
  1476. collection = db["Dwgc"]
  1477. await collection.update_one({'biao_id': biao_id, 'Dwgcbh': bh}, {'$set': {'rcjhz' : newHuizong}})
  1478. await zongjiaDwgc(client, biao_id, bh)
  1479. await tbxx(client, biao_id)
  1480. return {"result": "ok"}
  1481. async def applyFL(client, id, data):
  1482. db = client["baojia"]
  1483. collection = db["qufei"]
  1484. await collection.replace_one({"biao_id": id}, {"biao_id": id, "qufei": data})
  1485. collection = db['qdxm']
  1486. xm = data[0]
  1487. for dxgc in xm["children"]:
  1488. for dwgc in dxgc["children"]:
  1489. bh = dwgc['key']
  1490. glf = float(dwgc['管理费(%)'])
  1491. lr = float(dwgc['利润(%)'])
  1492. bz = dwgc['备注']
  1493. ##print(bh+glf+lr+bz)
  1494. async for post in collection.find({'biao_id': id, "Dwgcbh": bh}):
  1495. rgfs = float(post['人工费'])
  1496. clfs = float(post['材料费'])
  1497. jxfs = float(post['机械费'])
  1498. sl = float(post['数量'])
  1499. if rgfs < 0.0001 and clfs < 0.0001 and jxfs < 0.0001:
  1500. continue
  1501. ##danxiang = False
  1502. for child in post['__children']:##一条定额
  1503. bm = child['清单编码']
  1504. if bm.startswith("D"):
  1505. ##danxiang = True
  1506. continue
  1507. rgf = float(child['人工费'])
  1508. clf = float(child['材料费'])
  1509. jxf = float(child['机械费'])
  1510. zhdj = float(child['综合单价'])
  1511. sl_ = float(child['数量'])
  1512. if len(bz) == 0:
  1513. ##常规计算
  1514. child['管理费'] = (rgf + jxf) * glf / float(100)
  1515. child['利润'] = (rgf + jxf) * lr / float(100)
  1516. child['综合单价'] = rgf + clf + jxf + child['管理费'] + child['利润']
  1517. child['合价'] = sl * sl_ * child['综合单价']
  1518. else:
  1519. child['管理费'] = (rgf) * glf / float(100)
  1520. child['利润'] = (rgf) * lr / float(100)
  1521. child['综合单价'] = rgf + clf + jxf + child['管理费'] + child['利润']
  1522. child['合价'] = sl * sl_ * child['综合单价']
  1523. if True:
  1524. post['管理费'] = 0
  1525. post['利润'] = 0
  1526. for entry in post['__children']:
  1527. post['管理费'] = post['管理费'] + float(entry['管理费']) * float(entry['数量'])
  1528. post['利润'] = post['利润'] + float(entry['利润']) * float(entry['数量'])
  1529. post['管理费'] = str(post['管理费'])
  1530. post['利润'] = str(post['利润'])
  1531. post['综合单价'] = str(float(post['人工费']) + float(post['材料费']) + float(post['机械费']) + float(post['管理费']) + float(post['利润']))
  1532. post['合价'] = str(float(post['综合单价']) * float(post['数量']))
  1533. await collection.replace_one({'_id': post['_id']}, post )
  1534. collection = db['Djcs']
  1535. for dxgc in xm["children"]:
  1536. for dwgc in dxgc["children"]:
  1537. bh = dwgc['key']
  1538. glf = float(dwgc['管理费(%)'])
  1539. lr = float(dwgc['利润(%)'])
  1540. bz = dwgc['备注']
  1541. ##print(bh+glf+lr+bz)
  1542. async for post in collection.find({'biao_id': id, "Dwgcbh": bh}):
  1543. rgfs = float(post['人工费'])
  1544. clfs = float(post['材料费'])
  1545. jxfs = float(post['机械费'])
  1546. sl = float(post['数量'])
  1547. if rgfs < 0.0001 and clfs < 0.0001 and jxfs < 0.0001:
  1548. continue
  1549. ##danxiang = False##一般有单项定额的,清单就一条定额,就是这个单项定额
  1550. for child in post['__children']:
  1551. bm = child['清单编码']
  1552. if bm.startswith("D"):
  1553. ##danxiang = True
  1554. continue
  1555. rgf = float(child['人工费'])
  1556. clf = float(child['材料费'])
  1557. jxf = float(child['机械费'])
  1558. zhdj = float(child['综合单价'])
  1559. sl_ = float(child['数量'])
  1560. if len(bz) == 0:
  1561. ##常规计算
  1562. child['管理费'] = (rgf + jxf) * glf / float(100)
  1563. child['利润'] = (rgf + jxf) * lr / float(100)
  1564. child['综合单价'] = rgf + clf + jxf + child['管理费'] + child['利润']
  1565. child['合价'] = sl * sl_ * child['综合单价']
  1566. else:
  1567. child['管理费'] = (rgf) * glf / float(100)
  1568. child['利润'] = (rgf) * lr / float(100)
  1569. child['综合单价'] = rgf + clf + jxf + child['管理费'] + child['利润']
  1570. child['合价'] = sl * sl_ * child['综合单价']
  1571. if True:
  1572. post['管理费'] = 0
  1573. post['利润'] = 0
  1574. for entry in post['__children']:
  1575. post['管理费'] = post['管理费'] + float(entry['管理费']) * float(entry['数量'])
  1576. post['利润'] = post['利润'] + float(entry['利润']) * float(entry['数量'])
  1577. post['管理费'] = str(post['管理费'])
  1578. post['利润'] = str(post['利润'])
  1579. post['综合单价'] = str(float(post['人工费']) + float(post['材料费']) + float(post['机械费']) + float(post['管理费']) + float(post['利润']))
  1580. post['合价'] = str(float(post['综合单价']) * float(post['数量']))
  1581. await collection.replace_one({'_id': post['_id']}, post )
  1582. for dxgc in xm["children"]:
  1583. for dwgc in dxgc["children"]:
  1584. bh = dwgc['key']
  1585. await zongjiaDwgc(client, id, bh)
  1586. await tbxx(client, id)
  1587. return {"result": "ok"}
  1588. ###人材机汇总页面调价
  1589. async def tiaojia(client, biao_id, bh, bm, mingcheng, danwei, jiage, glf, lr, bz):
  1590. db = client["baojia"]
  1591. rcjhz = []
  1592. collection = db["qdxm"]
  1593. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}):
  1594. if "__children" not in post:
  1595. ##print(post)
  1596. continue
  1597. children = post["__children"]
  1598. qdsl = post['数量']
  1599. hit = False##清单级别
  1600. for entry in children:###对一条定额,调价
  1601. hitde = False
  1602. dercj = entry["dercj"]
  1603. dergf = 0
  1604. declf = 0
  1605. dezcf = 0
  1606. dejxf = 0
  1607. for i in range(1, len(dercj)):
  1608. rcj = dercj[i]
  1609. if rcj[1] == bm and rcj[2] == mingcheng and rcj[4] == danwei:
  1610. hit = True
  1611. hitde = True
  1612. rcj[5] = jiage
  1613. hanliang = rcj[10]
  1614. rcj[11] = str(float(jiage) * float(hanliang))
  1615. if int(rcj[8]) == 1:##rcjlb
  1616. dergf = dergf + float(rcj[11])
  1617. elif int(rcj[8]) == 2:
  1618. declf = declf + float(rcj[11])
  1619. if rcj[14] == 'true' :
  1620. dezcf = dezcf + float(rcj[11])
  1621. elif int(rcj[8]) == 3:
  1622. dejxf = dejxf + float(rcj[11])
  1623. if hitde:
  1624. entry['人工费'] = str(dergf)
  1625. entry['辅材费'] = str(declf - dezcf)
  1626. entry['主材费'] = str(dezcf)
  1627. entry['材料费'] = str(declf)
  1628. entry['机械费'] = str(dejxf)
  1629. if bm.startswith("D"):
  1630. entry['管理费'] = '0'
  1631. entry['利润'] = '0'
  1632. elif bz == 0:
  1633. entry['管理费'] = str((dergf + dejxf) * float(glf) / float(100))
  1634. entry['利润'] = str((dergf + dejxf) * float(lr) / float(100))
  1635. else:
  1636. entry['管理费'] = str((dergf) * float(glf) / float(100))
  1637. entry['利润'] = str((dergf) * float(lr) / float(100))
  1638. entry['综合单价'] = str(float(entry['人工费']) + float(entry['材料费']) + float(entry['机械费']) + float(entry['管理费']) + float(entry['利润']))
  1639. entry['合价'] = str(float(entry['综合单价']) * float(entry['数量']) * float(qdsl))
  1640. if hit:
  1641. post['综合单价'] = 0
  1642. post['合价'] = 0
  1643. post['人工费'] = 0
  1644. post['主材费'] = 0
  1645. post['设备费'] = 0
  1646. post['辅材费'] = 0
  1647. post['材料费'] = 0
  1648. post['机械费'] = 0
  1649. post['管理费'] = 0
  1650. post['利润'] = 0
  1651. for i in range(len(post["__children"])):
  1652. if len(post["__children"][i]['azfytag']) > 0:
  1653. continue
  1654. post['综合单价'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['综合单价'])
  1655. post['合价'] += float(post['__children'][i]['合价'])
  1656. post['人工费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['人工费'])
  1657. post['主材费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['主材费'])
  1658. post['设备费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['设备费'])
  1659. post['辅材费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['辅材费'])
  1660. post['材料费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['材料费'])
  1661. post['机械费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['机械费'])
  1662. post['管理费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['管理费'])
  1663. post['利润'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['利润'])
  1664. ##处理安装费用
  1665. ##console.log(qd["_children"].length);
  1666. for i in range(len(post["__children"])):
  1667. ##console.log(i);
  1668. if len(post["__children"][i]['azfytag']) > 0:
  1669. tag = post["__children"][i]['azfytag']
  1670. if tag[0] == '人工费':
  1671. current_rgf = post['人工费']
  1672. added = float(current_rgf) * float(tag[1]) / float(100)
  1673. added_rgf = added * float(tag[2]) / float(100)
  1674. added_clf = added * float(tag[3]) / float(100)
  1675. added_jxf = added * float(tag[4]) / float(100)
  1676. post["__children"][i]['人工费'] = added_rgf
  1677. post["__children"][i]['辅材费'] = added_clf
  1678. post["__children"][i]['材料费'] = added_clf
  1679. post["__children"][i]['机械费'] = added_jxf
  1680. if bz == 0:
  1681. ##changuiqufei
  1682. post["__children"][i]['管理费'] = (added_rgf + added_jxf) * float(glf) / float(100)
  1683. post["__children"][i]['利润'] = (added_rgf + added_jxf) * float(lr) / float(100)
  1684. else:
  1685. post["__children"][i]['管理费'] = (added_rgf) * float(glf) / float(100)
  1686. post["__children"][i]['利润'] = (added_rgf) * float(lr) / float(100)
  1687. post["__children"][i]['综合单价'] = post["__children"][i]['人工费'] + post["__children"][i]['材料费'] + post["__children"][i]['机械费'] + post["__children"][i]['管理费'] + post["__children"][i]['利润']
  1688. post["__children"][i]['合价'] = post["__children"][i]['综合单价'] * float(post["__children"][i]['数量']) * float(post['数量'])
  1689. dercj = post["__children"][i]['dercj']
  1690. for j in range(1, len(dercj)):
  1691. dercj[j][11] = float(added) * float(dercj[j][10]) / float(100)
  1692. if tag[0] == '人工费+机械费':
  1693. current_rgf = post['人工费'] + post['机械费']
  1694. added = float(current_rgf) * float(tag[1]) / float(100)
  1695. added_rgf = added * float(tag[2]) / float(100)
  1696. added_clf = added * float(tag[3]) / float(100)
  1697. added_jxf = added * float(tag[4]) / float(100)
  1698. post["__children"][i]['人工费'] = added_rgf
  1699. post["__children"][i]['辅材费'] = added_clf
  1700. post["__children"][i]['材料费'] = added_clf
  1701. post["__children"][i]['机械费'] = added_jxf
  1702. if bz == 0:
  1703. ###changuiqufei
  1704. post["__children"][i]['管理费'] = (added_rgf + added_jxf) * float(glf) / float(100)
  1705. post["__children"][i]['利润'] = (added_rgf + added_jxf) * float(lr) / float(100)
  1706. else:
  1707. post["__children"][i]['管理费'] = (added_rgf) * float(glf) / float(100)
  1708. post["__children"][i]['利润'] = (added_rgf) * float(lr) / float(100)
  1709. post["__children"][i]['综合单价'] = post["__children"][i]['人工费'] + post["__children"][i]['材料费'] + post["__children"][i]['机械费'] + post["__children"][i]['管理费'] + post["__children"][i]['利润']
  1710. post["__children"][i]['合价'] = post["__children"][i]['综合单价'] * float(post["__children"][i]['数量']) * float(post["数量"])
  1711. dercj = post["__children"][i]['dercj']
  1712. for j in range(1, len(dercj)):
  1713. dercj[j][11] = float(added) * float(dercj[j][10]) / float(100)
  1714. qdrcj = []
  1715. for i in range(len(post["__children"])):
  1716. dercj = post["__children"][i]['dercj']
  1717. sl = post["__children"][i]['数量']
  1718. for entry in dercj:
  1719. if '000FE' in entry[1] and entry[4] == '%': ##azfy
  1720. qdrcj.append(entry)
  1721. elif '00EXP001' in entry[1] and entry[4] == '%': ##回程费
  1722. qdrcj.append(entry)
  1723. elif '99EXP007' in entry[1] and entry[4] == '%': ##回程费
  1724. qdrcj.append(entry)
  1725. elif '31130104' in entry[1] and entry[4] == '%': ##回程费
  1726. qdrcj.append(entry)
  1727. elif entry[10] != '含量':
  1728. entry[10] = float(sl) * float(entry[10])
  1729. qdrcj.append(entry)
  1730. post["rcj"] = util.huizongrcj_order(qdrcj)
  1731. post['综合单价'] = 0
  1732. post['合价'] = 0
  1733. post['人工费'] = 0
  1734. post['主材费'] = 0
  1735. post['设备费'] = 0
  1736. post['辅材费'] = 0
  1737. post['材料费'] = 0
  1738. post['机械费'] = 0
  1739. post['管理费'] = 0
  1740. post['利润'] = 0
  1741. for i in range(len(post["__children"])):
  1742. post['综合单价'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['综合单价'])
  1743. post['合价'] += float(post['__children'][i]['合价'])
  1744. post['人工费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['人工费'])
  1745. post['主材费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['主材费'])
  1746. post['设备费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['设备费'])
  1747. post['辅材费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['辅材费'])
  1748. post['材料费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['材料费'])
  1749. post['机械费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['机械费'])
  1750. post['管理费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['管理费'])
  1751. post['利润'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['利润'])
  1752. await collection.replace_one({'_id': post['_id']}, post )
  1753. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  1754. qdrcj = post['rcj'][1:]
  1755. for entry in qdrcj:
  1756. if entry[4] != '%':
  1757. entry[10] = float(entry[10]) * float(post['数量'])
  1758. rcjhz = rcjhz + qdrcj
  1759. collection = db["Djcs"]
  1760. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}):
  1761. if "__children" not in post:
  1762. ##print(post)
  1763. continue
  1764. children = post["__children"]
  1765. qdsl = post['数量']
  1766. hit = False
  1767. for entry in children:###对一条定额,调价
  1768. hitde = False
  1769. dercj = entry["dercj"]
  1770. dergf = 0
  1771. declf = 0
  1772. dejxf = 0
  1773. for i in range(1, len(dercj)):
  1774. rcj = dercj[i]
  1775. if rcj[1] == bm and rcj[2] == mingcheng and rcj[4] == danwei:
  1776. hit = True
  1777. hitde = True
  1778. rcj[5] = jiage
  1779. hanliang = rcj[10]
  1780. rcj[11] = str(float(jiage) * float(hanliang))
  1781. if int(rcj[8]) == 1:
  1782. dergf = dergf + float(rcj[11])
  1783. elif int(rcj[8]) == 2:
  1784. declf = declf + float(rcj[11])
  1785. elif int(rcj[8]) == 3:
  1786. dejxf = dejxf + float(rcj[11])
  1787. if hitde:
  1788. for i in range(1, len(dercj)):
  1789. rcj = dercj[i]
  1790. if rcj[1] == '00EXP001' and rcj[4] == '%':##//回程费占人工费
  1791. rcj[11] = float(rcj[10]) * dergf / float(100)
  1792. if rcj[1] == '99EXP007' and rcj[4] == '%':##//回程费占机械费
  1793. rcj[11] = float(rcj[10]) * dejxf / float(100)
  1794. if rcj[1] == '31130104' and rcj[4] == '%':##//回程费占材料费
  1795. rcj[11] = float(rcj[10]) * declf / float(100)
  1796. dergf = 0
  1797. declf = 0
  1798. dejxf = 0
  1799. for i in range(1, len(dercj)):
  1800. rcj = dercj[i]
  1801. if int(rcj[8]) == 1:
  1802. dergf = dergf + float(rcj[11])
  1803. elif int(rcj[8]) == 2:
  1804. declf = declf + float(rcj[11])
  1805. elif int(rcj[8]) == 3:
  1806. dejxf = dejxf + float(rcj[11])
  1807. entry['人工费'] = str(dergf)
  1808. entry['辅材费'] = str(declf)
  1809. entry['材料费'] = str(declf)
  1810. entry['机械费'] = str(dejxf)
  1811. if bm.startswith("D"):
  1812. entry['管理费'] = '0'
  1813. entry['利润'] = '0'
  1814. elif bz == 0:
  1815. entry['管理费'] = str((dergf + dejxf) * float(glf) / float(100))
  1816. entry['利润'] = str((dergf + dejxf) * float(lr) / float(100))
  1817. else:
  1818. entry['管理费'] = str((dergf) * float(glf) / float(100))
  1819. entry['利润'] = str((dergf) * float(lr) / float(100))
  1820. entry['综合单价'] = str(float(entry['人工费']) + float(entry['材料费']) + float(entry['机械费']) + float(entry['管理费']) + float(entry['利润']))
  1821. entry['合价'] = str(float(entry['综合单价']) * float(entry['数量']) * float(qdsl))
  1822. if hit:
  1823. qdrcj = []
  1824. for i in range(len(post["__children"])):
  1825. dercj = post["__children"][i]['dercj']
  1826. sl = post["__children"][i]['数量']
  1827. for entry in dercj:
  1828. if '000FE' in entry[1] and entry[4] == '%': ##azfy
  1829. qdrcj.append(entry)
  1830. elif '00EXP001' in entry[1] and entry[4] == '%': ##回程费
  1831. qdrcj.append(entry)
  1832. elif '99EXP007' in entry[1] and entry[4] == '%': ##回程费
  1833. qdrcj.append(entry)
  1834. elif '31130104' in entry[1] and entry[4] == '%': ##回程费
  1835. qdrcj.append(entry)
  1836. elif entry[10] != '含量':
  1837. entry[10] = float(sl) * float(entry[10])
  1838. qdrcj.append(entry)
  1839. post["rcj"] = util.huizongrcj_order(qdrcj)
  1840. post['综合单价'] = 0
  1841. post['合价'] = 0
  1842. post['人工费'] = 0
  1843. post['主材费'] = 0
  1844. post['设备费'] = 0
  1845. post['辅材费'] = 0
  1846. post['材料费'] = 0
  1847. post['机械费'] = 0
  1848. post['管理费'] = 0
  1849. post['利润'] = 0
  1850. for i in range(len(post["__children"])):
  1851. post['综合单价'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['综合单价'])
  1852. post['合价'] += float(post['__children'][i]['合价'])
  1853. post['人工费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['人工费'])
  1854. post['主材费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['主材费'])
  1855. post['设备费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['设备费'])
  1856. post['辅材费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['辅材费'])
  1857. post['材料费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['材料费'])
  1858. post['机械费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['机械费'])
  1859. post['管理费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['管理费'])
  1860. post['利润'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['利润'])
  1861. await collection.replace_one({'_id': post['_id']}, post )
  1862. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  1863. qdrcj = post['rcj'][1:]
  1864. for entry in qdrcj:
  1865. if entry[4] != '%':
  1866. entry[10] = float(entry[10]) * float(post['数量'])
  1867. rcjhz = rcjhz + qdrcj
  1868. newHuizong = util.huizongrcj(rcjhz)
  1869. collection = db["Dwgc"]
  1870. #document = await collection.find_one({'biao_id': biao_id, "Dwgcbh": bh})
  1871. await collection.update_one({'biao_id': biao_id, "Dwgcbh": bh}, {'$set': {'rcjhz': newHuizong}})
  1872. await zongjiaDwgc(client, biao_id, bh)
  1873. await tbxx(client, biao_id)
  1874. return newHuizong