
-- ----------------------------
-- Table structure for zh_external_data
-- ----------------------------

CREATE TABLE `zh_external_data` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `tid` int(11) NOT NULL COMMENT '标段id',
  `sid` int(11) NOT NULL DEFAULT '-1' COMMENT '所属期id，-1表示整个标段共用',
  `ex_type` varchar(20) CHARACTER SET utf8 NOT NULL COMMENT '额外数据 - 类型(''fl'': 富龙接口数据)',
  `ex_field` varchar(20) CHARACTER SET utf8 NOT NULL COMMENT '额外数据 - 名称(具体细分由ex_type决定)',
  `ex_value` text CHARACTER SET utf8 COMMENT '额外数据 - 值',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='外部所需数据\r\n非计量支付内部运行所需数据，当接入外部系统时，这些系统可能要求我们提供某些额外的数据，例如：富龙接口，wbs_code\r\n类似数据，均存储在这里';

-- ----------------------------
-- zh_stage_bonus add column 发文单位
-- ----------------------------
ALTER TABLE `zh_stage_bonus`
ADD COLUMN `doc_co`  varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL COMMENT '发文单位' AFTER `code`;

-- ----------------------------
-- zh_stage_bonus add column 依据材料 - 文件列表
-- ----------------------------
ALTER TABLE `zh_stage_bonus`
ADD COLUMN `proof_file`  text CHARACTER SET utf8 NULL COMMENT '依据材料 - 文件列表(json)' AFTER `proof`;


-- 更改 zh_role_rpt_rel 结构，增加stage id
ALTER TABLE `zh_role_rpt_rel`
ADD COLUMN `sid` INT NULL AFTER `rpt_id`,
DROP INDEX `tender_idx` ,
ADD INDEX `tender_idx` (`tender_id` ASC, `rpt_id` ASC);


-- ----------------------------
-- Table structure for zh_maintain
-- ----------------------------
CREATE TABLE `zh_maintain` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `maintain_time` varchar(15) COLLATE utf8_unicode_ci NOT NULL COMMENT '维护时间',
  `duration` tinyint(4) NOT NULL DEFAULT '2' COMMENT '维护时长',
  `msg` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT '维护内容',
  `status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '维护状态，0：未设置，1：未开始，2：进行中',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='系统维护信息表';


INSERT INTO `zh_maintain` (`id`, `maintain_time`, `duration`, `msg`, `status`) VALUES
(1, '', 2, '', 0);

-- ----------------------------
-- zh_message add column 创建者id
-- ----------------------------
ALTER TABLE `zh_message`
ADD COLUMN `create_uid` int(11) DEFAULT NULL COMMENT '创建者id' AFTER `create_time`;

-- ----------------------------
-- zh_message add column 项目id
-- ----------------------------
ALTER TABLE `zh_message`
ADD COLUMN `project_id` int(11) DEFAULT NULL COMMENT '项目id，针对项目通知' AFTER `create_uid`;

-- ----------------------------
-- zh_message add column 是否置顶
-- ----------------------------
ALTER TABLE `zh_message`
ADD COLUMN `istop` varchar(15) NOT NULL DEFAULT '0' COMMENT '是否置顶，0为非置顶，时间戳为置顶时间' AFTER `release_time`;

-- ----------------------------
-- zh_message change column content
-- ----------------------------
ALTER TABLE `zh_message`
CHANGE `content` `content` text CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '消息内容';

-- ----------------------------
-- zh_message change column create_time
-- ----------------------------
ALTER TABLE `zh_message`
CHANGE `create_time` `create_time` varchar(15) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '创建时间';

-- ----------------------------
-- zh_message change column creator
-- ----------------------------
ALTER TABLE `zh_message`
CHANGE `creator` `creator` varchar(15) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '创建者';

-- ----------------------------
-- zh_message change column type
-- ----------------------------
ALTER TABLE `zh_message`
CHANGE `type` `type` tinyint(1) NOT NULL DEFAULT '1' COMMENT '消息类型 1为项目 2为系统';

-- ----------------------------
-- zh_message change column status
-- ----------------------------
ALTER TABLE `zh_message`
CHANGE `status` `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '消息状态，1：已发布，2：未发布';

-- ----------------------------
-- zh_message change column release_time
-- ----------------------------
ALTER TABLE `zh_message`
CHANGE `release_time` `release_time` int(10) NOT NULL DEFAULT '0' COMMENT '发布时间';

-- ----------------------------
-- zh_project add column 是否定制项目
-- ----------------------------
ALTER TABLE `zh_project`
ADD COLUMN `custom` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否是定制项目' AFTER `dealpay_json`;

-- ----------------------------
-- zh_project add column 定制项目接口是否可用
-- ----------------------------
ALTER TABLE `zh_project`
ADD COLUMN `can_api` tinyint(1) NOT NULL DEFAULT '1' COMMENT '定制项目接口是否可用';

-- ----------------------------
-- zh_project add column 定制项目私钥
-- ----------------------------
ALTER TABLE `zh_project`
ADD COLUMN `secret` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL COMMENT '定制项目私钥';

-- ----------------------------
-- zh_project_account add column 是否已绑定定制项目
-- ----------------------------
ALTER TABLE `zh_project_account`
ADD COLUMN `bind` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否已绑定定制项目' AFTER `sms_type`;

-- ----------------------------
-- 权限控制表，新增部分权限
-- ----------------------------
INSERT INTO `calculation`.`zh_permission` (`id`, `name`, `controller`, `action`, `pid`, `icon_class`, `create_time`, `isshow`) VALUES ('67', '系统维护', 'maintain', '', '11', '', NULL, '1');
INSERT INTO `calculation`.`zh_permission` (`id`, `name`, `controller`, `action`, `pid`, `icon_class`, `create_time`, `isshow`) VALUES ('68', '第三方接口', 'project', 'api2other', '38', 'api2other', NULL, '1');
INSERT INTO `calculation`.`zh_permission` (`id`, `name`, `controller`, `action`, `pid`, `icon_class`, `create_time`, `isshow`) VALUES ('69', '第三方接口设置', 'project', 'api2otherSave', '38', '', NULL, '1');

update `calculation`.`zh_permission` set `name` = '消息管理', `isshow` = 1 where `id` = 31;
update `calculation`.`zh_permission` set `name` = '消息通知', `isshow` = 1 where `id` = 32;
update `calculation`.`zh_permission` set `create_time` = '1' where `id` = 62;



-- ----------------------------
-- 先删除旧的调差表和数据，再新增
-- ----------------------------
DROP TABLE `zh_material`;
DROP TABLE `zh_material_audit`;
DROP TABLE `zh_material_bills`;
DROP TABLE `zh_material_list`;

-- --------------------------------------------------------

--
-- 表的结构 `zh_material`
--

CREATE TABLE `zh_material` (
  `id` int(11) NOT NULL COMMENT '自增id' AUTO_INCREMENT,
  `tid` int(11) NOT NULL COMMENT '标段id',
  `user_id` int(11) NOT NULL COMMENT '创建者id',
  `times` int(11) NOT NULL COMMENT '审批次数',
  `status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '审批状态',
  `stage_id` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT '期id列表',
  `s_order` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT '期数order列表',
  `order` tinyint(4) NOT NULL COMMENT '材料调差期数',
  `m_tp` decimal(30,8) DEFAULT NULL COMMENT '本期金额',
  `pre_tp` decimal(30,8) DEFAULT NULL COMMENT '截止上期金额',
  `rate` tinyint(11) NOT NULL DEFAULT '9' COMMENT '税率',
  `in_time` datetime NOT NULL COMMENT '创建时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='材料调差期列表';

-- --------------------------------------------------------

--
-- 表的结构 `zh_material_audit`
--

CREATE TABLE `zh_material_audit` (
  `id` int(11) NOT NULL COMMENT '主键' AUTO_INCREMENT,
  `tid` int(11) NOT NULL COMMENT '标段id',
  `mid` int(11) NOT NULL COMMENT '材料调差id',
  `aid` int(11) NOT NULL COMMENT '审批人id',
  `order` int(11) NOT NULL COMMENT '审批顺序',
  `times` int(11) NOT NULL COMMENT '审批次数',
  `status` tinyint(1) NOT NULL COMMENT '审批状态',
  `begin_time` datetime DEFAULT NULL COMMENT '开始审批时间',
  `end_time` datetime DEFAULT NULL COMMENT '结束审批时间',
  `opinion` varchar(1000) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '审批意见',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='材料调差审批表';

-- --------------------------------------------------------

--
-- 表的结构 `zh_material_bills`
--

CREATE TABLE `zh_material_bills` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `tid` int(11) NOT NULL COMMENT '所属标段id',
  `mid` int(11) NOT NULL COMMENT '所属调差调差id',
  `t_type` tinyint(4) NOT NULL DEFAULT '1' COMMENT '调差类型,1为消耗量，2为费用',
  `code` varchar(30) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '编号',
  `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '名称',
  `unit` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '单位',
  `spec` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '规格',
  `m_type` tinyint(1) NOT NULL DEFAULT '1' COMMENT '工料分类',
  `quantity` decimal(30,8) DEFAULT NULL COMMENT '本期应耗数量',
  `expr` varchar(1000) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '表达式',
  `basic_price` decimal(30,8) DEFAULT NULL COMMENT '基准价',
  `basic_times` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '基准时间',
  `msg_tp` decimal(30,8) DEFAULT NULL COMMENT '本期信息价单价',
  `msg_times` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '本期信息价时间',
  `msg_spread` decimal(30,8) DEFAULT NULL COMMENT '本期信息价价差',
  `m_up_risk` tinyint(3) DEFAULT NULL COMMENT '本期材料调差上涨风险幅度',
  `m_down_risk` tinyint(3) DEFAULT NULL COMMENT '本期材料调差下跌风险幅度',
  `m_spread` decimal(30,8) DEFAULT NULL COMMENT '本期材料调差有效价差',
  `pre_tp` decimal(30,8) DEFAULT NULL COMMENT '截止上期调差金额',
  `remark` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '备注',
  `in_time` datetime NOT NULL COMMENT '添加时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='调差工料清单表';

-- --------------------------------------------------------

--
-- 表的结构 `zh_material_bills_history`
--

CREATE TABLE `zh_material_bills_history` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `tid` int(11) NOT NULL COMMENT '所属标段',
  `mid` int(11) NOT NULL COMMENT '调差期id',
  `order` tinyint(4) NOT NULL COMMENT '调差期期数',
  `mb_id` int(11) NOT NULL COMMENT '工料id',
  `quantity` decimal(30,8) DEFAULT NULL COMMENT '本期应耗数量',
  `pre_tp` decimal(30,8) DEFAULT NULL COMMENT '截止上期调差金额',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='工料历史期部分操作数据';

-- --------------------------------------------------------

--
-- 表的结构 `zh_material_list`
--

CREATE TABLE `zh_material_list` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `tid` int(11) NOT NULL COMMENT '标段id',
  `order` tinyint(3) NOT NULL COMMENT '清单关联添加的原始期',
  `mid` int(11) NOT NULL COMMENT '调差期id',
  `mb_id` int(11) NOT NULL COMMENT '所属工料id',
  `gcl_id` varchar(100) COLLATE utf8_unicode_ci NOT NULL COMMENT '清单id',
  `xmj_id` varchar(100) COLLATE utf8_unicode_ci NOT NULL COMMENT '项目节id',
  `mx_id` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '部位明细id',
  `gather_qty` decimal(30,8) DEFAULT NULL COMMENT '本期计量数量-小计',
  `quantity` decimal(30,8) NOT NULL DEFAULT '0.00000000' COMMENT '数量',
  `is_join` tinyint(4) NOT NULL DEFAULT '1' COMMENT '是否参与调差',
  `in_time` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='调差工料-调差清单关联表';

-- --------------------------------------------------------

--
-- 表的结构 `zh_material_list_notjoin`
--

CREATE TABLE `zh_material_list_notjoin` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `tid` int(11) NOT NULL COMMENT '标段id',
  `mid` int(11) NOT NULL COMMENT '调差期id',
  `gcl_id` varchar(100) COLLATE utf8_unicode_ci NOT NULL COMMENT '清单id',
  `xmj_id` varchar(100) COLLATE utf8_unicode_ci NOT NULL COMMENT '项目节id',
  `mx_id` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '部位明细id',
  `in_time` datetime NOT NULL COMMENT '添加时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='不参与调差的清单表';
