SET FOREIGN_KEY_CHECKS=0;

ALTER TABLE `ClientCashInCashOut` ADD COLUMN `BankFlowId` varchar(100) NULL DEFAULT NULL COMMENT '银行流水ID' AFTER `SerialNumber`;

CREATE TABLE `client_variety_span_cfg`  (
  `id` int NOT NULL AUTO_INCREMENT COMMENT '主键Id',
  `ValueDate` date NOT NULL COMMENT '生效日期',
  `ClientId` int NOT NULL COMMENT '客户Id',
  `VarietyId` int NOT NULL COMMENT '品种Id',
  `SpanLimitRate` double(18, 4) NULL DEFAULT NULL COMMENT 'Span涨跌幅',
  `ForwardMarginRate` double(18, 4) NULL DEFAULT NULL COMMENT '远期预付金比例',
  `OptId` int NULL DEFAULT NULL COMMENT '操作人Id',
  `OptName` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '操作者名称',
  `OptDate` datetime NULL DEFAULT NULL COMMENT '操作日期',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `query_index`(`ValueDate` ASC, `ClientId` ASC, `VarietyId` ASC) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '客户品种 span 算法参数配置' ROW_FORMAT = Dynamic;

ALTER TABLE `eod_trade_risk_manual` MODIFY COLUMN `Pv` double(18, 4) NULL DEFAULT NULL COMMENT '持仓市值' AFTER `ValueDate`;

ALTER TABLE `eod_trade_risk_manual` MODIFY COLUMN `Delta` double(18, 4) NULL DEFAULT NULL COMMENT 'Delta' AFTER `Margin`;

ALTER TABLE `eod_trade_risk_manual` MODIFY COLUMN `Gamma` double(18, 4) NULL DEFAULT NULL COMMENT 'Gamma' AFTER `Delta`;

ALTER TABLE `eod_trade_risk_manual` MODIFY COLUMN `Vega` double(18, 4) NULL DEFAULT NULL COMMENT 'Vega' AFTER `Gamma`;

ALTER TABLE `eod_trade_risk_manual` MODIFY COLUMN `Theta` double(18, 4) NULL DEFAULT NULL COMMENT 'Theta' AFTER `Vega`;

ALTER TABLE `eod_trade_risk_manual` MODIFY COLUMN `Rho` double(18, 4) NULL DEFAULT NULL COMMENT 'Rho' AFTER `Theta`;

ALTER TABLE `eod_trade_risk_manual` MODIFY COLUMN `VegaCash` double NULL DEFAULT NULL COMMENT 'Vega现金' AFTER `GammaCash`;

CREATE TABLE `risk_manager_report_data`  (
  `id` int NOT NULL AUTO_INCREMENT COMMENT 'ID',
  `ValueDate` date NOT NULL COMMENT '报告日期',
  `RiskManagerReportData` longtext CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '报告内容',
  `OptDate` datetime NULL DEFAULT NULL COMMENT '操作日期',
  `OptId` int NULL DEFAULT NULL COMMENT '操作人ID',
  `OptName` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '操作人名称',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `index`(`ValueDate` ASC) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;

ALTER TABLE `trade_asian_option` ADD COLUMN `SoftPrincipal` double(18, 6) NULL DEFAULT NULL COMMENT '单位软保底' AFTER `EnhancedPrice`;

ALTER TABLE `trade_asian_option` ADD COLUMN `EnhancedPricesClient` double(18, 6) NULL DEFAULT NULL COMMENT '对客增强价格' AFTER `SoftPrincipal`;

ALTER TABLE `trade_asian_option` ADD COLUMN `HighStrike` double(18, 6) NULL DEFAULT NULL COMMENT '高执行价' AFTER `EnhancedPricesClient`;

ALTER TABLE `trade_asian_option` ADD COLUMN `LowStrike` double(18, 6) NULL DEFAULT NULL COMMENT '低执行价' AFTER `HighStrike`;

ALTER TABLE `trade_asian_option` ADD COLUMN `HighParticipationRate` double(18, 6) NULL DEFAULT NULL COMMENT '高参与率' AFTER `LowStrike`;

ALTER TABLE `trade_asian_option` ADD COLUMN `LowParticipationRate` double(18, 6) NULL DEFAULT NULL COMMENT '低参与率' AFTER `HighParticipationRate`;

ALTER TABLE `trade_asian_option` ADD COLUMN `HighEnhancedPrice` double(18, 6) NULL DEFAULT NULL COMMENT '高增强价格' AFTER `LowParticipationRate`;

ALTER TABLE `trade_asian_option` ADD COLUMN `LowEnhancedPrice` double(18, 6) NULL DEFAULT NULL COMMENT '低增强价格' AFTER `HighEnhancedPrice`;

ALTER TABLE `trade_contract_document` MODIFY COLUMN `StampDocumentFileName` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '用印文件' AFTER `ClientName`;

ALTER TABLE `trade_contract_document` MODIFY COLUMN `SealErrMsg` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '电子章用印错误信息' AFTER `SealResult`;

CREATE TABLE `trade_contract_r_number`  (
  `Id` int NOT NULL AUTO_INCREMENT,
  `TradeId` int NULL DEFAULT NULL COMMENT '交易id',
  `TradeCashId` int NULL DEFAULT NULL COMMENT '交易明细id',
  `TradeConfirmNumber` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '确认书里面生成编号',
  `ShowTradeConfirmNumber` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '确认书列表显示编号',
  `TradeConfirmNumberType` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '类型（C 交易确认书 U 提前平仓确然 S 到期确认书）',
  `TradeParentId` int NULL DEFAULT NULL COMMENT '交易父id',
  `OptId` int NULL DEFAULT NULL COMMENT '操作人ID',
  `OptName` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '操作人名称',
  `OptDate` datetime NULL DEFAULT NULL COMMENT '操作时间',
  PRIMARY KEY (`Id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = DYNAMIC;

CREATE TABLE `trade_margin_cfg`  (
  `id` int NOT NULL AUTO_INCREMENT COMMENT '主键Id',
  `TradeId` int NOT NULL COMMENT '交易Id',
  `ValueDate` date NOT NULL COMMENT '生效日期',
  `MarginRules` int NOT NULL COMMENT '预付金算法 0 Span算法 1 Delta算法',
  `SpanLimitRate` double(18, 4) NULL DEFAULT NULL COMMENT 'Span涨跌幅',
  `CombinationDiscount` int NOT NULL COMMENT '组合优惠 0 无  1 有',
  `CombinationTag` varchar(16) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '组合标识',
  `JoinMax` tinyint NOT NULL COMMENT '是否参与max比较 0 不参与 1 参与',
  `OptId` int NULL DEFAULT NULL COMMENT '操作人Id',
  `OptName` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '操作者名称',
  `OptDate` datetime NULL DEFAULT NULL COMMENT '操作日期',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `tradeindex`(`TradeId` ASC, `ValueDate` ASC) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '交易预付金配置' ROW_FORMAT = Dynamic;

ALTER TABLE `variety` ADD COLUMN `DeltaMarginRate` double NULL DEFAULT 1 COMMENT 'Delta算法预付金比例' AFTER `IndexType`;

DROP TABLE IF EXISTS `trs_gateway`;

SET FOREIGN_KEY_CHECKS=1;