db.py 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921
  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. qdbt_addition = service.getQdxm_addition(root, entry["bh"])
  346. zygczgj = service.getZygczgj(root, entry["bh"])
  347. Dwgc = {}
  348. Dwgc["bjhz"] = bjhz
  349. Dwgc["gfsj"] = gfsj
  350. Dwgc["qtxm"] = qtxm
  351. Dwgc["zlje"] = zlje
  352. Dwgc["jrg"] = jrg
  353. Dwgc['zygczgj'] = zygczgj
  354. Dwgc["zcbfwf"] = zcbfwf
  355. Dwgc["fbrgycl"] = fbrgycl
  356. Dwgc["rcjhz"] = rcjhz
  357. Dwgc["zjcs"] = zjcs
  358. Dwgc["qdbt"] = qdbt
  359. Dwgc['qdbt_addition'] = qdbt_addition
  360. Dwgc["DogNum"] = entry["num"]
  361. Dwgc["Dwgcbh"] = entry["bh"]
  362. Dwgc["biao_id"] = biao_id
  363. await collection.insert_one(Dwgc)
  364. collection = db["Djcs"]
  365. for entry in Dwgcbh:
  366. djcs = service.getDjcs(root, entry["bh"])
  367. for cs in djcs:
  368. cs["DogNum"] = entry["num"]
  369. cs["Dwgcbh"] = entry["bh"]
  370. cs["biao_id"] = biao_id
  371. rcj = getDjcsQingdanrcj_(root, entry["bh"], "", cs['清单编码'])
  372. cs["rcj"] = rcj
  373. if "__children" in cs:
  374. children = cs["__children"]
  375. for child in children:
  376. dercj = getDjcsDingercj_(root, entry["bh"], "", cs["清单编码"], child["清单编码"])
  377. child["dercj"] = dercj
  378. child['fuzhuEnable'] = False
  379. await collection.insert_one(cs)
  380. collection = db["qdxm"]
  381. for entry in Dwgcbh:
  382. bts = service.getQdxm(root, entry["bh"])
  383. for bt in bts:
  384. print("###################")
  385. print(entry['bh'])
  386. print(bt)
  387. qdmx = service.getQdmx(root, entry["bh"], bt)
  388. for qd in qdmx:
  389. qd["DogNum"] = entry["num"]
  390. qd["Dwgcbh"] = entry["bh"]
  391. qd["biao_id"] = biao_id
  392. qd["bt"] = bt
  393. rcj = getQingdanrcj_(root, entry["bh"], bt, qd["清单编码"])
  394. qd["rcj"] = rcj
  395. if "__children" in qd:
  396. children = qd["__children"]
  397. for child in children:
  398. dercj = getDingercj_(root, entry["bh"], bt, qd["清单编码"], child["清单编码"])
  399. child["dercj"] = dercj
  400. child['fuzhuEnable'] = False
  401. await collection.insert_one(qd)
  402. collection = db["qufei"]
  403. document = jingjibiao
  404. dxgc = document['Dxgcxx']
  405. result = []
  406. for entry in dxgc:
  407. newone = {"名称" : entry['Dxgcmc'], "工程类型":"", "工程类别": "", "管理费(%)": "", "利润(%)": "","备注":"", "key" : str(uuid.uuid4()) }
  408. children = []
  409. for dwgc in entry['Dwgc']:
  410. children.append({"名称" : dwgc['Dwgcmc'], "工程类型":"", "工程类别": "", "管理费(%)": "", "利润(%)": "","备注":"", "key" : dwgc['Dwgcbh']})
  411. newone["children"] = children
  412. result.append(newone)
  413. await collection.insert_one({"biao_id": biao_id, "qufei": [{
  414. "名称" : document['Xmmc'], "工程类型":"", "工程类别": "", "管理费(%)": "", "利润(%)": "","备注":"", "key" : str(uuid.uuid4()), "children" : result
  415. }]})
  416. collection = db["jingjibiao"]
  417. await collection.update_one({'_id': ObjectId(biao_id)}, {'$set': {'visible': True}})
  418. def dfs(items):
  419. result = []
  420. for entry in items:
  421. result.append([entry['序号'], entry['名称'], entry['金额'], entry['暂估价'], entry['类别']])
  422. if '__children' in entry:
  423. result_ = dfs(entry['__children'])
  424. for r in result_:
  425. result.append(r)
  426. return result
  427. def dfs2(items):
  428. result = []
  429. for entry in items:
  430. result.append([entry['序号'], entry['名称'], entry['取费基数'], entry['计算基础'], entry['费率'], entry['金额'], entry['类别']])
  431. if '__children' in entry:
  432. result_ = dfs2(entry['__children'])
  433. for r in result_:
  434. result.append(r)
  435. return result
  436. def dfs3(items):
  437. result = []
  438. for entry in items:
  439. result.append([entry['序号'], entry['名称'], entry['金额'], entry['项目类别'], entry['备注']])
  440. if '__children' in entry:
  441. result_ = dfs3(entry['__children'])
  442. for r in result_:
  443. result.append(r)
  444. return result
  445. async def build(client, root, id):
  446. db = client["baojia"]
  447. collection = db["jingjibiao"]
  448. document = await collection.find_one({'_id': ObjectId(id)})
  449. root.set('BiaoDuanNO', document['BiaoDuanNO'])
  450. root.set('Jsfs', document['Jsfs'])
  451. root.set('Version', document['Version'])
  452. root.set('Xmmc', document['Xmmc'])
  453. TouBiaoXx = ET.SubElement(root, 'TouBiaoXx')
  454. ##{'Tbzj' : '', 'Zgj' : '', 'Aqwmf' : '', 'Gf' : '' }
  455. TouBiaoXx.set('Tbzj', str(document['TouBiaoXx']['Tbzj']))
  456. TouBiaoXx.set('Zgj', str(document['TouBiaoXx']['Zgj']))
  457. TouBiaoXx.set('Aqwmf', str(document['TouBiaoXx']['Aqwmf']))
  458. TouBiaoXx.set('Gf', str(document['TouBiaoXx']['Gf']))
  459. if 'Zbr' in document['TouBiaoXx']:
  460. TouBiaoXx.set('Zbr', str(document['TouBiaoXx']['Zbr']))
  461. if 'Tbr' in document['TouBiaoXx']:
  462. TouBiaoXx.set('Tbr', str(document['TouBiaoXx']['Tbr']))
  463. if 'TbrDb' in document['TouBiaoXx']:
  464. TouBiaoXx.set('TbrDb', str(document['TouBiaoXx']['TbrDb']))
  465. if 'Bzr' in document['TouBiaoXx']:
  466. TouBiaoXx.set('Bzr', str(document['TouBiaoXx']['Bzr']))
  467. if 'BzTime' in document['TouBiaoXx']:
  468. TouBiaoXx.set('BzTime', str(document['TouBiaoXx']['BzTime']))
  469. for item in document['Dxgcxx']:
  470. Dxgcxx = ET.SubElement(root, 'Dxgcxx')
  471. Dxgcxx.set('Dxgcbh', str(item['Dxgcbh']))
  472. Dxgcxx.set('Dxgcmc', str(item['Dxgcmc']))
  473. Dxgcxx.set('Je', str(item['Je']))
  474. Dxgcxx.set('Zgj', str(item['Zgj']))
  475. Dxgcxx.set('Aqwmf', str(item['Aqwmf']))
  476. Dxgcxx.set('Gf', str(item['Gf']))
  477. for entry in item['Dwgc']:
  478. Dwgcxx = ET.SubElement(Dxgcxx, 'Dwgcxx')
  479. Dwgcxx.set('Dwgcbh', str(entry['Dwgcbh']))
  480. Dwgcxx.set('Dwgcmc', str(entry['Dwgcmc']))
  481. Dwgcxx.set('Zylb', str(entry['Zylb']))
  482. Dwgcxx.set('SoftName', str(entry['SoftName']))
  483. Dwgcxx.set('SoftNum', str(entry['SoftNum']))
  484. Dwgcxx.set('DogNum', str(entry['DogNum']))
  485. Dwgcxx.set('MachineKey', str(entry['MachineKey']))
  486. collection = db["Dwgc"]
  487. Dwgc = await collection.find_one({'biao_id': id, "Dwgcbh": entry['Dwgcbh']})
  488. bjhz = dfs(Dwgc['bjhz'])
  489. gfsj = dfs2(Dwgc['gfsj'])
  490. qtxm = dfs3(Dwgc['qtxm'])
  491. zlje = Dwgc['zlje']
  492. zygczgj = Dwgc['zygczgj']
  493. jrg = Dwgc['jrg']
  494. zcbfwf = Dwgc['zcbfwf']
  495. fbrgycl = Dwgc['fbrgycl']
  496. rcjhz = Dwgc['rcjhz']
  497. zjcs = Dwgc['zjcs']
  498. qdbt = Dwgc['qdbt']
  499. ########################################Fywj##########################
  500. Fywj = ET.SubElement(Dwgcxx, 'Fywj')
  501. for bjhz_ in bjhz:
  502. FywjMx = ET.SubElement(Fywj, 'FywjMx')
  503. FywjMx.set('Xh', str(bjhz_[0]))
  504. FywjMx.set('Mc', str(bjhz_[1]))
  505. FywjMx.set('Je', str(bjhz_[2]))
  506. FywjMx.set('Zgj', str(bjhz_[3]))
  507. FywjMx.set('Fyxlb', str(bjhz_[4]))
  508. ########################################Gfsj##########################
  509. Gfsj = ET.SubElement(Dwgcxx, 'Gfsj')
  510. for gfsj_ in gfsj:
  511. GfsjMx = ET.SubElement(Gfsj, 'GfsjMx')
  512. GfsjMx.set('Xh', str(gfsj_[0]))
  513. GfsjMx.set('Mc', str(gfsj_[1]))
  514. GfsjMx.set('Qfjs', str(gfsj_[2]))
  515. GfsjMx.set('Jsjc', str(gfsj_[3]))
  516. GfsjMx.set('Fl', str(gfsj_[4]))
  517. GfsjMx.set('Je', str(gfsj_[5]))
  518. GfsjMx.set('Fyxlb', str(gfsj_[6]))
  519. Qdxm = ET.SubElement(Dwgcxx, 'Qdxm')
  520. if 'Default' in qdbt:
  521. collection = db["qdxm"]
  522. before_sort = []
  523. async for post in collection.find({"biao_id": id, "Dwgcbh": entry['Dwgcbh']}):
  524. before_sort.append(post)
  525. after_sort = sorted(before_sort, key=lambda x: int(x['序号']))
  526. for qdmx in after_sort:
  527. Qdmx = ET.SubElement(Qdxm, 'Qdmx')
  528. Qdmx.set('Xh', str(qdmx['序号']))
  529. Qdmx.set('Qdbm', str(qdmx['清单编码']))
  530. Qdmx.set('Mc', str(qdmx['名称']))
  531. Qdmx.set('Xmtz', str(qdmx['项目特征']))
  532. Qdmx.set('Jsgz', str(qdmx['计算规则']))
  533. Qdmx.set('Dw', str(qdmx['单位']))
  534. Qdmx.set('Sl', str(qdmx['数量']))
  535. Qdmx.set('Zhdj', str(qdmx['综合单价']))
  536. Qdmx.set('Zhhj', str(qdmx['合价']))
  537. Qdmx.set('Rgf', str(qdmx['人工费']))
  538. Qdmx.set('Zcf', str(qdmx['主材费']))
  539. Qdmx.set('Sbf', str(qdmx['设备费']))
  540. Qdmx.set('Fcf', str(qdmx['辅材费']))
  541. Qdmx.set('Clf', str(qdmx['材料费']))
  542. Qdmx.set('Jxf', str(qdmx['机械费']))
  543. Qdmx.set('Glf', str(qdmx['管理费']))
  544. Qdmx.set('Lr', str(qdmx['利润']))
  545. Qdmx.set('Zgj', str(qdmx['暂估价']))
  546. Qdmx.set('Zgr', str(qdmx['综合人工工日']))
  547. Qdmx.set('Bz', str(qdmx['备注']))
  548. Qdxdezj = ET.SubElement(Qdmx, 'Qdxdezj')
  549. if '__children' in qdmx:
  550. for child in qdmx['__children']:
  551. QdxdezjMx = ET.SubElement(Qdxdezj, 'QdxdezjMx')
  552. QdxdezjMx.set('Debm', str(child['清单编码']))
  553. QdxdezjMx.set('Mc', str(child['名称']))
  554. QdxdezjMx.set('Dw', str(child['单位']))
  555. QdxdezjMx.set('DwQdSl', str(child['数量']))
  556. QdxdezjMx.set('Dj', str(child['综合单价']))
  557. QdxdezjMx.set('Hj', str(child['合价']))
  558. QdxdezjMx.set('Rgf', str(child['人工费']))
  559. QdxdezjMx.set('Zcf', str(child['主材费']))
  560. QdxdezjMx.set('Sbf', str(child['设备费']))
  561. QdxdezjMx.set('Fcf', str(child['辅材费']))
  562. QdxdezjMx.set('Clf', str(child['材料费']))
  563. QdxdezjMx.set('Jxf', str(child['机械费']))
  564. QdxdezjMx.set('Glf', str(child['管理费']))
  565. QdxdezjMx.set('Lr', str(child['利润']))
  566. Qdxdercjhl = ET.SubElement(QdxdezjMx, 'Qdxdercjhl')
  567. for i in range(len(child['dercj'])):
  568. if i == 0:
  569. pass
  570. else:
  571. QdxdercjhlMx = ET.SubElement(Qdxdercjhl, 'QdxdercjhlMx')
  572. QdxdercjhlMx.set('RcjId', util.indexrcj(rcjhz, child['dercj'][i]))
  573. QdxdercjhlMx.set('Rcjhl', str(child['dercj'][i][10]))
  574. QdxdercjhlMx.set('Rcjhj', str(child['dercj'][i][11]))
  575. Qdxrcjhl = ET.SubElement(Qdmx, 'Qdxrcjhl')
  576. for i in range(len(qdmx['rcj'])):
  577. if i == 0:
  578. pass
  579. else:
  580. QdxrcjhlMx = ET.SubElement(Qdxrcjhl, 'QdxrcjhlMx')
  581. QdxrcjhlMx.set('RcjId', util.indexrcj(rcjhz, qdmx['rcj'][i]))
  582. ##str(djcs['rcj'][i][0]))
  583. QdxrcjhlMx.set('Rcjhl', str(qdmx['rcj'][i][10]))
  584. QdxrcjhlMx.set('Rcjhj', str(qdmx['rcj'][i][11]))
  585. QdxrcjhlMx.set('Zgjbz', str(qdmx['rcj'][i][12]))
  586. QdxrcjhlMx.set('Zyclbz', str(qdmx['rcj'][i][13]))
  587. QdxrcjhlMx.set('Zcbz', str(qdmx['rcj'][i][14]))
  588. QdxrcjhlMx.set('Sbbz', str(qdmx['rcj'][i][15]))
  589. else:
  590. qdbt_addition = Dwgc['qdbt_addition']
  591. for bt in qdbt_addition:
  592. QdBt = ET.SubElement(Qdxm, 'QdBt')
  593. QdBt.set('Xh', bt['Xh'])
  594. QdBt.set('Mc', bt['Mc'])
  595. QdBt.set('Je', bt['Je'])
  596. QdBt.set('Zgj', bt['Zgj'])
  597. QdBt.set('Bz', bt['Bz'])
  598. collection = db["qdxm"]
  599. before_sort = []
  600. async for post in collection.find({"biao_id": id, "Dwgcbh": entry['Dwgcbh'], 'bt': bt['Mc']}):
  601. before_sort.append(post)
  602. after_sort = sorted(before_sort, key=lambda x: int(x['序号']))
  603. for qdmx in after_sort:
  604. Qdmx = ET.SubElement(QdBt, 'Qdmx')
  605. Qdmx.set('Xh', str(qdmx['序号']))
  606. Qdmx.set('Qdbm', str(qdmx['清单编码']))
  607. Qdmx.set('Mc', str(qdmx['名称']))
  608. Qdmx.set('Xmtz', str(qdmx['项目特征']))
  609. Qdmx.set('Jsgz', str(qdmx['计算规则']))
  610. Qdmx.set('Dw', str(qdmx['单位']))
  611. Qdmx.set('Sl', str(qdmx['数量']))
  612. Qdmx.set('Zhdj', str(qdmx['综合单价']))
  613. Qdmx.set('Zhhj', str(qdmx['合价']))
  614. Qdmx.set('Rgf', str(qdmx['人工费']))
  615. Qdmx.set('Zcf', str(qdmx['主材费']))
  616. Qdmx.set('Sbf', str(qdmx['设备费']))
  617. Qdmx.set('Fcf', str(qdmx['辅材费']))
  618. Qdmx.set('Clf', str(qdmx['材料费']))
  619. Qdmx.set('Jxf', str(qdmx['机械费']))
  620. Qdmx.set('Glf', str(qdmx['管理费']))
  621. Qdmx.set('Lr', str(qdmx['利润']))
  622. Qdmx.set('Zgj', str(qdmx['暂估价']))
  623. Qdmx.set('Zgr', str(qdmx['综合人工工日']))
  624. Qdmx.set('Bz', str(qdmx['备注']))
  625. Qdxdezj = ET.SubElement(Qdmx, 'Qdxdezj')
  626. if '__children' in qdmx:
  627. for child in qdmx['__children']:
  628. QdxdezjMx = ET.SubElement(Qdxdezj, 'QdxdezjMx')
  629. QdxdezjMx.set('Debm', str(child['清单编码']))
  630. QdxdezjMx.set('Mc', str(child['名称']))
  631. QdxdezjMx.set('Dw', str(child['单位']))
  632. QdxdezjMx.set('DwQdSl', str(child['数量']))
  633. QdxdezjMx.set('Dj', str(child['综合单价']))
  634. QdxdezjMx.set('Hj', str(child['合价']))
  635. QdxdezjMx.set('Rgf', str(child['人工费']))
  636. QdxdezjMx.set('Zcf', str(child['主材费']))
  637. QdxdezjMx.set('Sbf', str(child['设备费']))
  638. QdxdezjMx.set('Fcf', str(child['辅材费']))
  639. QdxdezjMx.set('Clf', str(child['材料费']))
  640. QdxdezjMx.set('Jxf', str(child['机械费']))
  641. QdxdezjMx.set('Glf', str(child['管理费']))
  642. QdxdezjMx.set('Lr', str(child['利润']))
  643. Qdxdercjhl = ET.SubElement(QdxdezjMx, 'Qdxdercjhl')
  644. for i in range(len(child['dercj'])):
  645. if i == 0:
  646. pass
  647. else:
  648. QdxdercjhlMx = ET.SubElement(Qdxdercjhl, 'QdxdercjhlMx')
  649. QdxdercjhlMx.set('RcjId', util.indexrcj(rcjhz, child['dercj'][i]))
  650. QdxdercjhlMx.set('Rcjhl', str(child['dercj'][i][10]))
  651. QdxdercjhlMx.set('Rcjhj', str(child['dercj'][i][11]))
  652. Qdxrcjhl = ET.SubElement(Qdmx, 'Qdxrcjhl')
  653. for i in range(len(qdmx['rcj'])):
  654. if i == 0:
  655. pass
  656. else:
  657. QdxrcjhlMx = ET.SubElement(Qdxrcjhl, 'QdxrcjhlMx')
  658. QdxrcjhlMx.set('RcjId', util.indexrcj(rcjhz, qdmx['rcj'][i]))
  659. ##str(djcs['rcj'][i][0]))
  660. QdxrcjhlMx.set('Rcjhl', str(qdmx['rcj'][i][10]))
  661. QdxrcjhlMx.set('Rcjhj', str(qdmx['rcj'][i][11]))
  662. QdxrcjhlMx.set('Zgjbz', str(qdmx['rcj'][i][12]))
  663. QdxrcjhlMx.set('Zyclbz', str(qdmx['rcj'][i][13]))
  664. QdxrcjhlMx.set('Zcbz', str(qdmx['rcj'][i][14]))
  665. QdxrcjhlMx.set('Sbbz', str(qdmx['rcj'][i][15]))
  666. ########################################Csxm##########################
  667. Csxm = ET.SubElement(Dwgcxx, 'Csxm')
  668. ZjCs = ET.SubElement(Csxm, 'ZjCs')
  669. for zjcs_ in zjcs:
  670. ZjCsMx = ET.SubElement(ZjCs, 'ZjCsMx')
  671. ZjCsMx.set('Xh', str(zjcs_['序号']))
  672. ZjCsMx.set('Bm', str(zjcs_['清单编码']))
  673. ZjCsMx.set('Mc', str(zjcs_['名称']))
  674. ZjCsMx.set('Js', str(zjcs_['计算基数']))
  675. ZjCsMx.set('Jsjc', str(zjcs_['计算基础']))
  676. ZjCsMx.set('Fl', str(zjcs_['费率']))
  677. ZjCsMx.set('Je', str(zjcs_['金额']))
  678. ZjCsMx.set('Xmlb', str(zjcs_['项目类别']))
  679. if '__children' in zjcs_:
  680. AqwmfMx = ET.SubElement(ZjCsMx, 'AqwmfMx')
  681. AqwmfMx.set('Mc', str(zjcs_['__children'][0]['名称']))
  682. AqwmfMx.set('Js', str(zjcs_['__children'][0]['计算基数']))
  683. AqwmfMx.set('Jsjc', str(zjcs_['__children'][0]['计算基础']))
  684. AqwmfMx.set('Fl', str(zjcs_['__children'][0]['费率']))
  685. AqwmfMx.set('Je', str(zjcs_['__children'][0]['金额']))
  686. AqwmfMx.set('Xmlb', str(zjcs_['__children'][0]['项目类别']))
  687. AqwmfMx = ET.SubElement(ZjCsMx, 'AqwmfMx')
  688. AqwmfMx.set('Mc', str(zjcs_['__children'][1]['名称']))
  689. AqwmfMx.set('Js', str(zjcs_['__children'][1]['计算基数']))
  690. AqwmfMx.set('Jsjc', str(zjcs_['__children'][1]['计算基础']))
  691. AqwmfMx.set('Fl', str(zjcs_['__children'][1]['费率']))
  692. AqwmfMx.set('Je', str(zjcs_['__children'][1]['金额']))
  693. AqwmfMx.set('Xmlb', str(zjcs_['__children'][1]['项目类别']))
  694. AqwmfMx = ET.SubElement(ZjCsMx, 'AqwmfMx')
  695. AqwmfMx.set('Mc', str(zjcs_['__children'][2]['名称']))
  696. AqwmfMx.set('Js', str(zjcs_['__children'][2]['计算基数']))
  697. AqwmfMx.set('Jsjc', str(zjcs_['__children'][2]['计算基础']))
  698. AqwmfMx.set('Fl', str(zjcs_['__children'][2]['费率']))
  699. AqwmfMx.set('Je', str(zjcs_['__children'][2]['金额']))
  700. AqwmfMx.set('Xmlb', str(zjcs_['__children'][2]['项目类别']))
  701. DjCs = ET.SubElement(Csxm, 'DjCs')
  702. collection = db["Djcs"]
  703. before_sort = []
  704. async for post in collection.find({"biao_id": id, "Dwgcbh": entry['Dwgcbh']}):
  705. before_sort.append(post)
  706. after_sort = sorted(before_sort, key=lambda x: int(x['序号']))
  707. for djcs in after_sort:
  708. DjCsMx = ET.SubElement(DjCs, 'DjCsMx')
  709. DjCsMx.set('Xh', str(djcs['序号']))
  710. DjCsMx.set('Bm', str(djcs['清单编码']))
  711. DjCsMx.set('Mc', str(djcs['名称']))
  712. DjCsMx.set('Xmtz', str(djcs['项目特征']))
  713. DjCsMx.set('Jsgz', str(djcs['计算规则']))
  714. DjCsMx.set('Dw', str(djcs['单位']))
  715. DjCsMx.set('Sl', str(djcs['数量']))
  716. DjCsMx.set('Zhdj', str(djcs['综合单价']))
  717. DjCsMx.set('Zhhj', str(djcs['合价']))
  718. DjCsMx.set('Rgf', str(djcs['人工费']))
  719. DjCsMx.set('Zcf', str(djcs['主材费']))
  720. DjCsMx.set('Sbf', str(djcs['设备费']))
  721. DjCsMx.set('Fcf', str(djcs['辅材费']))
  722. DjCsMx.set('Clf', str(djcs['材料费']))
  723. DjCsMx.set('Jxf', str(djcs['机械费']))
  724. DjCsMx.set('Glf', str(djcs['管理费']))
  725. DjCsMx.set('Lr', str(djcs['利润']))
  726. DjCsMx.set('Zgj', str(djcs['暂估价']))
  727. DjCsMx.set('Zgr', str(djcs['综合人工工日']))
  728. Csxdezj = ET.SubElement(DjCsMx, 'Csxdezj')
  729. if '__children' in djcs:
  730. for child in djcs['__children']:
  731. CsxdezjMx = ET.SubElement(Csxdezj, 'CsxdezjMx')
  732. CsxdezjMx.set('Debm', str(child['清单编码']))
  733. CsxdezjMx.set('Mc', str(child['名称']))
  734. CsxdezjMx.set('Dw', str(child['单位']))
  735. CsxdezjMx.set('DwQdSl', str(child['数量']))
  736. CsxdezjMx.set('Dj', str(child['综合单价']))
  737. CsxdezjMx.set('Hj', str(child['合价']))
  738. CsxdezjMx.set('Rgf', str(child['人工费']))
  739. CsxdezjMx.set('Zcf', str(child['主材费']))
  740. CsxdezjMx.set('Sbf', str(child['设备费']))
  741. CsxdezjMx.set('Fcf', str(child['辅材费']))
  742. CsxdezjMx.set('Clf', str(child['材料费']))
  743. CsxdezjMx.set('Jxf', str(child['机械费']))
  744. CsxdezjMx.set('Glf', str(child['管理费']))
  745. CsxdezjMx.set('Lr', str(child['利润']))
  746. Csxdercjhl = ET.SubElement(CsxdezjMx, 'Csxdercjhl')
  747. for i in range(len(child['dercj'])):
  748. if i == 0:
  749. pass
  750. else:
  751. CsxdercjhlMx = ET.SubElement(Csxdercjhl, 'CsxdercjhlMx')
  752. CsxdercjhlMx.set('RcjId', util.indexrcj(rcjhz, child['dercj'][i]))
  753. CsxdercjhlMx.set('Rcjhl', str(child['dercj'][i][10]))
  754. CsxdercjhlMx.set('Rcjhj', str(child['dercj'][i][11]))
  755. Csxrcjhl = ET.SubElement(DjCsMx, 'Csxrcjhl')
  756. for i in range(len(djcs['rcj'])):
  757. if i == 0:
  758. pass
  759. else:
  760. CsxrcjhlMx = ET.SubElement(Csxrcjhl, 'CsxrcjhlMx')
  761. CsxrcjhlMx.set('RcjId', util.indexrcj(rcjhz, djcs['rcj'][i]))
  762. ##str(djcs['rcj'][i][0]))
  763. CsxrcjhlMx.set('Rcjhl', str(djcs['rcj'][i][10]))
  764. CsxrcjhlMx.set('Rcjhj', str(djcs['rcj'][i][11]))
  765. CsxrcjhlMx.set('Zgjbz', str(djcs['rcj'][i][12]))
  766. CsxrcjhlMx.set('Zyclbz', str(djcs['rcj'][i][13]))
  767. CsxrcjhlMx.set('Zcbz', str(djcs['rcj'][i][14]))
  768. CsxrcjhlMx.set('Sbbz', str(djcs['rcj'][i][15]))
  769. ########################################Qtxm##########################
  770. Qtxm = ET.SubElement(Dwgcxx, 'Qtxm')
  771. for qtxm_ in qtxm:
  772. QtxmMx = ET.SubElement(Qtxm, 'QtxmMx')
  773. QtxmMx.set('Xh', str(qtxm_[0]))
  774. QtxmMx.set('Mc', str(qtxm_[1]))
  775. QtxmMx.set('Je', str(qtxm_[2]))
  776. QtxmMx.set('Xmlb', str(qtxm_[3]))
  777. QtxmMx.set('Bz', str(qtxm_[4]))
  778. Zlje = ET.SubElement(Dwgcxx, 'Zlje')
  779. for i in range(len(zlje)):
  780. ZljeMx = ET.SubElement(Zlje, 'ZljeMx')
  781. ZljeMx.set('Xh', str(zlje[i]['序号']))
  782. ZljeMx.set('Mc', str(zlje[i]['名称']))
  783. ZljeMx.set('Dw', str(zlje[i]['单位']))
  784. ZljeMx.set('Zdje', str(zlje[i]['暂定金额']))
  785. ZljeMx.set('Bz', str(zlje[i]['备注']))
  786. Clzg = ET.SubElement(Dwgcxx, 'Clzg')
  787. Zygczg = ET.SubElement(Dwgcxx, 'Zygczg')
  788. for zygczgj_ in zygczgj:
  789. ZygczgMx = ET.SubElement(Zygczg, 'ZygczgMx')
  790. ZygczgMx.set('Xh', str(zygczgj_['序号']))
  791. ZygczgMx.set('Mc', str(zygczgj_['名称']))
  792. ZygczgMx.set('Gcnr', str(zygczgj_['工程内容']))
  793. ZygczgMx.set('Je', str(zygczgj_['金额']))
  794. ZygczgMx.set('Bz', str(zygczgj_['备注']))
  795. Jrg = ET.SubElement(Dwgcxx, 'Jrg')
  796. for jrg_ in jrg:
  797. JrgBt = ET.SubElement(Jrg, 'JrgBt')
  798. JrgBt.set('Xh', str(jrg_['序号']))
  799. JrgBt.set('Mc', str(jrg_['名称']))
  800. JrgBt.set('Je', str(jrg_['金额']))
  801. JrgBt.set('Lb', str(jrg_['类别']))
  802. Zcbfwf = ET.SubElement(Dwgcxx, 'Zcbfwf')
  803. for zcbfwf_ in zcbfwf:
  804. ZcbfwfMx = ET.SubElement(Zcbfwf, 'ZcbfwfMx')
  805. ZcbfwfMx.set('Xh', str(zcbfwf_['序号']))
  806. ZcbfwfMx.set('Mc', str(zcbfwf_['名称']))
  807. ZcbfwfMx.set('Xmjz', str(zcbfwf_['项目价值']))
  808. ZcbfwfMx.set('Fwnr', str(zcbfwf_['服务内容']))
  809. ZcbfwfMx.set('Jsjc', str(zcbfwf_['计算基础']))
  810. ZcbfwfMx.set('Fl', str(zcbfwf_['费率']))
  811. ZcbfwfMx.set('Je', str(zcbfwf_['金额']))
  812. Zjxmjdkzffj = ET.SubElement(Dwgcxx, 'Zjxmjdkzffj')
  813. Fbrgycl = ET.SubElement(Dwgcxx, 'Fbrgycl')
  814. for fbrgycl_ in fbrgycl:
  815. FbrgyclMx = ET.SubElement(Fbrgycl, 'FbrgyclMx')
  816. FbrgyclMx.set('Xh', str(fbrgycl_['序号']))
  817. FbrgyclMx.set('RcjId', str(fbrgycl_['ID']))
  818. FbrgyclMx.set('Clbh', str(fbrgycl_['材料编号']))
  819. FbrgyclMx.set('Mc', str(fbrgycl_['名称']))
  820. FbrgyclMx.set('Ggxh', str(fbrgycl_['规格型号']))
  821. FbrgyclMx.set('Dw', str(fbrgycl_['单位']))
  822. FbrgyclMx.set('Sl', str(fbrgycl_['数量']))
  823. FbrgyclMx.set('Dj', str(fbrgycl_['单价']))
  824. FbrgyclMx.set('Hj', str(fbrgycl_['合价']))
  825. FbrgyclMx.set('Jhfs', str(fbrgycl_['交货方式']))
  826. FbrgyclMx.set('Sddd', str(fbrgycl_['送达地点']))
  827. FbrgyclMx.set('Bz', str(fbrgycl_['备注']))
  828. Cbrgycl = ET.SubElement(Dwgcxx, 'Cbrgycl')
  829. Rcjhz = ET.SubElement(Dwgcxx, 'Rcjhz')
  830. for i in range(len(rcjhz)):
  831. if i == 0:
  832. pass
  833. else:
  834. RcjhzMx = ET.SubElement(Rcjhz, 'RcjhzMx')
  835. RcjhzMx.set('RcjId', str(i))
  836. RcjhzMx.set('RcjBm', str(rcjhz[i][1]))
  837. RcjhzMx.set('Mc', str(rcjhz[i][2]))
  838. RcjhzMx.set('Ggxh', str(rcjhz[i][3]))
  839. RcjhzMx.set('Dw', str(rcjhz[i][4]))
  840. RcjhzMx.set('Sl', str(rcjhz[i][5]))
  841. RcjhzMx.set('Dj', str(rcjhz[i][6]))
  842. RcjhzMx.set('Hj', str(rcjhz[i][7]))
  843. RcjhzMx.set('Cd', str(rcjhz[i][8]))
  844. RcjhzMx.set('Gycs', str(rcjhz[i][9]))
  845. RcjhzMx.set('Rcjlb', str(rcjhz[i][10]))
  846. RcjhzMx.set('Zyclbz', str(rcjhz[i][11]))
  847. RcjhzMx.set('Zcbz', str(rcjhz[i][12]))
  848. RcjhzMx.set('Sbbz', str(rcjhz[i][13]))
  849. RcjhzMx.set('Jgbz', str(rcjhz[i][14]))
  850. RcjhzMx.set('Zgjbz', str(rcjhz[i][15]))
  851. async def delete_files(client, id):
  852. db = client["baojia"]
  853. collection = db["jingjibiao"]
  854. result = []
  855. await collection.update_one({'_id': ObjectId(id)}, {'$set': {'visible': False}})
  856. return result
  857. async def list_files(client):
  858. db = client["baojia"]
  859. collection = db["jingjibiao"]
  860. result = []
  861. async for post in collection.find({"visible": True}):
  862. result.append([str(post['_id']), post["Xmmc"], post['created'] if 'created' in post else ""])
  863. return result
  864. def getDwgc(id, Zylb):
  865. result = []
  866. #result.append(["ming cheng", "jin e", "zan gu jia", "anquan wenming fei", "guifei"])
  867. ##result.append([child.attrib["Dxgcmc"], child.attrib["Je"], child.attrib["Zgj"], child.attrib["Aqwmf"], child.attrib["Gf"]])
  868. id = id + "Zylb" + Zylb
  869. result.append({"id": id + "bao jia hui zong", "label": "报价汇总表"})
  870. result.append({"id": id + "gui fei shui jin", "label": "规费税金"})
  871. result.append({"id": id + "qing dan xiang mu", "label": "清单项目"})
  872. result.append({"id": id + "cuo shi xiang mu", "label": "措施项目"})
  873. result.append({"id": id +"qi ta xiang mu", "label": "其他项目"})
  874. result.append({"id": id +"zan lie jin e", "label": "暂列金额"})
  875. result.append({"id": id +"cai liao zan gu jia", "label": "材料暂估价"})
  876. result.append({"id": id + "zhuan ye gong cheng zan gu jia", "label": "专业工程暂估价"})
  877. result.append({"id": id + "ji ri gong", "label": "计日工"})
  878. result.append({"id": id + "zong cheng bao fu wu fei", "label": "总承包服务费"})
  879. result.append({"id": id + "zong jia xiang mu jin du kuan zhi fu fen jie", "label": "总价项目进度款支付分解"})
  880. result.append({"id": id + "fa bao ren gong ying cai liao", "label": "发包人供应材料"})
  881. result.append({"id": id + "cheng bao ren gong ying cai liao", "label": "承包人供应材料"})
  882. result.append({"id": id + "ren cai ji hui zong", "label": "人材机汇总"})
  883. return result
  884. async def getOutline(client, id):
  885. db = client["baojia"]
  886. collection = db["jingjibiao"]
  887. document = await collection.find_one({'_id': ObjectId(id)})
  888. result = []
  889. if 'TouBiaoXx' in document:
  890. result.append({"id" : "TouBiaoXx", "label" : "投标信息" })
  891. if 'Dxgcxx' in document:
  892. Dxgcxx = document["Dxgcxx"]
  893. for dxgc in Dxgcxx:
  894. result2 = []
  895. Dwgc = dxgc["Dwgc"]
  896. for grandchild in Dwgc:
  897. result2.append({"id" : grandchild['Dwgcbh'], "Zylb":grandchild['Zylb'], "label": grandchild["Dwgcmc"], "children" : getDwgc(grandchild['Dwgcbh'], grandchild['Zylb'])})
  898. result.append({"id" : dxgc['Dxgcbh'], "label" : dxgc['Dxgcmc'], "children" : result2})
  899. return result
  900. async def getDetail(client, id):
  901. db = client["baojia"]
  902. collection = db["jingjibiao"]
  903. document = await collection.find_one({'_id': ObjectId(id)})
  904. result = []
  905. ##result.append(["名称", "金额", "暂估价", "安全文明施工费", "规费"])
  906. if 'TouBiaoXx' in document:
  907. toubiaoxx = document["TouBiaoXx"]
  908. result.append({'名称': '投标总价', '金额' : toubiaoxx["Tbzj"], '暂估价': toubiaoxx["Zgj"], '安全文明施工费': toubiaoxx["Aqwmf"], '规费' : toubiaoxx["Gf"], '_children': []})
  909. if 'Dxgcxx' in document:
  910. Dxgcxx = document["Dxgcxx"]
  911. for dxgc in Dxgcxx:
  912. result[0]['_children'].append({'名称' :dxgc["Dxgcmc"], '金额' : dxgc["Je"], '暂估价' : dxgc["Zgj"],'安全文明施工费' : dxgc["Aqwmf"], '规费' : dxgc["Gf"]})
  913. return result
  914. else:
  915. if 'Dxgcxx' in document:
  916. Dxgcxx = document["Dxgcxx"]
  917. for dxgc in Dxgcxx:
  918. result.append({'名称' :dxgc["Dxgcmc"], '金额' : dxgc["Je"], '暂估价' : dxgc["Zgj"],'安全文明施工费' : dxgc["Aqwmf"], '规费' : dxgc["Gf"]})
  919. return result
  920. async def getBjhz(client, objectid, id):
  921. db = client["baojia"]
  922. collection = db["Dwgc"]
  923. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  924. return document['bjhz']
  925. async def getGfsj(client, objectid, id):
  926. db = client["baojia"]
  927. collection = db["Dwgc"]
  928. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  929. return document['gfsj']
  930. async def getQtxm(client, objectid, id):
  931. db = client["baojia"]
  932. collection = db["Dwgc"]
  933. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  934. return document['qtxm']
  935. async def getZygczgj(client, objectid, id):
  936. db = client["baojia"]
  937. collection = db["Dwgc"]
  938. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  939. return document['zygczgj']
  940. async def getZlje(client, objectid, id):
  941. db = client["baojia"]
  942. collection = db["Dwgc"]
  943. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  944. return document['zlje']
  945. async def getJrg(client, objectid, id):
  946. db = client["baojia"]
  947. collection = db["Dwgc"]
  948. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  949. return document['jrg']
  950. async def getZcbfwf(client, objectid, id):
  951. db = client["baojia"]
  952. collection = db["Dwgc"]
  953. document = await collection.find_one({"Dwgcbh": id, "biao_id": objectid})
  954. return document['zcbfwf']
  955. async def getFbrgycl(client, objectid, id):
  956. db = client["baojia"]
  957. collection = db["Dwgc"]
  958. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  959. return document['fbrgycl']
  960. async def getRcjhz(client, objectid, id):
  961. db = client["baojia"]
  962. collection = db["Dwgc"]
  963. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  964. return document['rcjhz']
  965. async def getZjcs(client, objectid, id):
  966. db = client["baojia"]
  967. collection = db["Dwgc"]
  968. document = await collection.find_one({ "Dwgcbh": id, "biao_id": objectid})
  969. return document['zjcs']
  970. async def getDjcs(client, objectid, id):
  971. db = client["baojia"]
  972. collection = db["Djcs"]
  973. result = []
  974. async for post in collection.find({"Dwgcbh": id, "biao_id": objectid}):
  975. ##post["ID"] = post["_id"]
  976. del post["_id"]
  977. ##print( post["rcj"])
  978. ## del post["DogNum"]
  979. result.append(post)
  980. return result
  981. async def getDjcsQingdanrcj(client, name, bh, bt, bm):
  982. db = client["baojia"]
  983. collection = db["Djcs"]
  984. document = await collection.find_one({ "Dwgcbh": bh, "清单编码": bm, "biao_id": name})
  985. result = document["rcj"]
  986. return result
  987. async def getDjcsDingercj(client, name, bh, bt, qdbm, debm):
  988. db = client["baojia"]
  989. collection = db["Djcs"]
  990. document = await collection.find_one({"Dwgcbh": bh, "清单编码": qdbm, "biao_id": name})
  991. children = document["__children"]
  992. result = []
  993. for child in children:
  994. if child["清单编码"] == debm:
  995. result = child["dercj"]
  996. return result
  997. async def getQdxm(client, name, bh):
  998. db = client["baojia"]
  999. collection = db["Dwgc"]
  1000. document = await collection.find_one({'biao_id': name, "Dwgcbh": bh})
  1001. if document:
  1002. return document['qdbt']
  1003. else:
  1004. return []
  1005. async def getQdmx(client, name, bh, bt):
  1006. db = client["baojia"]
  1007. collection = db["qdxm"]
  1008. result = []
  1009. async for post in collection.find({'biao_id': name, "Dwgcbh": bh, "bt": bt}):
  1010. ##post["ID"] = post["_id"]
  1011. del post["_id"]
  1012. #del post["rcj"]
  1013. #del post["DogNum"]
  1014. result.append(post)
  1015. return result
  1016. async def getQingdanrcj(client, name, bh, bt, bm):
  1017. db = client["baojia"]
  1018. collection = db["qdxm"]
  1019. document = await collection.find_one({ "Dwgcbh": bh, "清单编码": bm, "biao_id": name, "bt": bt})
  1020. result = document["rcj"]
  1021. return result
  1022. async def getDingercj(client, name, bh, bt, qdbm, debm):
  1023. db = client["baojia"]
  1024. collection = db["qdxm"]
  1025. document = await collection.find_one({"Dwgcbh": bh, "清单编码": qdbm, "biao_id": name, "bt": bt})
  1026. result = []
  1027. if "__children" in document:
  1028. children = document["__children"]
  1029. for child in children:
  1030. if child["清单编码"] == debm:
  1031. result = child["dercj"]
  1032. return result
  1033. async def getQufei(client, id):
  1034. db = client["baojia"]
  1035. collection = db["qufei"]
  1036. document = await collection.find_one({'biao_id': id})
  1037. return document['qufei']
  1038. async def searchde(client, zhuanye, text):
  1039. db = client["dinge"]
  1040. collection = db["de-collection"]
  1041. result = []
  1042. async for post in collection.find({'$text': {"$search": "\"" + text + "\""}, "zhuanye": zhuanye}):
  1043. result.append(post["DEBH"] + " " + post['GCLMC'] )
  1044. if len(result) > 10:
  1045. break
  1046. return result
  1047. ##################################editor##########################
  1048. async def updatezjcs(client, id, bh, mc, fl):
  1049. db = client["baojia"]
  1050. collection = db["Dwgc"]
  1051. document = await collection.find_one({'biao_id': id, 'Dwgcbh': bh}, {'rcjhz': 0})
  1052. zjcs = document['zjcs']
  1053. for entry in zjcs:
  1054. if entry['名称'] == mc:
  1055. entry['费率'] = fl
  1056. entry['金额'] = str(float(entry['计算基数']) * float(fl) / float(100))
  1057. await collection.update_one({'biao_id': id, "Dwgcbh": bh}, {'$set': {'zjcs': zjcs}})
  1058. async def save(client, data):
  1059. db = client["baojia"]
  1060. collection = db["qdxm"]
  1061. biao_id = None
  1062. bh = None
  1063. for entry in data:
  1064. entry["__children"] = entry["_children"]
  1065. del entry["_children"]
  1066. biao_id = entry['biao_id']
  1067. bh = entry['Dwgcbh']
  1068. await collection.replace_one({"biao_id": entry["biao_id"], "Dwgcbh": entry["Dwgcbh"], "bt": entry["bt"], "清单编码": entry["清单编码"]}, entry)
  1069. if not biao_id:
  1070. return {"result" : "ok"}
  1071. rcjhz = []
  1072. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  1073. qdrcj = post['rcj'][1:]
  1074. for entry in qdrcj:
  1075. entry[10] = float(entry[10]) * float(post['数量'])
  1076. rcjhz = rcjhz + qdrcj
  1077. collection = db["Djcs"]
  1078. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  1079. qdrcj = post['rcj'][1:]
  1080. for entry in qdrcj:
  1081. entry[10] = float(entry[10]) * float(post['数量'])
  1082. rcjhz = rcjhz + qdrcj
  1083. newHuizong = util.huizongrcj(rcjhz)
  1084. collection = db["Dwgc"]
  1085. await collection.update_one({'biao_id': biao_id, 'Dwgcbh': bh}, {'$set': {'rcjhz' : newHuizong}})
  1086. await zongjiaDwgc(client, biao_id, bh)
  1087. await tbxx(client, biao_id)
  1088. return {"result": "ok"}
  1089. async def savedjcs(client, data):
  1090. db = client["baojia"]
  1091. collection = db["Djcs"]
  1092. biao_id = None
  1093. bh = None
  1094. for entry in data:
  1095. entry["__children"] = entry["_children"]
  1096. del entry["_children"]
  1097. biao_id = entry['biao_id']
  1098. bh = entry['Dwgcbh']
  1099. await collection.replace_one({"biao_id": entry["biao_id"], "Dwgcbh": entry["Dwgcbh"], "清单编码": entry["清单编码"]}, entry)
  1100. if not biao_id:
  1101. return {"result" : "ok"}
  1102. rcjhz = []
  1103. collection = db["qdxm"]
  1104. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  1105. qdrcj = post['rcj'][1:]
  1106. for entry in qdrcj:
  1107. entry[10] = float(entry[10]) * float(post['数量'])
  1108. rcjhz = rcjhz + qdrcj
  1109. collection = db["Djcs"]
  1110. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  1111. qdrcj = post['rcj'][1:]
  1112. for entry in qdrcj:
  1113. entry[10] = float(entry[10]) * float(post['数量'])
  1114. rcjhz = rcjhz + qdrcj
  1115. newHuizong = util.huizongrcj(rcjhz)
  1116. collection = db["Dwgc"]
  1117. await collection.update_one({'biao_id': biao_id, 'Dwgcbh': bh}, {'$set': {'rcjhz' : newHuizong}})
  1118. await zongjiaDwgc(client, biao_id, bh)
  1119. await tbxx(client, biao_id)
  1120. return {"result": "ok"}
  1121. async def applyFL(client, id, data):
  1122. db = client["baojia"]
  1123. collection = db["qufei"]
  1124. await collection.replace_one({"biao_id": id}, {"biao_id": id, "qufei": data})
  1125. collection = db['qdxm']
  1126. xm = data[0]
  1127. for dxgc in xm["children"]:
  1128. for dwgc in dxgc["children"]:
  1129. bh = dwgc['key']
  1130. glf = float(dwgc['管理费(%)'])
  1131. lr = float(dwgc['利润(%)'])
  1132. bz = dwgc['备注']
  1133. ##print(bh+glf+lr+bz)
  1134. async for post in collection.find({'biao_id': id, "Dwgcbh": bh}):
  1135. rgfs = float(post['人工费'])
  1136. clfs = float(post['材料费'])
  1137. jxfs = float(post['机械费'])
  1138. sl = float(post['数量'])
  1139. if rgfs < 0.0001 and clfs < 0.0001 and jxfs < 0.0001:
  1140. continue
  1141. ##danxiang = False
  1142. for child in post['__children']:##一条定额
  1143. bm = child['清单编码']
  1144. if bm.startswith("D"):
  1145. ##danxiang = True
  1146. continue
  1147. rgf = float(child['人工费'])
  1148. clf = float(child['材料费'])
  1149. jxf = float(child['机械费'])
  1150. zhdj = float(child['综合单价'])
  1151. sl_ = float(child['数量'])
  1152. if len(bz) == 0:
  1153. ##常规计算
  1154. child['管理费'] = (rgf + jxf) * glf / float(100)
  1155. child['利润'] = (rgf + jxf) * lr / float(100)
  1156. child['综合单价'] = rgf + clf + jxf + child['管理费'] + child['利润']
  1157. child['合价'] = sl * sl_ * child['综合单价']
  1158. else:
  1159. child['管理费'] = (rgf) * glf / float(100)
  1160. child['利润'] = (rgf) * lr / float(100)
  1161. child['综合单价'] = rgf + clf + jxf + child['管理费'] + child['利润']
  1162. child['合价'] = sl * sl_ * child['综合单价']
  1163. if True:
  1164. post['管理费'] = 0
  1165. post['利润'] = 0
  1166. for entry in post['__children']:
  1167. post['管理费'] = post['管理费'] + float(entry['管理费']) * float(entry['数量'])
  1168. post['利润'] = post['利润'] + float(entry['利润']) * float(entry['数量'])
  1169. post['管理费'] = str(post['管理费'])
  1170. post['利润'] = str(post['利润'])
  1171. post['综合单价'] = str(float(post['人工费']) + float(post['材料费']) + float(post['机械费']) + float(post['管理费']) + float(post['利润']))
  1172. post['合价'] = str(float(post['综合单价']) * float(post['数量']))
  1173. await collection.replace_one({'_id': post['_id']}, post )
  1174. collection = db['Djcs']
  1175. for dxgc in xm["children"]:
  1176. for dwgc in dxgc["children"]:
  1177. bh = dwgc['key']
  1178. glf = float(dwgc['管理费(%)'])
  1179. lr = float(dwgc['利润(%)'])
  1180. bz = dwgc['备注']
  1181. ##print(bh+glf+lr+bz)
  1182. async for post in collection.find({'biao_id': id, "Dwgcbh": bh}):
  1183. rgfs = float(post['人工费'])
  1184. clfs = float(post['材料费'])
  1185. jxfs = float(post['机械费'])
  1186. sl = float(post['数量'])
  1187. if rgfs < 0.0001 and clfs < 0.0001 and jxfs < 0.0001:
  1188. continue
  1189. ##danxiang = False##一般有单项定额的,清单就一条定额,就是这个单项定额
  1190. for child in post['__children']:
  1191. bm = child['清单编码']
  1192. if bm.startswith("D"):
  1193. ##danxiang = True
  1194. continue
  1195. rgf = float(child['人工费'])
  1196. clf = float(child['材料费'])
  1197. jxf = float(child['机械费'])
  1198. zhdj = float(child['综合单价'])
  1199. sl_ = float(child['数量'])
  1200. if len(bz) == 0:
  1201. ##常规计算
  1202. child['管理费'] = (rgf + jxf) * glf / float(100)
  1203. child['利润'] = (rgf + jxf) * lr / float(100)
  1204. child['综合单价'] = rgf + clf + jxf + child['管理费'] + child['利润']
  1205. child['合价'] = sl * sl_ * child['综合单价']
  1206. else:
  1207. child['管理费'] = (rgf) * glf / float(100)
  1208. child['利润'] = (rgf) * lr / float(100)
  1209. child['综合单价'] = rgf + clf + jxf + child['管理费'] + child['利润']
  1210. child['合价'] = sl * sl_ * child['综合单价']
  1211. if True:
  1212. post['管理费'] = 0
  1213. post['利润'] = 0
  1214. for entry in post['__children']:
  1215. post['管理费'] = post['管理费'] + float(entry['管理费']) * float(entry['数量'])
  1216. post['利润'] = post['利润'] + float(entry['利润']) * float(entry['数量'])
  1217. post['管理费'] = str(post['管理费'])
  1218. post['利润'] = str(post['利润'])
  1219. post['综合单价'] = str(float(post['人工费']) + float(post['材料费']) + float(post['机械费']) + float(post['管理费']) + float(post['利润']))
  1220. post['合价'] = str(float(post['综合单价']) * float(post['数量']))
  1221. await collection.replace_one({'_id': post['_id']}, post )
  1222. for dxgc in xm["children"]:
  1223. for dwgc in dxgc["children"]:
  1224. bh = dwgc['key']
  1225. await zongjiaDwgc(client, id, bh)
  1226. await tbxx(client, id)
  1227. return {"result": "ok"}
  1228. async def tiaojia(client, biao_id, bh, bm, mingcheng, danwei, jiage, glf, lr, bz):
  1229. db = client["baojia"]
  1230. collection = db["qdxm"]
  1231. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}):
  1232. if "__children" not in post:
  1233. ##print(post)
  1234. continue
  1235. children = post["__children"]
  1236. qdsl = post['数量']
  1237. hit = False
  1238. for entry in children:###对一条定额,调价
  1239. hitde = False
  1240. dercj = entry["dercj"]
  1241. dergf = 0
  1242. declf = 0
  1243. dejxf = 0
  1244. for i in range(1, len(dercj)):
  1245. rcj = dercj[i]
  1246. if rcj[1] == bm and rcj[2] == mingcheng and rcj[4] == danwei:
  1247. hit = True
  1248. hitde = True
  1249. rcj[5] = jiage
  1250. hanliang = rcj[10]
  1251. rcj[11] = str(float(jiage) * float(hanliang))
  1252. if int(rcj[8]) == 1:
  1253. dergf = dergf + float(rcj[11])
  1254. elif int(rcj[8]) == 2:
  1255. declf = declf + float(rcj[11])
  1256. elif int(rcj[8]) == 3:
  1257. dejxf = dejxf + float(rcj[11])
  1258. if hitde:
  1259. entry['人工费'] = str(dergf)
  1260. entry['辅材费'] = str(declf)
  1261. entry['材料费'] = str(declf)
  1262. entry['机械费'] = str(dejxf)
  1263. if bm.startswith("D"):
  1264. entry['管理费'] = '0'
  1265. entry['利润'] = '0'
  1266. elif bz == 0:
  1267. entry['管理费'] = str((dergf + dejxf) * float(glf) / float(100))
  1268. entry['利润'] = str((dergf + dejxf) * float(lr) / float(100))
  1269. else:
  1270. entry['管理费'] = str((dergf) * float(glf) / float(100))
  1271. entry['利润'] = str((dergf) * float(lr) / float(100))
  1272. entry['综合单价'] = str(float(entry['人工费']) + float(entry['材料费']) + float(entry['机械费']) + float(entry['管理费']) + float(entry['利润']))
  1273. entry['合价'] = str(float(entry['综合单价']) * float(entry['数量']) * float(qdsl))
  1274. if hit:
  1275. ##调整清单
  1276. qdrcj = post['rcj']
  1277. qdrgf = 0
  1278. qdclf = 0
  1279. qdjxf = 0
  1280. for i in range(1, len(qdrcj)):
  1281. entry = qdrcj[i]
  1282. if entry[1] == bm and entry[2] == mingcheng and entry[4] == danwei:
  1283. entry[5] = jiage
  1284. hanliang = entry[10]
  1285. entry[11] = str(float(jiage) * float(hanliang))
  1286. if int(entry[8]) == 1:
  1287. qdrgf = qdrgf + float(entry[11])
  1288. elif int(entry[8]) == 2:
  1289. qdclf = qdclf + float(entry[11])
  1290. elif int(entry[8]) == 3:
  1291. qdjxf = qdjxf + float(entry[11])
  1292. post['人工费'] = str(qdrgf)
  1293. post['辅材费'] = str(qdclf)
  1294. post['材料费'] = str(qdclf)
  1295. post['机械费'] = str(qdjxf)
  1296. post['管理费'] = 0
  1297. post['利润'] = 0
  1298. for entry in children:
  1299. post['管理费'] = post['管理费'] + float(entry['管理费']) * float(entry['数量'])
  1300. post['利润'] = post['利润'] + float(entry['利润']) * float(entry['数量'])
  1301. post['管理费'] = str(post['管理费'])
  1302. post['利润'] = str(post['利润'])
  1303. post['综合单价'] = str(float(post['人工费']) + float(post['材料费']) + float(post['机械费']) + float(post['管理费']) + float(post['利润']))
  1304. post['合价'] = str(float(post['综合单价']) * float(qdsl))
  1305. print(post)
  1306. await collection.replace_one({'_id': post['_id']}, post )
  1307. collection = db["Djcs"]
  1308. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}):
  1309. children = post["__children"]
  1310. qdsl = post['数量']
  1311. hit = False
  1312. for entry in children:###对一条定额,调价
  1313. hitde = False
  1314. dercj = entry["dercj"]
  1315. dergf = 0
  1316. declf = 0
  1317. dejxf = 0
  1318. for i in range(1, len(dercj)):
  1319. rcj = dercj[i]
  1320. if rcj[1] == bm and rcj[2] == mingcheng and rcj[4] == danwei:
  1321. hit = True
  1322. hitde = True
  1323. rcj[5] = jiage
  1324. hanliang = rcj[10]
  1325. rcj[11] = str(float(jiage) * float(hanliang))
  1326. if int(rcj[8]) == 1:
  1327. dergf = dergf + float(rcj[11])
  1328. elif int(rcj[8]) == 2:
  1329. declf = declf + float(rcj[11])
  1330. elif int(rcj[8]) == 3:
  1331. dejxf = dejxf + float(rcj[11])
  1332. if hitde:
  1333. entry['人工费'] = str(dergf)
  1334. entry['辅材费'] = str(declf)
  1335. entry['材料费'] = str(declf)
  1336. entry['机械费'] = str(dejxf)
  1337. if bm.startswith("D"):
  1338. entry['管理费'] = '0'
  1339. entry['利润'] = '0'
  1340. elif bz == 0:
  1341. entry['管理费'] = str((dergf + dejxf) * float(glf) / float(100))
  1342. entry['利润'] = str((dergf + dejxf) * float(lr) / float(100))
  1343. else:
  1344. entry['管理费'] = str((dergf) * float(glf) / float(100))
  1345. entry['利润'] = str((dergf) * float(lr) / float(100))
  1346. entry['综合单价'] = str(float(entry['人工费']) + float(entry['材料费']) + float(entry['机械费']) + float(entry['管理费']) + float(entry['利润']))
  1347. entry['合价'] = str(float(entry['综合单价']) * float(entry['数量']) * float(qdsl))
  1348. if hit:
  1349. ##调整清单
  1350. qdrcj = post['rcj']
  1351. qdrgf = 0
  1352. qdclf = 0
  1353. qdjxf = 0
  1354. for i in range(1, len(qdrcj)):
  1355. entry = qdrcj[i]
  1356. if entry[1] == bm and entry[2] == mingcheng and entry[4] == danwei:
  1357. entry[5] = jiage
  1358. hanliang = entry[10]
  1359. entry[11] = str(float(jiage) * float(hanliang))
  1360. if int(entry[8]) == 1:
  1361. qdrgf = qdrgf + float(entry[11])
  1362. elif int(entry[8]) == 2:
  1363. qdclf = qdclf + float(entry[11])
  1364. elif int(entry[8]) == 3:
  1365. qdjxf = qdjxf + float(entry[11])
  1366. post['人工费'] = str(qdrgf)
  1367. post['辅材费'] = str(qdclf)
  1368. post['材料费'] = str(qdclf)
  1369. post['机械费'] = str(qdjxf)
  1370. post['管理费'] = 0
  1371. post['利润'] = 0
  1372. for entry in children:
  1373. post['管理费'] = post['管理费'] + float(entry['管理费']) * float(entry['数量'])
  1374. post['利润'] = post['利润'] + float(entry['利润']) * float(entry['数量'])
  1375. post['管理费'] = str(post['管理费'])
  1376. post['利润'] = str(post['利润'])
  1377. post['综合单价'] = str(float(post['人工费']) + float(post['材料费']) + float(post['机械费']) + float(post['管理费']) + float(post['利润']))
  1378. post['合价'] = str(float(post['综合单价']) * float(qdsl))
  1379. await collection.replace_one({'_id': post['_id']}, post )
  1380. collection = db["Dwgc"]
  1381. document = await collection.find_one({'biao_id': biao_id, "Dwgcbh": bh})
  1382. hz = document['rcjhz']
  1383. for entry in hz:
  1384. if entry[1] == bm and entry[2] == mingcheng and entry[4] == danwei:
  1385. entry[6] = jiage
  1386. entry[7] = float(jiage) * float(entry[5])
  1387. await collection.update_one({'biao_id': biao_id, "Dwgcbh": bh}, {'$set': {'rcjhz': hz}})
  1388. await zongjiaDwgc(client, biao_id, bh)
  1389. await tbxx(client, biao_id)
  1390. def bjhz_template():
  1391. result = []
  1392. result.append({'序号': '1', '名称': '分部分项工程', '金额': '0', '暂估价': '0', '类别' : '1', '__children': [
  1393. {'序号': '1.1', '名称': '人工费', '金额': '0', '暂估价': '0', '类别' : '1.1'},
  1394. {'序号': '1.2', '名称': '材料费', '金额': '0', '暂估价': '0', '类别' : '1.2'},
  1395. {'序号': '1.3', '名称': '施工机具使用费', '金额': '0', '暂估价': '0', '类别' : '1.3'},
  1396. {'序号': '1.4', '名称': '企业管理费', '金额': '0', '暂估价': '0', '类别' : '1.4'},
  1397. {'序号': '1.5', '名称': '利润', '金额': '0', '暂估价': '0', '类别' : '1.5'}
  1398. ]})
  1399. result.append({'序号': '2', '名称': '措施项目', '金额': '0', '暂估价': '0', '类别' : '2', '__children': [
  1400. {'序号': '2.1', '名称': '单价措施项目费', '金额': '0', '暂估价': '0', '类别' : '2.1'},
  1401. {'序号': '2.2', '名称': '总价措施项目费', '金额': '0', '暂估价': '0', '类别' : '2.2', '__children' : [
  1402. {'序号': '2.2.1', '名称': '其中:安全文明施工措施费', '金额': '0', '暂估价': '0', '类别' : '2.2.1'},]
  1403. }
  1404. ]})
  1405. result.append({'序号': '3', '名称': '其他项目', '金额': '0', '暂估价': '0', '类别' : '3', '__children': [
  1406. {'序号': '3.1', '名称': '其中:暂列金额', '金额': '0', '暂估价': '0', '类别' : '3.1'},
  1407. {'序号': '3.2', '名称': '其中:专业工程暂估价', '金额': '0', '暂估价': '0', '类别' : '3.2'},
  1408. {'序号': '3.3', '名称': '其中:计日工', '金额': '0', '暂估价': '0', '类别' : '3.3'},
  1409. {'序号': '3.4', '名称': '其中:总承包服务费', '金额': '0', '暂估价': '0', '类别' : '3.4'},
  1410. ]})
  1411. result.append({'序号': '4', '名称': '规费', '金额': '0', '暂估价': '0', '类别' : '4', })
  1412. result.append({'序号': '5', '名称': '税金', '金额': '0', '暂估价': '0', '类别' : '5', })
  1413. result.append({'序号': '6', '名称': '工程造价', '金额': '0', '暂估价': '0', '类别' : '6', })
  1414. return result
  1415. async def tbxx(client, biao_id):
  1416. db = client["baojia"]
  1417. collection = db["jingjibiao"]
  1418. document = await collection.find_one({'_id': ObjectId(biao_id)})
  1419. dxgcxx = document['Dxgcxx']
  1420. tbxx = document['TouBiaoXx']
  1421. tbxx['Tbzj'] = '0'
  1422. tbxx['Zgj'] = '0'
  1423. tbxx['Aqwmf'] = '0'
  1424. tbxx['Gf'] = '0'
  1425. dwdx = {}##单位工程映射单项工程
  1426. for dxgc in dxgcxx:
  1427. dxgc['Aqwmf'] = '0'
  1428. dxgc['Gf'] = '0'
  1429. dxgc['Je'] = '0'
  1430. dxgc['Zgj'] = '0'
  1431. mc = dxgc['Dxgcmc']
  1432. Dwgc = dxgc['Dwgc']
  1433. for dwgc in Dwgc:
  1434. Dwgcbh = dwgc['Dwgcbh']
  1435. dwdx[Dwgcbh] = dxgc
  1436. collection = db['Dwgc']
  1437. async for post in collection.find({'biao_id': biao_id}):
  1438. bh = post['Dwgcbh']
  1439. dx = dwdx[bh]
  1440. bjhz = post['bjhz']
  1441. print('######################################################')
  1442. print(bjhz)
  1443. if len(bjhz) == 0:
  1444. pass
  1445. else:
  1446. qtxm = post['qtxm']
  1447. dx['Aqwmf'] = str(float(dx['Aqwmf']) + float(bjhz[1]['__children'][1]['__children'][0]['金额']))
  1448. dx['Gf'] = str(float(dx['Gf']) + float(bjhz[3]['金额']))
  1449. dx['Je'] = str(float(dx['Je']) + float(bjhz[5]['金额']))
  1450. dx['Zgj']= str(float(dx['Zgj']) + float(qtxm[1]['金额']))
  1451. for dxgc in dxgcxx:
  1452. tbxx['Tbzj'] = str(float(tbxx['Tbzj']) + float(dxgc['Je']))
  1453. tbxx['Zgj'] = str(float(tbxx['Zgj']) + float(dxgc['Zgj']))
  1454. tbxx['Aqwmf'] = str(float(tbxx['Aqwmf']) + float(dxgc['Aqwmf']))
  1455. tbxx['Gf'] = str(float(tbxx['Gf']) + float(dxgc['Gf']))
  1456. collection = db["jingjibiao"]
  1457. await collection.update_one({'_id': ObjectId(biao_id)}, {'$set': {'Dxgcxx': dxgcxx, 'TouBiaoXx' : tbxx}})
  1458. async def zongjiaDwgc(client, biao_id, bh):
  1459. db = client["baojia"]
  1460. djcs_sum = 0
  1461. collection = db["Djcs"]
  1462. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  1463. djcs_sum = djcs_sum + float(post['合价'])
  1464. collection = db['Dwgc']
  1465. document = await collection.find_one({'biao_id': biao_id, "Dwgcbh": bh}, {'rcjhz': 0})
  1466. qdbt = document['qdbt']
  1467. qdbt_addition = document['qdbt_addition']
  1468. bts = {}
  1469. distinguish = False
  1470. if 'Default' in qdbt:
  1471. pass
  1472. else:
  1473. distinguish = True
  1474. for item in qdbt_addition:
  1475. bts[item['Mc']] = 0
  1476. collection = db["qdxm"]
  1477. qd_sum = 0
  1478. rgf_sum = 0
  1479. clf_sum = 0
  1480. jxf_sum = 0
  1481. glf_sum = 0
  1482. lr_sum = 0
  1483. fbrgycl_sum = 0
  1484. async for post in collection.find({'biao_id': biao_id, "Dwgcbh": bh}, {'__children': 0}):
  1485. qd_sum = qd_sum + float(post['合价'])
  1486. rgf_sum = rgf_sum + float(post['数量']) * float(post['人工费'])
  1487. clf_sum = clf_sum + float(post['数量']) * float(post['材料费'])
  1488. jxf_sum = jxf_sum + float(post['数量']) * float(post['机械费'])
  1489. glf_sum = glf_sum + float(post['数量']) * float(post['管理费'])
  1490. lr_sum = lr_sum + float(post['数量']) * float(post['利润'])
  1491. if distinguish:
  1492. bts[post['bt']] = bts[post['bt']] + float(post['合价'])
  1493. sum = qd_sum + djcs_sum
  1494. fbrgycl = document['fbrgycl']
  1495. for entry in fbrgycl:
  1496. fbrgycl_sum = fbrgycl_sum + float(entry['合价'])
  1497. zjcs = document['zjcs']
  1498. def process(n):
  1499. n['计算基数'] = str(sum)
  1500. n['金额'] = float(sum) * float(n['费率']) / float(100)
  1501. if "__children" in n:
  1502. for entry in n['__children']:
  1503. entry['计算基数'] = str(sum)
  1504. entry['金额'] = float(sum) * float(entry['费率']) / float(100)
  1505. return n
  1506. result = [process(item) for item in zjcs]
  1507. for entry in result:
  1508. if '安全文明施工' in entry['名称']:
  1509. sum_ = 0
  1510. for child in entry['__children']:
  1511. sum_ = sum_ + float(child['金额'])
  1512. entry['金额'] = str(sum_)
  1513. entry['计算基数'] = str(sum_)
  1514. zjcs_sum = 0
  1515. for entry in result:
  1516. zjcs_sum = zjcs_sum + float(entry['金额'])
  1517. qtxm = document['qtxm']##dwgc qtxm
  1518. qtxm_sum = 0
  1519. for entry in qtxm:
  1520. qtxm_sum = qtxm_sum + float(entry['金额'])
  1521. gfsj = document['gfsj']
  1522. gf_sum = 0
  1523. sj_sum = 0
  1524. for item in gfsj:
  1525. if item['名称'] == '规费':
  1526. child = item['__children']
  1527. for children in child:
  1528. children['取费基数'] = str(sum + zjcs_sum + qtxm_sum)
  1529. children['金额'] = str(float(sum + zjcs_sum + qtxm_sum) * float(children['费率']) / float(100))
  1530. gf_sum = gf_sum + float(children['金额'])
  1531. for item in gfsj:
  1532. if item['名称'] == '规费':
  1533. item['取费基数'] = str(gf_sum)
  1534. item['金额'] = str(gf_sum)
  1535. for item in gfsj:
  1536. if item['名称'] == '税金':
  1537. item['取费基数'] = str(sum + zjcs_sum + qtxm_sum + gf_sum - fbrgycl_sum / float(1.01))
  1538. item['金额'] = float(item['取费基数']) * float(item['费率']) / float(100)
  1539. sj_sum = float(item['金额'])
  1540. for item in gfsj:
  1541. if item['名称'] == '合计':
  1542. item['取费基数'] = str(sj_sum + gf_sum)
  1543. item['金额'] = item['取费基数']
  1544. qtxm = document['qtxm']
  1545. zlje = 0
  1546. zygczgj = 0
  1547. jrg = 0
  1548. zcbfwf = 0
  1549. clzgj = 0
  1550. for entry in qtxm:
  1551. if entry['序号'] == '1':
  1552. zlje = entry['金额']
  1553. if entry['序号'] == '3':
  1554. jrg = entry['金额']
  1555. if entry['序号'] == '4':
  1556. zcbfwf = entry['金额']
  1557. if entry['序号'] == '2':
  1558. for child in entry['__children']:
  1559. if child['序号'] == '2.2':
  1560. zygczgj = child['金额']
  1561. if child['序号'] == '2.1':
  1562. clzgj = child['金额']
  1563. qtxm_sum = float(zlje) + float(zygczgj) + float(jrg) + float(zcbfwf) + float(clzgj)
  1564. bjhz = bjhz_template()
  1565. for entry in bjhz:
  1566. if entry['序号'] == '1':
  1567. entry['金额'] = qd_sum
  1568. for child in entry['__children']:
  1569. if child['序号'] == '1.1':
  1570. child['金额'] = str(rgf_sum)
  1571. if child['序号'] == '1.2':
  1572. child['金额'] = str(clf_sum)
  1573. if child['序号'] == '1.3':
  1574. child['金额'] = str(jxf_sum)
  1575. if child['序号'] == '1.4':
  1576. child['金额'] = str(glf_sum)
  1577. if child['序号'] == '1.5':
  1578. child['金额'] = str(lr_sum)
  1579. if entry['序号'] == '2':
  1580. entry['金额'] = str(djcs_sum + zjcs_sum)
  1581. for child in entry['__children']:
  1582. if child['序号'] == '2.1':
  1583. child['金额'] = str(djcs_sum)
  1584. if child['序号'] == '2.2':
  1585. child['金额'] = str(zjcs_sum)
  1586. for grandchild in child['__children']:
  1587. if grandchild['序号'] == '2.2.1':
  1588. grandchild['金额'] = str(sum_)
  1589. if entry['序号'] == '3':
  1590. entry['金额'] = str(qtxm_sum)
  1591. if entry['序号'] == '4':
  1592. entry['金额'] = str(gf_sum)
  1593. if entry['序号'] == '5':
  1594. entry['金额'] = str(sj_sum)
  1595. if entry['序号'] == '6':
  1596. entry['金额'] = str(float(qd_sum) + float(djcs_sum) + float(zjcs_sum) + float(qtxm_sum) + float(gf_sum) + float(sj_sum))
  1597. collection = db['Dwgc']
  1598. if distinguish:
  1599. for entry in qdbt_addition:
  1600. entry['Je'] = str(bts[entry['Mc']])
  1601. await collection.update_one({'biao_id': biao_id, "Dwgcbh": bh}, {'$set': {'zjcs': result, 'gfsj' : gfsj, 'bjhz': bjhz, 'qdbt_addition' : qdbt_addition}})