db.py 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733
  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. Fywj = ET.SubElement(Dwgcxx, 'Fywj')
  497. for bjhz_ in bjhz:
  498. FywjMx = ET.SubElement(Fywj, 'FywjMx')
  499. FywjMx.set('Xh', str(bjhz_[0]))
  500. FywjMx.set('Mc', str(bjhz_[1]))
  501. FywjMx.set('Je', str(bjhz_[2]))
  502. FywjMx.set('Zgj', str(bjhz_[3]))
  503. FywjMx.set('Fyxlb', str(bjhz_[4]))
  504. Gfsj = ET.SubElement(Dwgcxx, 'Gfsj')
  505. for gfsj_ in gfsj:
  506. GfsjMx = ET.SubElement(Gfsj, 'GfsjMx')
  507. GfsjMx.set('Xh', str(gfsj_[0]))
  508. GfsjMx.set('Mc', str(gfsj_[1]))
  509. GfsjMx.set('Qfjs', str(gfsj_[2]))
  510. GfsjMx.set('Jsjc', str(gfsj_[3]))
  511. GfsjMx.set('Fl', str(gfsj_[4]))
  512. GfsjMx.set('Je', str(gfsj_[5]))
  513. GfsjMx.set('Fyxlb', str(gfsj_[6]))
  514. Csxm = ET.SubElement(Dwgcxx, 'Csxm')
  515. ZjCs = ET.SubElement(Csxm, 'ZjCs')
  516. for zjcs_ in zjcs:
  517. ZjCsMx = ET.SubElement(ZjCs, 'ZjCsMx')
  518. ZjCsMx.set('Xh', str(zjcs_['序号']))
  519. ZjCsMx.set('Bm', str(zjcs_['清单编码']))
  520. ZjCsMx.set('Mc', str(zjcs_['名称']))
  521. ZjCsMx.set('Js', str(zjcs_['计算基数']))
  522. ZjCsMx.set('Jsjc', str(zjcs_['计算基础']))
  523. ZjCsMx.set('Fl', str(zjcs_['费率']))
  524. ZjCsMx.set('Je', str(zjcs_['金额']))
  525. ZjCsMx.set('Xmlb', str(zjcs_['项目类别']))
  526. if '__children' in zjcs_:
  527. AqwmfMx = ET.SubElement(ZjCsMx, 'AqwmfMx')
  528. AqwmfMx.set('Mc', str(zjcs_['__children'][0]['名称']))
  529. AqwmfMx.set('Js', str(zjcs_['__children'][0]['计算基数']))
  530. AqwmfMx.set('Jsjc', str(zjcs_['__children'][0]['计算基础']))
  531. AqwmfMx.set('Fl', str(zjcs_['__children'][0]['费率']))
  532. AqwmfMx.set('Je', str(zjcs_['__children'][0]['金额']))
  533. AqwmfMx.set('Xmlb', str(zjcs_['__children'][0]['项目类别']))
  534. AqwmfMx = ET.SubElement(ZjCsMx, 'AqwmfMx')
  535. AqwmfMx.set('Mc', str(zjcs_['__children'][1]['名称']))
  536. AqwmfMx.set('Js', str(zjcs_['__children'][1]['计算基数']))
  537. AqwmfMx.set('Jsjc', str(zjcs_['__children'][1]['计算基础']))
  538. AqwmfMx.set('Fl', str(zjcs_['__children'][1]['费率']))
  539. AqwmfMx.set('Je', str(zjcs_['__children'][1]['金额']))
  540. AqwmfMx.set('Xmlb', str(zjcs_['__children'][1]['项目类别']))
  541. AqwmfMx = ET.SubElement(ZjCsMx, 'AqwmfMx')
  542. AqwmfMx.set('Mc', str(zjcs_['__children'][2]['名称']))
  543. AqwmfMx.set('Js', str(zjcs_['__children'][2]['计算基数']))
  544. AqwmfMx.set('Jsjc', str(zjcs_['__children'][2]['计算基础']))
  545. AqwmfMx.set('Fl', str(zjcs_['__children'][2]['费率']))
  546. AqwmfMx.set('Je', str(zjcs_['__children'][2]['金额']))
  547. AqwmfMx.set('Xmlb', str(zjcs_['__children'][2]['项目类别']))
  548. DjCs = ET.SubElement(Csxm, 'DjCs')
  549. collection = db["Djcs"]
  550. before_sort = []
  551. async for post in collection.find({"biao_id": id, "Dwgcbh": entry['Dwgcbh']}):
  552. before_sort.append(post)
  553. after_sort = sorted(before_sort, key=lambda x: int(x['序号']))
  554. for djcs in after_sort:
  555. DjCsMx = ET.SubElement(DjCs, 'DjCsMx')
  556. DjCsMx.set('Xh', str(djcs['序号']))
  557. DjCsMx.set('Bm', str(djcs['清单编码']))
  558. DjCsMx.set('Mc', str(djcs['名称']))
  559. DjCsMx.set('Xmtz', str(djcs['项目特征']))
  560. DjCsMx.set('Jsgz', str(djcs['计算规则']))
  561. DjCsMx.set('Dw', str(djcs['单位']))
  562. DjCsMx.set('Sl', str(djcs['数量']))
  563. DjCsMx.set('Zhdj', str(djcs['综合单价']))
  564. DjCsMx.set('Zhhj', str(djcs['合价']))
  565. DjCsMx.set('Rgf', str(djcs['人工费']))
  566. DjCsMx.set('Zcf', str(djcs['主材费']))
  567. DjCsMx.set('Sbf', str(djcs['设备费']))
  568. DjCsMx.set('Fcf', str(djcs['辅材费']))
  569. DjCsMx.set('Clf', str(djcs['材料费']))
  570. DjCsMx.set('Jxf', str(djcs['机械费']))
  571. DjCsMx.set('Glf', str(djcs['管理费']))
  572. DjCsMx.set('Lr', str(djcs['利润']))
  573. DjCsMx.set('Zgj', str(djcs['暂估价']))
  574. DjCsMx.set('Zgr', str(djcs['综合人工工日']))
  575. Csxdezj = ET.SubElement(DjCsMx, 'Csxdezj')
  576. if '__children' in djcs:
  577. for child in djcs['__children']:
  578. CsxdezjMx = ET.SubElement(Csxdezj, 'CsxdezjMx')
  579. CsxdezjMx.set('Debm', str(child['清单编码']))
  580. CsxdezjMx.set('Mc', str(child['名称']))
  581. CsxdezjMx.set('Dw', str(child['单位']))
  582. CsxdezjMx.set('DwQdSl', str(child['数量']))
  583. CsxdezjMx.set('Dj', str(child['综合单价']))
  584. CsxdezjMx.set('Hj', str(child['合价']))
  585. CsxdezjMx.set('Rgf', str(child['人工费']))
  586. CsxdezjMx.set('Zcf', str(child['主材费']))
  587. CsxdezjMx.set('Sbf', str(child['设备费']))
  588. CsxdezjMx.set('Fcf', str(child['辅材费']))
  589. CsxdezjMx.set('Clf', str(child['材料费']))
  590. CsxdezjMx.set('Jxf', str(child['机械费']))
  591. CsxdezjMx.set('Glf', str(child['管理费']))
  592. CsxdezjMx.set('Lr', str(child['利润']))
  593. Csxdercjhl = ET.SubElement(CsxdezjMx, 'Csxdercjhl')
  594. for i in range(len(child['dercj'])):
  595. if i == 0:
  596. pass
  597. else:
  598. CsxdercjhlMx = ET.SubElement(Csxdercjhl, 'CsxdercjhlMx')
  599. CsxdercjhlMx.set('RcjId', str(child['dercj'][i][0]))
  600. CsxdercjhlMx.set('Rcjhl', str(child['dercj'][i][10]))
  601. CsxdercjhlMx.set('Rcjhj', str(child['dercj'][i][11]))
  602. Csxrcjhl = ET.SubElement(DjCsMx, 'Csxrcjhl')
  603. for i in range(len(djcs['rcj'])):
  604. if i == 0:
  605. pass
  606. else:
  607. CsxrcjhlMx = ET.SubElement(Csxrcjhl, 'CsxrcjhlMx')
  608. CsxrcjhlMx.set('RcjId', str(djcs['rcj'][i][0]))
  609. CsxrcjhlMx.set('Rcjhl', str(djcs['rcj'][i][10]))
  610. CsxrcjhlMx.set('Rcjhj', str(djcs['rcj'][i][11]))
  611. CsxrcjhlMx.set('Zgjbz', str(djcs['rcj'][i][12]))
  612. CsxrcjhlMx.set('Zyclbz', str(djcs['rcj'][i][13]))
  613. CsxrcjhlMx.set('Zcbz', str(djcs['rcj'][i][14]))
  614. CsxrcjhlMx.set('Sbbz', str(djcs['rcj'][i][15]))
  615. Qtxm = ET.SubElement(Dwgcxx, 'Qtxm')
  616. for qtxm_ in qtxm:
  617. QtxmMx = ET.SubElement(Qtxm, 'QtxmMx')
  618. QtxmMx.set('Xh', str(qtxm_[0]))
  619. QtxmMx.set('Mc', str(qtxm_[1]))
  620. QtxmMx.set('Je', str(qtxm_[2]))
  621. QtxmMx.set('Xmlb', str(qtxm_[3]))
  622. QtxmMx.set('Bz', str(qtxm_[4]))
  623. Zlje = ET.SubElement(Dwgcxx, 'Zlje')
  624. for i in range(len(zlje)):
  625. ZljeMx = ET.SubElement(Zlje, 'ZljeMx')
  626. ZljeMx.set('Xh', str(zlje[i]['序号']))
  627. ZljeMx.set('Mc', str(zlje[i]['名称']))
  628. ZljeMx.set('Dw', str(zlje[i]['单位']))
  629. ZljeMx.set('Zdje', str(zlje[i]['暂定金额']))
  630. ZljeMx.set('Bz', str(zlje[i]['备注']))
  631. Clzg = ET.SubElement(Dwgcxx, 'Clzg')
  632. Zygczg = ET.SubElement(Dwgcxx, 'Zygczg')
  633. for zygczgj_ in zygczgj:
  634. ZygczgMx = ET.SubElement(Zygczg, 'ZygczgMx')
  635. ZygczgMx.set('Xh', str(zygczgj_['序号']))
  636. ZygczgMx.set('Mc', str(zygczgj_['名称']))
  637. ZygczgMx.set('Gcnr', str(zygczgj_['工程内容']))
  638. ZygczgMx.set('Je', str(zygczgj_['金额']))
  639. ZygczgMx.set('Bz', str(zygczgj_['备注']))
  640. Jrg = ET.SubElement(Dwgcxx, 'Jrg')
  641. for jrg_ in jrg:
  642. JrgBt = ET.SubElement(Jrg, 'JrgBt')
  643. JrgBt.set('Xh', str(jrg_['序号']))
  644. JrgBt.set('Mc', str(jrg_['名称']))
  645. JrgBt.set('Je', str(jrg_['金额']))
  646. JrgBt.set('Lb', str(jrg_['类别']))
  647. Zcbfwf = ET.SubElement(Dwgcxx, 'Zcbfwf')
  648. for zcbfwf_ in zcbfwf:
  649. ZcbfwfMx = ET.SubElement(Zcbfwf, 'ZcbfwfMx')
  650. ZcbfwfMx.set('Xh', str(zcbfwf_['序号']))
  651. ZcbfwfMx.set('Mc', str(zcbfwf_['名称']))
  652. ZcbfwfMx.set('Xmjz', str(zcbfwf_['项目价值']))
  653. ZcbfwfMx.set('Fwnr', str(zcbfwf_['服务内容']))
  654. ZcbfwfMx.set('Jsjc', str(zcbfwf_['计算基础']))
  655. ZcbfwfMx.set('Fl', str(zcbfwf_['费率']))
  656. ZcbfwfMx.set('Je', str(zcbfwf_['金额']))
  657. Zjxmjdkzffj = ET.SubElement(Dwgcxx, 'Zjxmjdkzffj')
  658. Fbrgycl = ET.SubElement(Dwgcxx, 'Fbrgycl')
  659. for fbrgycl_ in fbrgycl:
  660. FbrgyclMx = ET.SubElement(Fbrgycl, 'FbrgyclMx')
  661. FbrgyclMx.set('Xh', str(fbrgycl_['序号']))
  662. FbrgyclMx.set('RcjId', str(fbrgycl_['ID']))
  663. FbrgyclMx.set('Clbh', str(fbrgycl_['材料编号']))
  664. FbrgyclMx.set('Mc', str(fbrgycl_['名称']))
  665. FbrgyclMx.set('Ggxh', str(fbrgycl_['规格型号']))
  666. FbrgyclMx.set('Dw', str(fbrgycl_['单位']))
  667. FbrgyclMx.set('Sl', str(fbrgycl_['数量']))
  668. FbrgyclMx.set('Dj', str(fbrgycl_['单价']))
  669. FbrgyclMx.set('Hj', str(fbrgycl_['合价']))
  670. FbrgyclMx.set('Jhfs', str(fbrgycl_['交货方式']))
  671. FbrgyclMx.set('Sddd', str(fbrgycl_['送达地点']))
  672. FbrgyclMx.set('Bz', str(fbrgycl_['备注']))
  673. Cbrgycl = ET.SubElement(Dwgcxx, 'Cbrgycl')
  674. Rcjhz = ET.SubElement(Dwgcxx, 'Rcjhz')
  675. for i in range(len(rcjhz)):
  676. if i == 0:
  677. pass
  678. else:
  679. RcjhzMx = ET.SubElement(Rcjhz, 'RcjhzMx')
  680. RcjhzMx.set('RcjId', str(rcjhz[i][0]))
  681. RcjhzMx.set('RcjBm', str(rcjhz[i][1]))
  682. RcjhzMx.set('Mc', str(rcjhz[i][2]))
  683. RcjhzMx.set('Ggxh', str(rcjhz[i][3]))
  684. RcjhzMx.set('Dw', str(rcjhz[i][4]))
  685. RcjhzMx.set('Sl', str(rcjhz[i][5]))
  686. RcjhzMx.set('Dj', str(rcjhz[i][6]))
  687. RcjhzMx.set('Hj', str(rcjhz[i][7]))
  688. RcjhzMx.set('Cd', str(rcjhz[i][8]))
  689. RcjhzMx.set('Gycs', str(rcjhz[i][9]))
  690. RcjhzMx.set('Rcjlb', str(rcjhz[i][10]))
  691. RcjhzMx.set('Zyclbz', str(rcjhz[i][11]))
  692. RcjhzMx.set('Zcbz', str(rcjhz[i][12]))
  693. RcjhzMx.set('Sbbz', str(rcjhz[i][13]))
  694. RcjhzMx.set('Jgbz', str(rcjhz[i][14]))
  695. RcjhzMx.set('Zgjbz', str(rcjhz[i][15]))
  696. async def delete_files(client, id):
  697. db = client["baojia"]
  698. collection = db["jingjibiao"]
  699. result = []
  700. await collection.update_one({'_id': ObjectId(id)}, {'$set': {'visible': False}})
  701. return result
  702. async def list_files(client):
  703. db = client["baojia"]
  704. collection = db["jingjibiao"]
  705. result = []
  706. async for post in collection.find({"visible": True}):
  707. result.append([str(post['_id']), post["Xmmc"], post['created'] if 'created' in post else ""])
  708. return result
  709. def getDwgc(id, Zylb):
  710. result = []
  711. #result.append(["ming cheng", "jin e", "zan gu jia", "anquan wenming fei", "guifei"])
  712. ##result.append([child.attrib["Dxgcmc"], child.attrib["Je"], child.attrib["Zgj"], child.attrib["Aqwmf"], child.attrib["Gf"]])
  713. id = id + "Zylb" + Zylb
  714. result.append({"id": id + "bao jia hui zong", "label": "报价汇总表"})
  715. result.append({"id": id + "gui fei shui jin", "label": "规费税金"})
  716. result.append({"id": id + "qing dan xiang mu", "label": "清单项目"})
  717. result.append({"id": id + "cuo shi xiang mu", "label": "措施项目"})
  718. result.append({"id": id +"qi ta xiang mu", "label": "其他项目"})
  719. result.append({"id": id +"zan lie jin e", "label": "暂列金额"})
  720. result.append({"id": id +"cai liao zan gu jia", "label": "材料暂估价"})
  721. result.append({"id": id + "zhuan ye gong cheng zan gu jia", "label": "专业工程暂估价"})
  722. result.append({"id": id + "ji ri gong", "label": "计日工"})
  723. result.append({"id": id + "zong cheng bao fu wu fei", "label": "总承包服务费"})
  724. result.append({"id": id + "zong jia xiang mu jin du kuan zhi fu fen jie", "label": "总价项目进度款支付分解"})
  725. result.append({"id": id + "fa bao ren gong ying cai liao", "label": "发包人供应材料"})
  726. result.append({"id": id + "cheng bao ren gong ying cai liao", "label": "承包人供应材料"})
  727. result.append({"id": id + "ren cai ji hui zong", "label": "人材机汇总"})
  728. return result
  729. async def getOutline(client, id):
  730. db = client["baojia"]
  731. collection = db["jingjibiao"]
  732. document = await collection.find_one({'_id': ObjectId(id)})
  733. result = []
  734. if 'TouBiaoXx' in document:
  735. result.append({"id" : "TouBiaoXx", "label" : "投标信息" })
  736. if 'Dxgcxx' in document:
  737. Dxgcxx = document["Dxgcxx"]
  738. for dxgc in Dxgcxx:
  739. result2 = []
  740. Dwgc = dxgc["Dwgc"]
  741. for grandchild in Dwgc:
  742. result2.append({"id" : grandchild['Dwgcbh'], "Zylb":grandchild['Zylb'], "label": grandchild["Dwgcmc"], "children" : getDwgc(grandchild['Dwgcbh'], grandchild['Zylb'])})
  743. result.append({"id" : dxgc['Dxgcbh'], "label" : dxgc['Dxgcmc'], "children" : result2})
  744. return result
  745. async def getDetail(client, id):
  746. db = client["baojia"]
  747. collection = db["jingjibiao"]
  748. document = await collection.find_one({'_id': ObjectId(id)})
  749. result = []
  750. ##result.append(["名称", "金额", "暂估价", "安全文明施工费", "规费"])
  751. if 'TouBiaoXx' in document:
  752. toubiaoxx = document["TouBiaoXx"]
  753. result.append({'名称': '投标总价', '金额' : toubiaoxx["Tbzj"], '暂估价': toubiaoxx["Zgj"], '安全文明施工费': toubiaoxx["Aqwmf"], '规费' : toubiaoxx["Gf"], '_children': []})
  754. if 'Dxgcxx' in document:
  755. Dxgcxx = document["Dxgcxx"]
  756. for dxgc in Dxgcxx:
  757. result[0]['_children'].append({'名称' :dxgc["Dxgcmc"], '金额' : dxgc["Je"], '暂估价' : dxgc["Zgj"],'安全文明施工费' : dxgc["Aqwmf"], '规费' : dxgc["Gf"]})
  758. return result
  759. else:
  760. if 'Dxgcxx' in document:
  761. Dxgcxx = document["Dxgcxx"]
  762. for dxgc in Dxgcxx:
  763. result.append({'名称' :dxgc["Dxgcmc"], '金额' : dxgc["Je"], '暂估价' : dxgc["Zgj"],'安全文明施工费' : dxgc["Aqwmf"], '规费' : dxgc["Gf"]})
  764. return result
  765. async def getBjhz(client, objectid, id):
  766. db = client["baojia"]
  767. collection = db["Dwgc"]
  768. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  769. return document['bjhz']
  770. async def getGfsj(client, objectid, id):
  771. db = client["baojia"]
  772. collection = db["Dwgc"]
  773. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  774. return document['gfsj']
  775. async def getQtxm(client, objectid, id):
  776. db = client["baojia"]
  777. collection = db["Dwgc"]
  778. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  779. return document['qtxm']
  780. async def getZygczgj(client, objectid, id):
  781. db = client["baojia"]
  782. collection = db["Dwgc"]
  783. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  784. return document['zygczgj']
  785. async def getZlje(client, objectid, id):
  786. db = client["baojia"]
  787. collection = db["Dwgc"]
  788. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  789. return document['zlje']
  790. async def getJrg(client, objectid, id):
  791. db = client["baojia"]
  792. collection = db["Dwgc"]
  793. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  794. return document['jrg']
  795. async def getZcbfwf(client, objectid, id):
  796. db = client["baojia"]
  797. collection = db["Dwgc"]
  798. document = await collection.find_one({"Dwgcbh": id, "biao_id": objectid})
  799. return document['zcbfwf']
  800. async def getFbrgycl(client, objectid, id):
  801. db = client["baojia"]
  802. collection = db["Dwgc"]
  803. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  804. return document['fbrgycl']
  805. async def getRcjhz(client, objectid, id):
  806. db = client["baojia"]
  807. collection = db["Dwgc"]
  808. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  809. return document['rcjhz']
  810. async def getZjcs(client, objectid, id):
  811. db = client["baojia"]
  812. collection = db["Dwgc"]
  813. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  814. return document['zjcs']
  815. async def getDjcs(client, objectid, id):
  816. db = client["baojia"]
  817. collection = db["Djcs"]
  818. result = []
  819. async for post in collection.find({"Dwgcbh": id, "biao_id": objectid}):
  820. ##post["ID"] = post["_id"]
  821. del post["_id"]
  822. ##print( post["rcj"])
  823. ## del post["DogNum"]
  824. result.append(post)
  825. return result
  826. async def getDjcsQingdanrcj(client, name, bh, bt, bm):
  827. db = client["baojia"]
  828. collection = db["Djcs"]
  829. document = await collection.find_one({ "Dwgcbh": bh, "清单编码": bm, "biao_id": name})
  830. result = document["rcj"]
  831. return result
  832. async def getDjcsDingercj(client, name, bh, bt, qdbm, debm):
  833. db = client["baojia"]
  834. collection = db["Djcs"]
  835. document = await collection.find_one({"Dwgcbh": bh, "清单编码": qdbm, "biao_id": name})
  836. children = document["__children"]
  837. result = []
  838. for child in children:
  839. if child["清单编码"] == debm:
  840. result = child["dercj"]
  841. return result
  842. async def getQdxm(client, name, bh):
  843. db = client["baojia"]
  844. collection = db["Dwgc"]
  845. document = await collection.find_one({'biao_id': name, "Dwgcbh": bh})
  846. if document:
  847. return document['qdbt']
  848. else:
  849. return []
  850. async def getQdmx(client, name, bh, bt):
  851. db = client["baojia"]
  852. collection = db["qdxm"]
  853. result = []
  854. async for post in collection.find({'biao_id': name, "Dwgcbh": bh, "bt": bt}):
  855. ##post["ID"] = post["_id"]
  856. del post["_id"]
  857. #del post["rcj"]
  858. #del post["DogNum"]
  859. result.append(post)
  860. return result
  861. async def getQingdanrcj(client, name, bh, bt, bm):
  862. db = client["baojia"]
  863. collection = db["qdxm"]
  864. document = await collection.find_one({ "Dwgcbh": bh, "清单编码": bm, "biao_id": name, "bt": bt})
  865. result = document["rcj"]
  866. return result
  867. async def getDingercj(client, name, bh, bt, qdbm, debm):
  868. db = client["baojia"]
  869. collection = db["qdxm"]
  870. document = await collection.find_one({"Dwgcbh": bh, "清单编码": qdbm, "biao_id": name, "bt": bt})
  871. result = []
  872. if "__children" in document:
  873. children = document["__children"]
  874. for child in children:
  875. if child["清单编码"] == debm:
  876. result = child["dercj"]
  877. return result
  878. async def getQufei(client, id):
  879. db = client["baojia"]
  880. collection = db["qufei"]
  881. document = await collection.find_one({'biao_id': id})
  882. return document['qufei']
  883. async def searchde(client, zhuanye, text):
  884. db = client["dinge"]
  885. collection = db["de-collection"]
  886. result = []
  887. async for post in collection.find({'$text': {"$search": "\"" + text + "\""}, "zhuanye": zhuanye}):
  888. result.append(post["DEBH"] + " " + post['GCLMC'] )
  889. if len(result) > 10:
  890. break
  891. return result
  892. ##################################editor##########################
  893. async def updatezjcs(client, id, bh, mc, fl):
  894. db = client["baojia"]
  895. collection = db["Dwgc"]
  896. document = await collection.find_one({'biao_id': id, 'Dwgcbh': bh}, {'rcjhz': 0})
  897. zjcs = document['zjcs']
  898. for entry in zjcs:
  899. if entry['名称'] == mc:
  900. entry['费率'] = fl
  901. entry['金额'] = str(float(entry['计算基数']) * float(fl) / float(100))
  902. await collection.update_one({'biao_id': id, "Dwgcbh": bh}, {'$set': {'zjcs': zjcs}})
  903. async def save(client, data):
  904. db = client["baojia"]
  905. collection = db["qdxm"]
  906. biao_id = None
  907. bh = None
  908. for entry in data:
  909. entry["__children"] = entry["_children"]
  910. del entry["_children"]
  911. biao_id = entry['biao_id']
  912. bh = entry['Dwgcbh']
  913. await collection.replace_one({"biao_id": entry["biao_id"], "Dwgcbh": entry["Dwgcbh"], "bt": entry["bt"], "清单编码": entry["清单编码"]}, entry)
  914. if not biao_id:
  915. return {"result" : "ok"}
  916. rcjhz = []
  917. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  918. qdrcj = post['rcj'][1:]
  919. for entry in qdrcj:
  920. entry[10] = float(entry[10]) * float(post['数量'])
  921. rcjhz = rcjhz + qdrcj
  922. collection = db["Djcs"]
  923. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  924. qdrcj = post['rcj'][1:]
  925. for entry in qdrcj:
  926. entry[10] = float(entry[10]) * float(post['数量'])
  927. rcjhz = rcjhz + qdrcj
  928. newHuizong = util.huizongrcj(rcjhz)
  929. collection = db["Dwgc"]
  930. await collection.update_one({'biao_id': biao_id, 'Dwgcbh': bh}, {'$set': {'rcjhz' : newHuizong}})
  931. await zongjiaDwgc(client, biao_id, bh)
  932. await tbxx(client, biao_id)
  933. return {"result": "ok"}
  934. async def savedjcs(client, data):
  935. db = client["baojia"]
  936. collection = db["Djcs"]
  937. biao_id = None
  938. bh = None
  939. for entry in data:
  940. entry["__children"] = entry["_children"]
  941. del entry["_children"]
  942. biao_id = entry['biao_id']
  943. bh = entry['Dwgcbh']
  944. await collection.replace_one({"biao_id": entry["biao_id"], "Dwgcbh": entry["Dwgcbh"], "清单编码": entry["清单编码"]}, entry)
  945. if not biao_id:
  946. return {"result" : "ok"}
  947. rcjhz = []
  948. collection = db["qdxm"]
  949. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  950. qdrcj = post['rcj'][1:]
  951. for entry in qdrcj:
  952. entry[10] = float(entry[10]) * float(post['数量'])
  953. rcjhz = rcjhz + qdrcj
  954. collection = db["Djcs"]
  955. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  956. qdrcj = post['rcj'][1:]
  957. for entry in qdrcj:
  958. entry[10] = float(entry[10]) * float(post['数量'])
  959. rcjhz = rcjhz + qdrcj
  960. newHuizong = util.huizongrcj(rcjhz)
  961. collection = db["Dwgc"]
  962. await collection.update_one({'biao_id': biao_id, 'Dwgcbh': bh}, {'$set': {'rcjhz' : newHuizong}})
  963. await zongjiaDwgc(client, biao_id, bh)
  964. await tbxx(client, biao_id)
  965. return {"result": "ok"}
  966. async def applyFL(client, id, data):
  967. db = client["baojia"]
  968. collection = db["qufei"]
  969. await collection.replace_one({"biao_id": id}, {"biao_id": id, "qufei": data})
  970. collection = db['qdxm']
  971. xm = data[0]
  972. for dxgc in xm["children"]:
  973. for dwgc in dxgc["children"]:
  974. bh = dwgc['key']
  975. glf = float(dwgc['管理费(%)'])
  976. lr = float(dwgc['利润(%)'])
  977. bz = dwgc['备注']
  978. ##print(bh+glf+lr+bz)
  979. async for post in collection.find({'biao_id': id, "Dwgcbh": bh}):
  980. rgfs = float(post['人工费'])
  981. clfs = float(post['材料费'])
  982. jxfs = float(post['机械费'])
  983. sl = float(post['数量'])
  984. if rgfs < 0.0001 and clfs < 0.0001 and jxfs < 0.0001:
  985. continue
  986. ##danxiang = False
  987. for child in post['__children']:##一条定额
  988. bm = child['清单编码']
  989. if bm.startswith("D"):
  990. ##danxiang = True
  991. continue
  992. rgf = float(child['人工费'])
  993. clf = float(child['材料费'])
  994. jxf = float(child['机械费'])
  995. zhdj = float(child['综合单价'])
  996. sl_ = float(child['数量'])
  997. if len(bz) == 0:
  998. ##常规计算
  999. child['管理费'] = (rgf + jxf) * glf / float(100)
  1000. child['利润'] = (rgf + jxf) * lr / float(100)
  1001. child['综合单价'] = rgf + clf + jxf + child['管理费'] + child['利润']
  1002. child['合价'] = sl * sl_ * child['综合单价']
  1003. else:
  1004. child['管理费'] = (rgf) * glf / float(100)
  1005. child['利润'] = (rgf) * lr / float(100)
  1006. child['综合单价'] = rgf + clf + jxf + child['管理费'] + child['利润']
  1007. child['合价'] = sl * sl_ * child['综合单价']
  1008. if True:
  1009. post['管理费'] = 0
  1010. post['利润'] = 0
  1011. for entry in post['__children']:
  1012. post['管理费'] = post['管理费'] + float(entry['管理费']) * float(entry['数量'])
  1013. post['利润'] = post['利润'] + float(entry['利润']) * float(entry['数量'])
  1014. post['管理费'] = str(post['管理费'])
  1015. post['利润'] = str(post['利润'])
  1016. post['综合单价'] = str(float(post['人工费']) + float(post['材料费']) + float(post['机械费']) + float(post['管理费']) + float(post['利润']))
  1017. post['合价'] = str(float(post['综合单价']) * float(post['数量']))
  1018. await collection.replace_one({'_id': post['_id']}, post )
  1019. collection = db['Djcs']
  1020. for dxgc in xm["children"]:
  1021. for dwgc in dxgc["children"]:
  1022. bh = dwgc['key']
  1023. glf = float(dwgc['管理费(%)'])
  1024. lr = float(dwgc['利润(%)'])
  1025. bz = dwgc['备注']
  1026. ##print(bh+glf+lr+bz)
  1027. async for post in collection.find({'biao_id': id, "Dwgcbh": bh}):
  1028. rgfs = float(post['人工费'])
  1029. clfs = float(post['材料费'])
  1030. jxfs = float(post['机械费'])
  1031. sl = float(post['数量'])
  1032. if rgfs < 0.0001 and clfs < 0.0001 and jxfs < 0.0001:
  1033. continue
  1034. ##danxiang = False##一般有单项定额的,清单就一条定额,就是这个单项定额
  1035. for child in post['__children']:
  1036. bm = child['清单编码']
  1037. if bm.startswith("D"):
  1038. ##danxiang = True
  1039. continue
  1040. rgf = float(child['人工费'])
  1041. clf = float(child['材料费'])
  1042. jxf = float(child['机械费'])
  1043. zhdj = float(child['综合单价'])
  1044. sl_ = float(child['数量'])
  1045. if len(bz) == 0:
  1046. ##常规计算
  1047. child['管理费'] = (rgf + jxf) * glf / float(100)
  1048. child['利润'] = (rgf + jxf) * lr / float(100)
  1049. child['综合单价'] = rgf + clf + jxf + child['管理费'] + child['利润']
  1050. child['合价'] = sl * sl_ * child['综合单价']
  1051. else:
  1052. child['管理费'] = (rgf) * glf / float(100)
  1053. child['利润'] = (rgf) * lr / float(100)
  1054. child['综合单价'] = rgf + clf + jxf + child['管理费'] + child['利润']
  1055. child['合价'] = sl * sl_ * child['综合单价']
  1056. if True:
  1057. post['管理费'] = 0
  1058. post['利润'] = 0
  1059. for entry in post['__children']:
  1060. post['管理费'] = post['管理费'] + float(entry['管理费']) * float(entry['数量'])
  1061. post['利润'] = post['利润'] + float(entry['利润']) * float(entry['数量'])
  1062. post['管理费'] = str(post['管理费'])
  1063. post['利润'] = str(post['利润'])
  1064. post['综合单价'] = str(float(post['人工费']) + float(post['材料费']) + float(post['机械费']) + float(post['管理费']) + float(post['利润']))
  1065. post['合价'] = str(float(post['综合单价']) * float(post['数量']))
  1066. await collection.replace_one({'_id': post['_id']}, post )
  1067. for dxgc in xm["children"]:
  1068. for dwgc in dxgc["children"]:
  1069. bh = dwgc['key']
  1070. await zongjiaDwgc(client, id, bh)
  1071. await tbxx(client, id)
  1072. return {"result": "ok"}
  1073. async def tiaojia(client, biao_id, bh, bm, mingcheng, danwei, jiage, glf, lr, bz):
  1074. db = client["baojia"]
  1075. collection = db["qdxm"]
  1076. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}):
  1077. if "__children" not in post:
  1078. ##print(post)
  1079. continue
  1080. children = post["__children"]
  1081. qdsl = post['数量']
  1082. hit = False
  1083. for entry in children:###对一条定额,调价
  1084. hitde = False
  1085. dercj = entry["dercj"]
  1086. dergf = 0
  1087. declf = 0
  1088. dejxf = 0
  1089. for i in range(1, len(dercj)):
  1090. rcj = dercj[i]
  1091. if rcj[1] == bm and rcj[2] == mingcheng and rcj[4] == danwei:
  1092. hit = True
  1093. hitde = True
  1094. rcj[5] = jiage
  1095. hanliang = rcj[10]
  1096. rcj[11] = str(float(jiage) * float(hanliang))
  1097. if int(rcj[8]) == 1:
  1098. dergf = dergf + float(rcj[11])
  1099. elif int(rcj[8]) == 2:
  1100. declf = declf + float(rcj[11])
  1101. elif int(rcj[8]) == 3:
  1102. dejxf = dejxf + float(rcj[11])
  1103. if hitde:
  1104. entry['人工费'] = str(dergf)
  1105. entry['辅材费'] = str(declf)
  1106. entry['材料费'] = str(declf)
  1107. entry['机械费'] = str(dejxf)
  1108. if bm.startswith("D"):
  1109. entry['管理费'] = '0'
  1110. entry['利润'] = '0'
  1111. elif bz == 0:
  1112. entry['管理费'] = str((dergf + dejxf) * float(glf) / float(100))
  1113. entry['利润'] = str((dergf + dejxf) * float(lr) / float(100))
  1114. else:
  1115. entry['管理费'] = str((dergf) * float(glf) / float(100))
  1116. entry['利润'] = str((dergf) * float(lr) / float(100))
  1117. entry['综合单价'] = str(float(entry['人工费']) + float(entry['材料费']) + float(entry['机械费']) + float(entry['管理费']) + float(entry['利润']))
  1118. entry['合价'] = str(float(entry['综合单价']) * float(entry['数量']) * float(qdsl))
  1119. if hit:
  1120. ##调整清单
  1121. qdrcj = post['rcj']
  1122. qdrgf = 0
  1123. qdclf = 0
  1124. qdjxf = 0
  1125. for i in range(1, len(qdrcj)):
  1126. entry = qdrcj[i]
  1127. if entry[1] == bm and entry[2] == mingcheng and entry[4] == danwei:
  1128. entry[5] = jiage
  1129. hanliang = entry[10]
  1130. entry[11] = str(float(jiage) * float(hanliang))
  1131. if int(entry[8]) == 1:
  1132. qdrgf = qdrgf + float(entry[11])
  1133. elif int(entry[8]) == 2:
  1134. qdclf = qdclf + float(entry[11])
  1135. elif int(entry[8]) == 3:
  1136. qdjxf = qdjxf + float(entry[11])
  1137. post['人工费'] = str(qdrgf)
  1138. post['辅材费'] = str(qdclf)
  1139. post['材料费'] = str(qdclf)
  1140. post['机械费'] = str(qdjxf)
  1141. post['管理费'] = 0
  1142. post['利润'] = 0
  1143. for entry in children:
  1144. post['管理费'] = post['管理费'] + float(entry['管理费']) * float(entry['数量'])
  1145. post['利润'] = post['利润'] + float(entry['利润']) * float(entry['数量'])
  1146. post['管理费'] = str(post['管理费'])
  1147. post['利润'] = str(post['利润'])
  1148. post['综合单价'] = str(float(post['人工费']) + float(post['材料费']) + float(post['机械费']) + float(post['管理费']) + float(post['利润']))
  1149. post['合价'] = str(float(post['综合单价']) * float(qdsl))
  1150. print(post)
  1151. await collection.replace_one({'_id': post['_id']}, post )
  1152. collection = db["Djcs"]
  1153. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}):
  1154. children = post["__children"]
  1155. qdsl = post['数量']
  1156. hit = False
  1157. for entry in children:###对一条定额,调价
  1158. hitde = False
  1159. dercj = entry["dercj"]
  1160. dergf = 0
  1161. declf = 0
  1162. dejxf = 0
  1163. for i in range(1, len(dercj)):
  1164. rcj = dercj[i]
  1165. if rcj[1] == bm and rcj[2] == mingcheng and rcj[4] == danwei:
  1166. hit = True
  1167. hitde = True
  1168. rcj[5] = jiage
  1169. hanliang = rcj[10]
  1170. rcj[11] = str(float(jiage) * float(hanliang))
  1171. if int(rcj[8]) == 1:
  1172. dergf = dergf + float(rcj[11])
  1173. elif int(rcj[8]) == 2:
  1174. declf = declf + float(rcj[11])
  1175. elif int(rcj[8]) == 3:
  1176. dejxf = dejxf + float(rcj[11])
  1177. if hitde:
  1178. entry['人工费'] = str(dergf)
  1179. entry['辅材费'] = str(declf)
  1180. entry['材料费'] = str(declf)
  1181. entry['机械费'] = str(dejxf)
  1182. if bm.startswith("D"):
  1183. entry['管理费'] = '0'
  1184. entry['利润'] = '0'
  1185. elif bz == 0:
  1186. entry['管理费'] = str((dergf + dejxf) * float(glf) / float(100))
  1187. entry['利润'] = str((dergf + dejxf) * float(lr) / float(100))
  1188. else:
  1189. entry['管理费'] = str((dergf) * float(glf) / float(100))
  1190. entry['利润'] = str((dergf) * float(lr) / float(100))
  1191. entry['综合单价'] = str(float(entry['人工费']) + float(entry['材料费']) + float(entry['机械费']) + float(entry['管理费']) + float(entry['利润']))
  1192. entry['合价'] = str(float(entry['综合单价']) * float(entry['数量']) * float(qdsl))
  1193. if hit:
  1194. ##调整清单
  1195. qdrcj = post['rcj']
  1196. qdrgf = 0
  1197. qdclf = 0
  1198. qdjxf = 0
  1199. for i in range(1, len(qdrcj)):
  1200. entry = qdrcj[i]
  1201. if entry[1] == bm and entry[2] == mingcheng and entry[4] == danwei:
  1202. entry[5] = jiage
  1203. hanliang = entry[10]
  1204. entry[11] = str(float(jiage) * float(hanliang))
  1205. if int(entry[8]) == 1:
  1206. qdrgf = qdrgf + float(entry[11])
  1207. elif int(entry[8]) == 2:
  1208. qdclf = qdclf + float(entry[11])
  1209. elif int(entry[8]) == 3:
  1210. qdjxf = qdjxf + float(entry[11])
  1211. post['人工费'] = str(qdrgf)
  1212. post['辅材费'] = str(qdclf)
  1213. post['材料费'] = str(qdclf)
  1214. post['机械费'] = str(qdjxf)
  1215. post['管理费'] = 0
  1216. post['利润'] = 0
  1217. for entry in children:
  1218. post['管理费'] = post['管理费'] + float(entry['管理费']) * float(entry['数量'])
  1219. post['利润'] = post['利润'] + float(entry['利润']) * float(entry['数量'])
  1220. post['管理费'] = str(post['管理费'])
  1221. post['利润'] = str(post['利润'])
  1222. post['综合单价'] = str(float(post['人工费']) + float(post['材料费']) + float(post['机械费']) + float(post['管理费']) + float(post['利润']))
  1223. post['合价'] = str(float(post['综合单价']) * float(qdsl))
  1224. await collection.replace_one({'_id': post['_id']}, post )
  1225. collection = db["Dwgc"]
  1226. document = await collection.find_one({'biao_id': biao_id, "Dwgcbh": bh})
  1227. hz = document['rcjhz']
  1228. for entry in hz:
  1229. if entry[1] == bm and entry[2] == mingcheng and entry[4] == danwei:
  1230. entry[6] = jiage
  1231. entry[7] = float(jiage) * float(entry[5])
  1232. await collection.update_one({'biao_id': biao_id, "Dwgcbh": bh}, {'$set': {'rcjhz': hz}})
  1233. await zongjiaDwgc(client, biao_id, bh)
  1234. await tbxx(client, biao_id)
  1235. def bjhz_template():
  1236. result = []
  1237. result.append({'序号': '1', '名称': '分部分项工程', '金额': '0', '暂估价': '0', '类别' : '1', '__children': [
  1238. {'序号': '1.1', '名称': '人工费', '金额': '0', '暂估价': '0', '类别' : '1.1'},
  1239. {'序号': '1.2', '名称': '材料费', '金额': '0', '暂估价': '0', '类别' : '1.2'},
  1240. {'序号': '1.3', '名称': '施工机具使用费', '金额': '0', '暂估价': '0', '类别' : '1.3'},
  1241. {'序号': '1.4', '名称': '企业管理费', '金额': '0', '暂估价': '0', '类别' : '1.4'},
  1242. {'序号': '1.5', '名称': '利润', '金额': '0', '暂估价': '0', '类别' : '1.5'}
  1243. ]})
  1244. result.append({'序号': '2', '名称': '措施项目', '金额': '0', '暂估价': '0', '类别' : '2', '__children': [
  1245. {'序号': '2.1', '名称': '单价措施项目费', '金额': '0', '暂估价': '0', '类别' : '2.1'},
  1246. {'序号': '2.2', '名称': '总价措施项目费', '金额': '0', '暂估价': '0', '类别' : '2.2', '__children' : [
  1247. {'序号': '2.2.1', '名称': '其中:安全文明施工措施费', '金额': '0', '暂估价': '0', '类别' : '2.2.1'},]
  1248. }
  1249. ]})
  1250. result.append({'序号': '3', '名称': '其他项目', '金额': '0', '暂估价': '0', '类别' : '3', '__children': [
  1251. {'序号': '3.1', '名称': '其中:暂列金额', '金额': '0', '暂估价': '0', '类别' : '3.1'},
  1252. {'序号': '3.2', '名称': '其中:专业工程暂估价', '金额': '0', '暂估价': '0', '类别' : '3.2'},
  1253. {'序号': '3.3', '名称': '其中:计日工', '金额': '0', '暂估价': '0', '类别' : '3.3'},
  1254. {'序号': '3.4', '名称': '其中:总承包服务费', '金额': '0', '暂估价': '0', '类别' : '3.4'},
  1255. ]})
  1256. result.append({'序号': '4', '名称': '规费', '金额': '0', '暂估价': '0', '类别' : '4', })
  1257. result.append({'序号': '5', '名称': '税金', '金额': '0', '暂估价': '0', '类别' : '5', })
  1258. result.append({'序号': '6', '名称': '工程造价', '金额': '0', '暂估价': '0', '类别' : '6', })
  1259. return result
  1260. async def tbxx(client, biao_id):
  1261. db = client["baojia"]
  1262. collection = db["jingjibiao"]
  1263. document = await collection.find_one({'_id': ObjectId(biao_id)})
  1264. dxgcxx = document['Dxgcxx']
  1265. tbxx = document['TouBiaoXx']
  1266. tbxx['Tbzj'] = '0'
  1267. tbxx['Zgj'] = '0'
  1268. tbxx['Aqwmf'] = '0'
  1269. tbxx['Gf'] = '0'
  1270. dwdx = {}##单位工程映射单项工程
  1271. for dxgc in dxgcxx:
  1272. dxgc['Aqwmf'] = '0'
  1273. dxgc['Gf'] = '0'
  1274. dxgc['Je'] = '0'
  1275. dxgc['Zgj'] = '0'
  1276. mc = dxgc['Dxgcmc']
  1277. Dwgc = dxgc['Dwgc']
  1278. for dwgc in Dwgc:
  1279. Dwgcbh = dwgc['Dwgcbh']
  1280. dwdx[Dwgcbh] = dxgc
  1281. collection = db['Dwgc']
  1282. async for post in collection.find({'biao_id': biao_id}):
  1283. bh = post['Dwgcbh']
  1284. dx = dwdx[bh]
  1285. bjhz = post['bjhz']
  1286. print('######################################################')
  1287. print(bjhz)
  1288. if len(bjhz) == 0:
  1289. pass
  1290. else:
  1291. qtxm = post['qtxm']
  1292. dx['Aqwmf'] = str(float(dx['Aqwmf']) + float(bjhz[1]['__children'][1]['__children'][0]['金额']))
  1293. dx['Gf'] = str(float(dx['Gf']) + float(bjhz[3]['金额']))
  1294. dx['Je'] = str(float(dx['Je']) + float(bjhz[5]['金额']))
  1295. dx['Zgj']= str(float(dx['Zgj']) + float(qtxm[1]['金额']))
  1296. for dxgc in dxgcxx:
  1297. tbxx['Tbzj'] = str(float(tbxx['Tbzj']) + float(dxgc['Je']))
  1298. tbxx['Zgj'] = str(float(tbxx['Zgj']) + float(dxgc['Zgj']))
  1299. tbxx['Aqwmf'] = str(float(tbxx['Aqwmf']) + float(dxgc['Aqwmf']))
  1300. tbxx['Gf'] = str(float(tbxx['Gf']) + float(dxgc['Gf']))
  1301. collection = db["jingjibiao"]
  1302. await collection.update_one({'_id': ObjectId(biao_id)}, {'$set': {'Dxgcxx': dxgcxx, 'TouBiaoXx' : tbxx}})
  1303. async def zongjiaDwgc(client, biao_id, bh):
  1304. db = client["baojia"]
  1305. collection = db["qdxm"]
  1306. qd_sum = 0
  1307. djcs_sum = 0
  1308. rgf_sum = 0
  1309. clf_sum = 0
  1310. jxf_sum = 0
  1311. glf_sum = 0
  1312. lr_sum = 0
  1313. fbrgycl_sum = 0
  1314. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  1315. qd_sum = qd_sum + float(post['合价'])
  1316. rgf_sum = rgf_sum + float(post['数量']) * float(post['人工费'])
  1317. clf_sum = clf_sum + float(post['数量']) * float(post['材料费'])
  1318. jxf_sum = jxf_sum + float(post['数量']) * float(post['机械费'])
  1319. glf_sum = glf_sum + float(post['数量']) * float(post['管理费'])
  1320. lr_sum = lr_sum + float(post['数量']) * float(post['利润'])
  1321. collection = db["Djcs"]
  1322. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  1323. djcs_sum = djcs_sum + float(post['合价'])
  1324. sum = qd_sum + djcs_sum
  1325. collection = db['Dwgc']
  1326. document = await collection.find_one({'biao_id': biao_id, "Dwgcbh": bh}, {'rcjhz': 0})
  1327. fbrgycl = document['fbrgycl']
  1328. for entry in fbrgycl:
  1329. fbrgycl_sum = fbrgycl_sum + float(entry['合价'])
  1330. zjcs = document['zjcs']
  1331. def process(n):
  1332. n['计算基数'] = str(sum)
  1333. n['金额'] = float(sum) * float(n['费率']) / float(100)
  1334. if "__children" in n:
  1335. for entry in n['__children']:
  1336. entry['计算基数'] = str(sum)
  1337. entry['金额'] = float(sum) * float(entry['费率']) / float(100)
  1338. return n
  1339. result = [process(item) for item in zjcs]
  1340. for entry in result:
  1341. if '安全文明施工' in entry['名称']:
  1342. sum_ = 0
  1343. for child in entry['__children']:
  1344. sum_ = sum_ + float(child['金额'])
  1345. entry['金额'] = str(sum_)
  1346. entry['计算基数'] = str(sum_)
  1347. zjcs_sum = 0
  1348. for entry in result:
  1349. zjcs_sum = zjcs_sum + float(entry['金额'])
  1350. qtxm = document['qtxm']##dwgc qtxm
  1351. qtxm_sum = 0
  1352. for entry in qtxm:
  1353. qtxm_sum = qtxm_sum + float(entry['金额'])
  1354. gfsj = document['gfsj']
  1355. gf_sum = 0
  1356. sj_sum = 0
  1357. for item in gfsj:
  1358. if item['名称'] == '规费':
  1359. child = item['__children']
  1360. for children in child:
  1361. children['取费基数'] = str(sum + zjcs_sum + qtxm_sum)
  1362. children['金额'] = str(float(sum + zjcs_sum + qtxm_sum) * float(children['费率']) / float(100))
  1363. gf_sum = gf_sum + float(children['金额'])
  1364. for item in gfsj:
  1365. if item['名称'] == '规费':
  1366. item['取费基数'] = str(gf_sum)
  1367. item['金额'] = str(gf_sum)
  1368. for item in gfsj:
  1369. if item['名称'] == '税金':
  1370. item['取费基数'] = str(sum + zjcs_sum + qtxm_sum + gf_sum - fbrgycl_sum / float(1.01))
  1371. item['金额'] = float(item['取费基数']) * float(item['费率']) / float(100)
  1372. sj_sum = float(item['金额'])
  1373. for item in gfsj:
  1374. if item['名称'] == '合计':
  1375. item['取费基数'] = str(sj_sum + gf_sum)
  1376. item['金额'] = item['取费基数']
  1377. qtxm = document['qtxm']
  1378. zlje = 0
  1379. zygczgj = 0
  1380. jrg = 0
  1381. zcbfwf = 0
  1382. clzgj = 0
  1383. for entry in qtxm:
  1384. if entry['序号'] == '1':
  1385. zlje = entry['金额']
  1386. if entry['序号'] == '3':
  1387. jrg = entry['金额']
  1388. if entry['序号'] == '4':
  1389. zcbfwf = entry['金额']
  1390. if entry['序号'] == '2':
  1391. for child in entry['__children']:
  1392. if child['序号'] == '2.2':
  1393. zygczgj = child['金额']
  1394. if child['序号'] == '2.1':
  1395. clzgj = child['金额']
  1396. qtxm_sum = float(zlje) + float(zygczgj) + float(jrg) + float(zcbfwf) + float(clzgj)
  1397. bjhz = bjhz_template()
  1398. for entry in bjhz:
  1399. if entry['序号'] == '1':
  1400. entry['金额'] = qd_sum
  1401. for child in entry['__children']:
  1402. if child['序号'] == '1.1':
  1403. child['金额'] = str(rgf_sum)
  1404. if child['序号'] == '1.2':
  1405. child['金额'] = str(clf_sum)
  1406. if child['序号'] == '1.3':
  1407. child['金额'] = str(jxf_sum)
  1408. if child['序号'] == '1.4':
  1409. child['金额'] = str(glf_sum)
  1410. if child['序号'] == '1.5':
  1411. child['金额'] = str(lr_sum)
  1412. if entry['序号'] == '2':
  1413. entry['金额'] = str(djcs_sum + zjcs_sum)
  1414. for child in entry['__children']:
  1415. if child['序号'] == '2.1':
  1416. child['金额'] = str(djcs_sum)
  1417. if child['序号'] == '2.2':
  1418. child['金额'] = str(zjcs_sum)
  1419. for grandchild in child['__children']:
  1420. if grandchild['序号'] == '2.2.1':
  1421. grandchild['金额'] = str(sum_)
  1422. if entry['序号'] == '3':
  1423. entry['金额'] = str(qtxm_sum)
  1424. if entry['序号'] == '4':
  1425. entry['金额'] = str(gf_sum)
  1426. if entry['序号'] == '5':
  1427. entry['金额'] = str(sj_sum)
  1428. if entry['序号'] == '6':
  1429. entry['金额'] = str(float(qd_sum) + float(djcs_sum) + float(zjcs_sum) + float(qtxm_sum) + float(gf_sum) + float(sj_sum))
  1430. await collection.update_one({'biao_id': biao_id, "Dwgcbh": bh}, {'$set': {'zjcs': result, 'gfsj' : gfsj, 'bjhz': bjhz}})