Browse Source

220809 api

yukyo0821 2 years ago
parent
commit
3c43623c7f
4 changed files with 110 additions and 66 deletions
  1. 2 1
      .gitignore
  2. 0 27
      diagrams/0.通路代碼.puml
  3. 0 38
      diagrams/3.倉管.puml
  4. 108 0
      src/api/main.py

+ 2 - 1
.gitignore

@@ -1 +1,2 @@
-src/__pycache__/main.cpython-37.pyc
+src/__pycache__/*
+src/api/__pycache__/*

+ 0 - 27
diagrams/0.通路代碼.puml

@@ -1,27 +0,0 @@
-@startuml
-
-start
-:選擇通路;
-switch ()
-case()
-    :宅配;
-    :宅配通
-    黑猫宅急便
-    全速配
-    新竹貨運
-    便利帶
-    順豐速運;
-case()
-    :店配;
-    :全家
-    統一數網;
-case()
-    :自送;
-case()
-    :店到店;
-endswitch
-
-:通路代碼;
-stop
-
-@enduml

+ 0 - 38
diagrams/3.倉管.puml

@@ -1,38 +0,0 @@
-@startuml
-
-start
-switch (倉管)
-case()
-    :入庫;
-    :選擇通路代碼;
-    :選擇倉別/儲區;
-    :stock_in();
-case()
-    :上架;
-    :選擇通路代碼;
-    :選擇倉別/儲區;
-    :shelf();
-case()
-    :出庫;
-    :選擇倉庫;
-    :stock_out();
-case()
-    :移動儲位;
-    :選擇倉庫;
-    :選擇來源儲區;
-    :選擇目的儲區;
-    :stock_move();
-case()
-    :下架;
-    :選擇下架方式(標示/掃描/批次);
-    :選擇倉庫;
-    :outstock();
-case()
-    :出庫檢核;
-    :匯入/匯出/清空;
-    :stock_check();
-endswitch
-stop
-
-
-@enduml

+ 108 - 0
src/api/main.py

@@ -0,0 +1,108 @@
+
+import mysql.connector
+from fastapi import FastAPI
+from fastapi.middleware.cors import CORSMiddleware
+
+from datetime import tzinfo
+import datetime
+import uvicorn
+import json
+
+app = FastAPI()
+
+origins = [
+    "*"
+]
+app.add_middleware(
+    CORSMiddleware,
+    allow_origins=origins,
+    allow_credentials=True,
+    allow_methods=["*"],
+    allow_headers=["*"],
+)
+
+connobj = {
+    'host': 'db.ptt.cx',
+    'database': 'yodb',
+    'user': 'choozmo',
+    'password': 'pAssw0rd',
+    'use_unicode': True,
+    'charset': 'utf8',
+    'collation': 'utf8_unicode_ci'
+}
+
+def ExecuteQuery(isql):
+    with mysql.connector.connect(**connobj) as connection:
+        with connection.cursor(dictionary=True) as cursor:
+            # connection.set_charset_collation('utf8','utf8_general_ci')
+            #cursor = connection.cursor(dictionary=True)
+            cursor.execute(isql)
+            return cursor.fetchall()
+
+def ExecuteCmd(isql):
+    with mysql.connector.connect(**connobj) as connection:
+        cursor = connection.cursor(dictionary=True)
+        cursor.execute(isql)
+        #print(cursor.rowcount)
+        connection.commit()
+        return None
+
+
+@app.post("/in_stock")
+def in_stock(inJson:str = ''):
+    jObj = json.loads(inJson)
+    
+    if ExecuteQuery("select * from cc_stock where tNO = '"+jObj['ivuObjectNumber']+"' and tStatus = 'A' "):
+        return {"success":"0","msg":"本單號已入庫"}
+    else:
+        ExecuteCmd("insert into cc_stock select null,'"+jObj['ivuObjectNumber']+"','"+jObj['ivuNumber']+"','"+jObj['ivuStorehouse']+"','"+jObj['ivuArea']+"','A','XXX',CURRENT_TIME(),null")
+        ExecuteCmd("insert into cc_stock_transaction select null,'"+jObj['ivuObjectNumber']+"','I',CURRENT_TIME()")
+        return {"success":"1","msg":"入庫完成"}
+    
+    
+@app.post("/out_stock")
+def out_stock(inJson:str = ''):
+    jObj = json.loads(inJson)
+    
+    if not ExecuteQuery("select * from cc_stock where tNO = '"+jObj['ivuObjectNumber']+"' and tStatus = 'A' "):
+        return {"success":"0","msg":"本單號未入庫"}
+    else:
+        #ExecuteCmd("insert into cc_stock select null,'"+jObj['ivuObjectNumber']+"','"+jObj['ivuNumber']+"','"+jObj['ivuStorehouse']+"','"+jObj['ivuArea']+"','A','XXX',CURRENT_TIME(),null")
+        ExecuteCmd("update cc_stock set tStatus = 'O', tOutDtime = CURRENT_TIME() where tNO = '"+jObj['ivuObjectNumber']+"' and tStatus = 'A' ")
+        ExecuteCmd("insert into cc_stock_transaction select null,'"+jObj['ivuObjectNumber']+"','O',CURRENT_TIME()")
+        return {"success":"1","msg":"出庫完成"}
+
+    
+@app.post("/stock_list")
+def stock_list(inJson:str = ''):
+    jObj = json.loads(inJson)
+    
+    sql = "select * from cc_stock where tStatus='A' "
+    if jObj['ivuStorehouse'] != "":
+        sql +=  " and tStock = '" + jObj['ivuStorehouse'] + "' "
+    if jObj['ivuArea'] != "":
+        sql +=  " and tSPos = '" + jObj['ivuArea'] + "' "
+    if jObj['ivuObjectNumber'] != "":
+        sql +=  " and tNo = '" + jObj['ivuObjectNumber'] + "' "
+    if jObj['tInDtime'] != "" and jObj['tOutDtime'] != "":
+        sql +=  " and tInDtime between '" + str(jObj['tInDtime']).replace("T"," ") + "' and '" + str(jObj['tOutDtime']).replace("T"," ") + "' "
+            
+    sql +=  " order by tInDtime desc "
+    #print(sql)
+    return ExecuteQuery(sql)
+
+    
+""" aa = pd.DataFrame(ExecuteQuery("select * from cc_stock"))
+if aa.empty:
+    print(aa)
+
+ExecuteCmd("insert into cc_stock_transaction select null,'','',CURRENT_TIME()") """
+
+#print(in_stock('{"ivuType":"宅配","ivuNumber":"宅配通","ivuStorehouse":"長慶倉庫","ivuArea":"B-04-01","ivuObjectNumber":"111111123333"}'))
+#print(out_stock('{"ivuStorehouse":"長慶倉庫","ivuObjectNumber":"111111123333"}'))
+#print(stock_list('{"ivuStorehouse":"","ivuArea":"","ivuObjectNumber":"191919191919","tInDtime":"","tOutDtime":"","ivuObjectGBNumber":"","ivuObjectReturnNumber":""}'))
+
+""" if __name__ == "__main__":
+    uvicorn.run(app, host="localhost", port=8000) """
+
+