import json
if 82 - 82: Iii1i
from flask import Blueprint , render_template , request , g , redirect , url_for , flash
from sqlalchemy import or_ , and_
if 87 - 87: Ii % i1i1i1111I . Oo / OooOoo * I1Ii1I1 - I1I
from forms . wgcommform import *
from exts import db
from decorators import login_required
from models . iccard import *
import vwAppConfig
from sqlalchemy import text
if 81 - 81: i1 + ooOOO / oOo0O00 * i1iiIII111 * IiIIii11Ii
__all__ = [
 "bp" ,
 "web_multi_card_list" ,
"web_multi_card_edit" ,
"web_multi_card_edit_morecard_total" ,
 "web_multi_card_user_register"
 ]
bp = Blueprint ( 'wgcomm_extern_multi_card' , __name__ , url_prefix = '/' )
if 84 - 84: ooo000 - Ooo0Ooo + iI1iII1I1I1i . IIiIIiIi11I1
if 98 - 98: I11iiIi11i1I % oOO
@ bp . route ( '/web_multi_card_list' , methods = [ 'GET' , 'POST' ] )
@ login_required
def web_multi_card_list ( ) :
 i1ii1 = db . session . query ( TBDoor . f_DoorID , TBDoor . f_DoorName , TBDoor . f_MoreCards_Total , TBDoor . f_DoorNO ,
 TBController . f_ControllerSN ,
 TBDoor . f_DoorEnabled ) . filter_by ( f_DoorEnabled = True ) . join ( TBController ,
 TBController . f_ControllerID == TBDoor . f_ControllerID ) . order_by ( TBDoor . f_DoorName )
 ooo0O0oO00 = i1ii1 . all ( )
 if 55 - 55: I11II1Ii % iIi
 ii = {
 "objlist" : ooo0O0oO00 ,
 }
 return render_template ( "wgcomm/extern-multi-card-list.html" , ** ii )
 if 91 - 91: i1 . Ii . i1i1i1111I + i1 % IIiIIiIi11I1 + I1I
 if 70 - 70: I11II1Ii * I11II1Ii
@ bp . route ( '/edit_morecard_total' , methods = [ 'POST' ] )
@ login_required
def web_multi_card_edit_morecard_total ( ) :
 if 61 - 61: Ooo0Ooo - I1I
 iIIIII1i111i = "wgcomm_extern_multi_card.web_multi_card_list"
 if request . form . get ( "submitcancel" ) is not None :
  return redirect ( url_for ( iIIIII1i111i ) )
  if 8 - 8: i1iiIII111 * i1 . I1I / oOO
 if request . form . get ( 'f_DoorID' ) :
  ooOOooO0 = extern_multi_card_setup_form ( request . form )
  i1iiiiIIIiIi = ooOOooO0 . f_DoorID . data
  II = ooOOooO0 . f_MoreCards_Total . data
  OO0000 = ooOOooO0 . f_DoorName . data
  if 92 - 92: I1I / I1I + I11II1Ii . oOO
  i1ii1 = db . session . query ( TBDoor . f_DoorID , TBDoor . f_DoorName , TBDoor . f_MoreCards_Total , TBDoor . f_DoorNO ,
 TBController . f_ControllerSN , TBController . f_MoreCards_GoInOut ,
 TBController . f_ControllerID ,
 TBDoor . f_DoorEnabled ) . filter_by ( f_DoorEnabled = True ) . filter_by ( f_DoorID = i1iiiiIIIiIi ) . join (
 TBController ,
 TBController . f_ControllerID == TBDoor . f_ControllerID ) . order_by (
 TBDoor . f_DoorName )
  ooo0O0oO00 = i1ii1 . all ( )
  if 8 - 8: Ii + I11II1Ii . I11iiIi11i1I - I1Ii1I1 % I11iiIi11i1I . i1i1i1111I
  if ooo0O0oO00 :
   ii1iIi1i11i = ooo0O0oO00 [ 0 ]
   I111IIi11IiI = ii1iIi1i11i . f_MoreCards_GoInOut
   o0OOOooO00oo = ii1iIi1i11i . f_DoorNO
   IIii = ii1iIi1i11i . f_ControllerSN
   OO00 = ii1iIi1i11i . f_ControllerID
   if II == 0 :
    if IIii < 400000000 :
     I111IIi11IiI = I111IIi11IiI & ( 0xFF - ( 1 << ( o0OOOooO00oo - 1 ) * 2 ) )
     I111IIi11IiI = I111IIi11IiI & ( 0xFF - ( 1 << ( o0OOOooO00oo - 1 ) * 2 + 1 ) )
    else :
     I111IIi11IiI = I111IIi11IiI & ( 0xFF - ( 1 << ( o0OOOooO00oo - 1 ) ) )
   else :
    if IIii < 400000000 :
     I111IIi11IiI = I111IIi11IiI | ( 1 << ( o0OOOooO00oo - 1 ) * 2 )
     I111IIi11IiI = I111IIi11IiI & ( 0xFF - ( 1 << ( o0OOOooO00oo - 1 ) * 2 + 1 ) )
    else :
     I111IIi11IiI = I111IIi11IiI | ( ( 1 << ( o0OOOooO00oo - 1 ) ) )
     if 39 - 39: I11iiIi11i1I * oOO . Oo + ooOOO / Oo
   TBController . query . filter_by ( f_ControllerID = OO00 ) . update (
 { "f_MoreCards_GoInOut" : I111IIi11IiI } , synchronize_session = False )
   TBDoor . query . filter_by ( f_DoorID = i1iiiiIIIiIi ) . update (
 { "f_MoreCards_Total" : II } , synchronize_session = False )
   if 14 - 14: OooOoo % oOo0O00 + I1I % i1iiIII111 * ooOOO / I11iiIi11i1I
   try :
    db . session . commit ( )
    vwAppConfig . setcontrollerdoorChangeTime ( )
    if 63 - 63: i1i1i1111I . Ooo0Ooo * ooOOO
    flash ( "{} Multi-card designated number of people completed, takes effect only after uploading settings in the main console!!!" . format ( OO0000 ) )
    vwAppConfig . vwlog ( '{}--{}' . format ( g . user . f_OperatorName , "{} Multi-card designated number of people successful!" . format (
 OO0000 ) ) )
    return redirect ( url_for ( iIIIII1i111i ) )
   except Exception as ii1Ii1I :
    print ( ii1Ii1I )
    if 71 - 71: oOO - Oo . OooOoo . Ii % I11II1Ii + oOO
    db . session . rollback ( )
    IiII = "wgcomm/extern-multi-card-setup.html"
    flash ( "Multi-card designated number of people failed！" )
    return render_template ( IiII , wgform = ooOOooO0 )
 web_multi_card_list ( )
 if 6 - 6: i1 / Oo * IiIIii11Ii
 if 100 - 100: iIi - OooOoo * I1Ii1I1 / Ooo0Ooo / Iii1i
@ bp . route ( '/multi_card_edit' , methods = [ 'POST' ] )
@ login_required
def web_multi_card_edit ( ) :
 if 23 - 23: Ooo0Ooo + i1 * I1Ii1I1 + Oo * Ii - IIiIIiIi11I1
 iIIIII1i111i = "wgcomm_extern_multi_card.web_multi_card_list"
 if request . form . get ( "submitcancel" ) is not None :
  return redirect ( url_for ( iIIIII1i111i ) )
 if request . form . get ( 'conID' ) :
  i1iiiiIIIiIi = request . form . get ( 'conID' )
  iIIiii1iI = request . form . get ( 'operate' )
  ooOOooO0 = extern_multi_card_setup_form ( )
  ooOOooO0 . f_DoorID . data = 1
  OOO = TBDoor . query . get ( i1iiiiIIIiIi )
  if OOO :
   ooOOooO0 . f_DoorID . data = i1iiiiIIIiIi
   if 83 - 83: oOO - Iii1i + ooOOO . I11II1Ii / ooOOO
   ooOOooO0 . f_DoorName . data = OOO . f_DoorName
   ooOOooO0 . f_MoreCards_Total . data = OOO . f_MoreCards_Total
   if iIIiii1iI == 'op1' :
    ii = {
 "wgform" : ooOOooO0
 }
    IiII = "wgcomm/extern-multi-card-setup.html"
    return render_template ( IiII , ** ii )
    if 5 - 5: iIi
   if iIIiii1iI == 'op2' :
    OOO00oO0oOo0O = i1iiiiIIIiIi
    iIi1I1I = " SELECT  t_b_Consumer.f_ConsumerID, "
    iIi1I1I += " f_ConsumerNO, f_ConsumerName, f_CardNO "
    if 85 - 85: oOo0O00
    iIi1I1I += " , f_MoreCards_GrpID"
    if 65 - 65: Ooo0Ooo * ooo000 + oOo0O00
    iIi1I1I += " , f_GroupID "
    iIi1I1I += " FROM t_b_Consumer "
    iIi1I1I += " LEFT OUTER JOIN t_d_doorMoreCardsUsers ON t_b_Consumer.f_ConsumerID=t_d_doorMoreCardsUsers.f_ConsumerID AND f_DoorID= " + OOO00oO0oOo0O
    iIi1I1I += " ORDER BY f_ConsumerNO ASC "
    if 71 - 71: Ooo0Ooo / ooo000
    i1ii1 = db . session . execute ( text ( iIi1I1I ) )
    I1iIIiI1 = i1ii1 . all ( )
    ii = {
 "objlist" : I1iIIiI1 ,
 "wgform" : ooOOooO0 ,

    "deleteUrl" : "/user_del" ,
 "losecardUrl" : "/user_losecard" ,

    }
    return render_template ( "wgcomm/extern-multi-card-user-list.html" , ** ii )
    if 78 - 78: iI1iII1I1I1i + iI1iII1I1I1i - I1I * IIiIIiIi11I1 % I1Ii1I1 * i1i1i1111I
    if 37 - 37: iIi * i1i1i1111I + oOo0O00 / I1I / OooOoo
@ bp . route ( '/multi_card_user_register' , methods = [ 'POST' ] )
@ login_required
def web_multi_card_user_register ( ) :
 iI1iI = vwAppConfig . parseInt ( request . form . get ( "primaryID" ) )
 if 54 - 54: I1I % ooo000 * ooo000 - OooOoo / Iii1i * Oo
 if 100 - 100: I1Ii1I1 / I11iiIi11i1I * Ii - oOO
 iiI1111II = vwAppConfig . parseInt ( request . form . get ( "f_MoreCards_GrpID" ) )
 O0OO = vwAppConfig . parseInt ( request . form . get ( "door_id" ) )
 if 34 - 34: ooOOO * I11iiIi11i1I
 if iI1iI :
  try :
   TDDoormorecardsuser . query . filter_by ( f_ConsumerID = iI1iI ) . filter_by ( f_DoorID = O0OO ) . delete ( )
   db . session . commit ( )
   if iiI1111II > 0 :
    oOo0Oo = TDDoormorecardsuser ( f_DoorID = O0OO , f_MoreCards_GrpID = iiI1111II ,
 f_ConsumerID = iI1iI )
    db . session . add ( oOo0Oo )
    db . session . commit ( )
   vwAppConfig . vwlog ( '{}--{} ' . format ( g . user . f_OperatorName ,
 "User {} door number {} multi-card setup successful!" . format (
 iI1iI , O0OO ) ) )
   if 35 - 35: oOO + OooOoo . OooOoo
   if 30 - 30: OooOoo * I1I * Ooo0Ooo . Ooo0Ooo
   return "OK"
  except Exception as ii1Ii1I :
   vwAppConfig . vwlog ( '{}--{} ' . format ( g . user . f_OperatorName ,
 "User {} door number {} multi-card setup failed!" . format (
 iI1iI , O0OO ) ) )
 return "Failed"
# dd678faae9ac167bc83abf78e5cb2f3f0688d3a3
