Commit e8f77a13 authored by liucx's avatar liucx

定时任务

parent 8c0d3919
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -5,7 +5,10 @@ ...@@ -5,7 +5,10 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="87728678-ea41-4406-bbc7-9c6c6813eb7d" name="Default Changelist" comment="上传"> <list default="true" id="87728678-ea41-4406-bbc7-9c6c6813eb7d" name="Default Changelist" comment="上传">
<change afterPath="$PROJECT_DIR$/src/main/java/com/zfxftech/telmarket/task/followAccount/StockPriceTask.java" afterDir="false" /> <change afterPath="$PROJECT_DIR$/src/main/java/com/zfxftech/telmarket/task/followAccount/AssetStockPriceTask.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/com/zfxftech/telmarket/task/followAccount/SmartStockPriceTask.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/sonarlint/issuestore/index.pb" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/sonarlint/issuestore/index.pb" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
...@@ -48,21 +51,18 @@ ...@@ -48,21 +51,18 @@
<property name="SONARLINT_PRECOMMIT_ANALYSIS" value="true" /> <property name="SONARLINT_PRECOMMIT_ANALYSIS" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" /> <property name="WebServerToolWindowFactoryState" value="false" />
<property name="aspect.path.notification.shown" value="true" /> <property name="aspect.path.notification.shown" value="true" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/src/main/java/com/zfxftech/telmarket/task/followAccount" /> <property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="settings.editor.selected.configurable" value="MavenSettings" /> <property name="settings.editor.selected.configurable" value="MavenSettings" />
</component> </component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="D:\stockPricetask\stockpricetack\src\main\java\com\zfxftech\telmarket\task\followAccount" />
</key>
<key name="CopyClassDialog.RECENTS_KEY">
<recent name="com.zfxftech.telmarket.task.followAccount" />
</key>
</component>
<component name="RunManager"> <component name="RunManager">
<configuration default="true" type="ArquillianJUnit" factoryName="" nameIsGenerated="true">
<option name="arquillianRunConfiguration">
<value>
<option name="containerStateName" value="" />
</value>
</option>
<option name="TEST_OBJECT" value="class" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="NewInvestApplication" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot"> <configuration name="NewInvestApplication" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot">
<module name="invest" /> <module name="invest" />
<option name="SPRING_BOOT_MAIN_CLASS" value="com.zfxftech.telmarket.NewInvestApplication" /> <option name="SPRING_BOOT_MAIN_CLASS" value="com.zfxftech.telmarket.NewInvestApplication" />
...@@ -82,7 +82,9 @@ ...@@ -82,7 +82,9 @@
<option name="number" value="Default" /> <option name="number" value="Default" />
<option name="presentableId" value="Default" /> <option name="presentableId" value="Default" />
<updated>1653440926847</updated> <updated>1653440926847</updated>
<workItem from="1653440928814" duration="837000" /> <workItem from="1653440928814" duration="874000" />
<workItem from="1653466009407" duration="206000" />
<workItem from="1653471319452" duration="879000" />
</task> </task>
<task id="LOCAL-00001" summary="上传"> <task id="LOCAL-00001" summary="上传">
<created>1653440999839</created> <created>1653440999839</created>
...@@ -98,7 +100,14 @@ ...@@ -98,7 +100,14 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1653441464906</updated> <updated>1653441464906</updated>
</task> </task>
<option name="localTasksCounter" value="3" /> <task id="LOCAL-00003" summary="上传">
<created>1653441806141</created>
<option name="number" value="00003" />
<option name="presentableId" value="LOCAL-00003" />
<option name="project" value="LOCAL" />
<updated>1653441806141</updated>
</task>
<option name="localTasksCounter" value="4" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
...@@ -114,6 +123,7 @@ ...@@ -114,6 +123,7 @@
</entry> </entry>
</map> </map>
</option> </option>
<option name="oldMeFiltersMigrated" value="true" />
</component> </component>
<component name="VcsManagerConfiguration"> <component name="VcsManagerConfiguration">
<option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" /> <option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" />
......
...@@ -118,4 +118,28 @@ public class AssetAccountProductRelation { ...@@ -118,4 +118,28 @@ public class AssetAccountProductRelation {
*/ */
private String remark; private String remark;
/**
* 示范总资产
*/
private BigDecimal simulatedTotalPrice;
/**
* 示范盈亏比例
*/
private BigDecimal simulatedTotalProfit;
/**
* 示范持仓比
*/
private BigDecimal simulatedProportion;
/**
* 示范盘盈亏金额
*/
private BigDecimal profitAmount;
/**
* 示范盘持仓数量
*/
private int positionCount;
} }
\ No newline at end of file
...@@ -118,4 +118,26 @@ public class SmartAccountProductRelation { ...@@ -118,4 +118,26 @@ public class SmartAccountProductRelation {
*/ */
private String remark; private String remark;
/**
* 示范总资产
*/
private BigDecimal simulatedTotalPrice;
/**
* 示范盈亏比例
*/
private BigDecimal simulatedTotalProfit;
/**
* 示范持仓比
*/
private BigDecimal simulatedProportion;
/**
* 示范盘盈亏金额
*/
private BigDecimal profitAmount;
/**
* 示范盘持仓数量
*/
private int positionCount;
} }
\ No newline at end of file
package com.zfxftech.telmarket.task.followAccount;
import com.zfxftech.telmarket.common.config.CommonConfig;
import com.zfxftech.telmarket.common.pojo.dao.AccountProductRelation;
import com.zfxftech.telmarket.common.pojo.dao.MemberBase;
import com.zfxftech.telmarket.common.pojo.dao.StockPosition;
import com.zfxftech.telmarket.common.pojo.dao.asset.AssetAccountProductRelation;
import com.zfxftech.telmarket.common.pojo.dao.asset.AssetStockPosition;
import com.zfxftech.telmarket.common.pojo.vo.MarketDetailsVO;
import com.zfxftech.telmarket.common.pojo.vo.asset.AssetMarketDetailsVO;
import com.zfxftech.telmarket.common.util.DateUtil;
import com.zfxftech.telmarket.common.util.OptionalUtil;
import com.zfxftech.telmarket.service.business.*;
import com.zfxftech.telmarket.service.business.asset.AssetAccountProductRelationService;
import com.zfxftech.telmarket.service.business.asset.AssetStockPositionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicReference;
import static com.zfxftech.telmarket.common.constant.AdminConstant.MarketTypeEnum.REAL;
import static com.zfxftech.telmarket.common.constant.AdminConstant.MarketTypeEnum.SIMULATED;
/**
* Create time: 2022/1/26
*/
@Slf4j
@Component
@Order(value = 1)
/**
* 资管计算总市值、股票市值、持仓数量
*/
public class AssetStockPriceTask implements ApplicationRunner {
@Autowired
private AssetAccountProductRelationService accountProductRelationService;
@Autowired
private AssetStockPositionService stockPositionService;
@Autowired
private CommonConfig commonConfig;
@Autowired
private UsMemberBaseService memberBaseService;
@Override
public void run(ApplicationArguments args) throws Exception {
log.info("私人定制计算股票统计日志开始");
//log.info("私人定制计算股票统计日志开始配置更新开关状态:" + commonConfig.getStockPriceTask());
//if (commonConfig.getStockPriceTask() != null && commonConfig.getStockPriceTask().equals("run")) {
if (true) {
//分页查询异动配置列表
ExecutorService PersonalexecutorService = Executors.newSingleThreadExecutor();
ExecutorService executorServicePersonal = Executors.newFixedThreadPool(100);
CompletableFuture.runAsync(() -> {
while (true) {
// if (DateUtil.isTradeDayForChangeRemind()) {
if (true) {
AtomicReference<Integer> pageNo = new AtomicReference<>(1);
Integer pageSize = 100;
Date startTime = new Date();
List<CompletableFuture<String>> futureList = new ArrayList<>();
List<AssetAccountProductRelation> accountProductRelations = accountProductRelationService.queryAll();
if (!ObjectUtils.isEmpty(accountProductRelations) && accountProductRelations.size() > 0) {
log.info("私人定制计算股票统计数据大小:{}", accountProductRelations.size());
Integer pageTOtl = accountProductRelations.size() % pageSize == 0 ? accountProductRelations.size() / pageSize : accountProductRelations.size() / pageSize + 1;
for (Integer i = 0; i < pageTOtl; i++) {
List<AssetAccountProductRelation> accountProductRelationList = this.page(accountProductRelations, pageNo.get(), pageSize);
CompletableFuture cf = CompletableFuture.supplyAsync(() -> {
for (AssetAccountProductRelation accountProductRelation : accountProductRelationList) {
this.AccountProductRelationTask(accountProductRelation);
}
return " ";
}, executorServicePersonal).handle((result, ex) -> {
if (null != ex) {
log.error("资管错误消息:{}", ex);
return 0;
} else {
return result;
}
});
futureList.add(cf);
pageNo.set(pageNo.get() + 1);
}
}
try {
CompletableFuture<Void> combinedFuture = CompletableFuture.allOf(futureList.toArray(new CompletableFuture[0]));
combinedFuture.get();
log.info("持仓统计--------主线程开始阻塞,消息发送完成--------");
log.info("持仓统计,本次共计算" + (ObjectUtils.isEmpty(accountProductRelations) == true ? 0 : accountProductRelations.size()) + "持仓统计。耗时" + DateUtil.calculateTimeGapSecond(startTime, new Date()) + "秒");
} catch (Exception e) {
log.error("持仓统计错误信息:{}", e);
e.printStackTrace();
}
try {
Thread.sleep(20000);
} catch (Exception e) {
e.printStackTrace();
}
} else {
try {
Thread.sleep(8000);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}, PersonalexecutorService);
}
}
public List<AssetAccountProductRelation> page(List<AssetAccountProductRelation> list, Integer pageNo, Integer pageSize) {
if (CollectionUtils.isEmpty(list)) {
return list;
}
List<AssetAccountProductRelation> resultList = new ArrayList();
// 所有dataList数据中的第几条
int currIdx = pageNo > 1 ? (pageNo - 1) * pageSize : 0;
for (int i = 0; i < pageSize && i < list.size() - currIdx; i++) {
resultList.add(list.get(currIdx + i));
}
return resultList;
}
//私人定制
public void AccountProductRelationTask(AssetAccountProductRelation accountProductRelation) {
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();
}
if (SIMULATED.getCode().equals(type)) {
funding = accountProductRelation.getSimulatedFunding();
}
//获取所有买入过的股票
List<AssetStockPosition> stockPositions = stockPositionService.queryStockPositions(marketId);
//汇总数据
AssetMarketDetailsVO marketDetailsVO = stockPositionService.createMarketDetailsVO(memberBase, stockPositions, funding, accountProductRelation, marketId);
//示范盈亏比例
accountProductRelation.setSimulatedTotalProfit(new BigDecimal(marketDetailsVO.getTotalProfitRate()));
//示范盘总资产
accountProductRelation.setSimulatedTotalPrice(new BigDecimal(marketDetailsVO.getTotalPrice()));
//示范持仓比
accountProductRelation.setSimulatedProportion(new BigDecimal(marketDetailsVO.getPosition()));
//示范盘持仓数量
accountProductRelation.setPositionCount(ObjectUtils.isEmpty(stockPositions.size()) ? 0 : stockPositions.size());
//示范盘盈亏金额
accountProductRelation.setProfitAmount(new BigDecimal(marketDetailsVO.getTotalProfit()));
accountProductRelationService.updateAccountProductRelation(accountProductRelation);
}
}
package com.zfxftech.telmarket.task.followAccount;
import com.zfxftech.telmarket.common.config.CommonConfig;
import com.zfxftech.telmarket.common.pojo.dao.AccountProductRelation;
import com.zfxftech.telmarket.common.pojo.dao.MemberBase;
import com.zfxftech.telmarket.common.pojo.dao.StockPosition;
import com.zfxftech.telmarket.common.pojo.dao.smart.SmartAccountProductRelation;
import com.zfxftech.telmarket.common.pojo.dao.smart.SmartStockPosition;
import com.zfxftech.telmarket.common.pojo.vo.MarketDetailsVO;
import com.zfxftech.telmarket.common.pojo.vo.smart.SmartMarketDetailsVO;
import com.zfxftech.telmarket.common.util.DateUtil;
import com.zfxftech.telmarket.common.util.OptionalUtil;
import com.zfxftech.telmarket.service.business.*;
import com.zfxftech.telmarket.service.business.smart.SmartAccountProductRelationService;
import com.zfxftech.telmarket.service.business.smart.SmartStockPositionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicReference;
import static com.zfxftech.telmarket.common.constant.AdminConstant.MarketTypeEnum.REAL;
import static com.zfxftech.telmarket.common.constant.AdminConstant.MarketTypeEnum.SIMULATED;
/**
* Create time: 2022/1/26
*/
@Slf4j
@Component
@Order(value = 1)
/**
* 智能跟投计算总市值、股票市值、持仓数量
*/
public class SmartStockPriceTask implements ApplicationRunner {
@Autowired
private SmartAccountProductRelationService accountProductRelationService;
@Autowired
private SmartStockPositionService stockPositionService;
@Autowired
private StockCodeService stockCodeService;
@Autowired
private CommonConfig commonConfig;
@Autowired
private UsMemberBaseService memberBaseService;
@Override
public void run(ApplicationArguments args) throws Exception {
log.info("私人定制计算股票统计日志开始");
//log.info("私人定制计算股票统计日志开始配置更新开关状态:" + commonConfig.getStockPriceTask());
//if (commonConfig.getStockPriceTask() != null && commonConfig.getStockPriceTask().equals("run")) {
if (true) {
//分页查询异动配置列表
ExecutorService PersonalexecutorService = Executors.newSingleThreadExecutor();
ExecutorService executorServicePersonal = Executors.newFixedThreadPool(100);
CompletableFuture.runAsync(() -> {
while (true) {
// if (DateUtil.isTradeDayForChangeRemind()) {
if (true) {
AtomicReference<Integer> pageNo = new AtomicReference<>(1);
Integer pageSize = 100;
Date startTime = new Date();
List<CompletableFuture<String>> futureList = new ArrayList<>();
List<SmartAccountProductRelation> accountProductRelations = accountProductRelationService.queryAll();
if (!ObjectUtils.isEmpty(accountProductRelations) && accountProductRelations.size() > 0) {
log.info("私人定制计算股票统计数据大小:{}", accountProductRelations.size());
Integer pageTOtl = accountProductRelations.size() % pageSize == 0 ? accountProductRelations.size() / pageSize : accountProductRelations.size() / pageSize + 1;
for (Integer i = 0; i < pageTOtl; i++) {
List<SmartAccountProductRelation> accountProductRelationList = this.page(accountProductRelations, pageNo.get(), pageSize);
CompletableFuture cf = CompletableFuture.supplyAsync(() -> {
for (SmartAccountProductRelation accountProductRelation : accountProductRelationList) {
this.AccountProductRelationTask(accountProductRelation);
}
return " ";
}, executorServicePersonal).handle((result, ex) -> {
if (null != ex) {
log.error("资管错误消息:{}", ex);
return 0;
} else {
return result;
}
});
futureList.add(cf);
pageNo.set(pageNo.get() + 1);
}
}
try {
CompletableFuture<Void> combinedFuture = CompletableFuture.allOf(futureList.toArray(new CompletableFuture[0]));
combinedFuture.get();
log.info("持仓统计--------主线程开始阻塞,消息发送完成--------");
log.info("持仓统计,本次共计算" + (ObjectUtils.isEmpty(accountProductRelations) == true ? 0 : accountProductRelations.size()) + "持仓统计。耗时" + DateUtil.calculateTimeGapSecond(startTime, new Date()) + "秒");
} catch (Exception e) {
log.error("持仓统计错误信息:{}", e);
e.printStackTrace();
}
try {
Thread.sleep(20000);
} catch (Exception e) {
e.printStackTrace();
}
} else {
try {
Thread.sleep(8000);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}, PersonalexecutorService);
}
}
public List<SmartAccountProductRelation> page(List<SmartAccountProductRelation> list, Integer pageNo, Integer pageSize) {
if (CollectionUtils.isEmpty(list)) {
return list;
}
List<SmartAccountProductRelation> resultList = new ArrayList();
// 所有dataList数据中的第几条
int currIdx = pageNo > 1 ? (pageNo - 1) * pageSize : 0;
for (int i = 0; i < pageSize && i < list.size() - currIdx; i++) {
resultList.add(list.get(currIdx + i));
}
return resultList;
}
//私人定制
public void AccountProductRelationTask(SmartAccountProductRelation accountProductRelation) {
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();
}
if (SIMULATED.getCode().equals(type)) {
funding = accountProductRelation.getSimulatedFunding();
}
//获取所有买入过的股票
List<SmartStockPosition> stockPositions = stockPositionService.queryStockPositions(marketId);
//汇总数据
SmartMarketDetailsVO marketDetailsVO = stockPositionService.createMarketDetailsVO(memberBase, stockPositions, funding, accountProductRelation, marketId);
//示范盈亏比例
accountProductRelation.setSimulatedTotalProfit(new BigDecimal(marketDetailsVO.getTotalProfitRate()));
//示范盘总资产
accountProductRelation.setSimulatedTotalPrice(new BigDecimal(marketDetailsVO.getTotalPrice()));
//示范持仓比
accountProductRelation.setSimulatedProportion(new BigDecimal(marketDetailsVO.getPosition()));
//示范盘持仓数量
accountProductRelation.setPositionCount(ObjectUtils.isEmpty(stockPositions.size()) ? 0 : stockPositions.size());
//示范盘盈亏金额
accountProductRelation.setProfitAmount(new BigDecimal(marketDetailsVO.getTotalProfit()));
accountProductRelationService.updateAccountProductRelation(accountProductRelation);
}
}
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