From 895796b48c888d9068d5d480e54f57630a5fdb54 Mon Sep 17 00:00:00 2001 From: Lxy Date: Sat, 24 Jan 2026 09:50:45 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E5=88=9D=E6=AD=A5=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E5=AE=8C=E5=96=84=E8=A1=8C=E4=B8=9A=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../newstocksystem/domain/TIndustryIndex.java | 186 +++++++++++++++++- .../impl/IndustryIndexServiceImpl.java | 38 ++++ .../newstocksystem/IndustryIndexMapper.xml | 101 ++++++++-- .../alter_t_industry_index_add_fields.sql | 15 ++ sql_refacor0120/t_industry_index.sql | 17 +- 5 files changed, 342 insertions(+), 15 deletions(-) create mode 100644 sql_refacor0120/alter_t_industry_index_add_fields.sql diff --git a/newstock-system/src/main/java/com/ruoyi/newstocksystem/domain/TIndustryIndex.java b/newstock-system/src/main/java/com/ruoyi/newstocksystem/domain/TIndustryIndex.java index 55d9af7..ac8e039 100644 --- a/newstock-system/src/main/java/com/ruoyi/newstocksystem/domain/TIndustryIndex.java +++ b/newstock-system/src/main/java/com/ruoyi/newstocksystem/domain/TIndustryIndex.java @@ -19,11 +19,11 @@ public class TIndustryIndex extends BaseEntity private static final long serialVersionUID = 1L; /** 行业指数代码(如802089.EI) */ - @Excel(name = "行业指数代码") + @Excel(name = "证券代码") private String industryIndexCode; /** 行业指数名称(如"银行") */ - @Excel(name = "行业指数名称") + @Excel(name = "证券名称") private String industryIndexName; /** 成份个数(行业包含个股数量) */ @@ -71,6 +71,58 @@ public class TIndustryIndex extends BaseEntity @Excel(name = "市盈率PE(TTM)中位值") private BigDecimal peTtmMedian; + /** 最高价(指数点位) */ + @Excel(name = "最高价") + private BigDecimal highPrice; + + /** 最低价(指数点位) */ + @Excel(name = "最低价") + private BigDecimal lowPrice; + + /** 振幅(百分比) */ + @Excel(name = "振幅") + private BigDecimal amplitude; + + /** 换手率(百分比) */ + @Excel(name = "换手率") + private BigDecimal turnoverRate; + + /** 等权重平均涨跌幅(百分比) */ + @Excel(name = "等权平均涨跌幅") + private BigDecimal equalWeightAvgChangeRate; + + /** 成份股上涨家数 */ + @Excel(name = "上涨家数") + private Integer upCount; + + /** 成份股下跌家数 */ + @Excel(name = "下跌家数") + private Integer downCount; + + /** 成份股涨停家数 */ + @Excel(name = "涨停家数") + private Integer limitUpCount; + + /** 成份股跌停家数 */ + @Excel(name = "跌停家数") + private Integer limitDownCount; + + /** 成份股平盘家数 */ + @Excel(name = "平盘家数") + private Integer noChangeCount; + + /** 成份股停牌家数 */ + @Excel(name = "停牌家数") + private Integer suspendCount; + + /** 近期创历史新高 */ + @Excel(name = "创历史新高", readConverterExp = "1=是,0=否") + private Integer newHighFlag; + + /** 近期创历史新低 */ + @Excel(name = "创历史新低", readConverterExp = "1=是,0=否") + private Integer newLowFlag; + public String getIndustryIndexCode() { return industryIndexCode; @@ -201,6 +253,136 @@ public class TIndustryIndex extends BaseEntity this.peTtmMedian = peTtmMedian; } + public BigDecimal getHighPrice() + { + return highPrice; + } + + public void setHighPrice(BigDecimal highPrice) + { + this.highPrice = highPrice; + } + + public BigDecimal getLowPrice() + { + return lowPrice; + } + + public void setLowPrice(BigDecimal lowPrice) + { + this.lowPrice = lowPrice; + } + + public BigDecimal getAmplitude() + { + return amplitude; + } + + public void setAmplitude(BigDecimal amplitude) + { + this.amplitude = amplitude; + } + + public BigDecimal getTurnoverRate() + { + return turnoverRate; + } + + public void setTurnoverRate(BigDecimal turnoverRate) + { + this.turnoverRate = turnoverRate; + } + + public BigDecimal getEqualWeightAvgChangeRate() + { + return equalWeightAvgChangeRate; + } + + public void setEqualWeightAvgChangeRate(BigDecimal equalWeightAvgChangeRate) + { + this.equalWeightAvgChangeRate = equalWeightAvgChangeRate; + } + + public Integer getUpCount() + { + return upCount; + } + + public void setUpCount(Integer upCount) + { + this.upCount = upCount; + } + + public Integer getDownCount() + { + return downCount; + } + + public void setDownCount(Integer downCount) + { + this.downCount = downCount; + } + + public Integer getLimitUpCount() + { + return limitUpCount; + } + + public void setLimitUpCount(Integer limitUpCount) + { + this.limitUpCount = limitUpCount; + } + + public Integer getLimitDownCount() + { + return limitDownCount; + } + + public void setLimitDownCount(Integer limitDownCount) + { + this.limitDownCount = limitDownCount; + } + + public Integer getNoChangeCount() + { + return noChangeCount; + } + + public void setNoChangeCount(Integer noChangeCount) + { + this.noChangeCount = noChangeCount; + } + + public Integer getSuspendCount() + { + return suspendCount; + } + + public void setSuspendCount(Integer suspendCount) + { + this.suspendCount = suspendCount; + } + + public Integer getNewHighFlag() + { + return newHighFlag; + } + + public void setNewHighFlag(Integer newHighFlag) + { + this.newHighFlag = newHighFlag; + } + + public Integer getNewLowFlag() + { + return newLowFlag; + } + + public void setNewLowFlag(Integer newLowFlag) + { + this.newLowFlag = newLowFlag; + } + @Override public String toString() { diff --git a/newstock-system/src/main/java/com/ruoyi/newstocksystem/service/impl/IndustryIndexServiceImpl.java b/newstock-system/src/main/java/com/ruoyi/newstocksystem/service/impl/IndustryIndexServiceImpl.java index 252e100..61023ba 100644 --- a/newstock-system/src/main/java/com/ruoyi/newstocksystem/service/impl/IndustryIndexServiceImpl.java +++ b/newstock-system/src/main/java/com/ruoyi/newstocksystem/service/impl/IndustryIndexServiceImpl.java @@ -64,6 +64,44 @@ public class IndustryIndexServiceImpl implements IIndustryIndexService @Override public int importIndustryIndex(List industryIndexList, Date tradeDate) { + // 为每个行业指数数据设置交易日期 + for (TIndustryIndex industryIndex : industryIndexList) + { + industryIndex.setTradeDate(tradeDate); + + // 检查并创建或更新行业基础数据 + String industryCode = industryIndex.getIndustryIndexCode(); + String industryName = industryIndex.getIndustryIndexName(); + + // 查询行业基础数据是否存在 + com.ruoyi.newstocksystem.domain.TIndustryBasic existingIndustryBasic = + industryBasicService.selectTIndustryBasicByCode(industryCode); + + if (existingIndustryBasic == null) + { + // 如果行业基础数据不存在,则创建 + com.ruoyi.newstocksystem.domain.TIndustryBasic industryBasic = new com.ruoyi.newstocksystem.domain.TIndustryBasic(); + industryBasic.setIndustryCode(industryCode); + industryBasic.setIndustryName(industryName); + industryBasic.setIndustryLevel(2); // 默认为二级行业 + industryBasic.setStatus(1); // 默认启用 + industryBasic.setSortOrder(0); // 默认排序 + + industryBasicService.insertTIndustryBasic(industryBasic); + } + else + { + // 如果行业基础数据存在,检查名称是否发生变化 + if (!existingIndustryBasic.getIndustryName().equals(industryName)) + { + // 名称发生变化,更新行业基础数据 + existingIndustryBasic.setIndustryName(industryName); + industryBasicService.updateTIndustryBasic(existingIndustryBasic); + } + } + } + + // 批量插入或更新行业指数数据 return industryIndexMapper.batchUpsertIndustryIndex(industryIndexList); } diff --git a/newstock-system/src/main/resources/mapper/newstocksystem/IndustryIndexMapper.xml b/newstock-system/src/main/resources/mapper/newstocksystem/IndustryIndexMapper.xml index dd3dd5f..d3113b1 100644 --- a/newstock-system/src/main/resources/mapper/newstocksystem/IndustryIndexMapper.xml +++ b/newstock-system/src/main/resources/mapper/newstocksystem/IndustryIndexMapper.xml @@ -10,22 +10,37 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + + + + + + + + + + select industry_index_code, industry_index_name, component_count, trade_date, - open_price, close_price, volume, turnover, total_market_cap, - free_circulation_cap, price_change_rate, pe_ttm, pe_ttm_median, - create_time, update_time + open_price, close_price, high_price, low_price, volume, turnover, + total_market_cap, free_circulation_cap, price_change_rate, amplitude, + turnover_rate, equal_weight_avg_change_rate, pe_ttm, pe_ttm_median, + up_count, down_count, limit_up_count, limit_down_count, no_change_count, + suspend_count, new_high_flag, new_low_flag, create_time, update_time from t_industry_index @@ -77,13 +92,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" trade_date, open_price, close_price, + high_price, + low_price, volume, turnover, total_market_cap, free_circulation_cap, price_change_rate, + amplitude, + turnover_rate, + equal_weight_avg_change_rate, pe_ttm, pe_ttm_median, + up_count, + down_count, + limit_up_count, + limit_down_count, + no_change_count, + suspend_count, + new_high_flag, + new_low_flag, create_time, @@ -93,13 +121,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{tradeDate}, #{openPrice}, #{closePrice}, + #{highPrice}, + #{lowPrice}, #{volume}, #{turnover}, #{totalMarketCap}, #{freeCirculationCap}, #{priceChangeRate}, + #{amplitude}, + #{turnoverRate}, + #{equalWeightAvgChangeRate}, #{peTtm}, #{peTtmMedian}, + #{upCount}, + #{downCount}, + #{limitUpCount}, + #{limitDownCount}, + #{noChangeCount}, + #{suspendCount}, + #{newHighFlag}, + #{newLowFlag}, NOW(), @@ -111,13 +152,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" component_count = #{componentCount}, open_price = #{openPrice}, close_price = #{closePrice}, + high_price = #{highPrice}, + low_price = #{lowPrice}, volume = #{volume}, turnover = #{turnover}, total_market_cap = #{totalMarketCap}, free_circulation_cap = #{freeCirculationCap}, price_change_rate = #{priceChangeRate}, + amplitude = #{amplitude}, + turnover_rate = #{turnoverRate}, + equal_weight_avg_change_rate = #{equalWeightAvgChangeRate}, pe_ttm = #{peTtm}, pe_ttm_median = #{peTtmMedian}, + up_count = #{upCount}, + down_count = #{downCount}, + limit_up_count = #{limitUpCount}, + limit_down_count = #{limitDownCount}, + no_change_count = #{noChangeCount}, + suspend_count = #{suspendCount}, + new_high_flag = #{newHighFlag}, + new_low_flag = #{newLowFlag}, update_time = NOW(), where industry_index_code = #{industryIndexCode} and trade_date = #{tradeDate} @@ -129,38 +183,63 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" insert into t_industry_index(industry_index_code, industry_index_name, component_count, trade_date, - open_price, close_price, volume, turnover, total_market_cap, - free_circulation_cap, price_change_rate, pe_ttm, pe_ttm_median, create_time) + open_price, close_price, high_price, low_price, volume, turnover, + total_market_cap, free_circulation_cap, price_change_rate, amplitude, + turnover_rate, equal_weight_avg_change_rate, pe_ttm, pe_ttm_median, + up_count, down_count, limit_up_count, limit_down_count, no_change_count, + suspend_count, new_high_flag, new_low_flag, create_time) values (#{item.industryIndexCode}, #{item.industryIndexName}, #{item.componentCount}, #{item.tradeDate}, - #{item.openPrice}, #{item.closePrice}, #{item.volume}, #{item.turnover}, #{item.totalMarketCap}, - #{item.freeCirculationCap}, #{item.priceChangeRate}, #{item.peTtm}, #{item.peTtmMedian}, NOW()) + #{item.openPrice}, #{item.closePrice}, #{item.highPrice}, #{item.lowPrice}, #{item.volume}, #{item.turnover}, + #{item.totalMarketCap}, #{item.freeCirculationCap}, #{item.priceChangeRate}, #{item.amplitude}, + #{item.turnoverRate}, #{item.equalWeightAvgChangeRate}, #{item.peTtm}, #{item.peTtmMedian}, + #{item.upCount}, #{item.downCount}, #{item.limitUpCount}, #{item.limitDownCount}, #{item.noChangeCount}, + #{item.suspendCount}, #{item.newHighFlag}, #{item.newLowFlag}, NOW()) insert into t_industry_index(industry_index_code, industry_index_name, component_count, trade_date, - open_price, close_price, volume, turnover, total_market_cap, - free_circulation_cap, price_change_rate, pe_ttm, pe_ttm_median, create_time) + open_price, close_price, high_price, low_price, volume, turnover, + total_market_cap, free_circulation_cap, price_change_rate, amplitude, + turnover_rate, equal_weight_avg_change_rate, pe_ttm, pe_ttm_median, + up_count, down_count, limit_up_count, limit_down_count, no_change_count, + suspend_count, new_high_flag, new_low_flag, create_time) values (#{item.industryIndexCode}, #{item.industryIndexName}, #{item.componentCount}, #{item.tradeDate}, - #{item.openPrice}, #{item.closePrice}, #{item.volume}, #{item.turnover}, #{item.totalMarketCap}, - #{item.freeCirculationCap}, #{item.priceChangeRate}, #{item.peTtm}, #{item.peTtmMedian}, NOW()) + #{item.openPrice}, #{item.closePrice}, #{item.highPrice}, #{item.lowPrice}, #{item.volume}, #{item.turnover}, + #{item.totalMarketCap}, #{item.freeCirculationCap}, #{item.priceChangeRate}, #{item.amplitude}, + #{item.turnoverRate}, #{item.equalWeightAvgChangeRate}, #{item.peTtm}, #{item.peTtmMedian}, + #{item.upCount}, #{item.downCount}, #{item.limitUpCount}, #{item.limitDownCount}, #{item.noChangeCount}, + #{item.suspendCount}, #{item.newHighFlag}, #{item.newLowFlag}, NOW()) ON DUPLICATE KEY UPDATE industry_index_name = VALUES(industry_index_name), component_count = VALUES(component_count), open_price = VALUES(open_price), close_price = VALUES(close_price), + high_price = VALUES(high_price), + low_price = VALUES(low_price), volume = VALUES(volume), turnover = VALUES(turnover), total_market_cap = VALUES(total_market_cap), free_circulation_cap = VALUES(free_circulation_cap), price_change_rate = VALUES(price_change_rate), + amplitude = VALUES(amplitude), + turnover_rate = VALUES(turnover_rate), + equal_weight_avg_change_rate = VALUES(equal_weight_avg_change_rate), pe_ttm = VALUES(pe_ttm), pe_ttm_median = VALUES(pe_ttm_median), + up_count = VALUES(up_count), + down_count = VALUES(down_count), + limit_up_count = VALUES(limit_up_count), + limit_down_count = VALUES(limit_down_count), + no_change_count = VALUES(no_change_count), + suspend_count = VALUES(suspend_count), + new_high_flag = VALUES(new_high_flag), + new_low_flag = VALUES(new_low_flag), update_time = NOW() diff --git a/sql_refacor0120/alter_t_industry_index_add_fields.sql b/sql_refacor0120/alter_t_industry_index_add_fields.sql new file mode 100644 index 0000000..9b5f3b4 --- /dev/null +++ b/sql_refacor0120/alter_t_industry_index_add_fields.sql @@ -0,0 +1,15 @@ +-- 为 t_industry_index 表添加新字段,补充行业指数数据的完整字段 +ALTER TABLE `t_industry_index` +ADD COLUMN `high_price` DECIMAL(10,2) NULL COMMENT '最高价(指数点位)' AFTER `close_price`, +ADD COLUMN `low_price` DECIMAL(10,2) NULL COMMENT '最低价(指数点位)' AFTER `high_price`, +ADD COLUMN `amplitude` DECIMAL(6,4) NULL COMMENT '振幅(百分比)' AFTER `low_price`, +ADD COLUMN `turnover_rate` DECIMAL(6,4) NULL COMMENT '换手率(百分比)' AFTER `amplitude`, +ADD COLUMN `equal_weight_avg_change_rate` DECIMAL(6,4) NULL COMMENT '等权重平均涨跌幅(百分比)' AFTER `turnover_rate`, +ADD COLUMN `up_count` INT NULL COMMENT '成份股上涨家数' AFTER `equal_weight_avg_change_rate`, +ADD COLUMN `down_count` INT NULL COMMENT '成份股下跌家数' AFTER `up_count`, +ADD COLUMN `limit_up_count` INT NULL COMMENT '成份股涨停家数' AFTER `down_count`, +ADD COLUMN `limit_down_count` INT NULL COMMENT '成份股跌停家数' AFTER `limit_up_count`, +ADD COLUMN `no_change_count` INT NULL COMMENT '成份股平盘家数' AFTER `limit_down_count`, +ADD COLUMN `suspend_count` INT NULL COMMENT '成份股停牌家数' AFTER `no_change_count`, +ADD COLUMN `new_high_flag` TINYINT NULL COMMENT '近期创历史新高(1=是,0=否)' AFTER `suspend_count`, +ADD COLUMN `new_low_flag` TINYINT NULL COMMENT '近期创历史新低(1=是,0=否)' AFTER `new_high_flag`; \ No newline at end of file diff --git a/sql_refacor0120/t_industry_index.sql b/sql_refacor0120/t_industry_index.sql index b23023c..e66ef94 100644 --- a/sql_refacor0120/t_industry_index.sql +++ b/sql_refacor0120/t_industry_index.sql @@ -1,7 +1,7 @@ -- 行业指数表:存储东财二级行业指数基础信息及每日成交数据 CREATE TABLE `t_industry_index` ( `industry_index_code` VARCHAR(20) NOT NULL COMMENT '行业指数代码(如802089.EI)', - `industry_index_name` VARCHAR(50) NOT NULL COMMENT '行业指数名称(如“银行”)', + `industry_index_name` VARCHAR(50) NOT NULL COMMENT '行业指数名称(如"银行")', `component_count` INT NULL COMMENT '成份个数(行业包含个股数量)', `trade_date` DATE NOT NULL COMMENT '交易日期', `open_price` DECIMAL(10,2) NULL COMMENT '开盘价(指数点位)', @@ -13,9 +13,22 @@ CREATE TABLE `t_industry_index` ( `price_change_rate` DECIMAL(6,4) NULL COMMENT '涨跌幅(百分比,如1.2937=1.2937%)', `pe_ttm` DECIMAL(10,2) NULL COMMENT '市盈率PE(TTM)', `pe_ttm_median` DECIMAL(10,2) NULL COMMENT '市盈率PE(TTM)中位值', + `high_price` DECIMAL(10,2) NULL COMMENT '最高价(指数点位)', + `low_price` DECIMAL(10,2) NULL COMMENT '最低价(指数点位)', + `amplitude` DECIMAL(6,4) NULL COMMENT '振幅(百分比)', + `turnover_rate` DECIMAL(6,4) NULL COMMENT '换手率(百分比)', + `equal_weight_avg_change_rate` DECIMAL(6,4) NULL COMMENT '等权重平均涨跌幅(百分比)', + `up_count` INT NULL COMMENT '成份股上涨家数', + `down_count` INT NULL COMMENT '成份股下跌家数', + `limit_up_count` INT NULL COMMENT '成份股涨停家数', + `limit_down_count` INT NULL COMMENT '成份股跌停家数', + `no_change_count` INT NULL COMMENT '成份股平盘家数', + `suspend_count` INT NULL COMMENT '成份股停牌家数', + `new_high_flag` TINYINT NULL COMMENT '近期创历史新高(1=是,0=否)', + `new_low_flag` TINYINT NULL COMMENT '近期创历史新低(1=是,0=否)', `create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '数据创建时间(自动填充)', `update_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '数据更新时间(自动更新)', - -- 复合主键:确保“指数代码+日期”唯一 + -- 复合主键:确保"指数代码+日期"唯一 PRIMARY KEY (`industry_index_code`, `trade_date`), -- 索引:优化按日期查询所有行业指数的场景 INDEX `idx_t_industry_index_trade_date` (`trade_date`)