db.py 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364
  1. import xml.etree.ElementTree as ET
  2. from subdir import service, util
  3. from bson.objectid import ObjectId
  4. import uuid
  5. ###############helper##################
  6. def getDingercj_(root, bh, bt, qdbm, debm):
  7. result = [["ID", "人材机编码", "名称", "规格型号", "单位", "单价", "产地",
  8. "供应厂商", "人材机类别", "甲供标志", "含量", "合价", "暂估价标志", "主要材料标志", "主材标志", "设备标志" ]]
  9. #result.append(["ming cheng", "jin e", "zan gu jia", "anquan wenming fei", "guifei"])
  10. item = None
  11. for child in root:
  12. if child.tag == "Dxgcxx":
  13. for child1 in child:
  14. Dwgcbh = child1.attrib["Dwgcbh"]
  15. if Dwgcbh == bh:
  16. item = child1
  17. break
  18. ##result.append([child.attrib["Dxgcmc"], child.attrib["Je"], child.attrib["Zgj"], child.attrib["Aqwmf"], child.attrib["Gf"]])
  19. Fywj = None
  20. for child in item:
  21. if child.tag == 'Qdxm':
  22. Fywj= child
  23. break
  24. Rcjhz = None
  25. for child in item:
  26. if child.tag == 'Rcjhz':
  27. Rcjhz = child
  28. break
  29. kv = {}
  30. for entry in Rcjhz:
  31. kv[entry.attrib["RcjId"]]=entry
  32. container = None
  33. for child in Fywj:
  34. ##child is mx
  35. if child.tag == "QdBt":
  36. if child.attrib["Mc"] == bt:
  37. container = child
  38. break
  39. if not container:
  40. container = Fywj
  41. zimu = None
  42. for child in container:
  43. if child.attrib["Qdbm"] == qdbm:
  44. zimu = child
  45. break
  46. box = None
  47. if not zimu:
  48. return result
  49. for child in zimu:
  50. if child.tag == "Qdxdezj":
  51. box = child
  52. break
  53. hlmx_parent = None
  54. for child in box:
  55. if child.attrib["Debm"] == debm:
  56. for grandchild in child:
  57. if grandchild.tag == "Qdxdercjhl":
  58. hlmx_parent = grandchild
  59. for child in hlmx_parent:
  60. result.append([child.attrib["RcjId"],
  61. kv[child.attrib["RcjId"]].attrib["RcjBm"],
  62. kv[child.attrib["RcjId"]].attrib["Mc"],
  63. kv[child.attrib["RcjId"]].attrib["Ggxh"],
  64. kv[child.attrib["RcjId"]].attrib["Dw"],
  65. kv[child.attrib["RcjId"]].attrib["Dj"],
  66. kv[child.attrib["RcjId"]].attrib["Cd"],
  67. kv[child.attrib["RcjId"]].attrib["Gycs"],
  68. kv[child.attrib["RcjId"]].attrib["Rcjlb"],
  69. kv[child.attrib["RcjId"]].attrib["Jgbz"],
  70. child.attrib["Rcjhl"], child.attrib["Rcjhj"], "",
  71. "", "", ""
  72. ])
  73. return result
  74. def getQingdanrcj_(root, bh, bt, bm):
  75. result = [["ID", "人材机编码", "名称", "规格型号", "单位", "单价", "产地",
  76. "供应厂商", "人材机类别", "甲供标志", "含量", "合价", "暂估价标志", "主要材料标志", "主材标志", "设备标志" ]]
  77. #result.append(["ming cheng", "jin e", "zan gu jia", "anquan wenming fei", "guifei"])
  78. item = None
  79. for child in root:
  80. if child.tag == "Dxgcxx":
  81. for child1 in child:
  82. Dwgcbh = child1.attrib["Dwgcbh"]
  83. if Dwgcbh == bh:
  84. item = child1
  85. break
  86. ##result.append([child.attrib["Dxgcmc"], child.attrib["Je"], child.attrib["Zgj"], child.attrib["Aqwmf"], child.attrib["Gf"]])
  87. Fywj = None
  88. for child in item:
  89. if child.tag == 'Qdxm':
  90. Fywj= child
  91. break
  92. Rcjhz = None
  93. for child in item:
  94. if child.tag == 'Rcjhz':
  95. Rcjhz = child
  96. break
  97. kv = {}
  98. for entry in Rcjhz:
  99. kv[entry.attrib["RcjId"]]=entry
  100. container = None
  101. for child in Fywj:
  102. ##child is mx
  103. if child.tag == "QdBt":
  104. if child.attrib["Mc"] == bt:
  105. container = child
  106. break
  107. if not container:
  108. container = Fywj
  109. zimu = None
  110. for child in container:
  111. if child.attrib["Qdbm"] == bm:
  112. zimu = child
  113. break
  114. box = None
  115. if not zimu:
  116. return result
  117. for child in zimu:
  118. if child.tag == "Qdxrcjhl":
  119. box = child
  120. break
  121. for child in box:
  122. result.append([child.attrib["RcjId"],
  123. kv[child.attrib["RcjId"]].attrib["RcjBm"],
  124. kv[child.attrib["RcjId"]].attrib["Mc"],
  125. kv[child.attrib["RcjId"]].attrib["Ggxh"],
  126. kv[child.attrib["RcjId"]].attrib["Dw"],
  127. kv[child.attrib["RcjId"]].attrib["Dj"],
  128. kv[child.attrib["RcjId"]].attrib["Cd"],
  129. kv[child.attrib["RcjId"]].attrib["Gycs"],
  130. kv[child.attrib["RcjId"]].attrib["Rcjlb"],
  131. kv[child.attrib["RcjId"]].attrib["Jgbz"],
  132. child.attrib["Rcjhl"], child.attrib["Rcjhj"], child.attrib["Zgjbz"],
  133. child.attrib["Zyclbz"], child.attrib["Zcbz"], child.attrib["Sbbz"]
  134. ])
  135. return result
  136. def getDjcsDingercj_(root, bh, bt, qdbm, debm):
  137. result = [["ID", "人材机编码", "名称", "规格型号", "单位", "单价", "产地",
  138. "供应厂商", "人材机类别", "甲供标志", "含量", "合价", "暂估价标志", "主要材料标志", "主材标志", "设备标志" ]]
  139. #result.append(["ming cheng", "jin e", "zan gu jia", "anquan wenming fei", "guifei"])
  140. item = None
  141. for child in root:
  142. if child.tag == "Dxgcxx":
  143. for child1 in child:
  144. Dwgcbh = child1.attrib["Dwgcbh"]
  145. if Dwgcbh == bh:
  146. item = child1
  147. break
  148. ##result.append([child.attrib["Dxgcmc"], child.attrib["Je"], child.attrib["Zgj"], child.attrib["Aqwmf"], child.attrib["Gf"]])
  149. Fywj = None
  150. for child in item:
  151. if child.tag == 'Csxm':
  152. Fywj= child
  153. break
  154. Rcjhz = None
  155. for child in item:
  156. if child.tag == 'Rcjhz':
  157. Rcjhz = child
  158. break
  159. kv = {}
  160. for entry in Rcjhz:
  161. kv[entry.attrib["RcjId"]]=entry
  162. container = None
  163. for child in Fywj:
  164. if child.tag == "DjCs":
  165. container = child
  166. break
  167. zimu = None
  168. for child in container:
  169. if child.attrib["Bm"] == qdbm:
  170. zimu = child
  171. break
  172. box = None
  173. if not zimu:
  174. return result
  175. for child in zimu:
  176. if child.tag == "Csxdezj":
  177. box = child
  178. break
  179. hlmx_parent = None
  180. for child in box:
  181. if child.attrib["Debm"] == debm:
  182. for grandchild in child:
  183. if grandchild.tag == "Csxdercjhl":
  184. hlmx_parent = grandchild
  185. for child in hlmx_parent:
  186. result.append([child.attrib["RcjId"],
  187. kv[child.attrib["RcjId"]].attrib["RcjBm"],
  188. kv[child.attrib["RcjId"]].attrib["Mc"],
  189. kv[child.attrib["RcjId"]].attrib["Ggxh"],
  190. kv[child.attrib["RcjId"]].attrib["Dw"],
  191. kv[child.attrib["RcjId"]].attrib["Dj"],
  192. kv[child.attrib["RcjId"]].attrib["Cd"],
  193. kv[child.attrib["RcjId"]].attrib["Gycs"],
  194. kv[child.attrib["RcjId"]].attrib["Rcjlb"],
  195. kv[child.attrib["RcjId"]].attrib["Jgbz"],
  196. child.attrib["Rcjhl"], child.attrib["Rcjhj"], "",
  197. "", "", ""
  198. ])
  199. return result
  200. def getDjcsQingdanrcj_(root, bh, bt, bm):
  201. result = [["ID", "人材机编码", "名称", "规格型号", "单位", "单价", "产地",
  202. "供应厂商", "人材机类别", "甲供标志", "含量", "合价", "暂估价标志", "主要材料标志", "主材标志", "设备标志" ]]
  203. #result.append(["ming cheng", "jin e", "zan gu jia", "anquan wenming fei", "guifei"])
  204. item = None
  205. for child in root:
  206. if child.tag == "Dxgcxx":
  207. for child1 in child:
  208. Dwgcbh = child1.attrib["Dwgcbh"]
  209. if Dwgcbh == bh:
  210. item = child1
  211. break
  212. ##result.append([child.attrib["Dxgcmc"], child.attrib["Je"], child.attrib["Zgj"], child.attrib["Aqwmf"], child.attrib["Gf"]])
  213. Fywj = None
  214. for child in item:
  215. if child.tag == 'Csxm':
  216. Fywj= child
  217. break
  218. hl_parent = None
  219. for child in Fywj:
  220. if child.tag == "DjCs":
  221. hl_parent = child
  222. Rcjhz = None
  223. for child in item:
  224. if child.tag == 'Rcjhz':
  225. Rcjhz = child
  226. break
  227. kv = {}
  228. for entry in Rcjhz:
  229. kv[entry.attrib["RcjId"]]=entry
  230. zimu = None
  231. for child in hl_parent:
  232. if child.attrib["Bm"] == bm:
  233. zimu = child
  234. break
  235. box = None
  236. if not zimu:
  237. return result
  238. for child in zimu:
  239. if child.tag == "Csxrcjhl":
  240. box = child
  241. break
  242. for child in box:
  243. result.append([child.attrib["RcjId"],
  244. kv[child.attrib["RcjId"]].attrib["RcjBm"],
  245. kv[child.attrib["RcjId"]].attrib["Mc"],
  246. kv[child.attrib["RcjId"]].attrib["Ggxh"],
  247. kv[child.attrib["RcjId"]].attrib["Dw"],
  248. kv[child.attrib["RcjId"]].attrib["Dj"],
  249. kv[child.attrib["RcjId"]].attrib["Cd"],
  250. kv[child.attrib["RcjId"]].attrib["Gycs"],
  251. kv[child.attrib["RcjId"]].attrib["Rcjlb"],
  252. kv[child.attrib["RcjId"]].attrib["Jgbz"],
  253. child.attrib["Rcjhl"], child.attrib["Rcjhj"], child.attrib["Zgjbz"],
  254. child.attrib["Zyclbz"], child.attrib["Zcbz"], child.attrib["Sbbz"]
  255. ])
  256. return result
  257. ######################end of helper ########################
  258. async def resolve(manager, websocket, data, client):
  259. tree = ET.parse("data/" + data)
  260. root = tree.getroot()
  261. print(root)
  262. Dwgcbh = []
  263. jingjibiao = {}
  264. jingjibiao["BiaoDuanNO"] = root.attrib["BiaoDuanNO"]
  265. jingjibiao["Jsfs"] = root.attrib["Jsfs"]
  266. jingjibiao["Version"] = root.attrib["Version"]
  267. jingjibiao["Xmmc"] = root.attrib["Xmmc"]
  268. jingjibiao["Dxgcxx"] = []
  269. for child in root:
  270. if child.tag == "ZhaoBiaoXx":
  271. jingjibiao["ZhaoBiaoXx"] = {}
  272. jingjibiao["ZhaoBiaoXx"]["BzTime"] = child.attrib["BzTime"]
  273. jingjibiao["ZhaoBiaoXx"]["Bzr"] = child.attrib["Bzr"]
  274. jingjibiao["ZhaoBiaoXx"]["FhTime"] = child.attrib["FhTime"]
  275. jingjibiao["ZhaoBiaoXx"]["Fhr"] = child.attrib["Fhr"]
  276. jingjibiao["ZhaoBiaoXx"]["Zbr"] = child.attrib["Zbr"]
  277. jingjibiao["ZhaoBiaoXx"]["ZbrDb"] = child.attrib["ZbrDb"]
  278. jingjibiao["ZhaoBiaoXx"]["Zxr"] = child.attrib["Zxr"]
  279. jingjibiao["ZhaoBiaoXx"]["ZxrDb"] = child.attrib["ZxrDb"]
  280. elif child.tag == "TouBiaoXx":
  281. jingjibiao["TouBiaoXx"] = {}
  282. jingjibiao["TouBiaoXx"]["Zbr"] = child.attrib["Zbr"]
  283. jingjibiao["TouBiaoXx"]["Tbr"] = child.attrib["Tbr"]
  284. jingjibiao["TouBiaoXx"]["TbrDb"] = child.attrib["TbrDb"]
  285. jingjibiao["TouBiaoXx"]["Bzr"] = child.attrib["Bzr"]
  286. jingjibiao["TouBiaoXx"]["BzTime"] = child.attrib["BzTime"]
  287. jingjibiao["TouBiaoXx"]["Tbzj"] = child.attrib["Tbzj"]
  288. jingjibiao["TouBiaoXx"]["Zgj"] = child.attrib["Zgj"]
  289. jingjibiao["TouBiaoXx"]["Aqwmf"] = child.attrib["Aqwmf"]
  290. jingjibiao["TouBiaoXx"]["Gf"] = child.attrib["Gf"]
  291. elif child.tag == "Dxgcxx":
  292. Dxgcxx = {}
  293. Dxgcxx["Aqwmf"] = child.attrib["Aqwmf"]
  294. Dxgcxx["Dxgcbh"] = child.attrib["Dxgcbh"]
  295. Dxgcxx["Dxgcmc"] = child.attrib["Dxgcmc"]
  296. Dxgcxx["Gf"] = child.attrib["Gf"]
  297. Dxgcxx["Je"] = child.attrib["Je"]
  298. Dxgcxx["Zgj"] = child.attrib["Zgj"]
  299. Dxgcxx["Dwgc"] = []
  300. for grandchild in child:
  301. if grandchild.tag == "Dwgcxx":
  302. Dwgcxx = {}
  303. Dwgcxx["DogNum"] = grandchild.attrib["DogNum"]
  304. Dwgcxx["Dwgcbh"] = grandchild.attrib["Dwgcbh"]
  305. Dwgcbh.append({"bh": grandchild.attrib["Dwgcbh"], "num": grandchild.attrib["DogNum"]})
  306. Dwgcxx["Dwgcmc"] = grandchild.attrib["Dwgcmc"]
  307. Dwgcxx["MachineKey"] = grandchild.attrib["MachineKey"]
  308. Dwgcxx["SoftName"] = grandchild.attrib["SoftName"]
  309. Dwgcxx["SoftNum"] = grandchild.attrib["SoftNum"]
  310. Dwgcxx["Zylb"] = grandchild.attrib["Zylb"]
  311. Dxgcxx["Dwgc"].append(Dwgcxx)
  312. jingjibiao["Dxgcxx"].append(Dxgcxx)
  313. if not 'TouBiaoXx' in jingjibiao:
  314. jingjibiao['TouBiaoXx'] = {'Tbzj' : '', 'Zgj' : '', 'Aqwmf' : '', 'Gf' : '' }
  315. db = client["baojia"]
  316. collection = db["jingjibiao"]
  317. biao_id = (await collection.insert_one(jingjibiao)).inserted_id
  318. biao_id = str(biao_id)
  319. collection = db["Dwgc"]
  320. for entry in Dwgcbh:
  321. bjhz = service.getBjhz(root, entry["bh"])###array which contains __children
  322. gfsj = service.getGfsj(root, entry["bh"])##array which contains __children
  323. qtxm = service.getQtxm(root, entry["bh"])##array which contains __children
  324. zlje = service.getZlje(root, entry["bh"])
  325. jrg = service.getJrg(root, entry["bh"])
  326. zcbfwf = service.getZcbfwf(root, entry["bh"])
  327. fbrgycl = service.getFbrgycl(root, entry["bh"])
  328. rcjhz = service.getRcjhz(root, entry["bh"])
  329. zjcs = service.getZjcs(root, entry["bh"])
  330. qdbt = service.getQdxm(root, entry["bh"])
  331. zygczgj = service.getZygczgj(root, entry["bh"])
  332. Dwgc = {}
  333. Dwgc["bjhz"] = bjhz
  334. Dwgc["gfsj"] = gfsj
  335. Dwgc["qtxm"] = qtxm
  336. Dwgc["zlje"] = zlje
  337. Dwgc["jrg"] = jrg
  338. Dwgc['zygczgj'] = zygczgj
  339. Dwgc["zcbfwf"] = zcbfwf
  340. Dwgc["fbrgycl"] = fbrgycl
  341. Dwgc["rcjhz"] = rcjhz
  342. Dwgc["zjcs"] = zjcs
  343. Dwgc["qdbt"] = qdbt
  344. Dwgc["DogNum"] = entry["num"]
  345. Dwgc["Dwgcbh"] = entry["bh"]
  346. Dwgc["biao_id"] = biao_id
  347. await collection.insert_one(Dwgc)
  348. collection = db["Djcs"]
  349. for entry in Dwgcbh:
  350. djcs = service.getDjcs(root, entry["bh"])
  351. for cs in djcs:
  352. cs["DogNum"] = entry["num"]
  353. cs["Dwgcbh"] = entry["bh"]
  354. cs["biao_id"] = entry["biao_id"]
  355. rcj = getDjcsQingdanrcj_(root, entry["bh"], "", cs['清单编码'])
  356. cs["rcj"] = rcj
  357. if "__children" in cs:
  358. children = cs["__children"]
  359. for child in children:
  360. dercj = getDjcsDingercj_(root, entry["bh"], "", cs["清单编码"], child["清单编码"])
  361. child["dercj"] = dercj
  362. child['fuzhuEnable'] = False
  363. await collection.insert_one(cs)
  364. collection = db["qdxm"]
  365. for entry in Dwgcbh:
  366. bts = service.getQdxm(root, entry["bh"])
  367. for bt in bts:
  368. qdmx = service.getQdmx(root, entry["bh"], bt)
  369. for qd in qdmx:
  370. qd["DogNum"] = entry["num"]
  371. qd["Dwgcbh"] = entry["bh"]
  372. qd["biao_id"] = biao_id
  373. qd["bt"] = bt
  374. rcj = getQingdanrcj_(root, entry["bh"], bt, qd["清单编码"])
  375. qd["rcj"] = rcj
  376. if "__children" in qd:
  377. children = qd["__children"]
  378. for child in children:
  379. dercj = getDingercj_(root, entry["bh"], bt, qd["清单编码"], child["清单编码"])
  380. child["dercj"] = dercj
  381. child['fuzhuEnable'] = False
  382. await collection.insert_one(qd)
  383. collection = db["qufei"]
  384. document = jingjibiao
  385. dxgc = document['Dxgcxx']
  386. result = []
  387. for entry in dxgc:
  388. newone = {"名称" : entry['Dxgcmc'], "工程类型":"", "工程类别": "", "管理费(%)": "", "利润(%)": "","备注":"", "key" : str(uuid.uuid4()) }
  389. children = []
  390. for dwgc in entry['Dwgc']:
  391. children.append({"名称" : dwgc['Dwgcmc'], "工程类型":"", "工程类别": "", "管理费(%)": "", "利润(%)": "","备注":"", "key" : dwgc['Dwgcbh']})
  392. newone["children"] = children
  393. result.append(newone)
  394. await collection.insert_one({"biao_id": biao_id, "qufei": [{
  395. "名称" : document['Xmmc'], "工程类型":"", "工程类别": "", "管理费(%)": "", "利润(%)": "","备注":"", "key" : str(uuid.uuid4()), "children" : result
  396. }]})
  397. await manager.send_personal_message(f"You wrote: {data}", websocket)
  398. async def list_files(client):
  399. db = client["baojia"]
  400. collection = db["jingjibiao"]
  401. result = []
  402. async for post in collection.find():
  403. result.append([str(post['_id']), post["Xmmc"]])
  404. return result
  405. def getDwgc(id, Zylb):
  406. result = []
  407. #result.append(["ming cheng", "jin e", "zan gu jia", "anquan wenming fei", "guifei"])
  408. ##result.append([child.attrib["Dxgcmc"], child.attrib["Je"], child.attrib["Zgj"], child.attrib["Aqwmf"], child.attrib["Gf"]])
  409. id = id + "Zylb" + Zylb
  410. result.append({"id": id + "bao jia hui zong", "label": "报价汇总表"})
  411. result.append({"id": id + "gui fei shui jin", "label": "规费税金"})
  412. result.append({"id": id + "qing dan xiang mu", "label": "清单项目"})
  413. result.append({"id": id + "cuo shi xiang mu", "label": "措施项目"})
  414. result.append({"id": id +"qi ta xiang mu", "label": "其他项目"})
  415. result.append({"id": id +"zan lie jin e", "label": "暂列金额"})
  416. result.append({"id": id +"cai liao zan gu jia", "label": "材料暂估价"})
  417. result.append({"id": id + "zhuan ye gong cheng zan gu jia", "label": "专业工程暂估价"})
  418. result.append({"id": id + "ji ri gong", "label": "计日工"})
  419. result.append({"id": id + "zong cheng bao fu wu fei", "label": "总承包服务费"})
  420. result.append({"id": id + "zong jia xiang mu jin du kuan zhi fu fen jie", "label": "总价项目进度款支付分解"})
  421. result.append({"id": id + "fa bao ren gong ying cai liao", "label": "发包人供应材料"})
  422. result.append({"id": id + "cheng bao ren gong ying cai liao", "label": "承包人供应材料"})
  423. result.append({"id": id + "ren cai ji hui zong", "label": "人材机汇总"})
  424. return result
  425. async def getOutline(client, id):
  426. db = client["baojia"]
  427. collection = db["jingjibiao"]
  428. document = await collection.find_one({'_id': ObjectId(id)})
  429. result = []
  430. if 'TouBiaoXx' in document:
  431. result.append({"id" : "TouBiaoXx", "label" : "投标信息" })
  432. if 'Dxgcxx' in document:
  433. Dxgcxx = document["Dxgcxx"]
  434. for dxgc in Dxgcxx:
  435. result2 = []
  436. Dwgc = dxgc["Dwgc"]
  437. for grandchild in Dwgc:
  438. result2.append({"id" : grandchild['Dwgcbh'], "Zylb":grandchild['Zylb'], "label": grandchild["Dwgcmc"], "children" : getDwgc(grandchild['Dwgcbh'], grandchild['Zylb'])})
  439. result.append({"id" : dxgc['Dxgcbh'], "label" : dxgc['Dxgcmc'], "children" : result2})
  440. return result
  441. async def getDetail(client, id):
  442. db = client["baojia"]
  443. collection = db["jingjibiao"]
  444. document = await collection.find_one({'_id': ObjectId(id)})
  445. result = []
  446. ##result.append(["名称", "金额", "暂估价", "安全文明施工费", "规费"])
  447. if 'TouBiaoXx' in document:
  448. toubiaoxx = document["TouBiaoXx"]
  449. result.append({'名称': '投标总价', '金额' : toubiaoxx["Tbzj"], '暂估价': toubiaoxx["Zgj"], '安全文明施工费': toubiaoxx["Aqwmf"], '规费' : toubiaoxx["Gf"], '_children': []})
  450. if 'Dxgcxx' in document:
  451. Dxgcxx = document["Dxgcxx"]
  452. for dxgc in Dxgcxx:
  453. result[0]['_children'].append({'名称' :dxgc["Dxgcmc"], '金额' : dxgc["Je"], '暂估价' : dxgc["Zgj"],'安全文明施工费' : dxgc["Aqwmf"], '规费' : dxgc["Gf"]})
  454. return result
  455. else:
  456. if 'Dxgcxx' in document:
  457. Dxgcxx = document["Dxgcxx"]
  458. for dxgc in Dxgcxx:
  459. result.append({'名称' :dxgc["Dxgcmc"], '金额' : dxgc["Je"], '暂估价' : dxgc["Zgj"],'安全文明施工费' : dxgc["Aqwmf"], '规费' : dxgc["Gf"]})
  460. return result
  461. async def getBjhz(client, objectid, id):
  462. db = client["baojia"]
  463. collection = db["Dwgc"]
  464. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  465. return document['bjhz']
  466. async def getGfsj(client, objectid, id):
  467. db = client["baojia"]
  468. collection = db["Dwgc"]
  469. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  470. return document['gfsj']
  471. async def getQtxm(client, objectid, id):
  472. db = client["baojia"]
  473. collection = db["Dwgc"]
  474. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  475. return document['qtxm']
  476. async def getZygczgj(client, objectid, id):
  477. db = client["baojia"]
  478. collection = db["Dwgc"]
  479. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  480. return document['zygczgj']
  481. async def getZlje(client, objectid, id):
  482. db = client["baojia"]
  483. collection = db["Dwgc"]
  484. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  485. return document['zlje']
  486. async def getJrg(client, objectid, id):
  487. db = client["baojia"]
  488. collection = db["Dwgc"]
  489. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  490. return document['jrg']
  491. async def getZcbfwf(client, objectid, id):
  492. db = client["baojia"]
  493. collection = db["Dwgc"]
  494. document = await collection.find_one({"Dwgcbh": id, "biao_id": objectid})
  495. return document['zcbfwf']
  496. async def getFbrgycl(client, objectid, id):
  497. db = client["baojia"]
  498. collection = db["Dwgc"]
  499. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  500. return document['fbrgycl']
  501. async def getRcjhz(client, objectid, id):
  502. db = client["baojia"]
  503. collection = db["Dwgc"]
  504. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  505. return document['rcjhz']
  506. async def getZjcs(client, objectid, id):
  507. db = client["baojia"]
  508. collection = db["Dwgc"]
  509. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  510. return document['zjcs']
  511. async def getDjcs(client, objectid, id):
  512. db = client["baojia"]
  513. collection = db["Djcs"]
  514. result = []
  515. async for post in collection.find({"Dwgcbh": id, "biao_id": objectid}):
  516. ##post["ID"] = post["_id"]
  517. del post["_id"]
  518. ##print( post["rcj"])
  519. ## del post["DogNum"]
  520. result.append(post)
  521. return result
  522. async def getDjcsQingdanrcj(client, name, bh, bt, bm):
  523. db = client["baojia"]
  524. collection = db["Djcs"]
  525. document = await collection.find_one({ "Dwgcbh": bh, "清单编码": bm, "biao_id": name})
  526. result = document["rcj"]
  527. return result
  528. async def getDjcsDingercj(client, name, bh, bt, qdbm, debm):
  529. db = client["baojia"]
  530. collection = db["Djcs"]
  531. document = await collection.find_one({"Dwgcbh": bh, "清单编码": qdbm, "biao_id": name})
  532. children = document["__children"]
  533. result = []
  534. for child in children:
  535. if child["清单编码"] == debm:
  536. result = child["dercj"]
  537. return result
  538. async def getQdxm(client, name, bh):
  539. db = client["baojia"]
  540. collection = db["Dwgc"]
  541. document = await collection.find_one({'biao_id': name, "Dwgcbh": bh})
  542. if document:
  543. return document['qdbt']
  544. else:
  545. return []
  546. async def getQdmx(client, name, bh, bt):
  547. db = client["baojia"]
  548. collection = db["qdxm"]
  549. result = []
  550. async for post in collection.find({'biao_id': name, "Dwgcbh": bh, "bt": bt}):
  551. ##post["ID"] = post["_id"]
  552. del post["_id"]
  553. #del post["rcj"]
  554. #del post["DogNum"]
  555. result.append(post)
  556. return result
  557. async def getQingdanrcj(client, name, bh, bt, bm):
  558. db = client["baojia"]
  559. collection = db["qdxm"]
  560. document = await collection.find_one({ "Dwgcbh": bh, "清单编码": bm, "biao_id": name, "bt": bt})
  561. result = document["rcj"]
  562. return result
  563. async def getDingercj(client, name, bh, bt, qdbm, debm):
  564. db = client["baojia"]
  565. collection = db["qdxm"]
  566. document = await collection.find_one({"Dwgcbh": bh, "清单编码": qdbm, "biao_id": name, "bt": bt})
  567. result = []
  568. if "__children" in document:
  569. children = document["__children"]
  570. for child in children:
  571. if child["清单编码"] == debm:
  572. result = child["dercj"]
  573. return result
  574. async def getQufei(client, id):
  575. db = client["baojia"]
  576. collection = db["qufei"]
  577. document = await collection.find_one({'biao_id': id})
  578. return document['qufei']
  579. async def searchde(client, zhuanye, text):
  580. db = client["dinge"]
  581. collection = db["de-collection"]
  582. result = []
  583. async for post in collection.find({'$text': {"$search": "\"" + text + "\""}, "zhuanye": zhuanye}):
  584. result.append(post["DEBH"] + " " + post['GCLMC'] )
  585. if len(result) > 10:
  586. break
  587. return result
  588. ##################################editor##########################
  589. async def updatezjcs(client, id, bh, mc, fl):
  590. db = client["baojia"]
  591. collection = db["Dwgc"]
  592. document = await collection.find_one({'biao_id': id, 'Dwgcbh': bh}, {'rcjhz': 0})
  593. zjcs = document['zjcs']
  594. for entry in zjcs:
  595. if entry['名称'] == mc:
  596. entry['费率'] = fl
  597. entry['金额'] = str(float(entry['计算基数']) * float(fl) / float(100))
  598. await collection.update_one({'biao_id': id, "Dwgcbh": bh}, {'$set': {'zjcs': zjcs}})
  599. async def save(client, data):
  600. db = client["baojia"]
  601. collection = db["qdxm"]
  602. biao_id = None
  603. bh = None
  604. for entry in data:
  605. entry["__children"] = entry["_children"]
  606. del entry["_children"]
  607. biao_id = entry['biao_id']
  608. bh = entry['Dwgcbh']
  609. await collection.replace_one({"biao_id": entry["biao_id"], "Dwgcbh": entry["Dwgcbh"], "bt": entry["bt"], "清单编码": entry["清单编码"]}, entry)
  610. if not biao_id:
  611. return {"result" : "ok"}
  612. rcjhz = []
  613. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  614. qdrcj = post['rcj'][1:]
  615. for entry in qdrcj:
  616. entry[10] = float(entry[10]) * float(post['数量'])
  617. rcjhz = rcjhz + qdrcj
  618. collection = db["Djcs"]
  619. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  620. qdrcj = post['rcj'][1:]
  621. for entry in qdrcj:
  622. entry[10] = float(entry[10]) * float(post['数量'])
  623. rcjhz = rcjhz + qdrcj
  624. newHuizong = util.huizongrcj(rcjhz)
  625. collection = db["Dwgc"]
  626. await collection.update_one({'biao_id': biao_id, 'Dwgcbh': bh}, {'$set': {'rcjhz' : newHuizong}})
  627. await zongjiaDwgc(client, biao_id, bh)
  628. await tbxx(client, biao_id)
  629. return {"result": "ok"}
  630. async def savedjcs(client, data):
  631. db = client["baojia"]
  632. collection = db["Djcs"]
  633. biao_id = None
  634. bh = None
  635. for entry in data:
  636. entry["__children"] = entry["_children"]
  637. del entry["_children"]
  638. biao_id = entry['biao_id']
  639. bh = entry['Dwgcbh']
  640. await collection.replace_one({"biao_id": entry["biao_id"], "Dwgcbh": entry["Dwgcbh"], "清单编码": entry["清单编码"]}, entry)
  641. if not biao_id:
  642. return {"result" : "ok"}
  643. rcjhz = []
  644. collection = db["qdxm"]
  645. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  646. qdrcj = post['rcj'][1:]
  647. for entry in qdrcj:
  648. entry[10] = float(entry[10]) * float(post['数量'])
  649. rcjhz = rcjhz + qdrcj
  650. collection = db["Djcs"]
  651. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  652. qdrcj = post['rcj'][1:]
  653. for entry in qdrcj:
  654. entry[10] = float(entry[10]) * float(post['数量'])
  655. rcjhz = rcjhz + qdrcj
  656. newHuizong = util.huizongrcj(rcjhz)
  657. collection = db["Dwgc"]
  658. await collection.update_one({'biao_id': biao_id, 'Dwgcbh': bh}, {'$set': {'rcjhz' : newHuizong}})
  659. await zongjiaDwgc(client, biao_id, bh)
  660. await tbxx(client, biao_id)
  661. return {"result": "ok"}
  662. async def applyFL(client, id, data):
  663. db = client["baojia"]
  664. collection = db["qufei"]
  665. await collection.replace_one({"biao_id": id}, {"biao_id": id, "qufei": data})
  666. collection = db['qdxm']
  667. xm = data[0]
  668. for dxgc in xm["children"]:
  669. for dwgc in dxgc["children"]:
  670. bh = dwgc['key']
  671. glf = float(dwgc['管理费(%)'])
  672. lr = float(dwgc['利润(%)'])
  673. bz = dwgc['备注']
  674. ##print(bh+glf+lr+bz)
  675. async for post in collection.find({'biao_id': id, "Dwgcbh": bh}):
  676. rgfs = float(post['人工费'])
  677. clfs = float(post['材料费'])
  678. jxfs = float(post['机械费'])
  679. sl = float(post['数量'])
  680. if rgfs < 0.0001 and clfs < 0.0001 and jxfs < 0.0001:
  681. continue
  682. ##danxiang = False
  683. for child in post['__children']:##一条定额
  684. bm = child['清单编码']
  685. if bm.startswith("D"):
  686. ##danxiang = True
  687. continue
  688. rgf = float(child['人工费'])
  689. clf = float(child['材料费'])
  690. jxf = float(child['机械费'])
  691. zhdj = float(child['综合单价'])
  692. sl_ = float(child['数量'])
  693. if len(bz) == 0:
  694. ##常规计算
  695. child['管理费'] = (rgf + jxf) * glf / float(100)
  696. child['利润'] = (rgf + jxf) * lr / float(100)
  697. child['综合单价'] = rgf + clf + jxf + child['管理费'] + child['利润']
  698. child['合价'] = sl * sl_ * child['综合单价']
  699. else:
  700. child['管理费'] = (rgf) * glf / float(100)
  701. child['利润'] = (rgf) * lr / float(100)
  702. child['综合单价'] = rgf + clf + jxf + child['管理费'] + child['利润']
  703. child['合价'] = sl * sl_ * child['综合单价']
  704. if True:
  705. post['管理费'] = 0
  706. post['利润'] = 0
  707. for entry in post['__children']:
  708. post['管理费'] = post['管理费'] + float(entry['管理费']) * float(entry['数量'])
  709. post['利润'] = post['利润'] + float(entry['利润']) * float(entry['数量'])
  710. post['管理费'] = str(post['管理费'])
  711. post['利润'] = str(post['利润'])
  712. post['综合单价'] = str(float(post['人工费']) + float(post['材料费']) + float(post['机械费']) + float(post['管理费']) + float(post['利润']))
  713. post['合价'] = str(float(post['综合单价']) * float(post['数量']))
  714. await collection.replace_one({'_id': post['_id']}, post )
  715. collection = db['Djcs']
  716. for dxgc in xm["children"]:
  717. for dwgc in dxgc["children"]:
  718. bh = dwgc['key']
  719. glf = float(dwgc['管理费(%)'])
  720. lr = float(dwgc['利润(%)'])
  721. bz = dwgc['备注']
  722. ##print(bh+glf+lr+bz)
  723. async for post in collection.find({'biao_id': id, "Dwgcbh": bh}):
  724. rgfs = float(post['人工费'])
  725. clfs = float(post['材料费'])
  726. jxfs = float(post['机械费'])
  727. sl = float(post['数量'])
  728. if rgfs < 0.0001 and clfs < 0.0001 and jxfs < 0.0001:
  729. continue
  730. ##danxiang = False##一般有单项定额的,清单就一条定额,就是这个单项定额
  731. for child in post['__children']:
  732. bm = child['清单编码']
  733. if bm.startswith("D"):
  734. ##danxiang = True
  735. continue
  736. rgf = float(child['人工费'])
  737. clf = float(child['材料费'])
  738. jxf = float(child['机械费'])
  739. zhdj = float(child['综合单价'])
  740. sl_ = float(child['数量'])
  741. if len(bz) == 0:
  742. ##常规计算
  743. child['管理费'] = (rgf + jxf) * glf / float(100)
  744. child['利润'] = (rgf + jxf) * lr / float(100)
  745. child['综合单价'] = rgf + clf + jxf + child['管理费'] + child['利润']
  746. child['合价'] = sl * sl_ * child['综合单价']
  747. else:
  748. child['管理费'] = (rgf) * glf / float(100)
  749. child['利润'] = (rgf) * lr / float(100)
  750. child['综合单价'] = rgf + clf + jxf + child['管理费'] + child['利润']
  751. child['合价'] = sl * sl_ * child['综合单价']
  752. if True:
  753. post['管理费'] = 0
  754. post['利润'] = 0
  755. for entry in post['__children']:
  756. post['管理费'] = post['管理费'] + float(entry['管理费']) * float(entry['数量'])
  757. post['利润'] = post['利润'] + float(entry['利润']) * float(entry['数量'])
  758. post['管理费'] = str(post['管理费'])
  759. post['利润'] = str(post['利润'])
  760. post['综合单价'] = str(float(post['人工费']) + float(post['材料费']) + float(post['机械费']) + float(post['管理费']) + float(post['利润']))
  761. post['合价'] = str(float(post['综合单价']) * float(post['数量']))
  762. await collection.replace_one({'_id': post['_id']}, post )
  763. for dxgc in xm["children"]:
  764. for dwgc in dxgc["children"]:
  765. bh = dwgc['key']
  766. await zongjiaDwgc(client, id, bh)
  767. await tbxx(client, id)
  768. return {"result": "ok"}
  769. async def tiaojia(client, biao_id, bh, bm, mingcheng, danwei, jiage, glf, lr, bz):
  770. db = client["baojia"]
  771. collection = db["qdxm"]
  772. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}):
  773. if "__children" not in post:
  774. ##print(post)
  775. continue
  776. children = post["__children"]
  777. qdsl = post['数量']
  778. hit = False
  779. for entry in children:###对一条定额,调价
  780. hitde = False
  781. dercj = entry["dercj"]
  782. dergf = 0
  783. declf = 0
  784. dejxf = 0
  785. for i in range(1, len(dercj)):
  786. rcj = dercj[i]
  787. if rcj[1] == bm and rcj[2] == mingcheng and rcj[4] == danwei:
  788. hit = True
  789. hitde = True
  790. rcj[5] = jiage
  791. hanliang = rcj[10]
  792. rcj[11] = str(float(jiage) * float(hanliang))
  793. if int(rcj[8]) == 1:
  794. dergf = dergf + float(rcj[11])
  795. elif int(rcj[8]) == 2:
  796. declf = declf + float(rcj[11])
  797. elif int(rcj[8]) == 3:
  798. dejxf = dejxf + float(rcj[11])
  799. if hitde:
  800. entry['人工费'] = str(dergf)
  801. entry['辅材费'] = str(declf)
  802. entry['材料费'] = str(declf)
  803. entry['机械费'] = str(dejxf)
  804. if bm.startswith("D"):
  805. entry['管理费'] = '0'
  806. entry['利润'] = '0'
  807. elif bz == 0:
  808. entry['管理费'] = str((dergf + dejxf) * float(glf) / float(100))
  809. entry['利润'] = str((dergf + dejxf) * float(lr) / float(100))
  810. else:
  811. entry['管理费'] = str((dergf) * float(glf) / float(100))
  812. entry['利润'] = str((dergf) * float(lr) / float(100))
  813. entry['综合单价'] = str(float(entry['人工费']) + float(entry['材料费']) + float(entry['机械费']) + float(entry['管理费']) + float(entry['利润']))
  814. entry['合价'] = str(float(entry['综合单价']) * float(entry['数量']) * float(qdsl))
  815. if hit:
  816. ##调整清单
  817. qdrcj = post['rcj']
  818. qdrgf = 0
  819. qdclf = 0
  820. qdjxf = 0
  821. for i in range(1, len(qdrcj)):
  822. entry = qdrcj[i]
  823. if entry[1] == bm and entry[2] == mingcheng and entry[4] == danwei:
  824. entry[5] = jiage
  825. hanliang = entry[10]
  826. entry[11] = str(float(jiage) * float(hanliang))
  827. if int(entry[8]) == 1:
  828. qdrgf = qdrgf + float(entry[11])
  829. elif int(entry[8]) == 2:
  830. qdclf = qdclf + float(entry[11])
  831. elif int(entry[8]) == 3:
  832. qdjxf = qdjxf + float(entry[11])
  833. post['人工费'] = str(qdrgf)
  834. post['辅材费'] = str(qdclf)
  835. post['材料费'] = str(qdclf)
  836. post['机械费'] = str(qdjxf)
  837. post['管理费'] = 0
  838. post['利润'] = 0
  839. for entry in children:
  840. post['管理费'] = post['管理费'] + float(entry['管理费']) * float(entry['数量'])
  841. post['利润'] = post['利润'] + float(entry['利润']) * float(entry['数量'])
  842. post['管理费'] = str(post['管理费'])
  843. post['利润'] = str(post['利润'])
  844. post['综合单价'] = str(float(post['人工费']) + float(post['材料费']) + float(post['机械费']) + float(post['管理费']) + float(post['利润']))
  845. post['合价'] = str(float(post['综合单价']) * float(qdsl))
  846. print(post)
  847. await collection.replace_one({'_id': post['_id']}, post )
  848. collection = db["Djcs"]
  849. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}):
  850. children = post["__children"]
  851. qdsl = post['数量']
  852. hit = False
  853. for entry in children:###对一条定额,调价
  854. hitde = False
  855. dercj = entry["dercj"]
  856. dergf = 0
  857. declf = 0
  858. dejxf = 0
  859. for i in range(1, len(dercj)):
  860. rcj = dercj[i]
  861. if rcj[1] == bm and rcj[2] == mingcheng and rcj[4] == danwei:
  862. hit = True
  863. hitde = True
  864. rcj[5] = jiage
  865. hanliang = rcj[10]
  866. rcj[11] = str(float(jiage) * float(hanliang))
  867. if int(rcj[8]) == 1:
  868. dergf = dergf + float(rcj[11])
  869. elif int(rcj[8]) == 2:
  870. declf = declf + float(rcj[11])
  871. elif int(rcj[8]) == 3:
  872. dejxf = dejxf + float(rcj[11])
  873. if hitde:
  874. entry['人工费'] = str(dergf)
  875. entry['辅材费'] = str(declf)
  876. entry['材料费'] = str(declf)
  877. entry['机械费'] = str(dejxf)
  878. if bm.startswith("D"):
  879. entry['管理费'] = '0'
  880. entry['利润'] = '0'
  881. elif bz == 0:
  882. entry['管理费'] = str((dergf + dejxf) * float(glf) / float(100))
  883. entry['利润'] = str((dergf + dejxf) * float(lr) / float(100))
  884. else:
  885. entry['管理费'] = str((dergf) * float(glf) / float(100))
  886. entry['利润'] = str((dergf) * float(lr) / float(100))
  887. entry['综合单价'] = str(float(entry['人工费']) + float(entry['材料费']) + float(entry['机械费']) + float(entry['管理费']) + float(entry['利润']))
  888. entry['合价'] = str(float(entry['综合单价']) * float(entry['数量']) * float(qdsl))
  889. if hit:
  890. ##调整清单
  891. qdrcj = post['rcj']
  892. qdrgf = 0
  893. qdclf = 0
  894. qdjxf = 0
  895. for i in range(1, len(qdrcj)):
  896. entry = qdrcj[i]
  897. if entry[1] == bm and entry[2] == mingcheng and entry[4] == danwei:
  898. entry[5] = jiage
  899. hanliang = entry[10]
  900. entry[11] = str(float(jiage) * float(hanliang))
  901. if int(entry[8]) == 1:
  902. qdrgf = qdrgf + float(entry[11])
  903. elif int(entry[8]) == 2:
  904. qdclf = qdclf + float(entry[11])
  905. elif int(entry[8]) == 3:
  906. qdjxf = qdjxf + float(entry[11])
  907. post['人工费'] = str(qdrgf)
  908. post['辅材费'] = str(qdclf)
  909. post['材料费'] = str(qdclf)
  910. post['机械费'] = str(qdjxf)
  911. post['管理费'] = 0
  912. post['利润'] = 0
  913. for entry in children:
  914. post['管理费'] = post['管理费'] + float(entry['管理费']) * float(entry['数量'])
  915. post['利润'] = post['利润'] + float(entry['利润']) * float(entry['数量'])
  916. post['管理费'] = str(post['管理费'])
  917. post['利润'] = str(post['利润'])
  918. post['综合单价'] = str(float(post['人工费']) + float(post['材料费']) + float(post['机械费']) + float(post['管理费']) + float(post['利润']))
  919. post['合价'] = str(float(post['综合单价']) * float(qdsl))
  920. await collection.replace_one({'_id': post['_id']}, post )
  921. collection = db["Dwgc"]
  922. document = await collection.find_one({'biao_id': biao_id, "Dwgcbh": bh})
  923. hz = document['rcjhz']
  924. for entry in hz:
  925. if entry[1] == bm and entry[2] == mingcheng and entry[4] == danwei:
  926. entry[6] = jiage
  927. entry[7] = float(jiage) * float(entry[5])
  928. await collection.update_one({'biao_id': biao_id, "Dwgcbh": bh}, {'$set': {'rcjhz': hz}})
  929. await zongjiaDwgc(client, biao_id, bh)
  930. await tbxx(client, biao_id)
  931. def bjhz_template():
  932. result = []
  933. result.append({'序号': '1', '名称': '分部分项工程', '金额': '0', '暂估价': '0', '类别' : '1', '__children': [
  934. {'序号': '1.1', '名称': '人工费', '金额': '0', '暂估价': '0', '类别' : '1.1'},
  935. {'序号': '1.2', '名称': '材料费', '金额': '0', '暂估价': '0', '类别' : '1.2'},
  936. {'序号': '1.3', '名称': '施工机具使用费', '金额': '0', '暂估价': '0', '类别' : '1.3'},
  937. {'序号': '1.4', '名称': '企业管理费', '金额': '0', '暂估价': '0', '类别' : '1.4'},
  938. {'序号': '1.5', '名称': '利润', '金额': '0', '暂估价': '0', '类别' : '1.5'}
  939. ]})
  940. result.append({'序号': '2', '名称': '措施项目', '金额': '0', '暂估价': '0', '类别' : '2', '__children': [
  941. {'序号': '2.1', '名称': '单价措施项目费', '金额': '0', '暂估价': '0', '类别' : '2.1'},
  942. {'序号': '2.2', '名称': '总价措施项目费', '金额': '0', '暂估价': '0', '类别' : '2.2', '__children' : [
  943. {'序号': '2.2.1', '名称': '其中:安全文明施工措施费', '金额': '0', '暂估价': '0', '类别' : '2.2.1'},]
  944. }
  945. ]})
  946. result.append({'序号': '3', '名称': '其他项目', '金额': '0', '暂估价': '0', '类别' : '3', '__children': [
  947. {'序号': '3.1', '名称': '其中:暂列金额', '金额': '0', '暂估价': '0', '类别' : '3.1'},
  948. {'序号': '3.2', '名称': '其中:专业工程暂估价', '金额': '0', '暂估价': '0', '类别' : '3.2'},
  949. {'序号': '3.3', '名称': '其中:计日工', '金额': '0', '暂估价': '0', '类别' : '3.3'},
  950. {'序号': '3.4', '名称': '其中:总承包服务费', '金额': '0', '暂估价': '0', '类别' : '3.4'},
  951. ]})
  952. result.append({'序号': '4', '名称': '规费', '金额': '0', '暂估价': '0', '类别' : '4', })
  953. result.append({'序号': '5', '名称': '税金', '金额': '0', '暂估价': '0', '类别' : '5', })
  954. result.append({'序号': '6', '名称': '工程造价', '金额': '0', '暂估价': '0', '类别' : '6', })
  955. return result
  956. async def tbxx(client, biao_id):
  957. db = client["baojia"]
  958. collection = db["jingjibiao"]
  959. document = await collection.find_one({'_id': ObjectId(biao_id)})
  960. dxgcxx = document['Dxgcxx']
  961. tbxx = document['TouBiaoXx']
  962. tbxx['Tbzj'] = '0'
  963. tbxx['Zgj'] = '0'
  964. tbxx['Aqwmf'] = '0'
  965. tbxx['Gf'] = '0'
  966. dwdx = {}##单位工程映射单项工程
  967. for dxgc in dxgcxx:
  968. dxgc['Aqwmf'] = '0'
  969. dxgc['Gf'] = '0'
  970. dxgc['Je'] = '0'
  971. dxgc['Zgj'] = '0'
  972. mc = dxgc['Dxgcmc']
  973. Dwgc = dxgc['Dwgc']
  974. for dwgc in Dwgc:
  975. Dwgcbh = dwgc['Dwgcbh']
  976. dwdx[Dwgcbh] = dxgc
  977. collection = db['Dwgc']
  978. async for post in collection.find({'biao_id': biao_id}):
  979. bh = post['Dwgcbh']
  980. dx = dwdx[bh]
  981. bjhz = post['bjhz']
  982. qtxm = post['qtxm']
  983. dx['Aqwmf'] = str(float(dx['Aqwmf']) + float(bjhz[1]['__children'][1]['__children'][0]['金额']))
  984. dx['Gf'] = str(float(dx['Gf']) + float(bjhz[3]['金额']))
  985. dx['Je'] = str(float(dx['Je']) + float(bjhz[5]['金额']))
  986. dx['Zgj']= str(float(dx['Zgj']) + float(qtxm[1]['金额']))
  987. for dxgc in dxgcxx:
  988. tbxx['Tbzj'] = str(float(tbxx['Tbzj']) + float(dxgc['Je']))
  989. tbxx['Zgj'] = str(float(tbxx['Zgj']) + float(dxgc['Zgj']))
  990. tbxx['Aqwmf'] = str(float(tbxx['Aqwmf']) + float(dxgc['Aqwmf']))
  991. tbxx['Gf'] = str(float(tbxx['Gf']) + float(dxgc['Gf']))
  992. collection = db["jingjibiao"]
  993. await collection.update_one({'_id': ObjectId(biao_id)}, {'$set': {'Dxgcxx': dxgcxx, 'TouBiaoXx' : tbxx}})
  994. async def zongjiaDwgc(client, biao_id, bh):
  995. db = client["baojia"]
  996. collection = db["qdxm"]
  997. qd_sum = 0
  998. djcs_sum = 0
  999. rgf_sum = 0
  1000. clf_sum = 0
  1001. jxf_sum = 0
  1002. glf_sum = 0
  1003. lr_sum = 0
  1004. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  1005. qd_sum = qd_sum + float(post['合价'])
  1006. rgf_sum = rgf_sum + float(post['数量']) * float(post['人工费'])
  1007. clf_sum = clf_sum + float(post['数量']) * float(post['材料费'])
  1008. jxf_sum = jxf_sum + float(post['数量']) * float(post['机械费'])
  1009. glf_sum = glf_sum + float(post['数量']) * float(post['管理费'])
  1010. lr_sum = lr_sum + float(post['数量']) * float(post['利润'])
  1011. collection = db["Djcs"]
  1012. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  1013. djcs_sum = djcs_sum + float(post['合价'])
  1014. sum = qd_sum + djcs_sum
  1015. collection = db['Dwgc']
  1016. document = await collection.find_one({'biao_id': biao_id, "Dwgcbh": bh}, {'rcjhz': 0})
  1017. zjcs = document['zjcs']
  1018. def process(n):
  1019. n['计算基数'] = str(sum)
  1020. n['金额'] = float(sum) * float(n['费率']) / float(100)
  1021. if "__children" in n:
  1022. for entry in n['__children']:
  1023. entry['计算基数'] = str(sum)
  1024. entry['金额'] = float(sum) * float(entry['费率']) / float(100)
  1025. return n
  1026. result = [process(item) for item in zjcs]
  1027. for entry in result:
  1028. if '安全文明施工' in entry['名称']:
  1029. sum_ = 0
  1030. for child in entry['__children']:
  1031. sum_ = sum_ + float(child['金额'])
  1032. entry['金额'] = str(sum_)
  1033. entry['计算基数'] = str(sum_)
  1034. zjcs_sum = 0
  1035. for entry in result:
  1036. zjcs_sum = zjcs_sum + float(entry['金额'])
  1037. qtxm = document['qtxm']##dwgc qtxm
  1038. qtxm_sum = 0
  1039. for entry in qtxm:
  1040. qtxm_sum = qtxm_sum + float(entry['金额'])
  1041. gfsj = document['gfsj']
  1042. gf_sum = 0
  1043. sj_sum = 0
  1044. for item in gfsj:
  1045. if item['名称'] == '规费':
  1046. child = item['__children']
  1047. for children in child:
  1048. children['取费基数'] = str(sum + zjcs_sum + qtxm_sum)
  1049. children['金额'] = str(float(sum + zjcs_sum + qtxm_sum) * float(children['费率']) / float(100))
  1050. gf_sum = gf_sum + float(children['金额'])
  1051. for item in gfsj:
  1052. if item['名称'] == '规费':
  1053. item['取费基数'] = str(gf_sum)
  1054. item['金额'] = str(gf_sum)
  1055. for item in gfsj:
  1056. if item['名称'] == '税金':
  1057. item['取费基数'] = str(sum + zjcs_sum + qtxm_sum + gf_sum)
  1058. item['金额'] = float(item['取费基数']) * float(item['费率']) / float(100)
  1059. sj_sum = float(item['金额'])
  1060. for item in gfsj:
  1061. if item['名称'] == '合计':
  1062. item['取费基数'] = str(sj_sum + gf_sum)
  1063. item['金额'] = item['取费基数']
  1064. qtxm = document['qtxm']
  1065. zlje = 0
  1066. zygczgj = 0
  1067. jrg = 0
  1068. zcbfwf = 0
  1069. clzgj = 0
  1070. for entry in qtxm:
  1071. if entry['序号'] == '1':
  1072. zlje = entry['金额']
  1073. if entry['序号'] == '3':
  1074. jrg = entry['金额']
  1075. if entry['序号'] == '4':
  1076. zcbfwf = entry['金额']
  1077. if entry['序号'] == '2':
  1078. for child in entry['__children']:
  1079. if child['序号'] == '2.2':
  1080. zygczgj = child['金额']
  1081. if child['序号'] == '2.1':
  1082. clzgj = child['金额']
  1083. qtxm_sum = float(zlje) + float(zygczgj) + float(jrg) + float(zcbfwf) + float(clzgj)
  1084. bjhz = bjhz_template()
  1085. for entry in bjhz:
  1086. if entry['序号'] == '1':
  1087. entry['金额'] = qd_sum
  1088. for child in entry['__children']:
  1089. if child['序号'] == '1.1':
  1090. child['金额'] = str(rgf_sum)
  1091. if child['序号'] == '1.2':
  1092. child['金额'] = str(clf_sum)
  1093. if child['序号'] == '1.3':
  1094. child['金额'] = str(jxf_sum)
  1095. if child['序号'] == '1.4':
  1096. child['金额'] = str(glf_sum)
  1097. if child['序号'] == '1.5':
  1098. child['金额'] = str(lr_sum)
  1099. if entry['序号'] == '2':
  1100. entry['金额'] = str(djcs_sum + zjcs_sum)
  1101. for child in entry['__children']:
  1102. if child['序号'] == '2.1':
  1103. child['金额'] = str(djcs_sum)
  1104. if child['序号'] == '2.2':
  1105. child['金额'] = str(zjcs_sum)
  1106. for grandchild in child['__children']:
  1107. if grandchild['序号'] == '2.2.1':
  1108. grandchild['金额'] = str(sum_)
  1109. if entry['序号'] == '3':
  1110. entry['金额'] = str(qtxm_sum)
  1111. if entry['序号'] == '4':
  1112. entry['金额'] = str(gf_sum)
  1113. if entry['序号'] == '5':
  1114. entry['金额'] = str(sj_sum)
  1115. if entry['序号'] == '6':
  1116. entry['金额'] = str(float(qd_sum) + float(djcs_sum) + float(zjcs_sum) + float(qtxm_sum) + float(gf_sum) + float(sj_sum))
  1117. await collection.update_one({'biao_id': biao_id, "Dwgcbh": bh}, {'$set': {'zjcs': result, 'gfsj' : gfsj, 'bjhz': bjhz}})