From e9d1092222c15b320533f4cbcc6e1b0f41f7d243 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EA=B5=AC?= Date: Mon, 22 Jan 2024 17:12:18 +0900 Subject: [PATCH] =?UTF-8?q?=EC=B0=BD=EA=B3=A0=20=EC=9D=B4=EB=A6=84=20?= =?UTF-8?q?=EB=A6=AC=EC=8A=A4=ED=8A=B8=EB=A5=BC=20=EC=BD=A4=EB=B3=B4?= =?UTF-8?q?=EB=B0=95=EC=8A=A4=EB=A1=9C=20=EC=84=A0=ED=83=9D=ED=95=A0=20?= =?UTF-8?q?=EC=88=98=20=EC=9E=88=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20=E3=84=B4=20db=EC=97=90=20=EC=9E=AC=EA=B3=A0(stock?= =?UTF-8?q?=20=ED=85=8C=EC=9D=B4=EB=B8=94)=20=EA=B0=92=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=EB=90=98=EB=8F=84=EB=A1=9D=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 198 +++++++++++++------------------------------- templates/form.html | 11 ++- 2 files changed, 68 insertions(+), 141 deletions(-) diff --git a/app.py b/app.py index 4f4ed31..83cd62a 100644 --- a/app.py +++ b/app.py @@ -8,13 +8,6 @@ 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') @@ -29,7 +22,7 @@ def dbcon(): db= config['DB_CONFIG']['DBNAME'], charset="utf8") -def insert_data(quantity): +def insert_data(group_number, product_id, quantity, warehouse_id, manager_id): try: db = dbcon() c = db.cursor() @@ -49,7 +42,19 @@ def update_data(url): db = dbcon() c = db.cursor() setdata = (url) - c.execute("UPDATE wms.plan_In SET clear = TRUE WHERE url=%s", setdata) + c.execute("UPDATE wms.plan_In SET clear = TRUE, activation = false WHERE url=%s", setdata) + db.commit() + except Exception as e: + print('db error:', e) + finally: + db.close() + +def update_stock(warehouse_id, product_id, quantity): + try: + db = dbcon() + c = db.cursor() + setdata = (warehouse_id, product_id,warehouse_id,product_id, warehouse_id, product_id, quantity, warehouse_id,product_id,quantity) + c.execute("INSERT INTO wms.stock(id, warehouse_id, product_id, quantity, activation)VALUES(CASE WHEN( SELECT inner_stock.id from stock inner_stock where inner_stock.warehouse_id = %s and inner_stock.product_id = %s) is null THEN UUID() ELSE (SELECT inner_stock2.id from stock inner_stock2 where inner_stock2.warehouse_id = %s and inner_stock2.product_id = %s) END, %s, %s, %s, TRUE) ON DUPLICATE KEY UPDATE quantity = (SELECT quantity from stock s where s.warehouse_id = %s and s.product_id = %s) + %s", setdata) db.commit() except Exception as e: print('db error:', e) @@ -72,27 +77,28 @@ def select_all(): 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 = () +def wh_select_all(): + ret = list() try: db = dbcon() - #c = db.cursor() + # c = db.cursor() + c = db.cursor(pymysql.cursors.DictCursor) + #c.execute('SELECT * FROM wms.plan_In') + c.execute('SELECT * FROM wms.warehouse WHERE activation=1') + 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 = list() + 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) @@ -104,114 +110,28 @@ def select_num(url): 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 -# """ - -# cur.execute(sql, 'testqr') - -# 데이터 접근 -# result = cur.fetchall() -# rows = cur.fetchall() -# result = cur.fetchone() - -# for record in result: -# print(record) - -# 연결 종료 -#conn.close() - -# 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))] -#------------------------------------------------ - app = Flask(__name__) @app.route('/') def hello(): return 'Hello, World!' - -@app.route('/hello') -def hellohtml(): - return render_template("hello.html") - -@app.route('/hellos/') -def hellos(name): - return "hellos {}".format(name) - -@app.route('/input/') -def input(num): - name = '' - if num == 1: - name = '도라에몽' - elif num == 2: - name = '진구' - elif num == 3: - name = '퉁퉁이' - return "hello {}".format(name) - -app.route('/test') -def test1(): - return 'test1' - -@app.route('/test/') -def test2(): - return 'test2' - -@app.route('/naver') -def naver(): - return render_template("naver.html") - -@app.route('/kakao') -def daum(): - return redirect("https://www.daum.net/") - -@app.route('/urltest') -def url_test(): - return redirect(url_for('daum')) - -@app.route('/dora') -def myimage(): - return render_template("myimage.html") #@app.route('/form') -@app.route('/form/') +@app.route('/qr/') #def formhtml(): def formhtml(str): - ret = select_num(str) - for row in ret: - print() + d = select_num(str) + row = d[0] + ret2 = wh_select_all() - 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'], wh_name = row['wh_name'], quantity = row['quantity'], pd_name = row['pd_name']) + return render_template("form.html", date = row['date'], wh_name = row['wh_name'], + quantity = row['quantity'], pd_name = row['pd_name'], group_number = row['group_number'], + product_id = row['product_id'], warehouse_id = row['warehouse_id'], manager_id = row['manager_id'], + url = row['url'], server_list = ret2) @app.route('/method', methods=['GET', 'POST']) def method(): @@ -225,25 +145,23 @@ def method(): # num = request.form["num"] # name = request.form["name"] # return "POST로 전달된 데이터({}, {})".format(num, name) - if request.method == 'GET': - # args_dict = request.args.to_dict() - # print(args_dict) - date = request.args.get["date"] - warehouse_id = request.args.get("wh_name") - # name = request.args.get("name") - # return "GET으로 전달된 데이터({}, {})".format(date, warehouse_id, quantity, name) - return "GET으로 전달된 데이터({}, {}, {})".format(date, wh_name, quantity) - else: - date = request.form["date"] - wh_name = request.form["wh_name"] - quantity = request.form["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']) + date = request.form["date"] + wh_name = request.form["wh_name"] + warehouse_id = wh_name + quantity = request.form["quantity"] + pd_name = request.form["pd_name"] + group_number = request.form["group_number"] + product_id = request.form["product_id"] + manager_id = request.form["manager_id"] + url = request.form["url"] + + insert_data(group_number, product_id, quantity, warehouse_id, manager_id) + update_data(url) + update_stock(warehouse_id, product_id, quantity) + + 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(): - print(url_for('daum')) app.run() \ No newline at end of file diff --git a/templates/form.html b/templates/form.html index 16625b3..816e954 100644 --- a/templates/form.html +++ b/templates/form.html @@ -19,8 +19,17 @@


+ + + + -

+

+