db.py 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393
  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. ##await manager.send_personal_message(f"You wrote: {data}", websocket)
  417. async def delete_files(client, id):
  418. db = client["baojia"]
  419. collection = db["jingjibiao"]
  420. result = []
  421. await collection.update_one({'_id': ObjectId(id)}, {'$set': {'visible': False}})
  422. return result
  423. async def list_files(client):
  424. db = client["baojia"]
  425. collection = db["jingjibiao"]
  426. result = []
  427. async for post in collection.find({"visible": True}):
  428. result.append([str(post['_id']), post["Xmmc"], post['created'] if 'created' in post else ""])
  429. return result
  430. def getDwgc(id, Zylb):
  431. result = []
  432. #result.append(["ming cheng", "jin e", "zan gu jia", "anquan wenming fei", "guifei"])
  433. ##result.append([child.attrib["Dxgcmc"], child.attrib["Je"], child.attrib["Zgj"], child.attrib["Aqwmf"], child.attrib["Gf"]])
  434. id = id + "Zylb" + Zylb
  435. result.append({"id": id + "bao jia hui zong", "label": "报价汇总表"})
  436. result.append({"id": id + "gui fei shui jin", "label": "规费税金"})
  437. result.append({"id": id + "qing dan xiang mu", "label": "清单项目"})
  438. result.append({"id": id + "cuo shi xiang mu", "label": "措施项目"})
  439. result.append({"id": id +"qi ta xiang mu", "label": "其他项目"})
  440. result.append({"id": id +"zan lie jin e", "label": "暂列金额"})
  441. result.append({"id": id +"cai liao zan gu jia", "label": "材料暂估价"})
  442. result.append({"id": id + "zhuan ye gong cheng zan gu jia", "label": "专业工程暂估价"})
  443. result.append({"id": id + "ji ri gong", "label": "计日工"})
  444. result.append({"id": id + "zong cheng bao fu wu fei", "label": "总承包服务费"})
  445. result.append({"id": id + "zong jia xiang mu jin du kuan zhi fu fen jie", "label": "总价项目进度款支付分解"})
  446. result.append({"id": id + "fa bao ren gong ying cai liao", "label": "发包人供应材料"})
  447. result.append({"id": id + "cheng bao ren gong ying cai liao", "label": "承包人供应材料"})
  448. result.append({"id": id + "ren cai ji hui zong", "label": "人材机汇总"})
  449. return result
  450. async def getOutline(client, id):
  451. db = client["baojia"]
  452. collection = db["jingjibiao"]
  453. document = await collection.find_one({'_id': ObjectId(id)})
  454. result = []
  455. if 'TouBiaoXx' in document:
  456. result.append({"id" : "TouBiaoXx", "label" : "投标信息" })
  457. if 'Dxgcxx' in document:
  458. Dxgcxx = document["Dxgcxx"]
  459. for dxgc in Dxgcxx:
  460. result2 = []
  461. Dwgc = dxgc["Dwgc"]
  462. for grandchild in Dwgc:
  463. result2.append({"id" : grandchild['Dwgcbh'], "Zylb":grandchild['Zylb'], "label": grandchild["Dwgcmc"], "children" : getDwgc(grandchild['Dwgcbh'], grandchild['Zylb'])})
  464. result.append({"id" : dxgc['Dxgcbh'], "label" : dxgc['Dxgcmc'], "children" : result2})
  465. return result
  466. async def getDetail(client, id):
  467. db = client["baojia"]
  468. collection = db["jingjibiao"]
  469. document = await collection.find_one({'_id': ObjectId(id)})
  470. result = []
  471. ##result.append(["名称", "金额", "暂估价", "安全文明施工费", "规费"])
  472. if 'TouBiaoXx' in document:
  473. toubiaoxx = document["TouBiaoXx"]
  474. result.append({'名称': '投标总价', '金额' : toubiaoxx["Tbzj"], '暂估价': toubiaoxx["Zgj"], '安全文明施工费': toubiaoxx["Aqwmf"], '规费' : toubiaoxx["Gf"], '_children': []})
  475. if 'Dxgcxx' in document:
  476. Dxgcxx = document["Dxgcxx"]
  477. for dxgc in Dxgcxx:
  478. result[0]['_children'].append({'名称' :dxgc["Dxgcmc"], '金额' : dxgc["Je"], '暂估价' : dxgc["Zgj"],'安全文明施工费' : dxgc["Aqwmf"], '规费' : dxgc["Gf"]})
  479. return result
  480. else:
  481. if 'Dxgcxx' in document:
  482. Dxgcxx = document["Dxgcxx"]
  483. for dxgc in Dxgcxx:
  484. result.append({'名称' :dxgc["Dxgcmc"], '金额' : dxgc["Je"], '暂估价' : dxgc["Zgj"],'安全文明施工费' : dxgc["Aqwmf"], '规费' : dxgc["Gf"]})
  485. return result
  486. async def getBjhz(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['bjhz']
  491. async def getGfsj(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['gfsj']
  496. async def getQtxm(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['qtxm']
  501. async def getZygczgj(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['zygczgj']
  506. async def getZlje(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['zlje']
  511. async def getJrg(client, objectid, id):
  512. db = client["baojia"]
  513. collection = db["Dwgc"]
  514. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  515. return document['jrg']
  516. async def getZcbfwf(client, objectid, id):
  517. db = client["baojia"]
  518. collection = db["Dwgc"]
  519. document = await collection.find_one({"Dwgcbh": id, "biao_id": objectid})
  520. return document['zcbfwf']
  521. async def getFbrgycl(client, objectid, id):
  522. db = client["baojia"]
  523. collection = db["Dwgc"]
  524. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  525. return document['fbrgycl']
  526. async def getRcjhz(client, objectid, id):
  527. db = client["baojia"]
  528. collection = db["Dwgc"]
  529. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  530. return document['rcjhz']
  531. async def getZjcs(client, objectid, id):
  532. db = client["baojia"]
  533. collection = db["Dwgc"]
  534. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  535. return document['zjcs']
  536. async def getDjcs(client, objectid, id):
  537. db = client["baojia"]
  538. collection = db["Djcs"]
  539. result = []
  540. async for post in collection.find({"Dwgcbh": id, "biao_id": objectid}):
  541. ##post["ID"] = post["_id"]
  542. del post["_id"]
  543. ##print( post["rcj"])
  544. ## del post["DogNum"]
  545. result.append(post)
  546. return result
  547. async def getDjcsQingdanrcj(client, name, bh, bt, bm):
  548. db = client["baojia"]
  549. collection = db["Djcs"]
  550. document = await collection.find_one({ "Dwgcbh": bh, "清单编码": bm, "biao_id": name})
  551. result = document["rcj"]
  552. return result
  553. async def getDjcsDingercj(client, name, bh, bt, qdbm, debm):
  554. db = client["baojia"]
  555. collection = db["Djcs"]
  556. document = await collection.find_one({"Dwgcbh": bh, "清单编码": qdbm, "biao_id": name})
  557. children = document["__children"]
  558. result = []
  559. for child in children:
  560. if child["清单编码"] == debm:
  561. result = child["dercj"]
  562. return result
  563. async def getQdxm(client, name, bh):
  564. db = client["baojia"]
  565. collection = db["Dwgc"]
  566. document = await collection.find_one({'biao_id': name, "Dwgcbh": bh})
  567. if document:
  568. return document['qdbt']
  569. else:
  570. return []
  571. async def getQdmx(client, name, bh, bt):
  572. db = client["baojia"]
  573. collection = db["qdxm"]
  574. result = []
  575. async for post in collection.find({'biao_id': name, "Dwgcbh": bh, "bt": bt}):
  576. ##post["ID"] = post["_id"]
  577. del post["_id"]
  578. #del post["rcj"]
  579. #del post["DogNum"]
  580. result.append(post)
  581. return result
  582. async def getQingdanrcj(client, name, bh, bt, bm):
  583. db = client["baojia"]
  584. collection = db["qdxm"]
  585. document = await collection.find_one({ "Dwgcbh": bh, "清单编码": bm, "biao_id": name, "bt": bt})
  586. result = document["rcj"]
  587. return result
  588. async def getDingercj(client, name, bh, bt, qdbm, debm):
  589. db = client["baojia"]
  590. collection = db["qdxm"]
  591. document = await collection.find_one({"Dwgcbh": bh, "清单编码": qdbm, "biao_id": name, "bt": bt})
  592. result = []
  593. if "__children" in document:
  594. children = document["__children"]
  595. for child in children:
  596. if child["清单编码"] == debm:
  597. result = child["dercj"]
  598. return result
  599. async def getQufei(client, id):
  600. db = client["baojia"]
  601. collection = db["qufei"]
  602. document = await collection.find_one({'biao_id': id})
  603. return document['qufei']
  604. async def searchde(client, zhuanye, text):
  605. db = client["dinge"]
  606. collection = db["de-collection"]
  607. result = []
  608. async for post in collection.find({'$text': {"$search": "\"" + text + "\""}, "zhuanye": zhuanye}):
  609. result.append(post["DEBH"] + " " + post['GCLMC'] )
  610. if len(result) > 10:
  611. break
  612. return result
  613. ##################################editor##########################
  614. async def updatezjcs(client, id, bh, mc, fl):
  615. db = client["baojia"]
  616. collection = db["Dwgc"]
  617. document = await collection.find_one({'biao_id': id, 'Dwgcbh': bh}, {'rcjhz': 0})
  618. zjcs = document['zjcs']
  619. for entry in zjcs:
  620. if entry['名称'] == mc:
  621. entry['费率'] = fl
  622. entry['金额'] = str(float(entry['计算基数']) * float(fl) / float(100))
  623. await collection.update_one({'biao_id': id, "Dwgcbh": bh}, {'$set': {'zjcs': zjcs}})
  624. async def save(client, data):
  625. db = client["baojia"]
  626. collection = db["qdxm"]
  627. biao_id = None
  628. bh = None
  629. for entry in data:
  630. entry["__children"] = entry["_children"]
  631. del entry["_children"]
  632. biao_id = entry['biao_id']
  633. bh = entry['Dwgcbh']
  634. await collection.replace_one({"biao_id": entry["biao_id"], "Dwgcbh": entry["Dwgcbh"], "bt": entry["bt"], "清单编码": entry["清单编码"]}, entry)
  635. if not biao_id:
  636. return {"result" : "ok"}
  637. rcjhz = []
  638. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  639. qdrcj = post['rcj'][1:]
  640. for entry in qdrcj:
  641. entry[10] = float(entry[10]) * float(post['数量'])
  642. rcjhz = rcjhz + qdrcj
  643. collection = db["Djcs"]
  644. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  645. qdrcj = post['rcj'][1:]
  646. for entry in qdrcj:
  647. entry[10] = float(entry[10]) * float(post['数量'])
  648. rcjhz = rcjhz + qdrcj
  649. newHuizong = util.huizongrcj(rcjhz)
  650. collection = db["Dwgc"]
  651. await collection.update_one({'biao_id': biao_id, 'Dwgcbh': bh}, {'$set': {'rcjhz' : newHuizong}})
  652. await zongjiaDwgc(client, biao_id, bh)
  653. await tbxx(client, biao_id)
  654. return {"result": "ok"}
  655. async def savedjcs(client, data):
  656. db = client["baojia"]
  657. collection = db["Djcs"]
  658. biao_id = None
  659. bh = None
  660. for entry in data:
  661. entry["__children"] = entry["_children"]
  662. del entry["_children"]
  663. biao_id = entry['biao_id']
  664. bh = entry['Dwgcbh']
  665. await collection.replace_one({"biao_id": entry["biao_id"], "Dwgcbh": entry["Dwgcbh"], "清单编码": entry["清单编码"]}, entry)
  666. if not biao_id:
  667. return {"result" : "ok"}
  668. rcjhz = []
  669. collection = db["qdxm"]
  670. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  671. qdrcj = post['rcj'][1:]
  672. for entry in qdrcj:
  673. entry[10] = float(entry[10]) * float(post['数量'])
  674. rcjhz = rcjhz + qdrcj
  675. collection = db["Djcs"]
  676. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  677. qdrcj = post['rcj'][1:]
  678. for entry in qdrcj:
  679. entry[10] = float(entry[10]) * float(post['数量'])
  680. rcjhz = rcjhz + qdrcj
  681. newHuizong = util.huizongrcj(rcjhz)
  682. collection = db["Dwgc"]
  683. await collection.update_one({'biao_id': biao_id, 'Dwgcbh': bh}, {'$set': {'rcjhz' : newHuizong}})
  684. await zongjiaDwgc(client, biao_id, bh)
  685. await tbxx(client, biao_id)
  686. return {"result": "ok"}
  687. async def applyFL(client, id, data):
  688. db = client["baojia"]
  689. collection = db["qufei"]
  690. await collection.replace_one({"biao_id": id}, {"biao_id": id, "qufei": data})
  691. collection = db['qdxm']
  692. xm = data[0]
  693. for dxgc in xm["children"]:
  694. for dwgc in dxgc["children"]:
  695. bh = dwgc['key']
  696. glf = float(dwgc['管理费(%)'])
  697. lr = float(dwgc['利润(%)'])
  698. bz = dwgc['备注']
  699. ##print(bh+glf+lr+bz)
  700. async for post in collection.find({'biao_id': id, "Dwgcbh": bh}):
  701. rgfs = float(post['人工费'])
  702. clfs = float(post['材料费'])
  703. jxfs = float(post['机械费'])
  704. sl = float(post['数量'])
  705. if rgfs < 0.0001 and clfs < 0.0001 and jxfs < 0.0001:
  706. continue
  707. ##danxiang = False
  708. for child in post['__children']:##一条定额
  709. bm = child['清单编码']
  710. if bm.startswith("D"):
  711. ##danxiang = True
  712. continue
  713. rgf = float(child['人工费'])
  714. clf = float(child['材料费'])
  715. jxf = float(child['机械费'])
  716. zhdj = float(child['综合单价'])
  717. sl_ = float(child['数量'])
  718. if len(bz) == 0:
  719. ##常规计算
  720. child['管理费'] = (rgf + jxf) * glf / float(100)
  721. child['利润'] = (rgf + jxf) * lr / float(100)
  722. child['综合单价'] = rgf + clf + jxf + child['管理费'] + child['利润']
  723. child['合价'] = sl * sl_ * child['综合单价']
  724. else:
  725. child['管理费'] = (rgf) * glf / float(100)
  726. child['利润'] = (rgf) * lr / float(100)
  727. child['综合单价'] = rgf + clf + jxf + child['管理费'] + child['利润']
  728. child['合价'] = sl * sl_ * child['综合单价']
  729. if True:
  730. post['管理费'] = 0
  731. post['利润'] = 0
  732. for entry in post['__children']:
  733. post['管理费'] = post['管理费'] + float(entry['管理费']) * float(entry['数量'])
  734. post['利润'] = post['利润'] + float(entry['利润']) * float(entry['数量'])
  735. post['管理费'] = str(post['管理费'])
  736. post['利润'] = str(post['利润'])
  737. post['综合单价'] = str(float(post['人工费']) + float(post['材料费']) + float(post['机械费']) + float(post['管理费']) + float(post['利润']))
  738. post['合价'] = str(float(post['综合单价']) * float(post['数量']))
  739. await collection.replace_one({'_id': post['_id']}, post )
  740. collection = db['Djcs']
  741. for dxgc in xm["children"]:
  742. for dwgc in dxgc["children"]:
  743. bh = dwgc['key']
  744. glf = float(dwgc['管理费(%)'])
  745. lr = float(dwgc['利润(%)'])
  746. bz = dwgc['备注']
  747. ##print(bh+glf+lr+bz)
  748. async for post in collection.find({'biao_id': id, "Dwgcbh": bh}):
  749. rgfs = float(post['人工费'])
  750. clfs = float(post['材料费'])
  751. jxfs = float(post['机械费'])
  752. sl = float(post['数量'])
  753. if rgfs < 0.0001 and clfs < 0.0001 and jxfs < 0.0001:
  754. continue
  755. ##danxiang = False##一般有单项定额的,清单就一条定额,就是这个单项定额
  756. for child in post['__children']:
  757. bm = child['清单编码']
  758. if bm.startswith("D"):
  759. ##danxiang = True
  760. continue
  761. rgf = float(child['人工费'])
  762. clf = float(child['材料费'])
  763. jxf = float(child['机械费'])
  764. zhdj = float(child['综合单价'])
  765. sl_ = float(child['数量'])
  766. if len(bz) == 0:
  767. ##常规计算
  768. child['管理费'] = (rgf + jxf) * glf / float(100)
  769. child['利润'] = (rgf + jxf) * lr / float(100)
  770. child['综合单价'] = rgf + clf + jxf + child['管理费'] + child['利润']
  771. child['合价'] = sl * sl_ * child['综合单价']
  772. else:
  773. child['管理费'] = (rgf) * glf / float(100)
  774. child['利润'] = (rgf) * lr / float(100)
  775. child['综合单价'] = rgf + clf + jxf + child['管理费'] + child['利润']
  776. child['合价'] = sl * sl_ * child['综合单价']
  777. if True:
  778. post['管理费'] = 0
  779. post['利润'] = 0
  780. for entry in post['__children']:
  781. post['管理费'] = post['管理费'] + float(entry['管理费']) * float(entry['数量'])
  782. post['利润'] = post['利润'] + float(entry['利润']) * float(entry['数量'])
  783. post['管理费'] = str(post['管理费'])
  784. post['利润'] = str(post['利润'])
  785. post['综合单价'] = str(float(post['人工费']) + float(post['材料费']) + float(post['机械费']) + float(post['管理费']) + float(post['利润']))
  786. post['合价'] = str(float(post['综合单价']) * float(post['数量']))
  787. await collection.replace_one({'_id': post['_id']}, post )
  788. for dxgc in xm["children"]:
  789. for dwgc in dxgc["children"]:
  790. bh = dwgc['key']
  791. await zongjiaDwgc(client, id, bh)
  792. await tbxx(client, id)
  793. return {"result": "ok"}
  794. async def tiaojia(client, biao_id, bh, bm, mingcheng, danwei, jiage, glf, lr, bz):
  795. db = client["baojia"]
  796. collection = db["qdxm"]
  797. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}):
  798. if "__children" not in post:
  799. ##print(post)
  800. continue
  801. children = post["__children"]
  802. qdsl = post['数量']
  803. hit = False
  804. for entry in children:###对一条定额,调价
  805. hitde = False
  806. dercj = entry["dercj"]
  807. dergf = 0
  808. declf = 0
  809. dejxf = 0
  810. for i in range(1, len(dercj)):
  811. rcj = dercj[i]
  812. if rcj[1] == bm and rcj[2] == mingcheng and rcj[4] == danwei:
  813. hit = True
  814. hitde = True
  815. rcj[5] = jiage
  816. hanliang = rcj[10]
  817. rcj[11] = str(float(jiage) * float(hanliang))
  818. if int(rcj[8]) == 1:
  819. dergf = dergf + float(rcj[11])
  820. elif int(rcj[8]) == 2:
  821. declf = declf + float(rcj[11])
  822. elif int(rcj[8]) == 3:
  823. dejxf = dejxf + float(rcj[11])
  824. if hitde:
  825. entry['人工费'] = str(dergf)
  826. entry['辅材费'] = str(declf)
  827. entry['材料费'] = str(declf)
  828. entry['机械费'] = str(dejxf)
  829. if bm.startswith("D"):
  830. entry['管理费'] = '0'
  831. entry['利润'] = '0'
  832. elif bz == 0:
  833. entry['管理费'] = str((dergf + dejxf) * float(glf) / float(100))
  834. entry['利润'] = str((dergf + dejxf) * float(lr) / float(100))
  835. else:
  836. entry['管理费'] = str((dergf) * float(glf) / float(100))
  837. entry['利润'] = str((dergf) * float(lr) / float(100))
  838. entry['综合单价'] = str(float(entry['人工费']) + float(entry['材料费']) + float(entry['机械费']) + float(entry['管理费']) + float(entry['利润']))
  839. entry['合价'] = str(float(entry['综合单价']) * float(entry['数量']) * float(qdsl))
  840. if hit:
  841. ##调整清单
  842. qdrcj = post['rcj']
  843. qdrgf = 0
  844. qdclf = 0
  845. qdjxf = 0
  846. for i in range(1, len(qdrcj)):
  847. entry = qdrcj[i]
  848. if entry[1] == bm and entry[2] == mingcheng and entry[4] == danwei:
  849. entry[5] = jiage
  850. hanliang = entry[10]
  851. entry[11] = str(float(jiage) * float(hanliang))
  852. if int(entry[8]) == 1:
  853. qdrgf = qdrgf + float(entry[11])
  854. elif int(entry[8]) == 2:
  855. qdclf = qdclf + float(entry[11])
  856. elif int(entry[8]) == 3:
  857. qdjxf = qdjxf + float(entry[11])
  858. post['人工费'] = str(qdrgf)
  859. post['辅材费'] = str(qdclf)
  860. post['材料费'] = str(qdclf)
  861. post['机械费'] = str(qdjxf)
  862. post['管理费'] = 0
  863. post['利润'] = 0
  864. for entry in children:
  865. post['管理费'] = post['管理费'] + float(entry['管理费']) * float(entry['数量'])
  866. post['利润'] = post['利润'] + float(entry['利润']) * float(entry['数量'])
  867. post['管理费'] = str(post['管理费'])
  868. post['利润'] = str(post['利润'])
  869. post['综合单价'] = str(float(post['人工费']) + float(post['材料费']) + float(post['机械费']) + float(post['管理费']) + float(post['利润']))
  870. post['合价'] = str(float(post['综合单价']) * float(qdsl))
  871. print(post)
  872. await collection.replace_one({'_id': post['_id']}, post )
  873. collection = db["Djcs"]
  874. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}):
  875. children = post["__children"]
  876. qdsl = post['数量']
  877. hit = False
  878. for entry in children:###对一条定额,调价
  879. hitde = False
  880. dercj = entry["dercj"]
  881. dergf = 0
  882. declf = 0
  883. dejxf = 0
  884. for i in range(1, len(dercj)):
  885. rcj = dercj[i]
  886. if rcj[1] == bm and rcj[2] == mingcheng and rcj[4] == danwei:
  887. hit = True
  888. hitde = True
  889. rcj[5] = jiage
  890. hanliang = rcj[10]
  891. rcj[11] = str(float(jiage) * float(hanliang))
  892. if int(rcj[8]) == 1:
  893. dergf = dergf + float(rcj[11])
  894. elif int(rcj[8]) == 2:
  895. declf = declf + float(rcj[11])
  896. elif int(rcj[8]) == 3:
  897. dejxf = dejxf + float(rcj[11])
  898. if hitde:
  899. entry['人工费'] = str(dergf)
  900. entry['辅材费'] = str(declf)
  901. entry['材料费'] = str(declf)
  902. entry['机械费'] = str(dejxf)
  903. if bm.startswith("D"):
  904. entry['管理费'] = '0'
  905. entry['利润'] = '0'
  906. elif bz == 0:
  907. entry['管理费'] = str((dergf + dejxf) * float(glf) / float(100))
  908. entry['利润'] = str((dergf + dejxf) * float(lr) / float(100))
  909. else:
  910. entry['管理费'] = str((dergf) * float(glf) / float(100))
  911. entry['利润'] = str((dergf) * float(lr) / float(100))
  912. entry['综合单价'] = str(float(entry['人工费']) + float(entry['材料费']) + float(entry['机械费']) + float(entry['管理费']) + float(entry['利润']))
  913. entry['合价'] = str(float(entry['综合单价']) * float(entry['数量']) * float(qdsl))
  914. if hit:
  915. ##调整清单
  916. qdrcj = post['rcj']
  917. qdrgf = 0
  918. qdclf = 0
  919. qdjxf = 0
  920. for i in range(1, len(qdrcj)):
  921. entry = qdrcj[i]
  922. if entry[1] == bm and entry[2] == mingcheng and entry[4] == danwei:
  923. entry[5] = jiage
  924. hanliang = entry[10]
  925. entry[11] = str(float(jiage) * float(hanliang))
  926. if int(entry[8]) == 1:
  927. qdrgf = qdrgf + float(entry[11])
  928. elif int(entry[8]) == 2:
  929. qdclf = qdclf + float(entry[11])
  930. elif int(entry[8]) == 3:
  931. qdjxf = qdjxf + float(entry[11])
  932. post['人工费'] = str(qdrgf)
  933. post['辅材费'] = str(qdclf)
  934. post['材料费'] = str(qdclf)
  935. post['机械费'] = str(qdjxf)
  936. post['管理费'] = 0
  937. post['利润'] = 0
  938. for entry in children:
  939. post['管理费'] = post['管理费'] + float(entry['管理费']) * float(entry['数量'])
  940. post['利润'] = post['利润'] + float(entry['利润']) * float(entry['数量'])
  941. post['管理费'] = str(post['管理费'])
  942. post['利润'] = str(post['利润'])
  943. post['综合单价'] = str(float(post['人工费']) + float(post['材料费']) + float(post['机械费']) + float(post['管理费']) + float(post['利润']))
  944. post['合价'] = str(float(post['综合单价']) * float(qdsl))
  945. await collection.replace_one({'_id': post['_id']}, post )
  946. collection = db["Dwgc"]
  947. document = await collection.find_one({'biao_id': biao_id, "Dwgcbh": bh})
  948. hz = document['rcjhz']
  949. for entry in hz:
  950. if entry[1] == bm and entry[2] == mingcheng and entry[4] == danwei:
  951. entry[6] = jiage
  952. entry[7] = float(jiage) * float(entry[5])
  953. await collection.update_one({'biao_id': biao_id, "Dwgcbh": bh}, {'$set': {'rcjhz': hz}})
  954. await zongjiaDwgc(client, biao_id, bh)
  955. await tbxx(client, biao_id)
  956. def bjhz_template():
  957. result = []
  958. result.append({'序号': '1', '名称': '分部分项工程', '金额': '0', '暂估价': '0', '类别' : '1', '__children': [
  959. {'序号': '1.1', '名称': '人工费', '金额': '0', '暂估价': '0', '类别' : '1.1'},
  960. {'序号': '1.2', '名称': '材料费', '金额': '0', '暂估价': '0', '类别' : '1.2'},
  961. {'序号': '1.3', '名称': '施工机具使用费', '金额': '0', '暂估价': '0', '类别' : '1.3'},
  962. {'序号': '1.4', '名称': '企业管理费', '金额': '0', '暂估价': '0', '类别' : '1.4'},
  963. {'序号': '1.5', '名称': '利润', '金额': '0', '暂估价': '0', '类别' : '1.5'}
  964. ]})
  965. result.append({'序号': '2', '名称': '措施项目', '金额': '0', '暂估价': '0', '类别' : '2', '__children': [
  966. {'序号': '2.1', '名称': '单价措施项目费', '金额': '0', '暂估价': '0', '类别' : '2.1'},
  967. {'序号': '2.2', '名称': '总价措施项目费', '金额': '0', '暂估价': '0', '类别' : '2.2', '__children' : [
  968. {'序号': '2.2.1', '名称': '其中:安全文明施工措施费', '金额': '0', '暂估价': '0', '类别' : '2.2.1'},]
  969. }
  970. ]})
  971. result.append({'序号': '3', '名称': '其他项目', '金额': '0', '暂估价': '0', '类别' : '3', '__children': [
  972. {'序号': '3.1', '名称': '其中:暂列金额', '金额': '0', '暂估价': '0', '类别' : '3.1'},
  973. {'序号': '3.2', '名称': '其中:专业工程暂估价', '金额': '0', '暂估价': '0', '类别' : '3.2'},
  974. {'序号': '3.3', '名称': '其中:计日工', '金额': '0', '暂估价': '0', '类别' : '3.3'},
  975. {'序号': '3.4', '名称': '其中:总承包服务费', '金额': '0', '暂估价': '0', '类别' : '3.4'},
  976. ]})
  977. result.append({'序号': '4', '名称': '规费', '金额': '0', '暂估价': '0', '类别' : '4', })
  978. result.append({'序号': '5', '名称': '税金', '金额': '0', '暂估价': '0', '类别' : '5', })
  979. result.append({'序号': '6', '名称': '工程造价', '金额': '0', '暂估价': '0', '类别' : '6', })
  980. return result
  981. async def tbxx(client, biao_id):
  982. db = client["baojia"]
  983. collection = db["jingjibiao"]
  984. document = await collection.find_one({'_id': ObjectId(biao_id)})
  985. dxgcxx = document['Dxgcxx']
  986. tbxx = document['TouBiaoXx']
  987. tbxx['Tbzj'] = '0'
  988. tbxx['Zgj'] = '0'
  989. tbxx['Aqwmf'] = '0'
  990. tbxx['Gf'] = '0'
  991. dwdx = {}##单位工程映射单项工程
  992. for dxgc in dxgcxx:
  993. dxgc['Aqwmf'] = '0'
  994. dxgc['Gf'] = '0'
  995. dxgc['Je'] = '0'
  996. dxgc['Zgj'] = '0'
  997. mc = dxgc['Dxgcmc']
  998. Dwgc = dxgc['Dwgc']
  999. for dwgc in Dwgc:
  1000. Dwgcbh = dwgc['Dwgcbh']
  1001. dwdx[Dwgcbh] = dxgc
  1002. collection = db['Dwgc']
  1003. async for post in collection.find({'biao_id': biao_id}):
  1004. bh = post['Dwgcbh']
  1005. dx = dwdx[bh]
  1006. bjhz = post['bjhz']
  1007. qtxm = post['qtxm']
  1008. dx['Aqwmf'] = str(float(dx['Aqwmf']) + float(bjhz[1]['__children'][1]['__children'][0]['金额']))
  1009. dx['Gf'] = str(float(dx['Gf']) + float(bjhz[3]['金额']))
  1010. dx['Je'] = str(float(dx['Je']) + float(bjhz[5]['金额']))
  1011. dx['Zgj']= str(float(dx['Zgj']) + float(qtxm[1]['金额']))
  1012. for dxgc in dxgcxx:
  1013. tbxx['Tbzj'] = str(float(tbxx['Tbzj']) + float(dxgc['Je']))
  1014. tbxx['Zgj'] = str(float(tbxx['Zgj']) + float(dxgc['Zgj']))
  1015. tbxx['Aqwmf'] = str(float(tbxx['Aqwmf']) + float(dxgc['Aqwmf']))
  1016. tbxx['Gf'] = str(float(tbxx['Gf']) + float(dxgc['Gf']))
  1017. collection = db["jingjibiao"]
  1018. await collection.update_one({'_id': ObjectId(biao_id)}, {'$set': {'Dxgcxx': dxgcxx, 'TouBiaoXx' : tbxx}})
  1019. async def zongjiaDwgc(client, biao_id, bh):
  1020. db = client["baojia"]
  1021. collection = db["qdxm"]
  1022. qd_sum = 0
  1023. djcs_sum = 0
  1024. rgf_sum = 0
  1025. clf_sum = 0
  1026. jxf_sum = 0
  1027. glf_sum = 0
  1028. lr_sum = 0
  1029. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  1030. qd_sum = qd_sum + float(post['合价'])
  1031. rgf_sum = rgf_sum + float(post['数量']) * float(post['人工费'])
  1032. clf_sum = clf_sum + float(post['数量']) * float(post['材料费'])
  1033. jxf_sum = jxf_sum + float(post['数量']) * float(post['机械费'])
  1034. glf_sum = glf_sum + float(post['数量']) * float(post['管理费'])
  1035. lr_sum = lr_sum + float(post['数量']) * float(post['利润'])
  1036. collection = db["Djcs"]
  1037. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  1038. djcs_sum = djcs_sum + float(post['合价'])
  1039. sum = qd_sum + djcs_sum
  1040. collection = db['Dwgc']
  1041. document = await collection.find_one({'biao_id': biao_id, "Dwgcbh": bh}, {'rcjhz': 0})
  1042. zjcs = document['zjcs']
  1043. def process(n):
  1044. n['计算基数'] = str(sum)
  1045. n['金额'] = float(sum) * float(n['费率']) / float(100)
  1046. if "__children" in n:
  1047. for entry in n['__children']:
  1048. entry['计算基数'] = str(sum)
  1049. entry['金额'] = float(sum) * float(entry['费率']) / float(100)
  1050. return n
  1051. result = [process(item) for item in zjcs]
  1052. for entry in result:
  1053. if '安全文明施工' in entry['名称']:
  1054. sum_ = 0
  1055. for child in entry['__children']:
  1056. sum_ = sum_ + float(child['金额'])
  1057. entry['金额'] = str(sum_)
  1058. entry['计算基数'] = str(sum_)
  1059. zjcs_sum = 0
  1060. for entry in result:
  1061. zjcs_sum = zjcs_sum + float(entry['金额'])
  1062. qtxm = document['qtxm']##dwgc qtxm
  1063. qtxm_sum = 0
  1064. for entry in qtxm:
  1065. qtxm_sum = qtxm_sum + float(entry['金额'])
  1066. gfsj = document['gfsj']
  1067. gf_sum = 0
  1068. sj_sum = 0
  1069. for item in gfsj:
  1070. if item['名称'] == '规费':
  1071. child = item['__children']
  1072. for children in child:
  1073. children['取费基数'] = str(sum + zjcs_sum + qtxm_sum)
  1074. children['金额'] = str(float(sum + zjcs_sum + qtxm_sum) * float(children['费率']) / float(100))
  1075. gf_sum = gf_sum + float(children['金额'])
  1076. for item in gfsj:
  1077. if item['名称'] == '规费':
  1078. item['取费基数'] = str(gf_sum)
  1079. item['金额'] = str(gf_sum)
  1080. for item in gfsj:
  1081. if item['名称'] == '税金':
  1082. item['取费基数'] = str(sum + zjcs_sum + qtxm_sum + gf_sum)
  1083. item['金额'] = float(item['取费基数']) * float(item['费率']) / float(100)
  1084. sj_sum = float(item['金额'])
  1085. for item in gfsj:
  1086. if item['名称'] == '合计':
  1087. item['取费基数'] = str(sj_sum + gf_sum)
  1088. item['金额'] = item['取费基数']
  1089. qtxm = document['qtxm']
  1090. zlje = 0
  1091. zygczgj = 0
  1092. jrg = 0
  1093. zcbfwf = 0
  1094. clzgj = 0
  1095. for entry in qtxm:
  1096. if entry['序号'] == '1':
  1097. zlje = entry['金额']
  1098. if entry['序号'] == '3':
  1099. jrg = entry['金额']
  1100. if entry['序号'] == '4':
  1101. zcbfwf = entry['金额']
  1102. if entry['序号'] == '2':
  1103. for child in entry['__children']:
  1104. if child['序号'] == '2.2':
  1105. zygczgj = child['金额']
  1106. if child['序号'] == '2.1':
  1107. clzgj = child['金额']
  1108. qtxm_sum = float(zlje) + float(zygczgj) + float(jrg) + float(zcbfwf) + float(clzgj)
  1109. bjhz = bjhz_template()
  1110. for entry in bjhz:
  1111. if entry['序号'] == '1':
  1112. entry['金额'] = qd_sum
  1113. for child in entry['__children']:
  1114. if child['序号'] == '1.1':
  1115. child['金额'] = str(rgf_sum)
  1116. if child['序号'] == '1.2':
  1117. child['金额'] = str(clf_sum)
  1118. if child['序号'] == '1.3':
  1119. child['金额'] = str(jxf_sum)
  1120. if child['序号'] == '1.4':
  1121. child['金额'] = str(glf_sum)
  1122. if child['序号'] == '1.5':
  1123. child['金额'] = str(lr_sum)
  1124. if entry['序号'] == '2':
  1125. entry['金额'] = str(djcs_sum + zjcs_sum)
  1126. for child in entry['__children']:
  1127. if child['序号'] == '2.1':
  1128. child['金额'] = str(djcs_sum)
  1129. if child['序号'] == '2.2':
  1130. child['金额'] = str(zjcs_sum)
  1131. for grandchild in child['__children']:
  1132. if grandchild['序号'] == '2.2.1':
  1133. grandchild['金额'] = str(sum_)
  1134. if entry['序号'] == '3':
  1135. entry['金额'] = str(qtxm_sum)
  1136. if entry['序号'] == '4':
  1137. entry['金额'] = str(gf_sum)
  1138. if entry['序号'] == '5':
  1139. entry['金额'] = str(sj_sum)
  1140. if entry['序号'] == '6':
  1141. entry['金额'] = str(float(qd_sum) + float(djcs_sum) + float(zjcs_sum) + float(qtxm_sum) + float(gf_sum) + float(sj_sum))
  1142. await collection.update_one({'biao_id': biao_id, "Dwgcbh": bh}, {'$set': {'zjcs': result, 'gfsj' : gfsj, 'bjhz': bjhz}})