db.py 40 KB

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