db.py 58 KB

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