qufei.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import xml.etree.ElementTree as ET
  2. from subdir import service
  3. from bson.objectid import ObjectId
  4. from pymongo import AsyncMongoClient
  5. import asyncio
  6. import uuid
  7. client = AsyncMongoClient()
  8. async def resolve(data):
  9. db = client["baojia"]
  10. collection = db["jingjibiao"]
  11. document = await collection.find_one({'_id': ObjectId(data)})
  12. dxgc = document['Dxgcxx']
  13. result = []
  14. for entry in dxgc:
  15. newone = {"名称" : entry['Dxgcmc'], "工程类型":"", "工程类别": "", "管理费(%)": "", "利润(%)": "", "备注":"", "key" : str(uuid.uuid4()) }
  16. children = []
  17. for dwgc in entry['Dwgc']:
  18. children.append({"名称" : dwgc['Dwgcmc'],"工程类型":"", "工程类别": "", "管理费(%)": "", "利润(%)": "","备注":"", "key" : dwgc['Dwgcbh']})
  19. newone["children"] = children
  20. result.append(newone)
  21. collection = db["qufei"]
  22. await collection.insert_one({"biao_id": data, "qufei": [{
  23. "名称" : document['Xmmc'], "工程类型":"", "工程类别": "", "管理费(%)": "", "利润(%)": "", "备注":"", "key" : str(uuid.uuid4()), "children" : result
  24. }]})
  25. import os
  26. ttt = ['686f656fca53720d42995c7a', '686f6579ec813b9efd38db53', '686f65845e169131760f1420']
  27. asyncio.run(resolve(ttt[0]))