db.py 170 KB

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