Commit 8f7d9b9b authored by 刘长帅's avatar 刘长帅

1458-删除无用方法

parent d482c293
...@@ -13,10 +13,7 @@ import java.util.List; ...@@ -13,10 +13,7 @@ import java.util.List;
*/ */
public interface AssetMarketProfitLogService extends IService<AssetMarketProfitLog> { public interface AssetMarketProfitLogService extends IService<AssetMarketProfitLog> {
/**
* 计算当日收益记录了
*/
void generateTodayMarketProfitLog();
/** /**
* 查询收益 * 查询收益
......
package com.zfxftech.telmarket.service.impl.business.asset; package com.zfxftech.telmarket.service.impl.business.asset;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zfxftech.telmarket.common.excepitonHandler.ApiException;
import com.zfxftech.telmarket.common.pojo.dao.Quote;
import com.zfxftech.telmarket.common.pojo.dao.asset.AssetAccountProductRelation;
import com.zfxftech.telmarket.common.pojo.dao.asset.AssetMarketProfitLog; import com.zfxftech.telmarket.common.pojo.dao.asset.AssetMarketProfitLog;
import com.zfxftech.telmarket.common.pojo.dao.asset.AssetStockPosition;
import com.zfxftech.telmarket.common.pojo.request.asset.AssetQueryIncomeBO; import com.zfxftech.telmarket.common.pojo.request.asset.AssetQueryIncomeBO;
import com.zfxftech.telmarket.common.util.DateUtil;
import com.zfxftech.telmarket.mapper.business.asset.AssetMarketProfitLogMapper; import com.zfxftech.telmarket.mapper.business.asset.AssetMarketProfitLogMapper;
import com.zfxftech.telmarket.service.business.StockCodeService;
import com.zfxftech.telmarket.service.business.WorkDayService;
import com.zfxftech.telmarket.service.business.asset.AssetAccountProductRelationService;
import com.zfxftech.telmarket.service.business.asset.AssetFinanceCalculateService;
import com.zfxftech.telmarket.service.business.asset.AssetMarketProfitLogService; import com.zfxftech.telmarket.service.business.asset.AssetMarketProfitLogService;
import com.zfxftech.telmarket.service.business.asset.AssetStockPositionService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.*; import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import static com.zfxftech.telmarket.common.constant.AdminConstant.NumberEnum.ZERO;
/** /**
* @Description TODO * @Description TODO
...@@ -39,85 +20,6 @@ import static com.zfxftech.telmarket.common.constant.AdminConstant.NumberEnum.ZE ...@@ -39,85 +20,6 @@ import static com.zfxftech.telmarket.common.constant.AdminConstant.NumberEnum.ZE
@Service @Service
public class AssetMarketProfitLogServiceImpl extends ServiceImpl<AssetMarketProfitLogMapper, AssetMarketProfitLog> implements AssetMarketProfitLogService { public class AssetMarketProfitLogServiceImpl extends ServiceImpl<AssetMarketProfitLogMapper, AssetMarketProfitLog> implements AssetMarketProfitLogService {
@Autowired
private StringRedisTemplate redisTemplate;
@Autowired
private AssetStockPositionService stockPositionService;
@Autowired
private AssetAccountProductRelationService accountProductRelationService;
@Autowired
private AssetFinanceCalculateService financeCalculateService;
@Autowired
private WorkDayService workDayService;
@Autowired
private StockCodeService stockCodeService;
@Transactional(propagation = Propagation.REQUIRED)
@Override
public void generateTodayMarketProfitLog() {
//判断是否是交易日
if (!DateUtil.isTradeDaysnapshoot()){
return;
}
//获取所有的持仓情况
List<AssetStockPosition> stockPositions = stockPositionService.getAll();
Map<Long, List<AssetStockPosition>> marketIdAndStockPositionsMapping = new HashMap<>();
for (AssetStockPosition stockPosition : stockPositions) {
Long marketId = stockPosition.getMarketId();
if (marketIdAndStockPositionsMapping.containsKey(marketId)) {
List<AssetStockPosition> temStockPositions = marketIdAndStockPositionsMapping.get(marketId);
temStockPositions.add(stockPosition);
} else {
List<AssetStockPosition> stockPositionList = new ArrayList<>();
stockPositionList.add(stockPosition);
marketIdAndStockPositionsMapping.put(marketId, stockPositionList);
}
}
//获取所有的可用余额
List<AssetAccountProductRelation> accountProductRelations = accountProductRelationService.queryAll();
Map<Long, BigDecimal> marketIdAndAvailableMapping = new HashMap<>();
Map<Long, BigDecimal> marketIdAndInitialMapping = new HashMap<>();
for (AssetAccountProductRelation accountProductRelation : accountProductRelations) {
BigDecimal initialFunding = accountProductRelation.getInitialFunding();
marketIdAndAvailableMapping.put(accountProductRelation.getRealMarketId(), accountProductRelation.getRealFunding());
marketIdAndAvailableMapping.put(accountProductRelation.getSimulatedMarketId(), accountProductRelation.getSimulatedFunding());
marketIdAndInitialMapping.put(accountProductRelation.getRealMarketId(), initialFunding);
marketIdAndInitialMapping.put(accountProductRelation.getSimulatedMarketId(), initialFunding);
}
Map<String, Quote> codeAndQuoteMapping = getCodeAndQuoteMapping();
//获取昨日的记录
String yesterday = DateUtil.getDateByStep(-1);
List<AssetMarketProfitLog> marketProfitLogs = queryMarketProfitLogsByDate(yesterday);
Map<Long, AssetMarketProfitLog> yesterdayMarketIdAndMarketProfitLogsMapping = marketProfitLogs.stream().collect(Collectors.toMap(AssetMarketProfitLog::getMarketId, Function.identity(), (key1, key2) -> key2));
//进行加法计算,然后持久化到数据库
List<AssetMarketProfitLog> marketProfitLogList = new ArrayList<>();
for (Long marketId : marketIdAndAvailableMapping.keySet()) {
try{
//可用金额
BigDecimal funding = marketIdAndAvailableMapping.get(marketId);
//初始金额
BigDecimal initial = marketIdAndInitialMapping.get(marketId);
List<AssetStockPosition> temStockPositions = marketIdAndStockPositionsMapping.get(marketId);
//总资产
BigDecimal totalPrice = financeCalculateService.calculateTotalAssets(funding, temStockPositions, codeAndQuoteMapping);
//总盈亏
// BigDecimal profit = BigDecimalUtil.sub(totalPrice, initial);
//获取昨日的
AssetMarketProfitLog yesterdayMarketProfitLog = yesterdayMarketIdAndMarketProfitLogsMapping.get(marketId);
AssetMarketProfitLog marketProfitLog = createMarketProfitLog(totalPrice, initial, marketId, yesterdayMarketProfitLog);
marketProfitLogList.add(marketProfitLog);
}catch (Exception e){
log.error("生成所有示范盘当天收益快照 出错marketId="+String.valueOf(marketId)+"error={}",e);
}
}
//批量插入数据库
if (!CollectionUtils.isEmpty(marketProfitLogList)) {
saveBatch(marketProfitLogList);
}
}
@Transactional(propagation = Propagation.SUPPORTS) @Transactional(propagation = Propagation.SUPPORTS)
@Override @Override
...@@ -134,58 +36,6 @@ public class AssetMarketProfitLogServiceImpl extends ServiceImpl<AssetMarketProf ...@@ -134,58 +36,6 @@ public class AssetMarketProfitLogServiceImpl extends ServiceImpl<AssetMarketProf
return queryWrapper; return queryWrapper;
} }
private AssetMarketProfitLog createMarketProfitLog(BigDecimal profit, BigDecimal principal, Long marketId, AssetMarketProfitLog yesterdayMarketProfitLog) {
AssetMarketProfitLog marketProfitLog = new AssetMarketProfitLog();
marketProfitLog.setPrincipal(principal);
marketProfitLog.setProfit(profit);
marketProfitLog.setMarketId(marketId);
marketProfitLog.setDate(new Date());
if (yesterdayMarketProfitLog != null) {
//昨天的收益
BigDecimal yesterdayProfit = yesterdayMarketProfitLog.getProfit();
//盈亏比例 收益/初始本值
BigDecimal profitRate = financeCalculateService.calculateProfitRate(profit, principal);
//较上一日增量收益
BigDecimal incrementProfit = financeCalculateService.calculateProfit(profit, yesterdayProfit);
marketProfitLog.setIncrementProfit(incrementProfit);
marketProfitLog.setProfitRate(profitRate);
} else {
marketProfitLog.setIncrementProfit(new BigDecimal(ZERO.getCode()));
marketProfitLog.setProfitRate(new BigDecimal(ZERO.getCode()));
}
return marketProfitLog;
}
private Map<String, Quote> getCodeAndQuoteMapping() {
Map<String, Quote> codeAndQuoteMapping = new HashMap<>();
//获取所有股票的收盘价
String pattern = "quote:realtime:*";
//获取所有的key
Set<String> keys = redisTemplate.keys(pattern);
if (CollectionUtils.isEmpty(keys)) {
throw new ApiException("行情数据异常");
}
for (String key : keys) {
String code = key.substring(key.lastIndexOf(":") + 1);
try{
Quote quote = stockCodeService.queryStockPrice(code);
quote.setCode(code);
codeAndQuoteMapping.put(quote.getCode(), quote);
}catch (Exception e){
log.error(JSON.toJSONString(e));
}
}
return codeAndQuoteMapping;
}
//获取指定日志的统计数据
public List<AssetMarketProfitLog> queryMarketProfitLogsByDate(String date) {
//获取所有的数据
QueryWrapper<AssetMarketProfitLog> queryWrapper = new QueryWrapper();
queryWrapper.eq("date", date);
return list(queryWrapper);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment