-- 保留公司动态分类 1~5;仅移除曾错误添加到 fa_news 的公司信息字段。 ALTER TABLE `fa_news` MODIFY COLUMN `type` ENUM('1', '2', '3', '4', '5') NULL DEFAULT NULL COMMENT '动态类型:1=产品动态,2=公司动态,3=首页公司简介,4=公司介绍,5=生产管理'; SET @drop_address = ( SELECT IF(COUNT(*) > 0, 'ALTER TABLE `fa_news` DROP COLUMN `address`', 'SELECT 1') FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'fa_news' AND COLUMN_NAME = 'address' ); PREPARE company_info_stmt FROM @drop_address; EXECUTE company_info_stmt; DEALLOCATE PREPARE company_info_stmt; SET @drop_employee_count = ( SELECT IF(COUNT(*) > 0, 'ALTER TABLE `fa_news` DROP COLUMN `employee_count`', 'SELECT 1') FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'fa_news' AND COLUMN_NAME = 'employee_count' ); PREPARE company_info_stmt FROM @drop_employee_count; EXECUTE company_info_stmt; DEALLOCATE PREPARE company_info_stmt; SET @drop_total_sales = ( SELECT IF(COUNT(*) > 0, 'ALTER TABLE `fa_news` DROP COLUMN `total_sales`', 'SELECT 1') FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'fa_news' AND COLUMN_NAME = 'total_sales' ); PREPARE company_info_stmt FROM @drop_total_sales; EXECUTE company_info_stmt; DEALLOCATE PREPARE company_info_stmt; CREATE TABLE IF NOT EXISTS `fa_company_info` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `address` VARCHAR(255) NOT NULL COMMENT '公司总部地址', `employee_count` VARCHAR(100) NOT NULL COMMENT '员工数量', `total_sales` VARCHAR(100) NOT NULL COMMENT '产品总销售额', `createtime` BIGINT NULL DEFAULT NULL COMMENT '创建时间', `updatetime` BIGINT NULL DEFAULT NULL COMMENT '更新时间', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='公司信息'; INSERT IGNORE INTO `fa_auth_rule` (`type`, `pid`, `name`, `title`, `icon`, `url`, `condition`, `remark`, `ismenu`, `menutype`, `extend`, `py`, `pinyin`, `createtime`, `updatetime`, `weigh`, `status`) VALUES ('file', 0, 'company_info', '公司信息', 'fa fa-building', '', '', '', 1, NULL, '', 'gsxx', 'gongsixinxi', UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), 0, 'normal'); SET @company_info_pid = (SELECT `id` FROM `fa_auth_rule` WHERE `name` = 'company_info' LIMIT 1); INSERT IGNORE INTO `fa_auth_rule` (`type`, `pid`, `name`, `title`, `icon`, `url`, `condition`, `remark`, `ismenu`, `menutype`, `extend`, `py`, `pinyin`, `createtime`, `updatetime`, `weigh`, `status`) VALUES ('file', @company_info_pid, 'company_info/index', '查看', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), 0, 'normal'), ('file', @company_info_pid, 'company_info/add', '添加', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), 0, 'normal'), ('file', @company_info_pid, 'company_info/edit', '编辑', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), 0, 'normal'), ('file', @company_info_pid, 'company_info/del', '删除', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), 0, 'normal'), ('file', @company_info_pid, 'company_info/multi', '批量更新', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), 0, 'normal'); -- 为现有“普通管理员”角色追加公司信息权限;重复执行不会重复追加。 SET @company_info_rules = ( SELECT GROUP_CONCAT(`id` ORDER BY `id` SEPARATOR ',') FROM `fa_auth_rule` WHERE `name` IN ('company_info', 'company_info/index', 'company_info/add', 'company_info/edit', 'company_info/del', 'company_info/multi') ); UPDATE `fa_auth_group` SET `rules` = CONCAT_WS(',', NULLIF(`rules`, ''), @company_info_rules) WHERE `id` = 2 AND FIND_IN_SET(@company_info_pid, `rules`) = 0;