db.py 168 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990
  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. import re
  8. ###############helper##################
  9. def getDingercj_default(root, bh, bt, qdbm, debm, key):
  10. result = [["ID", "人材机编码", "名称", "规格型号", "单位", "单价", "产地",
  11. "供应厂商", "人材机类别", "甲供标志", "含量", "合价", "暂估价标志", "主要材料标志", "主材标志", "设备标志", "隐藏", "key", "bc" ]]
  12. #result.append(["ming cheng", "jin e", "zan gu jia", "anquan wenming fei", "guifei"])
  13. item = None
  14. for child in root:
  15. if child.tag == "Dxgcxx":
  16. for child1 in child:
  17. Dwgcbh = child1.attrib["Dwgcbh"]
  18. if Dwgcbh == bh:
  19. item = child1
  20. break
  21. ##result.append([child.attrib["Dxgcmc"], child.attrib["Je"], child.attrib["Zgj"], child.attrib["Aqwmf"], child.attrib["Gf"]])
  22. Fywj = None
  23. for child in item:
  24. if child.tag == 'Qdxm':
  25. Fywj= child
  26. break
  27. Rcjhz = None
  28. for child in item:
  29. if child.tag == 'Rcjhz':
  30. Rcjhz = child
  31. break
  32. kv = {}
  33. for entry in Rcjhz:
  34. kv[entry.attrib["RcjId"]]=entry
  35. container = None
  36. for child in Fywj:
  37. ##child is mx
  38. if child.tag == "Qdmx" and child.attrib["Qdbm"] == qdbm:
  39. zimu = child
  40. break
  41. box = None
  42. if not zimu:
  43. return result
  44. for child in zimu:
  45. if child.tag == "Qdxdezj":
  46. box = child
  47. break
  48. hlmx_parent = None
  49. for child in box:
  50. if child.attrib["Debm"] == debm and child.attrib['key'] == key:
  51. for grandchild in child:
  52. if grandchild.tag == "Qdxdercjhl":
  53. hlmx_parent = grandchild
  54. for child in hlmx_parent:
  55. result.append([child.attrib["RcjId"],
  56. kv[child.attrib["RcjId"]].attrib["RcjBm"],
  57. kv[child.attrib["RcjId"]].attrib["Mc"],
  58. kv[child.attrib["RcjId"]].attrib["Ggxh"],
  59. kv[child.attrib["RcjId"]].attrib["Dw"],
  60. kv[child.attrib["RcjId"]].attrib["Dj"],
  61. kv[child.attrib["RcjId"]].attrib["Cd"],
  62. kv[child.attrib["RcjId"]].attrib["Gycs"],
  63. kv[child.attrib["RcjId"]].attrib["Rcjlb"],
  64. kv[child.attrib["RcjId"]].attrib["Jgbz"],
  65. child.attrib["Rcjhl"], child.attrib["Rcjhj"], kv[child.attrib["RcjId"]].attrib["Zgjbz"],
  66. kv[child.attrib["RcjId"]].attrib["Zyclbz"], kv[child.attrib["RcjId"]].attrib["Zcbz"], kv[child.attrib["RcjId"]].attrib["Sbbz"], "", ""
  67. ])
  68. return result
  69. def getDingercj_(root, bh, bt, qdbm, debm, key):
  70. if bt == 'Default':
  71. return getDingercj_default(root, bh, bt, qdbm, debm, key)
  72. result = [["ID", "人材机编码", "名称", "规格型号", "单位", "单价", "产地",
  73. "供应厂商", "人材机类别", "甲供标志", "含量", "合价", "暂估价标志", "主要材料标志", "主材标志", "设备标志", "key", "bc" ]]
  74. #result.append(["ming cheng", "jin e", "zan gu jia", "anquan wenming fei", "guifei"])
  75. item = None
  76. for child in root:
  77. if child.tag == "Dxgcxx":
  78. for child1 in child:
  79. Dwgcbh = child1.attrib["Dwgcbh"]
  80. if Dwgcbh == bh:
  81. item = child1
  82. break
  83. ##result.append([child.attrib["Dxgcmc"], child.attrib["Je"], child.attrib["Zgj"], child.attrib["Aqwmf"], child.attrib["Gf"]])
  84. Fywj = None
  85. for child in item:
  86. if child.tag == 'Qdxm':
  87. Fywj= child
  88. break
  89. Rcjhz = None
  90. for child in item:
  91. if child.tag == 'Rcjhz':
  92. Rcjhz = child
  93. break
  94. kv = {}
  95. for entry in Rcjhz:
  96. kv[entry.attrib["RcjId"]]=entry
  97. container = None
  98. for child in Fywj:
  99. ##child is mx
  100. if child.tag == "QdBt":
  101. if child.attrib["Mc"] == bt:
  102. count = 0
  103. for grandchild in child:
  104. count = count + 1
  105. if count > 0:
  106. container = child
  107. break
  108. if not container:
  109. container = Fywj
  110. zimu = None
  111. for child in container:
  112. if child.attrib["Qdbm"] == qdbm:
  113. zimu = child
  114. break
  115. box = None
  116. if not zimu:
  117. return result
  118. for child in zimu:
  119. if child.tag == "Qdxdezj":
  120. box = child
  121. break
  122. hlmx_parent = None
  123. for child in box:
  124. if child.attrib["Debm"] == debm and child.attrib['key'] == key:
  125. for grandchild in child:
  126. if grandchild.tag == "Qdxdercjhl":
  127. hlmx_parent = grandchild
  128. for child in hlmx_parent:
  129. result.append([child.attrib["RcjId"],
  130. kv[child.attrib["RcjId"]].attrib["RcjBm"],
  131. kv[child.attrib["RcjId"]].attrib["Mc"],
  132. kv[child.attrib["RcjId"]].attrib["Ggxh"],
  133. kv[child.attrib["RcjId"]].attrib["Dw"],
  134. kv[child.attrib["RcjId"]].attrib["Dj"],
  135. kv[child.attrib["RcjId"]].attrib["Cd"],
  136. kv[child.attrib["RcjId"]].attrib["Gycs"],
  137. kv[child.attrib["RcjId"]].attrib["Rcjlb"],
  138. kv[child.attrib["RcjId"]].attrib["Jgbz"],
  139. child.attrib["Rcjhl"], child.attrib["Rcjhj"], kv[child.attrib["RcjId"]].attrib["Zgjbz"],
  140. kv[child.attrib["RcjId"]].attrib["Zyclbz"], kv[child.attrib["RcjId"]].attrib["Zcbz"], kv[child.attrib["RcjId"]].attrib["Sbbz"], "", ""
  141. ])
  142. return result
  143. def getQingdanrcj_default(root, bh, bt, bm):
  144. result = [["ID", "人材机编码", "名称", "规格型号", "单位", "单价", "产地",
  145. "供应厂商", "人材机类别", "甲供标志", "含量", "合价", "暂估价标志", "主要材料标志", "主材标志", "设备标志"]]
  146. #result.append(["ming cheng", "jin e", "zan gu jia", "anquan wenming fei", "guifei"])
  147. item = None
  148. for child in root:
  149. if child.tag == "Dxgcxx":
  150. for child1 in child:
  151. Dwgcbh = child1.attrib["Dwgcbh"]
  152. if Dwgcbh == bh:
  153. item = child1
  154. break
  155. ##result.append([child.attrib["Dxgcmc"], child.attrib["Je"], child.attrib["Zgj"], child.attrib["Aqwmf"], child.attrib["Gf"]])
  156. Fywj = None
  157. for child in item:
  158. if child.tag == 'Qdxm':
  159. Fywj= child
  160. break
  161. Rcjhz = None
  162. for child in item:
  163. if child.tag == 'Rcjhz':
  164. Rcjhz = child
  165. break
  166. kv = {}
  167. for entry in Rcjhz:
  168. kv[entry.attrib["RcjId"]]=entry
  169. container = None
  170. for child in Fywj:
  171. ##child is mx
  172. if child.tag == "Qdmx" and child.attrib["Qdbm"] == bm:
  173. zimu = child
  174. break
  175. box = None
  176. if not zimu:
  177. return result
  178. for child in zimu:
  179. if child.tag == "Qdxrcjhl":
  180. box = child
  181. break
  182. for child in box:
  183. result.append([child.attrib["RcjId"],
  184. kv[child.attrib["RcjId"]].attrib["RcjBm"],
  185. kv[child.attrib["RcjId"]].attrib["Mc"],
  186. kv[child.attrib["RcjId"]].attrib["Ggxh"],
  187. kv[child.attrib["RcjId"]].attrib["Dw"],
  188. kv[child.attrib["RcjId"]].attrib["Dj"],
  189. kv[child.attrib["RcjId"]].attrib["Cd"],
  190. kv[child.attrib["RcjId"]].attrib["Gycs"],
  191. kv[child.attrib["RcjId"]].attrib["Rcjlb"],
  192. kv[child.attrib["RcjId"]].attrib["Jgbz"],
  193. child.attrib["Rcjhl"], child.attrib["Rcjhj"], kv[child.attrib["RcjId"]].attrib["Zgjbz"],
  194. kv[child.attrib["RcjId"]].attrib["Zyclbz"], kv[child.attrib["RcjId"]].attrib["Zcbz"], kv[child.attrib["RcjId"]].attrib["Sbbz"]
  195. ])
  196. return result
  197. def getQingdanrcj_(root, bh, bt, bm):
  198. if bt == 'Default':
  199. return getQingdanrcj_default(root, bh, bt, bm)
  200. result = [["ID", "人材机编码", "名称", "规格型号", "单位", "单价", "产地",
  201. "供应厂商", "人材机类别", "甲供标志", "含量", "合价", "暂估价标志", "主要材料标志", "主材标志", "设备标志" ]]
  202. #result.append(["ming cheng", "jin e", "zan gu jia", "anquan wenming fei", "guifei"])
  203. item = None
  204. for child in root:
  205. if child.tag == "Dxgcxx":
  206. for child1 in child:
  207. Dwgcbh = child1.attrib["Dwgcbh"]
  208. if Dwgcbh == bh:
  209. item = child1
  210. break
  211. ##result.append([child.attrib["Dxgcmc"], child.attrib["Je"], child.attrib["Zgj"], child.attrib["Aqwmf"], child.attrib["Gf"]])
  212. Fywj = None
  213. for child in item:
  214. if child.tag == 'Qdxm':
  215. Fywj= child
  216. break
  217. Rcjhz = None
  218. for child in item:
  219. if child.tag == 'Rcjhz':
  220. Rcjhz = child
  221. break
  222. kv = {}
  223. for entry in Rcjhz:
  224. kv[entry.attrib["RcjId"]]=entry
  225. container = None
  226. for child in Fywj:
  227. ##child is mx
  228. if child.tag == "QdBt":
  229. if child.attrib["Mc"] == bt:
  230. count = 0
  231. for grandchild in child:
  232. count = count +1
  233. if count > 0:
  234. container = child
  235. break
  236. if container == None:
  237. container = Fywj
  238. zimu = None
  239. for child in container:
  240. if child.attrib["Qdbm"] == bm:
  241. zimu = child
  242. break
  243. box = None
  244. if not zimu:
  245. return result
  246. for child in zimu:
  247. if child.tag == "Qdxrcjhl":
  248. box = child
  249. break
  250. for child in box:
  251. result.append([child.attrib["RcjId"],
  252. kv[child.attrib["RcjId"]].attrib["RcjBm"],
  253. kv[child.attrib["RcjId"]].attrib["Mc"],
  254. kv[child.attrib["RcjId"]].attrib["Ggxh"],
  255. kv[child.attrib["RcjId"]].attrib["Dw"],
  256. kv[child.attrib["RcjId"]].attrib["Dj"],
  257. kv[child.attrib["RcjId"]].attrib["Cd"],
  258. kv[child.attrib["RcjId"]].attrib["Gycs"],
  259. kv[child.attrib["RcjId"]].attrib["Rcjlb"],
  260. kv[child.attrib["RcjId"]].attrib["Jgbz"],
  261. child.attrib["Rcjhl"], child.attrib["Rcjhj"], kv[child.attrib["RcjId"]].attrib["Zgjbz"],
  262. kv[child.attrib["RcjId"]].attrib["Zyclbz"], kv[child.attrib["RcjId"]].attrib["Zcbz"], kv[child.attrib["RcjId"]].attrib["Sbbz"]
  263. ])
  264. return result
  265. def getDjcsDingercj_(root, bh, bt, qdbm, debm, key):
  266. result = [["ID", "人材机编码", "名称", "规格型号", "单位", "单价", "产地",
  267. "供应厂商", "人材机类别", "甲供标志", "含量", "合价", "暂估价标志", "主要材料标志", "主材标志", "设备标志", "key", "bc" ]]
  268. #result.append(["ming cheng", "jin e", "zan gu jia", "anquan wenming fei", "guifei"])
  269. item = None
  270. for child in root:
  271. if child.tag == "Dxgcxx":
  272. for child1 in child:
  273. Dwgcbh = child1.attrib["Dwgcbh"]
  274. if Dwgcbh == bh:
  275. item = child1
  276. break
  277. ##result.append([child.attrib["Dxgcmc"], child.attrib["Je"], child.attrib["Zgj"], child.attrib["Aqwmf"], child.attrib["Gf"]])
  278. Fywj = None
  279. for child in item:
  280. if child.tag == 'Csxm':
  281. Fywj= child
  282. break
  283. Rcjhz = None
  284. for child in item:
  285. if child.tag == 'Rcjhz':
  286. Rcjhz = child
  287. break
  288. kv = {}
  289. for entry in Rcjhz:
  290. kv[entry.attrib["RcjId"]]=entry
  291. container = None
  292. for child in Fywj:
  293. if child.tag == "DjCs":
  294. container = child
  295. break
  296. zimu = None
  297. for child in container:
  298. if child.attrib["Bm"] == qdbm:
  299. zimu = child
  300. break
  301. box = None
  302. if not zimu:
  303. return result
  304. for child in zimu:
  305. if child.tag == "Csxdezj":
  306. box = child
  307. break
  308. hlmx_parent = None
  309. for child in box:
  310. if child.attrib["Debm"] == debm and child.attrib['key'] == key:
  311. for grandchild in child:
  312. if grandchild.tag == "Csxdercjhl":
  313. hlmx_parent = grandchild
  314. for child in hlmx_parent:
  315. result.append([child.attrib["RcjId"],
  316. kv[child.attrib["RcjId"]].attrib["RcjBm"],
  317. kv[child.attrib["RcjId"]].attrib["Mc"],
  318. kv[child.attrib["RcjId"]].attrib["Ggxh"],
  319. kv[child.attrib["RcjId"]].attrib["Dw"],
  320. kv[child.attrib["RcjId"]].attrib["Dj"],
  321. kv[child.attrib["RcjId"]].attrib["Cd"],
  322. kv[child.attrib["RcjId"]].attrib["Gycs"],
  323. kv[child.attrib["RcjId"]].attrib["Rcjlb"],
  324. kv[child.attrib["RcjId"]].attrib["Jgbz"],
  325. child.attrib["Rcjhl"], child.attrib["Rcjhj"], kv[child.attrib["RcjId"]].attrib["Zgjbz"],
  326. kv[child.attrib["RcjId"]].attrib["Zyclbz"], kv[child.attrib["RcjId"]].attrib["Zcbz"],
  327. kv[child.attrib["RcjId"]].attrib["Sbbz"], "", ""
  328. ])
  329. return result
  330. def getDjcsQingdanrcj_(root, bh, bt, bm):
  331. result = [["ID", "人材机编码", "名称", "规格型号", "单位", "单价", "产地",
  332. "供应厂商", "人材机类别", "甲供标志", "含量", "合价", "暂估价标志", "主要材料标志", "主材标志", "设备标志" ]]
  333. #result.append(["ming cheng", "jin e", "zan gu jia", "anquan wenming fei", "guifei"])
  334. item = None
  335. for child in root:
  336. if child.tag == "Dxgcxx":
  337. for child1 in child:
  338. Dwgcbh = child1.attrib["Dwgcbh"]
  339. if Dwgcbh == bh:
  340. item = child1
  341. break
  342. ##result.append([child.attrib["Dxgcmc"], child.attrib["Je"], child.attrib["Zgj"], child.attrib["Aqwmf"], child.attrib["Gf"]])
  343. Fywj = None
  344. for child in item:
  345. if child.tag == 'Csxm':
  346. Fywj= child
  347. break
  348. hl_parent = None
  349. for child in Fywj:
  350. if child.tag == "DjCs":
  351. hl_parent = child
  352. Rcjhz = None
  353. for child in item:
  354. if child.tag == 'Rcjhz':
  355. Rcjhz = child
  356. break
  357. kv = {}
  358. for entry in Rcjhz:
  359. kv[entry.attrib["RcjId"]]=entry
  360. zimu = None
  361. for child in hl_parent:
  362. if child.attrib["Bm"] == bm:
  363. zimu = child
  364. break
  365. box = None
  366. if not zimu:
  367. return result
  368. for child in zimu:
  369. if child.tag == "Csxrcjhl":
  370. box = child
  371. break
  372. for child in box:
  373. result.append([child.attrib["RcjId"],
  374. kv[child.attrib["RcjId"]].attrib["RcjBm"],
  375. kv[child.attrib["RcjId"]].attrib["Mc"],
  376. kv[child.attrib["RcjId"]].attrib["Ggxh"],
  377. kv[child.attrib["RcjId"]].attrib["Dw"],
  378. kv[child.attrib["RcjId"]].attrib["Dj"],
  379. kv[child.attrib["RcjId"]].attrib["Cd"],
  380. kv[child.attrib["RcjId"]].attrib["Gycs"],
  381. kv[child.attrib["RcjId"]].attrib["Rcjlb"],
  382. kv[child.attrib["RcjId"]].attrib["Jgbz"],
  383. child.attrib["Rcjhl"], child.attrib["Rcjhj"], kv[child.attrib["RcjId"]].attrib["Zgjbz"],
  384. kv[child.attrib["RcjId"]].attrib["Zyclbz"], kv[child.attrib["RcjId"]].attrib["Zcbz"], kv[child.attrib["RcjId"]].attrib["Sbbz"]
  385. ])
  386. return result
  387. def getRcjbc(rcj):
  388. result = []
  389. for entry in rcj:
  390. if '10000F' in entry[1]:
  391. result.append({
  392. "id": str(uuid.uuid4()),
  393. "主材标志": "true",
  394. "主要材料标志": "true",
  395. "产地": "",
  396. "人材机类别": "2",
  397. "人材机编码": entry[1],
  398. "供应厂商": "",
  399. "单价": entry[5],
  400. "单位": entry[4],
  401. "名称": entry[2],
  402. "含量": entry[10],
  403. "暂估价标志": "",
  404. "甲供标志": "",
  405. "规格型号": "",
  406. "设备标志": ""
  407. })
  408. return result
  409. ######################end of helper ########################
  410. async def resolve(data, client):
  411. root = ET.fromstring(data)
  412. ##print(root)
  413. Dwgcbh = []
  414. jingjibiao = {}
  415. jingjibiao['visible'] = False
  416. jingjibiao['created'] = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
  417. jingjibiao["BiaoDuanNO"] = root.attrib["BiaoDuanNO"]
  418. jingjibiao["Jsfs"] = root.attrib["Jsfs"]
  419. jingjibiao["Version"] = root.attrib["Version"]
  420. jingjibiao["Xmmc"] = root.attrib["Xmmc"]
  421. jingjibiao["Dxgcxx"] = []
  422. for child in root:
  423. if child.tag == "ZhaoBiaoXx":
  424. jingjibiao["ZhaoBiaoXx"] = {}
  425. jingjibiao["ZhaoBiaoXx"]["BzTime"] = child.attrib["BzTime"]
  426. jingjibiao["ZhaoBiaoXx"]["Bzr"] = child.attrib["Bzr"]
  427. jingjibiao["ZhaoBiaoXx"]["FhTime"] = child.attrib["FhTime"]
  428. jingjibiao["ZhaoBiaoXx"]["Fhr"] = child.attrib["Fhr"]
  429. jingjibiao["ZhaoBiaoXx"]["Zbr"] = child.attrib["Zbr"]
  430. jingjibiao["ZhaoBiaoXx"]["ZbrDb"] = child.attrib["ZbrDb"]
  431. jingjibiao["ZhaoBiaoXx"]["Zxr"] = child.attrib["Zxr"]
  432. jingjibiao["ZhaoBiaoXx"]["ZxrDb"] = child.attrib["ZxrDb"]
  433. elif child.tag == "TouBiaoXx":
  434. jingjibiao["TouBiaoXx"] = {}
  435. jingjibiao["TouBiaoXx"]["Zbr"] = child.attrib["Zbr"]
  436. jingjibiao["TouBiaoXx"]["Tbr"] = child.attrib["Tbr"]
  437. jingjibiao["TouBiaoXx"]["TbrDb"] = child.attrib["TbrDb"]
  438. jingjibiao["TouBiaoXx"]["Bzr"] = child.attrib["Bzr"]
  439. jingjibiao["TouBiaoXx"]["BzTime"] = child.attrib["BzTime"]
  440. jingjibiao["TouBiaoXx"]["Tbzj"] = child.attrib["Tbzj"]
  441. jingjibiao["TouBiaoXx"]["Zgj"] = child.attrib["Zgj"]
  442. jingjibiao["TouBiaoXx"]["Aqwmf"] = child.attrib["Aqwmf"]
  443. jingjibiao["TouBiaoXx"]["Gf"] = child.attrib["Gf"]
  444. elif child.tag == "Dxgcxx":
  445. Dxgcxx = {}
  446. Dxgcxx["Aqwmf"] = child.attrib["Aqwmf"]
  447. Dxgcxx["Dxgcbh"] = child.attrib["Dxgcbh"]
  448. Dxgcxx["Dxgcmc"] = child.attrib["Dxgcmc"]
  449. Dxgcxx["Gf"] = child.attrib["Gf"]
  450. Dxgcxx["Je"] = child.attrib["Je"]
  451. Dxgcxx["Zgj"] = child.attrib["Zgj"]
  452. Dxgcxx["Dwgc"] = []
  453. for grandchild in child:
  454. if grandchild.tag == "Dwgcxx":
  455. Dwgcxx = {}
  456. Dwgcxx["DogNum"] = grandchild.attrib["DogNum"]
  457. Dwgcxx["Dwgcbh"] = grandchild.attrib["Dwgcbh"]
  458. Dwgcbh.append({"bh": grandchild.attrib["Dwgcbh"], "num": grandchild.attrib["DogNum"]})
  459. Dwgcxx["Dwgcmc"] = grandchild.attrib["Dwgcmc"]
  460. Dwgcxx["MachineKey"] = grandchild.attrib["MachineKey"]
  461. Dwgcxx["SoftName"] = grandchild.attrib["SoftName"]
  462. Dwgcxx["SoftNum"] = grandchild.attrib["SoftNum"]
  463. Dwgcxx["Zylb"] = grandchild.attrib["Zylb"]
  464. Dxgcxx["Dwgc"].append(Dwgcxx)
  465. jingjibiao["Dxgcxx"].append(Dxgcxx)
  466. if not 'TouBiaoXx' in jingjibiao:
  467. jingjibiao['TouBiaoXx'] = {'Tbzj' : '', 'Zgj' : '', 'Aqwmf' : '', 'Gf' : '' }
  468. db = client["baojia"]
  469. collection = db["jingjibiao"]
  470. biao_id = (await collection.insert_one(jingjibiao)).inserted_id
  471. biao_id = str(biao_id)
  472. collection = db["Dwgc"]
  473. for entry in Dwgcbh:
  474. bjhz = service.getBjhz(root, entry["bh"])###array which contains __children
  475. gfsj = service.getGfsj(root, entry["bh"])##array which contains __children
  476. qtxm = service.getQtxm(root, entry["bh"])##array which contains __children
  477. zlje = service.getZlje(root, entry["bh"])
  478. jrg = service.getJrg(root, entry["bh"])
  479. zcbfwf = service.getZcbfwf(root, entry["bh"])
  480. fbrgycl = service.getFbrgycl(root, entry["bh"])
  481. rcjhz = service.getRcjhz(root, entry["bh"])
  482. zjcs = service.getZjcs(root, entry["bh"])
  483. qdbt = service.getQdxm(root, entry["bh"])
  484. qdbt_addition = service.getQdxm_addition(root, entry["bh"])
  485. zygczgj = service.getZygczgj(root, entry["bh"])
  486. Dwgc = {}
  487. Dwgc["bjhz"] = bjhz
  488. Dwgc["gfsj"] = gfsj
  489. Dwgc["qtxm"] = qtxm
  490. Dwgc["zlje"] = zlje
  491. Dwgc["jrg"] = jrg
  492. Dwgc['zygczgj'] = zygczgj
  493. Dwgc["zcbfwf"] = zcbfwf
  494. Dwgc["fbrgycl"] = fbrgycl
  495. Dwgc["rcjhz"] = rcjhz
  496. Dwgc["zjcs"] = zjcs
  497. Dwgc["qdbt"] = qdbt
  498. Dwgc['qdbt_addition'] = qdbt_addition
  499. Dwgc["DogNum"] = entry["num"]
  500. Dwgc["Dwgcbh"] = entry["bh"]
  501. Dwgc["biao_id"] = biao_id
  502. await collection.insert_one(Dwgc)
  503. collection = db["Djcs"]
  504. for entry in Dwgcbh:
  505. djcs = service.getDjcs(root, entry["bh"])
  506. for cs in djcs:
  507. cs["DogNum"] = entry["num"]
  508. cs["Dwgcbh"] = entry["bh"]
  509. cs["biao_id"] = biao_id
  510. rcj = getDjcsQingdanrcj_(root, entry["bh"], "", cs['清单编码'])
  511. cs["rcj"] = rcj
  512. if "__children" in cs:
  513. children = cs["__children"]
  514. for child in children:
  515. dercj = getDjcsDingercj_(root, entry["bh"], "", cs["清单编码"], child["清单编码"], child['key'])
  516. child["dercj"] = dercj
  517. child['fuzhuEnable'] = False
  518. child['yuban'] = []
  519. await collection.insert_one(cs)
  520. collection = db["qdxm"]
  521. for entry in Dwgcbh:
  522. bts = service.getQdxm(root, entry["bh"])
  523. for bt in bts:
  524. if bt == 'Default':
  525. qdmx = service.getQdmx_default(root, entry["bh"], bt)
  526. else:
  527. qdmx = service.getQdmx(root, entry["bh"], bt)
  528. for qd in qdmx:
  529. qd["DogNum"] = entry["num"]
  530. qd["Dwgcbh"] = entry["bh"]
  531. qd["biao_id"] = biao_id
  532. qd["bt"] = bt
  533. rcj = getQingdanrcj_(root, entry["bh"], bt, qd["清单编码"])
  534. qd["rcj"] = rcj
  535. if "__children" in qd:
  536. children = qd["__children"]
  537. for child in children:
  538. dercj = getDingercj_(root, entry["bh"], bt, qd["清单编码"], child["清单编码"], child['key'])
  539. child["dercj"] = dercj
  540. child['fuzhuEnable'] = False
  541. child['yuban'] = []
  542. child['rcjbc'] = getRcjbc(dercj)
  543. child['azfytag'] = []###常规定额
  544. await collection.insert_one(qd)
  545. collection = db["qufei"]
  546. document = jingjibiao
  547. dxgc = document['Dxgcxx']
  548. result = []
  549. for entry in dxgc:
  550. newone = {"名称" : entry['Dxgcmc'], "工程类型":"", "工程类别": "", "管理费(%)": "", "利润(%)": "","备注":"", "key" : str(uuid.uuid4()) }
  551. children = []
  552. for dwgc in entry['Dwgc']:
  553. children.append({"名称" : dwgc['Dwgcmc'], "工程类型":"", "工程类别": "", "管理费(%)": "", "利润(%)": "","备注":"", "key" : dwgc['Dwgcbh']})
  554. newone["children"] = children
  555. result.append(newone)
  556. await collection.insert_one({"biao_id": biao_id, "qufei": [{
  557. "名称" : document['Xmmc'], "工程类型":"", "工程类别": "", "管理费(%)": "", "利润(%)": "","备注":"", "key" : str(uuid.uuid4()), "children" : result
  558. }]})
  559. collection = db["jingjibiao"]
  560. await collection.update_one({'_id': ObjectId(biao_id)}, {'$set': {'visible': True}})
  561. def dfs(items):
  562. result = []
  563. for entry in items:
  564. result.append([entry['序号'], entry['名称'], entry['金额'], entry['暂估价'], entry['类别']])
  565. if '__children' in entry:
  566. result_ = dfs(entry['__children'])
  567. for r in result_:
  568. result.append(r)
  569. return result
  570. def dfs2(items):
  571. result = []
  572. for entry in items:
  573. result.append([entry['序号'], entry['名称'], entry['取费基数'], entry['计算基础'], entry['费率'], entry['金额'], entry['类别']])
  574. if '__children' in entry:
  575. result_ = dfs2(entry['__children'])
  576. for r in result_:
  577. result.append(r)
  578. return result
  579. def dfs3(items):
  580. result = []
  581. for entry in items:
  582. result.append([entry['序号'], entry['名称'], entry['金额'], entry['项目类别'], entry['备注']])
  583. if '__children' in entry:
  584. result_ = dfs3(entry['__children'])
  585. for r in result_:
  586. result.append(r)
  587. return result
  588. def roundstr(input):
  589. a = float(input)
  590. b = round(a, 2)
  591. return str(b)
  592. def roundstr4(input):
  593. a = float(input)
  594. b = round(a, 4)
  595. return str(b)
  596. ###################################build xml file##################################
  597. async def build(client, root, id):
  598. db = client["baojia"]
  599. collection = db["jingjibiao"]
  600. document = await collection.find_one({'_id': ObjectId(id)})
  601. root.set('BiaoDuanNO', document['BiaoDuanNO'])
  602. root.set('Jsfs', document['Jsfs'])
  603. root.set('Version', document['Version'])
  604. root.set('Xmmc', document['Xmmc'])
  605. TouBiaoXx = ET.SubElement(root, 'TouBiaoXx')
  606. ##{'Tbzj' : '', 'Zgj' : '', 'Aqwmf' : '', 'Gf' : '' }
  607. TouBiaoXx.set('Tbzj', roundstr(document['TouBiaoXx']['Tbzj']))
  608. TouBiaoXx.set('Zgj', roundstr(document['TouBiaoXx']['Zgj']))
  609. TouBiaoXx.set('Aqwmf', roundstr(document['TouBiaoXx']['Aqwmf']))
  610. TouBiaoXx.set('Gf', roundstr(document['TouBiaoXx']['Gf']))
  611. if 'Zbr' in document['TouBiaoXx']:
  612. TouBiaoXx.set('Zbr', str(document['TouBiaoXx']['Zbr']))
  613. if 'Tbr' in document['TouBiaoXx']:
  614. TouBiaoXx.set('Tbr', str(document['TouBiaoXx']['Tbr']))
  615. if 'TbrDb' in document['TouBiaoXx']:
  616. TouBiaoXx.set('TbrDb', str(document['TouBiaoXx']['TbrDb']))
  617. if 'Bzr' in document['TouBiaoXx']:
  618. TouBiaoXx.set('Bzr', str(document['TouBiaoXx']['Bzr']))
  619. if 'BzTime' in document['TouBiaoXx']:
  620. TouBiaoXx.set('BzTime', str(document['TouBiaoXx']['BzTime']))
  621. for item in document['Dxgcxx']:
  622. Dxgcxx = ET.SubElement(root, 'Dxgcxx')
  623. Dxgcxx.set('Dxgcbh', str(item['Dxgcbh']))
  624. Dxgcxx.set('Dxgcmc', str(item['Dxgcmc']))
  625. Dxgcxx.set('Je', roundstr(item['Je']))
  626. Dxgcxx.set('Zgj', roundstr(item['Zgj']))
  627. Dxgcxx.set('Aqwmf', roundstr(item['Aqwmf']))
  628. Dxgcxx.set('Gf', roundstr(item['Gf']))
  629. for entry in item['Dwgc']:
  630. Dwgcxx = ET.SubElement(Dxgcxx, 'Dwgcxx')
  631. Dwgcxx.set('Dwgcbh', str(entry['Dwgcbh']))
  632. Dwgcxx.set('Dwgcmc', str(entry['Dwgcmc']))
  633. Dwgcxx.set('Zylb', str(entry['Zylb']))
  634. Dwgcxx.set('SoftName', str(entry['SoftName']))
  635. Dwgcxx.set('SoftNum', str(entry['SoftNum']))
  636. Dwgcxx.set('DogNum', str(entry['DogNum']))
  637. Dwgcxx.set('MachineKey', str(entry['MachineKey']))
  638. collection = db["Dwgc"]
  639. Dwgc = await collection.find_one({'biao_id': id, "Dwgcbh": entry['Dwgcbh']})
  640. bjhz = dfs(Dwgc['bjhz'])
  641. gfsj = dfs2(Dwgc['gfsj'])
  642. qtxm = dfs3(Dwgc['qtxm'])
  643. zlje = Dwgc['zlje']
  644. zygczgj = Dwgc['zygczgj']
  645. jrg = Dwgc['jrg']
  646. zcbfwf = Dwgc['zcbfwf']
  647. fbrgycl = Dwgc['fbrgycl']
  648. rcjhz = Dwgc['rcjhz']
  649. zjcs = Dwgc['zjcs']
  650. qdbt = Dwgc['qdbt']
  651. ########################################Fywj##########################
  652. Fywj = ET.SubElement(Dwgcxx, 'Fywj')
  653. for bjhz_ in bjhz:
  654. FywjMx = ET.SubElement(Fywj, 'FywjMx')
  655. FywjMx.set('Xh', str(bjhz_[0]))
  656. FywjMx.set('Mc', str(bjhz_[1]))
  657. FywjMx.set('Je', roundstr(bjhz_[2]))
  658. FywjMx.set('Zgj', roundstr(bjhz_[3]))
  659. FywjMx.set('Fyxlb', str(bjhz_[4]))
  660. ########################################Gfsj##########################
  661. Gfsj = ET.SubElement(Dwgcxx, 'Gfsj')
  662. for gfsj_ in gfsj:
  663. GfsjMx = ET.SubElement(Gfsj, 'GfsjMx')
  664. GfsjMx.set('Xh', str(gfsj_[0]))
  665. GfsjMx.set('Mc', str(gfsj_[1]))
  666. GfsjMx.set('Qfjs', roundstr(gfsj_[2]))
  667. GfsjMx.set('Jsjc', str(gfsj_[3]))
  668. GfsjMx.set('Fl', str(gfsj_[4]))
  669. GfsjMx.set('Je', roundstr(gfsj_[5]))
  670. GfsjMx.set('Fyxlb', str(gfsj_[6]))
  671. ########################################Qdxm##########################
  672. Qdxm = ET.SubElement(Dwgcxx, 'Qdxm')
  673. if 'Default' in qdbt:
  674. collection = db["qdxm"]
  675. before_sort = []
  676. async for post in collection.find({"biao_id": id, "Dwgcbh": entry['Dwgcbh'], 'bt': 'Default'}):
  677. before_sort.append(post)
  678. after_sort = sorted(before_sort, key=lambda x: int(x['序号']))
  679. for qdmx in after_sort:
  680. Qdmx = ET.SubElement(Qdxm, 'Qdmx')
  681. Qdmx.set('Xh', str(qdmx['序号']))
  682. Qdmx.set('Qdbm', str(qdmx['清单编码']))
  683. Qdmx.set('Mc', str(qdmx['名称']))
  684. Qdmx.set('Xmtz', str(qdmx['项目特征']))
  685. Qdmx.set('Jsgz', str(qdmx['计算规则']))
  686. Qdmx.set('Dw', str(qdmx['单位']))
  687. Qdmx.set('Sl', roundstr4(qdmx['数量']))
  688. Qdmx.set('Zhdj', roundstr4(qdmx['综合单价']))
  689. Qdmx.set('Zhhj', roundstr4(qdmx['合价']))
  690. Qdmx.set('Rgf', roundstr4(qdmx['人工费']))
  691. Qdmx.set('Zcf', roundstr4(qdmx['主材费']))
  692. Qdmx.set('Sbf', roundstr4(qdmx['设备费']))
  693. Qdmx.set('Fcf', roundstr4(qdmx['辅材费']))
  694. Qdmx.set('Clf', roundstr4(qdmx['材料费']))
  695. Qdmx.set('Jxf', roundstr4(qdmx['机械费']))
  696. Qdmx.set('Glf', roundstr4(qdmx['管理费']))
  697. Qdmx.set('Lr', roundstr4(qdmx['利润']))
  698. Qdmx.set('Zgj', roundstr4(qdmx['暂估价']))
  699. Qdmx.set('Zgr', roundstr4(qdmx['综合人工工日']))
  700. Qdmx.set('Bz', str(qdmx['备注']))
  701. Qdxdezj = ET.SubElement(Qdmx, 'Qdxdezj')
  702. if '__children' in qdmx:
  703. for child in qdmx['__children']:
  704. QdxdezjMx = ET.SubElement(Qdxdezj, 'QdxdezjMx')
  705. QdxdezjMx.set('Debm', str(child['清单编码']))
  706. QdxdezjMx.set('Mc', str(child['名称']))
  707. QdxdezjMx.set('Dw', str(child['单位']))
  708. QdxdezjMx.set('DwQdSl', roundstr4(child['数量']))
  709. QdxdezjMx.set('Dj', roundstr4(child['综合单价']))
  710. QdxdezjMx.set('Hj', roundstr4(child['合价']))
  711. QdxdezjMx.set('Rgf', roundstr4(child['人工费']))
  712. QdxdezjMx.set('Zcf', roundstr4(child['主材费']))
  713. QdxdezjMx.set('Sbf', roundstr4(child['设备费']))
  714. QdxdezjMx.set('Fcf', roundstr4(child['辅材费']))
  715. QdxdezjMx.set('Clf', roundstr4(child['材料费']))
  716. QdxdezjMx.set('Jxf', roundstr4(child['机械费']))
  717. QdxdezjMx.set('Glf', roundstr4(child['管理费']))
  718. QdxdezjMx.set('Lr', roundstr4(child['利润']))
  719. Qdxdercjhl = ET.SubElement(QdxdezjMx, 'Qdxdercjhl')
  720. for i in range(len(child['dercj'])):
  721. if i == 0:
  722. pass
  723. else:
  724. QdxdercjhlMx = ET.SubElement(Qdxdercjhl, 'QdxdercjhlMx')
  725. QdxdercjhlMx.set('RcjId', util.indexrcj(rcjhz, child['dercj'][i]))
  726. QdxdercjhlMx.set('Rcjhl', roundstr4(child['dercj'][i][10]))
  727. QdxdercjhlMx.set('Rcjhj', roundstr4(child['dercj'][i][11]))
  728. Qdxrcjhl = ET.SubElement(Qdmx, 'Qdxrcjhl')
  729. for i in range(len(qdmx['rcj'])):
  730. if i == 0:
  731. pass
  732. else:
  733. QdxrcjhlMx = ET.SubElement(Qdxrcjhl, 'QdxrcjhlMx')
  734. QdxrcjhlMx.set('RcjId', util.indexrcj(rcjhz, qdmx['rcj'][i]))
  735. ##str(djcs['rcj'][i][0]))
  736. QdxrcjhlMx.set('Rcjhl', roundstr4(qdmx['rcj'][i][10]))
  737. QdxrcjhlMx.set('Rcjhj', roundstr4(qdmx['rcj'][i][11]))
  738. QdxrcjhlMx.set('Zgjbz', str(qdmx['rcj'][i][12]))
  739. QdxrcjhlMx.set('Zyclbz', str(qdmx['rcj'][i][13]))
  740. QdxrcjhlMx.set('Zcbz', str(qdmx['rcj'][i][14]))
  741. QdxrcjhlMx.set('Sbbz', str(qdmx['rcj'][i][15]))
  742. qdbt_addition = Dwgc['qdbt_addition']
  743. for bt in qdbt_addition:
  744. QdBt = ET.SubElement(Qdxm, 'QdBt')
  745. QdBt.set('Xh', bt['Xh'])
  746. QdBt.set('Mc', bt['Mc'])
  747. QdBt.set('Je', roundstr(bt['Je']))
  748. QdBt.set('Zgj', roundstr(bt['Zgj']))
  749. QdBt.set('Bz', bt['Bz'])
  750. collection = db["qdxm"]
  751. before_sort = []
  752. async for post in collection.find({"biao_id": id, "Dwgcbh": entry['Dwgcbh'], 'bt': bt['Mc']}):
  753. before_sort.append(post)
  754. after_sort = sorted(before_sort, key=lambda x: int(x['序号']))
  755. for qdmx in after_sort:
  756. Qdmx = ET.SubElement(QdBt, 'Qdmx')
  757. Qdmx.set('Xh', str(qdmx['序号']))
  758. Qdmx.set('Qdbm', str(qdmx['清单编码']))
  759. Qdmx.set('Mc', str(qdmx['名称']))
  760. Qdmx.set('Xmtz', str(qdmx['项目特征']))
  761. Qdmx.set('Jsgz', str(qdmx['计算规则']))
  762. Qdmx.set('Dw', str(qdmx['单位']))
  763. Qdmx.set('Sl', roundstr4(qdmx['数量']))
  764. Qdmx.set('Zhdj', roundstr4(qdmx['综合单价']))
  765. Qdmx.set('Zhhj', roundstr4(qdmx['合价']))
  766. Qdmx.set('Rgf', roundstr4(qdmx['人工费']))
  767. Qdmx.set('Zcf', roundstr4(qdmx['主材费']))
  768. Qdmx.set('Sbf', roundstr4(qdmx['设备费']))
  769. Qdmx.set('Fcf', roundstr4(qdmx['辅材费']))
  770. Qdmx.set('Clf', roundstr4(qdmx['材料费']))
  771. Qdmx.set('Jxf', roundstr4(qdmx['机械费']))
  772. Qdmx.set('Glf', roundstr4(qdmx['管理费']))
  773. Qdmx.set('Lr', roundstr4(qdmx['利润']))
  774. Qdmx.set('Zgj', roundstr4(qdmx['暂估价']))
  775. Qdmx.set('Zgr', roundstr4(qdmx['综合人工工日']))
  776. Qdmx.set('Bz', str(qdmx['备注']))
  777. Qdxdezj = ET.SubElement(Qdmx, 'Qdxdezj')
  778. if '__children' in qdmx:
  779. for child in qdmx['__children']:
  780. QdxdezjMx = ET.SubElement(Qdxdezj, 'QdxdezjMx')
  781. QdxdezjMx.set('Debm', str(child['清单编码']))
  782. QdxdezjMx.set('Mc', str(child['名称']))
  783. QdxdezjMx.set('Dw', str(child['单位']))
  784. QdxdezjMx.set('DwQdSl', roundstr4(child['数量']))
  785. QdxdezjMx.set('Dj', roundstr4(child['综合单价']))
  786. QdxdezjMx.set('Hj', roundstr4(child['合价']))
  787. QdxdezjMx.set('Rgf', roundstr4(child['人工费']))
  788. QdxdezjMx.set('Zcf', roundstr4(child['主材费']))
  789. QdxdezjMx.set('Sbf', roundstr4(child['设备费']))
  790. QdxdezjMx.set('Fcf', roundstr4(child['辅材费']))
  791. QdxdezjMx.set('Clf', roundstr4(child['材料费']))
  792. QdxdezjMx.set('Jxf', roundstr4(child['机械费']))
  793. QdxdezjMx.set('Glf', roundstr4(child['管理费']))
  794. QdxdezjMx.set('Lr', roundstr4(child['利润']))
  795. Qdxdercjhl = ET.SubElement(QdxdezjMx, 'Qdxdercjhl')
  796. for i in range(len(child['dercj'])):
  797. if i == 0:
  798. pass
  799. else:
  800. QdxdercjhlMx = ET.SubElement(Qdxdercjhl, 'QdxdercjhlMx')
  801. QdxdercjhlMx.set('RcjId', util.indexrcj(rcjhz, child['dercj'][i]))
  802. QdxdercjhlMx.set('Rcjhl', roundstr4(child['dercj'][i][10]))
  803. QdxdercjhlMx.set('Rcjhj', roundstr4(child['dercj'][i][11]))
  804. Qdxrcjhl = ET.SubElement(Qdmx, 'Qdxrcjhl')
  805. for i in range(len(qdmx['rcj'])):
  806. if i == 0:
  807. pass
  808. else:
  809. QdxrcjhlMx = ET.SubElement(Qdxrcjhl, 'QdxrcjhlMx')
  810. QdxrcjhlMx.set('RcjId', util.indexrcj(rcjhz, qdmx['rcj'][i]))
  811. ##str(djcs['rcj'][i][0]))
  812. QdxrcjhlMx.set('Rcjhl', roundstr4(qdmx['rcj'][i][10]))
  813. QdxrcjhlMx.set('Rcjhj', roundstr4(qdmx['rcj'][i][11]))
  814. QdxrcjhlMx.set('Zgjbz', str(qdmx['rcj'][i][12]))
  815. QdxrcjhlMx.set('Zyclbz', str(qdmx['rcj'][i][13]))
  816. QdxrcjhlMx.set('Zcbz', str(qdmx['rcj'][i][14]))
  817. QdxrcjhlMx.set('Sbbz', str(qdmx['rcj'][i][15]))
  818. ########################################Csxm##########################
  819. Csxm = ET.SubElement(Dwgcxx, 'Csxm')
  820. ZjCs = ET.SubElement(Csxm, 'ZjCs')
  821. for zjcs_ in zjcs:
  822. ZjCsMx = ET.SubElement(ZjCs, 'ZjCsMx')
  823. ZjCsMx.set('Xh', str(zjcs_['序号']))
  824. ZjCsMx.set('Bm', str(zjcs_['清单编码']))
  825. ZjCsMx.set('Mc', str(zjcs_['名称']))
  826. ZjCsMx.set('Js', roundstr(zjcs_['计算基数']))
  827. ZjCsMx.set('Jsjc', str(zjcs_['计算基础']))
  828. ZjCsMx.set('Fl', str(zjcs_['费率']))
  829. ZjCsMx.set('Je', roundstr(zjcs_['金额']))
  830. ZjCsMx.set('Xmlb', str(zjcs_['项目类别']))
  831. if '__children' in zjcs_:
  832. AqwmfMx = ET.SubElement(ZjCsMx, 'AqwmfMx')
  833. AqwmfMx.set('Mc', str(zjcs_['__children'][0]['名称']))
  834. AqwmfMx.set('Js', roundstr(zjcs_['__children'][0]['计算基数']))
  835. AqwmfMx.set('Jsjc', str(zjcs_['__children'][0]['计算基础']))
  836. AqwmfMx.set('Fl', str(zjcs_['__children'][0]['费率']))
  837. AqwmfMx.set('Je', roundstr(zjcs_['__children'][0]['金额']))
  838. AqwmfMx.set('Xmlb', str(zjcs_['__children'][0]['项目类别']))
  839. AqwmfMx = ET.SubElement(ZjCsMx, 'AqwmfMx')
  840. AqwmfMx.set('Mc', str(zjcs_['__children'][1]['名称']))
  841. AqwmfMx.set('Js', roundstr(zjcs_['__children'][1]['计算基数']))
  842. AqwmfMx.set('Jsjc', str(zjcs_['__children'][1]['计算基础']))
  843. AqwmfMx.set('Fl', str(zjcs_['__children'][1]['费率']))
  844. AqwmfMx.set('Je', roundstr(zjcs_['__children'][1]['金额']))
  845. AqwmfMx.set('Xmlb', str(zjcs_['__children'][1]['项目类别']))
  846. AqwmfMx = ET.SubElement(ZjCsMx, 'AqwmfMx')
  847. AqwmfMx.set('Mc', str(zjcs_['__children'][2]['名称']))
  848. AqwmfMx.set('Js', roundstr(zjcs_['__children'][2]['计算基数']))
  849. AqwmfMx.set('Jsjc', str(zjcs_['__children'][2]['计算基础']))
  850. AqwmfMx.set('Fl', str(zjcs_['__children'][2]['费率']))
  851. AqwmfMx.set('Je', roundstr(zjcs_['__children'][2]['金额']))
  852. AqwmfMx.set('Xmlb', str(zjcs_['__children'][2]['项目类别']))
  853. DjCs = ET.SubElement(Csxm, 'DjCs')
  854. collection = db["Djcs"]
  855. before_sort = []
  856. async for post in collection.find({"biao_id": id, "Dwgcbh": entry['Dwgcbh']}):
  857. before_sort.append(post)
  858. after_sort = sorted(before_sort, key=lambda x: int(x['序号']))
  859. for djcs in after_sort:
  860. DjCsMx = ET.SubElement(DjCs, 'DjCsMx')
  861. DjCsMx.set('Xh', str(djcs['序号']))
  862. DjCsMx.set('Bm', str(djcs['清单编码']))
  863. DjCsMx.set('Mc', str(djcs['名称']))
  864. DjCsMx.set('Xmtz', str(djcs['项目特征']))
  865. DjCsMx.set('Jsgz', str(djcs['计算规则']))
  866. DjCsMx.set('Dw', str(djcs['单位']))
  867. DjCsMx.set('Sl', roundstr4(djcs['数量']))
  868. DjCsMx.set('Zhdj', roundstr4(djcs['综合单价']))
  869. DjCsMx.set('Zhhj', roundstr4(djcs['合价']))
  870. DjCsMx.set('Rgf', roundstr4(djcs['人工费']))
  871. DjCsMx.set('Zcf', roundstr4(djcs['主材费']))
  872. DjCsMx.set('Sbf', roundstr4(djcs['设备费']))
  873. DjCsMx.set('Fcf', roundstr4(djcs['辅材费']))
  874. DjCsMx.set('Clf', roundstr4(djcs['材料费']))
  875. DjCsMx.set('Jxf', roundstr4(djcs['机械费']))
  876. DjCsMx.set('Glf', roundstr4(djcs['管理费']))
  877. DjCsMx.set('Lr', roundstr4(djcs['利润']))
  878. DjCsMx.set('Zgj', roundstr4(djcs['暂估价']))
  879. DjCsMx.set('Zgr', roundstr4(djcs['综合人工工日']))
  880. Csxdezj = ET.SubElement(DjCsMx, 'Csxdezj')
  881. if '__children' in djcs:
  882. for child in djcs['__children']:
  883. CsxdezjMx = ET.SubElement(Csxdezj, 'CsxdezjMx')
  884. CsxdezjMx.set('Debm', str(child['清单编码']))
  885. CsxdezjMx.set('Mc', str(child['名称']))
  886. CsxdezjMx.set('Dw', str(child['单位']))
  887. CsxdezjMx.set('DwQdSl', roundstr4(child['数量']))
  888. CsxdezjMx.set('Dj', roundstr4(child['综合单价']))
  889. CsxdezjMx.set('Hj', roundstr4(child['合价']))
  890. CsxdezjMx.set('Rgf', roundstr4(child['人工费']))
  891. CsxdezjMx.set('Zcf', roundstr4(child['主材费']))
  892. CsxdezjMx.set('Sbf', roundstr4(child['设备费']))
  893. CsxdezjMx.set('Fcf', roundstr4(child['辅材费']))
  894. CsxdezjMx.set('Clf', roundstr4(child['材料费']))
  895. CsxdezjMx.set('Jxf', roundstr4(child['机械费']))
  896. CsxdezjMx.set('Glf', roundstr4(child['管理费']))
  897. CsxdezjMx.set('Lr', roundstr4(child['利润']))
  898. Csxdercjhl = ET.SubElement(CsxdezjMx, 'Csxdercjhl')
  899. for i in range(len(child['dercj'])):
  900. if i == 0:
  901. pass
  902. else:
  903. CsxdercjhlMx = ET.SubElement(Csxdercjhl, 'CsxdercjhlMx')
  904. CsxdercjhlMx.set('RcjId', util.indexrcj(rcjhz, child['dercj'][i]))
  905. CsxdercjhlMx.set('Rcjhl', roundstr4(child['dercj'][i][10]))
  906. CsxdercjhlMx.set('Rcjhj', roundstr4(child['dercj'][i][11]))
  907. Csxrcjhl = ET.SubElement(DjCsMx, 'Csxrcjhl')
  908. for i in range(len(djcs['rcj'])):
  909. if i == 0:
  910. pass
  911. else:
  912. CsxrcjhlMx = ET.SubElement(Csxrcjhl, 'CsxrcjhlMx')
  913. CsxrcjhlMx.set('RcjId', util.indexrcj(rcjhz, djcs['rcj'][i]))
  914. ##str(djcs['rcj'][i][0]))
  915. CsxrcjhlMx.set('Rcjhl', roundstr4(djcs['rcj'][i][10]))
  916. CsxrcjhlMx.set('Rcjhj', roundstr4(djcs['rcj'][i][11]))
  917. CsxrcjhlMx.set('Zgjbz', str(djcs['rcj'][i][12]))
  918. CsxrcjhlMx.set('Zyclbz', str(djcs['rcj'][i][13]))
  919. CsxrcjhlMx.set('Zcbz', str(djcs['rcj'][i][14]))
  920. CsxrcjhlMx.set('Sbbz', str(djcs['rcj'][i][15]))
  921. ########################################Qtxm##########################
  922. Qtxm = ET.SubElement(Dwgcxx, 'Qtxm')
  923. for qtxm_ in qtxm:
  924. QtxmMx = ET.SubElement(Qtxm, 'QtxmMx')
  925. QtxmMx.set('Xh', str(qtxm_[0]))
  926. QtxmMx.set('Mc', str(qtxm_[1]))
  927. QtxmMx.set('Je', roundstr(qtxm_[2]))
  928. QtxmMx.set('Xmlb', str(qtxm_[3]))
  929. QtxmMx.set('Bz', str(qtxm_[4]))
  930. Zlje = ET.SubElement(Dwgcxx, 'Zlje')
  931. for i in range(len(zlje)):
  932. ZljeMx = ET.SubElement(Zlje, 'ZljeMx')
  933. ZljeMx.set('Xh', str(zlje[i]['序号']))
  934. ZljeMx.set('Mc', str(zlje[i]['名称']))
  935. ZljeMx.set('Dw', str(zlje[i]['单位']))
  936. ZljeMx.set('Zdje', roundstr(zlje[i]['暂定金额']))
  937. ZljeMx.set('Bz', str(zlje[i]['备注']))
  938. Clzg = ET.SubElement(Dwgcxx, 'Clzg')
  939. Zygczg = ET.SubElement(Dwgcxx, 'Zygczg')
  940. for zygczgj_ in zygczgj:
  941. ZygczgMx = ET.SubElement(Zygczg, 'ZygczgMx')
  942. ZygczgMx.set('Xh', str(zygczgj_['序号']))
  943. ZygczgMx.set('Mc', str(zygczgj_['名称']))
  944. ZygczgMx.set('Gcnr', str(zygczgj_['工程内容']))
  945. ZygczgMx.set('Je', roundstr(zygczgj_['金额']))
  946. ZygczgMx.set('Bz', str(zygczgj_['备注']))
  947. Jrg = ET.SubElement(Dwgcxx, 'Jrg')
  948. for jrg_ in jrg:
  949. JrgBt = ET.SubElement(Jrg, 'JrgBt')
  950. JrgBt.set('Xh', str(jrg_['序号']))
  951. JrgBt.set('Mc', str(jrg_['名称']))
  952. JrgBt.set('Je', roundstr(jrg_['金额']))
  953. JrgBt.set('Lb', str(jrg_['类别']))
  954. Zcbfwf = ET.SubElement(Dwgcxx, 'Zcbfwf')
  955. for zcbfwf_ in zcbfwf:
  956. ZcbfwfMx = ET.SubElement(Zcbfwf, 'ZcbfwfMx')
  957. ZcbfwfMx.set('Xh', str(zcbfwf_['序号']))
  958. ZcbfwfMx.set('Mc', str(zcbfwf_['名称']))
  959. ZcbfwfMx.set('Xmjz', roundstr(zcbfwf_['项目价值']))
  960. ZcbfwfMx.set('Fwnr', str(zcbfwf_['服务内容']))
  961. ZcbfwfMx.set('Jsjc', str(zcbfwf_['计算基础']))
  962. ZcbfwfMx.set('Fl', str(zcbfwf_['费率']))
  963. ZcbfwfMx.set('Je', roundstr(zcbfwf_['金额']))
  964. Zjxmjdkzffj = ET.SubElement(Dwgcxx, 'Zjxmjdkzffj')
  965. Fbrgycl = ET.SubElement(Dwgcxx, 'Fbrgycl')
  966. for fbrgycl_ in fbrgycl:
  967. FbrgyclMx = ET.SubElement(Fbrgycl, 'FbrgyclMx')
  968. FbrgyclMx.set('Xh', str(fbrgycl_['序号']))
  969. FbrgyclMx.set('RcjId', util.indexrcj(rcjhz, [fbrgycl_['序号'], fbrgycl_['材料编号'], fbrgycl_['名称'], fbrgycl_['规格型号'], fbrgycl_['单位']]))
  970. FbrgyclMx.set('Clbh', str(fbrgycl_['材料编号']))
  971. FbrgyclMx.set('Mc', str(fbrgycl_['名称']))
  972. FbrgyclMx.set('Ggxh', str(fbrgycl_['规格型号']))
  973. FbrgyclMx.set('Dw', str(fbrgycl_['单位']))
  974. FbrgyclMx.set('Sl', roundstr4(fbrgycl_['数量']))
  975. FbrgyclMx.set('Dj', roundstr4(fbrgycl_['单价']))
  976. FbrgyclMx.set('Hj', roundstr4(fbrgycl_['合价']))
  977. FbrgyclMx.set('Jhfs', str(fbrgycl_['交货方式']))
  978. FbrgyclMx.set('Sddd', str(fbrgycl_['送达地点']))
  979. FbrgyclMx.set('Bz', str(fbrgycl_['备注']))
  980. Cbrgycl = ET.SubElement(Dwgcxx, 'Cbrgycl')
  981. Rcjhz = ET.SubElement(Dwgcxx, 'Rcjhz')
  982. for i in range(len(rcjhz)):
  983. if i == 0:
  984. pass
  985. else:
  986. RcjhzMx = ET.SubElement(Rcjhz, 'RcjhzMx')
  987. RcjhzMx.set('RcjId', str(i))
  988. RcjhzMx.set('RcjBm', str(rcjhz[i][1]))
  989. RcjhzMx.set('Mc', str(rcjhz[i][2]))
  990. RcjhzMx.set('Ggxh', str(rcjhz[i][3]))
  991. RcjhzMx.set('Dw', str(rcjhz[i][4]))
  992. RcjhzMx.set('Sl', roundstr4(rcjhz[i][5]))
  993. RcjhzMx.set('Dj', roundstr4(rcjhz[i][6]))
  994. RcjhzMx.set('Hj', roundstr4(rcjhz[i][7]))
  995. RcjhzMx.set('Cd', str(rcjhz[i][8]))
  996. RcjhzMx.set('Gycs', str(rcjhz[i][9]))
  997. RcjhzMx.set('Rcjlb', str(rcjhz[i][10]))
  998. RcjhzMx.set('Zyclbz', str(rcjhz[i][11]))
  999. RcjhzMx.set('Zcbz', str(rcjhz[i][12]))
  1000. RcjhzMx.set('Sbbz', str(rcjhz[i][13]))
  1001. RcjhzMx.set('Jgbz', str(rcjhz[i][14]))
  1002. RcjhzMx.set('Zgjbz', str(rcjhz[i][15]))
  1003. ############################end of build xml file#################################
  1004. async def delete_files(client, id):
  1005. db = client["baojia"]
  1006. collection = db["jingjibiao"]
  1007. result = []
  1008. await collection.update_one({'_id': ObjectId(id)}, {'$set': {'visible': False}})
  1009. return result
  1010. async def list_files(client):
  1011. db = client["baojia"]
  1012. collection = db["jingjibiao"]
  1013. result = []
  1014. async for post in collection.find({"visible": True}):
  1015. result.append([str(post['_id']), post["Xmmc"], post['created'] if 'created' in post else ""])
  1016. return result
  1017. def getDwgc(id, Zylb):
  1018. result = []
  1019. id = id + "Zylb" + Zylb
  1020. result.append({"id": id + "bao jia hui zong", "label": "报价汇总表"})
  1021. result.append({"id": id + "gui fei shui jin", "label": "规费税金"})
  1022. result.append({"id": id + "qing dan xiang mu", "label": "清单项目"})
  1023. result.append({"id": id + "cuo shi xiang mu", "label": "措施项目"})
  1024. result.append({"id": id +"qi ta xiang mu", "label": "其他项目"})
  1025. result.append({"id": id +"zan lie jin e", "label": "暂列金额"})
  1026. result.append({"id": id +"cai liao zan gu jia", "label": "材料暂估价"})
  1027. result.append({"id": id + "zhuan ye gong cheng zan gu jia", "label": "专业工程暂估价"})
  1028. result.append({"id": id + "ji ri gong", "label": "计日工"})
  1029. result.append({"id": id + "zong cheng bao fu wu fei", "label": "总承包服务费"})
  1030. result.append({"id": id + "zong jia xiang mu jin du kuan zhi fu fen jie", "label": "总价项目进度款支付分解"})
  1031. result.append({"id": id + "fa bao ren gong ying cai liao", "label": "发包人供应材料"})
  1032. result.append({"id": id + "cheng bao ren gong ying cai liao", "label": "承包人供应材料"})
  1033. result.append({"id": id + "ren cai ji hui zong", "label": "人材机汇总"})
  1034. return result
  1035. async def getOutline(client, id):
  1036. db = client["baojia"]
  1037. collection = db["jingjibiao"]
  1038. document = await collection.find_one({'_id': ObjectId(id)})
  1039. result = []
  1040. if 'TouBiaoXx' in document:
  1041. result.append({"id" : "TouBiaoXx", "label" : "投标信息" })
  1042. if 'Dxgcxx' in document:
  1043. Dxgcxx = document["Dxgcxx"]
  1044. for dxgc in Dxgcxx:
  1045. result2 = []
  1046. Dwgc = dxgc["Dwgc"]
  1047. for grandchild in Dwgc:
  1048. result2.append({"id" : grandchild['Dwgcbh'], "Zylb":grandchild['Zylb'], "label": grandchild["Dwgcmc"], "children" : getDwgc(grandchild['Dwgcbh'], grandchild['Zylb'])})
  1049. result.append({"id" : dxgc['Dxgcbh'], "label" : dxgc['Dxgcmc'], "children" : result2})
  1050. return result
  1051. async def getDetail(client, id):
  1052. db = client["baojia"]
  1053. collection = db["jingjibiao"]
  1054. document = await collection.find_one({'_id': ObjectId(id)})
  1055. result = []
  1056. ##result.append(["名称", "金额", "暂估价", "安全文明施工费", "规费"])
  1057. if 'TouBiaoXx' in document:
  1058. toubiaoxx = document["TouBiaoXx"]
  1059. result.append({'名称': '投标总价', '金额' : toubiaoxx["Tbzj"], '暂估价': toubiaoxx["Zgj"], '安全文明施工费': toubiaoxx["Aqwmf"], '规费' : toubiaoxx["Gf"], '_children': []})
  1060. if 'Dxgcxx' in document:
  1061. Dxgcxx = document["Dxgcxx"]
  1062. for dxgc in Dxgcxx:
  1063. result[0]['_children'].append({'名称' :dxgc["Dxgcmc"], '金额' : dxgc["Je"], '暂估价' : dxgc["Zgj"],'安全文明施工费' : dxgc["Aqwmf"], '规费' : dxgc["Gf"]})
  1064. return result
  1065. else:
  1066. if 'Dxgcxx' in document:
  1067. Dxgcxx = document["Dxgcxx"]
  1068. for dxgc in Dxgcxx:
  1069. result.append({'名称' :dxgc["Dxgcmc"], '金额' : dxgc["Je"], '暂估价' : dxgc["Zgj"],'安全文明施工费' : dxgc["Aqwmf"], '规费' : dxgc["Gf"]})
  1070. return result
  1071. async def getBjhz(client, objectid, id):
  1072. db = client["baojia"]
  1073. collection = db["Dwgc"]
  1074. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  1075. return document['bjhz']
  1076. async def getGfsj(client, objectid, id):
  1077. db = client["baojia"]
  1078. collection = db["Dwgc"]
  1079. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  1080. return document['gfsj']
  1081. async def getQtxm(client, objectid, id):
  1082. db = client["baojia"]
  1083. collection = db["Dwgc"]
  1084. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  1085. return document['qtxm']
  1086. async def getZygczgj(client, objectid, id):
  1087. db = client["baojia"]
  1088. collection = db["Dwgc"]
  1089. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  1090. return document['zygczgj']
  1091. async def getZlje(client, objectid, id):
  1092. db = client["baojia"]
  1093. collection = db["Dwgc"]
  1094. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  1095. return document['zlje']
  1096. async def getJrg(client, objectid, id):
  1097. db = client["baojia"]
  1098. collection = db["Dwgc"]
  1099. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  1100. return document['jrg']
  1101. async def getZcbfwf(client, objectid, id):
  1102. db = client["baojia"]
  1103. collection = db["Dwgc"]
  1104. document = await collection.find_one({"Dwgcbh": id, "biao_id": objectid})
  1105. return document['zcbfwf']
  1106. async def getFbrgycl(client, objectid, id):
  1107. db = client["baojia"]
  1108. collection = db["Dwgc"]
  1109. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  1110. return document['fbrgycl']
  1111. async def getRcjhz(client, objectid, id):
  1112. db = client["baojia"]
  1113. collection = db["Dwgc"]
  1114. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  1115. return document['rcjhz']
  1116. async def getZjcs(client, objectid, id):
  1117. db = client["baojia"]
  1118. collection = db["Dwgc"]
  1119. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  1120. return document['zjcs']
  1121. async def getDjcs(client, objectid, id):
  1122. db = client["baojia"]
  1123. collection = db["Djcs"]
  1124. result = []
  1125. async for post in collection.find({"Dwgcbh": id, "biao_id": objectid}):
  1126. del post["_id"]
  1127. result.append(post)
  1128. return result
  1129. async def getDjcsQingdanrcj(client, name, bh, bt, bm):
  1130. db = client["baojia"]
  1131. collection = db["Djcs"]
  1132. document = await collection.find_one({ "Dwgcbh": bh, "清单编码": bm, "biao_id": name})
  1133. result = document["rcj"]
  1134. return result
  1135. async def getDjcsDingercj(client, name, bh, bt, qdbm, debm):
  1136. db = client["baojia"]
  1137. collection = db["Djcs"]
  1138. document = await collection.find_one({"Dwgcbh": bh, "清单编码": qdbm, "biao_id": name})
  1139. children = document["__children"]
  1140. result = []
  1141. for child in children:
  1142. if child["清单编码"] == debm:
  1143. result = child["dercj"]
  1144. return result
  1145. async def getQdxm(client, name, bh):
  1146. db = client["baojia"]
  1147. collection = db["Dwgc"]
  1148. document = await collection.find_one({'biao_id': name, "Dwgcbh": bh})
  1149. if document:
  1150. return document['qdbt']
  1151. else:
  1152. return []
  1153. async def getQdmx(client, name, bh, bt):
  1154. db = client["baojia"]
  1155. collection = db["qdxm"]
  1156. result = []
  1157. if bt == 'ALL':
  1158. async for post in collection.find({'biao_id': name, "Dwgcbh": bh,}):
  1159. del post["_id"]
  1160. result.append(post)
  1161. else:
  1162. async for post in collection.find({'biao_id': name, "Dwgcbh": bh, "bt": bt}):
  1163. del post["_id"]
  1164. result.append(post)
  1165. return result
  1166. async def getQingdanrcj(client, name, bh, bt, bm):
  1167. db = client["baojia"]
  1168. collection = db["qdxm"]
  1169. document = await collection.find_one({ "Dwgcbh": bh, "清单编码": bm, "biao_id": name, "bt": bt})
  1170. result = document["rcj"]
  1171. return result
  1172. async def getDingercj(client, name, bh, bt, qdbm, debm):
  1173. db = client["baojia"]
  1174. collection = db["qdxm"]
  1175. document = await collection.find_one({"Dwgcbh": bh, "清单编码": qdbm, "biao_id": name, "bt": bt})
  1176. result = []
  1177. if "__children" in document:
  1178. children = document["__children"]
  1179. for child in children:
  1180. if child["清单编码"] == debm:
  1181. result = child["dercj"]
  1182. return result
  1183. async def getQufei(client, id):
  1184. db = client["baojia"]
  1185. collection = db["qufei"]
  1186. document = await collection.find_one({'biao_id': id})
  1187. return document['qufei']
  1188. async def searchde(client, zhuanye, text):
  1189. db = client["dinge"]
  1190. collection = db["de-collection"]
  1191. result = []
  1192. async for post in collection.find({'$text': {"$search": "\"" + text + "\""}, "zhuanye": zhuanye}):
  1193. result.append(post["DEBH"] + " " + post['GCLMC'] )
  1194. if len(result) > 10:
  1195. break
  1196. return result
  1197. async def getJiagongcai(client, id):
  1198. db = client["baojia"]
  1199. collection = db["Dwgc"]
  1200. result = []
  1201. async for post in collection.find({'biao_id': id}, {'rcjhz': 0}):
  1202. for entry in post['fbrgycl']:
  1203. result.append(entry)
  1204. return result
  1205. async def getSingleDeXilie_(model, client, zhuanye, debh, mc):
  1206. db = client["dinge"]
  1207. collection = db["de-collection"]
  1208. count = 0
  1209. actual_zhuanye = []
  1210. mcs = []
  1211. parents = []
  1212. if "附注" in debh:
  1213. position = debh.find("附注")
  1214. debh = debh[:position]
  1215. if "*" in debh:
  1216. position = debh.find("*")
  1217. debh = debh[:position]
  1218. if debh.endswith("换"):
  1219. debh = debh[:-1]
  1220. if "[" in debh:
  1221. position = debh.find("[")
  1222. debh = debh[:position-1]
  1223. for post in collection.find({'DEBH': debh}):
  1224. ##print(post)
  1225. actual_zhuanye.append(post['zhuanye'])
  1226. mcs.append(post['GCLMC'])
  1227. parents.append(post['parent'])
  1228. count = count + 1
  1229. if count == 0:
  1230. return None, None, None, None, None, None, None, zhuanye
  1231. elif count == 1:
  1232. if actual_zhuanye[0] == '土建':
  1233. A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_tj(debh)
  1234. return A1, A2, A3, A4, A5, A6, A7, 10
  1235. elif actual_zhuanye[0] == '市政':
  1236. A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_sz(debh)
  1237. return A1, A2, A3, A4, A5, A6, A7, 20
  1238. elif actual_zhuanye[0] == '安装':
  1239. A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_az(debh)
  1240. return A1, A2, A3, A4, A5, A6, A7, 30
  1241. elif actual_zhuanye[0] == '园林':
  1242. A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_yl(debh)
  1243. return A1, A2, A3, A4, A5, A6, A7, 40
  1244. elif actual_zhuanye[0] == '修缮工程土建':
  1245. A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_xstj(debh)
  1246. return A1, A2, A3, A4, A5, A6, A7, 50
  1247. elif actual_zhuanye[0] == '修缮工程安装':
  1248. A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_xsaz(debh)
  1249. return A1, A2, A3, A4, A5, A6, A7, 60
  1250. else:
  1251. hit = False
  1252. for i in range(0, count):
  1253. if mcs[i] in mc:
  1254. hit = True
  1255. actual_zhuanye[0] = actual_zhuanye[i]
  1256. if hit:
  1257. if actual_zhuanye[0] == '土建':
  1258. A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_tj(debh)
  1259. return A1, A2, A3, A4, A5, A6, A7, 10
  1260. elif actual_zhuanye[0] == '市政':
  1261. A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_sz(debh)
  1262. return A1, A2, A3, A4, A5, A6, A7, 20
  1263. elif actual_zhuanye[0] == '安装':
  1264. A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_az(debh)
  1265. return A1, A2, A3, A4, A5, A6, A7, 30
  1266. elif actual_zhuanye[0] == '园林':
  1267. A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_yl(debh)
  1268. return A1, A2, A3, A4, A5, A6, A7, 40
  1269. elif actual_zhuanye[0] == '修缮工程土建':
  1270. A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_xstj(debh)
  1271. return A1, A2, A3, A4, A5, A6, A7, 50
  1272. elif actual_zhuanye[0] == '修缮工程安装':
  1273. A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_xsaz(debh)
  1274. return A1, A2, A3, A4, A5, A6, A7, 60
  1275. else:
  1276. for i in range(len(parents)):
  1277. mcs[i] = parents[i] + ' ' + mcs[i]
  1278. mcs.append(mc)
  1279. #print(mcs)
  1280. embeddings = model.encode(mcs)
  1281. similarities = model.similarity( embeddings[-1], embeddings)
  1282. ##array([1.0000002, 0.7662151, 1.0000002], dtype=float32)
  1283. ##print(similarities)
  1284. sim = similarities[0].numpy()[:-1]
  1285. ##print(sim)
  1286. index = np.argmax(sim).item()
  1287. ##print(index)
  1288. ##print(actual_zhuanye)
  1289. actual_zhuanye[0] = actual_zhuanye[index]
  1290. if actual_zhuanye[0] == '土建':
  1291. A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_tj(debh)
  1292. return A1, A2, A3, A4, A5, A6, A7, 10
  1293. elif actual_zhuanye[0] == '市政':
  1294. A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_sz(debh)
  1295. return A1, A2, A3, A4, A5, A6, A7, 20
  1296. elif actual_zhuanye[0] == '安装':
  1297. A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_az(debh)
  1298. return A1, A2, A3, A4, A5, A6, A7, 30
  1299. elif actual_zhuanye[0] == '园林':
  1300. A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_yl(debh)
  1301. return A1, A2, A3, A4, A5, A6, A7, 40
  1302. elif actual_zhuanye[0] == '修缮工程土建':
  1303. A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_xstj(debh)
  1304. return A1, A2, A3, A4, A5, A6, A7, 50
  1305. elif actual_zhuanye[0] == '修缮工程安装':
  1306. A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_xsaz(debh)
  1307. return A1, A2, A3, A4, A5, A6, A7, 60
  1308. async def getSingleDeXilie(model, client, zhuanye, debh, mc):
  1309. db = client["dinge"]
  1310. collection = db["de-collection"]
  1311. count = 0
  1312. actual_zhuanye = []
  1313. mcs = []
  1314. parents = []
  1315. if "附注" in debh:
  1316. position = debh.find("附注")
  1317. debh = debh[:position]
  1318. if "*" in debh:
  1319. position = debh.find("*")
  1320. debh = debh[:position]
  1321. if debh.endswith("换"):
  1322. debh = debh[:-1]
  1323. if "[" in debh:
  1324. position = debh.find("[")
  1325. debh = debh[:position-1]
  1326. async for post in collection.find({'DEBH': debh}):
  1327. ##print(post)
  1328. actual_zhuanye.append(post['zhuanye'])
  1329. mcs.append(post['GCLMC'])
  1330. parents.append(post['parent'])
  1331. count = count + 1
  1332. if count == 0:
  1333. return None, None, None, None, None, None, None, zhuanye
  1334. elif count == 1:
  1335. if actual_zhuanye[0] == '土建':
  1336. A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_tj(debh)
  1337. return A1, A2, A3, A4, A5, A6, A7, 10
  1338. elif actual_zhuanye[0] == '市政':
  1339. A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_sz(debh)
  1340. return A1, A2, A3, A4, A5, A6, A7, 20
  1341. elif actual_zhuanye[0] == '安装':
  1342. A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_az(debh)
  1343. return A1, A2, A3, A4, A5, A6, A7, 30
  1344. elif actual_zhuanye[0] == '园林':
  1345. A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_yl(debh)
  1346. return A1, A2, A3, A4, A5, A6, A7, 40
  1347. elif actual_zhuanye[0] == '修缮工程土建':
  1348. A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_xstj(debh)
  1349. return A1, A2, A3, A4, A5, A6, A7, 50
  1350. elif actual_zhuanye[0] == '修缮工程安装':
  1351. A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_xsaz(debh)
  1352. return A1, A2, A3, A4, A5, A6, A7, 60
  1353. else:
  1354. hit = False
  1355. for i in range(0, count):
  1356. if mcs[i] in mc:
  1357. hit = True
  1358. actual_zhuanye[0] = actual_zhuanye[i]
  1359. if hit:
  1360. if actual_zhuanye[0] == '土建':
  1361. A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_tj(debh)
  1362. return A1, A2, A3, A4, A5, A6, A7, 10
  1363. elif actual_zhuanye[0] == '市政':
  1364. A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_sz(debh)
  1365. return A1, A2, A3, A4, A5, A6, A7, 20
  1366. elif actual_zhuanye[0] == '安装':
  1367. A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_az(debh)
  1368. return A1, A2, A3, A4, A5, A6, A7, 30
  1369. elif actual_zhuanye[0] == '园林':
  1370. A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_yl(debh)
  1371. return A1, A2, A3, A4, A5, A6, A7, 40
  1372. elif actual_zhuanye[0] == '修缮工程土建':
  1373. A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_xstj(debh)
  1374. return A1, A2, A3, A4, A5, A6, A7, 50
  1375. elif actual_zhuanye[0] == '修缮工程安装':
  1376. A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_xsaz(debh)
  1377. return A1, A2, A3, A4, A5, A6, A7, 60
  1378. else:
  1379. for i in range(len(parents)):
  1380. mcs[i] = parents[i] + " " + mcs[i]
  1381. mcs.append(mc)
  1382. embeddings = model.encode(mcs)
  1383. similarities = model.similarity( embeddings[-1], embeddings)
  1384. ##array([1.0000002, 0.7662151, 1.0000002], dtype=float32)
  1385. ##print(similarities)
  1386. sim = similarities[0].numpy()[:-1]
  1387. ##print(sim)
  1388. index = np.argmax(sim).item()
  1389. ##print(index)
  1390. ##print(actual_zhuanye)
  1391. actual_zhuanye[0] = actual_zhuanye[index]
  1392. if actual_zhuanye[0] == '土建':
  1393. A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_tj(debh)
  1394. return A1, A2, A3, A4, A5, A6, A7, 10
  1395. elif actual_zhuanye[0] == '市政':
  1396. A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_sz(debh)
  1397. return A1, A2, A3, A4, A5, A6, A7, 20
  1398. elif actual_zhuanye[0] == '安装':
  1399. A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_az(debh)
  1400. return A1, A2, A3, A4, A5, A6, A7, 30
  1401. elif actual_zhuanye[0] == '园林':
  1402. A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_yl(debh)
  1403. return A1, A2, A3, A4, A5, A6, A7, 40
  1404. elif actual_zhuanye[0] == '修缮工程土建':
  1405. A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_xstj(debh)
  1406. return A1, A2, A3, A4, A5, A6, A7, 50
  1407. elif actual_zhuanye[0] == '修缮工程安装':
  1408. A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_xsaz(debh)
  1409. return A1, A2, A3, A4, A5, A6, A7, 60
  1410. ##################################editor_code##########################
  1411. def bjhz_template():
  1412. result = []
  1413. result.append({'序号': '1', '名称': '分部分项工程', '金额': '0', '暂估价': '0', '类别' : '1', '__children': [
  1414. {'序号': '1.1', '名称': '人工费', '金额': '0', '暂估价': '0', '类别' : '1.1'},
  1415. {'序号': '1.2', '名称': '材料费', '金额': '0', '暂估价': '0', '类别' : '1.2'},
  1416. {'序号': '1.3', '名称': '施工机具使用费', '金额': '0', '暂估价': '0', '类别' : '1.3'},
  1417. {'序号': '1.4', '名称': '企业管理费', '金额': '0', '暂估价': '0', '类别' : '1.4'},
  1418. {'序号': '1.5', '名称': '利润', '金额': '0', '暂估价': '0', '类别' : '1.5'}
  1419. ]})
  1420. result.append({'序号': '2', '名称': '措施项目', '金额': '0', '暂估价': '0', '类别' : '2', '__children': [
  1421. {'序号': '2.1', '名称': '单价措施项目费', '金额': '0', '暂估价': '0', '类别' : '2.1'},
  1422. {'序号': '2.2', '名称': '总价措施项目费', '金额': '0', '暂估价': '0', '类别' : '2.2', '__children' : [
  1423. {'序号': '2.2.1', '名称': '其中:安全文明施工措施费', '金额': '0', '暂估价': '0', '类别' : '2.2.1'},]
  1424. }
  1425. ]})
  1426. result.append({'序号': '3', '名称': '其他项目', '金额': '0', '暂估价': '0', '类别' : '3', '__children': [
  1427. {'序号': '3.1', '名称': '其中:暂列金额', '金额': '0', '暂估价': '0', '类别' : '3.1'},
  1428. {'序号': '3.2', '名称': '其中:专业工程暂估价', '金额': '0', '暂估价': '0', '类别' : '3.2'},
  1429. {'序号': '3.3', '名称': '其中:计日工', '金额': '0', '暂估价': '0', '类别' : '3.3'},
  1430. {'序号': '3.4', '名称': '其中:总承包服务费', '金额': '0', '暂估价': '0', '类别' : '3.4'},
  1431. ]})
  1432. result.append({'序号': '4', '名称': '规费', '金额': '0', '暂估价': '0', '类别' : '4', })
  1433. result.append({'序号': '5', '名称': '税金', '金额': '0', '暂估价': '0', '类别' : '5', })
  1434. result.append({'序号': '6', '名称': '工程造价', '金额': '0', '暂估价': '0', '类别' : '6', })
  1435. return result
  1436. async def zongjiaDwgc(client, biao_id, bh):
  1437. db = client["baojia"]
  1438. djcs_sum = 0###单价措施汇总
  1439. collection = db["Djcs"]
  1440. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  1441. djcs_sum = djcs_sum + float(post['合价'])
  1442. collection = db['Dwgc']
  1443. document = await collection.find_one({'biao_id': biao_id, "Dwgcbh": bh}, {'rcjhz': 0})
  1444. qdbt = document['qdbt']
  1445. qdbt_addition = document['qdbt_addition']
  1446. bts = {}
  1447. distinguish = True
  1448. for item in qdbt_addition:
  1449. bts[item['Mc']] = 0
  1450. collection = db["qdxm"]
  1451. qd_sum = 0###清单汇总
  1452. rgf_sum = 0
  1453. clf_sum = 0
  1454. jxf_sum = 0
  1455. glf_sum = 0
  1456. lr_sum = 0
  1457. fbrgycl_sum = 0
  1458. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  1459. qd_sum = qd_sum + float(post['合价'])
  1460. rgf_sum = rgf_sum + float(post['数量']) * float(post['人工费'])
  1461. clf_sum = clf_sum + float(post['数量']) * float(post['材料费'])
  1462. jxf_sum = jxf_sum + float(post['数量']) * float(post['机械费'])
  1463. glf_sum = glf_sum + float(post['数量']) * float(post['管理费'])
  1464. lr_sum = lr_sum + float(post['数量']) * float(post['利润'])
  1465. if distinguish and post['bt'] in bts:
  1466. bts[post['bt']] = bts[post['bt']] + float(post['合价'])
  1467. sum = qd_sum + djcs_sum##作为总价措施和后续费用计算的的计算基础
  1468. fbrgycl = document['fbrgycl']
  1469. for entry in fbrgycl:
  1470. fbrgycl_sum = fbrgycl_sum + float(entry['合价'])
  1471. zjcs = document['zjcs']
  1472. def process(n):
  1473. n['计算基数'] = str(sum)
  1474. n['金额'] = float(sum) * float(n['费率']) / float(100)
  1475. if "__children" in n:
  1476. for entry in n['__children']:
  1477. entry['计算基数'] = str(sum)
  1478. entry['金额'] = float(sum) * float(entry['费率']) / float(100)
  1479. return n
  1480. ##目标数据,会存到数据库
  1481. result = [process(item) for item in zjcs]
  1482. for entry in result:
  1483. if '安全文明施工' in entry['名称']:
  1484. sum_ = 0
  1485. for child in entry['__children']:
  1486. sum_ = sum_ + float(child['金额'])
  1487. entry['金额'] = str(sum_)
  1488. entry['计算基数'] = str(sum_)
  1489. zjcs_sum = 0###总价措施汇总
  1490. for entry in result:
  1491. zjcs_sum = zjcs_sum + float(entry['金额'])
  1492. qtxm = document['qtxm']##dwgc qtxm
  1493. qtxm_sum = 0###其他项目汇总, 为了计算规费税金,其他项目本身不会改变
  1494. for entry in qtxm:
  1495. qtxm_sum = qtxm_sum + float(entry['金额'])
  1496. gfsj = document['gfsj']
  1497. gf_sum = 0###规费税金汇总
  1498. sj_sum = 0
  1499. for item in gfsj:
  1500. if item['名称'] == '规费':
  1501. child = item['__children']
  1502. for children in child:
  1503. children['取费基数'] = str(sum + zjcs_sum + qtxm_sum)
  1504. children['金额'] = str(float(sum + zjcs_sum + qtxm_sum) * float(children['费率']) / float(100))
  1505. gf_sum = gf_sum + float(children['金额'])
  1506. for item in gfsj:
  1507. if item['名称'] == '规费':
  1508. item['取费基数'] = str(gf_sum)
  1509. item['金额'] = str(gf_sum)
  1510. for item in gfsj:
  1511. if item['名称'] == '税金':
  1512. item['取费基数'] = str(sum + zjcs_sum + qtxm_sum + gf_sum - fbrgycl_sum / float(1.01))
  1513. item['金额'] = float(item['取费基数']) * float(item['费率']) / float(100)
  1514. sj_sum = float(item['金额'])
  1515. for item in gfsj:
  1516. if item['名称'] == '合计':
  1517. item['取费基数'] = str(sj_sum + gf_sum)
  1518. item['金额'] = item['取费基数']
  1519. qtxm = document['qtxm']
  1520. zlje = 0
  1521. zygczgj = 0
  1522. jrg = 0
  1523. zcbfwf = 0
  1524. clzgj = 0
  1525. for entry in qtxm:
  1526. if entry['序号'] == '1':
  1527. zlje = entry['金额']
  1528. if entry['序号'] == '3':
  1529. jrg = entry['金额']
  1530. if entry['序号'] == '4':
  1531. zcbfwf = entry['金额']
  1532. if entry['序号'] == '2':
  1533. for child in entry['__children']:
  1534. if child['序号'] == '2.2':
  1535. zygczgj = child['金额']
  1536. if child['序号'] == '2.1':
  1537. clzgj = child['金额']
  1538. ###重新算了一遍其他项目汇总
  1539. qtxm_sum = float(zlje) + float(zygczgj) + float(jrg) + float(zcbfwf) + float(clzgj)
  1540. bjhz = bjhz_template()
  1541. for entry in bjhz:
  1542. if entry['序号'] == '1':
  1543. entry['金额'] = qd_sum
  1544. for child in entry['__children']:
  1545. if child['序号'] == '1.1':
  1546. child['金额'] = str(rgf_sum)
  1547. if child['序号'] == '1.2':
  1548. child['金额'] = str(clf_sum)
  1549. if child['序号'] == '1.3':
  1550. child['金额'] = str(jxf_sum)
  1551. if child['序号'] == '1.4':
  1552. child['金额'] = str(glf_sum)
  1553. if child['序号'] == '1.5':
  1554. child['金额'] = str(lr_sum)
  1555. if entry['序号'] == '2':
  1556. entry['金额'] = str(djcs_sum + zjcs_sum)
  1557. for child in entry['__children']:
  1558. if child['序号'] == '2.1':
  1559. child['金额'] = str(djcs_sum)
  1560. if child['序号'] == '2.2':
  1561. child['金额'] = str(zjcs_sum)
  1562. for grandchild in child['__children']:
  1563. if grandchild['序号'] == '2.2.1':
  1564. grandchild['金额'] = str(sum_)
  1565. if entry['序号'] == '3':
  1566. entry['金额'] = str(qtxm_sum)
  1567. if entry['序号'] == '4':
  1568. entry['金额'] = str(gf_sum)
  1569. if entry['序号'] == '5':
  1570. entry['金额'] = str(sj_sum)
  1571. if entry['序号'] == '6':
  1572. entry['金额'] = str(float(qd_sum) + float(djcs_sum) + float(zjcs_sum) + float(qtxm_sum) + float(gf_sum) + float(sj_sum))
  1573. collection = db['Dwgc']
  1574. if distinguish:
  1575. for entry in qdbt_addition:
  1576. entry['Je'] = str(bts[entry['Mc']])
  1577. await collection.update_one({'biao_id': biao_id, "Dwgcbh": bh}, {'$set': {'zjcs': result, 'gfsj' : gfsj, 'bjhz': bjhz, 'qdbt_addition' : qdbt_addition}})
  1578. async def tbxx(client, biao_id):
  1579. db = client["baojia"]
  1580. collection = db["jingjibiao"]
  1581. document = await collection.find_one({'_id': ObjectId(biao_id)})
  1582. dxgcxx = document['Dxgcxx']
  1583. tbxx = document['TouBiaoXx']
  1584. tbxx['Tbzj'] = '0'
  1585. tbxx['Zgj'] = '0'
  1586. tbxx['Aqwmf'] = '0'
  1587. tbxx['Gf'] = '0'
  1588. dwdx = {}##单位工程映射单项工程
  1589. for dxgc in dxgcxx:
  1590. dxgc['Aqwmf'] = '0'
  1591. dxgc['Gf'] = '0'
  1592. dxgc['Je'] = '0'
  1593. dxgc['Zgj'] = '0'
  1594. mc = dxgc['Dxgcmc']
  1595. Dwgc = dxgc['Dwgc']
  1596. for dwgc in Dwgc:
  1597. Dwgcbh = dwgc['Dwgcbh']
  1598. dwdx[Dwgcbh] = dxgc
  1599. collection = db['Dwgc']
  1600. async for post in collection.find({'biao_id': biao_id}):
  1601. bh = post['Dwgcbh']
  1602. dx = dwdx[bh]
  1603. bjhz = post['bjhz']
  1604. if len(bjhz) == 0:
  1605. pass
  1606. else:
  1607. qtxm = post['qtxm']
  1608. dx['Aqwmf'] = str(float(dx['Aqwmf']) + float(bjhz[1]['__children'][1]['__children'][0]['金额']))
  1609. dx['Gf'] = str(float(dx['Gf']) + float(bjhz[3]['金额']))
  1610. dx['Je'] = str(float(dx['Je']) + float(bjhz[5]['金额']))
  1611. dx['Zgj']= str(float(dx['Zgj']) + float(qtxm[1]['金额']))
  1612. for dxgc in dxgcxx:
  1613. tbxx['Tbzj'] = str(float(tbxx['Tbzj']) + float(dxgc['Je']))
  1614. tbxx['Zgj'] = str(float(tbxx['Zgj']) + float(dxgc['Zgj']))
  1615. tbxx['Aqwmf'] = str(float(tbxx['Aqwmf']) + float(dxgc['Aqwmf']))
  1616. tbxx['Gf'] = str(float(tbxx['Gf']) + float(dxgc['Gf']))
  1617. collection = db["jingjibiao"]
  1618. await collection.update_one({'_id': ObjectId(biao_id)}, {'$set': {'Dxgcxx': dxgcxx, 'TouBiaoXx' : tbxx}})
  1619. async def updatezjcs(client, id, bh, mc, fl):
  1620. db = client["baojia"]
  1621. collection = db["Dwgc"]
  1622. document = await collection.find_one({'biao_id': id, 'Dwgcbh': bh}, {'rcjhz': 0})
  1623. zjcs = document['zjcs']
  1624. for entry in zjcs:
  1625. if entry['名称'] == mc:
  1626. entry['费率'] = fl
  1627. entry['金额'] = str(float(entry['计算基数']) * float(fl) / float(100))
  1628. await collection.update_one({'biao_id': id, "Dwgcbh": bh}, {'$set': {'zjcs': zjcs}})
  1629. await zongjiaDwgc(client, id, bh)
  1630. await tbxx(client, id)
  1631. #################保存清单项#############################
  1632. async def save(client, data):
  1633. db = client["baojia"]
  1634. collection = db["qdxm"]
  1635. biao_id = None
  1636. bh = None
  1637. for entry in data:
  1638. entry["__children"] = entry["_children"]
  1639. del entry["_children"]
  1640. biao_id = entry['biao_id']
  1641. bh = entry['Dwgcbh']
  1642. await collection.replace_one({"biao_id": entry["biao_id"], "Dwgcbh": entry["Dwgcbh"], "bt": entry["bt"], "清单编码": entry["清单编码"]}, entry)
  1643. if not biao_id:
  1644. return {"result" : "ok"}
  1645. rcjhz = []
  1646. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  1647. qdrcj = post['rcj'][1:]
  1648. for entry in qdrcj:
  1649. ##print(entry[4])
  1650. if entry[4] != '%':
  1651. entry[10] = float(entry[10]) * float(post['数量'])
  1652. rcjhz = rcjhz + qdrcj
  1653. collection = db["Djcs"]
  1654. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  1655. qdrcj = post['rcj'][1:]
  1656. for entry in qdrcj:
  1657. ##print(entry[4])
  1658. if entry[4] != '%':
  1659. entry[10] = float(entry[10]) * float(post['数量'])
  1660. rcjhz = rcjhz + qdrcj
  1661. newHuizong = util.huizongrcj(rcjhz)
  1662. collection = db["Dwgc"]
  1663. document = await collection.find_one({'biao_id': biao_id,'Dwgcbh': bh})
  1664. fbrgycl = document['fbrgycl']
  1665. for entry in fbrgycl:
  1666. id = entry['材料编号']
  1667. for entry2 in newHuizong:
  1668. if entry2[1] == id:
  1669. entry['数量'] = entry2[5]
  1670. entry['合价'] = entry2[7]
  1671. await collection.update_one({'biao_id': biao_id, 'Dwgcbh': bh}, {'$set': {'rcjhz' : newHuizong, 'fbrgycl': fbrgycl}})
  1672. await zongjiaDwgc(client, biao_id, bh)
  1673. await tbxx(client, biao_id)
  1674. return {"result": "ok"}
  1675. async def savedjcs(client, data):
  1676. db = client["baojia"]
  1677. collection = db["Djcs"]
  1678. biao_id = None
  1679. bh = None
  1680. for entry in data:
  1681. entry["__children"] = entry["_children"]
  1682. del entry["_children"]
  1683. biao_id = entry['biao_id']
  1684. bh = entry['Dwgcbh']
  1685. await collection.replace_one({"biao_id": entry["biao_id"], "Dwgcbh": entry["Dwgcbh"], "清单编码": entry["清单编码"]}, entry)
  1686. if not biao_id:
  1687. return {"result" : "ok"}
  1688. rcjhz = []
  1689. collection = db["qdxm"]
  1690. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  1691. qdrcj = post['rcj'][1:]
  1692. for entry in qdrcj:
  1693. if entry[4] != '%':
  1694. entry[10] = float(entry[10]) * float(post['数量'])
  1695. rcjhz = rcjhz + qdrcj
  1696. collection = db["Djcs"]
  1697. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  1698. qdrcj = post['rcj'][1:]
  1699. for entry in qdrcj:
  1700. if entry[4] != '%':
  1701. entry[10] = float(entry[10]) * float(post['数量'])
  1702. rcjhz = rcjhz + qdrcj
  1703. newHuizong = util.huizongrcj(rcjhz)
  1704. collection = db["Dwgc"]
  1705. document = await collection.find_one({'biao_id': biao_id,'Dwgcbh': bh})
  1706. fbrgycl = document['fbrgycl']
  1707. for entry in fbrgycl:
  1708. id = entry['材料编号']
  1709. for entry2 in newHuizong:
  1710. if entry2[1] == id:
  1711. entry['数量'] = entry2[5]
  1712. entry['合价'] = entry2[7]
  1713. await collection.update_one({'biao_id': biao_id, 'Dwgcbh': bh}, {'$set': {'rcjhz' : newHuizong, 'fbrgycl': fbrgycl}})
  1714. await zongjiaDwgc(client, biao_id, bh)
  1715. await tbxx(client, biao_id)
  1716. return {"result": "ok"}
  1717. async def applyFL(client, id, data):
  1718. db = client["baojia"]
  1719. collection = db["qufei"]
  1720. await collection.replace_one({"biao_id": id}, {"biao_id": id, "qufei": data})
  1721. collection = db['qdxm']
  1722. xm = data[0]
  1723. for dxgc in xm["children"]:
  1724. for dwgc in dxgc["children"]:
  1725. bh = dwgc['key']
  1726. glf = float(dwgc['管理费(%)'])
  1727. lr = float(dwgc['利润(%)'])
  1728. bz = dwgc['备注']
  1729. ##print(bh+glf+lr+bz)
  1730. async for post in collection.find({'biao_id': id, "Dwgcbh": bh}):
  1731. rgfs = float(post['人工费'])
  1732. clfs = float(post['材料费'])
  1733. jxfs = float(post['机械费'])
  1734. sl = float(post['数量'])
  1735. if rgfs < 0.0001 and clfs < 0.0001 and jxfs < 0.0001:
  1736. continue
  1737. ##danxiang = False
  1738. for child in post['__children']:##一条定额
  1739. bm = child['清单编码']
  1740. if bm.startswith("D"):
  1741. ##danxiang = True
  1742. continue
  1743. rgf = float(child['人工费'])
  1744. clf = float(child['材料费'])
  1745. jxf = float(child['机械费'])
  1746. zhdj = float(child['综合单价'])
  1747. sl_ = float(child['数量'])
  1748. if len(bz) == 0:
  1749. ##常规计算
  1750. child['管理费'] = (rgf + jxf) * glf / float(100)
  1751. child['利润'] = (rgf + jxf) * lr / float(100)
  1752. child['综合单价'] = rgf + clf + jxf + child['管理费'] + child['利润']
  1753. child['合价'] = sl * sl_ * child['综合单价']
  1754. else:
  1755. child['管理费'] = (rgf) * glf / float(100)
  1756. child['利润'] = (rgf) * lr / float(100)
  1757. child['综合单价'] = rgf + clf + jxf + child['管理费'] + child['利润']
  1758. child['合价'] = sl * sl_ * child['综合单价']
  1759. if True:
  1760. post['管理费'] = 0
  1761. post['利润'] = 0
  1762. for entry in post['__children']:
  1763. post['管理费'] = post['管理费'] + float(entry['管理费']) * float(entry['数量'])
  1764. post['利润'] = post['利润'] + float(entry['利润']) * float(entry['数量'])
  1765. post['管理费'] = str(post['管理费'])
  1766. post['利润'] = str(post['利润'])
  1767. post['综合单价'] = str(float(post['人工费']) + float(post['材料费']) + float(post['机械费']) + float(post['管理费']) + float(post['利润']))
  1768. post['合价'] = str(float(post['综合单价']) * float(post['数量']))
  1769. await collection.replace_one({'_id': post['_id']}, post )
  1770. collection = db['Djcs']
  1771. for dxgc in xm["children"]:
  1772. for dwgc in dxgc["children"]:
  1773. bh = dwgc['key']
  1774. glf = float(dwgc['管理费(%)'])
  1775. lr = float(dwgc['利润(%)'])
  1776. bz = dwgc['备注']
  1777. ##print(bh+glf+lr+bz)
  1778. async for post in collection.find({'biao_id': id, "Dwgcbh": bh}):
  1779. rgfs = float(post['人工费'])
  1780. clfs = float(post['材料费'])
  1781. jxfs = float(post['机械费'])
  1782. sl = float(post['数量'])
  1783. if rgfs < 0.0001 and clfs < 0.0001 and jxfs < 0.0001:
  1784. continue
  1785. ##danxiang = False##一般有单项定额的,清单就一条定额,就是这个单项定额
  1786. for child in post['__children']:
  1787. bm = child['清单编码']
  1788. if bm.startswith("D"):
  1789. ##danxiang = True
  1790. continue
  1791. rgf = float(child['人工费'])
  1792. clf = float(child['材料费'])
  1793. jxf = float(child['机械费'])
  1794. zhdj = float(child['综合单价'])
  1795. sl_ = float(child['数量'])
  1796. if len(bz) == 0:
  1797. ##常规计算
  1798. child['管理费'] = (rgf + jxf) * glf / float(100)
  1799. child['利润'] = (rgf + jxf) * lr / float(100)
  1800. child['综合单价'] = rgf + clf + jxf + child['管理费'] + child['利润']
  1801. child['合价'] = sl * sl_ * child['综合单价']
  1802. else:
  1803. child['管理费'] = (rgf) * glf / float(100)
  1804. child['利润'] = (rgf) * lr / float(100)
  1805. child['综合单价'] = rgf + clf + jxf + child['管理费'] + child['利润']
  1806. child['合价'] = sl * sl_ * child['综合单价']
  1807. if True:
  1808. post['管理费'] = 0
  1809. post['利润'] = 0
  1810. for entry in post['__children']:
  1811. post['管理费'] = post['管理费'] + float(entry['管理费']) * float(entry['数量'])
  1812. post['利润'] = post['利润'] + float(entry['利润']) * float(entry['数量'])
  1813. post['管理费'] = str(post['管理费'])
  1814. post['利润'] = str(post['利润'])
  1815. post['综合单价'] = str(float(post['人工费']) + float(post['材料费']) + float(post['机械费']) + float(post['管理费']) + float(post['利润']))
  1816. post['合价'] = str(float(post['综合单价']) * float(post['数量']))
  1817. await collection.replace_one({'_id': post['_id']}, post )
  1818. for dxgc in xm["children"]:
  1819. for dwgc in dxgc["children"]:
  1820. bh = dwgc['key']
  1821. await zongjiaDwgc(client, id, bh)
  1822. await tbxx(client, id)
  1823. return {"result": "ok"}
  1824. ###人材机汇总页面调价
  1825. async def tiaojia(client, biao_id, bh, bm, mingcheng, danwei, jiage, glf, lr, bz):
  1826. db = client["baojia"]
  1827. rcjhz = []
  1828. collection = db["qdxm"]
  1829. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}):
  1830. if "__children" not in post:
  1831. ##print(post)
  1832. continue
  1833. children = post["__children"]
  1834. qdsl = post['数量']
  1835. hit = False##清单级别
  1836. for entry in children:###对一条定额,调价
  1837. hitde = False
  1838. dercj = entry["dercj"]
  1839. dergf = 0
  1840. declf = 0
  1841. dezcf = 0
  1842. dejxf = 0
  1843. for i in range(1, len(dercj)):
  1844. rcj = dercj[i]
  1845. if rcj[1] == bm and rcj[2] == mingcheng and rcj[4] == danwei:
  1846. hit = True
  1847. hitde = True
  1848. rcj[5] = jiage
  1849. hanliang = rcj[10]
  1850. rcj[11] = str(float(jiage) * float(hanliang))
  1851. if int(rcj[8]) == 1:##rcjlb
  1852. dergf = dergf + float(rcj[11])
  1853. elif int(rcj[8]) == 2:
  1854. declf = declf + float(rcj[11])
  1855. if rcj[14] == 'true' :
  1856. dezcf = dezcf + float(rcj[11])
  1857. elif int(rcj[8]) == 3:
  1858. dejxf = dejxf + float(rcj[11])
  1859. if hitde:
  1860. for i in range(1, len(dercj)):
  1861. rcj = dercj[i]
  1862. if rcj[1] == '00EXP001' and rcj[4] == '%':##//回程费占人工费
  1863. rcj[11] = float(rcj[10]) * dergf / float(100)
  1864. if rcj[1] == '99EXP007' and rcj[4] == '%':##//回程费占机械费
  1865. rcj[11] = float(rcj[10]) * dejxf / float(100)
  1866. if rcj[1] == '99EXP022' and rcj[4] == '%':##//回程费占机械费
  1867. rcj[11] = float(rcj[10]) * dejxf / float(100)
  1868. if rcj[1] == '31130104' and rcj[4] == '%':##//回程费占材料费
  1869. rcj[11] = float(rcj[10]) * declf / float(100)
  1870. dergf = 0
  1871. declf = 0
  1872. dejxf = 0
  1873. dezcf = 0
  1874. for i in range(1, len(dercj)):
  1875. rcj = dercj[i]
  1876. if int(rcj[8]) == 1:
  1877. dergf = dergf + float(rcj[11])
  1878. elif int(rcj[8]) == 2:
  1879. declf = declf + float(rcj[11])
  1880. if rcj[14] == 'true' :
  1881. dezcf = dezcf + float(rcj[11])
  1882. elif int(rcj[8]) == 3:
  1883. dejxf = dejxf + float(rcj[11])
  1884. entry['人工费'] = str(dergf)
  1885. entry['辅材费'] = str(declf - dezcf)
  1886. entry['主材费'] = str(dezcf)
  1887. entry['材料费'] = str(declf)
  1888. entry['机械费'] = str(dejxf)
  1889. if bm.startswith("D"):
  1890. entry['管理费'] = '0'
  1891. entry['利润'] = '0'
  1892. elif bz == 0:
  1893. entry['管理费'] = str((dergf + dejxf) * float(glf) / float(100))
  1894. entry['利润'] = str((dergf + dejxf) * float(lr) / float(100))
  1895. else:
  1896. entry['管理费'] = str((dergf) * float(glf) / float(100))
  1897. entry['利润'] = str((dergf) * float(lr) / float(100))
  1898. entry['综合单价'] = str(float(entry['人工费']) + float(entry['材料费']) + float(entry['机械费']) + float(entry['管理费']) + float(entry['利润']))
  1899. entry['合价'] = str(float(entry['综合单价']) * float(entry['数量']) * float(qdsl))
  1900. if hit:
  1901. post['综合单价'] = 0
  1902. post['合价'] = 0
  1903. post['人工费'] = 0
  1904. post['主材费'] = 0
  1905. post['设备费'] = 0
  1906. post['辅材费'] = 0
  1907. post['材料费'] = 0
  1908. post['机械费'] = 0
  1909. post['管理费'] = 0
  1910. post['利润'] = 0
  1911. for i in range(len(post["__children"])):
  1912. if len(post["__children"][i]['azfytag']) > 0:
  1913. continue
  1914. post['综合单价'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['综合单价'])
  1915. post['合价'] += float(post['__children'][i]['合价'])
  1916. post['人工费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['人工费'])
  1917. post['主材费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['主材费'])
  1918. post['设备费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['设备费'])
  1919. post['辅材费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['辅材费'])
  1920. post['材料费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['材料费'])
  1921. post['机械费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['机械费'])
  1922. post['管理费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['管理费'])
  1923. post['利润'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['利润'])
  1924. ##处理安装费用
  1925. ##console.log(qd["_children"].length);
  1926. for i in range(len(post["__children"])):
  1927. ##console.log(i);
  1928. if len(post["__children"][i]['azfytag']) > 0:
  1929. tag = post["__children"][i]['azfytag']
  1930. if tag[0] == '人工费':
  1931. current_rgf = post['人工费']
  1932. added = float(current_rgf) * float(tag[1]) / float(100)
  1933. added_rgf = added * float(tag[2]) / float(100)
  1934. added_clf = added * float(tag[3]) / float(100)
  1935. added_jxf = added * float(tag[4]) / float(100)
  1936. post["__children"][i]['人工费'] = added_rgf
  1937. post["__children"][i]['辅材费'] = added_clf
  1938. post["__children"][i]['材料费'] = added_clf
  1939. post["__children"][i]['机械费'] = added_jxf
  1940. if bz == 0:
  1941. ##changuiqufei
  1942. post["__children"][i]['管理费'] = (added_rgf + added_jxf) * float(glf) / float(100)
  1943. post["__children"][i]['利润'] = (added_rgf + added_jxf) * float(lr) / float(100)
  1944. else:
  1945. post["__children"][i]['管理费'] = (added_rgf) * float(glf) / float(100)
  1946. post["__children"][i]['利润'] = (added_rgf) * float(lr) / float(100)
  1947. post["__children"][i]['综合单价'] = post["__children"][i]['人工费'] + post["__children"][i]['材料费'] + post["__children"][i]['机械费'] + post["__children"][i]['管理费'] + post["__children"][i]['利润']
  1948. post["__children"][i]['合价'] = post["__children"][i]['综合单价'] * float(post["__children"][i]['数量']) * float(post['数量'])
  1949. dercj = post["__children"][i]['dercj']
  1950. for j in range(1, len(dercj)):
  1951. dercj[j][11] = float(added) * float(dercj[j][10]) / float(100)
  1952. if tag[0] == '人工费+机械费':
  1953. current_rgf = post['人工费'] + post['机械费']
  1954. added = float(current_rgf) * float(tag[1]) / float(100)
  1955. added_rgf = added * float(tag[2]) / float(100)
  1956. added_clf = added * float(tag[3]) / float(100)
  1957. added_jxf = added * float(tag[4]) / float(100)
  1958. post["__children"][i]['人工费'] = added_rgf
  1959. post["__children"][i]['辅材费'] = added_clf
  1960. post["__children"][i]['材料费'] = added_clf
  1961. post["__children"][i]['机械费'] = added_jxf
  1962. if bz == 0:
  1963. ###changuiqufei
  1964. post["__children"][i]['管理费'] = (added_rgf + added_jxf) * float(glf) / float(100)
  1965. post["__children"][i]['利润'] = (added_rgf + added_jxf) * float(lr) / float(100)
  1966. else:
  1967. post["__children"][i]['管理费'] = (added_rgf) * float(glf) / float(100)
  1968. post["__children"][i]['利润'] = (added_rgf) * float(lr) / float(100)
  1969. post["__children"][i]['综合单价'] = post["__children"][i]['人工费'] + post["__children"][i]['材料费'] + post["__children"][i]['机械费'] + post["__children"][i]['管理费'] + post["__children"][i]['利润']
  1970. post["__children"][i]['合价'] = post["__children"][i]['综合单价'] * float(post["__children"][i]['数量']) * float(post["数量"])
  1971. dercj = post["__children"][i]['dercj']
  1972. for j in range(1, len(dercj)):
  1973. dercj[j][11] = float(added) * float(dercj[j][10]) / float(100)
  1974. qdrcj = []
  1975. for i in range(len(post["__children"])):
  1976. dercj = post["__children"][i]['dercj']
  1977. sl = post["__children"][i]['数量']
  1978. for entry in dercj:
  1979. if '000FE' in entry[1] and entry[4] == '%': ##azfy
  1980. qdrcj.append(entry)
  1981. elif '00EXP001' in entry[1] and entry[4] == '%': ##回程费
  1982. qdrcj.append(entry)
  1983. elif '99EXP007' in entry[1] and entry[4] == '%': ##回程费
  1984. qdrcj.append(entry)
  1985. elif '99EXP022' in entry[1] and entry[4] == '%': ##回程费
  1986. qdrcj.append(entry)
  1987. elif '31130104' in entry[1] and entry[4] == '%': ##回程费
  1988. qdrcj.append(entry)
  1989. elif entry[10] != '含量':
  1990. entry[10] = float(sl) * float(entry[10])
  1991. qdrcj.append(entry)
  1992. post["rcj"] = util.huizongrcj_order(qdrcj)
  1993. post['综合单价'] = 0
  1994. post['合价'] = 0
  1995. post['人工费'] = 0
  1996. post['主材费'] = 0
  1997. post['设备费'] = 0
  1998. post['辅材费'] = 0
  1999. post['材料费'] = 0
  2000. post['机械费'] = 0
  2001. post['管理费'] = 0
  2002. post['利润'] = 0
  2003. for i in range(len(post["__children"])):
  2004. post['综合单价'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['综合单价'])
  2005. post['合价'] += float(post['__children'][i]['合价'])
  2006. post['人工费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['人工费'])
  2007. post['主材费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['主材费'])
  2008. post['设备费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['设备费'])
  2009. post['辅材费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['辅材费'])
  2010. post['材料费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['材料费'])
  2011. post['机械费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['机械费'])
  2012. post['管理费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['管理费'])
  2013. post['利润'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['利润'])
  2014. await collection.replace_one({'_id': post['_id']}, post )
  2015. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  2016. qdrcj = post['rcj'][1:]
  2017. for entry in qdrcj:
  2018. if entry[4] != '%':
  2019. entry[10] = float(entry[10]) * float(post['数量'])
  2020. rcjhz = rcjhz + qdrcj
  2021. collection = db["Djcs"]
  2022. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}):
  2023. if "__children" not in post:
  2024. ##print(post)
  2025. continue
  2026. children = post["__children"]
  2027. qdsl = post['数量']
  2028. hit = False
  2029. for entry in children:###对一条定额,调价
  2030. hitde = False
  2031. dercj = entry["dercj"]
  2032. dergf = 0
  2033. declf = 0
  2034. dejxf = 0
  2035. dezcf = 0
  2036. for i in range(1, len(dercj)):
  2037. rcj = dercj[i]
  2038. if rcj[1] == bm and rcj[2] == mingcheng and rcj[4] == danwei:
  2039. hit = True
  2040. hitde = True
  2041. rcj[5] = jiage
  2042. hanliang = rcj[10]
  2043. rcj[11] = str(float(jiage) * float(hanliang))
  2044. if int(rcj[8]) == 1:
  2045. dergf = dergf + float(rcj[11])
  2046. elif int(rcj[8]) == 2:
  2047. declf = declf + float(rcj[11])
  2048. if rcj[14] == 'true' :
  2049. dezcf = dezcf + float(rcj[11])
  2050. elif int(rcj[8]) == 3:
  2051. dejxf = dejxf + float(rcj[11])
  2052. if hitde:
  2053. for i in range(1, len(dercj)):
  2054. rcj = dercj[i]
  2055. if rcj[1] == '00EXP001' and rcj[4] == '%':##//回程费占人工费
  2056. rcj[11] = float(rcj[10]) * dergf / float(100)
  2057. if rcj[1] == '99EXP007' and rcj[4] == '%':##//回程费占机械费
  2058. rcj[11] = float(rcj[10]) * dejxf / float(100)
  2059. if rcj[1] == '99EXP022' and rcj[4] == '%':##//回程费占机械费
  2060. rcj[11] = float(rcj[10]) * dejxf / float(100)
  2061. if rcj[1] == '31130104' and rcj[4] == '%':##//回程费占材料费
  2062. rcj[11] = float(rcj[10]) * declf / float(100)
  2063. dergf = 0
  2064. declf = 0
  2065. dejxf = 0
  2066. dezcf = 0
  2067. for i in range(1, len(dercj)):
  2068. rcj = dercj[i]
  2069. if int(rcj[8]) == 1:
  2070. dergf = dergf + float(rcj[11])
  2071. elif int(rcj[8]) == 2:
  2072. declf = declf + float(rcj[11])
  2073. if rcj[14] == 'true' :
  2074. dezcf = dezcf + float(rcj[11])
  2075. elif int(rcj[8]) == 3:
  2076. dejxf = dejxf + float(rcj[11])
  2077. entry['人工费'] = str(dergf)
  2078. entry['辅材费'] = str(declf - dezcf)
  2079. entry['材料费'] = str(declf)
  2080. entry['机械费'] = str(dejxf)
  2081. if bm.startswith("D"):
  2082. entry['管理费'] = '0'
  2083. entry['利润'] = '0'
  2084. elif bz == 0:
  2085. entry['管理费'] = str((dergf + dejxf) * float(glf) / float(100))
  2086. entry['利润'] = str((dergf + dejxf) * float(lr) / float(100))
  2087. else:
  2088. entry['管理费'] = str((dergf) * float(glf) / float(100))
  2089. entry['利润'] = str((dergf) * float(lr) / float(100))
  2090. entry['综合单价'] = str(float(entry['人工费']) + float(entry['材料费']) + float(entry['机械费']) + float(entry['管理费']) + float(entry['利润']))
  2091. entry['合价'] = str(float(entry['综合单价']) * float(entry['数量']) * float(qdsl))
  2092. if hit:
  2093. qdrcj = []
  2094. for i in range(len(post["__children"])):
  2095. dercj = post["__children"][i]['dercj']
  2096. sl = post["__children"][i]['数量']
  2097. for entry in dercj:
  2098. if '000FE' in entry[1] and entry[4] == '%': ##azfy
  2099. qdrcj.append(entry)
  2100. elif '00EXP001' in entry[1] and entry[4] == '%': ##回程费
  2101. qdrcj.append(entry)
  2102. elif '99EXP007' in entry[1] and entry[4] == '%': ##回程费
  2103. qdrcj.append(entry)
  2104. elif '99EXP022' in entry[1] and entry[4] == '%': ##回程费
  2105. qdrcj.append(entry)
  2106. elif '31130104' in entry[1] and entry[4] == '%': ##回程费
  2107. qdrcj.append(entry)
  2108. elif entry[10] != '含量':
  2109. entry[10] = float(sl) * float(entry[10])
  2110. qdrcj.append(entry)
  2111. post["rcj"] = util.huizongrcj_order(qdrcj)
  2112. post['综合单价'] = 0
  2113. post['合价'] = 0
  2114. post['人工费'] = 0
  2115. post['主材费'] = 0
  2116. post['设备费'] = 0
  2117. post['辅材费'] = 0
  2118. post['材料费'] = 0
  2119. post['机械费'] = 0
  2120. post['管理费'] = 0
  2121. post['利润'] = 0
  2122. for i in range(len(post["__children"])):
  2123. post['综合单价'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['综合单价'])
  2124. post['合价'] += float(post['__children'][i]['合价'])
  2125. post['人工费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['人工费'])
  2126. post['主材费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['主材费'])
  2127. post['设备费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['设备费'])
  2128. post['辅材费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['辅材费'])
  2129. post['材料费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['材料费'])
  2130. post['机械费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['机械费'])
  2131. post['管理费'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['管理费'])
  2132. post['利润'] += float(post['__children'][i]['数量']) * float(post['__children'][i]['利润'])
  2133. await collection.replace_one({'_id': post['_id']}, post )
  2134. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  2135. qdrcj = post['rcj'][1:]
  2136. for entry in qdrcj:
  2137. if entry[4] != '%':
  2138. entry[10] = float(entry[10]) * float(post['数量'])
  2139. rcjhz = rcjhz + qdrcj
  2140. newHuizong = util.huizongrcj(rcjhz)
  2141. collection = db["Dwgc"]
  2142. document = await collection.find_one({'biao_id': biao_id,'Dwgcbh': bh})
  2143. fbrgycl = document['fbrgycl']
  2144. for entry in fbrgycl:
  2145. id = entry['材料编号']
  2146. for entry2 in newHuizong:
  2147. if entry2[1] == id:
  2148. entry['数量'] = entry2[5]
  2149. entry['合价'] = entry2[7]
  2150. await collection.update_one({'biao_id': biao_id, "Dwgcbh": bh}, {'$set': {'rcjhz': newHuizong, 'fbrgycl': fbrgycl}})
  2151. await zongjiaDwgc(client, biao_id, bh)
  2152. await tbxx(client, biao_id)
  2153. return newHuizong
  2154. #################清单AI#############################
  2155. async def tuijian(client, query):##default return 10 neighbors
  2156. collection = client.get_or_create_collection(name="qingdan")
  2157. result = collection.get(ids=[query], include=["documents", "metadatas", "embeddings"])
  2158. if result and len(result['embeddings']) > 0:
  2159. result_ = re.findall(r'\d{9}', query)
  2160. bh = result_[0]
  2161. if bh[0:2] == '01':
  2162. collection = client.get_or_create_collection(name="de-tj")
  2163. hit = collection.query(
  2164. query_embeddings=result['embeddings']
  2165. )
  2166. answer = []
  2167. if len(hit['ids']) == 0:
  2168. return answer
  2169. for i in range(len(hit['ids'][0])):
  2170. answer.append({'组价定额': hit['ids'][0][i], '定额名称': hit['documents'][0][i], "id": hit['ids'][0][i]})
  2171. return answer
  2172. elif bh[0:2] == '03':
  2173. collection = client.get_or_create_collection(name="de-az")
  2174. hit = collection.query(
  2175. query_embeddings=result['embeddings']
  2176. )
  2177. answer = []
  2178. if len(hit['ids']) == 0:
  2179. return answer
  2180. for i in range(len(hit['ids'][0])):
  2181. answer.append({'组价定额': hit['ids'][0][i], '定额名称': hit['documents'][0][i], "id": hit['ids'][0][i]})
  2182. return answer
  2183. elif bh[0:2] == '04':
  2184. collection = client.get_or_create_collection(name="de-sz")
  2185. hit = collection.query(
  2186. query_embeddings=result['embeddings']
  2187. )
  2188. answer = []
  2189. if len(hit['ids']) == 0:
  2190. return answer
  2191. for i in range(len(hit['ids'][0])):
  2192. answer.append({'组价定额': hit['ids'][0][i], '定额名称': hit['documents'][0][i], "id": hit['ids'][0][i]})
  2193. return answer
  2194. elif bh[0:2] == '05':
  2195. collection = client.get_or_create_collection(name="de-yl")
  2196. hit = collection.query(
  2197. query_embeddings=result['embeddings']
  2198. )
  2199. answer = []
  2200. if len(hit['ids']) == 0:
  2201. return answer
  2202. for i in range(len(hit['ids'][0])):
  2203. answer.append({'组价定额': hit['ids'][0][i], '定额名称': hit['documents'][0][i], "id": hit['ids'][0][i]})
  2204. return answer
  2205. else:
  2206. return []
  2207. else:
  2208. return []
  2209. async def zujia(client, query):
  2210. db = client["baojia"]
  2211. collection = db["qdxm"]
  2212. regex_pattern1 = re.compile("^"+query, re.IGNORECASE)
  2213. result = {}
  2214. async for post in collection.find({'清单编码': {"$regex" : regex_pattern1}, "__children.0": {"$exists" : 1} }):
  2215. t = []
  2216. name = []
  2217. for entry in post["__children"]:
  2218. t.append(entry["清单编码"])
  2219. name.append(entry["名称"])
  2220. key = "@".join(t)
  2221. key = key + "@" + post['单位']
  2222. names = "@@".join(name)
  2223. if key in result:
  2224. result[key]["count"] = result[key]["count"] + 1
  2225. else:
  2226. result[key] = {"count": 1, "name" : names, "unit" : post["单位"], "price" : post["综合单价"]}
  2227. return [{"id" : x, "组价定额" : x[0:x.rfind("@")], "数量" : result[x]["count"], "定额名称" : result[x]["name"], "单位" : result[x]['unit'], "综合单价" : result[x]['price']} for x in result.keys()]
  2228. async def statistics(client, query):
  2229. db = client["baojia"]
  2230. collection = db["qdxm"]
  2231. if query == "":
  2232. tj = 0
  2233. fg = 0
  2234. az = 0
  2235. sz = 0
  2236. yl = 0
  2237. regex_pattern1 = re.compile("^01", re.IGNORECASE)
  2238. regex_pattern2 = re.compile("^02", re.IGNORECASE)
  2239. regex_pattern3 = re.compile("^03", re.IGNORECASE)
  2240. regex_pattern4 = re.compile("^04", re.IGNORECASE)
  2241. regex_pattern5 = re.compile("^05", re.IGNORECASE)
  2242. tj = await collection.count_documents({'清单编码': regex_pattern1})
  2243. fg = await collection.count_documents({'清单编码': regex_pattern2})
  2244. az = await collection.count_documents({'清单编码': regex_pattern3})
  2245. sz = await collection.count_documents({'清单编码': regex_pattern4})
  2246. yl = await collection.count_documents({'清单编码': regex_pattern5})
  2247. return [["工程类别", "清单数"],
  2248. ["建筑与装饰工程", tj],
  2249. ["仿古建筑", fg],
  2250. ["安装工程", az],
  2251. ["市政工程", sz],
  2252. ["园林绿化工程", yl]]
  2253. elif query == "建筑与装饰工程":
  2254. tsf = 0
  2255. ldm = 0
  2256. zj = 0
  2257. qz = 0
  2258. hnt = 0
  2259. js = 0
  2260. qzm = 0
  2261. mc = 0
  2262. wm = 0
  2263. total = 0
  2264. tp = 0
  2265. yq = 0
  2266. regex_pattern1 = re.compile("^01", re.IGNORECASE)
  2267. regex_pattern2 = re.compile("^0101", re.IGNORECASE)
  2268. regex_pattern3 = re.compile("^0111", re.IGNORECASE)
  2269. regex_pattern4 = re.compile("^0103", re.IGNORECASE)
  2270. regex_pattern5 = re.compile("^0104", re.IGNORECASE)
  2271. regex_pattern6 = re.compile("^0105", re.IGNORECASE)
  2272. regex_pattern7 = re.compile("^0106", re.IGNORECASE)
  2273. regex_pattern8 = re.compile("^0112", re.IGNORECASE)
  2274. regex_pattern9 = re.compile("^0108", re.IGNORECASE)
  2275. regex_pattern10 = re.compile("^0109", re.IGNORECASE)
  2276. regex_pattern11 = re.compile("^0113", re.IGNORECASE)
  2277. regex_pattern12 = re.compile("^0114", re.IGNORECASE)
  2278. total = await collection.count_documents({'清单编码': regex_pattern1})
  2279. tsf = await collection.count_documents({'清单编码': regex_pattern2})
  2280. ldm = await collection.count_documents({'清单编码': regex_pattern3})
  2281. zj = await collection.count_documents({'清单编码': regex_pattern4})
  2282. qz = await collection.count_documents({'清单编码': regex_pattern5})
  2283. hnt = await collection.count_documents({'清单编码': regex_pattern6})
  2284. js = await collection.count_documents({'清单编码': regex_pattern7})
  2285. qzm = await collection.count_documents({'清单编码': regex_pattern8})
  2286. mc = await collection.count_documents({'清单编码': regex_pattern9})
  2287. wm = await collection.count_documents({'清单编码': regex_pattern10})
  2288. tp = await collection.count_documents({'清单编码': regex_pattern11})
  2289. yq = await collection.count_documents({'清单编码': regex_pattern12})
  2290. return [
  2291. ["工程类别", "清单数"],
  2292. ['土石方工程', tsf],
  2293. ['楼地面', ldm],
  2294. ['桩基工程', zj],
  2295. ['砌筑工程', qz],
  2296. ['(钢筋)混凝土', hnt],
  2297. ['金属结构', js],
  2298. ['墙、柱面', qzm],
  2299. ['门窗工程', mc],
  2300. ['屋面及防水工程', wm],
  2301. ['天棚工程', tp],
  2302. ['油漆、涂料、裱糊', yq],
  2303. ['其他', total - tsf - ldm - zj - qz - hnt - js - qzm - mc - wm - tp - yq],
  2304. ]
  2305. elif query == "安装工程":
  2306. jx = 0
  2307. rl = 0
  2308. jz = 0
  2309. dq = 0
  2310. znh = 0
  2311. yb = 0
  2312. tf = 0
  2313. gd = 0
  2314. xf = 0
  2315. jps = 0
  2316. tx = 0
  2317. sy = 0
  2318. total = 0
  2319. regex_pattern1 = re.compile("^03", re.IGNORECASE)
  2320. regex_pattern2 = re.compile("^0301", re.IGNORECASE)
  2321. regex_pattern3 = re.compile("^0302", re.IGNORECASE)
  2322. regex_pattern4 = re.compile("^0303", re.IGNORECASE)
  2323. regex_pattern5 = re.compile("^0304", re.IGNORECASE)
  2324. regex_pattern6 = re.compile("^0305", re.IGNORECASE)
  2325. regex_pattern7 = re.compile("^0306", re.IGNORECASE)
  2326. regex_pattern8 = re.compile("^0307", re.IGNORECASE)
  2327. regex_pattern9 = re.compile("^0308", re.IGNORECASE)
  2328. regex_pattern10 = re.compile("^0309", re.IGNORECASE)
  2329. regex_pattern11 = re.compile("^0310", re.IGNORECASE)
  2330. regex_pattern12 = re.compile("^0311", re.IGNORECASE)
  2331. regex_pattern13 = re.compile("^0312", re.IGNORECASE)
  2332. total = await collection.count_documents({'清单编码': regex_pattern1})
  2333. jx = await collection.count_documents({'清单编码': regex_pattern2})
  2334. rl = await collection.count_documents({'清单编码': regex_pattern3})
  2335. jz = await collection.count_documents({'清单编码': regex_pattern4})
  2336. dq = await collection.count_documents({'清单编码': regex_pattern5})
  2337. znh = await collection.count_documents({'清单编码': regex_pattern6})
  2338. yb = await collection.count_documents({'清单编码': regex_pattern7})
  2339. tf = await collection.count_documents({'清单编码': regex_pattern8})
  2340. gd = await collection.count_documents({'清单编码': regex_pattern9})
  2341. xf = await collection.count_documents({'清单编码': regex_pattern10})
  2342. jps = await collection.count_documents({'清单编码': regex_pattern11})
  2343. tx = await collection.count_documents({'清单编码': regex_pattern12})
  2344. sy = await collection.count_documents({'清单编码': regex_pattern13})
  2345. return [
  2346. ["工程类别", "清单数"],
  2347. ['机械设备', jx],
  2348. ['热力设备', rl],
  2349. ['静置设备、金属结构', jz],
  2350. ['电气设备', dq],
  2351. ['智能化', znh],
  2352. ['仪表安装', yb],
  2353. ['通风空调', tf],
  2354. ['工业管道', gd],
  2355. ['消防工程', xf],
  2356. ['给排水、采暖、燃气', jps],
  2357. ['通信设备', tx],
  2358. ['刷油、防腐蚀、绝热', sy],
  2359. ['其他', total - jx - rl - jz - dq - znh - yb - tf - gd - xf - jps - tx - sy],
  2360. ]
  2361. elif query == "市政工程":
  2362. tsf = 0
  2363. dl = 0
  2364. qh = 0
  2365. sd = 0
  2366. gw = 0
  2367. scl = 0
  2368. lj = 0
  2369. ld = 0
  2370. gj = 0
  2371. cc = 0
  2372. total = 0
  2373. regex_pattern1 = re.compile("^04", re.IGNORECASE)
  2374. regex_pattern2 = re.compile("^0401", re.IGNORECASE)
  2375. regex_pattern3 = re.compile("^0402", re.IGNORECASE)
  2376. regex_pattern4 = re.compile("^0403", re.IGNORECASE)
  2377. regex_pattern5 = re.compile("^0404", re.IGNORECASE)
  2378. regex_pattern6 = re.compile("^0405", re.IGNORECASE)
  2379. regex_pattern7 = re.compile("^0406", re.IGNORECASE)
  2380. regex_pattern8 = re.compile("^0407", re.IGNORECASE)
  2381. regex_pattern9 = re.compile("^0408", re.IGNORECASE)
  2382. regex_pattern10 = re.compile("^0409", re.IGNORECASE)
  2383. regex_pattern11 = re.compile("^0410", re.IGNORECASE)
  2384. total = await collection.count_documents({'清单编码': regex_pattern1})
  2385. tsf = await collection.count_documents({'清单编码': regex_pattern2})
  2386. dl = await collection.count_documents({'清单编码': regex_pattern3})
  2387. qh = await collection.count_documents({'清单编码': regex_pattern4})
  2388. sd = await collection.count_documents({'清单编码': regex_pattern5})
  2389. gw = await collection.count_documents({'清单编码': regex_pattern6})
  2390. scl = await collection.count_documents({'清单编码': regex_pattern7})
  2391. lj = await collection.count_documents({'清单编码': regex_pattern8})
  2392. ld = await collection.count_documents({'清单编码': regex_pattern9})
  2393. gj = await collection.count_documents({'清单编码': regex_pattern10})
  2394. cc = await collection.count_documents({'清单编码': regex_pattern11})
  2395. return [
  2396. ["工程类别", "清单数"],
  2397. ['土石方', tsf],
  2398. ['道路工程', dl],
  2399. ['桥涵工程', qh],
  2400. ['隧道工程', sd],
  2401. ['管网工程', gw],
  2402. ['水处理', scl],
  2403. ['垃圾处理', lj],
  2404. ['路灯工程', ld],
  2405. ['钢筋工程', gj],
  2406. ['拆除工程', cc],
  2407. ['其他', total - tsf - dl - qh - sd - gw - scl - lj - ld - gj - cc ],
  2408. ]
  2409. elif query == "园林绿化工程":
  2410. lh = 0
  2411. yl = 0
  2412. jg = 0
  2413. total = 0
  2414. regex_pattern1 = re.compile("^05", re.IGNORECASE)
  2415. regex_pattern2 = re.compile("^0501", re.IGNORECASE)
  2416. regex_pattern3 = re.compile("^0502", re.IGNORECASE)
  2417. regex_pattern4 = re.compile("^0503", re.IGNORECASE)
  2418. total = await collection.count_documents({'清单编码': regex_pattern1})
  2419. lh = await collection.count_documents({'清单编码': regex_pattern2})
  2420. yl = await collection.count_documents({'清单编码': regex_pattern3})
  2421. jg = await collection.count_documents({'清单编码': regex_pattern4})
  2422. return [
  2423. ["工程类别", "清单数"],
  2424. ['绿化工程', lh],
  2425. ['园路、园桥', yl],
  2426. ['园林景观', jg],
  2427. ['其他', total - lh - yl - jg ],
  2428. ]
  2429. elif query == "仿古建筑":
  2430. zz = 0
  2431. sz = 0
  2432. ll = 0
  2433. hnt = 0
  2434. mz = 0
  2435. dm = 0
  2436. mh = 0
  2437. yq = 0
  2438. total = 0
  2439. regex_pattern1 = re.compile("^02", re.IGNORECASE)
  2440. regex_pattern2 = re.compile("^0201", re.IGNORECASE)
  2441. regex_pattern3 = re.compile("^0202", re.IGNORECASE)
  2442. regex_pattern4 = re.compile("^0203", re.IGNORECASE)
  2443. regex_pattern5 = re.compile("^0204", re.IGNORECASE)
  2444. regex_pattern6 = re.compile("^0205", re.IGNORECASE)
  2445. regex_pattern7 = re.compile("^0206", re.IGNORECASE)
  2446. regex_pattern8 = re.compile("^0207", re.IGNORECASE)
  2447. regex_pattern9 = re.compile("^0208", re.IGNORECASE)
  2448. regex_pattern10 = re.compile("^0209", re.IGNORECASE)
  2449. total = await collection.count_documents({'清单编码': regex_pattern1})
  2450. zz = await collection.count_documents({'清单编码': regex_pattern2})
  2451. sz = await collection.count_documents({'清单编码': regex_pattern3})
  2452. ll = await collection.count_documents({'清单编码': regex_pattern4})
  2453. hnt = await collection.count_documents({'清单编码': regex_pattern5})
  2454. mz = await collection.count_documents({'清单编码': regex_pattern6})
  2455. wm = await collection.count_documents({'清单编码': regex_pattern7})
  2456. dm = await collection.count_documents({'清单编码': regex_pattern8})
  2457. mh = await collection.count_documents({'清单编码': regex_pattern9})
  2458. yq = await collection.count_documents({'清单编码': regex_pattern10})
  2459. return [
  2460. ["工程类别", "清单数"],
  2461. ['砖作工程', zz],
  2462. ['石作工程', sz],
  2463. ['琉璃砌筑', ll],
  2464. ['(钢筋)混凝土', hnt],
  2465. ['木作工程', mz],
  2466. ['屋面工程', wm],
  2467. ['地面工程', dm],
  2468. ['抹灰工程', mh],
  2469. ['油漆彩画', yq],
  2470. ['其他', total - zz - sz - ll - hnt - mz - wm - dm - mh - yq ],
  2471. ]
  2472. async def frequency(client, type, query):
  2473. db = client["baojia"]
  2474. collection = db["qdxm"]
  2475. output = []
  2476. if type == '安装工程':
  2477. if query == "电气设备":
  2478. pipeline = [
  2479. {"$match":
  2480. {"清单编码": re.compile("^0304", re.IGNORECASE)},
  2481. },
  2482. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  2483. "名称" : 1}
  2484. },
  2485. {
  2486. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  2487. },
  2488. {
  2489. "$sort" : { "totalQuantity": -1 }
  2490. },
  2491. {"$limit" : 10}
  2492. ]
  2493. result = await collection.aggregate(pipeline)
  2494. async for item in result:
  2495. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", ""), "数量" : item["totalQuantity"]})
  2496. elif query == "机械设备":
  2497. pipeline = [
  2498. {"$match":
  2499. {"清单编码": re.compile("^0301", re.IGNORECASE)},
  2500. },
  2501. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  2502. "名称" : 1}
  2503. },
  2504. {
  2505. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  2506. },
  2507. {
  2508. "$sort" : { "totalQuantity": -1 }
  2509. },
  2510. {"$limit" : 10}
  2511. ]
  2512. result = await collection.aggregate(pipeline)
  2513. async for item in result:
  2514. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", ""), "数量" : item["totalQuantity"]})
  2515. elif query == "热力设备":
  2516. pipeline = [
  2517. {"$match":
  2518. {"清单编码": re.compile("^0302", re.IGNORECASE)},
  2519. },
  2520. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  2521. "名称" : 1}
  2522. },
  2523. {
  2524. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  2525. },
  2526. {
  2527. "$sort" : { "totalQuantity": -1 }
  2528. },
  2529. {"$limit" : 10}
  2530. ]
  2531. result = await collection.aggregate(pipeline)
  2532. async for item in result:
  2533. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", ""), "数量" : item["totalQuantity"]})
  2534. elif query == "静置设备、金属结构":
  2535. pipeline = [
  2536. {"$match":
  2537. {"清单编码": re.compile("^0303", re.IGNORECASE)},
  2538. },
  2539. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  2540. "名称" : 1}
  2541. },
  2542. {
  2543. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  2544. },
  2545. {
  2546. "$sort" : { "totalQuantity": -1 }
  2547. },
  2548. {"$limit" : 10}
  2549. ]
  2550. result = await collection.aggregate(pipeline)
  2551. async for item in result:
  2552. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", ""), "数量" : item["totalQuantity"]})
  2553. elif query == "智能化":
  2554. pipeline = [
  2555. {"$match":
  2556. {"清单编码": re.compile("^0305", re.IGNORECASE)},
  2557. },
  2558. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  2559. "名称" : 1}
  2560. },
  2561. {
  2562. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  2563. },
  2564. {
  2565. "$sort" : { "totalQuantity": -1 }
  2566. },
  2567. {"$limit" : 10}
  2568. ]
  2569. result = await collection.aggregate(pipeline)
  2570. async for item in result:
  2571. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", ""), "数量" : item["totalQuantity"]})
  2572. elif query == "仪表安装":
  2573. pipeline = [
  2574. {"$match":
  2575. {"清单编码": re.compile("^0306", re.IGNORECASE)},
  2576. },
  2577. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  2578. "名称" : 1}
  2579. },
  2580. {
  2581. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  2582. },
  2583. {
  2584. "$sort" : { "totalQuantity": -1 }
  2585. },
  2586. {"$limit" : 10}
  2587. ]
  2588. result = await collection.aggregate(pipeline)
  2589. async for item in result:
  2590. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", ""), "数量" : item["totalQuantity"]})
  2591. elif query == "通风空调":
  2592. pipeline = [
  2593. {"$match":
  2594. {"清单编码": re.compile("^0307", re.IGNORECASE)},
  2595. },
  2596. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  2597. "名称" : 1}
  2598. },
  2599. {
  2600. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  2601. },
  2602. {
  2603. "$sort" : { "totalQuantity": -1 }
  2604. },
  2605. {"$limit" : 10}
  2606. ]
  2607. result = await collection.aggregate(pipeline)
  2608. async for item in result:
  2609. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", ""), "数量" : item["totalQuantity"]})
  2610. elif query == "工业管道":
  2611. pipeline = [
  2612. {"$match":
  2613. {"清单编码": re.compile("^0308", re.IGNORECASE)},
  2614. },
  2615. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  2616. "名称" : 1}
  2617. },
  2618. {
  2619. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  2620. },
  2621. {
  2622. "$sort" : { "totalQuantity": -1 }
  2623. },
  2624. {"$limit" : 10}
  2625. ]
  2626. result = await collection.aggregate(pipeline)
  2627. async for item in result:
  2628. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", ""), "数量" : item["totalQuantity"]})
  2629. elif query == "消防工程":
  2630. pipeline = [
  2631. {"$match":
  2632. {"清单编码": re.compile("^0309", re.IGNORECASE)},
  2633. },
  2634. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  2635. "名称" : 1}
  2636. },
  2637. {
  2638. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  2639. },
  2640. {
  2641. "$sort" : { "totalQuantity": -1 }
  2642. },
  2643. {"$limit" : 10}
  2644. ]
  2645. result = await collection.aggregate(pipeline)
  2646. async for item in result:
  2647. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", ""), "数量" : item["totalQuantity"]})
  2648. elif query == "给排水、采暖、燃气":
  2649. pipeline = [
  2650. {"$match":
  2651. {"清单编码": re.compile("^0310", re.IGNORECASE)},
  2652. },
  2653. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  2654. "名称" : 1}
  2655. },
  2656. {
  2657. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  2658. },
  2659. {
  2660. "$sort" : { "totalQuantity": -1 }
  2661. },
  2662. {"$limit" : 10}
  2663. ]
  2664. result = await collection.aggregate(pipeline)
  2665. async for item in result:
  2666. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", ""), "数量" : item["totalQuantity"]})
  2667. elif query == "通信设备":
  2668. pipeline = [
  2669. {"$match":
  2670. {"清单编码": re.compile("^0311", re.IGNORECASE)},
  2671. },
  2672. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  2673. "名称" : 1}
  2674. },
  2675. {
  2676. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  2677. },
  2678. {
  2679. "$sort" : { "totalQuantity": -1 }
  2680. },
  2681. {"$limit" : 10}
  2682. ]
  2683. result = await collection.aggregate(pipeline)
  2684. async for item in result:
  2685. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", ""), "数量" : item["totalQuantity"]})
  2686. elif query == "刷油、防腐蚀、绝热":
  2687. pipeline = [
  2688. {"$match":
  2689. {"清单编码": re.compile("^0312", re.IGNORECASE)},
  2690. },
  2691. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  2692. "名称" : 1}
  2693. },
  2694. {
  2695. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  2696. },
  2697. {
  2698. "$sort" : { "totalQuantity": -1 }
  2699. },
  2700. {"$limit" : 10}
  2701. ]
  2702. result = await collection.aggregate(pipeline)
  2703. async for item in result:
  2704. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", ""), "数量" : item["totalQuantity"]})
  2705. elif query == "其他":
  2706. pipeline = [
  2707. {"$match":
  2708. {"清单编码": re.compile("^0313", re.IGNORECASE)},
  2709. },
  2710. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  2711. "名称" : 1}
  2712. },
  2713. {
  2714. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  2715. },
  2716. {
  2717. "$sort" : { "totalQuantity": -1 }
  2718. },
  2719. {"$limit" : 10}
  2720. ]
  2721. result = await collection.aggregate(pipeline)
  2722. async for item in result:
  2723. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", ""), "数量" : item["totalQuantity"]})
  2724. elif type == "建筑与装饰工程":
  2725. if query == "(钢筋)混凝土":
  2726. pipeline = [
  2727. {"$match":
  2728. {"清单编码": re.compile("^0105", re.IGNORECASE)},
  2729. },
  2730. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  2731. "名称" : 1}
  2732. },
  2733. {
  2734. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  2735. },
  2736. {
  2737. "$sort" : { "totalQuantity": -1 }
  2738. },
  2739. {"$limit" : 10}
  2740. ]
  2741. result = await collection.aggregate(pipeline)
  2742. async for item in result:
  2743. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", ""), "数量" : item["totalQuantity"]})
  2744. elif query == "金属结构":
  2745. pipeline = [
  2746. {"$match":
  2747. {"清单编码": re.compile("^0106", re.IGNORECASE)},
  2748. },
  2749. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  2750. "名称" : 1}
  2751. },
  2752. {
  2753. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  2754. },
  2755. {
  2756. "$sort" : { "totalQuantity": -1 }
  2757. },
  2758. {"$limit" : 10}
  2759. ]
  2760. result = await collection.aggregate(pipeline)
  2761. async for item in result:
  2762. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", "").replace("(屋面)", ""), "数量" : item["totalQuantity"]})
  2763. elif query == "土石方工程":
  2764. pipeline = [
  2765. {"$match":
  2766. {"清单编码": re.compile("^0101", re.IGNORECASE)},
  2767. },
  2768. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  2769. "名称" : 1}
  2770. },
  2771. {
  2772. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  2773. },
  2774. {
  2775. "$sort" : { "totalQuantity": -1 }
  2776. },
  2777. {"$limit" : 10}
  2778. ]
  2779. result = await collection.aggregate(pipeline)
  2780. async for item in result:
  2781. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", "").replace("(屋面)", ""), "数量" : item["totalQuantity"]})
  2782. elif query == "桩基工程":
  2783. pipeline = [
  2784. {"$match":
  2785. {"清单编码": re.compile("^0103", re.IGNORECASE)},
  2786. },
  2787. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  2788. "名称" : 1}
  2789. },
  2790. {
  2791. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  2792. },
  2793. {
  2794. "$sort" : { "totalQuantity": -1 }
  2795. },
  2796. {"$limit" : 10}
  2797. ]
  2798. result = await collection.aggregate(pipeline)
  2799. async for item in result:
  2800. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", "").replace("(屋面)", ""), "数量" : item["totalQuantity"]})
  2801. elif query == "砌筑工程":
  2802. pipeline = [
  2803. {"$match":
  2804. {"清单编码": re.compile("^0104", re.IGNORECASE)},
  2805. },
  2806. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  2807. "名称" : 1}
  2808. },
  2809. {
  2810. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  2811. },
  2812. {
  2813. "$sort" : { "totalQuantity": -1 }
  2814. },
  2815. {"$limit" : 10}
  2816. ]
  2817. result = await collection.aggregate(pipeline)
  2818. async for item in result:
  2819. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", "").replace("(屋面)", ""), "数量" : item["totalQuantity"]})
  2820. elif query == "门窗工程":
  2821. pipeline = [
  2822. {"$match":
  2823. {"清单编码": re.compile("^0108", re.IGNORECASE)},
  2824. },
  2825. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  2826. "名称" : 1}
  2827. },
  2828. {
  2829. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  2830. },
  2831. {
  2832. "$sort" : { "totalQuantity": -1 }
  2833. },
  2834. {"$limit" : 10}
  2835. ]
  2836. result = await collection.aggregate(pipeline)
  2837. async for item in result:
  2838. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", "").replace("(屋面)", ""), "数量" : item["totalQuantity"]})
  2839. elif query == "屋面及防水工程":
  2840. pipeline = [
  2841. {"$match":
  2842. {"清单编码": re.compile("^0109", re.IGNORECASE)},
  2843. },
  2844. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  2845. "名称" : 1}
  2846. },
  2847. {
  2848. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  2849. },
  2850. {
  2851. "$sort" : { "totalQuantity": -1 }
  2852. },
  2853. {"$limit" : 10}
  2854. ]
  2855. result = await collection.aggregate(pipeline)
  2856. async for item in result:
  2857. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", "").replace("(屋面)", ""), "数量" : item["totalQuantity"]})
  2858. elif query == "楼地面":
  2859. pipeline = [
  2860. {"$match":
  2861. {"清单编码": re.compile("^0110", re.IGNORECASE)},
  2862. },
  2863. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  2864. "名称" : 1}
  2865. },
  2866. {
  2867. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  2868. },
  2869. {
  2870. "$sort" : { "totalQuantity": -1 }
  2871. },
  2872. {"$limit" : 10}
  2873. ]
  2874. result = await collection.aggregate(pipeline)
  2875. async for item in result:
  2876. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", "").replace("(屋面)", ""), "数量" : item["totalQuantity"]})
  2877. elif query == "墙、柱面":
  2878. pipeline = [
  2879. {"$match":
  2880. {"清单编码": re.compile("^0112", re.IGNORECASE)},
  2881. },
  2882. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  2883. "名称" : 1}
  2884. },
  2885. {
  2886. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  2887. },
  2888. {
  2889. "$sort" : { "totalQuantity": -1 }
  2890. },
  2891. {"$limit" : 10}
  2892. ]
  2893. result = await collection.aggregate(pipeline)
  2894. async for item in result:
  2895. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", "").replace("(屋面)", ""), "数量" : item["totalQuantity"]})
  2896. elif query == "天棚工程":
  2897. pipeline = [
  2898. {"$match":
  2899. {"清单编码": re.compile("^0113", re.IGNORECASE)},
  2900. },
  2901. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  2902. "名称" : 1}
  2903. },
  2904. {
  2905. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  2906. },
  2907. {
  2908. "$sort" : { "totalQuantity": -1 }
  2909. },
  2910. {"$limit" : 10}
  2911. ]
  2912. result = await collection.aggregate(pipeline)
  2913. async for item in result:
  2914. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", "").replace("(屋面)", ""), "数量" : item["totalQuantity"]})
  2915. elif query == "油漆、涂料、裱糊":
  2916. pipeline = [
  2917. {"$match":
  2918. {"清单编码": re.compile("^0114", re.IGNORECASE)},
  2919. },
  2920. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  2921. "名称" : 1}
  2922. },
  2923. {
  2924. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  2925. },
  2926. {
  2927. "$sort" : { "totalQuantity": -1 }
  2928. },
  2929. {"$limit" : 10}
  2930. ]
  2931. result = await collection.aggregate(pipeline)
  2932. async for item in result:
  2933. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", "").replace("(屋面)", ""), "数量" : item["totalQuantity"]})
  2934. elif query == "其他":
  2935. pipeline = [
  2936. {"$match":
  2937. {"清单编码": re.compile("^(0102|0107|0110|0115|0116|0117|0118)", re.IGNORECASE)},
  2938. },
  2939. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  2940. "名称" : 1}
  2941. },
  2942. {
  2943. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  2944. },
  2945. {
  2946. "$sort" : { "totalQuantity": -1 }
  2947. },
  2948. {"$limit" : 10}
  2949. ]
  2950. result = await collection.aggregate(pipeline)
  2951. async for item in result:
  2952. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", "").replace("(屋面)", ""), "数量" : item["totalQuantity"]})
  2953. elif type == "市政工程":
  2954. if query == "管网工程":
  2955. pipeline = [
  2956. {"$match":
  2957. {"清单编码": re.compile("^0405", re.IGNORECASE)},
  2958. },
  2959. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  2960. "名称" : 1}
  2961. },
  2962. {
  2963. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  2964. },
  2965. {
  2966. "$sort" : { "totalQuantity": -1 }
  2967. },
  2968. {"$limit" : 10}
  2969. ]
  2970. result = await collection.aggregate(pipeline)
  2971. async for item in result:
  2972. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", ""), "数量" : item["totalQuantity"]})
  2973. elif query == "道路工程":
  2974. pipeline = [
  2975. {"$match":
  2976. {"清单编码": re.compile("^0402", re.IGNORECASE)},
  2977. },
  2978. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  2979. "名称" : 1}
  2980. },
  2981. {
  2982. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  2983. },
  2984. {
  2985. "$sort" : { "totalQuantity": -1 }
  2986. },
  2987. {"$limit" : 10}
  2988. ]
  2989. result = await collection.aggregate(pipeline)
  2990. async for item in result:
  2991. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", ""), "数量" : item["totalQuantity"]})
  2992. elif query == "土石方":
  2993. pipeline = [
  2994. {"$match":
  2995. {"清单编码": re.compile("^0401", re.IGNORECASE)},
  2996. },
  2997. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  2998. "名称" : 1}
  2999. },
  3000. {
  3001. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  3002. },
  3003. {
  3004. "$sort" : { "totalQuantity": -1 }
  3005. },
  3006. {"$limit" : 10}
  3007. ]
  3008. result = await collection.aggregate(pipeline)
  3009. async for item in result:
  3010. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", ""), "数量" : item["totalQuantity"]})
  3011. elif query == "路灯工程":
  3012. pipeline = [
  3013. {"$match":
  3014. {"清单编码": re.compile("^0408", re.IGNORECASE)},
  3015. },
  3016. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  3017. "名称" : 1}
  3018. },
  3019. {
  3020. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  3021. },
  3022. {
  3023. "$sort" : { "totalQuantity": -1 }
  3024. },
  3025. {"$limit" : 10}
  3026. ]
  3027. result = await collection.aggregate(pipeline)
  3028. async for item in result:
  3029. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", ""), "数量" : item["totalQuantity"]})
  3030. elif query == "拆除工程":
  3031. pipeline = [
  3032. {"$match":
  3033. {"清单编码": re.compile("^0410", re.IGNORECASE)},
  3034. },
  3035. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  3036. "名称" : 1}
  3037. },
  3038. {
  3039. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  3040. },
  3041. {
  3042. "$sort" : { "totalQuantity": -1 }
  3043. },
  3044. {"$limit" : 10}
  3045. ]
  3046. result = await collection.aggregate(pipeline)
  3047. async for item in result:
  3048. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", ""), "数量" : item["totalQuantity"]})
  3049. elif query == "桥涵工程":
  3050. pipeline = [
  3051. {"$match":
  3052. {"清单编码": re.compile("^0403", re.IGNORECASE)},
  3053. },
  3054. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  3055. "名称" : 1}
  3056. },
  3057. {
  3058. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  3059. },
  3060. {
  3061. "$sort" : { "totalQuantity": -1 }
  3062. },
  3063. {"$limit" : 10}
  3064. ]
  3065. result = await collection.aggregate(pipeline)
  3066. async for item in result:
  3067. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", ""), "数量" : item["totalQuantity"]})
  3068. elif query == "隧道工程":
  3069. pipeline = [
  3070. {"$match":
  3071. {"清单编码": re.compile("^0404", re.IGNORECASE)},
  3072. },
  3073. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  3074. "名称" : 1}
  3075. },
  3076. {
  3077. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  3078. },
  3079. {
  3080. "$sort" : { "totalQuantity": -1 }
  3081. },
  3082. {"$limit" : 10}
  3083. ]
  3084. result = await collection.aggregate(pipeline)
  3085. async for item in result:
  3086. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", ""), "数量" : item["totalQuantity"]})
  3087. elif query == "水处理":
  3088. pipeline = [
  3089. {"$match":
  3090. {"清单编码": re.compile("^0406", re.IGNORECASE)},
  3091. },
  3092. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  3093. "名称" : 1}
  3094. },
  3095. {
  3096. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  3097. },
  3098. {
  3099. "$sort" : { "totalQuantity": -1 }
  3100. },
  3101. {"$limit" : 10}
  3102. ]
  3103. result = await collection.aggregate(pipeline)
  3104. async for item in result:
  3105. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", ""), "数量" : item["totalQuantity"]})
  3106. elif query == "垃圾处理":
  3107. pipeline = [
  3108. {"$match":
  3109. {"清单编码": re.compile("^0407", re.IGNORECASE)},
  3110. },
  3111. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  3112. "名称" : 1}
  3113. },
  3114. {
  3115. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  3116. },
  3117. {
  3118. "$sort" : { "totalQuantity": -1 }
  3119. },
  3120. {"$limit" : 10}
  3121. ]
  3122. result = await collection.aggregate(pipeline)
  3123. async for item in result:
  3124. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", ""), "数量" : item["totalQuantity"]})
  3125. elif query == "钢筋工程":
  3126. pipeline = [
  3127. {"$match":
  3128. {"清单编码": re.compile("^0409", re.IGNORECASE)},
  3129. },
  3130. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  3131. "名称" : 1}
  3132. },
  3133. {
  3134. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  3135. },
  3136. {
  3137. "$sort" : { "totalQuantity": -1 }
  3138. },
  3139. {"$limit" : 10}
  3140. ]
  3141. result = await collection.aggregate(pipeline)
  3142. async for item in result:
  3143. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", ""), "数量" : item["totalQuantity"]})
  3144. elif query == "其他":
  3145. pipeline = [
  3146. {"$match":
  3147. {"清单编码": re.compile("^(0411|0413)", re.IGNORECASE)},
  3148. },
  3149. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  3150. "名称" : 1}
  3151. },
  3152. {
  3153. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  3154. },
  3155. {
  3156. "$sort" : { "totalQuantity": -1 }
  3157. },
  3158. {"$limit" : 10}
  3159. ]
  3160. result = await collection.aggregate(pipeline)
  3161. async for item in result:
  3162. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", ""), "数量" : item["totalQuantity"]})
  3163. elif type == "园林绿化工程":
  3164. if query == '绿化工程':
  3165. pipeline = [
  3166. {"$match":
  3167. {"清单编码": re.compile("^0501", re.IGNORECASE)},
  3168. },
  3169. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  3170. "名称" : 1}
  3171. },
  3172. {
  3173. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  3174. },
  3175. {
  3176. "$sort" : { "totalQuantity": -1 }
  3177. },
  3178. {"$limit" : 10}
  3179. ]
  3180. result = await collection.aggregate(pipeline)
  3181. async for item in result:
  3182. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", ""), "数量" : item["totalQuantity"]})
  3183. elif query == '园路、园桥':
  3184. pipeline = [
  3185. {"$match":
  3186. {"清单编码": re.compile("^0502", re.IGNORECASE)},
  3187. },
  3188. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  3189. "名称" : 1}
  3190. },
  3191. {
  3192. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  3193. },
  3194. {
  3195. "$sort" : { "totalQuantity": -1 }
  3196. },
  3197. {"$limit" : 10}
  3198. ]
  3199. result = await collection.aggregate(pipeline)
  3200. async for item in result:
  3201. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", ""), "数量" : item["totalQuantity"]})
  3202. elif query == '园林景观':
  3203. pipeline = [
  3204. {"$match":
  3205. {"清单编码": re.compile("^0503", re.IGNORECASE)},
  3206. },
  3207. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  3208. "名称" : 1}
  3209. },
  3210. {
  3211. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  3212. },
  3213. {
  3214. "$sort" : { "totalQuantity": -1 }
  3215. },
  3216. {"$limit" : 10}
  3217. ]
  3218. result = await collection.aggregate(pipeline)
  3219. async for item in result:
  3220. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", ""), "数量" : item["totalQuantity"]})
  3221. elif query == '其他':
  3222. pipeline = [
  3223. {"$match":
  3224. {"清单编码": re.compile("^0504", re.IGNORECASE)},
  3225. },
  3226. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  3227. "名称" : 1}
  3228. },
  3229. {
  3230. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  3231. },
  3232. {
  3233. "$sort" : { "totalQuantity": -1 }
  3234. },
  3235. {"$limit" : 10}
  3236. ]
  3237. result = await collection.aggregate(pipeline)
  3238. async for item in result:
  3239. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", ""), "数量" : item["totalQuantity"]})
  3240. elif type == "仿古建筑":
  3241. if query == '砖作工程':
  3242. pipeline = [
  3243. {"$match":
  3244. {"清单编码": re.compile("^0201", re.IGNORECASE)},
  3245. },
  3246. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  3247. "名称" : 1}
  3248. },
  3249. {
  3250. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  3251. },
  3252. {
  3253. "$sort" : { "totalQuantity": -1 }
  3254. },
  3255. {"$limit" : 10}
  3256. ]
  3257. result = await collection.aggregate(pipeline)
  3258. async for item in result:
  3259. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", ""), "数量" : item["totalQuantity"]})
  3260. elif query == '石作工程':
  3261. pipeline = [
  3262. {"$match":
  3263. {"清单编码": re.compile("^0202", re.IGNORECASE)},
  3264. },
  3265. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  3266. "名称" : 1}
  3267. },
  3268. {
  3269. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  3270. },
  3271. {
  3272. "$sort" : { "totalQuantity": -1 }
  3273. },
  3274. {"$limit" : 10}
  3275. ]
  3276. result = await collection.aggregate(pipeline)
  3277. async for item in result:
  3278. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", ""), "数量" : item["totalQuantity"]})
  3279. elif query == '琉璃砌筑':
  3280. pipeline = [
  3281. {"$match":
  3282. {"清单编码": re.compile("^0203", re.IGNORECASE)},
  3283. },
  3284. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  3285. "名称" : 1}
  3286. },
  3287. {
  3288. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  3289. },
  3290. {
  3291. "$sort" : { "totalQuantity": -1 }
  3292. },
  3293. {"$limit" : 10}
  3294. ]
  3295. result = await collection.aggregate(pipeline)
  3296. async for item in result:
  3297. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", ""), "数量" : item["totalQuantity"]})
  3298. elif query == '(钢筋)混凝土':
  3299. pipeline = [
  3300. {"$match":
  3301. {"清单编码": re.compile("^0204", re.IGNORECASE)},
  3302. },
  3303. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  3304. "名称" : 1}
  3305. },
  3306. {
  3307. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  3308. },
  3309. {
  3310. "$sort" : { "totalQuantity": -1 }
  3311. },
  3312. {"$limit" : 10}
  3313. ]
  3314. result = await collection.aggregate(pipeline)
  3315. async for item in result:
  3316. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", ""), "数量" : item["totalQuantity"]})
  3317. elif query == '木作工程':
  3318. pipeline = [
  3319. {"$match":
  3320. {"清单编码": re.compile("^0205", re.IGNORECASE)},
  3321. },
  3322. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  3323. "名称" : 1}
  3324. },
  3325. {
  3326. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  3327. },
  3328. {
  3329. "$sort" : { "totalQuantity": -1 }
  3330. },
  3331. {"$limit" : 10}
  3332. ]
  3333. result = await collection.aggregate(pipeline)
  3334. async for item in result:
  3335. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", ""), "数量" : item["totalQuantity"]})
  3336. elif query == '屋面工程':
  3337. pipeline = [
  3338. {"$match":
  3339. {"清单编码": re.compile("^0206", re.IGNORECASE)},
  3340. },
  3341. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  3342. "名称" : 1}
  3343. },
  3344. {
  3345. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  3346. },
  3347. {
  3348. "$sort" : { "totalQuantity": -1 }
  3349. },
  3350. {"$limit" : 10}
  3351. ]
  3352. result = await collection.aggregate(pipeline)
  3353. async for item in result:
  3354. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", ""), "数量" : item["totalQuantity"]})
  3355. elif query == '地面工程':
  3356. pipeline = [
  3357. {"$match":
  3358. {"清单编码": re.compile("^0207", re.IGNORECASE)},
  3359. },
  3360. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  3361. "名称" : 1}
  3362. },
  3363. {
  3364. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  3365. },
  3366. {
  3367. "$sort" : { "totalQuantity": -1 }
  3368. },
  3369. {"$limit" : 10}
  3370. ]
  3371. result = await collection.aggregate(pipeline)
  3372. async for item in result:
  3373. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", ""), "数量" : item["totalQuantity"]})
  3374. elif query == '抹灰工程':
  3375. pipeline = [
  3376. {"$match":
  3377. {"清单编码": re.compile("^0208", re.IGNORECASE)},
  3378. },
  3379. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  3380. "名称" : 1}
  3381. },
  3382. {
  3383. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  3384. },
  3385. {
  3386. "$sort" : { "totalQuantity": -1 }
  3387. },
  3388. {"$limit" : 10}
  3389. ]
  3390. result = await collection.aggregate(pipeline)
  3391. async for item in result:
  3392. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", ""), "数量" : item["totalQuantity"]})
  3393. elif query == '油漆彩画':
  3394. pipeline = [
  3395. {"$match":
  3396. {"清单编码": re.compile("^0209", re.IGNORECASE)},
  3397. },
  3398. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  3399. "名称" : 1}
  3400. },
  3401. {
  3402. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  3403. },
  3404. {
  3405. "$sort" : { "totalQuantity": -1 }
  3406. },
  3407. {"$limit" : 10}
  3408. ]
  3409. result = await collection.aggregate(pipeline)
  3410. async for item in result:
  3411. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", ""), "数量" : item["totalQuantity"]})
  3412. elif query == '其他':
  3413. pipeline = [
  3414. {"$match":
  3415. {"清单编码": re.compile("^0210", re.IGNORECASE)},
  3416. },
  3417. {"$project" : {"code" : {"$substrCP": [ "$清单编码", 0, 9 ]},
  3418. "名称" : 1}
  3419. },
  3420. {
  3421. "$group": { "_id": "$code", "totalQuantity": { "$count": {} }, "name" : {"$first": "$名称"}}
  3422. },
  3423. {
  3424. "$sort" : { "totalQuantity": -1 }
  3425. },
  3426. {"$limit" : 10}
  3427. ]
  3428. result = await collection.aggregate(pipeline)
  3429. async for item in result:
  3430. output.append({"id" : item["_id"], "清单编码": item["_id"], "名称" : item['name'].replace("(超高)", ""), "数量" : item["totalQuantity"]})
  3431. return output