diff --git a/app.py b/app.py index 1c2c6f5..4f4ed31 100644 --- a/app.py +++ b/app.py @@ -5,12 +5,23 @@ import configparser import os import pymysql # --- +import datetime +# import uuid + +# 전역함수 +global url +global group_number +global product_id +global warehouse_id +global manager_id # DB 연결 설정 정보 세팅 ( db_config.ini에 정의 ) config = configparser.ConfigParser() config.read(os.getcwd() + os.sep + 'db_config.ini', encoding='utf-8') -conn = pymysql.connect( +# db 연결 +def dbcon(): + return pymysql.connect( host = config.get('DB_CONFIG', 'HOST'), port = int(config['DB_CONFIG']['PORT']), user= config['DB_CONFIG']['USER'], @@ -18,35 +29,114 @@ conn = pymysql.connect( db= config['DB_CONFIG']['DBNAME'], charset="utf8") -# Tuple -cur = conn.cursor() +def insert_data(quantity): + try: + db = dbcon() + c = db.cursor() + setdata = (group_number, product_id, datetime.datetime.now(), quantity, warehouse_id, manager_id, 'a', True) + # setdata = (uuid.uuid1(), uuid.uuid1(), uuid.uuid1(), datetime.datetime.now(), quantity, uuid.uuid1(), uuid.uuid1(), 'test', True) + # c.execute("INSERT INTO wms.product_in2 VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)", setdata) + c.execute("INSERT INTO wms.product_in(id, group_number, product_id, in_date, quantity, warehouse_id, manager_id, note, activation) VALUES(UUID(), %s, %s, %s, %s, %s, %s, %s, %s)", setdata) + db.commit() + except Exception as e: + print('db error:', e) + print(group_number) + finally: + db.close() -# DictCursor -cur = conn.cursor(pymysql.cursors.DictCursor) +def update_data(url): + try: + db = dbcon() + c = db.cursor() + setdata = (url) + c.execute("UPDATE wms.plan_In SET clear = TRUE WHERE url=%s", setdata) + db.commit() + except Exception as e: + print('db error:', e) + finally: + db.close() -# sql = f"""SELECT * FROM wms.plan_In2 +def select_all(): + ret = list() + try: + db = dbcon() + c = db.cursor() + #c.execute('SELECT * FROM wms.plan_In') + c.execute('SELECT * FROM wms.plan_In WHERE clear=0') + ret = c.fetchall() + # for row in c.execute('SELECT * FROM student'): + # ret.append(row) + except Exception as e: + print('db error:', e) + finally: + db.close() + return ret + +# def select_num(url): +# ret = () +# try: +# db = dbcon() +# #c = db.cursor() +# c = db.cursor(pymysql.cursors.DictCursor) +# setdata = (url) +# # c.execute('SELECT * FROM wms.plan_In WHERE url=%s', setdata) +# c.execute('SELECT * FROM wms.plan_In WHERE url=%s AND clear=0', setdata) +# ret = c.fetchall() +# except Exception as e: +# print('db error:', e) +# finally: +# db.close() +# return ret + +def select_num(url): + ret = () + try: + db = dbcon() + #c = db.cursor() + c = db.cursor(pymysql.cursors.DictCursor) + setdata = (url) + # c.execute('SELECT * FROM wms.plan_In WHERE url=%s', setdata) + c.execute('SELECT wms.plan_In.url url, wms.plan_In.group_number group_number, wms.plan_In.product_id product_id, wms.plan_In.warehouse_id warehouse_id, wms.plan_In.manager_id manager_id, wms.plan_In.quantity quantity, wms.product.name pd_name, wms.warehouse.name wh_name, wms.plan_In.`date` FROM wms.plan_In left join wms.product on wms.product.id = wms.plan_In.product_id left join wms.warehouse on wms.warehouse.id = wms.plan_In.warehouse_id WHERE url=%s AND clear=0', setdata) + ret = c.fetchall() + except Exception as e: + print('db error:', e) + finally: + db.close() + return ret + +# # # DB 연결 +# # db = dbcon() + +# # Tuple +# cur = conn.cursor() + +# # DictCursor +# cur = conn.cursor(pymysql.cursors.DictCursor) + +# # sql = f"""SELECT * FROM wms.plan_In2 +# # """ + +# sql = f"""SELECT * FROM wms.plan_In2 where qr_hash=%s # """ -sql = f"""SELECT * FROM wms.plan_In2 where qr_hash=%s - """ - -cur.execute(sql, 'testqr') +# cur.execute(sql, 'testqr') # 데이터 접근 # result = cur.fetchall() -rows = cur.fetchall() +# rows = cur.fetchall() # result = cur.fetchone() # for record in result: # print(record) # 연결 종료 -conn.close() +#conn.close() -for row in rows: - # print(row) - print(row['quantity'], row['qr_hash'], row['date']) +# ret = select_num('485b02c0-b05e-11ee-935d-0242ac110006') +# for row in ret: +# # print(row) +# print(row['wh_name'], row['pd_name']) # rows = [list(rows[x]) for x in range(len(rows))] #------------------------------------------------ @@ -54,8 +144,7 @@ app = Flask(__name__) @app.route('/') def hello(): - # return 'Hello, World!' - return rows + return 'Hello, World!' @app.route('/hello') def hellohtml(): @@ -99,11 +188,30 @@ def url_test(): @app.route('/dora') def myimage(): return render_template("myimage.html") + +#@app.route('/form') +@app.route('/form/') +#def formhtml(): +def formhtml(str): + ret = select_num(str) + for row in ret: + print() -@app.route('/form') -def formhtml(): + global group_number + global product_id + global warehouse_id + global manager_id + global url + group_number = row['group_number'] + product_id = row['product_id'] + warehouse_id = row['warehouse_id'] + manager_id = row['manager_id'] + url = row['url'] + # print(group_number, product_id, warehouse_id, manager_id) + # if str == 'f90aef8a-aecd-11ee-935d-0242ac110006': + # return render_template("form.html", date = row['date'], warehouse_id = row['warehouse_id'], quantity = row['quantity']) # return render_template("form.html", date = row['date'], warehouse_id = row['warehouse_id'], name = row['name'], quantity = row['quantity']) - return render_template("form.html", date = row['date'], warehouse_id = row['warehouse_id'], quantity = row['quantity']) + return render_template("form.html", date = row['date'], wh_name = row['wh_name'], quantity = row['quantity'], pd_name = row['pd_name']) @app.route('/method', methods=['GET', 'POST']) def method(): @@ -121,15 +229,19 @@ def method(): # args_dict = request.args.to_dict() # print(args_dict) date = request.args.get["date"] - warehouse_id = request.args.get("warehouse_id") + warehouse_id = request.args.get("wh_name") # name = request.args.get("name") # return "GET으로 전달된 데이터({}, {})".format(date, warehouse_id, quantity, name) - return "GET으로 전달된 데이터({}, {}, {})".format(date, warehouse_id, quantity) + return "GET으로 전달된 데이터({}, {}, {})".format(date, wh_name, quantity) else: date = request.form["date"] - warehouse_id = request.form["warehouse_id"] + wh_name = request.form["wh_name"] quantity = request.form["quantity"] - return "POST로 전달된 데이터({}, {}, {})".format(date, warehouse_id, quantity) + pd_name = request.form["pd_name"] + insert_data(quantity) + update_data(url) + return "POST로 전달된 데이터({}, {}, {}, {})".format(date, wh_name, quantity, pd_name) + # return render_template("form.html", date = row['date'], warehouse_id = row['warehouse_id'], quantity = row['quantity']) if __name__ == '__main__': with app.test_request_context(): diff --git a/templates/form.html b/templates/form.html index 8ba392a..16625b3 100644 --- a/templates/form.html +++ b/templates/form.html @@ -1,21 +1,67 @@ - + + + + + + + WMS + +

WMS

-

- -

- -

- -

+

+ +

+ +

+ + + + +

+ - + + +