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
if 81 - 81: i1 + ooOOO / oOo0O00 * i1iiIII111 * IiIIii11Ii
__all__ = [
 "bp" ,
 "web_timeprofile_list" ,
 "web_timeprofile_add" ,
 "web_timeprofile_del" ,
 "web_timeprofile_edit"

]
bp = Blueprint ( 'wgcomm_timeprofile' , __name__ , url_prefix = '/' )
if 84 - 84: ooo000 - Ooo0Ooo + iI1iII1I1I1i . IIiIIiIi11I1
if 98 - 98: I11iiIi11i1I % oOO
@ bp . route ( '/web_timeprofile_list' , methods = [ 'GET' , 'POST' ] )
@ login_required
def web_timeprofile_list ( ) :
 i1ii1 = TBControlseg . query . order_by ( TBControlseg . f_ControlSegID )
 ooo0O0oO00 = i1ii1 . all ( )
 o00o0OO00O = {
 "objlist" : ooo0O0oO00 ,
 "deleteUrl" : "/timeprofile_del" ,
 "editSeg" : "/timeprofile_edit"
 }
 return render_template ( "wgcomm/timeprofile-list.html" , ** o00o0OO00O )
 if 57 - 57: iiIi1 - ii % Ii * i1i1i1111I / Ii
 if 43 - 43: I11iiIi11i1I
@ bp . route ( '/timeprofile_add' , methods = [ 'GET' , 'POST' ] )
@ login_required
def web_timeprofile_add ( ) :
 IIi1i111IiII = "wgcomm/timeprofile-add.html"
 i1I = "wgcomm_timeprofile.web_timeprofile_list"
 if request . method == 'GET' :
  OO0o000o = AddTimeProfileForm ( )
  OO0o000o . f_ControlSegID . data = 2
  IIiiii1IiIiII = TBControlseg . query . order_by ( TBControlseg . f_ControlSegID ) . all ( )
  if 32 - 32: iI1iII1I1I1i
  i1iiiiIIIiIi = 2
  if IIiiii1IiIiII :
   i1iiiiIIIiIi = 2
   for II in IIiiii1IiIiII :
    if II . f_ControlSegID != i1iiiiIIIiIi :
     if 34 - 34: Ooo0Ooo + oOO * IIiIIiIi11I1 * OooOoo
     break
    else :
     i1iiiiIIIiIi += 1
  if i1iiiiIIIiIi > 254 :
   flash ( "Time Profile ID <= 254" )
   return redirect ( url_for ( i1I ) )
  OO0o000o . f_ControlSegID . data = i1iiiiIIIiIi
  return render_template ( IIi1i111IiII , wgform = OO0o000o )
 else :
  OO0o000o = AddTimeProfileForm ( request . form )
  if OO0o000o . submitcancel . data :
   return redirect ( url_for ( i1I ) )
  if OO0o000o . validate ( ) :
   Ii111 = OO0o000o . f_ControlSegID . data
   Iio0 = OO0o000o . f_ControlSegName . data
   if 11 - 11: ii . i1i1i1111I
   I1i = OO0o000o . f_Monday . data
   i1111IIi = OO0o000o . f_Tuesday . data
   oOo00O = OO0o000o . f_Wednesday . data
   OoO = OO0o000o . f_Thursday . data
   ii1IiIiiII = OO0o000o . f_Friday . data
   I1I111i11I = OO0o000o . f_Saturday . data
   iii11i = OO0o000o . f_Sunday . data
   Oo0Oo00O0OO = OO0o000o . f_BeginYMD . data
   iIIiiIi1Ii1I = OO0o000o . f_EndYMD . data
   if 71 - 71: oOO - Oo . OooOoo . Ii % iiIi1 + oOO
   IiII = vwAppConfig . getDateTimeFromStr (
 "{} {}" . format ( OO0o000o . f_BeginYMD . data , OO0o000o . f_BeginHMS1 . data ) )
   I1i1i = vwAppConfig . getDateTimeFromStr ( "{} {}" . format ( OO0o000o . f_EndYMD . data , OO0o000o . f_EndHMS1 . data ) )
   O0ooooOoo0O = vwAppConfig . getDateTimeFromStr (
 "{} {}" . format ( OO0o000o . f_BeginYMD . data , OO0o000o . f_BeginHMS2 . data ) )
   oo0oOo = vwAppConfig . getDateTimeFromStr ( "{} {}" . format ( OO0o000o . f_EndYMD . data , OO0o000o . f_EndHMS2 . data ) )
   oOOOo = vwAppConfig . getDateTimeFromStr (
 "{} {}" . format ( OO0o000o . f_BeginYMD . data , OO0o000o . f_BeginHMS3 . data ) )
   iiIIIiII11I1 = vwAppConfig . getDateTimeFromStr ( "{} {}" . format ( OO0o000o . f_EndYMD . data , OO0o000o . f_EndHMS3 . data ) )
   oOo = OO0o000o . f_ControlSegIDLinked . data
   o0O = OO0o000o . f_ControlByHoliday . data
   Oo0Oo00O0OO = vwAppConfig . getDateTimeFromStr ( Oo0Oo00O0OO )
   iIIiiIi1Ii1I = vwAppConfig . getDateTimeFromStr ( iIIiiIi1Ii1I )
   if 45 - 45: Ooo0Ooo + I11iiIi11i1I % ooo000 . I1I % Ii + Ooo0Ooo
   iIi1I1I = TBControlseg . query . filter_by ( f_ControlSegID = Ii111 ) . first ( )
   if iIi1I1I :
    flash ( "TimeProfile ID duplicated  " )
    return render_template ( IIi1i111IiII , wgform = OO0o000o )
    if 85 - 85: oOo0O00
   OO0O0oo = OO0o000o . f_ReaderCount . data
   O0o00OO0oOOo = OO0o000o . f_LimitedTimesOfDayCurrentDay . data & 0xff
   O0o00OO0oOOo = O0o00OO0oOOo + ( OO0o000o . f_LimitedTimesOfDayMonth . data << 8 )
   OOO0o0O0o = OO0o000o . f_LimitedTimesOfHMS1 . data
   I111Iii1Ii = OO0o000o . f_LimitedTimesOfHMS2 . data
   iiIiII11i11II = OO0o000o . f_LimitedTimesOfHMS3 . data
   if 52 - 52: Iii1i / Oo
   o00O = TBControlseg ( f_ControlSegID = Ii111 , f_ControlSegName = Iio0 ,

   f_Monday = I1i ,
 f_Tuesday = i1111IIi ,
 f_Wednesday = oOo00O ,
 f_Thursday = OoO ,
 f_Friday = ii1IiIiiII ,
 f_Saturday = I1I111i11I ,
 f_Sunday = iii11i ,
 f_BeginYMD = Oo0Oo00O0OO ,
 f_EndYMD = iIIiiIi1Ii1I ,
 f_BeginHMS1 = IiII ,
 f_EndHMS1 = I1i1i ,
 f_BeginHMS2 = O0ooooOoo0O ,
 f_EndHMS2 = oo0oOo ,
 f_BeginHMS3 = oOOOo ,
 f_EndHMS3 = iiIIIiII11I1 ,
 f_ControlSegIDLinked = oOo ,
 f_ControlByHoliday = o0O ,
 f_ReaderCount = OO0O0oo ,
 f_LimitedTimesOfDay = O0o00OO0oOOo ,
 f_LimitedTimesOfHMS1 = OOO0o0O0o ,
 f_LimitedTimesOfHMS2 = I111Iii1Ii ,
 f_LimitedTimesOfHMS3 = iiIiII11i11II
 )
   try :
    db . session . add ( o00O )
    db . session . commit ( )
    flash ( "  Add Successfully ！" )
    vwAppConfig . vwlog ( '{}--{}' . format ( g . user . f_OperatorName ,
 "TimeProfile {} added successfully!  " . format (
 Ii111 ) ) )
    return redirect ( url_for ( i1I ) )
   except Exception as iIi :
    print ( iIi )
    if 60 - 60: oOO % i1iiIII111 % ii - I11iiIi11i1I * oOO - iI1iII1I1I1i
    db . session . rollback ( )
    flash ( " Add Failed ！" )
    vwAppConfig . vwlog ( '{}--{}[{}]' . format ( g . user . f_OperatorName ,
 "TimeProfile {} failed to add!  " . format ( Ii111 ) ,
 iIi ) )
    return render_template ( IIi1i111IiII , wgform = OO0o000o )
  else :
   for IIi1I1I1i in OO0o000o . messages :
    flash ( IIi1I1I1i )
   return render_template ( IIi1i111IiII , wgform = OO0o000o )
   if 36 - 36: oOo0O00 . ooOOO / i1iiIII111 + oOO
   if 11 - 11: i1 / ooo000
@ bp . route ( '/timeprofile_del' , methods = [ 'POST' ] )
@ login_required
def web_timeprofile_del ( ) :
 Ii111 = request . form . get ( "primaryID" )
 i1I = "wgcomm_timeprofile.web_timeprofile_list"
 if Ii111 :
  try :
   TBControlseg . query . filter_by ( f_ControlSegID = Ii111 ) . delete ( )
   db . session . commit ( )
   flash ( "Delete  Successfully " )
   vwAppConfig . vwlog ( '{}--{}' . format ( g . user . f_OperatorName ,
 "TimeProfile {} deleted successfully!  " . format ( Ii111 ) ) )
  except Exception as iIi :
   vwAppConfig . vwlog ( '{}--{}[{}]' . format ( g . user . f_OperatorName ,
 "TimeProfile {} failed to delete!  " . format ( Ii111 ) ,
 iIi ) )
 return redirect ( url_for ( i1I ) )
 if 89 - 89: I1I * i1i1i1111I
 if 54 - 54: oOO + Ooo0Ooo - I1I . Ooo0Ooo
@ bp . route ( '/timeprofile_edit' , methods = [ 'POST' ] )
@ login_required
def web_timeprofile_edit ( ) :
 if 50 - 50: Iii1i * ooo000 % Iii1i - oOo0O00 + ooo000
 if 54 - 54: oOO * i1 % i1 - Ooo0Ooo + IIiIIiIi11I1
 if 4 - 4: ooo000 + I1Ii1I1 * OooOoo - ii
 if 69 - 69: ooo000
 if 76 - 76: Iii1i * Ooo0Ooo . iI1iII1I1I1i / Ii / ooOOO
 if 49 - 49: iI1iII1I1I1i / i1iiIII111 + ooo000
 if 36 - 36: i1i1i1111I + Iii1i - oOO * Ii
 if 45 - 45: i1i1i1111I * Ii
 if 97 - 97: i1
 if 26 - 26: ii
 if 20 - 20: IIiIIiIi11I1 / Oo
 if 73 - 73: ooOOO - IiIIii11Ii
 if 22 - 22: Oo % oOo0O00 / iiIi1 . oOo0O00 . iiIi1
 if 87 - 87: I1I - iiIi1 . i1 * Oo
 IIi1i111IiII = "wgcomm/timeprofile-edit.html"
 i1I = "wgcomm_timeprofile.web_timeprofile_list"
 if request . form . get ( "submitcancel" ) is not None :
  return redirect ( url_for ( i1I ) )
 Ii111 = request . form . get ( "f_ControlSegID" )
 if Ii111 is not None and int ( Ii111 ) > 0 and request . form . get ( "submitsave" ) is None :
  if 90 - 90: ii * iiIi1 . Ii
  OO0o000o = AddTimeProfileForm ( )
  OO0o000o . f_ControlSegID . data = Ii111
  iIi1I1I = TBControlseg . query . filter_by ( f_ControlSegID = Ii111 ) . first ( )
  if iIi1I1I :
   if 45 - 45: IiIIii11Ii - I11iiIi11i1I . i1iiIII111 * Ooo0Ooo . IIiIIiIi11I1
   OO0o000o . f_ControlSegID . data = iIi1I1I . f_ControlSegID
   OO0o000o . f_ControlSegName . data = iIi1I1I . f_ControlSegName
   if 14 - 14: iI1iII1I1I1i + OooOoo * I1Ii1I1 - I11iiIi11i1I
   OO0o000o . f_Monday . data = iIi1I1I . f_Monday
   OO0o000o . f_Tuesday . data = iIi1I1I . f_Tuesday
   OO0o000o . f_Wednesday . data = iIi1I1I . f_Wednesday
   OO0o000o . f_Thursday . data = iIi1I1I . f_Thursday
   OO0o000o . f_Friday . data = iIi1I1I . f_Friday
   OO0o000o . f_Saturday . data = iIi1I1I . f_Saturday
   OO0o000o . f_Sunday . data = iIi1I1I . f_Sunday
   OO0o000o . f_BeginYMD . data = vwAppConfig . getStrOfDatetimeYMD ( iIi1I1I . f_BeginYMD )
   OO0o000o . f_EndYMD . data = vwAppConfig . getStrOfDatetimeYMD ( iIi1I1I . f_EndYMD )
   OO0o000o . f_BeginHMS1 . data = vwAppConfig . getStrOfDatetimeHHMM ( iIi1I1I . f_BeginHMS1 )
   OO0o000o . f_EndHMS1 . data = vwAppConfig . getStrOfDatetimeHHMM ( iIi1I1I . f_EndHMS1 )
   OO0o000o . f_BeginHMS2 . data = vwAppConfig . getStrOfDatetimeHHMM ( iIi1I1I . f_BeginHMS2 )
   OO0o000o . f_EndHMS2 . data = vwAppConfig . getStrOfDatetimeHHMM ( iIi1I1I . f_EndHMS2 )
   OO0o000o . f_BeginHMS3 . data = vwAppConfig . getStrOfDatetimeHHMM ( iIi1I1I . f_BeginHMS3 )
   OO0o000o . f_EndHMS3 . data = vwAppConfig . getStrOfDatetimeHHMM ( iIi1I1I . f_EndHMS3 )
   if 84 - 84: oOO % iI1iII1I1I1i - Ooo0Ooo
   OO0o000o . f_ReaderCount . data = iIi1I1I . f_ReaderCount
   OO0o000o . f_LimitedTimesOfDayCurrentDay . data = iIi1I1I . f_LimitedTimesOfDay & 0xff
   OO0o000o . f_LimitedTimesOfDayMonth . data = ( iIi1I1I . f_LimitedTimesOfDay & 0xff00 ) >> 8
   OO0o000o . f_LimitedTimesOfHMS1 . data = iIi1I1I . f_LimitedTimesOfHMS1
   OO0o000o . f_LimitedTimesOfHMS2 . data = iIi1I1I . f_LimitedTimesOfHMS2
   OO0o000o . f_LimitedTimesOfHMS3 . data = iIi1I1I . f_LimitedTimesOfHMS3
   if 94 - 94: i1iiIII111 + i1i1i1111I / iI1iII1I1I1i + iI1iII1I1I1i / iiIi1
   if 79 - 79: i1iiIII111 - IIiIIiIi11I1 . I1Ii1I1 + I1I - ooOOO + i1iiIII111
   if 36 - 36: ooOOO * Iii1i % I1I % i1 . Ooo0Ooo
   if 63 - 63: IIiIIiIi11I1 / IIiIIiIi11I1 * Iii1i - oOo0O00 . i1
   if 52 - 52: oOo0O00 / iiIi1 * IIiIIiIi11I1 + I11iiIi11i1I % Ooo0Ooo + oOO
   if 43 - 43: iI1iII1I1I1i * oOo0O00 + ooOOO
   if 30 - 30: I1I
   if 41 - 41: oOO
   if 98 - 98: I1I / IIiIIiIi11I1 / iiIi1 + ii % Oo + I1I
   if 38 - 38: I1Ii1I1 + oOo0O00
   if 2 - 2: OooOoo % Ii + oOO . OooOoo + IIiIIiIi11I1 * Oo
   if 2 - 2: IIiIIiIi11I1 + iI1iII1I1I1i - I1Ii1I1 + ooOOO . IIiIIiIi11I1
   OO0o000o . f_ControlSegIDLinked . data = iIi1I1I . f_ControlSegIDLinked
   OO0o000o . f_ControlByHoliday . data = iIi1I1I . f_ControlByHoliday
   if 15 - 15: ooo000
   if 63 - 63: iiIi1
   if 81 - 81: OooOoo . iiIi1 / i1i1i1111I + Oo / Ooo0Ooo % ii
   if 77 - 77: I11iiIi11i1I / iI1iII1I1I1i - oOo0O00 - Ooo0Ooo % oOo0O00
   if 73 - 73: ii . Oo * I1I / i1i1i1111I + I1Ii1I1
   if 31 - 31: i1i1i1111I % I1Ii1I1
   if 1 - 1: ii - oOo0O00 - i1 . oOo0O00
   if 91 - 91: iI1iII1I1I1i * i1 . ooOOO
   if 81 - 81: I1I * Oo - i1 % OooOoo * ooOOO
   if 19 - 19: Ii
   if 22 - 22: iiIi1 % iI1iII1I1I1i + Oo
   if 60 - 60: ooo000 + I11iiIi11i1I + IIiIIiIi11I1 % i1i1i1111I - Ii % Ooo0Ooo
   if 95 - 95: ooOOO % i1i1i1111I . i1
   if 87 - 87: Iii1i % ooOOO * Ii % IIiIIiIi11I1 / I11iiIi11i1I
   if 84 - 84: I1Ii1I1 + Ooo0Ooo % IIiIIiIi11I1 * i1i1i1111I
   if 61 - 61: i1iiIII111 - Oo + I1Ii1I1
   if 43 - 43: IIiIIiIi11I1 * ooo000 + Ii % iI1iII1I1I1i
   if 12 - 12: i1iiIII111 + ooo000 . I11iiIi11i1I
   if 1 - 1: iI1iII1I1I1i % Ii - I11iiIi11i1I / ii + iI1iII1I1I1i - Ii
  return render_template ( IIi1i111IiII , wgform = OO0o000o )
 else :
  OO0o000o = AddTimeProfileForm ( request . form )
  if OO0o000o . submitcancel . data :
   return redirect ( url_for ( i1I ) )
  if OO0o000o . validate ( ) :
   Ii111 = OO0o000o . f_ControlSegID . data
   Iio0 = OO0o000o . f_ControlSegName . data
   if 27 - 27: OooOoo % iI1iII1I1I1i + IIiIIiIi11I1
   I1i = OO0o000o . f_Monday . data
   i1111IIi = OO0o000o . f_Tuesday . data
   oOo00O = OO0o000o . f_Wednesday . data
   OoO = OO0o000o . f_Thursday . data
   ii1IiIiiII = OO0o000o . f_Friday . data
   I1I111i11I = OO0o000o . f_Saturday . data
   iii11i = OO0o000o . f_Sunday . data
   Oo0Oo00O0OO = OO0o000o . f_BeginYMD . data
   iIIiiIi1Ii1I = OO0o000o . f_EndYMD . data
   if 16 - 16: ii
   IiII = vwAppConfig . getDateTimeFromStr (
 "{} {}" . format ( OO0o000o . f_BeginYMD . data , OO0o000o . f_BeginHMS1 . data ) )
   I1i1i = vwAppConfig . getDateTimeFromStr ( "{} {}" . format ( OO0o000o . f_EndYMD . data , OO0o000o . f_EndHMS1 . data ) )
   O0ooooOoo0O = vwAppConfig . getDateTimeFromStr (
 "{} {}" . format ( OO0o000o . f_BeginYMD . data , OO0o000o . f_BeginHMS2 . data ) )
   oo0oOo = vwAppConfig . getDateTimeFromStr ( "{} {}" . format ( OO0o000o . f_EndYMD . data , OO0o000o . f_EndHMS2 . data ) )
   oOOOo = vwAppConfig . getDateTimeFromStr (
 "{} {}" . format ( OO0o000o . f_BeginYMD . data , OO0o000o . f_BeginHMS3 . data ) )
   iiIIIiII11I1 = vwAppConfig . getDateTimeFromStr ( "{} {}" . format ( OO0o000o . f_EndYMD . data , OO0o000o . f_EndHMS3 . data ) )
   oOo = OO0o000o . f_ControlSegIDLinked . data
   o0O = OO0o000o . f_ControlByHoliday . data
   Oo0Oo00O0OO = vwAppConfig . getDateTimeFromStr ( Oo0Oo00O0OO )
   iIIiiIi1Ii1I = vwAppConfig . getDateTimeFromStr ( iIIiiIi1Ii1I )
   if 31 - 31: oOo0O00 / Iii1i % Ooo0Ooo % i1 . iI1iII1I1I1i . Oo
   OO0O0oo = OO0o000o . f_ReaderCount . data
   O0o00OO0oOOo = OO0o000o . f_LimitedTimesOfDayCurrentDay . data & 0xff
   O0o00OO0oOOo = O0o00OO0oOOo + ( OO0o000o . f_LimitedTimesOfDayMonth . data << 8 )
   OOO0o0O0o = OO0o000o . f_LimitedTimesOfHMS1 . data
   I111Iii1Ii = OO0o000o . f_LimitedTimesOfHMS2 . data
   iiIiII11i11II = OO0o000o . f_LimitedTimesOfHMS3 . data
   iIi1I1I = TBControlseg . query . filter_by ( f_ControlSegID = Ii111 ) . first ( )
   if iIi1I1I :
    TBControlseg . query . filter_by ( f_ControlSegID = Ii111 ) . delete ( )
    db . session . commit ( )
    if 83 - 83: oOo0O00 - I11iiIi11i1I
    if 91 - 91: IIiIIiIi11I1 - i1 - iI1iII1I1I1i
    if 71 - 71: I1I - ii
   o00O = TBControlseg ( f_ControlSegID = Ii111 , f_ControlSegName = Iio0 ,

   f_Monday = I1i ,
 f_Tuesday = i1111IIi ,
 f_Wednesday = oOo00O ,
 f_Thursday = OoO ,
 f_Friday = ii1IiIiiII ,
 f_Saturday = I1I111i11I ,
 f_Sunday = iii11i ,
 f_BeginYMD = Oo0Oo00O0OO ,
 f_EndYMD = iIIiiIi1Ii1I ,
 f_BeginHMS1 = IiII ,
 f_EndHMS1 = I1i1i ,
 f_BeginHMS2 = O0ooooOoo0O ,
 f_EndHMS2 = oo0oOo ,
 f_BeginHMS3 = oOOOo ,
 f_EndHMS3 = iiIIIiII11I1 ,
 f_ControlSegIDLinked = oOo ,
 f_ControlByHoliday = o0O ,
 f_ReaderCount = OO0O0oo ,
 f_LimitedTimesOfDay = O0o00OO0oOOo ,
 f_LimitedTimesOfHMS1 = OOO0o0O0o ,
 f_LimitedTimesOfHMS2 = I111Iii1Ii ,
 f_LimitedTimesOfHMS3 = iiIiII11i11II
 )
   try :
    db . session . add ( o00O )
    db . session . commit ( )
    flash ( "  Edit Successfully ！" )
    vwAppConfig . vwlog ( '{}--{}' . format ( g . user . f_OperatorName ,
 "TimeProfile {} modified successfully!  " . format (
 Ii111 ) ) )
    return redirect ( url_for ( i1I ) )
   except Exception as iIi :
    print ( iIi )
    if 66 - 66: i1i1i1111I / Ooo0Ooo + I11iiIi11i1I + Iii1i + oOo0O00 + iiIi1
    db . session . rollback ( )
    flash ( " Edit Failed ！" )
    vwAppConfig . vwlog ( '{}--{}[{}]' . format ( g . user . f_OperatorName ,
 "TimeProfile {} failed to modify!" . format ( Ii111 ) ,
 iIi ) )
    return render_template ( IIi1i111IiII , wgform = OO0o000o )
  else :
   for IIi1I1I1i in OO0o000o . messages :
    flash ( IIi1I1I1i )
   return render_template ( IIi1i111IiII , wgform = OO0o000o )
# dd678faae9ac167bc83abf78e5cb2f3f0688d3a3
