|
@@ -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) """
|
|
|
+
|
|
|
+
|