Commit 38646681 authored by liucx's avatar liucx

优化 只能新4个字段

parent 1cb1a151
......@@ -129,6 +129,7 @@ public interface AssetStockPositionService {
AssetMarketDetailsVO createMarketDetailsVO(MemberBase memberBase, List<AssetStockPosition> stockPositions, BigDecimal funding, AssetAccountProductRelation accountProductRelation, Long marketId);
AssetMarketDetailsVO createMarketDetailsVOTask( List<AssetStockPosition> stockPositions, BigDecimal funding, AssetAccountProductRelation accountProductRelation);
AssetStockVO createStockVO(AssetStockPosition stockPosition, Map<String, Quote> codeAndQuoteMapping);
......
......@@ -1362,6 +1362,32 @@ public class AssetStockPositionServiceImpl extends ServiceImpl<AssetStockPositio
return marketDetailsVO;
}
@Override
public AssetMarketDetailsVO createMarketDetailsVOTask( List<AssetStockPosition> stockPositions, BigDecimal funding, AssetAccountProductRelation accountProductRelation) {
AssetMarketDetailsVO marketDetailsVO = new AssetMarketDetailsVO();
List<String> codes = stockPositions.stream().map(AssetStockPosition::getCode).collect(Collectors.toList());
//批量获取股票当前价格
Map<String, Quote> codeAndPriceMapping = stockCodeService.batchQueryStockPrice(codes);
//计算股票总市值(当前)
BigDecimal stocksTotalPrice = assetFinanceCalculateService.calculateTotalAssets(stockPositions, codeAndPriceMapping);
//计算总值
BigDecimal totalPrice = BigDecimalUtil.add(funding, stocksTotalPrice);
//计算仓位
BigDecimal position = BigDecimalUtil.div(stocksTotalPrice, totalPrice);
//盈亏比例
BigDecimal totalProfitRate = assetFinanceCalculateService.calculateProfitRate(totalPrice, accountProductRelation.getInitialFunding());
//总盈亏(股票当前市值和成本总值的差值)
BigDecimal totalProfit = assetFinanceCalculateService.calculateProfit(totalPrice, accountProductRelation.getInitialFunding());
marketDetailsVO.setPosition(position.toPlainString());
marketDetailsVO.setTotalPrice(totalPrice.toPlainString());
marketDetailsVO.setTotalProfit(totalProfit.toPlainString());
marketDetailsVO.setTotalProfitRate(totalProfitRate.toPlainString());
return marketDetailsVO;
}
@Override
public List<AssetStockPosition> getCode(Long id) {
LambdaQueryWrapper<AssetStockPosition> queryWrapper = Wrappers.lambdaQuery();
......
......@@ -148,34 +148,33 @@ public class AssetStockPriceTask implements ApplicationRunner {
String type = SIMULATED.getCode();
OptionalUtil.checkNull(accountProductRelation, "当前用户产品关系不存在");
//查询客户信息
Long customerId = accountProductRelation.getCustomerId();
MemberBase memberBase = memberBaseService.queryUsMemberBaseById(customerId);
Long marketId = accountProductRelation.getSimulatedMarketId();
OptionalUtil.checkNull(memberBase, "查询用户数据不存在");
//查询持仓信息
BigDecimal funding = null;
//获取可用资金
if (REAL.getCode().equals(type)) {
funding = accountProductRelation.getRealFunding();
return;
}
if (SIMULATED.getCode().equals(type)) {
funding = accountProductRelation.getSimulatedFunding();
}
AssetAccountProductRelation productRelation = new AssetAccountProductRelation();
productRelation.setId(accountProductRelation.getId());
//获取所有买入过的股票
List<AssetStockPosition> stockPositions = stockPositionService.queryStockPositions(marketId);
//汇总数据
AssetMarketDetailsVO marketDetailsVO = stockPositionService.createMarketDetailsVO(memberBase, stockPositions, funding, accountProductRelation, marketId);
AssetMarketDetailsVO marketDetailsVO = stockPositionService.createMarketDetailsVOTask( stockPositions, funding, accountProductRelation);
//示范盈亏比例
accountProductRelation.setSimulatedTotalProfit(new BigDecimal(marketDetailsVO.getTotalProfitRate()));
productRelation.setSimulatedTotalProfit(new BigDecimal(marketDetailsVO.getTotalProfitRate()));
//示范盘总资产
accountProductRelation.setSimulatedTotalPrice(new BigDecimal(marketDetailsVO.getTotalPrice()));
productRelation.setSimulatedTotalPrice(new BigDecimal(marketDetailsVO.getTotalPrice()));
//示范持仓比
accountProductRelation.setSimulatedProportion(new BigDecimal(marketDetailsVO.getPosition()));
productRelation.setSimulatedProportion(new BigDecimal(marketDetailsVO.getPosition()));
//示范盘持仓数量
accountProductRelation.setPositionCount(ObjectUtils.isEmpty(stockPositions.size()) ? 0 : stockPositions.size());
productRelation.setPositionCount(ObjectUtils.isEmpty(stockPositions.size()) ? 0 : stockPositions.size());
//示范盘盈亏金额
accountProductRelation.setProfitAmount(new BigDecimal(marketDetailsVO.getTotalProfit()));
accountProductRelationService.updateAccountProductRelation(accountProductRelation);
productRelation.setProfitAmount(new BigDecimal(marketDetailsVO.getTotalProfit()));
accountProductRelationService.updateAccountProductRelation(productRelation);
}
......
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