main.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. import time
  2. from fastapi import FastAPI
  3. import sys
  4. import os
  5. import datetime
  6. import ast
  7. from fastapi.responses import JSONResponse, FileResponse
  8. from fastapi.middleware.cors import CORSMiddleware
  9. from pydantic import BaseModel
  10. import uvicorn
  11. from fastapi.staticfiles import StaticFiles
  12. import markdown
  13. from fastapi import Request, APIRouter
  14. from fastapi.responses import HTMLResponse
  15. from fastapi.templating import Jinja2Templates
  16. templates = Jinja2Templates(directory="templates")
  17. def openfile(filename):
  18. filepath = os.path.join("page/", filename)
  19. with open(filepath, "r", encoding="utf-8") as input_file:
  20. text = input_file.read()
  21. html = markdown.markdown(text)
  22. data = {
  23. "page": html
  24. }
  25. return data
  26. description = """
  27. 長慶運通系統設計
  28. ## Items
  29. You can **read items**.
  30. ## Users
  31. ![This image doesn't work](/imgs/datamodel.svg)
  32. You will be able to:
  33. * **Create users** (_not implemented_).
  34. * **Read users** (_not implemented_).
  35. """
  36. app = FastAPI(description=description)
  37. app.mount("/imgs", StaticFiles(directory="imgs"), name="imgs")
  38. origins = [
  39. "http://www.googo.org",
  40. "http://www.googo.org:8080",
  41. "http://0.0.0.0:8080",
  42. "http://googo.org:8080",
  43. "http://googo.org",
  44. "http://139.162.121.30"
  45. ]
  46. #uvicorn main:app --host 0.0.0.0 --port 8001
  47. app.add_middleware(
  48. CORSMiddleware,
  49. allow_origins=origins,
  50. allow_credentials=True,
  51. allow_methods=["*"],
  52. allow_headers=["*"],
  53. )
  54. @app.get("/page/{page_name}", response_class=HTMLResponse)
  55. async def show_page(request: Request, page_name: str):
  56. data = openfile(page_name+".md")
  57. print(data)
  58. return templates.TemplateResponse("page.html", {"request": request, "data": data})
  59. class q_req(BaseModel):
  60. domain_name: str
  61. class kw_req(BaseModel):
  62. fullurl: str
  63. shorturl: str
  64. class upload_orders_item(BaseModel):
  65. objtype: str
  66. channel_id: str
  67. customer_contract_id: str
  68. shipment_type:str
  69. ship_date:str
  70. class shipping_details(BaseModel):
  71. filed_date: str
  72. channel_id: str
  73. customer_contract_id: str
  74. shipment_type:str
  75. ship_date:str
  76. @app.post("/op_doc/upload_orders",
  77. summary="訂單明細上傳",
  78. description=
  79. """
  80. parameters:
  81. 訂單明細上傳(Excel格式)
  82. - current_insite: 收單營業所
  83. - transport_type: 配送類別
  84. - transport_id: 通路代碼
  85. - transport_site: 入單營業所
  86. - transport_contract_id: 客契代碼
  87. - transport_no: 配送單號
  88. - shipment_no: 運單號碼
  89. - shipment_type: 運單種類(一單到底/換單)
  90. - shipment_2: 是否二配
  91. - shipment_date: 出貨日期
  92. - package_id: 袋號
  93. - order_id: 訂單編號
  94. - sender_data: 送件人資料
  95. {
  96. sender_name: 送件人姓名
  97. sender_mobileno: 送件人手機號碼
  98. sender_addr: 送件人地址
  99. sender_spot_id: 超商代碼
  100. sender_spot_name: 超商名稱
  101. sender_spot_addr: 超商地址
  102. ...
  103. }
  104. - recipient_data: 收件人資料
  105. {
  106. recipient_name: 收件人姓名
  107. recipient_mobileno: 收件人手機號碼
  108. recipient_addr: 收件人地址
  109. recipient_spot_id: 超商代碼
  110. recipient_spot_name: 超商名稱
  111. recipient_spot_addr: 超商地址
  112. ...
  113. }
  114. - package: 貨件內容
  115. {
  116. package_charge: 代收貨款
  117. package_weight: 貨件重量
  118. package_contemt: 內容物
  119. ...
  120. }
  121. - dInDtime: 建檔日期
  122. - dInUser: 建檔人
  123. - dInFilename: 檔案名稱
  124. ...
  125. return:
  126. {'success':'1'/'0'} 上傳成功/失敗
  127. """
  128. )
  129. async def upload_orders(req:upload_orders_item):
  130. return "OK"
  131. @app.post("/op_doc/query_shipping_details",
  132. response_model=shipping_details,
  133. summary="出貨明細查詢",
  134. description=
  135. """
  136. parameters:
  137. 查詢條件
  138. {
  139. ...
  140. }
  141. return:
  142. dataset
  143. [{
  144. - dInDtime: 建檔日期
  145. - transport_site: 入單營業所
  146. - current_insite: 收單營業所
  147. - transport_type: 配送類別
  148. - transport_name: 通路商
  149. - shipment_type: 運單種類
  150. - shipment_2: 二配
  151. - dInUser: 建檔人
  152. - dInFilename: 檔案名稱
  153. - upload_dtime: 上傳時間
  154. - upload_account: 傳送帳號
  155. }]
  156. """
  157. )
  158. async def query_shipping_details():
  159. return None
  160. @app.post("/stock_taking/shipment_out",
  161. response_model=shipping_details,
  162. summary="出貨面單",
  163. description=
  164. """
  165. parameters:
  166. - transport_id: 通路代碼
  167. - shipment_no: 運單號碼
  168. return:
  169. - sender_data: 送件人資料
  170. {
  171. sender_name: 送件人姓名
  172. sender_mobileno: 送件人手機號碼
  173. sender_addr: 送件人地址
  174. sender_spot_id: 超商代碼
  175. sender_spot_name: 超商名稱
  176. sender_spot_addr: 超商地址
  177. ...
  178. },
  179. - recipient_data: 收件人資料
  180. {
  181. recipient_name: 收件人姓名
  182. recipient_mobileno: 收件人手機號碼
  183. recipient_addr: 收件人地址
  184. recipient_spot_id: 超商代碼
  185. recipient_spot_name: 超商名稱
  186. recipient_spot_addr: 超商地址
  187. ...
  188. },
  189. - package: 貨件內容
  190. {
  191. package_charge: 代收貨款
  192. package_weight: 貨件重量
  193. package_contemt: 內容物
  194. ...
  195. }
  196. """
  197. )
  198. async def shipment_out():
  199. return None
  200. @app.post("/stock_taking/bag_in",
  201. response_model=shipping_details,
  202. summary="袋進倉",
  203. description=
  204. """
  205. parameters:
  206. - package_id: 袋號
  207. return:
  208. {'success':'1'/'0'} 資料正常/異常
  209. """
  210. )
  211. async def bag_in():
  212. return None
  213. @app.post("/stock_taking/wh_in",
  214. response_model=shipping_details,
  215. summary="進站",
  216. description=
  217. """
  218. parameters:
  219. - transport_id: 通路代碼
  220. - transport_no: 配送單號
  221. - if_cancel: 取消刷件
  222. - insite_comment: 其他說明
  223. return:
  224. {'success':'1'/'0'} 資料正常/異常
  225. """
  226. )
  227. async def wh_in():
  228. return None
  229. @app.post("/stock_taking/wh_out",
  230. response_model=shipping_details,
  231. summary="出站",
  232. description=
  233. """
  234. parameters:
  235. - transport_id: 通路代碼
  236. - transport_no: 配送單號
  237. - transport_next: 下一站代碼
  238. - if_cancel: 取消刷件
  239. - insite_comment: 其他說明
  240. return:
  241. {'success':'1'/'0'} 資料正常/異常
  242. """
  243. )
  244. async def wh_out():
  245. return None
  246. @app.post("/stock_taking/deliver_out",
  247. response_model=shipping_details,
  248. summary="配送",
  249. description=
  250. """
  251. parameters:
  252. - transport_id: 通路代碼
  253. - transport_no: 配送單號
  254. - if_cancel: 取消刷件
  255. - insite_comment: 其他說明
  256. return:
  257. {'success':'1'/'0'} 資料正常/異常
  258. """
  259. )
  260. async def deliver_out():
  261. return None
  262. @app.post("/stock_taking/sign",
  263. response_model=shipping_details,
  264. summary="簽收",
  265. description=
  266. """
  267. parameters:
  268. - transport_type: 配送類別
  269. - transport_id: 通路代碼
  270. - transport_no: 配送單號
  271. - transport_sign_status: 簽收類別(成功/異常)
  272. - transport_sign: 簽收人(本人/代收/警衛)
  273. return:
  274. {'success':'1'/'0'} 資料正常/異常
  275. """
  276. )
  277. async def sign():
  278. return None
  279. @app.post("/stock_taking/whout_again",
  280. response_model=shipping_details,
  281. summary="二次出貨",
  282. description=
  283. """
  284. parameters:
  285. - transport_id: 通路代碼
  286. - shipment_no: 運單號碼
  287. return:
  288. - sender_data: 送件人資料
  289. {
  290. sender_name: 送件人姓名
  291. sender_mobileno: 送件人手機號碼
  292. sender_addr: 送件人地址
  293. sender_spot_id: 超商代碼
  294. sender_spot_name: 超商名稱
  295. sender_spot_addr: 超商地址
  296. ...
  297. },
  298. - recipient_data: 收件人資料
  299. {
  300. recipient_name: 收件人姓名
  301. recipient_mobileno: 收件人手機號碼
  302. recipient_addr: 收件人地址
  303. recipient_spot_id: 超商代碼
  304. recipient_spot_name: 超商名稱
  305. recipient_spot_addr: 超商地址
  306. ...
  307. },
  308. - package: 貨件內容
  309. {
  310. package_charge: 代收貨款
  311. package_weight: 貨件重量
  312. package_contemt: 內容物
  313. ...
  314. }
  315. """
  316. )
  317. async def whout_again():
  318. return None
  319. @app.post("/stock_taking/s_return",
  320. response_model=shipping_details,
  321. summary="退貨",
  322. description=
  323. """
  324. parameters:
  325. - transport_site: 營業所
  326. - transport_id: 通路代碼
  327. - transport_no: 配送單號
  328. - stock_id: 倉別(長慶倉庫)
  329. - stock_storage_id: 儲區
  330. - if_cancel: 取消刷件
  331. - insite_comment: 其他說明
  332. return:
  333. {'success':'1'/'0'} 資料正常/異常
  334. """
  335. )
  336. async def s_return():
  337. return None
  338. @app.post("/stock_taking/reprint",
  339. response_model=shipping_details,
  340. summary="重印面單",
  341. description=
  342. """
  343. parameters:
  344. - transport_id: 通路代碼
  345. - shipment_no: 運單號碼
  346. return:
  347. - sender_data: 送件人資料
  348. {
  349. sender_name: 送件人姓名
  350. sender_mobileno: 送件人手機號碼
  351. sender_addr: 送件人地址
  352. sender_spot_id: 超商代碼
  353. sender_spot_name: 超商名稱
  354. sender_spot_addr: 超商地址
  355. ...
  356. },
  357. - recipient_data: 收件人資料
  358. {
  359. recipient_name: 收件人姓名
  360. recipient_mobileno: 收件人手機號碼
  361. recipient_addr: 收件人地址
  362. recipient_spot_id: 超商代碼
  363. recipient_spot_name: 超商名稱
  364. recipient_spot_addr: 超商地址
  365. ...
  366. },
  367. - package: 貨件內容
  368. {
  369. package_charge: 代收貨款
  370. package_weight: 貨件重量
  371. package_contemt: 內容物
  372. ...
  373. }
  374. """
  375. )
  376. async def reprint():
  377. return None
  378. @app.post("/stock_taking/batch_print",
  379. response_model=shipping_details,
  380. summary="面單批次列印",
  381. description=
  382. """
  383. parameters:
  384. 查詢條件
  385. {
  386. ...
  387. }
  388. return:
  389. dataset
  390. [
  391. - sender_data: 送件人資料
  392. {
  393. sender_name: 送件人姓名
  394. sender_mobileno: 送件人手機號碼
  395. sender_addr: 送件人地址
  396. sender_spot_id: 超商代碼
  397. sender_spot_name: 超商名稱
  398. sender_spot_addr: 超商地址
  399. ...
  400. },
  401. - recipient_data: 收件人資料
  402. {
  403. recipient_name: 收件人姓名
  404. recipient_mobileno: 收件人手機號碼
  405. recipient_addr: 收件人地址
  406. recipient_spot_id: 超商代碼
  407. recipient_spot_name: 超商名稱
  408. recipient_spot_addr: 超商地址
  409. ...
  410. },
  411. - package: 貨件內容
  412. {
  413. package_charge: 代收貨款
  414. package_weight: 貨件重量
  415. package_contemt: 內容物
  416. ...
  417. }
  418. ]
  419. """
  420. )
  421. async def batch_print():
  422. return None
  423. @app.post("/stock_taking/print_return",
  424. response_model=shipping_details,
  425. summary="刷退條碼",
  426. description=
  427. """
  428. parameters:
  429. - transport_id: 通路代碼
  430. - transport_no: 配送單號
  431. return:
  432. {'success':'1'/'0'} 資料正常/異常
  433. """
  434. )
  435. async def print_return():
  436. return None
  437. @app.post("/ELPC/stock_in",
  438. response_model=shipping_details,
  439. summary="入庫",
  440. description=
  441. """
  442. parameters:
  443. - transport_id: 通路代碼
  444. - transport_no: 配送單號
  445. - stock_id: 倉別(長慶倉庫)
  446. - stock_storage_id: 儲區
  447. - if_cancel: 取消刷件
  448. return:
  449. {'success':'1'/'0'} 資料正常/異常
  450. """
  451. )
  452. async def stock_in():
  453. return None
  454. @app.post("/ELPC/shelf",
  455. response_model=shipping_details,
  456. summary="上架",
  457. description=
  458. """
  459. parameters:
  460. - transport_id: 通路代碼
  461. - transport_no: 配送單號
  462. - stock_id: 倉別(長慶倉庫)
  463. - stock_storage_id: 儲區
  464. - if_cancel: 取消刷件
  465. return:
  466. {'success':'1'/'0'} 資料正常/異常
  467. """
  468. )
  469. async def shelf():
  470. return None
  471. @app.post("/ELPC/stock_out",
  472. response_model=shipping_details,
  473. summary="出庫",
  474. description=
  475. """
  476. parameters:
  477. - stock_id: 倉庫(長慶倉庫)
  478. return:
  479. {'success':'1'/'0'} 資料正常/異常
  480. """
  481. )
  482. async def stock_out():
  483. return None
  484. @app.post("/ELPC/stock_move",
  485. response_model=shipping_details,
  486. summary="移動儲位",
  487. description=
  488. """
  489. parameters:
  490. - stock_id: 倉別(長慶倉庫)
  491. - source_stock_storage_id: 來源儲區
  492. - target_stock_storage_id: 目的儲區
  493. return:
  494. {'success':'1'/'0'} 資料正常/異常
  495. """
  496. )
  497. async def stock_move():
  498. return None
  499. @app.post("/ELPC/outstock",
  500. response_model=shipping_details,
  501. summary="下架",
  502. description=
  503. """
  504. parameters:
  505. - transport_site: 下架營業站
  506. - transport_id: 通路代碼
  507. - stock_id: 倉別(長慶倉庫)
  508. return:
  509. {'success':'1'/'0'} 資料正常/異常
  510. """
  511. )
  512. async def outstock():
  513. return None
  514. @app.post("/ELPC/stock_check",
  515. response_model=shipping_details,
  516. summary="出庫檢核",
  517. description=
  518. """
  519. parameters:
  520. 匯入檢核單號(Excel格式)
  521. dataset
  522. [
  523. - transport_no: 配送單號
  524. ]
  525. return:
  526. {'success':'1'/'0'} 資料正常/異常
  527. """
  528. )
  529. async def outstock():
  530. return None
  531. if __name__ == "__main__":
  532. uvicorn.run("main:app", host="0.0.0.0", port=9898)