修改接口

pull/1/head
xiaoCJ 2 years ago
parent 28473f6f1d
commit d3407be568

@ -17,6 +17,7 @@ import io.swagger.annotations.ApiParam;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
@Api(tags = "预警页面") @Api(tags = "预警页面")
@ -35,16 +36,16 @@ public class WarningController {
private AlertHoldDurationRecordMapper alertHoldDurationRecordMapper; private AlertHoldDurationRecordMapper alertHoldDurationRecordMapper;
@GetMapping("aa") @GetMapping("aa")
public String getaa(@RequestParam String memberId,@RequestParam String trainingId){ public String getaa(@RequestParam String memberId, @RequestParam String trainingId) {
return wainingService.compareMarginLevels(memberId,trainingId); return wainingService.compareMarginLevels(memberId, trainingId);
} }
//保证金预警页面展示 //保证金预警页面展示
@GetMapping("/getMarginWarning") @GetMapping("/getMarginWarning")
@ApiOperation("保证金预警页面展示") @ApiOperation("保证金预警页面展示")
public ResultEntity<MarginWarning> getMarginWarning(@ApiParam("姓名")@RequestParam String userName, public ResultEntity<MarginWarning> getMarginWarning(@ApiParam("姓名") @RequestParam String userName,
@ApiParam("任务ID")@RequestParam String trainingId, @ApiParam("任务ID") @RequestParam String trainingId,
@ApiParam("成员ID")@RequestParam String memberId) { @ApiParam("成员ID") @RequestParam String memberId) {
return new ResultEntity<>(wainingService.getMarginWarning(userName, trainingId, memberId)); return new ResultEntity<>(wainingService.getMarginWarning(userName, trainingId, memberId));
} }
@ -52,28 +53,28 @@ public class WarningController {
//保证金报警水平保存 //保证金报警水平保存
@PostMapping("/saveWarningLevel") @PostMapping("/saveWarningLevel")
@ApiOperation("保证金报警水平修改保存") @ApiOperation("保证金报警水平修改保存")
public ResultEntity<MarginWarning> saveWarningLevel(@ApiParam("预警水平")@RequestParam Integer warningLevel, public ResultEntity<MarginWarning> saveWarningLevel(@ApiParam("预警水平") @RequestParam Integer warningLevel,
@ApiParam("成员ID")@RequestParam String memberId, @ApiParam("成员ID") @RequestParam String memberId,
@ApiParam("姓名")@RequestParam String userName, @ApiParam("姓名") @RequestParam String userName,
@ApiParam("任务ID")@RequestParam String trainingId) { @ApiParam("任务ID") @RequestParam String trainingId) {
return new ResultEntity<>(wainingService.saveWarningLevel(warningLevel, memberId, userName, trainingId)); return new ResultEntity<>(wainingService.saveWarningLevel(warningLevel, memberId, userName, trainingId));
} }
//查询保证金预警记录 //查询保证金预警记录
@GetMapping("/getMarginWarningRecord") @GetMapping("/getMarginWarningRecord")
@ApiOperation("查询保证金预警记录") @ApiOperation("查询保证金预警记录")
public ResultEntity<PageInfo<MarginWarningRecord>> getMarginWarningRecord(@ApiParam("姓名")@RequestParam String userName, public ResultEntity<PageInfo<MarginWarningRecord>> getMarginWarningRecord(@ApiParam("姓名") @RequestParam String userName,
@ApiParam("任务ID")@RequestParam String trainingId, @ApiParam("任务ID") @RequestParam String trainingId,
@ApiParam("首页页码")@RequestParam Integer index, @ApiParam("首页页码") @RequestParam Integer index,
@ApiParam("页面条数")@RequestParam Integer size) { @ApiParam("页面条数") @RequestParam Integer size) {
return new ResultEntity<>(wainingService.getMarginWarningRecord(index, size,userName, trainingId)); return new ResultEntity<>(wainingService.getMarginWarningRecord(index, size, userName, trainingId));
} }
//启用或停止保证金预警状态 //启用或停止保证金预警状态
@PutMapping("/setMarginWarningStatus") @PutMapping("/setMarginWarningStatus")
@ApiOperation("启用或停止保证金预警状态") @ApiOperation("启用或停止保证金预警状态")
public ResultEntity<String> setMarginWarningStatus(@ApiParam("0 停用 1 启用")@RequestParam Integer status, public ResultEntity<String> setMarginWarningStatus(@ApiParam("0 停用 1 启用") @RequestParam Integer status,
@ApiParam("任务ID")@RequestParam String id) { @ApiParam("任务ID") @RequestParam String id) {
wainingService.setMarginWarningStatus(status, id); wainingService.setMarginWarningStatus(status, id);
return new ResultEntity<>("修改成功"); return new ResultEntity<>("修改成功");
} }
@ -88,20 +89,20 @@ public class WarningController {
//新增行情预警 //新增行情预警
@PostMapping("/addMarketWarning") @PostMapping("/addMarketWarning")
@ApiOperation("新增行情预警") @ApiOperation("新增行情预警")
public void addMarketWarning(@ApiParam("行情预警对象")@RequestBody MarketWarning marketWarning, public void addMarketWarning(@ApiParam("行情预警对象") @RequestBody MarketWarning marketWarning,
@ApiParam("任务ID")@RequestParam String trainingId, @ApiParam("任务ID") @RequestParam String trainingId,
@ApiParam("姓名")@RequestParam String name) { @ApiParam("姓名") @RequestParam String name) {
wainingService.addMarketWarning(marketWarning, trainingId, name); wainingService.addMarketWarning(marketWarning, trainingId, name);
} }
//查询行情预警 //查询行情预警
@GetMapping("/getMarketWarning") @GetMapping("/getMarketWarning")
@ApiOperation("查询行情预警") @ApiOperation("查询行情预警")
public ResultEntity<PageInfo<MarketWarning>> getMarketWarning(@ApiParam("姓名")@RequestParam String name, public ResultEntity<PageInfo<MarketWarning>> getMarketWarning(@ApiParam("姓名") @RequestParam String name,
@ApiParam("任务ID")@RequestParam String trainingId, @ApiParam("任务ID") @RequestParam String trainingId,
@ApiParam("首页页码")@RequestParam Integer index, @ApiParam("首页页码") @RequestParam Integer index,
@ApiParam("页面条数")@RequestParam Integer size) { @ApiParam("页面条数") @RequestParam Integer size) {
PageHelper.startPage(index,size); PageHelper.startPage(index, size);
MarketWarningExample marketWarningExample = new MarketWarningExample(); MarketWarningExample marketWarningExample = new MarketWarningExample();
marketWarningExample.createCriteria().andNameEqualTo(name).andTariningidEqualTo(trainingId); marketWarningExample.createCriteria().andNameEqualTo(name).andTariningidEqualTo(trainingId);
List<MarketWarning> marketWarnings = marketWarningMapper.selectByExample(marketWarningExample); List<MarketWarning> marketWarnings = marketWarningMapper.selectByExample(marketWarningExample);
@ -112,8 +113,8 @@ public class WarningController {
//查询行情预警记录 //查询行情预警记录
@GetMapping("/getMarketWarningRecord") @GetMapping("/getMarketWarningRecord")
@ApiOperation("查询行情预警记录") @ApiOperation("查询行情预警记录")
public ResultEntity<List<MarketWarningRecord>> getMarketWarningRecord(@ApiParam("姓名")@RequestParam String name, public ResultEntity<List<MarketWarningRecord>> getMarketWarningRecord(@ApiParam("姓名") @RequestParam String name,
@ApiParam("任务ID")@RequestParam String trainingId) { @ApiParam("任务ID") @RequestParam String trainingId) {
MarketWarningRecordExample marketWarningRecordExample = new MarketWarningRecordExample(); MarketWarningRecordExample marketWarningRecordExample = new MarketWarningRecordExample();
marketWarningRecordExample.createCriteria().andNameEqualTo(name).andTariningidEqualTo(trainingId); marketWarningRecordExample.createCriteria().andNameEqualTo(name).andTariningidEqualTo(trainingId);
return new ResultEntity<>(marketWarningRecordMapper.selectByExample(marketWarningRecordExample)); return new ResultEntity<>(marketWarningRecordMapper.selectByExample(marketWarningRecordExample));
@ -122,22 +123,22 @@ public class WarningController {
//删除行情预警 //删除行情预警
@DeleteMapping("/deleteMarketWarning") @DeleteMapping("/deleteMarketWarning")
@ApiOperation("删除行情预警") @ApiOperation("删除行情预警")
public void deleteMarketWarningById(@ApiParam("id")@RequestParam String id) { public void deleteMarketWarningById(@ApiParam("id") @RequestParam String id) {
marketWarningMapper.deleteByPrimaryKey(id); marketWarningMapper.deleteByPrimaryKey(id);
} }
//删除行情预警记录 //删除行情预警记录
@DeleteMapping("/deleteMarketWarningRecord") @DeleteMapping("/deleteMarketWarningRecord")
@ApiOperation("删除行情预警记录") @ApiOperation("删除行情预警记录")
public void deleteMarketWarningRecordById(@ApiParam("id")@RequestParam String id) { public void deleteMarketWarningRecordById(@ApiParam("id") @RequestParam String id) {
marketWarningRecordMapper.deleteByPrimaryKey(id); marketWarningRecordMapper.deleteByPrimaryKey(id);
} }
//启用或关闭行情预警 //启用或关闭行情预警
@PutMapping("/setMarketWarning") @PutMapping("/setMarketWarning")
@ApiOperation("启用或关闭行情预警") @ApiOperation("启用或关闭行情预警")
public void updateStatus(@ApiParam("0 停用 1 启用")@RequestParam Integer status, public void updateStatus(@ApiParam("0 停用 1 启用") @RequestParam Integer status,
@ApiParam("id")@RequestParam String id) { @ApiParam("id") @RequestParam String id) {
MarketWarning marketWarning = marketWarningMapper.selectByPrimaryKey(id); MarketWarning marketWarning = marketWarningMapper.selectByPrimaryKey(id);
marketWarning.setStatus(status); marketWarning.setStatus(status);
marketWarningMapper.updateByPrimaryKeySelective(marketWarning); marketWarningMapper.updateByPrimaryKeySelective(marketWarning);
@ -146,25 +147,25 @@ public class WarningController {
//新增持仓时长预警 //新增持仓时长预警
@PostMapping("/addAlertHoldDuration") @PostMapping("/addAlertHoldDuration")
@ApiOperation("新增持仓时长预警") @ApiOperation("新增持仓时长预警")
public void addAlertHoldDuration(@ApiParam("持仓时长预警对象")@RequestBody AlertHoldDuration alertHoldDuration, public void addAlertHoldDuration(@ApiParam("持仓时长预警对象") @RequestBody AlertHoldDuration alertHoldDuration,
@ApiParam("任务ID")@RequestParam String trainingId, @ApiParam("任务ID") @RequestParam String trainingId,
@ApiParam("姓名")@RequestParam String name, @ApiParam("姓名") @RequestParam String name
@ApiParam("交易记录表ID")@RequestParam String stashId) { ) {
wainingService.addAlertHoldDuration(alertHoldDuration,trainingId,name,stashId); wainingService.addAlertHoldDuration(alertHoldDuration, trainingId, name);
} }
//删除持仓时长预警 //删除持仓时长预警
@DeleteMapping("/deleteAlertHoldDuration") @DeleteMapping("/deleteAlertHoldDuration")
@ApiOperation("删除持仓时长预警") @ApiOperation("删除持仓时长预警")
public void deleteAlertHoldDuration(@ApiParam("id")@RequestParam String id) { public void deleteAlertHoldDuration(@ApiParam("id") @RequestParam String id) {
alertHoldDurationMapper.deleteByPrimaryKey(id); alertHoldDurationMapper.deleteByPrimaryKey(id);
} }
//启用或关闭持仓时长预警 //启用或关闭持仓时长预警
@PutMapping("/setAlertHoldDuration") @PutMapping("/setAlertHoldDuration")
@ApiOperation("启用或关闭持仓时长预警") @ApiOperation("启用或关闭持仓时长预警")
public void setAlertHoldDuration(@ApiParam("0 停用 1 启用")@RequestParam Integer status, public void setAlertHoldDuration(@ApiParam("0 停用 1 启用") @RequestParam Integer status,
@ApiParam("id")@RequestParam String id) { @ApiParam("id") @RequestParam String id) {
AlertHoldDuration alertHoldDuration = alertHoldDurationMapper.selectByPrimaryKey(id); AlertHoldDuration alertHoldDuration = alertHoldDurationMapper.selectByPrimaryKey(id);
alertHoldDuration.setStatus(status); alertHoldDuration.setStatus(status);
alertHoldDurationMapper.updateByPrimaryKeySelective(alertHoldDuration); alertHoldDurationMapper.updateByPrimaryKeySelective(alertHoldDuration);
@ -173,7 +174,7 @@ public class WarningController {
//删除持仓时长预警记录表 //删除持仓时长预警记录表
@DeleteMapping("/deleteAlertHoldDurationRecordMapper") @DeleteMapping("/deleteAlertHoldDurationRecordMapper")
@ApiOperation("删除持仓时长预警记录表数据") @ApiOperation("删除持仓时长预警记录表数据")
public void deleteAlertHoldDurationRecordMapper(@ApiParam("id")@RequestParam String id) { public void deleteAlertHoldDurationRecordMapper(@ApiParam("id") @RequestParam String id) {
alertHoldDurationRecordMapper.deleteByPrimaryKey(id); alertHoldDurationRecordMapper.deleteByPrimaryKey(id);
} }

@ -107,6 +107,7 @@ public class IndexService {
criteria1.andNameLike("%" + name + "%"); criteria1.andNameLike("%" + name + "%");
} }
memberExample.setOrderByClause("yield DESC"); memberExample.setOrderByClause("yield DESC");
PageHelper.startPage(index, size);
List<Member> membersForTraining = memberMapper.selectByExample(memberExample); List<Member> membersForTraining = memberMapper.selectByExample(memberExample);
for (int i = 1; i <= membersForTraining.size(); i++) { for (int i = 1; i <= membersForTraining.size(); i++) {
for (Member member : membersForTraining) { for (Member member : membersForTraining) {

@ -114,7 +114,7 @@ public class WainingService {
warning.setStatus(1); warning.setStatus(1);
warning.setAccount(userName); warning.setAccount(userName);
warning.setWarningLevel(warningLevel); warning.setWarningLevel(warningLevel);
marginWarningMapper.updateByExampleSelective(warning, marginWarningExample); marginWarningMapper.updateByPrimaryKeySelective(warning);
BeanUtils.copyProperties(warning, marginWarningRecord); BeanUtils.copyProperties(warning, marginWarningRecord);
marginWarningRecord.setId(IdUtil.simpleUUID()); marginWarningRecord.setId(IdUtil.simpleUUID());
marginWarningRecord.setMarginWarningId(warning.getId()); marginWarningRecord.setMarginWarningId(warning.getId());
@ -125,40 +125,6 @@ public class WainingService {
return null; 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) { public PageInfo<MarginWarningRecord> getMarginWarningRecord(Integer index, Integer size, String userName, String trainingId) {
@ -176,47 +142,6 @@ public class WainingService {
marginWarningMapper.updateByPrimaryKeySelective(marginWarning); 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) { public void addMarketWarning(MarketWarning marketWarning, String trainingId, String name) {
// 记录表需要设置预警水平和预警时间 为报警时候的值 // 记录表需要设置预警水平和预警时间 为报警时候的值
@ -267,7 +192,7 @@ public class WainingService {
simpMessagingTemplate.convertAndSend("/topic/alerts", message); simpMessagingTemplate.convertAndSend("/topic/alerts", message);
marketWarningRecord.setWarningPrice(buyPic); marketWarningRecord.setWarningPrice(buyPic);
marketWarningRecord.setWarningTime((new Timestamp(new Date().getTime()))); marketWarningRecord.setWarningTime((new Timestamp(new Date().getTime())));
marketWarningRecordMapper.updateByExampleSelective(marketWarningRecord, marketWarningRecordExample); marketWarningRecordMapper.updateByPrimaryKeySelective(marketWarningRecord);
redisUtil.del(key); redisUtil.del(key);
} }
} else { } else {
@ -275,7 +200,7 @@ public class WainingService {
simpMessagingTemplate.convertAndSend("/topic/alerts", message); simpMessagingTemplate.convertAndSend("/topic/alerts", message);
marketWarningRecord.setWarningPrice(sellPicValue); marketWarningRecord.setWarningPrice(sellPicValue);
marketWarningRecord.setWarningTime((new Timestamp(new Date().getTime()))); marketWarningRecord.setWarningTime((new Timestamp(new Date().getTime())));
marketWarningRecordMapper.updateByExampleSelective(marketWarningRecord, marketWarningRecordExample); marketWarningRecordMapper.updateByPrimaryKeySelective(marketWarningRecord);
redisUtil.del(key); redisUtil.del(key);
} }
} }
@ -284,56 +209,154 @@ public class WainingService {
} }
//新增持仓时长预警 //新增持仓时长预警
public void addAlertHoldDuration(AlertHoldDuration alertHoldDuration, String trainingId, String name, String stashId) { public void addAlertHoldDuration(AlertHoldDuration alertHoldDuration, String trainingId, String name) {
TakeStash takeStash = takeStashMapper.selectByPrimaryKey(stashId); String symbol = alertHoldDuration.getSymbol();
alertHoldDuration.setName(name); TakeStashExample takeStashExample = new TakeStashExample();
alertHoldDuration.setTrainingid(trainingId); takeStashExample.createCriteria().andTradingCodeEqualTo(symbol);
alertHoldDuration.setSetTime(new Timestamp(new Date().getTime())); List<TakeStash> takeStashes = takeStashMapper.selectByExample(takeStashExample);
alertHoldDuration.setStashid(stashId); for (TakeStash takeStash : takeStashes) {
alertHoldDurationMapper.insert(alertHoldDuration); String stashId = takeStash.getStashId();
String durationId = alertHoldDuration.getId(); alertHoldDuration.setName(name);
AlertHoldDurationRecord ahdr = new AlertHoldDurationRecord(); alertHoldDuration.setTrainingid(trainingId);
BeanUtils.copyProperties(alertHoldDuration, ahdr); alertHoldDuration.setSetTime(new Timestamp(new Date().getTime()));
ahdr.setId(IdUtil.simpleUUID()); alertHoldDuration.setStashid(stashId);
ahdr.setDurationid(durationId); alertHoldDurationMapper.insert(alertHoldDuration);
ahdr.setDirection(takeStash.getBuySellType());
ahdr.setTradingHour(takeStash.getTimeTransaction()); String durationId = alertHoldDuration.getId();
HashMap<String, Object> objectObjectHashMap = new HashMap<>(); AlertHoldDurationRecord ahdr = new AlertHoldDurationRecord();
objectObjectHashMap.put("takeStashId",stashId); BeanUtils.copyProperties(alertHoldDuration, ahdr);
objectObjectHashMap.put("durationId",durationId); ahdr.setId(IdUtil.simpleUUID());
alertHoldDurationRecordMapper.insert(ahdr); ahdr.setDurationid(durationId);
redisUtil.hmset("AlertHoldDurationTakeStashId" + stashId + "_", objectObjectHashMap); ahdr.setDirection(takeStash.getBuySellType());
b(); 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) @Scheduled(fixedRate = 10000)
public void b(){ public void b() {
// Set<String> alertHoldDurationTakeStashId = redisUtil.keys("AlertHoldDurationTakeStashId"); Set<String> alertHoldDurationTakeStashId = redisUtil.keys("AlertHoldDurationTakeStashId");
// for (String takeStashId : alertHoldDurationTakeStashId) { for (String takeStashId : alertHoldDurationTakeStashId) {
// Map<Object, Object> hmget = redisUtil.hmget(takeStashId); Map<Object, Object> hmget = redisUtil.hmget(takeStashId);
// String resultTakeStashId = (String) hmget.get("takeStashId"); String resultTakeStashId = (String) hmget.get("takeStashId");
// String durationId = (String)hmget.get("durationId"); String durationId = (String) hmget.get("durationId");
// AlertHoldDurationRecordExample alertHoldDurationRecordExample = new AlertHoldDurationRecordExample(); //根据TakeStashId查出对应的持仓记录对象
// alertHoldDurationRecordExample.createCriteria().andStashidEqualTo(resultTakeStashId); AlertHoldDurationRecordExample alertHoldDurationRecordExample = new AlertHoldDurationRecordExample();
// List<AlertHoldDuration> alertHoldDurations = alertHoldDurationMapper.selectByExample(alertHoldDurationExample); alertHoldDurationRecordExample.createCriteria().andStashidEqualTo(resultTakeStashId);
// for (AlertHoldDuration alertHoldDuration : alertHoldDurations) { TakeStash takeStash = takeStashMapper.selectByPrimaryKey(resultTakeStashId);
// String wariningHoldDuration = alertHoldDuration.getWariningHoldDuration(); Date timeTransaction = takeStash.getTimeTransaction(); //交易时间
// Date setTime = alertHoldDuration.getSetTime(); String buySellType = takeStash.getBuySellType(); //买卖类型
// Calendar calendar = Calendar.getInstance(); List<AlertHoldDurationRecord> alertHoldDurationRecords = alertHoldDurationRecordMapper.selectByExample(alertHoldDurationRecordExample);
// calendar.setTime(setTime); AlertHoldDurationRecord ahdr = alertHoldDurationRecords.get(0);
// calendar.add(Calendar.DAY_OF_YEAR, Integer.parseInt(wariningHoldDuration));
// //相加后的时间 AlertHoldDuration alertHoldDurations = alertHoldDurationMapper.selectByPrimaryKey(durationId);
// Date time = calendar.getTime(); String wainingHoldDuration = alertHoldDurations.getWariningHoldDuration();
// Timestamp timestamp = new Timestamp(new Date().getTime()); Date setTime = alertHoldDurations.getSetTime();
// if ("当前时间等于或大于预警值就将时间存库然后发送消息给前端"){ Calendar calendar = Calendar.getInstance();
//// TODO 设置记录表的持仓时长和交易时间两个参数 calendar.setTime(setTime);
// // ahdr.setHoldDuration("持仓时长"); calendar.add(Calendar.DAY_OF_YEAR, Integer.parseInt(wainingHoldDuration));
//// ahdr.setWariningTime("预警时间"); //相加后的时间
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
// }
// }
// }
// }
// }
// }
} }

Loading…
Cancel
Save