SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for rep_group
-- ----------------------------
DROP TABLE IF EXISTS `rep_group`;
CREATE TABLE `rep_group`  (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `GroupId` int(11) NULL DEFAULT NULL COMMENT '分组ID',
  `ReportId` int(11) NULL DEFAULT NULL COMMENT '报表Id',
  `GroupName` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  PRIMARY KEY (`Id`) USING BTREE
) ENGINE = MyISAM AUTO_INCREMENT = 35 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of rep_group
-- ----------------------------
INSERT INTO `rep_group` VALUES (1, 724, 81, '全院收入');
INSERT INTO `rep_group` VALUES (2, 724, 82, '门诊收入');
INSERT INTO `rep_group` VALUES (3, 724, 83, '住院收入');
INSERT INTO `rep_group` VALUES (4, 650, 60, '首页');
INSERT INTO `rep_group` VALUES (5, 650, 61, NULL);
INSERT INTO `rep_group` VALUES (6, 650, 62, NULL);
INSERT INTO `rep_group` VALUES (7, 725, 84, '科室收入');
INSERT INTO `rep_group` VALUES (8, 725, 85, NULL);
INSERT INTO `rep_group` VALUES (9, 725, 86, NULL);
INSERT INTO `rep_group` VALUES (10, 650, 63, NULL);
INSERT INTO `rep_group` VALUES (11, NULL, 91, '全院工作量726');
INSERT INTO `rep_group` VALUES (12, NULL, 92, '门诊工作量726');
INSERT INTO `rep_group` VALUES (13, NULL, 93, '住院工作量726');
INSERT INTO `rep_group` VALUES (14, NULL, 94, '科室工作量727');
INSERT INTO `rep_group` VALUES (15, 727, 95, NULL);
INSERT INTO `rep_group` VALUES (16, 727, 96, NULL);
INSERT INTO `rep_group` VALUES (17, 728, 101, '次均费用');
INSERT INTO `rep_group` VALUES (18, NULL, 102, '门诊次均费用 groupID: 728');
INSERT INTO `rep_group` VALUES (19, 729, 103, '科室次均费用');
INSERT INTO `rep_group` VALUES (20, 731, 106, '科室绩效发放金额');
INSERT INTO `rep_group` VALUES (21, 732, 104, '医生人均绩效');
INSERT INTO `rep_group` VALUES (29, 650, 69, NULL);
INSERT INTO `rep_group` VALUES (28, 730, 108, '全院绩效发放金额');
INSERT INTO `rep_group` VALUES (23, 650, 68, NULL);
INSERT INTO `rep_group` VALUES (24, 650, 64, NULL);
INSERT INTO `rep_group` VALUES (25, 650, 65, NULL);
INSERT INTO `rep_group` VALUES (26, 650, 66, NULL);
INSERT INTO `rep_group` VALUES (27, 650, 67, NULL);
INSERT INTO `rep_group` VALUES (30, 733, 110, '绩效占全院比值');
INSERT INTO `rep_group` VALUES (31, 726, 111, NULL);
INSERT INTO `rep_group` VALUES (33, 734, 112, '科室绩效占科室收入比');
INSERT INTO `rep_group` VALUES (34, 650, 70, '首页');

-- ----------------------------
-- Table structure for rep_group_selection
-- ----------------------------
DROP TABLE IF EXISTS `rep_group_selection`;
CREATE TABLE `rep_group_selection`  (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `GroupId` int(11) NULL DEFAULT NULL,
  `SelectionId` int(11) NULL DEFAULT NULL,
  PRIMARY KEY (`Id`) USING BTREE
) ENGINE = MyISAM AUTO_INCREMENT = 37 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Fixed;

-- ----------------------------
-- Records of rep_group_selection
-- ----------------------------
INSERT INTO `rep_group_selection` VALUES (1, 724, 2549);
INSERT INTO `rep_group_selection` VALUES (2, 724, 2550);
INSERT INTO `rep_group_selection` VALUES (3, 724, 2551);
INSERT INTO `rep_group_selection` VALUES (4, 650, 2549);
INSERT INTO `rep_group_selection` VALUES (5, 650, 2550);
INSERT INTO `rep_group_selection` VALUES (6, 650, 2551);
INSERT INTO `rep_group_selection` VALUES (7, 725, 2549);
INSERT INTO `rep_group_selection` VALUES (8, 725, 2550);
INSERT INTO `rep_group_selection` VALUES (9, 725, 2551);
INSERT INTO `rep_group_selection` VALUES (10, 726, 2552);
INSERT INTO `rep_group_selection` VALUES (11, 726, 2550);
INSERT INTO `rep_group_selection` VALUES (12, 726, 2551);
INSERT INTO `rep_group_selection` VALUES (13, 727, 2552);
INSERT INTO `rep_group_selection` VALUES (14, 727, 2550);
INSERT INTO `rep_group_selection` VALUES (15, 727, 2551);
INSERT INTO `rep_group_selection` VALUES (16, 728, 2553);
INSERT INTO `rep_group_selection` VALUES (17, 728, 2550);
INSERT INTO `rep_group_selection` VALUES (18, 728, 2551);
INSERT INTO `rep_group_selection` VALUES (19, 729, 2553);
INSERT INTO `rep_group_selection` VALUES (20, 729, 2550);
INSERT INTO `rep_group_selection` VALUES (21, 729, 2551);
INSERT INTO `rep_group_selection` VALUES (22, 730, 2554);
INSERT INTO `rep_group_selection` VALUES (23, 730, 2550);
INSERT INTO `rep_group_selection` VALUES (24, 730, 2551);
INSERT INTO `rep_group_selection` VALUES (31, 733, 2556);
INSERT INTO `rep_group_selection` VALUES (26, 732, 2550);
INSERT INTO `rep_group_selection` VALUES (27, 732, 2551);
INSERT INTO `rep_group_selection` VALUES (28, 731, 2554);
INSERT INTO `rep_group_selection` VALUES (29, 731, 2550);
INSERT INTO `rep_group_selection` VALUES (30, 731, 2551);
INSERT INTO `rep_group_selection` VALUES (32, 733, 2550);
INSERT INTO `rep_group_selection` VALUES (33, 733, 2551);
INSERT INTO `rep_group_selection` VALUES (34, 734, 2556);
INSERT INTO `rep_group_selection` VALUES (35, 734, 2550);
INSERT INTO `rep_group_selection` VALUES (36, 734, 2551);

-- ----------------------------
-- Table structure for rep_importconfig
-- ----------------------------
DROP TABLE IF EXISTS `rep_importconfig`;
CREATE TABLE `rep_importconfig`  (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `TableName` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `ImportScript` varchar(2000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `DeleteScript` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `ConfigId` int(11) NULL DEFAULT NULL COMMENT '数据库地址，仅在HIS抽取时使用',
  `ScriptType` int(11) NOT NULL DEFAULT 1 COMMENT '脚本类型 1 HIS抽取 2 EXCEL抽取',
  `TimeRange` varchar(11) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '1' COMMENT '时间范围 1 当前 2 同期 3 上期',
  `IsEnable` int(11) NOT NULL DEFAULT 1 COMMENT '是否有效 1 有效 0 无效',
  PRIMARY KEY (`ID`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 336 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '导入报表SQL配置' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of rep_importconfig
-- ----------------------------
INSERT INTO `rep_importconfig` VALUES (331, 'report_allot_crowd', 'select allotid,year,month,hospitalid,positionname,totelvalue totalfee,avgvalue avgfee,totelnumber totalnumber \r\nfrom res_baiscnorm tab1\r\n	left join per_allot tab2 on tab1.allotid=tab2.id\r\nwhere allotid=@allotid and PositionName not like \'%保底绩效%\'\r\n', 'delete from report_allot_crowd where allotid=@allotid', NULL, 2, '1', 1);
INSERT INTO `rep_importconfig` VALUES (332, 'report_allot_summary', 'select allotid,year,month,hospitalid,accountingunit,realgivefee from view_report_allot_summary where allotid=@allotId', 'delete from report_allot_summary where allotid=@allotid', NULL, 2, '1', 1);
INSERT INTO `rep_importconfig` VALUES (333, 'report_original_income', 'select distinct allotid,year,month,hospitalid,sourcetype,accountingunit,department,typename,cellvalue from view_report_original_income where unittype in (1,3) and ifnull(accountingunit,\'\')<>\'\' and allotid=@allotId;', 'delete from report_original_income where allotid=@allotid', NULL, 2, '1', 1);
INSERT INTO `rep_importconfig` VALUES (334, 'report_original_persontime', 'select @allotid allotid,@year year,@month month,@hospitalid hospitalid,\'住院\' sourcetype,in_dept_name department,count(1) persontime from inpat_reg_info where in_dept_name is not null and ((datepart(month,inhos_time)=@month and datepart(year,inhos_time)=@year) or (datepart(month,outhos_time)=@month and datepart(year,outhos_time)=@year)) group by in_dept_name\r\nunion all \r\nselect @allotid allotid,@year year,@month month,@hospitalid hospitalid,\'门诊\' sourcetype,dept_name department,count(1) persontime from out_reg_info where dept_name is not null and datepart(month,reg_time)=@month and datepart(year,reg_time)=@year group by dept_name;', 'delete from report_original_persontime where hospitalid=@hospitalid and year=@year and month=@month', 30, 1, '1,2,3', 1);


INSERT INTO `db_performance`.`rep_importconfig`(`ID`, `TableName`, `ImportScript`, `DeleteScript`, `ConfigId`, `ScriptType`, `TimeRange`, `IsEnable`) VALUES (335, 'report_original_persontime', 'update report_original_persontime tab \r\n		join (select distinct\r\n							allotid,\r\n							YEAR,\r\n							MONTH,\r\n							hospitalid,\r\n							sourcetype,\r\n							department,\r\n							accountingunit,\r\n							typename,\r\n							cellvalue \r\n						FROM\r\n							view_report_original_income \r\n						WHERE\r\n							unittype IN ( 1, 3 ) and allotid= @allotId\r\n							AND ifnull( accountingunit, \'\' )<> \'\' \r\n					) vie \r\n				on tab.AllotID = vie.AllotID and\r\n					 tab.HospitalID = vie.HospitalID and\r\n					 tab.YEAR = vie.`YEAR` and\r\n					 tab.`Month` = vie.`Month` and\r\n					 tab.Department = vie.Department and\r\n					 tab.SourceType = vie.SourceType 						 \r\n			 set tab.accountingunit = vie.accountingunit where tab.allotid= @allotId;', NULL, NULL, 3, '1', 1);


-- ----------------------------
-- Table structure for rep_report
-- ----------------------------
DROP TABLE IF EXISTS `rep_report`;
CREATE TABLE `rep_report`  (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `ChartType` int(11) NULL DEFAULT NULL,
  `Sort` int(11) NULL DEFAULT NULL,
  `Content` varchar(5000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'sql执行语句（{wh}及{w}为占位符）',
  `Title` varchar(145) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '报表标题',
  `XTitle` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'X轴标题',
  `XUnit` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'X轴单位',
  `YTitle` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'Y轴标题',
  `YUnit` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'Y轴单位',
  `VTitle` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '值标题',
  `VUnit` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '值单位',
  `NTitle` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'name标题',
  `NUnit` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'name单位',
  `Formula` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '图表说明',
  `DataType` int(11) NULL DEFAULT NULL COMMENT '1表示需要进行小于百分2的类型进行合并',
  `FilterValue` decimal(11, 4) NULL DEFAULT NULL COMMENT '图标value过滤执值',
  PRIMARY KEY (`ID`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 113 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '报表配置表' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of rep_report
-- ----------------------------
INSERT INTO `rep_report` VALUES (60, 301, 1, 'select ifnull(chargetype,typename) name,sum(cellvalue) value from report_original_income t1 left join cof_drugtype t2 on t1.allotid = t2.allotid and t1.typename = t2.charge {w} group by ifnull(chargetype,typename) order by value desc', '业务收入结构占比', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `rep_report` VALUES (61, 101, 2, 'select \'当前\' x,\'药占比\' y,round(sum(if(chargetype=\'药费\', cellvalue, 0)) * 100 / sum(cellvalue),2) value \r\nfrom report_original_income t1 \r\n	left join cof_drugtype t2 on t1.TypeName = t2.Charge and t1.AllotID = t2.AllotId and t2.ChargeType = \'药费\'\r\nwhere hospitalid=@hospitalid and year=@year and month=@month {wh}\r\nunion all \r\nselect \'同期\' x,\'药占比\' y,round(sum(if(chargetype=\'药费\', cellvalue, 0)) * 100 / sum(cellvalue),2) value \r\nfrom report_original_income t1 \r\n	left join cof_drugtype t2 on t1.TypeName = t2.Charge and t1.AllotID = t2.AllotId and t2.ChargeType = \'药费\'\r\nwhere hospitalid=@hospitalid and year=@yesteryear and month=@month {wh}\r\nunion all \r\nselect \'上期\' x,\'药占比\' y,round(sum(if(chargetype=\'药费\', cellvalue, 0)) * 100 / sum(cellvalue),2) value \r\nfrom report_original_income t1 \r\n	left join cof_drugtype t2 on t1.TypeName = t2.Charge and t1.AllotID = t2.AllotId and t2.ChargeType = \'药费\'\r\nwhere hospitalid=@hospitalid and year=@year and month=@lastmonth {wh}\r\n', '药占比', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `rep_report` VALUES (62, 101, 3, 'select \'当前\' x,\'耗材占比\' y,round(sum(if(chargetype=\'材料费\', cellvalue, 0)) * 100 / sum(cellvalue),2) value \r\nfrom report_original_income t1 \r\n	left join cof_drugtype t2 on t1.TypeName = t2.Charge and t1.AllotID = t2.AllotId and t2.ChargeType = \'材料费\'\r\nwhere hospitalid=@hospitalid and year=@year and month=@month {wh}\r\nunion all \r\nselect \'同期\' x,\'耗材占比\' y,round(sum(if(chargetype=\'材料费\', cellvalue, 0)) * 100 / sum(cellvalue),2) value \r\nfrom report_original_income t1 \r\n	left join cof_drugtype t2 on t1.TypeName = t2.Charge and t1.AllotID = t2.AllotId and t2.ChargeType = \'材料费\'\r\nwhere hospitalid=@hospitalid and year=@yesteryear and month=@month {wh}\r\nunion all \r\nselect \'上期\' x,\'耗材占比\' y,round(sum(if(chargetype=\'材料费\', cellvalue, 0)) * 100 / sum(cellvalue),2) value \r\nfrom report_original_income t1 \r\n	left join cof_drugtype t2 on t1.TypeName = t2.Charge and t1.AllotID = t2.AllotId and t2.ChargeType = \'材料费\'\r\nwhere hospitalid=@hospitalid and year=@year and month=@lastmonth {wh}\r\n', '耗材占比', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `rep_report` VALUES (63, 0, 1, 'select * from (\r\n	select sourcetype x,\'当前\' y,sum(cellvalue) value from report_original_income where hospitalid=@hospitalid and year=@year and month=@month {wh} group by sourcetype\r\n	union all\r\n	select sourcetype x,\'同期\' y,sum(cellvalue) value from report_original_income where hospitalid=@hospitalid and year=@yesteryear and month=@month {wh} group by sourcetype\r\n	union all\r\n	select sourcetype x,\'上期\' y,sum(cellvalue) value from report_original_income where hospitalid=@hospitalid and year=@year and month=@lastmonth {wh} group by sourcetype\r\n) tab', '业务概况', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `rep_report` VALUES (64, 0, 2, 'select * from (\r\n	select sourcetype x,\'当前\' y,sum(persontime) value from report_original_persontime where hospitalid=@hospitalid and year=@year and month=@month {wh} group by sourcetype\r\n	union all\r\n	select sourcetype x,\'同期\' y,sum(persontime) value from report_original_persontime where hospitalid=@hospitalid and year=@yesteryear and month=@month {wh} group by sourcetype\r\n	union all\r\n	select sourcetype x,\'上期\' y,sum(persontime) value from report_original_persontime where hospitalid=@hospitalid and year=@year and month=@lastmonth {wh} group by sourcetype\r\n) tab', '工作量', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `rep_report` VALUES (65, 0, 3, 'select tab1.x,tab1.y,round(tab1.value/tab2.value,2) value from (\r\n	select sourcetype x,\'当前\' y,sum(cellvalue) value from report_original_income where hospitalid=@hospitalid and year=@year and month=@month {wh} group by sourcetype\r\n	union all\r\n	select sourcetype x,\'同期\' y,sum(cellvalue) value from report_original_income where hospitalid=@hospitalid and year=@yesteryear and month=@month {wh} group by sourcetype\r\n	union all\r\n	select sourcetype x,\'上期\' y,sum(cellvalue) value from report_original_income where hospitalid=@hospitalid and year=@year and month=@lastmonth {wh} group by sourcetype\r\n) tab1\r\nleft join (\r\n	select sourcetype x,\'当前\' y,sum(persontime) value from report_original_persontime where hospitalid=@hospitalid and year=@year and month=@month {wh} group by sourcetype\r\n	union all\r\n	select sourcetype x,\'同期\' y,sum(persontime) value from report_original_persontime where hospitalid=@hospitalid and year=@yesteryear and month=@month {wh} group by sourcetype\r\n	union all\r\n	select sourcetype x,\'上期\' y,sum(persontime) value from report_original_persontime where hospitalid=@hospitalid and year=@year and month=@lastmonth {wh} group by sourcetype\r\n) tab2 on tab1.x=tab2.x and tab1.y=tab2.y\r\n', '次均费用', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `rep_report` VALUES (66, 0, 4, 'select \'绩效发放金额\' x,tab.* from (\r\n	select \'当前\' y,sum(realgivefee) value from report_allot_summary where hospitalid=@hospitalid and year=@year and month=@month {wh} group by allotid\r\n	union all\r\n	select \'同期\' y,sum(realgivefee) value from report_allot_summary where hospitalid=@hospitalid and year=@yesteryear and month=@month {wh} group by allotid\r\n	union all\r\n	select \'上期\' y,sum(realgivefee) value from report_allot_summary where hospitalid=@hospitalid and year=@year and month=@lastmonth {wh} group by allotid\r\n) tab', '绩效发放', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `rep_report` VALUES (67, 0, 5, 'select tab.* from (\r\n	select type x,\'当前\' y,round(sum(avgfee)/count(1),2) value from (select *,case when locate(\'科室主任\',positionname)>0 or locate(\'医生\',positionname)>0 then \'医生\' when locate(\'护士\',positionname)>0 then \'护理\' else null end type from report_allot_crowd where hospitalid=@hospitalid and year=@year and month=@month and locate(\'自定义\',positionname)<1) t where t.type is not null group by type\r\n	union all\r\n	select type x,\'同期\' y,round(sum(avgfee)/count(1),2) value from (select *,case when locate(\'科室主任\',positionname)>0 or locate(\'医生\',positionname)>0 then \'医生\' when locate(\'护士\',positionname)>0 then \'护理\' else null end type from report_allot_crowd where hospitalid=@hospitalid and year=@yesteryear and month=@month and locate(\'自定义\',positionname)<1) t where t.type is not null group by type\r\n	union all\r\n	select type x,\'上期\' y,round(sum(avgfee)/count(1),2) value from (select *,case when locate(\'科室主任\',positionname)>0 or locate(\'医生\',positionname)>0 then \'医生\' when locate(\'护士\',positionname)>0 then \'护理\' else null end type from report_allot_crowd where hospitalid=@hospitalid and year=@year and month=@lastmonth and locate(\'自定义\',positionname)<1) t where t.type is not null group by type\r\n) tab', '医生/护理人均', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `rep_report` VALUES (68, 151, 4, 'select positionname x,avgfee value from report_allot_crowd {w} order by avgfee asc', '绩效群体绩效权重', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `rep_report` VALUES (69, 0, 6, 'select null x,null y,null value', '内外科医护比', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `rep_report` VALUES (70, 0, 5, '\r\nselect \'绩效占全院比值\' x,tab1.y,round(tab1.value/tab2.value,2) value from (\r\n	select \'当前\' y,sum(realgivefee) value from report_allot_summary where hospitalid=@hospitalid and year=@year and month=@month {wh} group by allotid\r\n	union all\r\n	select \'同期\' y,sum(realgivefee) value from report_allot_summary where hospitalid=@hospitalid and year=@yesteryear and month=@month {wh} group by allotid\r\n	union all\r\n	select \'上期\' y,sum(realgivefee) value from report_allot_summary where hospitalid=@hospitalid and year=@year and month=@lastmonth {wh} group by allotid\r\n) tab1\r\nleft join (\r\n	select \'当前\' y,sum(cellvalue) value from report_original_income where hospitalid=@hospitalid and year=@year and month=@month {wh}\r\n	union all\r\n	select \'同期\' y,sum(cellvalue) value from report_original_income where hospitalid=@hospitalid and year=@yesteryear and month=@month {wh}\r\n	union all\r\n	select \'上期\' y,sum(cellvalue) value from report_original_income where hospitalid=@hospitalid and year=@year and month=@lastmonth {wh}\r\n) tab2 on tab1.y=tab2.y', '绩效占全院比值', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `rep_report` VALUES (81, 101, 1, 'select ifnull(chargetype,typename) x,\'收入占比\' y,sum(CellValue) value \r\nfrom report_original_income t1\r\n	left join cof_drugtype t2 on t1.allotid = t2.allotid and t1.typename = t2.charge {w}\r\ngroup by ifnull(chargetype,typename) order by value desc\r\n\r\n', '业务收入', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `rep_report` VALUES (82, 101, 2, 'select ifnull(chargetype,typename) x,\'收入占比\' y,sum(CellValue) value \r\nfrom report_original_income t1\r\n	left join cof_drugtype t2 on t1.allotid = t2.allotid and t1.typename = t2.charge\r\nwhere sourcetype=\'门诊\'{wh}\r\ngroup by ifnull(chargetype,typename) order by value desc', '门诊业务收入', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `rep_report` VALUES (83, 101, 3, 'select ifnull(chargetype,typename) x,\'收入占比\' y,sum(CellValue) value \r\nfrom report_original_income t1\r\n	left join cof_drugtype t2 on t1.allotid = t2.allotid and t1.typename = t2.charge\r\nwhere sourcetype=\'住院\'{wh}\r\ngroup by ifnull(chargetype,typename) order by value desc', '住院业务收入', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `rep_report` VALUES (84, 101, 1, 'select accountingunit x,ifnull(chargetype,typename) y,sum(CellValue) value \r\nfrom report_original_income t1\r\n	left join cof_drugtype t2 on t1.allotid = t2.allotid and t1.typename = t2.charge {w}\r\ngroup by accountingunit,ifnull(chargetype,typename) having ifnull(accountingunit,\'\')!=\'\' order by value desc', '业务收入', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `rep_report` VALUES (85, 101, 2, 'select accountingunit x,ifnull(chargetype,typename) y,sum(CellValue) value \r\nfrom report_original_income t1\r\n	left join cof_drugtype t2 on t1.allotid = t2.allotid and t1.typename = t2.charge\r\nwhere sourcetype=\'门诊\' and ifnull(accountingunit,\'\')!=\'\' {wh}\r\ngroup by accountingunit,ifnull(chargetype,typename) order by value desc\r\n', '门诊业务收入', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `rep_report` VALUES (86, 101, 3, 'select accountingunit x,ifnull(chargetype,typename) y,sum(CellValue) value \r\nfrom report_original_income t1\r\n	left join cof_drugtype t2 on t1.allotid = t2.allotid and t1.typename = t2.charge\r\nwhere sourcetype=\'住院\' and ifnull(accountingunit,\'\')!=\'\' {wh}\r\ngroup by accountingunit,ifnull(chargetype,typename) order by value desc\r\n', '住院业务收入', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `rep_report` VALUES (91, 101, 1, 'select accountingunit x,\'工作量\' y,sum(persontime) value from report_original_persontime {w} group by accountingunit having ifnull(accountingunit,\'\')!=\'\' order by value desc\r\n', '工作量', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `rep_report` VALUES (92, 101, 2, 'select accountingunit x,\'门诊量\' y,sum(persontime) value from report_original_persontime where sourcetype=\'门诊\' and ifnull(accountingunit,\'\')!=\'\' {wh} group by accountingunit order by value desc\r\n', '门诊工作量', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `rep_report` VALUES (93, 101, 3, 'select accountingunit x,\'住院量\' y,sum(persontime) value from report_original_persontime where sourcetype=\'住院\' and ifnull(accountingunit,\'\')!=\'\' {wh} group by accountingunit order by value desc\r\n', '住院工作量', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `rep_report` VALUES (94, 101, 1, 'select accountingunit x,\'工作量\' y,sum(persontime) value from report_original_persontime {w} group by accountingunit having ifnull(accountingunit,\'\')!=\'\' order by value desc\r\n', '工作量', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `rep_report` VALUES (95, 101, 2, 'select accountingunit x,\'当前\' y,sum(persontime) value from report_original_persontime where sourcetype=\'门诊\' and ifnull(accountingunit,\'\')!=\'\' and hospitalid=@hospitalid and year=@year and month=@month {wh} group by accountingunit\r\nunion all\r\nselect accountingunit x,\'同期\' y,sum(persontime) value from report_original_persontime where sourcetype=\'门诊\' and ifnull(accountingunit,\'\')!=\'\' and hospitalid=@hospitalid and year=@yesteryear and month=@month {wh} group by accountingunit\r\nunion all\r\nselect accountingunit x,\'上期\' y,sum(persontime) value from report_original_persontime where sourcetype=\'门诊\' and ifnull(accountingunit,\'\')!=\'\' and hospitalid=@hospitalid and year=@year and month=@lastmonth {wh} group by accountingunit order by x ', '门诊工作量', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `rep_report` VALUES (96, 101, 3, 'select accountingunit x,\'当前\' y,sum(persontime) value from report_original_persontime where sourcetype=\'住院\' and ifnull(accountingunit,\'\')!=\'\' and hospitalid=@hospitalid and year=@year and month=@month {wh} group by accountingunit\r\nunion all\r\nselect accountingunit x,\'同期\' y,sum(persontime) value from report_original_persontime where sourcetype=\'住院\' and ifnull(accountingunit,\'\')!=\'\' and hospitalid=@hospitalid and year=@yesteryear and month=@month {wh} group by accountingunit\r\nunion all\r\nselect accountingunit x,\'上期\' y,sum(persontime) value from report_original_persontime where sourcetype=\'住院\' and ifnull(accountingunit,\'\')!=\'\' and hospitalid=@hospitalid and year=@year and month=@lastmonth {wh} group by accountingunit order by x ', '住院工作量', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `rep_report` VALUES (101, 101, 1, 'select tab1.x,tab1.y y,round(tab1.value/tab2.value,2) value from (\r\n	select sourcetype x,\'当前\' y,sum(cellvalue) value from report_original_income where hospitalid=@hospitalid and year=@year and month=@month {wh} group by sourcetype\r\n	union all\r\n	select sourcetype x,\'同期\' y,sum(cellvalue) value from report_original_income where hospitalid=@hospitalid and year=@yesteryear and month=@month {wh} group by sourcetype\r\n	union all\r\n	select sourcetype x,\'上期\' y,sum(cellvalue) value from report_original_income where hospitalid=@hospitalid and year=@year and month=@lastmonth {wh} group by sourcetype\r\n) tab1\r\nleft join (\r\n	select sourcetype x,\'当前\' y,sum(persontime) value from report_original_persontime where hospitalid=@hospitalid and year=@year and month=@month {wh} group by sourcetype\r\n	union all\r\n	select sourcetype x,\'同期\' y,sum(persontime) value from report_original_persontime where hospitalid=@hospitalid and year=@yesteryear and month=@month {wh} group by sourcetype\r\n	union all\r\n	select sourcetype x,\'上期\' y,sum(persontime) value from report_original_persontime where hospitalid=@hospitalid and year=@year and month=@lastmonth {wh} group by sourcetype\r\n) tab2 on tab1.x=tab2.x and tab1.y=tab2.y\r\n', '次均费用', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `rep_report` VALUES (102, 101, 2, 'select tab1.x,\'次均费用\' y,round(tab1.value/tab2.value,2) value from (\r\n	select sourcetype x,sum(cellvalue) value from report_original_income where sourcetype=\'门诊\'{wh} group by sourcetype\r\n) tab1\r\nleft join (\r\n	select sourcetype x,sum(persontime) value from report_original_persontime where sourcetype=\'门诊\'{wh} group by sourcetype\r\n) tab2 on tab1.x=tab2.x', '门诊次均费用', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `rep_report` VALUES (103, 101, 3, 'select tab1.x,tab1.y,round(tab1.value/tab2.value,2) value from (\r\n	select accountingunit x,\'当前\' y,sum(cellvalue) value from report_original_income where ifnull(cellvalue,0)!=0 and ifnull(accountingunit,\'\')!=\'\' and hospitalid=@hospitalid and year=@year and month=@month {wh} group by accountingunit,allotid\r\n	union all\r\n	select accountingunit x,\'同期\' y,sum(cellvalue) value from report_original_income where ifnull(cellvalue,0)!=0 and ifnull(accountingunit,\'\')!=\'\' and  hospitalid=@hospitalid and year=@yesteryear and month=@month {wh} group by accountingunit,allotid\r\n	union all\r\n	select accountingunit x,\'上期\' y,sum(cellvalue) value from report_original_income where ifnull(cellvalue,0)!=0 and ifnull(accountingunit,\'\')!=\'\' and  hospitalid=@hospitalid and year=@year and month=@lastmonth {wh} group by accountingunit,allotid\r\n) tab1\r\njoin (\r\n	select accountingunit x,\'当前\' y,sum(persontime) value from report_original_persontime where ifnull(persontime,0)!=0 and ifnull(accountingunit,\'\')!=\'\' and  hospitalid=@hospitalid and year=@year and month=@month {wh} group by accountingunit,allotid\r\n	union all\r\n	select accountingunit x,\'同期\' y,sum(persontime) value from report_original_persontime where ifnull(persontime,0)!=0 and ifnull(accountingunit,\'\')!=\'\' and  hospitalid=@hospitalid and year=@yesteryear and month=@month {wh} group by accountingunit,allotid\r\n	union all\r\n	select accountingunit x,\'上期\' y,sum(persontime) value from report_original_persontime where ifnull(persontime,0)!=0 and ifnull(accountingunit,\'\')!=\'\' and  hospitalid=@hospitalid and year=@year and month=@lastmonth {wh} group by accountingunit,allotid\r\n) tab2 on tab1.x=tab2.x and tab1.y=tab2.y order by x,y', '科室次均费用', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `rep_report` VALUES (104, 101, 1, 'select * from (\r\n	select positionname x,\'当前\' y,avgfee value from report_allot_crowd where hospitalid=@hospitalid and year=@year and month=@month\r\n	union all\r\n	select positionname x,\'同期\' y,avgfee value from report_allot_crowd where hospitalid=@hospitalid and year=@yesteryear and month=@month\r\n	union all\r\n	select positionname x,\'上期\' y,avgfee value from report_allot_crowd where hospitalid=@hospitalid and year=@year and month=@lastmonth\r\n) tab', '医生人均绩效', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `rep_report` VALUES (105, 101, 2, 'select positionname x,avgfee value from report_allot_crowd where locate(\'自定义\',positionname)<1 and locate(\'护士\',positionname)>0 {wh}', '护理人均绩效', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `rep_report` VALUES (106, 101, 1, 'select * from (\r\n	select accountingunit x,\'当前\' y,sum(realgivefee) value from report_allot_summary where ifnull(realgivefee,0)!=0 and ifnull(accountingunit,\'\')!=\'\' and hospitalid=@hospitalid and year=@year and month=@month {wh} group by accountingunit\r\n	union all\r\n	select accountingunit x,\'同期\' y,sum(realgivefee) value from report_allot_summary where ifnull(realgivefee,0)!=0 and ifnull(accountingunit,\'\')!=\'\' and hospitalid=@hospitalid and year=@yesteryear and month=@month {wh} group by accountingunit \r\n	union all\r\n	select accountingunit x,\'上期\' y,sum(realgivefee) value from report_allot_summary where ifnull(realgivefee,0)!=0 and ifnull(accountingunit,\'\')!=\'\' and hospitalid=@hospitalid and year=@year and month=@lastmonth {wh} group by accountingunit \r\n) tab  order by value desc', '绩效发放金额', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `rep_report` VALUES (108, 101, 1, 'select \'全员绩效发放金额\' x,tab.* from (\r\n	select \'当前\' y,sum(realgivefee) value from report_allot_summary where ifnull(realgivefee,0)!=0 and hospitalid=@hospitalid and year=@year and month=@month {wh} group by allotid \r\n	union all\r\n	select \'同期\' y,sum(realgivefee) value from report_allot_summary where ifnull(realgivefee,0)!=0 and hospitalid=@hospitalid and year=@yesteryear and month=@month {wh} group by allotid \r\n	union all\r\n	select \'上期\' y,sum(realgivefee) value from report_allot_summary where ifnull(realgivefee,0)!=0 and hospitalid=@hospitalid and year=@year and month=@lastmonth {wh} group by allotid \r\n) tab', '绩效发放金额', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `rep_report` VALUES (110, 101, 2, 'select \'绩效占全院比值\' x,tab1.y,round(tab1.value/tab2.value*100,2) value from (\r\n	select \'当前\' y,sum(realgivefee) value from report_allot_summary where ifnull(realgivefee,0)!=0 and hospitalid=@hospitalid and year=@year and month=@month {wh} group by allotid\r\n	union all\r\n	select \'同期\' y,sum(realgivefee) value from report_allot_summary where ifnull(realgivefee,0)!=0 and hospitalid=@hospitalid and year=@yesteryear and month=@month {wh} group by allotid\r\n	union all\r\n	select \'上期\' y,sum(realgivefee) value from report_allot_summary where ifnull(realgivefee,0)!=0 and hospitalid=@hospitalid and year=@year and month=@lastmonth {wh} group by allotid\r\n) tab1\r\nleft join (\r\n	select \'当前\' y,sum(cellvalue) value from report_original_income where ifnull(cellvalue,0)!=0 and hospitalid=@hospitalid and year=@year and month=@month {wh}\r\n	union all\r\n	select \'同期\' y,sum(cellvalue) value from report_original_income where ifnull(cellvalue,0)!=0 and hospitalid=@hospitalid and year=@yesteryear and month=@month {wh}\r\n	union all\r\n	select \'上期\' y,sum(cellvalue) value from report_original_income where ifnull(cellvalue,0)!=0 and hospitalid=@hospitalid and year=@year and month=@lastmonth {wh}\r\n) tab2 on tab1.y=tab2.y', '绩效占全院比值', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `rep_report` VALUES (111, 101, 1, 'select \'当前\' y,sourcetype x,sum(persontime) value from report_original_persontime where ifnull(persontime,0)!=0 and hospitalid=@hospitalid and year=@year and month=@month {wh} group by sourcetype,allotid\r\nunion all \r\nselect \'同期\' y,sourcetype x,sum(persontime) value from report_original_persontime where ifnull(persontime,0)!=0 and hospitalid=@hospitalid and year=@yesteryear and month=@month {wh} group by sourcetype,allotid\r\nunion all \r\nselect \'上期\' y,sourcetype x,sum(persontime) value from report_original_persontime where ifnull(persontime,0)!=0 and hospitalid=@hospitalid and year=@year and month=@lastmonth {wh} group by sourcetype,allotid order by x,y', '工作量', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `rep_report` VALUES (112, 101, 1, 'select tab1.x,tab1.y,round(tab1.value/tab2.value*100,2) value from (\r\n	select accountingunit x,\'当前\' y,sum(realgivefee) value from report_allot_summary where ifnull(realgivefee,0)!=0 and ifnull(accountingunit,\'\')!=\'\' and hospitalid=@hospitalid and year=@year and month=@month {wh} group by accountingunit,allotid\r\n	union all\r\n	select accountingunit x,\'同期\' y,sum(realgivefee) value from report_allot_summary where ifnull(realgivefee,0)!=0 and ifnull(accountingunit,\'\')!=\'\' and hospitalid=@hospitalid and year=@yesteryear and month=@month {wh} group by accountingunit,allotid\r\n	union all\r\n	select accountingunit x,\'上期\' y,sum(realgivefee) value from report_allot_summary where ifnull(realgivefee,0)!=0 and ifnull(accountingunit,\'\')!=\'\' and hospitalid=@hospitalid and year=@year and month=@lastmonth {wh} group by accountingunit,allotid\r\n) tab1\r\nleft join (\r\n	select accountingunit x,\'当前\' y,sum(cellvalue) value from report_original_income where ifnull(cellvalue,0)!=0 and ifnull(accountingunit,\'\')!=\'\' and hospitalid=@hospitalid and year=@year and month=@month {wh} group by accountingunit,allotid\r\n	union all\r\n	select accountingunit x,\'同期\' y,sum(cellvalue) value from report_original_income where ifnull(cellvalue,0)!=0 and ifnull(accountingunit,\'\')!=\'\' and hospitalid=@hospitalid and year=@yesteryear and month=@month {wh} group by accountingunit,allotid\r\n	union all\r\n	select accountingunit x,\'上期\' y,sum(cellvalue) value from report_original_income where ifnull(cellvalue,0)!=0 and ifnull(accountingunit,\'\')!=\'\' and hospitalid=@hospitalid and year=@year and month=@lastmonth {wh} group by accountingunit,allotid\r\n) tab2 on tab1.x=tab2.x and tab1.y=tab2.y', '科室绩效占科室收入比', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);

-- ----------------------------
-- Table structure for rep_selection
-- ----------------------------
DROP TABLE IF EXISTS `rep_selection`;
CREATE TABLE `rep_selection`  (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `Title` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '条件标题',
  `Sort` decimal(18, 2) NULL DEFAULT NULL COMMENT '排序',
  `Content` varchar(2000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '条件SQL语句',
  `Type` int(11) NOT NULL COMMENT '条件类型（1固定条件，2需要通过语句获取）',
  `InputName` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '控件名称',
  `InputType` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '控件类型（1：input框、2：radio单选、3：checkbox多选、4：select单选、5：select多选、6：自动补全单选、7：自动补全多选、10：日期区间）',
  `Required` int(11) NULL DEFAULT NULL COMMENT '是否必填(1表示必填0表示非必填）',
  `LoadType` int(11) NOT NULL DEFAULT 1 COMMENT '条件加载方式 1 立即加载 2 联动加载 3 自动补全',
  `LoadParent` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '联动加载父InputID',
  `DefaultType` int(11) NULL DEFAULT NULL COMMENT '默认值类型(1 固定文本 2 动态结果第一项)',
  `DefaultValue` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '默认值文本',
  `Joint` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'SQL拼接条件 Equal、Like、In、Not Like、Not In',
  `State` int(11) NULL DEFAULT 1 COMMENT '条件状态 1 正常 2 可用但不显示 3 不显示不可用 4 不可用但显示',
  `AddTitle` int(11) NULL DEFAULT 0 COMMENT '是否条件内容附加到标题中，1 附加',
  PRIMARY KEY (`ID`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 2557 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '条件表' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of rep_selection
-- ----------------------------
INSERT INTO `rep_selection` VALUES (2549, '类型', 1.00, '全院|724,科室|725', 1, 'groupid', 'radio', 1, 1, NULL, NULL, NULL, NULL, 4, 1);
INSERT INTO `rep_selection` VALUES (2550, '年份', 2.00, '2019年|2019,2020年|2020,2021年|2021,2022年|2022', 1, 'year', 'radio', 1, 1, NULL, NULL, NULL, 'In', 1, 0);
INSERT INTO `rep_selection` VALUES (2551, '月份', 3.00, '1月|1,2月|2,3月|3,4月|4,5月|5,6月|6,7月|7,8月|8,9月|9,10月|10,11月|11,12月|12', 1, 'month', 'radio', 1, 1, NULL, NULL, NULL, 'In', 1, 0);
INSERT INTO `rep_selection` VALUES (2552, '类型', 1.00, '全院|726,科室|727', 1, 'groupid', 'radio', 1, 1, NULL, NULL, NULL, NULL, 4, 1);
INSERT INTO `rep_selection` VALUES (2553, '类型', 1.00, '全院|728,科室|729', 1, 'groupid', 'radio', 1, 1, NULL, NULL, NULL, NULL, 4, 1);
INSERT INTO `rep_selection` VALUES (2554, '类型', 1.00, '全院|730,科室|731', 1, 'groupid', 'radio', 1, 1, NULL, NULL, NULL, NULL, 4, 1);
INSERT INTO `rep_selection` VALUES (2555, '类型', 1.00, '全院|732,科室|732', 1, 'groupid', 'radio', 1, 1, NULL, NULL, NULL, NULL, 4, 1);
INSERT INTO `rep_selection` VALUES (2556, '类型', 1.00, '全院|733,科室|734', 1, 'groupid', 'radio', 1, 1, NULL, NULL, NULL, NULL, 4, 1);

DROP TABLE IF EXISTS `per_budget_amount`;
CREATE TABLE `per_budget_amount` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `HospitalId` int(11) NOT NULL,
  `MainYear` int(11) NOT NULL COMMENT '根据该年份测算下一年',
  `Year` int(11) NOT NULL COMMENT '实际年份、预算年份',
  `HospitalRevenue` decimal(12,4) DEFAULT NULL COMMENT '医院业务收入(万)',
  `TotalLaborCost` decimal(12,4) DEFAULT NULL COMMENT '人力总成本（万）',
  `StaffSpendingFixed` decimal(12,4) DEFAULT NULL COMMENT '人员支出固定部分（万）',
  `StaffSpendingBonus` decimal(12,4) DEFAULT NULL COMMENT '人员支出浮动部分（奖金）',
  `TotalMeritPay` decimal(12,4) DEFAULT NULL COMMENT '绩效工资合计',
  `AmountOfStaff` decimal(12,4) DEFAULT NULL COMMENT '人员数',
  `ThePerCapitaMerit` decimal(12,4) DEFAULT NULL COMMENT '原人均月绩效（元）',
  `TheIncrementCapita` decimal(12,4) DEFAULT NULL COMMENT '增量后人均绩效（元）',
  `TheDrugIncome` decimal(12,4) DEFAULT NULL COMMENT '药品收入（万）',
  `MaterialIncome` decimal(12,4) DEFAULT NULL COMMENT '材料支出（万）',
  `TheCostInTotal` decimal(12,4) DEFAULT NULL COMMENT '药品+材料+人支（万）',
  `DepreOfFixedAssets` decimal(12,4) DEFAULT NULL COMMENT '固定资产折旧费（万）',
  `AmortOfIntangibleAssets` decimal(12,4) DEFAULT NULL COMMENT '无形资产摊销费（万）',
  `MedicalRisk` decimal(12,4) DEFAULT NULL COMMENT '提取医疗风险基金（万）',
  `OtherExpenses` decimal(12,4) DEFAULT NULL COMMENT '其他费用（万）',
  `BalanceOfPayments` decimal(12,4) DEFAULT NULL COMMENT '收支结余（%）',
  `FiscalSubsidies` decimal(12,4) DEFAULT NULL COMMENT '财政补贴',
  `TheTotalHospitalBalance` decimal(12,4) DEFAULT NULL COMMENT '医院总收支结余',
  `CreateTime` datetime DEFAULT NULL,
  `CreateUser` int(11) DEFAULT NULL,
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8 COMMENT='预算管理金额';


DROP TABLE IF EXISTS `per_budget_ratio`;
CREATE TABLE `per_budget_ratio` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `HospitalId` int(11) NOT NULL,
  `MainYear` int(11) NOT NULL COMMENT '根据该年份测算下一年',
  `Year` int(11) NOT NULL COMMENT '实际年份、预算年份',
  `HospitalRevenue` decimal(10,4) DEFAULT NULL COMMENT '医院业务收入预算比例',
  `TotalLaborCost` decimal(10,4) DEFAULT NULL COMMENT '人力总成本占比',
  `StaffSpendingFixed` decimal(10,4) DEFAULT NULL COMMENT '人员支出固定部分占比',
  `StaffSpendingBonus` decimal(10,4) DEFAULT NULL COMMENT '人员支出浮动部分占比',
  `MeritPayIncrement` decimal(10,4) DEFAULT NULL COMMENT '绩效工资增量预算比例',
  `TotalMeritPay` decimal(10,4) DEFAULT NULL COMMENT '绩效工资合计',
  `Amplification` decimal(10,4) DEFAULT NULL COMMENT '增长幅度',
  `IncrementCapitaRatio` decimal(10,4) DEFAULT NULL COMMENT '增量后绩效工资人员经费比例',
  `TheDrugIncome` decimal(10,4) DEFAULT NULL COMMENT '药品收入占比',
  `TheDrugIncomeBudget` decimal(10,4) DEFAULT NULL COMMENT '药品收入预算比例',
  `MaterialIncome` decimal(10,4) DEFAULT NULL COMMENT '材料支出占比',
  `MaterialIncomeBudget` decimal(10,4) DEFAULT NULL COMMENT '材料支出预算比例',
  `TheCostInTotal` decimal(10,4) DEFAULT NULL COMMENT '药品+材料+人支占比',
  `DepreOfFixedAssets` decimal(10,4) DEFAULT NULL COMMENT '固定资产折旧费占比',
  `AmortOfIntangibleAssets` decimal(10,4) DEFAULT NULL COMMENT '无形资产摊销费占比',
  `MedicalRisk` decimal(10,4) DEFAULT NULL COMMENT '提取医疗风险基金占比',
  `OtherExpenses` decimal(10,4) DEFAULT NULL COMMENT '其他费用占比',
  `BalanceOfPayments` decimal(10,4) DEFAULT NULL COMMENT '收支结余（%）',
  `TheTotalHospitalBalance` decimal(10,4) DEFAULT NULL COMMENT '医院总收支结余',
  `CreateTime` datetime DEFAULT NULL,
  `CreateUser` int(11) DEFAULT NULL,
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8 COMMENT='预算管理占比';


DROP TABLE IF EXISTS `per_budget_result`;
CREATE TABLE `per_budget_result` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `HospitalId` int(11) NOT NULL,
  `Year` int(11) NOT NULL,
  `Month` int(11) NOT NULL,
  `Grant` decimal(10,4) DEFAULT NULL COMMENT '绩效可发比例',
  `Adjust` decimal(10,4) DEFAULT NULL COMMENT '调节系数',
  `MedicalIncome` decimal(12,4) DEFAULT NULL COMMENT '医疗收入',
  `PersonnelExpenditure` decimal(12,4) DEFAULT NULL COMMENT '人员经费',
  `TheNewPerformance` decimal(12,4) DEFAULT NULL COMMENT '新绩效',
  `MedicineProportion` decimal(12,4) DEFAULT NULL COMMENT '药占比（收入）',
  `MaterialCosts` decimal(12,4) DEFAULT NULL COMMENT '材料支出',
  `TotalMedicine` decimal(12,4) DEFAULT NULL COMMENT '药材比例合计',
  `DepreOfFixedAssets` decimal(12,4) DEFAULT NULL COMMENT '固定资产折旧',
  `OtherExpenses` decimal(12,4) DEFAULT NULL COMMENT '其他',
  `TheCostInTotal` decimal(12,4) DEFAULT NULL COMMENT '人+药+材的支出比例',
  `TheCostCombined` decimal(12,4) DEFAULT NULL COMMENT '成本合计',
  `PersonExpendRatio` decimal(10,4) DEFAULT NULL COMMENT '人员经费实际比例',
  `NewPerformanceRatio` decimal(10,4) DEFAULT NULL COMMENT '新绩效实际比例',
  `MedicinePropRatio` decimal(10,4) DEFAULT NULL COMMENT '药占比实际比例',
  `MaterialCostsRatio` decimal(10,4) DEFAULT NULL COMMENT '材料支出实际比例',
  `TotalMedicineRatio` decimal(10,4) DEFAULT NULL COMMENT '药材合计实际比例',
  `DepreOfFixedAssetsRatio` decimal(10,4) DEFAULT NULL COMMENT '固定资产折旧实际比例',
  `OtherExpensesRatio` decimal(10,4) DEFAULT NULL COMMENT '其他费用实际比例',
  `TheCostInTotalRatio` decimal(10,4) DEFAULT NULL COMMENT '人+药+材的支出实际比例',
  `TheCostCombinedRatio` decimal(10,4) DEFAULT NULL COMMENT '成本合计实际比例',
  `NoPerformanceExpenditure` decimal(10,4) DEFAULT NULL COMMENT '人员经费（不含绩效）',
  `NoPerformanceExpenditureRatio` decimal(10,4) DEFAULT NULL COMMENT '人员经费（不含绩效）实际比例',
  `States` int(11) NOT NULL DEFAULT '1' COMMENT '1.初始 2. 确认使用发放/调节系数',
  `CreateDate` datetime DEFAULT NULL,
  `CreateUser` int(11) DEFAULT NULL,
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=116 DEFAULT CHARSET=utf8 COMMENT='预算控制年度合计';


INSERT INTO `db_performance`.`sys_menu`(`ID`, `ParentID`, `MenuName`, `MenuUrl`, `MenuIcon`, `States`, `Sort`) VALUES (75, 17, '科室业务指标分析', '', NULL, 1, 2);

INSERT INTO `db_performance`.`sys_menu`(`ID`, `ParentID`, `MenuName`, `MenuUrl`, `MenuIcon`, `States`, `Sort`) VALUES (76, 75, '科室及医生业务总收入', '', NULL, 1, 1);

INSERT INTO `db_performance`.`sys_menu`(`ID`, `ParentID`, `MenuName`, `MenuUrl`, `MenuIcon`, `States`, `Sort`) VALUES (77, 75, '科室及医生门诊住院业务总收入比', '', NULL, 1, 2);

INSERT INTO `db_performance`.`sys_menu`(`ID`, `ParentID`, `MenuName`, `MenuUrl`, `MenuIcon`, `States`, `Sort`) VALUES (78, 75, '科室及医生业务收入结构占比', '', NULL, 1, 3);

INSERT INTO `db_performance`.`sys_menu`(`ID`, `ParentID`, `MenuName`, `MenuUrl`, `MenuIcon`, `States`, `Sort`) VALUES (79, 75, '科室及医生药占比', '', NULL, 1, 4);

INSERT INTO `db_performance`.`sys_menu`(`ID`, `ParentID`, `MenuName`, `MenuUrl`, `MenuIcon`, `States`, `Sort`) VALUES (80, 75, '科室及医生耗材占比', '', NULL, 1, 5);

INSERT INTO `db_performance`.`sys_menu`(`ID`, `ParentID`, `MenuName`, `MenuUrl`, `MenuIcon`, `States`, `Sort`) VALUES (81, 75, '科室及医生业务量分析', '', NULL, 1, 6);

INSERT INTO `db_performance`.`sys_menu`(`ID`, `ParentID`, `MenuName`, `MenuUrl`, `MenuIcon`, `States`, `Sort`) VALUES (82, 75, '科室及医生次均费用分析', '', NULL, 1, 7);

INSERT INTO `db_performance`.`sys_menu`(`ID`, `ParentID`, `MenuName`, `MenuUrl`, `MenuIcon`, `States`, `Sort`) VALUES (83, 16, '绩效概况', '/survey', NULL, 0, 0);

INSERT INTO `db_performance`.`sys_menu`(`ID`, `ParentID`, `MenuName`, `MenuUrl`, `MenuIcon`, `States`, `Sort`) VALUES (85, 16, '预算管理', '/budget', NULL, 1, 4);

UPDATE `db_performance`.`sys_menu` SET `ParentID` = 16, `MenuName` = '模板下载', `MenuUrl` = '/templet', `MenuIcon` = '', `States` = 1, `Sort` = 5 WHERE `ID` = 6;

UPDATE `db_performance`.`sys_menu` SET `ParentID` = 17, `MenuName` = '医院考核', `MenuUrl` = '', `MenuIcon` = 'iconjixiaofafang', `States` = 0, `Sort` = 6 WHERE `ID` = 34;

UPDATE `db_performance`.`sys_menu` SET `ParentID` = 34, `MenuName` = '考核配置', `MenuUrl` = '/assessConf', `MenuIcon` = NULL, `States` = 0, `Sort` = 1 WHERE `ID` = 35;

UPDATE `db_performance`.`sys_menu` SET `ParentID` = 34, `MenuName` = '考核录入', `MenuUrl` = '/assessEntering', `MenuIcon` = NULL, `States` = 0, `Sort` = 2 WHERE `ID` = 36;

UPDATE `db_performance`.`sys_menu` SET `ParentID` = 16, `MenuName` = '绩效概况', `MenuUrl` = '/leader/overview', `MenuIcon` = NULL, `States` = 1, `Sort` = 2 WHERE `ID` = 42;

INSERT INTO `db_performance`.`sys_role`(`ID`, `RoleName`, `Type`, `IndexUrl`, `Remark`, `States`, `ParentRoles`) VALUES (5, '绩效核算办', 5, '/leader/overview', '查看所在医院绩效结果', 1, '1,2');

INSERT INTO `db_performance`.`sys_role`(`ID`, `RoleName`, `Type`, `IndexUrl`, `Remark`, `States`, `ParentRoles`) VALUES (6, '院领导', 6, '/leader/overview', '', 1, '1,2');

INSERT INTO `db_performance`.`sys_role`(`ID`, `RoleName`, `Type`, `IndexUrl`, `Remark`, `States`, `ParentRoles`) VALUES (7, '财务科', 7, '/performance', '', 1, '1,2');

INSERT INTO `db_performance`.`sys_role`(`ID`, `RoleName`, `Type`, `IndexUrl`, `Remark`, `States`, `ParentRoles`) VALUES (8, '人事科', 8, '/performance', '', 1, '1,2');

UPDATE `db_performance`.`sys_role` SET `RoleName` = '绩效管理员', `Type` = 1, `IndexUrl` = '/hospital', `Remark` = '配置绩效方案，管理多家医院', `States` = 1, `ParentRoles` = NULL WHERE `ID` = 1;

UPDATE `db_performance`.`sys_role` SET `RoleName` = '医院管理员', `Type` = 2, `IndexUrl` = '/leader/overview', `Remark` = '查看所在医院绩效数据/survey', `States` = 1, `ParentRoles` = '1' WHERE `ID` = 2;

UPDATE `db_performance`.`sys_role` SET `RoleName` = '护士长', `Type` = 3, `IndexUrl` = '/performance', `Remark` = '执行第二次绩效分配、计算', `States` = 1, `ParentRoles` = '1,2' WHERE `ID` = 3;

UPDATE `db_performance`.`sys_role` SET `RoleName` = '科主任', `Type` = 4, `IndexUrl` = '/leader/overview', `Remark` = '执行第二次绩效分配、计算', `States` = 1, `ParentRoles` = '1,2' WHERE `ID` = 4;

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (31, 1, 35);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (32, 1, 36);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (33, 1, 34);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (112, 2, 35);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (113, 2, 36);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (114, 2, 34);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (176, 5, 5);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (177, 5, 6);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (178, 5, 7);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (179, 5, 8);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (181, 5, 10);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (182, 5, 11);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (183, 5, 12);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (184, 5, 13);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (185, 5, 14);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (186, 5, 15);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (187, 5, 16);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (188, 5, 17);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (189, 5, 18);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (190, 5, 19);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (191, 5, 20);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (192, 5, 21);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (193, 5, 22);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (194, 5, 23);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (195, 5, 24);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (196, 5, 25);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (197, 5, 26);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (198, 5, 27);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (199, 5, 28);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (200, 5, 29);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (201, 5, 30);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (202, 5, 35);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (203, 5, 36);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (204, 5, 34);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (206, 5, 38);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (208, 5, 42);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (209, 5, 40);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (210, 5, 55);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (211, 5, 56);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (212, 5, 57);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (213, 5, 59);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (214, 5, 61);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (215, 5, 62);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (216, 5, 63);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (217, 5, 64);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (218, 5, 65);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (219, 5, 66);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (220, 5, 67);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (221, 5, 68);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (224, 5, 52);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (225, 5, 53);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (226, 5, 54);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (227, 3, 75);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (228, 3, 76);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (229, 3, 77);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (230, 3, 78);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (231, 3, 79);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (232, 3, 80);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (233, 3, 81);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (234, 3, 82);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (235, 4, 75);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (236, 4, 76);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (237, 4, 77);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (238, 4, 78);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (239, 4, 79);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (240, 4, 80);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (241, 4, 81);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (242, 4, 82);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (243, 3, 17);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (244, 4, 17);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (245, 6, 16);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (246, 6, 5);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (247, 6, 42);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (252, 3, 42);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (253, 4, 42);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (257, 7, 16);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (258, 7, 40);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (259, 7, 17);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (260, 7, 18);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (261, 7, 26);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (262, 8, 16);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (263, 8, 40);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (264, 8, 17);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (265, 8, 1);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (266, 8, 73);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (267, 8, 74);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (268, 5, 1);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (269, 5, 3);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (270, 5, 4);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (271, 5, 73);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (272, 5, 74);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (273, 5, 85);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (276, 1, 85);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (277, 2, 85);

INSERT INTO `db_performance`.`sys_role_menu`(`ID`, `RoleID`, `MenuID`) VALUES (278, 6, 85);

UPDATE `db_performance`.`sys_role_menu` SET `RoleID` = 1, `MenuID` = 73 WHERE `ID` = 165;

UPDATE `db_performance`.`sys_role_menu` SET `RoleID` = 1, `MenuID` = 74 WHERE `ID` = 166;

UPDATE `db_performance`.`sys_role_menu` SET `RoleID` = 2, `MenuID` = 73 WHERE `ID` = 167;

UPDATE `db_performance`.`sys_role_menu` SET `RoleID` = 2, `MenuID` = 74 WHERE `ID` = 168;

UPDATE `db_performance`.`sys_role_menu` SET `RoleID` = 2, `MenuID` = 52 WHERE `ID` = 169;

UPDATE `db_performance`.`sys_role_menu` SET `RoleID` = 2, `MenuID` = 53 WHERE `ID` = 170;

UPDATE `db_performance`.`sys_role_menu` SET `RoleID` = 2, `MenuID` = 54 WHERE `ID` = 171;

UPDATE `db_performance`.`sys_role_menu` SET `RoleID` = 5, `MenuID` = 2 WHERE `ID` = 173;

DELETE FROM `db_performance`.`sys_role_menu` WHERE `ID` = 2;

DELETE FROM `db_performance`.`sys_role_menu` WHERE `ID` = 7;

DELETE FROM `db_performance`.`sys_role_menu` WHERE `ID` = 121;

DELETE FROM `db_performance`.`sys_role_menu` WHERE `ID` = 172;

ALTER TABLE `db_performance`.`report_original_income` ADD COLUMN `AccountingUnit` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '科室核算单元' AFTER `SourceType`;

ALTER TABLE `db_performance`.`report_original_persontime` ADD COLUMN `AccountingUnit` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '科室核算单元' AFTER `SourceType`;

CREATE OR REPLACE VIEW `db_performance`.`view_report_sheet` AS select `per_sheet`.`ID` AS `ID`,`per_sheet`.`AllotID` AS `AllotID`,`per_sheet`.`SheetName` AS `SheetName`,`per_sheet`.`SheetType` AS `SheetType`,`per_sheet`.`Source` AS `Source`,(case when (`per_sheet`.`SheetName` like '%门诊开单%') then '门诊' when (`per_sheet`.`SheetName` like '%住院开单%') then '住院' end) AS `SourceType` from `per_sheet` where ((`per_sheet`.`SheetType` = 3) and ((`per_sheet`.`SheetName` like '%门诊开单%') or (`per_sheet`.`SheetName` like '%住院开单%'))) ;

CREATE OR REPLACE VIEW `db_performance`.`view_report_allot_summary` AS select `pa`.`ID` AS `AllotID`,`pa`.`Year` AS `Year`,`pa`.`Month` AS `Month`,`pa`.`HospitalId` AS `HospitalID`,`ra`.`AccountingUnit` AS `AccountingUnit`,sum(`ra`.`RealGiveFee`) AS `RealGiveFee` from (`db_performance`.`per_allot` `pa` join (select `db_performance`.`res_account`.`AllotID` AS `AllotID`,`db_performance`.`res_account`.`AccountingUnit` AS `AccountingUnit`,`db_performance`.`res_account`.`RealGiveFee` AS `RealGiveFee` from `db_performance`.`res_account` union all select `db_performance`.`res_compute`.`AllotID` AS `AllotID`,`db_performance`.`res_compute`.`AccountingUnit` AS `AccountingUnit`,`db_performance`.`res_compute`.`RealGiveFee` AS `RealGiveFee` from `db_performance`.`res_compute` union all select distinct `db_performance`.`res_specialunit`.`AllotID` AS `allotid`,`db_performance`.`res_specialunit`.`AccountingUnit` AS `AccountingUnit`,`db_performance`.`res_specialunit`.`RealGiveFee` AS `RealGiveFee` from `db_performance`.`res_specialunit`) `ra` on((`pa`.`ID` = `ra`.`AllotID`))) where (`pa`.`States` in (6,8,10)) group by `pa`.`ID`,`pa`.`Year`,`pa`.`Month`,`pa`.`HospitalId`,`ra`.`AccountingUnit` ;

CREATE OR REPLACE VIEW `db_performance`.`view_report_original_income` AS SELECT
	`pa`.`ID` AS `AllotID`,
	`pa`.`Year` AS `YEAR`,
	`pa`.`Month` AS `MONTH`,
	`pa`.`HospitalId` AS `HOSPITALID`,
	`ps`.`SourceType` AS `SourceType`,
	`dt`.`UnitType` AS `UnitType`,
	`dt`.`AccountingUnit` AS `AccountingUnit`,
IF
	( ( ifnull( `dt`.`Department`, '' ) = '' ), '未知', `dt`.`Department` ) AS `Department`,
IF
	( ( ifnull( `dt`.`TypeName`, '' ) = '' ), '未知', `dt`.`TypeName` ) AS `TypeName`,
	`dt`.`CellValue` AS `CellValue` 
FROM
	(
		( `per_allot` `pa` JOIN `view_report_sheet` `ps` ON ( ( `pa`.`ID` = `ps`.`AllotID` ) ) )
		JOIN `im_data` `dt` ON ( ( `ps`.`ID` = `dt`.`SheetID` ) ) 
	) 
WHERE
	( `pa`.`States` IN ( 6, 8, 10 ) ) ;

SET FOREIGN_KEY_CHECKS = 1;