|
|
@@ -93,6 +93,8 @@ def Request(ctx, db_info = { "user":_USER, "pass":_PASSWORD, "host":_HOST, "db":
|
|
|
res = Group(_conn, ctx)
|
|
|
elif ctx["function"] == "Ruleclass":
|
|
|
res = Ruleclass(_conn, ctx)
|
|
|
+ elif ctx["function"] == "Reissue":
|
|
|
+ res = Reissue(_conn, ctx)
|
|
|
elif ctx["function"] == "RecycleCard":
|
|
|
res = RecycleCard(_conn, ctx)
|
|
|
elif ctx["function"] == "AddCardBlock":
|
|
|
@@ -764,6 +766,84 @@ def User(db, ctx):
|
|
|
|
|
|
return res
|
|
|
|
|
|
+## _
|
|
|
+## _ __ ___(_)___ ___ _ _ ___
|
|
|
+## | '__/ _ \ / __/ __| | | |/ _ \
|
|
|
+## | | | __/ \__ \__ \ |_| | __/
|
|
|
+## |_| \___|_|___/___/\__,_|\___|
|
|
|
+##
|
|
|
+
|
|
|
+def _fixup_card_pass_state(cursor, cid):
|
|
|
+
|
|
|
+ num_active_query = "select count(active) from user_pass " + \
|
|
|
+ " where logiacl_card_id = %s and expired = 0"
|
|
|
+ cursor.execute(num_active_query, [cid])
|
|
|
+ num_res = int(cursor.fetchone()[0])
|
|
|
+
|
|
|
+ # nothing to do
|
|
|
+ #
|
|
|
+ if num_res == 1:
|
|
|
+ return
|
|
|
+
|
|
|
+ min_queue_query = "select min(queue_order) from user_pass " + \
|
|
|
+ " where logical_card_id = %s and expired = 0 "
|
|
|
+ cursor.execute(min_queue_query, [cid])
|
|
|
+ minq = int(cursor.fetchone()[0])
|
|
|
+
|
|
|
+ set_active_query = "update user_pass set active = 1 " + \
|
|
|
+ " where logical_card_id = %s and expired = 0 and queue_order = %s "
|
|
|
+ cursor.execute(set_active_query, [cid, minq])
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+def Reissue(db, ctx):
|
|
|
+ res = {"result":"fail"}
|
|
|
+ cursor = db.cursor()
|
|
|
+
|
|
|
+ fields = [ "src_logical_card_id", "dst_logical_card_id" ]
|
|
|
+
|
|
|
+ val = {}
|
|
|
+ for f in fields:
|
|
|
+ if f in ctx:
|
|
|
+ if ctx[f] and len(ctx[f]) > 0:
|
|
|
+ val[f] = ctx[f]
|
|
|
+
|
|
|
+ if not ("src_logical_card_id" in val):
|
|
|
+ return res
|
|
|
+
|
|
|
+ if not ("dst_logical_card_id" in val):
|
|
|
+ return res
|
|
|
+
|
|
|
+ cursor.execute("select max(queue_order) from user_pass where logiacl_card_id = %s", [val["src_logical_card_id"]])
|
|
|
+ cursor.execute("select count(queue_order) from user_pass where expired = 0 logiacl_card_id = %s", [val["src_logical_card_id"]])
|
|
|
+
|
|
|
+ src_query = "select user_pass_id, active, expired, queue_order " + \
|
|
|
+ " from user_pass where logical_card_id = %s " + \
|
|
|
+ " order by queue_order asc "
|
|
|
+ cursor.execute(src_query, [val["src_logical_card_id"]]);
|
|
|
+ src_rows = cursor.fetchall()
|
|
|
+
|
|
|
+ dst_card_order_queue = 0
|
|
|
+ cursor.execute("select count(queue_order) from user_pass where logical_card_id = %s", [val["dst_logical_card_id"]])
|
|
|
+ dst_pass_count = cursor.fetchone()[0];
|
|
|
+
|
|
|
+ if int(dst_pass_count) > 0:
|
|
|
+ dst_query = "select max(queue_order) from user_pass where logical_card_id = %s"
|
|
|
+ cursor.execute(dst_query, [val["dst_logical_card_id"]])
|
|
|
+ dst_card_order_queue = int(cursor.fetchone()[0]);
|
|
|
+
|
|
|
+ for src_row in src_rows:
|
|
|
+ if (src_row[2] == 1): continue
|
|
|
+
|
|
|
+ dst_card_order_queue += 1
|
|
|
+ xfer_query = "update user_pass set active = 0, logical_card_id = %s, queue_order = %s where user_pass_id = %s"
|
|
|
+ cursor.execute(xfer_query, [val["dst_logiacl_card_id"], dst_card_order_queue, src_row[0]] )
|
|
|
+
|
|
|
+ _fixup_card_pass_state(val["dst_logical_card_id"])
|
|
|
+ res["result"] = "success"
|
|
|
+
|
|
|
+ return res
|
|
|
+
|
|
|
## _ _
|
|
|
## _ __ ___ ___ _ _ ___| | ___ ___ __ _ _ __ __| |
|
|
|
## | '__/ _ \/ __| | | |/ __| |/ _ \ / __/ _` | '__/ _` |
|