db.py 104 KB

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