fix: 增加分析前端api等细节

dev_refactor_0120_qoder
Lxy 4 months ago
parent 9f39fb2695
commit 1faa74db11

@ -22,6 +22,7 @@ import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log; import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.controller.BaseController;
@ -320,6 +321,24 @@ public class StockDataController extends BaseController
return AjaxResult.success(lastTradeDate); return AjaxResult.success(lastTradeDate);
} }
/**
*
*/
@GetMapping("/checkAnalysisStatus")
public AjaxResult checkAnalysisStatus(@RequestParam String tradeDate)
{
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date tradeDateObj = sdf.parse(tradeDate);
boolean exists = stockDailyTradeService.checkTrendsExists(tradeDateObj);
return AjaxResult.success(exists);
} catch (ParseException e) {
return AjaxResult.error("日期格式错误请使用yyyy-MM-dd格式");
} catch (Exception e) {
return AjaxResult.error("检查失败:" + e.getMessage());
}
}
/** /**
* *
*/ */

@ -109,4 +109,12 @@ public interface TStockDailyTradeMapper
* @return yyyy-MM-dd * @return yyyy-MM-dd
*/ */
public String selectLastTradeDate(); public String selectLastTradeDate();
/**
*
*
* @param tradeDate
* @return 10
*/
public int checkTradeDataExistsByDate(Date tradeDate);
} }

@ -1,5 +1,6 @@
package com.ruoyi.newstocksystem.mapper; package com.ruoyi.newstocksystem.mapper;
import java.util.Date;
import java.util.List; import java.util.List;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@ -70,4 +71,12 @@ public interface TTrendsMapper
* @return * @return
*/ */
public int batchUpsert(List<TTrends> tTrendsList); public int batchUpsert(List<TTrends> tTrendsList);
/**
*
*
* @param tradeDate
* @return 10
*/
public int checkTrendsExistsByDate(Date tradeDate);
} }

@ -109,4 +109,12 @@ public interface IStockDailyTradeService
* @return * @return
*/ */
public String analysisStockData(TStockDailyTrade stockDailyTrade); public String analysisStockData(TStockDailyTrade stockDailyTrade);
/**
*
*
* @param tradeDate
* @return
*/
public boolean checkTrendsExists(Date tradeDate);
} }

@ -17,8 +17,8 @@ import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.newstocksystem.domain.TIndustryBasic; import com.ruoyi.newstocksystem.domain.TIndustryBasic;
import com.ruoyi.newstocksystem.domain.TStockBasic; import com.ruoyi.newstocksystem.domain.TStockBasic;
import com.ruoyi.newstocksystem.domain.TStockDailyTrade; import com.ruoyi.newstocksystem.domain.TStockDailyTrade;
import com.ruoyi.newstocksystem.mapper.TStockBasicMapper;
import com.ruoyi.newstocksystem.mapper.TStockDailyTradeMapper; import com.ruoyi.newstocksystem.mapper.TStockDailyTradeMapper;
import com.ruoyi.newstocksystem.mapper.TTrendsMapper;
import com.ruoyi.newstocksystem.service.IIndustryIndexService; import com.ruoyi.newstocksystem.service.IIndustryIndexService;
import com.ruoyi.newstocksystem.service.IStockBasicService; import com.ruoyi.newstocksystem.service.IStockBasicService;
import com.ruoyi.newstocksystem.service.IStockDailyTradeService; import com.ruoyi.newstocksystem.service.IStockDailyTradeService;
@ -38,6 +38,9 @@ public class StockDailyTradeServiceImpl implements IStockDailyTradeService
@Autowired @Autowired
private TStockDailyTradeMapper stockDailyTradeMapper; private TStockDailyTradeMapper stockDailyTradeMapper;
@Autowired
private TTrendsMapper trendsMapper;
@Autowired @Autowired
private IStockBasicService stockBasicService; private IStockBasicService stockBasicService;
@ -386,25 +389,64 @@ public class StockDailyTradeServiceImpl implements IStockDailyTradeService
return stockDailyTradeMapper.selectLastTradeDate(); return stockDailyTradeMapper.selectLastTradeDate();
} }
@Override
public boolean checkTrendsExists(Date tradeDate)
{
logger.info("检查指定日期是否存在趋势数据,交易日期: {}", tradeDate);
try {
int count = trendsMapper.checkTrendsExistsByDate(tradeDate);
return count > 0;
} catch (Exception e) {
logger.error("检查趋势数据存在性失败,交易日期: {}", tradeDate, e);
throw new RuntimeException("检查失败: " + e.getMessage());
}
}
/**
*
*
* @param tradeDate
* @return
*/
private boolean checkTradeDataExists(Date tradeDate)
{
logger.info("检查指定日期是否存在交易数据,交易日期: {}", tradeDate);
try {
int count = stockDailyTradeMapper.checkTradeDataExistsByDate(tradeDate);
return count > 0;
} catch (Exception e) {
logger.error("检查交易数据存在性失败,交易日期: {}", tradeDate, e);
throw new RuntimeException("检查失败: " + e.getMessage());
}
}
@Override @Override
public String analysisStockData(TStockDailyTrade stockDailyTrade) public String analysisStockData(TStockDailyTrade stockDailyTrade)
{ {
logger.info("开始分析股票数据,交易日期: {}", stockDailyTrade.getTradeDate()); logger.info("开始分析股票数据,交易日期: {}", stockDailyTrade.getTradeDate());
try { try {
// 这里实现具体的分析逻辑参考stocksystem的analysis方法 // 1. 先检查指定日期是否存在交易数据
if (!checkTradeDataExists(stockDailyTrade.getTradeDate())) {
logger.info("指定日期不存在交易数据,无法进行分析,交易日期: {}", stockDailyTrade.getTradeDate());
return "该日期不存在交易数据,无法进行分析";
}
// 2. 再检查指定日期是否已存在分析数据
if (checkTrendsExists(stockDailyTrade.getTradeDate())) {
logger.info("指定日期已存在分析数据,跳过分析,交易日期: {}", stockDailyTrade.getTradeDate());
return "该日期已存在分析数据,无需重复分析";
}
// 3. 这里实现具体的分析逻辑参考stocksystem的analysis方法
// 目前先记录日志并返回成功 // 目前先记录日志并返回成功
// 1. 可以在这里添加分析逻辑,比如: // 可以在这里添加分析逻辑,比如:
// - 更新涨跌幅数据 // - 更新涨跌幅数据
// - 计算动量指标 // - 计算动量指标
// - 生成技术分析结果 // - 生成技术分析结果
// - 其他业务逻辑 // - 其他业务逻辑
// 2. 示例:可以遍历当天数据,进行某些计算
// List<TStockDailyTrade> dailyTradeList = stockDailyTradeMapper.selectStockDailyTradeList(stockDailyTrade);
// 然后对这些数据进行分析处理
logger.info("股票数据分析完成,交易日期: {}", stockDailyTrade.getTradeDate()); logger.info("股票数据分析完成,交易日期: {}", stockDailyTrade.getTradeDate());
return "分析完成"; return "分析完成";
} catch (Exception e) { } catch (Exception e) {

@ -244,4 +244,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
momentum_20d = VALUES(momentum_20d), momentum_20d = VALUES(momentum_20d),
momentum_60d = VALUES(momentum_60d) momentum_60d = VALUES(momentum_60d)
</insert> </insert>
<select id="checkTradeDataExistsByDate" parameterType="Date" resultType="int">
select count(1) from t_stock_daily_trade where trade_date = #{tradeDate}
</select>
</mapper> </mapper>

@ -146,4 +146,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
eastmoney_industry_name = VALUES(eastmoney_industry_name), eastmoney_industry_name = VALUES(eastmoney_industry_name),
update_time = VALUES(update_time) update_time = VALUES(update_time)
</insert> </insert>
<select id="checkTrendsExistsByDate" parameterType="Date" resultType="int">
select count(1) from t_trends where trade_date = #{tradeDate}
</select>
</mapper> </mapper>

@ -167,6 +167,15 @@ export default {
}) })
}, },
// 查询指定日期是否已存在分析数据
checkAnalysisStatus(tradeDate) {
return request({
url: '/newstocksystem/stockdata/checkAnalysisStatus',
method: 'get',
params: { tradeDate }
})
},
// ========================= 个股新高新低状态相关 ========================= // ========================= 个股新高新低状态相关 =========================
// 查询个股新高新低状态列表 // 查询个股新高新低状态列表

@ -46,7 +46,16 @@
<el-form-item> <el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="queryDailyTrade"></el-button> <el-button type="primary" icon="el-icon-search" size="mini" @click="queryDailyTrade"></el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetDailyTradeQuery"></el-button> <el-button icon="el-icon-refresh" size="mini" @click="resetDailyTradeQuery"></el-button>
<el-button type="success" icon="el-icon-s-data" size="mini" @click="handleAnalysis"></el-button> <el-button
type="success"
icon="el-icon-s-data"
size="mini"
@click="handleAnalysis"
:disabled="analysisStatus.isAnalyzed || analysisStatus.checking || dailyTradeTotal === 0"
:loading="analysisStatus.checking"
>
{{ dailyTradeTotal === 0 ? '无数据' : (analysisStatus.isAnalyzed ? '已分析' : '分析') }}
</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
@ -347,7 +356,13 @@ export default {
updateSupport: false, updateSupport: false,
tradeDate: null tradeDate: null
}, },
fileList: [] fileList: [],
// ========================= =========================
analysisStatus: {
isAnalyzed: false, //
checking: false //
}
} }
}, },
computed: { computed: {
@ -355,6 +370,12 @@ export default {
return { Authorization: 'Bearer ' + getToken() } return { Authorization: 'Bearer ' + getToken() }
} }
}, },
watch: {
//
'dailyTradeQuery.tradeDate'(newVal) {
this.checkAnalysisStatus(newVal)
}
},
created() { created() {
this.getIndustryOptions() this.getIndustryOptions()
this.getLastTradeDate() this.getLastTradeDate()
@ -378,12 +399,31 @@ export default {
this.dailyTradeQuery.tradeDate = lastTradeDate this.dailyTradeQuery.tradeDate = lastTradeDate
this.industryIndexQuery.tradeDate = lastTradeDate this.industryIndexQuery.tradeDate = lastTradeDate
this.stockHighLowQuery.tradeDate = lastTradeDate this.stockHighLowQuery.tradeDate = lastTradeDate
//
this.checkAnalysisStatus(lastTradeDate)
} }
// //
this.getDailyTradeList() this.getDailyTradeList()
}) })
}, },
/** 检查指定日期是否已存在分析数据 */
checkAnalysisStatus(tradeDate) {
if (!tradeDate) {
this.analysisStatus.isAnalyzed = false
return
}
this.analysisStatus.checking = true
stockdataApi.checkAnalysisStatus(tradeDate).then(response => {
this.analysisStatus.isAnalyzed = response.data
}).catch(error => {
this.$message.error('检查分析状态失败:' + (error.msg || error.message || '未知错误'))
this.analysisStatus.isAnalyzed = false
}).finally(() => {
this.analysisStatus.checking = false
})
},
/** Tab 切换 */ /** Tab 切换 */
handleTabClick(tab) { handleTabClick(tab) {
if (tab.name === 'dailyTrade') { if (tab.name === 'dailyTrade') {
@ -451,6 +491,8 @@ export default {
}).then(() => { }).then(() => {
stockdataApi.analysis({ tradeDate: this.dailyTradeQuery.tradeDate }).then(response => { stockdataApi.analysis({ tradeDate: this.dailyTradeQuery.tradeDate }).then(response => {
this.$message.success(response.msg || '分析完成') this.$message.success(response.msg || '分析完成')
//
this.analysisStatus.isAnalyzed = true
// //
this.getDailyTradeList() this.getDailyTradeList()
}).catch(error => { }).catch(error => {
@ -670,6 +712,8 @@ export default {
this.getStockBasicList() this.getStockBasicList()
} else if (this.upload.type === 'stockDailyTrade') { } else if (this.upload.type === 'stockDailyTrade') {
this.getDailyTradeList() this.getDailyTradeList()
//
this.checkAnalysisStatus(this.dailyTradeQuery.tradeDate)
} else if (this.upload.type === 'stockHighLow') { } else if (this.upload.type === 'stockHighLow') {
this.getStockHighLowList() this.getStockHighLowList()
} }

Loading…
Cancel
Save