--0.门禁系统初始化菜单
INSERT INTO dbo.ST_MenuInfo(Menu_ID,System_No,Menu_No,Menu_Name,Menu_Hint,Para_ID,Call_Mode,Form_Name,ShortKey,
                        Menu_Index,Image_Index,Separator,InToolBar,Remark)
SELECT * FROM (SELECT 145[Menu_ID],'MJ'[System_No],'MJ_01'[Menu_No],'系统管理'[Menu_Name],NULL[Menu_Hint],-1[Para_ID],NULL[Call_Mode],
                      NULL[Form_Name],NULL[ShortKey],'1'[Menu_Index],-1[Image_Index],NULL[Separator],0[InToolBar],NULL[Remark]
                UNION ALL SELECT 146,'MJ','MJ_0101','系统参数','系统参数',145,'2','TfrmAcsParam',NULL,'1',42,'1',0,NULL
                UNION ALL SELECT 147,'MJ','MJ_0102','退出系统','退出系统',145,'5','Exit',NULL,'2',0,'0',0,NULL
                UNION ALL SELECT 148,'MJ','MJ_03','门禁管理',NULL,-1,NULL,NULL,NULL,'2',-1,NULL,0,NULL
                UNION ALL SELECT 149,'MJ','MJ_0301','控制器设置','控制器设置',148,'2','TfrmController',NULL,'1',44,'0',0,NULL
                UNION ALL SELECT 150,'MJ','MJ_0302','门属性设置','门属性设置',148,'2','TfrmDoor',NULL,'3',45,'1',0,NULL
                UNION ALL SELECT 151,'MJ','MJ_0303','人员设置','人员设置',148,'1','TfrmAcsPerson',NULL,'4',46,'1',0,NULL
	        	UNION ALL SELECT 452,'MJ','MJ_0306','门权限设置','门权限设置',148,'1','TfrmAscDoor',NULL,'7',45,'1',0,NULL
                UNION ALL SELECT 152,'MJ','MJ_0304','超级卡或密码','超级卡或密码',148,'2','TfrmCardAndPwd',NULL,'5',47,'0',0,NULL
                UNION ALL SELECT 153,'MJ','MJ_02','时段管理',NULL,-1,NULL,NULL,NULL,'3',-1,NULL,0,NULL
                UNION ALL SELECT 154,'MJ','MJ_0201','门开关时段设置','门开关时段设置',153,'2','TfrmDoorPeriod',NULL,'1',-1,'0',0,NULL
                UNION ALL SELECT 155,'MJ','MJ_0202','门特殊时段设置','门特殊时段设置',153,'2','TfrmDoorSpecial',NULL,'2',-1,'1',0,NULL
                UNION ALL SELECT 156,'MJ','MJ_0203','人进出时段设置','人进出时段设置',153,'2','TfrmPersonPeriod',NULL,'3',-1,'0',0,NULL
                UNION ALL SELECT 157,'MJ','MJ_0204','人特殊时段设置','人特殊时段设置',153,'2','TfrmPersonSpecial',NULL,'4',-1,'1',0,NULL
                UNION ALL SELECT 158,'MJ','MJ_04','控制管理',NULL,-1,NULL,NULL,NULL,'4',-1,NULL,0,NULL
                UNION ALL SELECT 159,'MJ','MJ_0401','控制器联动设置','控制器联动设置',158,'2','TfrmLinkage',NULL,'1',-1,'0',0,NULL
                UNION ALL SELECT 160,'MJ','MJ_0402','报警输出设置','报警输出设置',158,'2','TfrmAlarmOutput',NULL,'2',-1,'1',0,NULL
                UNION ALL SELECT 161,'MJ','MJ_0403','多门互锁设置','多门互锁设置',158,'2','TfrmDoorInterlock',NULL,'3',-1,'0',0,NULL
                UNION ALL SELECT 162,'MJ','MJ_0404','紧急群组设置','紧急群组设置',158,'2','TfrmUrgencyGroup',NULL,'4',-1,'0',0,NULL
                UNION ALL SELECT 163,'MJ','MJ_05','远程监控',NULL,-1,NULL,NULL,NULL,'5',-1,NULL,0,NULL
                UNION ALL SELECT 164,'MJ','MJ_0501','门禁控制台','门禁控制台',163,'1','TfrmConsole',NULL,'1',48,'1',0,NULL
                UNION ALL SELECT 165,'MJ','MJ_0502','扩展点设置','扩展点设置',148,'2','TfrmDotState',NULL,'2',49,'0',0,NULL
                UNION ALL SELECT 166,'MJ','MJ_0503','电子地图设计','电子地图设计',163,'1','TfrmMap',NULL,'2',50,'0',0,NULL
                UNION ALL SELECT 167,'MJ','MJ_0504','地图实时监控','地图实时监控',163,'1','TfrmMapWatch',NULL,'3',51,'0',0,NULL
                UNION ALL SELECT 168,'MJ','MJ_06','门禁查询',NULL,-1,NULL,NULL,NULL,'6',-1,NULL,0,NULL
                UNION ALL SELECT 169,'MJ','MJ_0601','门禁正常刷卡记录','门禁正常刷卡记录',168,'1','TfrmNormal',NULL,'1',52,'0',0,NULL
                UNION ALL SELECT 170,'MJ','MJ_0602','门禁异常刷卡记录','门禁异常刷卡记录',168,'1','TfrmAbnormal',NULL,'2',-1,'1',0,NULL
                UNION ALL SELECT 171,'MJ','MJ_0603','报警设备事件记录','报警设备事件记录',168,'1','TfrmAlarm',NULL,'3',-1,'0',0,NULL
                UNION ALL SELECT 172,'MJ','MJ_07','系统维护',NULL,-1,NULL,NULL,NULL,'7',-1,NULL,0,NULL
                UNION ALL SELECT 173,'MJ','MJ_0701','清理过期数据','清理过期数据',172,'2','TfrmDataClean',NULL,'1',-1,'1',0,NULL
                UNION ALL SELECT 174,'MJ','MJ_0702','扩展功能设置','扩展功能设置',172,'2','TfrmExtend',NULL,'2',53,'0',0,NULL
                UNION ALL SELECT 197,'MJ','MJ_0405','首卡开门设置','首卡开门设置',158,2,'TfrmDoorFirstCardOpen',NULL,5,-1,1,0,NULL
                UNION ALL SELECT 198,'MJ','MJ_0406','多卡开门设置','多卡开门设置',158,2,'TfrmDoorMultiCardOpen',NULL,6,-1,0,0,NULL
                UNION ALL SELECT 199,'MJ','MJ_0407','管理卡设置','管理卡设置',158,2,'TfrmManaCardSetup',NULL,7,-1,0,0,NULL
	              UNION ALL SELECT 450,'MJ','MJ_0408','会议管理','会议管理',158,2,'TfrmMjMeeting',NULL,8,-1,0,0,NULL
                UNION ALL SELECT 200,'MJ','MJ_0205','进出权限方案管理','进去权限方案管理',153,'2','TfrmSolution',NULL,'5',43,'0',0,NULL
                UNION ALL SELECT 451,'MJ','MJ_0305','刷卡添加用户','刷卡添加用户',148,2,'TfrmBrushCardPerson',NULL,6,-1,0,0,NULL
                UNION ALL SELECT 650,'MJ','MJ_0409','DVS联动','DVS联动',158,1,'TfrmDVSMJScroll',NULL,9,-1,0,0,NULL
							) A
 WHERE A.Menu_ID NOT IN (SELECT Menu_ID FROM dbo.ST_MenuInfo)
GO

--1.初始化功能扩展数据
INSERT INTO dbo.MJ_ExtendFunc(Menu_No,Menu_Name,Is_Menu,Is_Use)
SELECT A.* FROM (SELECT 'Is_APB'[Menu_No],'防尾随'[Menu_Name],1[Is_Menu],0[Is_Use]
								UNION ALL SELECT 'Is_HiddenBack ','防潜回',1,0
								UNION ALL SELECT 'Is_PwdKeyBoard','密码键盘',1,0
								UNION ALL SELECT 'MJ_0401','控制器联动设置',0,0
								UNION ALL SELECT 'MJ_0402','报警输出设置',0,0
								UNION ALL SELECT 'MJ_0403','多门互锁设置',0,0
								UNION ALL SELECT 'MJ_0404','紧急群组设置',0,0
								UNION ALL SELECT 'Allow_HoldNumber ','允许容纳人数',1,0
								UNION ALL SELECT 'Is_ReadCardAttend','读卡器用于设置考勤',1,0
								UNION ALL SELECT 'MJ_0405' ,'首卡开门设置',0,0
								UNION ALL SELECT 'MJ_0406','多卡开门设置',0,0
								UNION ALL SELECT 'MJ_0407','管理卡设置',0,0
								UNION ALL SELECT 'MJ_0408','会议管理',0,0
                UNION ALL SELECT 'MJ_0409','DVS联动',0,0
							) A
WHERE A.Menu_No NOT IN(SELECT Menu_No FROM dbo.MJ_ExtendFunc)
GO	

--2.初始化资源参数表数据
DELETE FROM dbo.MJ_ResParam
GO

INSERT INTO dbo.MJ_ResParam(Ctrl_Type,Ctrl_Name,Res_Type,Idx_No,Res_Name,Res_Number,Is_Extend)
  /**/SELECT '1','一控一','0','1','门','1',0
  UNION ALL SELECT '1','一控一','1','1','输入点','1',1
  UNION ALL SELECT '1','一控一','2','1','输出点','1',1
  /**/
  UNION ALL SELECT '2','一控二','0','1','门','2',0
  UNION ALL SELECT '2','一控二','1','1','输入点','2',1
  UNION ALL SELECT '2','一控二','2','1','输出点','2',1
  /*一控四*/
  UNION ALL SELECT '4','一控四','0','1','门','4',0
  UNION ALL SELECT '4','一控四','1','1','输入点','4',1
  UNION ALL SELECT '4','一控四','2','1','输出点','4',1
  /*一控八*/
  UNION ALL SELECT '8','一控八','0','1','门','8',0
  UNION ALL SELECT '8','一控八','1','1','输入点','8',1
  UNION ALL SELECT '8','一控八','2','1','输出点','8',1
GO

--3.初始化功能扩展数据
INSERT INTO dbo.MJ_SysParam(Param_Code,Param_Name,Param_Value)
SELECT A.* FROM (SELECT 'PHOTO_DOORIN'[Param_Code],'进门是否显示照片'[Param_Name],'1'[Param_Value]
								UNION ALL SELECT 'PHOTO_DOOROUT','出门是否显示照片','1'								
								UNION ALL SELECT 'IS_AUTOCLEAR','是否自动清理过期数据','0'
								UNION ALL SELECT 'NORMAL_DAYS','正常刷卡保留天数','7'
								UNION ALL SELECT 'ABNORM_DAYS','异常刷卡保留天数','15'
								UNION ALL SELECT 'ALARM_DAYS','报警事件保留天数','15'
								UNION ALL SELECT 'CLEAR_DAYS','清理数据保留天数','30'
								UNION ALL SELECT 'CLEAR_DATE','清理过期数据日期','2006-07-15'
								UNION ALL SELECT 'ACSSERVER','门禁通信服务器','127.0.0.1'
								UNION ALL SELECT 'ACSPORT','通讯端口号','4003'
								UNION ALL SELECT 'CARDTOWIGAND26','是否需要将卡号转换为微耕26格式','0'
								UNION ALL SELECT 'ISUSECARD_SN','是否采用IC卡序列号做门禁卡号','0'
								UNION ALL SELECT 'LAST_READCARD','最后一次门禁读头读到卡号','0'
                UNION ALL SELECT 'DVSPhotoStoreDir','DVS联动存储位置',''
                UNION ALL SELECT 'Is_APB','防尾随','1'
					      UNION ALL SELECT 'Is_HiddenBack','防潜回','1'
					 ) A
WHERE A.Param_Code NOT IN(SELECT Param_Code FROM dbo.MJ_SysParam)
GO

INSERT INTO MJ_EventInfo(Event_Type,Event_Code,Event_Name,Record_Color,Info_Style)
 SELECT A.* FROM
   (SELECT 0 [Event_Type],0[Event_Code],'刷卡开门'[Event_Name],1[Record_Color],'S1'[Info_Style]
     UNION ALL SELECT	0,1,'密码开门',1,'S2'
     UNION ALL SELECT	0,2,'卡+密码开门',1,'S1'
     UNION ALL SELECT	0,3,'按钮开门',2,'S2'
     UNION ALL SELECT	0,4,'非普通模式开门',2,'S1'
     UNION ALL SELECT	0,5,'超级卡开门',1,'S2'
     UNION ALL SELECT	0,6,'远程控制开门',2,'S2'
     UNION ALL SELECT	0,7,'联动开门',2,'S2'
     UNION ALL SELECT	0,8,'门常开到点开门',2,'S2'
     UNION ALL SELECT	0,9,'多卡开门',1,'S2'
     UNION ALL SELECT	0,10,'首卡常开',1,'S4'
     UNION ALL SELECT	0,11,'首卡+密码常开',1,'S4'
     UNION ALL SELECT	0,12,'远程控制门常开',2,'S2'
     UNION ALL SELECT	0,13,'超级密码开门',1,'S2'
     UNION ALL SELECT	1,16,'解除报警',0,'S2'
     UNION ALL SELECT	1,17,'强制打开报警',4,'S3'
     UNION ALL SELECT	1,18,'门开超时报警',4,'S3'
     UNION ALL SELECT	1,19,'胁迫报警',4,'S3'
     UNION ALL SELECT	1,20,'非法卡报警',3,'S5'
     UNION ALL SELECT	1,21,'无权限报警',3,'S5'
     UNION ALL SELECT	1,22,'无时段报警',3,'S5'
     UNION ALL SELECT	1,23,'尾随报警',4,'S3'
     UNION ALL SELECT	1,24,'潜回报警',4,'S3'
     UNION ALL SELECT	1,25,'密码错误',3,'S2'
     UNION ALL SELECT	1,26,'人数不足报警',4,'S3'
     UNION ALL SELECT	1,27,'人数超限报警',4,'S3'
     UNION ALL SELECT	1,28,'不需要刷卡',3,'S2'
     UNION ALL SELECT	1,29,'门互锁无法开门',3,'S2'

     UNION ALL SELECT	2,32,'关门',2,'S2'
     UNION ALL SELECT	2,33,'门常闭',2,'S2'
     UNION ALL SELECT	2,34,'远程控制关门',2,'S2'
     UNION ALL SELECT	2,35,'远程控制门常闭',2,'S2'
     UNION ALL SELECT	2,36,'联动关门',2,'S2'
     UNION ALL SELECT	3,47,'考勤刷卡',2,'S2'
   
     UNION ALL SELECT	4,64,'输入点1报警',2,'S3'
     UNION ALL SELECT	4,65,'输入点2报警',2,'S3'
     UNION ALL SELECT	4,66,'输入点3报警',2,'S3'
     UNION ALL SELECT	4,67,'输入点4报警',2,'S3'
     UNION ALL SELECT	4,68,'输入点5报警',2,'S3'
     UNION ALL SELECT	4,69,'输入点6报警',2,'S3'
     UNION ALL SELECT	4,70,'输入点7报警',2,'S3'
     UNION ALL SELECT	4,71,'输入点8报警',2,'S3'
     UNION ALL SELECT	4,72,'输出点1报警',2,'S3'
     UNION ALL SELECT	4,73,'输出点2报警',2,'S3'
     UNION ALL SELECT	4,74,'输出点3报警',2,'S3'
     UNION ALL SELECT	4,75,'输出点4报警',2,'S3'
     UNION ALL SELECT	4,76,'输出点5报警',2,'S3'
     UNION ALL SELECT	4,77,'输出点6报警',2,'S3'
     UNION ALL SELECT	4,78,'输出点7报警',2,'S3'
     UNION ALL SELECT	4,79,'输出点8报警',2,'S3'
   ) A
 WHERE NOT EXISTS(SELECT Event_Code FROM MJ_EventInfo 
                   WHERE MJ_EventInfo.Event_Type=A.Event_Type AND MJ_EventInfo.Event_Code=A.Event_Code)
GO	

IF NOT EXISTS(SELECT DoorTime_No FROM MJ_DoorSwitchTime WHERE DoorTime_No=1)
  INSERT INTO MJ_DoorSwitchTime(DoorTime_No,DoorTime_Name,SpecTime_Info)
    VALUES(1,'任意开关时段',0)
GO

IF NOT EXISTS(SELECT DoorTime_No FROM MJ_DoorSwitchTimeSub WHERE DoorTime_No=1)
  INSERT INTO MJ_DoorSwitchTimeSub(DoorTime_No,Start_Time,End_Time,Door_State)
    VALUES(1,'00:00','23:59',2)
GO

IF NOT EXISTS(SELECT PsnTime_No FROM MJ_PsnInOutTime WHERE PsnTime_No=1)
  INSERT INTO MJ_PsnInOutTime(PsnTime_No,PsnTime_Name,Start_Date,End_Date,Rule_Type,Cycle_Total,SpecTime_Info)
    VALUES(1,'任意进出时段',CONVERT(VARCHAR(10),GETDATE(),121),'2031-12-31',1,1,0)
GO

IF NOT EXISTS(SELECT PsnTime_No FROM MJ_PsnInOutTimeSub WHERE PsnTime_No=1 and TimeSect_ID=1)
  INSERT INTO MJ_PsnInOutTimeSub(PsnTime_No,Group_No,TimeSect_ID,Start_Time,End_Time)
    VALUES(1,'A1',1,'00:00','23:59')
GO

IF NOT EXISTS(SELECT PsnTime_No FROM MJ_PsnInOutTimeSub WHERE PsnTime_No=1 and TimeSect_ID=-1)
  INSERT INTO MJ_PsnInOutTimeSub(PsnTime_No,Group_No,TimeSect_ID,Start_Time,End_Time)
    VALUES(1,'A1',-1,'1','')
GO

--4.增加系统权限值列表
--4.1增加每个模块的默认权限值

--5.增加角色权限默认管理员组

--6.更新子系统创建日期
UPDATE dbo.ST_SubSystem SET DBCreateDate=CONVERT(VARCHAR(10),GETDATE(),121),DBVersion = '3.2.0'
WHERE  System_No = 'MJ'
GO