db.py 67 KB

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