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 forms . wgcommform import extern_peripheral_control_setup_form , extern_inter_lock_setup_form
from models . iccard import *
import vwAppConfig
from sqlalchemy import text
if 81 - 81: i1 + ooOOO / oOo0O00 * i1iiIII111 * IiIIii11Ii
__all__ = [
 "bp" ,
 "web_extern_inter_lock_list" ,
"web_extern_inter_lock_edit" ,
"web_extern_inter_lock_option"
]
bp = Blueprint ( 'wgcomm_extern_inter_lock' , __name__ , url_prefix = '/' )
if 84 - 84: ooo000 - Ooo0Ooo + iI1iII1I1I1i . IIiIIiIi11I1
if 98 - 98: I11iiIi11i1I % oOO
@ bp . route ( '/extern_inter_lock_list' , methods = [ 'GET' , 'POST' ] )
@ login_required
def web_extern_inter_lock_list ( ) :
 i1ii1 = TBController . query . filter_by ( )
 ooo0O0oO00 = i1ii1 . all ( )
 if 55 - 55: I11II1Ii % iIi
 ii = [ "(Not enabled)" , "Door 1 and Door 2 interlock" , "Door 3 and Door 4 interlock" ,
 "Door 1 and Door 2 interlock; Door 3 and Door 4 interlock" , "Door 1, Door 2, and Door 3 interlock" , "Door 1, Door 2, Door 3, and Door 4 interlock" ]
 iiI = {
 "objlist" : ooo0O0oO00 ,

 "interlockdesc" : ii
 }
 return render_template ( "wgcomm/extern-inter-lock-list.html" , ** iiI )
 if 10 - 10: ooOOO / IIiIIiIi11I1 * oOO / I11II1Ii / I11II1Ii
 if 61 - 61: Ooo0Ooo - I1I
 if 13 - 13: Ooo0Ooo
 if 46 - 46: iI1iII1I1I1i - Ii * Oo * Ii
 if 52 - 52: Oo + I1I / oOO / OooOoo - I1Ii1I1 - ooOOO
 if 60 - 60: iI1iII1I1I1i . oOO
 if 13 - 13: oOO
 if 2 - 2: i1
 if 22 - 22: IIiIIiIi11I1 - ooo000 / I1Ii1I1 . ooo000
 if 1 - 1: iI1iII1I1I1i + Ooo0Ooo + oOO * IIiIIiIi11I1
 if 20 - 20: I1I + Ii
 if 75 - 75: Ii % i1iiIII111 * Ii . IIiIIiIi11I1 % I11iiIi11i1I % I1Ii1I1
 if 8 - 8: I1Ii1I1 . iIi . i1 . Oo - I11II1Ii
 if 32 - 32: Ii % i1i1i1111I % I11II1Ii - I11iiIi11i1I % i1iiIII111
 if 34 - 34: i1iiIII111 * i1
 if 34 - 34: oOo0O00 / i1iiIII111 - Iii1i . iI1iII1I1I1i
 if 80 - 80: i1i1i1111I . I1I % ooOOO % IiIIii11Ii / i1i1i1111I
 if 32 - 32: I1Ii1I1 + oOO - oOo0O00
 if 79 - 79: Iii1i % oOO * Oo + ooOOO / Oo . oOO
 if 20 - 20: iIi + i1iiIII111 / I1I
 if 88 - 88: I11iiIi11i1I + ooOOO - i1i1i1111I . Ooo0Ooo * Ii + Iii1i
 if 43 - 43: ooOOO * I1Ii1I1
 if 95 - 95: Ooo0Ooo % Iii1i % i1i1i1111I . OooOoo
 if 70 - 70: IiIIii11Ii
 if 75 - 75: Ooo0Ooo / Ii / IiIIii11Ii + IiIIii11Ii . I1I
 if 88 - 88: Oo * IiIIii11Ii
 if 100 - 100: iIi - OooOoo * I1Ii1I1 / Ooo0Ooo / Iii1i
 if 23 - 23: Ooo0Ooo + i1 * I1Ii1I1 + Oo * Ii - IIiIIiIi11I1
 if 29 - 29: IiIIii11Ii - oOo0O00
 if 30 - 30: I1I . ooo000
 if 43 - 43: ooOOO . I11iiIi11i1I + ooo000
 if 87 - 87: Iii1i + ooOOO . I11II1Ii / Ii + Oo
 if 77 - 77: i1iiIII111 + iIi - Oo % ooo000
 if 74 - 74: Ii + Ooo0Ooo
 if 1 - 1: I1I % Ooo0Ooo + i1iiIII111 . i1iiIII111 % Oo
 if 93 - 93: oOo0O00 % Ooo0Ooo * i1iiIII111
 if 52 - 52: oOO + I1I / ooo000 - I1Ii1I1 * I11II1Ii % oOo0O00
 if 52 - 52: oOo0O00 . I1I + I11II1Ii - i1iiIII111 % iI1iII1I1I1i
 if 57 - 57: I1I * IIiIIiIi11I1 % I1Ii1I1 * i1i1i1111I
 if 37 - 37: iIi * i1i1i1111I + oOo0O00 / I1I / OooOoo
 if 4 - 4: i1
 if 61 - 61: iI1iII1I1I1i . I11II1Ii - ooo000 / ooo000 - i1
 if 19 - 19: Iii1i * Ooo0Ooo . I1Ii1I1 / I11iiIi11i1I * Ii - oOO
 if 32 - 32: iI1iII1I1I1i
 if 18 - 18: I11iiIi11i1I * iIi % iI1iII1I1I1i + iIi
 if 93 - 93: oOO - I1Ii1I1 - IIiIIiIi11I1 * ooOOO - i1
 if 82 - 82: IIiIIiIi11I1 % i1 * ooOOO
 if 57 - 57: oOo0O00
 if 31 - 31: i1iiIII111 + i1i1i1111I % OooOoo
 if 20 - 20: OooOoo - I1I
 if 9 - 9: i1iiIII111 - iI1iII1I1I1i % Ii - I1I
 if 54 - 54: Iii1i % ooo000 % Iii1i - IiIIii11Ii
 if 39 - 39: oOO - oOO * i1 % IIiIIiIi11I1
 if 29 - 29: IIiIIiIi11I1 - ooo000 . i1iiIII111
 if 86 - 86: I1Ii1I1 - OooOoo - oOO % ooo000 . I11II1Ii % Iii1i
 if 11 - 11: OooOoo - I1Ii1I1 - ooOOO . i1iiIII111 - iI1iII1I1I1i / i1iiIII111
 if 44 - 44: Ooo0Ooo + i1i1i1111I + Iii1i - oOO
 if 7 - 7: i1i1i1111I / Ii * Iii1i
 if 32 - 32: iIi . OooOoo
 if 31 - 31: Oo - I11II1Ii
 if 28 - 28: ooOOO * I1Ii1I1 + iIi % Oo
 if 100 - 100: Oo + I11II1Ii
 if 4 - 4: ooo000 % I1I - i1i1i1111I
 if 76 - 76: i1 * oOo0O00 . iIi * I11II1Ii . IiIIii11Ii . oOO
 if 55 - 55: i1i1i1111I + i1iiIII111 % Ooo0Ooo . Oo - IiIIii11Ii - iI1iII1I1I1i
 if 91 - 91: I1Ii1I1 - I11iiIi11i1I
@ bp . route ( '/extern_inter_lock_edit' , methods = [ 'POST' ] )
@ login_required
def web_extern_inter_lock_edit ( ) :
 OO00OOooO = "wgcomm/extern-inter-lock-edit.html"
 o000OOoOO = "wgcomm_extern_inter_lock.web_extern_inter_lock_list"
 if request . form . get ( 'conID' ) :
  IIIII = request . form . get ( 'conID' )
  oooo0OO0o0 = AddControllerForm ( )
  oooo0OO0o0 . f_ControllerNO . data = 1
  OooOoO0oO = TBController . query . get ( IIIII )
  if OooOoO0oO :
   oooo0OO0o0 . f_ControllerID . data = IIIII
   oooo0OO0o0 . f_ControllerNO . data = OooOoO0oO . f_ControllerNO
   oooo0OO0o0 . f_ControllerSN . data = OooOoO0oO . f_ControllerSN
   oooo0OO0o0 . f_ForceWarn . data = OooOoO0oO . f_ForceWarn
   oooo0OO0o0 . f_InvalidCardWarn . data = OooOoO0oO . f_InvalidCardWarn
   oooo0OO0o0 . f_DoorInvalidOpen . data = OooOoO0oO . f_DoorInvalidOpen
   oooo0OO0o0 . f_DoorOpenTooLong . data = OooOoO0oO . f_DoorOpenTooLong
   oooo0OO0o0 . producttype . data = vwAppConfig . getProductType ( OooOoO0oO . f_ControllerSN )
   oooo0OO0o0 . f_InterLock . data = OooOoO0oO . f_InterLock & 0xff
   oooo0OO0o0 . f_InterLock_share_group . data = ( OooOoO0oO . f_InterLock >> 8 ) & 0xff
   oooo0OO0o0 . f_inter_lock_share . data = int ( TASystemparam . query . filter_by ( f_NO = 61 ) . first ( ) . f_Value )
   if 85 - 85: IIiIIiIi11I1 + I11iiIi11i1I % Ooo0Ooo + oOO * i1iiIII111
  return render_template ( OO00OOooO , wgform = oooo0OO0o0 )
 if request . form . get ( 'f_ControllerID' ) :
  oooo0OO0o0 = AddControllerForm ( request . form )
  if oooo0OO0o0 . submitcancel . data :
   return redirect ( url_for ( o000OOoOO ) )
  if oooo0OO0o0 . submitsaveandadd . data :
   IIIII = oooo0OO0o0 . f_ControllerID . data
   oooo0OO0o0 = AddControllerForm ( )
   oooo0OO0o0 . f_ControllerNO . data = 1
   OooOoO0oO = TBController . query . get ( IIIII )
   if OooOoO0oO :
    oooo0OO0o0 . f_ControllerID . data = IIIII
    oooo0OO0o0 . f_ControllerNO . data = OooOoO0oO . f_ControllerNO
    oooo0OO0o0 . f_ControllerSN . data = OooOoO0oO . f_ControllerSN
    oooo0OO0o0 . producttype . data = vwAppConfig . getProductType ( OooOoO0oO . f_ControllerSN )
    oooo0OO0o0 . f_inter_lock_share . data = int ( TASystemparam . query . filter_by ( f_NO = 61 ) . first ( ) . f_Value )
   return render_template ( OO00OOooO , wgform = oooo0OO0o0 )
  if oooo0OO0o0 . validate ( ) :
   OOOoo0 = oooo0OO0o0 . f_ControllerNO . data
   I11 = oooo0OO0o0 . f_ControllerSN . data
   i1II1 = oooo0OO0o0 . f_ControllerID . data
   oOoOo = oooo0OO0o0 . f_InterLock . data
   o0oOoo0O0o0Oo = oooo0OO0o0 . f_InterLock_share_group . data
   oOoOo = oOoOo + ( o0oOoo0O0o0Oo << 8 )
   if 2 - 2: IIiIIiIi11I1 + iI1iII1I1I1i - I1Ii1I1 + ooOOO . IIiIIiIi11I1
   if 15 - 15: ooo000
   TBController . query . filter_by ( f_ControllerID = i1II1 ) . update (
 { "f_InterLock" : oOoOo } , synchronize_session = False )
   if 63 - 63: I11II1Ii
   try :
    db . session . commit ( )
    vwAppConfig . setcontrollerdoorChangeTime ( )
    flash ( "Controller {} modified successfully! Takes effect only after uploading settings in the main console!!!" . format ( I11 ) )
    vwAppConfig . vwlog ( '{}--{}' . format ( g . user . f_OperatorName , "Controller {} modified successfully! Takes effect only after uploading settings in the main console!!!" . format (
 I11 ) ) )
    return redirect ( url_for ( o000OOoOO ) )
   except Exception as i1Ii :
    print ( i1Ii )
    if 32 - 32: oOO
    db . session . rollback ( )
    flash ( "Controller Edit Failed！" )
    return render_template ( OO00OOooO , wgform = oooo0OO0o0 )
  else :
   for oOOOO0OO00 in oooo0OO0o0 . messages :
    flash ( oOOOO0OO00 )
   return render_template ( OO00OOooO , wgform = oooo0OO0o0 )
   if 8 - 8: Oo * I1I / i1i1i1111I + i1 / I1Ii1I1
@ bp . route ( '/extern_inter_lock_option' , methods = [ 'POST' , 'GET' ] )
@ login_required
def web_extern_inter_lock_option ( ) :
 OO00OOooO = "wgcomm/extern-inter-lock-option.html"
 o000OOoOO = "wgcomm_extern_inter_lock.web_extern_inter_lock_list"
 if request . form . get ( "submitcancel" ) is not None :
  return redirect ( url_for ( o000OOoOO ) )
 if request . form . get ( 'submitsaveandadd' ) :
  flash ( "Retrieved default value successfully!" . format ( "" ) )
  oooo0OO0o0 = extern_inter_lock_setup_form ( )
  iiI = {
 "wgform" : oooo0OO0o0 ,
 }
  return render_template ( "wgcomm/extern-inter-lock-option.html" , ** iiI )
 if request . form . get ( "submitsave" ) is not None :
  oooo0OO0o0 = extern_inter_lock_setup_form ( request . form )
  iI = oooo0OO0o0 . f_inter_lock_share . data
  if 58 - 58: IIiIIiIi11I1 % Ii + oOo0O00 / oOo0O00 * iI1iII1I1I1i * i1i1i1111I
  if 88 - 88: I11II1Ii + I1I
  TASystemparam . query . filter_by ( f_NO = 61 ) . update (
 { "f_Value" : iI } , synchronize_session = False )
  try :
   db . session . commit ( )
   vwAppConfig . setcontrollerdoorChangeTime ( )
   flash ( "Interlock option modified successfully! Takes effect only after uploading settings in the main console!!!" . format ( "" ) )
   vwAppConfig . vwlog ( '{}--{}' . format ( g . user . f_OperatorName , "Modified successfully! Takes effect only after uploading settings in the main console!!!" . format (
 ) ) )
   return redirect ( url_for ( o000OOoOO ) )
  except Exception as i1Ii :
   print ( i1Ii )
   if 55 - 55: oOO
   db . session . rollback ( )
   flash ( "Interlock option modification failed!" )
   return render_template ( OO00OOooO , wgform = oooo0OO0o0 )
   if 29 - 29: ooOOO / i1i1i1111I / I1Ii1I1 . iIi + I11II1Ii * oOo0O00
 oooo0OO0o0 = extern_inter_lock_setup_form ( )
 oooo0OO0o0 . f_inter_lock_share . data = int ( TASystemparam . query . filter_by ( f_NO = 61 ) . first ( ) . f_Value )
 if 57 - 57: iI1iII1I1I1i
 iiI = {
 "wgform" : oooo0OO0o0 ,
 }
 return render_template ( "wgcomm/extern-inter-lock-option.html" , ** iiI )
 if 89 - 89: ooo000 * I11iiIi11i1I + oOO
# dd678faae9ac167bc83abf78e5cb2f3f0688d3a3
