main.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834
  1. import xml.etree.ElementTree as ET
  2. from typing import Union
  3. from fastapi import FastAPI
  4. import os
  5. import uuid
  6. import re
  7. import zipfile
  8. import json
  9. from fastapi.middleware.cors import CORSMiddleware
  10. from fastapi.middleware.gzip import GZipMiddleware
  11. import base64
  12. from pydantic import BaseModel
  13. from subdir import service
  14. from subdir import db
  15. from subdir import util
  16. import xml.dom.minidom as MD
  17. import numpy as np
  18. from fastapi.staticfiles import StaticFiles
  19. from pymongo import AsyncMongoClient
  20. client = AsyncMongoClient()
  21. from fastapi.responses import FileResponse
  22. from fastapi import WebSocket, WebSocketDisconnect
  23. from fastapi import UploadFile
  24. class ConnectionManager:
  25. """Class defining socket events"""
  26. def __init__(self):
  27. """init method, keeping track of connections"""
  28. self.active_connections = []
  29. async def connect(self, websocket: WebSocket):
  30. """connect event"""
  31. await websocket.accept()
  32. self.active_connections.append(websocket)
  33. async def send_personal_message(self, message: str, websocket: WebSocket):
  34. """Direct Message"""
  35. await websocket.send_text(message)
  36. def disconnect(self, websocket: WebSocket):
  37. """disconnect event"""
  38. self.active_connections.remove(websocket)
  39. app = FastAPI()
  40. origins = [
  41. "http://localhost.tiangolo.com",
  42. "https://localhost.tiangolo.com",
  43. "http://localhost",
  44. "http://localhost:9002",
  45. "http://127.0.0.1:9002",
  46. ]
  47. app.add_middleware(
  48. CORSMiddleware,
  49. allow_origins=["*"],
  50. allow_credentials=True,
  51. allow_methods=["*"],
  52. allow_headers=["*"],
  53. )
  54. app.add_middleware(GZipMiddleware, minimum_size=1000, compresslevel=5)
  55. app.mount("/static", StaticFiles(directory="front/dist"), name="static")
  56. manager = ConnectionManager()
  57. for root, dirs, files in os.walk("./data", topdown=False):
  58. for name in files:
  59. print(os.path.join(root, name))
  60. file_data = os.path.join(root, name)
  61. def getDetail(root):
  62. print(root.tag)
  63. print(root.text)
  64. print(root.attrib)
  65. result = []
  66. result.append(["名称", "金额", "暂估价", "安全文明施工费", "规费"])
  67. for child in root:
  68. print(child.tag)
  69. print(child.attrib)
  70. if child.tag == "TouBiaoXx":
  71. result.append([child.attrib["Zbr"], child.attrib["Tbzj"], child.attrib["Zgj"], child.attrib["Aqwmf"], child.attrib["Gf"]])
  72. if child.tag == "Dxgcxx":
  73. Dxgcbh = child.attrib["Dxgcbh"]
  74. Dxgcmc = child.attrib["Dxgcmc"]
  75. result.append([child.attrib["Dxgcmc"], child.attrib["Je"], child.attrib["Zgj"], child.attrib["Aqwmf"], child.attrib["Gf"]])
  76. return result
  77. def getOutline(root):
  78. print(root.tag)
  79. print(root.text)
  80. print(root.attrib)
  81. result = []
  82. for child in root:
  83. print(child.tag)
  84. print(child.attrib)
  85. if child.tag == "TouBiaoXx":
  86. result.append({"id" : "TouBiaoXx", "label" : "投标信息" })
  87. if child.tag == "Dxgcxx":
  88. Dxgcbh = child.attrib["Dxgcbh"]
  89. Dxgcmc = child.attrib["Dxgcmc"]
  90. result2 = []
  91. for child1 in child:
  92. #print("level2===================================")
  93. #print(child1.tag)
  94. #print(child1.attrib)
  95. Dwgcbh = child1.attrib["Dwgcbh"]
  96. Dwgcmc = child1.attrib["Dwgcmc"]
  97. Zylb = child1.attrib["Zylb"]
  98. result2.append({"id" : Dwgcbh,"Zylb":Zylb, "label": Dwgcmc, "children" : service.getDwgc(root, Dwgcbh, Zylb)})
  99. result.append({"id" : Dxgcbh, "label" : Dxgcmc, "children" : result2})
  100. return result
  101. class Info(BaseModel):
  102. name: str
  103. class DingeshuRequest(BaseModel):
  104. value: int
  105. class DingeXilieRequest(BaseModel):
  106. value: int
  107. id: str
  108. class SingleDingeXilieRequest(BaseModel):
  109. zhuanye: int
  110. debh: str
  111. class InfoWithID(BaseModel):
  112. name: str
  113. id: str
  114. class Tiaojia(BaseModel):
  115. biao_id: str
  116. bh: str
  117. bm: str
  118. mingcheng: str
  119. danwei: str
  120. jiage: str
  121. glf: str
  122. lr: str
  123. bz: int
  124. class SearchDe(BaseModel):
  125. zhuanye: str
  126. text: str
  127. class UpdateZjcs(BaseModel):
  128. biao_id: str
  129. bh: str
  130. mc: str
  131. fl: str
  132. @app.post("/outline")
  133. async def read_root(info: Info):
  134. for root, dirs, files in os.walk("./data", topdown=False):
  135. for name in files:
  136. if name == info.name:
  137. print(os.path.join(root, name))
  138. file_data = os.path.join(root, name)
  139. tree = ET.parse(file_data)
  140. root = tree.getroot()
  141. return getOutline(root)
  142. @app.post("/outline2")
  143. async def read_root2(info: Info):
  144. return await db.getOutline(client, info.name)
  145. @app.post("/detail")
  146. async def read_detail(info: Info):
  147. for root, dirs, files in os.walk("./data", topdown=False):
  148. for name in files:
  149. if name == info.name:
  150. print(os.path.join(root, name))
  151. file_data = os.path.join(root, name)
  152. tree = ET.parse(file_data)
  153. root = tree.getroot()
  154. return getDetail(root)
  155. @app.post("/detail2")
  156. async def read_detail2(info: Info):
  157. return await db.getDetail(client, info.name)
  158. @app.post("/baojiahuizong/")
  159. async def read_bjhz(info: InfoWithID):
  160. for root, dirs, files in os.walk("./data", topdown=False):
  161. for name in files:
  162. if name == info.name:
  163. print(os.path.join(root, name))
  164. file_data = os.path.join(root, name)
  165. tree = ET.parse(file_data)
  166. root = tree.getroot()
  167. return service.getBjhz(root, info.id)
  168. @app.post("/baojiahuizong2/")
  169. async def read_bjhz2(info: InfoWithID):
  170. raw = await db.getBjhz(client, info.name, info.id)
  171. raw2 = []
  172. for entry in raw:
  173. if "__children" in entry:
  174. entry["_children"] = entry["__children"]
  175. for grandchild in entry["_children"]:
  176. if "__children" in grandchild:
  177. grandchild['_children'] = grandchild['__children']
  178. del grandchild['__children']
  179. del entry["__children"]
  180. raw2.append(entry)
  181. return raw2
  182. @app.post("/guifeishuijin/")
  183. async def read_gfsj(info: InfoWithID):
  184. for root, dirs, files in os.walk("./data", topdown=False):
  185. for name in files:
  186. if name == info.name:
  187. print(os.path.join(root, name))
  188. file_data = os.path.join(root, name)
  189. tree = ET.parse(file_data)
  190. root = tree.getroot()
  191. return service.getGfsj(root, info.id)
  192. @app.post("/guifeishuijin2/")
  193. async def read_gfsj2(info: InfoWithID):
  194. raw = await db.getGfsj(client, info.name, info.id)
  195. raw2 = []
  196. for entry in raw:
  197. if "__children" in entry:
  198. entry["_children"] = entry["__children"]
  199. del entry["__children"]
  200. raw2.append(entry)
  201. return raw2
  202. @app.post("/qitaxiangmu/")
  203. async def read_qtxm(info: InfoWithID):
  204. for root, dirs, files in os.walk("./data", topdown=False):
  205. for name in files:
  206. if name == info.name:
  207. print(os.path.join(root, name))
  208. file_data = os.path.join(root, name)
  209. tree = ET.parse(file_data)
  210. root = tree.getroot()
  211. return service.getQtxm(root, info.id)
  212. @app.post("/qitaxiangmu2/")
  213. async def read_qtxm2(info: InfoWithID):
  214. raw = await db.getQtxm(client, info.name, info.id)
  215. raw2 = []
  216. for entry in raw:
  217. if "__children" in entry:
  218. entry["_children"] = entry["__children"]
  219. del entry["__children"]
  220. raw2.append(entry)
  221. return raw2
  222. @app.post("/zygczgj/")
  223. async def zygczgj(info: InfoWithID):
  224. return await db.getZygczgj(client, info.name, info.id)
  225. @app.post("/zanliejine/")
  226. async def read_zlje(info: InfoWithID):
  227. for root, dirs, files in os.walk("./data", topdown=False):
  228. for name in files:
  229. if name == info.name:
  230. print(os.path.join(root, name))
  231. file_data = os.path.join(root, name)
  232. tree = ET.parse(file_data)
  233. root = tree.getroot()
  234. return service.getZlje(root, info.id)
  235. @app.post("/zanliejine2/")
  236. async def read_zlje2(info: InfoWithID):
  237. return await db.getZlje(client, info.name, info.id)
  238. @app.post("/jirigong/")
  239. async def read_jrg(info: InfoWithID):
  240. for root, dirs, files in os.walk("./data", topdown=False):
  241. for name in files:
  242. if name == info.name:
  243. print(os.path.join(root, name))
  244. file_data = os.path.join(root, name)
  245. tree = ET.parse(file_data)
  246. root = tree.getroot()
  247. return service.getJrg(root, info.id)
  248. @app.post("/jirigong2/")
  249. async def read_jrg2(info: InfoWithID):
  250. return await db.getJrg(client, info.name, info.id)
  251. @app.post("/zongchengbaofuwufei/")
  252. async def read_zcbfwf(info: InfoWithID):
  253. for root, dirs, files in os.walk("./data", topdown=False):
  254. for name in files:
  255. if name == info.name:
  256. print(os.path.join(root, name))
  257. file_data = os.path.join(root, name)
  258. tree = ET.parse(file_data)
  259. root = tree.getroot()
  260. return service.getZcbfwf(root, info.id)
  261. @app.post("/zongchengbaofuwufei2/")
  262. async def read_zcbfwf2(info: InfoWithID):
  263. return await db.getZcbfwf(client, info.name, info.id)
  264. @app.post("/fabaorengongyingcailiao/")
  265. async def read_fbrgycl(info: InfoWithID):
  266. for root, dirs, files in os.walk("./data", topdown=False):
  267. for name in files:
  268. if name == info.name:
  269. print(os.path.join(root, name))
  270. file_data = os.path.join(root, name)
  271. tree = ET.parse(file_data)
  272. root = tree.getroot()
  273. return service.getFbrgycl(root, info.id)
  274. @app.post("/fabaorengongyingcailiao2/")
  275. async def read_fbrgycl2(info: InfoWithID):
  276. return await db.getFbrgycl(client, info.name, info.id)
  277. @app.post("/rencaijihuizong/")
  278. async def read_rcjhz(info: InfoWithID):
  279. for root, dirs, files in os.walk("./data", topdown=False):
  280. for name in files:
  281. if name == info.name:
  282. print(os.path.join(root, name))
  283. file_data = os.path.join(root, name)
  284. tree = ET.parse(file_data)
  285. root = tree.getroot()
  286. return service.getRcjhz(root, info.id)
  287. @app.post("/rencaijihuizong2/")
  288. async def read_rcjhz2(info: InfoWithID):
  289. return await db.getRcjhz(client, info.name, info.id)
  290. @app.post("/qingdanxiangmu/")
  291. async def read_qdxm(info: InfoWithID):
  292. for root, dirs, files in os.walk("./data", topdown=False):
  293. for name in files:
  294. if name == info.name:
  295. print(os.path.join(root, name))
  296. file_data = os.path.join(root, name)
  297. tree = ET.parse(file_data)
  298. root = tree.getroot()
  299. return service.getQdxm(root, info.id)
  300. #return []
  301. @app.post("/qingdanxiangmu2/")
  302. async def read_qdxm2(info: InfoWithID):
  303. return await db.getQdxm(client, info.name, info.id)
  304. class Item(BaseModel):
  305. bh: str
  306. bt: str
  307. name: str
  308. class Rcj(BaseModel):
  309. bh: str
  310. bt: str
  311. bm: str
  312. name: str
  313. class Dercj(BaseModel):
  314. bh: str
  315. bt: str
  316. qdbm: str
  317. debm: str
  318. name: str
  319. class Zjcs(BaseModel):
  320. bh: str
  321. name: str
  322. @app.post("/qingdanmingxi/")
  323. async def read_qdmx(item : Item):
  324. return await db.getQdmx(client, item.name, item.bh, item.bt)
  325. @app.post("/qingdanrcj/")
  326. async def read_rcj(item : Rcj):
  327. if item.bt == "Djcs":
  328. return await db.getDjcsQingdanrcj(client, item.name, item.bh, item.bt, item.bm)
  329. return await db.getQingdanrcj(client, item.name, item.bh, item.bt, item.bm)
  330. @app.post("/qingdantuijian/")
  331. async def read_tuijian(item : Rcj):
  332. return service.getQingdanTuijian(item.bh, item.bt, item.bm)
  333. @app.post("/dingercj/")
  334. async def read_dercj(item : Dercj):
  335. if item.bt == "Djcs":
  336. return await db.getDjcsDingercj(client, item.name, item.bh, item.bt, item.qdbm, item.debm)
  337. return await db.getDingercj(client, item.name, item.bh, item.bt, item.qdbm, item.debm)
  338. @app.post("/zjcs/")
  339. async def read_zjcs(item : Zjcs):
  340. raw = await db.getZjcs(client, item.name, item.bh)
  341. raw2 = []
  342. for entry in raw:
  343. if "__children" in entry:
  344. entry["_children"] = entry["__children"]
  345. del entry["__children"]
  346. raw2.append(entry)
  347. return raw2
  348. @app.post("/djcs/")
  349. async def read_djcs(item : Zjcs):
  350. raw = await db.getDjcs(client, item.name, item.bh)
  351. raw2 = []
  352. for entry in raw:
  353. if "__children" in entry:
  354. entry["_children"] = entry["__children"]
  355. del entry["__children"]
  356. raw2.append(entry)
  357. return raw2
  358. @app.post("/files/")
  359. async def read_files():
  360. result = []
  361. for root, dirs, files in os.walk("./data", topdown=False):
  362. for name in files:
  363. print(os.path.join(root, name))
  364. result.append([name, "", ""])
  365. return result
  366. @app.post("/files2/")
  367. async def read_files2():
  368. result = await db.list_files(client)
  369. return result
  370. @app.post("/deleteFile/")
  371. async def delete(r: Info):
  372. result = await db.delete_files(client, r.name)
  373. return result
  374. @app.post("/des/")
  375. async def read_des(r: DingeshuRequest):
  376. result = service.getDes(r.value)
  377. if r.value == 30:
  378. result.append({
  379. "id": "2075",
  380. "key" : "2075",
  381. "value" : "2075",
  382. "label" : "安装费用",
  383. "title" : "安装费用",
  384. "children" : [
  385. {
  386. "id": "2076",
  387. "key" : "2076",
  388. "value" : "2076",
  389. "label" : "脚手架搭拆费",
  390. "title" : "脚手架搭拆费",
  391. "children" : []
  392. },
  393. {
  394. "id": "2077",
  395. "key" : "2077",
  396. "value" : "2077",
  397. "label" : "施工超高增加费",
  398. "title" : "施工超高增加费",
  399. "children" : []
  400. },
  401. {
  402. "id": "2078",
  403. "key" : "2078",
  404. "value" : "2078",
  405. "label" : "安装生产同时增加费",
  406. "title" : "安装生产同时增加费",
  407. "children" : []
  408. },
  409. {
  410. "id": "2079",
  411. "key" : "2079",
  412. "value" : "2079",
  413. "label" : "有害环境操作增加费",
  414. "title" : "有害环境操作增加费",
  415. "children" : []
  416. },
  417. {
  418. "id": "2080",
  419. "key" : "2080",
  420. "value" : "2080",
  421. "label" : "高层建筑增加费",
  422. "title" : "高层建筑增加费",
  423. "children" : [
  424. {
  425. "id": "2081",
  426. "key" : "2081",
  427. "value" : "2081",
  428. "label" : "第四册",
  429. "title" : "第四册",
  430. "children" : []
  431. },
  432. {
  433. "id": "2082",
  434. "key" : "2082",
  435. "value" : "2082",
  436. "label" : "第五册",
  437. "title" : "第五册",
  438. "children" : []
  439. },
  440. {
  441. "id": "2083",
  442. "key" : "2083",
  443. "value" : "2083",
  444. "label" : "第七册",
  445. "title" : "第七册",
  446. "children" : []
  447. },
  448. {
  449. "id": "2084",
  450. "key" : "2084",
  451. "value" : "2084",
  452. "label" : "第九册",
  453. "title" : "第九册",
  454. "children" : []
  455. },
  456. {
  457. "id": "2085",
  458. "key" : "2085",
  459. "value" : "2085",
  460. "label" : "第十册",
  461. "title" : "第十册",
  462. "children" : []
  463. },
  464. {
  465. "id": "2086",
  466. "key" : "2086",
  467. "value" : "2086",
  468. "label" : "第十一册",
  469. "title" : "第十一册",
  470. "children" : []
  471. },
  472. ]
  473. },
  474. {
  475. "id": "2087",
  476. "key" : "2087",
  477. "value" : "2087",
  478. "label" : "系统调试费",
  479. "title" : "系统调试费",
  480. "children" : []
  481. },
  482. ]
  483. })
  484. return result
  485. @app.post("/pbs/")
  486. async def read_pbs(r: DingeshuRequest):
  487. result = service.getPbs(r.value)
  488. #print(result)
  489. result.insert(0, {"id": "0","key": "0", "label": "全部", "title": "全部"})
  490. return result
  491. @app.post("/pbxl/")
  492. async def read_pbxl(r: Info):
  493. result = service.getPbxl(r.name)
  494. #print(result)
  495. return result
  496. @app.post("/cankao/")
  497. async def cankao():
  498. result = service.getCankao()
  499. #print(result)
  500. return result
  501. @app.post("/qufei/")
  502. async def read_qufei(r: Info):
  503. return await db.getQufei(client, r.name)
  504. @app.post("/dexilie/")
  505. async def read_dexilie(r: DingeXilieRequest):
  506. if r.value == 30 and int(r.id) > 2074:
  507. return service.getDeXilie_azfy(r.value, r.id)
  508. result = service.getDeXilie(r.value, r.id)
  509. #print(result)
  510. return result
  511. @app.post("/singledexilie/")
  512. async def read_singledexilie(r: SingleDingeXilieRequest):
  513. if r.debh.startswith("D") :
  514. return json.dumps({
  515. "reverse": "None",
  516. "rgde": None,
  517. "jxde": None,
  518. "clde": None,
  519. "actual_zhuanye": r.zhuanye,
  520. "bz_selected": {"BZBH": {}},
  521. "bz_selected2": {"BZBH": {}}
  522. }, ensure_ascii=False)
  523. if "-F" in r.debh:
  524. return service.read_singledexilie_azfy(r.debh)
  525. r_debh = r.debh.split("#")[0]
  526. result1, result2, rgde, jxde, clde, bz_selected, bz_selected2, actual_zhuanye= service.getSingleDeXilie(r.zhuanye, r_debh)
  527. print("get result ***************************************")
  528. if result1:
  529. result3 = json.loads(result1)
  530. else:
  531. result3 = {}
  532. result3["reverse"] = str(result2)
  533. result3["rgde"] = rgde
  534. result3["jxde"] = jxde
  535. result3["clde"] = clde
  536. result3["actual_zhuanye"] = actual_zhuanye
  537. if bz_selected != None:
  538. result3["bz_selected"] = json.loads(bz_selected)
  539. else:
  540. result3["bz_selected"] = {"BZBH": {}}
  541. if bz_selected2 != None:
  542. result3["bz_selected2"] = json.loads(bz_selected2)
  543. else:
  544. result3["bz_selected2"] = {"BZBH": {}}
  545. if "[" in r_debh:
  546. position3 = r_debh.find("*")
  547. coef = 1
  548. if position3 == -1:
  549. pass
  550. else:
  551. coef = r_debh[1 + position3:]
  552. print(coef)
  553. tail = 0
  554. for i in range(0, len(coef) + 1):
  555. if i == len(coef):
  556. tail = i
  557. break
  558. if coef[i] > '9' or coef[i] < '0':
  559. tail = i
  560. break
  561. if tail == 0:
  562. print("1113111")
  563. result3["reverse"] = 'None'
  564. return json.dumps(result3, ensure_ascii=False)
  565. coef = int(coef[0:tail])
  566. position1 = r_debh.find("[")
  567. position2 = r_debh.find("]")
  568. if position2 == -1:
  569. print("1121111")
  570. result3["reverse"] = 'None'
  571. return json.dumps(result3, ensure_ascii=False)
  572. if r_debh[position1-1] == "+":
  573. pass
  574. elif r_debh[position1-1] == "-":
  575. coef = -coef
  576. else:
  577. print("111111")
  578. result3["reverse"] = 'None'
  579. return json.dumps(result3, ensure_ascii=False)
  580. debh = r_debh[position1+1: position2]
  581. if result3['GLDE']: ##csv文件里的字段,表示这个定额有没有配套的增减定额
  582. hit = False
  583. for key, value in result3['GLDE'].items():
  584. if value == debh:
  585. hit = True
  586. if not hit:
  587. result3["reverse"] = 'None'
  588. return json.dumps(result3, ensure_ascii=False)
  589. else:
  590. result3["reverse"] = 'None'
  591. return json.dumps(result3, ensure_ascii=False)
  592. result1_, result2_, rgde_, jxde_, clde_, bz_selected_, bz_selected2_, actual_zhuanye_ = service.getSingleDeXilie(r.zhuanye, debh)
  593. if result1_:
  594. util.mergerg(rgde, rgde_, coef)
  595. util.mergejx(jxde, jxde_, coef)
  596. util.mergecl(clde, clde_, coef)
  597. result3["rgde"] = rgde
  598. result3["jxde"] = jxde
  599. result3["clde"] = clde
  600. item_ = None
  601. for item in result3['DW'].keys():
  602. item_ = item
  603. result3['DEBH'] = {item_: util.cleanBM(r_debh)}
  604. else:
  605. result3["reverse"] = 'None'
  606. return json.dumps(result3, ensure_ascii=False)
  607. @app.post("/save/")
  608. async def save(r: Info):
  609. data = json.loads(r.name)
  610. ##print(data)
  611. return await db.save(client, data)
  612. @app.post("/savedjcs/")
  613. async def savedjcs(r: Info):
  614. data = json.loads(r.name)
  615. ##print(data)
  616. return await db.savedjcs(client, data)
  617. @app.post("/applyFL/")
  618. async def applyFL(r: InfoWithID):
  619. data = json.loads(r.name)
  620. print(data)
  621. return await db.applyFL(client, r.id, data)
  622. @app.post("/tiaojia/")
  623. async def tiaojia(r: Tiaojia):
  624. ##return []
  625. glf = r.glf
  626. lr = r.lr
  627. if r.glf == '':
  628. glf = '0'
  629. if r.lr == "":
  630. lr = '0'
  631. return await db.tiaojia(client, r.biao_id, r.bh, r.bm, r.mingcheng, r.danwei, r.jiage, glf, lr, r.bz)
  632. @app.post("/searchde/")
  633. async def searchde(r: SearchDe):
  634. ##return []
  635. return await db.searchde(client, r.zhuanye, r.text)
  636. @app.post("/updatezjcs/")
  637. async def updatezjcs(r: UpdateZjcs):
  638. ##return []
  639. return await db.updatezjcs(client, r.biao_id, r.bh, r.mc, r.fl)
  640. @app.post("/upload/")
  641. async def upload(file: UploadFile):
  642. if file.filename.endswith('13jz') or file.filename.endswith("13jt"):
  643. content = await file.read()
  644. string = content.decode('utf-8')
  645. await resolve(string)
  646. return [file.filename]
  647. elif file.filename.endswith("jszf"):
  648. content = await file.read()
  649. string = content.decode('utf-8')
  650. root = ET.fromstring(string)
  651. for child in root:
  652. print(child)
  653. if child.tag == "ZBFileContent":
  654. base64_bytes = child.text.encode("ascii")
  655. sample_string_bytes = base64.b64decode(base64_bytes)
  656. tmp = str(uuid.uuid4())
  657. os.mkdir(os.path.join("tmp", tmp))
  658. with open(tmp, "wb") as file_:
  659. file_.write(sample_string_bytes)
  660. with zipfile.ZipFile(tmp, 'r') as zip_ref:
  661. zip_ref.extractall(os.path.join("tmp", tmp))
  662. dir_list = os.listdir(os.path.join("tmp", tmp))
  663. print(dir_list)
  664. for entry in dir_list:
  665. if entry.endswith("13jz"):
  666. with open(os.path.join("tmp", tmp, entry), 'r') as f:
  667. await resolve(f.read())
  668. return [file.filename]
  669. else:
  670. return [file.filename]
  671. @app.get("/download/{item_id}")
  672. async def download_file(item_id):
  673. file_path = "export/contacts.xml.b"
  674. # Create the root element
  675. root = ET.Element("JingJiBiao")
  676. # Create a sub-element
  677. ##TouBiaoXx = ET.SubElement(root, "TouBiaoXx")
  678. await db.build(client, root, item_id)
  679. # Create the tree and write to a file
  680. tree = ET.ElementTree(root)
  681. tree.write("export/contacts.xml", encoding="utf-8")
  682. dom = MD.parse("export/contacts.xml")
  683. with open("export/contacts.xml.b", 'w') as f:
  684. f.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n")
  685. content = (dom.toprettyxml(indent=" "))
  686. content_ = content.split("\n")
  687. f.write("\n".join(content_[1:]))
  688. return FileResponse(file_path, media_type='application/octet-stream', filename="contacts.xml")
  689. async def resolve(data):
  690. await db.resolve(data, client)##manager.send_personal_message(f"You wrote: {data}", websocket)
  691. @app.websocket("/ws")
  692. async def websocket_endpoint(websocket: WebSocket):
  693. await manager.connect(websocket)
  694. try:
  695. while True:
  696. data = await websocket.receive_text()
  697. await resolve(websocket, data)
  698. ##await manager.broadcast(f"Client #{client_id} says: {data}")
  699. except WebSocketDisconnect:
  700. manager.disconnect(websocket)
  701. ##await manager.broadcast(f"Client left the chat")