|
|
|
@ -114,7 +114,7 @@ public class WainingService {
|
|
|
|
|
warning.setStatus(1);
|
|
|
|
|
warning.setAccount(userName);
|
|
|
|
|
warning.setWarningLevel(warningLevel);
|
|
|
|
|
marginWarningMapper.updateByExampleSelective(warning, marginWarningExample);
|
|
|
|
|
marginWarningMapper.updateByPrimaryKeySelective(warning);
|
|
|
|
|
BeanUtils.copyProperties(warning, marginWarningRecord);
|
|
|
|
|
marginWarningRecord.setId(IdUtil.simpleUUID());
|
|
|
|
|
marginWarningRecord.setMarginWarningId(warning.getId());
|
|
|
|
@ -125,40 +125,6 @@ public class WainingService {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 定时任务,五秒比较一次保证金预警值是否相等,
|
|
|
|
|
// @Scheduled(fixedRate = 10000)
|
|
|
|
|
// public void compareMarginLevels() {
|
|
|
|
|
// Boolean isStorageNeeded = true;
|
|
|
|
|
// Set<String> keys = redisUtil.keys("*marginWarningId*");
|
|
|
|
|
// for (String key : keys) {
|
|
|
|
|
// Map<Object, Object> hmget = redisUtil.hmget(key);
|
|
|
|
|
// Integer warningLevel = (Integer) hmget.get("warningLevel");
|
|
|
|
|
// MarginWarningRecord marginWarningRecord = (MarginWarningRecord) hmget.get("marginWarningRecord");
|
|
|
|
|
// String memberId = (String) hmget.get("memberId");
|
|
|
|
|
// Member member = memberMapper.selectByPrimaryKey(memberId);
|
|
|
|
|
// String message = "保证金已到达预警水平!";
|
|
|
|
|
// if (warningLevel != null) {
|
|
|
|
|
// Double aDouble = Double.valueOf(warningLevel);
|
|
|
|
|
// Double marginLevel = member.getMarginLevel();
|
|
|
|
|
// if (redisUtil.get("StorageOrNot") != null) {
|
|
|
|
|
// boolean storageOrNot = redisUtil.get("StorageOrNot");
|
|
|
|
|
//// 相等就存预警水平和预警时间,并且发送消息给前端提醒
|
|
|
|
|
// if (aDouble >= marginLevel) {
|
|
|
|
|
// if (!storageOrNot) {
|
|
|
|
|
// Date date = new Date();
|
|
|
|
|
// Timestamp current = new Timestamp(date.getTime());
|
|
|
|
|
// marginWarningRecord.setWarningTime(current);
|
|
|
|
|
// marginWarningRecord.setWarningLevel(aDouble.intValue());
|
|
|
|
|
// marginWarningRecordMapper.insert(marginWarningRecord);
|
|
|
|
|
// redisUtil.set("StorageOrNot", true);
|
|
|
|
|
// simpMessagingTemplate.convertAndSend("/topic/margin-change", message);
|
|
|
|
|
//// isStorageNeeded = false; // 存完库后设置为false
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
//查询保证金预警记录表
|
|
|
|
|
public PageInfo<MarginWarningRecord> getMarginWarningRecord(Integer index, Integer size, String userName, String trainingId) {
|
|
|
|
@ -176,47 +142,6 @@ public class WainingService {
|
|
|
|
|
marginWarningMapper.updateByPrimaryKeySelective(marginWarning);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // 新增行情预警,并在达到预警值时将数据存入记录表
|
|
|
|
|
// public void addMarketWarning(MarketWarning marketWarning, String trainingId, String name) {
|
|
|
|
|
// 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(marketWarning.getId());
|
|
|
|
|
// marketWarningRecord.setId(IdUtil.simpleUUID());
|
|
|
|
|
//
|
|
|
|
|
//// 1.从redis中取出当前价位
|
|
|
|
|
// ForexMarketData forexMarketDateByCode = forexMarketDateUtil.getForexMarketDateByCode(marketWarning.getSymbol());
|
|
|
|
|
// if (forexMarketDateByCode != null) {
|
|
|
|
|
// Double buyPic = forexMarketDateByCode.getBuyPic();
|
|
|
|
|
// String sellPic = forexMarketDateByCode.getSellPic();
|
|
|
|
|
// Double sellPicValue = Double.parseDouble(sellPic);
|
|
|
|
|
//// 2.判断新增的预警是买还是卖
|
|
|
|
|
// String direction = marketWarning.getDirection();
|
|
|
|
|
// Double upperBreakPrice = marketWarning.getUpperBreakPrice();
|
|
|
|
|
// Double lowerBreakPrice = marketWarning.getLowerBreakPrice();
|
|
|
|
|
// String message = "预警通知:价格已达到预警值";
|
|
|
|
|
// if (direction.equals("买")) {
|
|
|
|
|
//// 3.拿redis的价位和新增的高价低价做比较,==的时候就弹出提示,并且存入行情预警记录表
|
|
|
|
|
// if (buyPic.equals(upperBreakPrice) || buyPic.equals(lowerBreakPrice)) {
|
|
|
|
|
// simpMessagingTemplate.convertAndSend("/topic/alerts", message);
|
|
|
|
|
// marketWarningRecord.setWarningPrice(buyPic);
|
|
|
|
|
// marketWarningRecord.setWarningTime((new Timestamp(new Date().getTime())));
|
|
|
|
|
// }
|
|
|
|
|
// } else {
|
|
|
|
|
// if (sellPicValue.equals(upperBreakPrice) || sellPicValue.equals(lowerBreakPrice)) {
|
|
|
|
|
// simpMessagingTemplate.convertAndSend("/topic/alerts", message);
|
|
|
|
|
// marketWarningRecord.setWarningPrice(sellPicValue);
|
|
|
|
|
// marketWarningRecord.setWarningTime((new Timestamp(new Date().getTime())));
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// marketWarningRecordMapper.insert(marketWarningRecord);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// 新增行情预警,并在达到预警值时将数据存入记录表
|
|
|
|
|
public void addMarketWarning(MarketWarning marketWarning, String trainingId, String name) {
|
|
|
|
|
// 记录表需要设置预警水平和预警时间 为报警时候的值
|
|
|
|
@ -267,7 +192,7 @@ public class WainingService {
|
|
|
|
|
simpMessagingTemplate.convertAndSend("/topic/alerts", message);
|
|
|
|
|
marketWarningRecord.setWarningPrice(buyPic);
|
|
|
|
|
marketWarningRecord.setWarningTime((new Timestamp(new Date().getTime())));
|
|
|
|
|
marketWarningRecordMapper.updateByExampleSelective(marketWarningRecord, marketWarningRecordExample);
|
|
|
|
|
marketWarningRecordMapper.updateByPrimaryKeySelective(marketWarningRecord);
|
|
|
|
|
redisUtil.del(key);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
@ -275,7 +200,7 @@ public class WainingService {
|
|
|
|
|
simpMessagingTemplate.convertAndSend("/topic/alerts", message);
|
|
|
|
|
marketWarningRecord.setWarningPrice(sellPicValue);
|
|
|
|
|
marketWarningRecord.setWarningTime((new Timestamp(new Date().getTime())));
|
|
|
|
|
marketWarningRecordMapper.updateByExampleSelective(marketWarningRecord, marketWarningRecordExample);
|
|
|
|
|
marketWarningRecordMapper.updateByPrimaryKeySelective(marketWarningRecord);
|
|
|
|
|
redisUtil.del(key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -284,56 +209,154 @@ public class WainingService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//新增持仓时长预警
|
|
|
|
|
public void addAlertHoldDuration(AlertHoldDuration alertHoldDuration, String trainingId, String name, String stashId) {
|
|
|
|
|
TakeStash takeStash = takeStashMapper.selectByPrimaryKey(stashId);
|
|
|
|
|
alertHoldDuration.setName(name);
|
|
|
|
|
alertHoldDuration.setTrainingid(trainingId);
|
|
|
|
|
alertHoldDuration.setSetTime(new Timestamp(new Date().getTime()));
|
|
|
|
|
alertHoldDuration.setStashid(stashId);
|
|
|
|
|
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);
|
|
|
|
|
redisUtil.hmset("AlertHoldDurationTakeStashId" + stashId + "_", objectObjectHashMap);
|
|
|
|
|
b();
|
|
|
|
|
public void addAlertHoldDuration(AlertHoldDuration alertHoldDuration, String trainingId, String name) {
|
|
|
|
|
String symbol = alertHoldDuration.getSymbol();
|
|
|
|
|
TakeStashExample takeStashExample = new TakeStashExample();
|
|
|
|
|
takeStashExample.createCriteria().andTradingCodeEqualTo(symbol);
|
|
|
|
|
List<TakeStash> takeStashes = takeStashMapper.selectByExample(takeStashExample);
|
|
|
|
|
for (TakeStash takeStash : takeStashes) {
|
|
|
|
|
String stashId = takeStash.getStashId();
|
|
|
|
|
alertHoldDuration.setName(name);
|
|
|
|
|
alertHoldDuration.setTrainingid(trainingId);
|
|
|
|
|
alertHoldDuration.setSetTime(new Timestamp(new Date().getTime()));
|
|
|
|
|
alertHoldDuration.setStashid(stashId);
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
redisUtil.hmset("AlertHoldDurationTakeStashId" + stashId + "_", objectObjectHashMap);
|
|
|
|
|
b();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//持仓时长预警对比定时任务
|
|
|
|
|
// @Scheduled(fixedRate = 10000)
|
|
|
|
|
public void b(){
|
|
|
|
|
// Set<String> alertHoldDurationTakeStashId = redisUtil.keys("AlertHoldDurationTakeStashId");
|
|
|
|
|
// for (String takeStashId : alertHoldDurationTakeStashId) {
|
|
|
|
|
// Map<Object, Object> hmget = redisUtil.hmget(takeStashId);
|
|
|
|
|
// String resultTakeStashId = (String) hmget.get("takeStashId");
|
|
|
|
|
// String durationId = (String)hmget.get("durationId");
|
|
|
|
|
// AlertHoldDurationRecordExample alertHoldDurationRecordExample = new AlertHoldDurationRecordExample();
|
|
|
|
|
// alertHoldDurationRecordExample.createCriteria().andStashidEqualTo(resultTakeStashId);
|
|
|
|
|
// List<AlertHoldDuration> alertHoldDurations = alertHoldDurationMapper.selectByExample(alertHoldDurationExample);
|
|
|
|
|
// for (AlertHoldDuration alertHoldDuration : alertHoldDurations) {
|
|
|
|
|
// String wariningHoldDuration = alertHoldDuration.getWariningHoldDuration();
|
|
|
|
|
// Date setTime = alertHoldDuration.getSetTime();
|
|
|
|
|
// Calendar calendar = Calendar.getInstance();
|
|
|
|
|
// calendar.setTime(setTime);
|
|
|
|
|
// calendar.add(Calendar.DAY_OF_YEAR, Integer.parseInt(wariningHoldDuration));
|
|
|
|
|
// //相加后的时间
|
|
|
|
|
// Date time = calendar.getTime();
|
|
|
|
|
// Timestamp timestamp = new Timestamp(new Date().getTime());
|
|
|
|
|
// if ("当前时间等于或大于预警值就将时间存库然后发送消息给前端"){
|
|
|
|
|
//// TODO 设置记录表的持仓时长和交易时间两个参数
|
|
|
|
|
// // ahdr.setHoldDuration("持仓时长");
|
|
|
|
|
//// ahdr.setWariningTime("预警时间");
|
|
|
|
|
// 持仓时长预警对比定时任务
|
|
|
|
|
@Scheduled(fixedRate = 10000)
|
|
|
|
|
public void b() {
|
|
|
|
|
Set<String> alertHoldDurationTakeStashId = redisUtil.keys("AlertHoldDurationTakeStashId");
|
|
|
|
|
for (String takeStashId : alertHoldDurationTakeStashId) {
|
|
|
|
|
Map<Object, Object> hmget = redisUtil.hmget(takeStashId);
|
|
|
|
|
String resultTakeStashId = (String) hmget.get("takeStashId");
|
|
|
|
|
String durationId = (String) hmget.get("durationId");
|
|
|
|
|
//根据TakeStashId查出对应的持仓记录对象
|
|
|
|
|
AlertHoldDurationRecordExample alertHoldDurationRecordExample = new AlertHoldDurationRecordExample();
|
|
|
|
|
alertHoldDurationRecordExample.createCriteria().andStashidEqualTo(resultTakeStashId);
|
|
|
|
|
TakeStash takeStash = takeStashMapper.selectByPrimaryKey(resultTakeStashId);
|
|
|
|
|
Date timeTransaction = takeStash.getTimeTransaction(); //交易时间
|
|
|
|
|
String buySellType = takeStash.getBuySellType(); //买卖类型
|
|
|
|
|
List<AlertHoldDurationRecord> alertHoldDurationRecords = alertHoldDurationRecordMapper.selectByExample(alertHoldDurationRecordExample);
|
|
|
|
|
AlertHoldDurationRecord ahdr = alertHoldDurationRecords.get(0);
|
|
|
|
|
|
|
|
|
|
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 timeString = days + "天 " + hours + "小时";
|
|
|
|
|
//"当前时间等于或大于预警值就将时间存库然后发送消息给前端"
|
|
|
|
|
if (nowTime.compareTo(resultTime) >= 0) {
|
|
|
|
|
ahdr.setWariningTime(nowTime); //设置预警时间
|
|
|
|
|
ahdr.setTradingHour(timeTransaction); //设置交易时间
|
|
|
|
|
}
|
|
|
|
|
if (buySellType != null) {
|
|
|
|
|
ahdr.setDirection(buySellType); //设置买卖类型
|
|
|
|
|
}
|
|
|
|
|
ahdr.setHoldDuration(timeString); //设置持仓时长
|
|
|
|
|
alertHoldDurationRecordMapper.updateByPrimaryKeySelective(ahdr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// // 新增行情预警,并在达到预警值时将数据存入记录表
|
|
|
|
|
// public void addMarketWarning(MarketWarning marketWarning, String trainingId, String name) {
|
|
|
|
|
// 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(marketWarning.getId());
|
|
|
|
|
// marketWarningRecord.setId(IdUtil.simpleUUID());
|
|
|
|
|
//
|
|
|
|
|
//// 1.从redis中取出当前价位
|
|
|
|
|
// ForexMarketData forexMarketDateByCode = forexMarketDateUtil.getForexMarketDateByCode(marketWarning.getSymbol());
|
|
|
|
|
// if (forexMarketDateByCode != null) {
|
|
|
|
|
// Double buyPic = forexMarketDateByCode.getBuyPic();
|
|
|
|
|
// String sellPic = forexMarketDateByCode.getSellPic();
|
|
|
|
|
// Double sellPicValue = Double.parseDouble(sellPic);
|
|
|
|
|
//// 2.判断新增的预警是买还是卖
|
|
|
|
|
// String direction = marketWarning.getDirection();
|
|
|
|
|
// Double upperBreakPrice = marketWarning.getUpperBreakPrice();
|
|
|
|
|
// Double lowerBreakPrice = marketWarning.getLowerBreakPrice();
|
|
|
|
|
// String message = "预警通知:价格已达到预警值";
|
|
|
|
|
// if (direction.equals("买")) {
|
|
|
|
|
//// 3.拿redis的价位和新增的高价低价做比较,==的时候就弹出提示,并且存入行情预警记录表
|
|
|
|
|
// if (buyPic.equals(upperBreakPrice) || buyPic.equals(lowerBreakPrice)) {
|
|
|
|
|
// simpMessagingTemplate.convertAndSend("/topic/alerts", message);
|
|
|
|
|
// marketWarningRecord.setWarningPrice(buyPic);
|
|
|
|
|
// marketWarningRecord.setWarningTime((new Timestamp(new Date().getTime())));
|
|
|
|
|
// }
|
|
|
|
|
// } else {
|
|
|
|
|
// if (sellPicValue.equals(upperBreakPrice) || sellPicValue.equals(lowerBreakPrice)) {
|
|
|
|
|
// simpMessagingTemplate.convertAndSend("/topic/alerts", message);
|
|
|
|
|
// marketWarningRecord.setWarningPrice(sellPicValue);
|
|
|
|
|
// marketWarningRecord.setWarningTime((new Timestamp(new Date().getTime())));
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
// marketWarningRecordMapper.insert(marketWarningRecord);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
// 定时任务,五秒比较一次保证金预警值是否相等,
|
|
|
|
|
// @Scheduled(fixedRate = 10000)
|
|
|
|
|
// public void compareMarginLevels() {
|
|
|
|
|
// Boolean isStorageNeeded = true;
|
|
|
|
|
// Set<String> keys = redisUtil.keys("*marginWarningId*");
|
|
|
|
|
// for (String key : keys) {
|
|
|
|
|
// Map<Object, Object> hmget = redisUtil.hmget(key);
|
|
|
|
|
// Integer warningLevel = (Integer) hmget.get("warningLevel");
|
|
|
|
|
// MarginWarningRecord marginWarningRecord = (MarginWarningRecord) hmget.get("marginWarningRecord");
|
|
|
|
|
// String memberId = (String) hmget.get("memberId");
|
|
|
|
|
// Member member = memberMapper.selectByPrimaryKey(memberId);
|
|
|
|
|
// String message = "保证金已到达预警水平!";
|
|
|
|
|
// if (warningLevel != null) {
|
|
|
|
|
// Double aDouble = Double.valueOf(warningLevel);
|
|
|
|
|
// Double marginLevel = member.getMarginLevel();
|
|
|
|
|
// if (redisUtil.get("StorageOrNot") != null) {
|
|
|
|
|
// boolean storageOrNot = redisUtil.get("StorageOrNot");
|
|
|
|
|
//// 相等就存预警水平和预警时间,并且发送消息给前端提醒
|
|
|
|
|
// if (aDouble >= marginLevel) {
|
|
|
|
|
// if (!storageOrNot) {
|
|
|
|
|
// Date date = new Date();
|
|
|
|
|
// Timestamp current = new Timestamp(date.getTime());
|
|
|
|
|
// marginWarningRecord.setWarningTime(current);
|
|
|
|
|
// marginWarningRecord.setWarningLevel(aDouble.intValue());
|
|
|
|
|
// marginWarningRecordMapper.insert(marginWarningRecord);
|
|
|
|
|
// redisUtil.set("StorageOrNot", true);
|
|
|
|
|
// simpMessagingTemplate.convertAndSend("/topic/margin-change", message);
|
|
|
|
|
//// isStorageNeeded = false; // 存完库后设置为false
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|