|
|
|
@ -4,6 +4,7 @@ import cn.hutool.core.util.IdUtil;
|
|
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
|
|
import com.sztzjy.forex.trading_trading.config.websocket.WebSocket;
|
|
|
|
|
import com.sztzjy.forex.trading_trading.controller.TradingController;
|
|
|
|
|
import com.sztzjy.forex.trading_trading.entity.*;
|
|
|
|
|
import com.sztzjy.forex.trading_trading.mappers.*;
|
|
|
|
|
import com.sztzjy.forex.trading_trading.util.ForexMarketDateUtil;
|
|
|
|
@ -43,16 +44,19 @@ public class WainingService {
|
|
|
|
|
@Autowired
|
|
|
|
|
private TransactionNumberWarningRecordMapper transactionNumberWarningRecordMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
private WebSocket webSocket;
|
|
|
|
|
private TrainingMapper trainingMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
private MemberService memberService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//保证金比较接口
|
|
|
|
|
public String compareMarginLevels(String memberId, String trainingId) {
|
|
|
|
|
public void compareMarginLevels(String memberId, String trainingId) {
|
|
|
|
|
String message = "保证金已到达预警水平!";
|
|
|
|
|
MemberExample memberExample = new MemberExample();
|
|
|
|
|
memberExample.createCriteria().andMemberIdEqualTo(memberId).andTrainingIdEqualTo(trainingId);
|
|
|
|
|
List<Member> members = memberMapper.selectByExample(memberExample);
|
|
|
|
|
MarginWarningExample marginWarningExample = new MarginWarningExample();
|
|
|
|
|
marginWarningExample.createCriteria().andMemberIdEqualTo(memberId);
|
|
|
|
|
marginWarningExample.createCriteria().andMemberIdEqualTo(memberId).andStatusEqualTo(1);
|
|
|
|
|
MarginWarningRecordExample mwre = new MarginWarningRecordExample();
|
|
|
|
|
List<MarginWarning> marginWarningList = marginWarningMapper.selectByExample(marginWarningExample);
|
|
|
|
|
for (MarginWarning marginWarning : marginWarningList) {
|
|
|
|
@ -73,7 +77,6 @@ public class WainingService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return message;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//保证金预警查询
|
|
|
|
@ -94,18 +97,23 @@ public class WainingService {
|
|
|
|
|
MemberExample memberExample = new MemberExample();
|
|
|
|
|
memberExample.createCriteria().andTrainingIdEqualTo(trainingId).andNameEqualTo(userName);
|
|
|
|
|
List<Member> members = memberMapper.selectByExample(memberExample);
|
|
|
|
|
// Double positionProfitLoss = takeStashController.getPositionProfitLoss(memberId); //获取持仓盈亏
|
|
|
|
|
for (Member member : members) {
|
|
|
|
|
marginWarning.setAccount(userName);
|
|
|
|
|
BeanUtils.copyProperties(member, marginWarning);
|
|
|
|
|
marginWarning.setStatus(0);
|
|
|
|
|
marginWarning.setId(IdUtil.simpleUUID());
|
|
|
|
|
marginWarning.setMarginLevel(50.12);
|
|
|
|
|
marginWarning.setNetValue(50.2131);
|
|
|
|
|
//这两个值需要写方法去取
|
|
|
|
|
//净值 = 持仓盈亏 + 累计盈亏 + 期初资金 保证金水平 = 净值/已用保证金 (%)
|
|
|
|
|
// Double marginLevel =
|
|
|
|
|
marginWarning.setMarginLevel(50.12); //保证金水平
|
|
|
|
|
marginWarning.setNetValue(50.2131); //净值
|
|
|
|
|
marginWarningMapper.insert(marginWarning);
|
|
|
|
|
}
|
|
|
|
|
return marginWarning;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//保证金预警水平修改保存
|
|
|
|
|
public MarginWarning saveWarningLevel(Integer warningLevel, String memberId, String userName, String trainingId) {
|
|
|
|
|
MarginWarningExample marginWarningExample = new MarginWarningExample();
|
|
|
|
@ -149,29 +157,34 @@ public class WainingService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 新增行情预警,并在达到预警值时将数据存入记录表
|
|
|
|
|
public void addMarketWarning(MarketWarning marketWarning, String trainingId, String name) {
|
|
|
|
|
// 记录表需要设置预警水平和预警时间 为报警时候的值
|
|
|
|
|
String marketWarningId = marketWarning.getId();
|
|
|
|
|
MarketWarningRecord marketWarningRecord = new MarketWarningRecord();
|
|
|
|
|
marketWarning.setTime(new Timestamp(new Date().getTime()));
|
|
|
|
|
marketWarning.setTariningid(trainingId);
|
|
|
|
|
marketWarning.setName(name);
|
|
|
|
|
marketWarningMapper.insert(marketWarning);
|
|
|
|
|
BeanUtils.copyProperties(marketWarning, marketWarningRecord);
|
|
|
|
|
marketWarningRecord.setMarketWarningId(marketWarningId);
|
|
|
|
|
marketWarningRecord.setId(IdUtil.simpleUUID());
|
|
|
|
|
marketWarningRecordMapper.insert(marketWarningRecord);
|
|
|
|
|
HashMap<String, Object> objectObjectHashMap = new HashMap<>();
|
|
|
|
|
objectObjectHashMap.put("marketWarningId", marketWarningId);
|
|
|
|
|
redisUtil.hmset("marketWarningRecord_" + marketWarningId + "_", objectObjectHashMap);
|
|
|
|
|
ComparativeTransactionPrice();
|
|
|
|
|
public void addMarketWarning(MarketWarning marketWarning) {
|
|
|
|
|
String trainingId = marketWarning.getTariningid();
|
|
|
|
|
Training training = trainingMapper.selectByPrimaryKey(trainingId);
|
|
|
|
|
if (training.getStatus().equals("ONGOING")) {
|
|
|
|
|
// 记录表需要设置预警水平和预警时间 为报警时候的值
|
|
|
|
|
String marketWarningId = IdUtil.simpleUUID();
|
|
|
|
|
marketWarning.setId(marketWarningId);
|
|
|
|
|
MarketWarningRecord marketWarningRecord = new MarketWarningRecord();
|
|
|
|
|
marketWarning.setTime(new Timestamp(new Date().getTime()));
|
|
|
|
|
marketWarningMapper.insert(marketWarning);
|
|
|
|
|
BeanUtils.copyProperties(marketWarning, marketWarningRecord);
|
|
|
|
|
marketWarningRecord.setMarketWarningId(marketWarningId);
|
|
|
|
|
marketWarningRecord.setId(IdUtil.simpleUUID());
|
|
|
|
|
marketWarningRecordMapper.insert(marketWarningRecord);
|
|
|
|
|
|
|
|
|
|
HashMap<String, Object> objectObjectHashMap = new HashMap<>();
|
|
|
|
|
objectObjectHashMap.put("marketWarningId", marketWarningId);
|
|
|
|
|
redisUtil.hmset("trainingId_" + trainingId + "_marketWarningRecord_" + marketWarningId + "_", objectObjectHashMap);
|
|
|
|
|
|
|
|
|
|
comparativeTransactionPrice();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//行情预警,监控用户设置的交易品种当前的交易价格,10S一次
|
|
|
|
|
@Scheduled(fixedRate = 10000)
|
|
|
|
|
public void ComparativeTransactionPrice() {
|
|
|
|
|
@Scheduled(fixedRate = 120000)
|
|
|
|
|
public void comparativeTransactionPrice() {
|
|
|
|
|
// 从redis取出所有的marketWarning
|
|
|
|
|
Set<String> marketWarningSet = redisUtil.keys("marketWarningRecord*");
|
|
|
|
|
Set<String> marketWarningSet = redisUtil.keys("*marketWarningRecord*");
|
|
|
|
|
// 从redis取出所有的交易品种的参数
|
|
|
|
|
List<ForexMarketData> forexDateList = redisUtil.get("ForexDateList");
|
|
|
|
|
Map<String, ForexMarketData> forexMarketDateMap = forexMarketDateUtil.getForexMarketDateMap(forexDateList);
|
|
|
|
@ -179,35 +192,38 @@ public class WainingService {
|
|
|
|
|
for (String key : marketWarningSet) {
|
|
|
|
|
Map<Object, Object> marketWarningMap = redisUtil.hmget(key);
|
|
|
|
|
String marketWarningId = (String) marketWarningMap.get("marketWarningId");
|
|
|
|
|
MarketWarningRecordExample marketWarningRecordExample = new MarketWarningRecordExample();
|
|
|
|
|
marketWarningRecordExample.createCriteria().andMarketWarningIdEqualTo(marketWarningId);
|
|
|
|
|
List<MarketWarningRecord> marketWarningRecords = marketWarningRecordMapper.selectByExample(marketWarningRecordExample);
|
|
|
|
|
for (MarketWarningRecord marketWarningRecord : marketWarningRecords) {
|
|
|
|
|
ForexMarketData forexMarketData = forexMarketDateMap.get(marketWarningRecord.getSymbol());
|
|
|
|
|
String sellPic = forexMarketData.getSellPic();
|
|
|
|
|
Double buyPic = forexMarketData.getBuyPic();
|
|
|
|
|
Double sellPicValue = Double.parseDouble(sellPic);
|
|
|
|
|
MarketWarning marketWarning = marketWarningMapper.selectByPrimaryKey(marketWarningId);
|
|
|
|
|
if (marketWarning != null && marketWarning.getStatus() != null && marketWarning.getStatus() == 1) {
|
|
|
|
|
MarketWarningRecordExample marketWarningRecordExample = new MarketWarningRecordExample();
|
|
|
|
|
marketWarningRecordExample.createCriteria().andMarketWarningIdEqualTo(marketWarningId);
|
|
|
|
|
List<MarketWarningRecord> marketWarningRecords = marketWarningRecordMapper.selectByExample(marketWarningRecordExample);
|
|
|
|
|
for (MarketWarningRecord marketWarningRecord : marketWarningRecords) {
|
|
|
|
|
ForexMarketData forexMarketData = forexMarketDateMap.get(marketWarningRecord.getSymbol());
|
|
|
|
|
String sellPic = forexMarketData.getSellPic();
|
|
|
|
|
Double buyPic = forexMarketData.getBuyPic();
|
|
|
|
|
Double sellPicValue = Double.parseDouble(sellPic);
|
|
|
|
|
// 2.判断新增的预警是买还是卖
|
|
|
|
|
Double upperBreakPrice = marketWarningRecord.getUpperBreakPrice();
|
|
|
|
|
Double lowerBreakPrice = marketWarningRecord.getLowerBreakPrice();
|
|
|
|
|
String direction = marketWarningRecord.getDirection();
|
|
|
|
|
String message = "预警通知:价格已达到预警值";
|
|
|
|
|
if (direction.equals("买")) {
|
|
|
|
|
Double upperBreakPrice = marketWarningRecord.getUpperBreakPrice();
|
|
|
|
|
Double lowerBreakPrice = marketWarningRecord.getLowerBreakPrice();
|
|
|
|
|
String direction = marketWarningRecord.getDirection();
|
|
|
|
|
String message = "预警通知:价格已达到预警值";
|
|
|
|
|
if (direction.equals("买入")) {
|
|
|
|
|
// 3.拿redis的价位和新增的高价低价做比较,==的时候就弹出提示,并且存入行情预警记录表
|
|
|
|
|
if (buyPic.equals(upperBreakPrice) || buyPic.equals(lowerBreakPrice)) {
|
|
|
|
|
WebSocket.sendMessage(message);
|
|
|
|
|
marketWarningRecord.setWarningPrice(buyPic);
|
|
|
|
|
marketWarningRecord.setWarningTime((new Timestamp(new Date().getTime())));
|
|
|
|
|
marketWarningRecordMapper.updateByPrimaryKeySelective(marketWarningRecord);
|
|
|
|
|
redisUtil.del(key);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (sellPicValue.equals(upperBreakPrice) || sellPicValue.equals(lowerBreakPrice)) {
|
|
|
|
|
WebSocket.sendMessage(message);
|
|
|
|
|
marketWarningRecord.setWarningPrice(sellPicValue);
|
|
|
|
|
marketWarningRecord.setWarningTime((new Timestamp(new Date().getTime())));
|
|
|
|
|
marketWarningRecordMapper.updateByPrimaryKeySelective(marketWarningRecord);
|
|
|
|
|
redisUtil.del(key);
|
|
|
|
|
if (buyPic >= upperBreakPrice || buyPic <= lowerBreakPrice) {
|
|
|
|
|
WebSocket.sendMessage(message);
|
|
|
|
|
marketWarningRecord.setWarningPrice(buyPic);
|
|
|
|
|
marketWarningRecord.setWarningTime((new Timestamp(new Date().getTime())));
|
|
|
|
|
marketWarningRecordMapper.updateByPrimaryKeySelective(marketWarningRecord);
|
|
|
|
|
redisUtil.del(key);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (sellPicValue >= upperBreakPrice || sellPicValue <= lowerBreakPrice) {
|
|
|
|
|
WebSocket.sendMessage(message);
|
|
|
|
|
marketWarningRecord.setWarningPrice(sellPicValue);
|
|
|
|
|
marketWarningRecord.setWarningTime((new Timestamp(new Date().getTime())));
|
|
|
|
|
marketWarningRecordMapper.updateByPrimaryKeySelective(marketWarningRecord);
|
|
|
|
|
redisUtil.del(key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -215,38 +231,45 @@ public class WainingService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//新增持仓时长预警
|
|
|
|
|
public void addAlertHoldDuration(AlertHoldDuration alertHoldDuration) {
|
|
|
|
|
public String addAlertHoldDuration(AlertHoldDuration alertHoldDuration) {
|
|
|
|
|
String trainingid = alertHoldDuration.getTrainingid();
|
|
|
|
|
String symbol = alertHoldDuration.getSymbol();
|
|
|
|
|
TakeStashExample takeStashExample = new TakeStashExample();
|
|
|
|
|
takeStashExample.createCriteria().andTradingCodeEqualTo(symbol);
|
|
|
|
|
takeStashExample.createCriteria().andTradingCodeEqualTo(symbol).andStatusEqualTo(0);
|
|
|
|
|
List<TakeStash> takeStashes = takeStashMapper.selectByExample(takeStashExample);
|
|
|
|
|
for (TakeStash takeStash : takeStashes) {
|
|
|
|
|
String stashId = takeStash.getStashId();
|
|
|
|
|
alertHoldDuration.setSetTime(new Timestamp(new Date().getTime()));
|
|
|
|
|
alertHoldDuration.setStashid(stashId);
|
|
|
|
|
alertHoldDurationMapper.insert(alertHoldDuration);
|
|
|
|
|
if (takeStashes != null) {
|
|
|
|
|
for (TakeStash takeStash : takeStashes) {
|
|
|
|
|
String stashId = takeStash.getStashId();
|
|
|
|
|
alertHoldDuration.setSetTime(new Timestamp(new Date().getTime()));
|
|
|
|
|
alertHoldDuration.setStashid(stashId);
|
|
|
|
|
alertHoldDuration.setId(IdUtil.simpleUUID());
|
|
|
|
|
alertHoldDurationMapper.insert(alertHoldDuration);
|
|
|
|
|
|
|
|
|
|
String durationId = alertHoldDuration.getId();
|
|
|
|
|
AlertHoldDurationRecord ahdr = new AlertHoldDurationRecord();
|
|
|
|
|
BeanUtils.copyProperties(alertHoldDuration, ahdr);
|
|
|
|
|
ahdr.setId(IdUtil.simpleUUID());
|
|
|
|
|
ahdr.setDurationid(durationId);
|
|
|
|
|
ahdr.setDirection(takeStash.getBuySellType());
|
|
|
|
|
ahdr.setTradingHour(takeStash.getTimeTransaction());
|
|
|
|
|
HashMap<String, Object> objectObjectHashMap = new HashMap<>();
|
|
|
|
|
objectObjectHashMap.put("takeStashId", stashId);
|
|
|
|
|
objectObjectHashMap.put("durationId", durationId);
|
|
|
|
|
alertHoldDurationRecordMapper.insert(ahdr);
|
|
|
|
|
String durationId = alertHoldDuration.getId();
|
|
|
|
|
AlertHoldDurationRecord ahdr = new AlertHoldDurationRecord();
|
|
|
|
|
BeanUtils.copyProperties(alertHoldDuration, ahdr);
|
|
|
|
|
ahdr.setId(IdUtil.simpleUUID());
|
|
|
|
|
ahdr.setDurationid(durationId);
|
|
|
|
|
ahdr.setDirection(takeStash.getBuySellType());
|
|
|
|
|
ahdr.setTradingHour(takeStash.getTimeTransaction());
|
|
|
|
|
HashMap<String, Object> objectObjectHashMap = new HashMap<>();
|
|
|
|
|
objectObjectHashMap.put("takeStashId", stashId);
|
|
|
|
|
objectObjectHashMap.put("durationId", durationId);
|
|
|
|
|
alertHoldDurationRecordMapper.insert(ahdr);
|
|
|
|
|
|
|
|
|
|
redisUtil.hmset("AlertHoldDurationTakeStashId" + stashId + "_", objectObjectHashMap);
|
|
|
|
|
b();
|
|
|
|
|
if (alertHoldDuration.getStatus() == 1) {
|
|
|
|
|
redisUtil.hmset("trainingId_" + trainingid + "_AlertHoldDurationTakeStashId" + stashId + "_", objectObjectHashMap);
|
|
|
|
|
b();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return "该品种下没有交易记录";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 持仓时长预警对比定时任务
|
|
|
|
|
@Scheduled(fixedRate = 10000)
|
|
|
|
|
@Scheduled(fixedRate = 120000)
|
|
|
|
|
public void b() {
|
|
|
|
|
Set<String> alertHoldDurationTakeStashId = redisUtil.keys("AlertHoldDurationTakeStashId");
|
|
|
|
|
Set<String> alertHoldDurationTakeStashId = redisUtil.keys("*AlertHoldDurationTakeStashId*");
|
|
|
|
|
for (String takeStashId : alertHoldDurationTakeStashId) {
|
|
|
|
|
Map<Object, Object> hmget = redisUtil.hmget(takeStashId);
|
|
|
|
|
String resultTakeStashId = (String) hmget.get("takeStashId");
|
|
|
|
@ -258,34 +281,46 @@ public class WainingService {
|
|
|
|
|
Date timeTransaction = takeStash.getTimeTransaction(); //交易时间
|
|
|
|
|
String buySellType = takeStash.getBuySellType(); //买卖类型
|
|
|
|
|
List<AlertHoldDurationRecord> alertHoldDurationRecords = alertHoldDurationRecordMapper.selectByExample(alertHoldDurationRecordExample);
|
|
|
|
|
AlertHoldDurationRecord ahdr = alertHoldDurationRecords.get(0);
|
|
|
|
|
if (!alertHoldDurationRecords.isEmpty()) {
|
|
|
|
|
AlertHoldDurationRecord ahdr = alertHoldDurationRecords.get(0);
|
|
|
|
|
AlertHoldDuration alertHoldDurations = alertHoldDurationMapper.selectByPrimaryKey(ahdr.getDurationid());
|
|
|
|
|
if (alertHoldDurations != null && alertHoldDurations.getStatus() != null) {
|
|
|
|
|
if (alertHoldDurations.getStatus() == 1) {
|
|
|
|
|
// String wainingHoldDuration = alertHoldDurations.getWariningHoldDuration();
|
|
|
|
|
// Date setTime = alertHoldDurations.getSetTime();
|
|
|
|
|
// Calendar calendar = Calendar.getInstance();
|
|
|
|
|
// calendar.setTime(setTime);
|
|
|
|
|
// calendar.add(Calendar.DAY_OF_YEAR, Integer.parseInt(wainingHoldDuration));
|
|
|
|
|
// //相加后的时间
|
|
|
|
|
// Timestamp resultTime = new Timestamp(calendar.getTime().getTime());
|
|
|
|
|
|
|
|
|
|
AlertHoldDuration alertHoldDurations = alertHoldDurationMapper.selectByPrimaryKey(durationId);
|
|
|
|
|
String wainingHoldDuration = alertHoldDurations.getWariningHoldDuration();
|
|
|
|
|
Date setTime = alertHoldDurations.getSetTime();
|
|
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
|
|
calendar.setTime(setTime);
|
|
|
|
|
calendar.add(Calendar.DAY_OF_YEAR, Integer.parseInt(wainingHoldDuration));
|
|
|
|
|
//相加后的时间
|
|
|
|
|
Timestamp resultTime = new Timestamp(calendar.getTime().getTime());
|
|
|
|
|
|
|
|
|
|
Timestamp nowTime = new Timestamp(new Date().getTime());
|
|
|
|
|
long timeDiff = nowTime.getTime() - timeTransaction.getTime();
|
|
|
|
|
long totalHours = timeDiff / (1000 * 60 * 60);
|
|
|
|
|
long days = totalHours / 24;
|
|
|
|
|
long hours = totalHours % 24;
|
|
|
|
|
//当前时间 - 交易时间 = 持仓时间 持仓时间 > 用户设置的持仓预警时间 就报警
|
|
|
|
|
String wainingHoldDuration = alertHoldDurations.getWariningHoldDuration();
|
|
|
|
|
long warningHours = Long.parseLong(wainingHoldDuration) * 24;
|
|
|
|
|
Timestamp nowTime = new Timestamp(new Date().getTime());
|
|
|
|
|
long timeDiff = nowTime.getTime() - timeTransaction.getTime(); //当前时间 - 交易时间 = 持仓时间
|
|
|
|
|
long totalHours = timeDiff / (1000 * 60 * 60);
|
|
|
|
|
long days = totalHours / 24;
|
|
|
|
|
long hours = totalHours % 24;
|
|
|
|
|
|
|
|
|
|
String timeString = days + "天 " + hours + "小时";
|
|
|
|
|
//"当前时间等于或大于预警值就将时间存库然后发送消息给前端"
|
|
|
|
|
if (nowTime.compareTo(resultTime) >= 0) {
|
|
|
|
|
ahdr.setWariningTime(nowTime); //设置预警时间
|
|
|
|
|
ahdr.setTradingHour(timeTransaction); //设置交易时间
|
|
|
|
|
}
|
|
|
|
|
if (buySellType != null) {
|
|
|
|
|
ahdr.setDirection(buySellType); //设置买卖类型
|
|
|
|
|
String timeString = days + "天 " + hours + "小时";
|
|
|
|
|
//"当前时间等于或大于预警值就将时间存库然后发送消息给前端"
|
|
|
|
|
if (totalHours >= warningHours) {
|
|
|
|
|
String message = alertHoldDurations.getSymbol() + "货币对已持仓xx天,请择机平仓!";
|
|
|
|
|
ahdr.setWariningTime(nowTime); //设置预警时间
|
|
|
|
|
ahdr.setTradingHour(timeTransaction); //设置交易时间
|
|
|
|
|
WebSocket.sendMessage(message);
|
|
|
|
|
redisUtil.del(takeStashId);
|
|
|
|
|
}
|
|
|
|
|
if (buySellType != null) {
|
|
|
|
|
ahdr.setDirection(buySellType); //设置买卖类型
|
|
|
|
|
}
|
|
|
|
|
ahdr.setHoldDuration(timeString); //设置持仓时长
|
|
|
|
|
alertHoldDurationRecordMapper.updateByPrimaryKeySelective(ahdr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ahdr.setHoldDuration(timeString); //设置持仓时长
|
|
|
|
|
alertHoldDurationRecordMapper.updateByPrimaryKeySelective(ahdr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -293,7 +328,8 @@ public class WainingService {
|
|
|
|
|
public String addTransactionNumberWarning(TransactionNumberWarning transactionNumberWarning) {
|
|
|
|
|
TransactionNumberWarningRecord tnwr = new TransactionNumberWarningRecord();
|
|
|
|
|
transactionNumberWarning.setSetTime(new Timestamp(new Date().getTime()));
|
|
|
|
|
|
|
|
|
|
transactionNumberWarning.setId(IdUtil.simpleUUID());
|
|
|
|
|
tnwr.setId(IdUtil.simpleUUID());
|
|
|
|
|
BeanUtils.copyProperties(transactionNumberWarning, tnwr);
|
|
|
|
|
transactionNumberWarningMapper.insert(transactionNumberWarning);
|
|
|
|
|
transactionNumberWarningRecordMapper.insert(tnwr);
|
|
|
|
@ -301,33 +337,37 @@ public class WainingService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//比较交易次数的公共方法
|
|
|
|
|
public String CompareTransactionNumber(String memberId, String trainingId) {
|
|
|
|
|
public void compareTransactionNumber(String memberId, String trainingId) {
|
|
|
|
|
String message = "交易笔数未达到所设置的预警值,请增加交易次数。";
|
|
|
|
|
MemberExample memberExample = new MemberExample();
|
|
|
|
|
memberExample.createCriteria().andMemberIdEqualTo(memberId).andTrainingIdEqualTo(trainingId);
|
|
|
|
|
List<Member> members = memberMapper.selectByExample(memberExample);
|
|
|
|
|
TransactionNumberWarningRecordExample tnwrExample = new TransactionNumberWarningRecordExample();
|
|
|
|
|
tnwrExample.createCriteria().andMemberIdEqualTo(memberId).andTrainingIdEqualTo(trainingId);
|
|
|
|
|
List<TransactionNumberWarningRecord> transactionNumberWarningRecords = transactionNumberWarningRecordMapper.selectByExample(tnwrExample);
|
|
|
|
|
for (TransactionNumberWarningRecord tnwr : transactionNumberWarningRecords) {
|
|
|
|
|
for (Member member : members) {
|
|
|
|
|
Integer warningCount = tnwr.getWarningCount();
|
|
|
|
|
Integer openingTrades = member.getOpeningTrades(); //开仓次数即当前交易次数
|
|
|
|
|
Date warningTime = tnwr.getWarningTime();
|
|
|
|
|
Date date = new Date();
|
|
|
|
|
if (openingTrades < warningCount && date == warningTime) {
|
|
|
|
|
// 如果当前交易次数在到达用户设置的预警时间时还是小于,那么就返回消息给前端提示
|
|
|
|
|
tnwr.setWarningingCount(openingTrades);
|
|
|
|
|
tnwr.setWarningTime(new Timestamp(new Date().getTime()));
|
|
|
|
|
WebSocket.sendMessage(message);
|
|
|
|
|
transactionNumberWarningRecordMapper.updateByPrimaryKeySelective(tnwr);
|
|
|
|
|
TransactionNumberWarningExample tnwrExample = new TransactionNumberWarningExample();
|
|
|
|
|
tnwrExample.createCriteria().andMemberIdEqualTo(memberId).andTrainingIdEqualTo(trainingId).andStatusEqualTo(1);
|
|
|
|
|
List<TransactionNumberWarning> transactionNumberWarnings = transactionNumberWarningMapper.selectByExample(tnwrExample);
|
|
|
|
|
|
|
|
|
|
for (TransactionNumberWarning transactionNumberWarning : transactionNumberWarnings) {
|
|
|
|
|
TransactionNumberWarningRecordExample tnwre = new TransactionNumberWarningRecordExample();
|
|
|
|
|
tnwre.createCriteria().andTransactionNumberWarningIdEqualTo(transactionNumberWarning.getId());
|
|
|
|
|
List<TransactionNumberWarningRecord> transactionNumberWarningRecords = transactionNumberWarningRecordMapper.selectByExample(tnwre);
|
|
|
|
|
for (TransactionNumberWarningRecord tnwr : transactionNumberWarningRecords) {
|
|
|
|
|
for (Member member : members) {
|
|
|
|
|
Integer warningCount = tnwr.getWarningCount();
|
|
|
|
|
Integer openingTrades = member.getOpeningTrades(); //开仓次数即当前交易次数
|
|
|
|
|
Date warningTime = tnwr.getWarningTime();
|
|
|
|
|
Date date = new Date();
|
|
|
|
|
if (openingTrades < warningCount && date == warningTime) {
|
|
|
|
|
// 如果当前交易次数在到达用户设置的预警时间时还是小于,那么就返回消息给前端提示
|
|
|
|
|
tnwr.setWarningingCount(openingTrades);
|
|
|
|
|
tnwr.setWarningTime(new Timestamp(new Date().getTime()));
|
|
|
|
|
WebSocket.sendMessage(message);
|
|
|
|
|
transactionNumberWarningRecordMapper.updateByPrimaryKeySelective(tnwr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return message;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // 新增行情预警,并在达到预警值时将数据存入记录表
|
|
|
|
|
// public void addMarketWarning(MarketWarning marketWarning, String trainingId, String name) {
|
|
|
|
|
// MarketWarningRecord marketWarningRecord = new MarketWarningRecord();
|
|
|
|
|