From 3b946c1e13eae40c21663dc9337ca82f8fce9c57 Mon Sep 17 00:00:00 2001 From: xiaoCJ <406612557@qq.com> Date: Wed, 2 Aug 2023 16:28:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=83=A8=E5=88=86=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/WarningController.java | 75 +++++++++++-------- .../service/WainingService.java | 57 +++++++------- 2 files changed, 75 insertions(+), 57 deletions(-) diff --git a/src/main/java/com/sztzjy/forex/trading_trading/controller/WarningController.java b/src/main/java/com/sztzjy/forex/trading_trading/controller/WarningController.java index 176d550..9769409 100644 --- a/src/main/java/com/sztzjy/forex/trading_trading/controller/WarningController.java +++ b/src/main/java/com/sztzjy/forex/trading_trading/controller/WarningController.java @@ -13,7 +13,8 @@ import io.swagger.annotations.ApiParam; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; -import java.util.List; +import java.sql.Timestamp; +import java.util.*; @Api(tags = "预警页面") @RestController @@ -165,8 +166,11 @@ public class WarningController { //删除持仓时长预警 @DeleteMapping("/deleteAlertHoldDuration") @ApiOperation("删除持仓时长预警") - public String deleteAlertHoldDuration(@ApiParam("id") @RequestParam String id) { - alertHoldDurationMapper.deleteByPrimaryKey(id); + public String deleteAlertHoldDuration(@ApiParam("交易品种") @RequestParam String symbol, + @ApiParam("持仓预警时长") @RequestParam String warningHoldDuration) { + AlertHoldDurationExample alertHoldDurationExample = new AlertHoldDurationExample(); + alertHoldDurationExample.createCriteria().andWariningHoldDurationEqualTo(warningHoldDuration).andSymbolEqualTo(symbol); + alertHoldDurationMapper.deleteByExample(alertHoldDurationExample); return "删除成功"; } @@ -175,17 +179,15 @@ public class WarningController { @PutMapping("/setAlertHoldDuration") @ApiOperation("启用或关闭持仓时长预警") public void setAlertHoldDuration(@ApiParam("0 停用 1 启用") @RequestParam Integer status, - @ApiParam("id") @RequestParam String id) { -// AlertHoldDurationExample alertHoldDurationExample = new AlertHoldDurationExample(); -// alertHoldDurationExample.createCriteria().andSymbolEqualTo(symbol); -// List alertHoldDurations = alertHoldDurationMapper.selectByExample(alertHoldDurationExample); -// for (AlertHoldDuration alertHoldDuration : alertHoldDurations) { -// alertHoldDuration.setStatus(status); -// alertHoldDurationMapper.updateByPrimaryKeySelective(alertHoldDuration); -// } - AlertHoldDuration alertHoldDuration = alertHoldDurationMapper.selectByPrimaryKey(id); - alertHoldDuration.setStatus(status); - alertHoldDurationMapper.updateByPrimaryKeySelective(alertHoldDuration); + @ApiParam("交易品种") @RequestParam String symbol, + @ApiParam("持仓预警时长") @RequestParam String warningHoldDuration) { + AlertHoldDurationExample alertHoldDurationExample = new AlertHoldDurationExample(); + alertHoldDurationExample.createCriteria().andWariningHoldDurationEqualTo(warningHoldDuration).andSymbolEqualTo(symbol); + List alertHoldDurations = alertHoldDurationMapper.selectByExample(alertHoldDurationExample); + for (AlertHoldDuration alertHoldDuration : alertHoldDurations) { + alertHoldDuration.setStatus(status); + alertHoldDurationMapper.updateByPrimaryKeySelective(alertHoldDuration); + } } //删除持仓时长预警记录表 @@ -203,7 +205,7 @@ public class WarningController { @ApiParam("trainingId") @RequestParam String trainingId, @ApiParam("首页页码") @RequestParam Integer index, @ApiParam("页面条数") @RequestParam Integer size) { - PageHelper.startPage(index,size); + PageHelper.startPage(index, size); AlertHoldDurationRecordExample alertHoldDurationRecordExample = new AlertHoldDurationRecordExample(); alertHoldDurationRecordExample.createCriteria().andTrainingidEqualTo(trainingId).andMemberidEqualTo(memberId); List alertHoldDurationRecords = alertHoldDurationRecordMapper.selectByExample(alertHoldDurationRecordExample); @@ -212,7 +214,7 @@ public class WarningController { // if (alertHoldDurationRecord.getWariningHoldDuration() != null && alertHoldDurationRecord.getWariningTime() != null) // resultAHDR.add(alertHoldDurationRecord); // } - PageInfopageInfo = new PageInfo<>(alertHoldDurationRecords); + PageInfo pageInfo = new PageInfo<>(alertHoldDurationRecords); return new ResultEntity<>(pageInfo); } @@ -220,17 +222,26 @@ public class WarningController { @GetMapping("/getAlertHoldDuration") @ApiOperation("查询持仓时长预警表") public ResultEntity> getAlertHoldDuration(@ApiParam("memberId") @RequestParam String memberId, - @ApiParam("trainingId") @RequestParam String trainingId, - @ApiParam("首页页码") @RequestParam Integer index, - @ApiParam("页面条数") @RequestParam Integer size) { - PageHelper.startPage(index,size); + @ApiParam("trainingId") @RequestParam String trainingId, + @ApiParam("首页页码") @RequestParam Integer index, + @ApiParam("页面条数") @RequestParam Integer size) { + PageHelper.startPage(index, size); AlertHoldDurationExample alertHoldDurationExample = new AlertHoldDurationExample(); alertHoldDurationExample.createCriteria().andTrainingidEqualTo(trainingId).andMemberidEqualTo(memberId); List alertHoldDurations = alertHoldDurationMapper.selectByExample(alertHoldDurationExample); -// for (AlertHoldDuration alertHoldDuration : alertHoldDurations) { -// return new ResultEntity<>(alertHoldDurationMapper.selectBySymbol(alertHoldDuration.getSymbol())); -// } - PageInfo pageInfo = new PageInfo<>(alertHoldDurations); + Set uniqueCombinations = new HashSet<>(); // 创建Set集合用于存储唯一的匹配项 + List resultAlertHoldDurations = new ArrayList<>(); // 创建List用于存储不重复的数据 + + for (AlertHoldDuration alertHoldDuration : alertHoldDurations) { + String wariningHoldDuration = alertHoldDuration.getWariningHoldDuration(); + String symbol = alertHoldDuration.getSymbol(); + String uniqueCombination = symbol + wariningHoldDuration; + + if (uniqueCombinations.add(uniqueCombination)) { // 判断是否是新的组合 + resultAlertHoldDurations.add(alertHoldDuration); + } + } + PageInfo pageInfo = new PageInfo<>(resultAlertHoldDurations); return new ResultEntity<>(pageInfo); } @@ -253,10 +264,10 @@ public class WarningController { @GetMapping("/getTransactionNumberWarning") @ApiOperation("交易次数预警查询") public ResultEntity> getTransactionNumberWarning(@ApiParam("memberId") @RequestParam String memberId, - @ApiParam("memberId") @RequestParam String trainingId, - @ApiParam("首页页码") @RequestParam Integer index, - @ApiParam("页面条数") @RequestParam Integer size) { - PageHelper.startPage(index,size); + @ApiParam("memberId") @RequestParam String trainingId, + @ApiParam("首页页码") @RequestParam Integer index, + @ApiParam("页面条数") @RequestParam Integer size) { + PageHelper.startPage(index, size); TransactionNumberWarningExample tnwr = new TransactionNumberWarningExample(); tnwr.createCriteria().andTrainingIdEqualTo(trainingId).andMemberIdEqualTo(memberId); List tnwrs = transactionNumberWarningMapper.selectByExample(tnwr); @@ -279,10 +290,10 @@ public class WarningController { @GetMapping("/getTransactionNumberWarningRecord") @ApiOperation("交易次数预警记录查询") public ResultEntity> getTransactionNumberWarningRecord(@ApiParam("memberId") @RequestParam String memberId, - @ApiParam("memberId") @RequestParam String trainingId, - @ApiParam("首页页码") @RequestParam Integer index, - @ApiParam("页面条数") @RequestParam Integer size) { - PageHelper.startPage(index,size); + @ApiParam("memberId") @RequestParam String trainingId, + @ApiParam("首页页码") @RequestParam Integer index, + @ApiParam("页面条数") @RequestParam Integer size) { + PageHelper.startPage(index, size); TransactionNumberWarningRecordExample tnwre = new TransactionNumberWarningRecordExample(); tnwre.createCriteria().andTrainingIdEqualTo(trainingId).andMemberIdEqualTo(memberId); List tnwrs = transactionNumberWarningRecordMapper.selectByExample(tnwre); diff --git a/src/main/java/com/sztzjy/forex/trading_trading/service/WainingService.java b/src/main/java/com/sztzjy/forex/trading_trading/service/WainingService.java index b4c9d62..4904836 100644 --- a/src/main/java/com/sztzjy/forex/trading_trading/service/WainingService.java +++ b/src/main/java/com/sztzjy/forex/trading_trading/service/WainingService.java @@ -11,6 +11,7 @@ import com.sztzjy.forex.trading_trading.util.ForexMarketDateUtil; import com.sztzjy.forex.trading_trading.util.RedisUtil; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; @@ -240,36 +241,42 @@ public class WainingService { public String addAlertHoldDuration(AlertHoldDuration alertHoldDuration) { String trainingid = alertHoldDuration.getTrainingid(); String symbol = alertHoldDuration.getSymbol(); - TakeStashExample takeStashExample = new TakeStashExample(); - takeStashExample.createCriteria().andTradingCodeEqualTo(symbol).andStatusEqualTo(0); - List takeStashes = takeStashMapper.selectByExample(takeStashExample); - 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); + AlertHoldDurationExample alertHoldDurationExample = new AlertHoldDurationExample(); + alertHoldDurationExample.createCriteria().andSymbolEqualTo(symbol).andWariningHoldDurationEqualTo(alertHoldDuration.getWariningHoldDuration()); + List alertHoldDurations = alertHoldDurationMapper.selectByExample(alertHoldDurationExample); + if (alertHoldDurations.isEmpty()) { + TakeStashExample takeStashExample = new TakeStashExample(); + takeStashExample.createCriteria().andTradingCodeEqualTo(symbol).andStatusEqualTo(0); + List takeStashes = takeStashMapper.selectByExample(takeStashExample); + 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 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 objectObjectHashMap = new HashMap<>(); + objectObjectHashMap.put("takeStashId", stashId); + objectObjectHashMap.put("durationId", durationId); + alertHoldDurationRecordMapper.insert(ahdr); - if (alertHoldDuration.getStatus() == 1) { - redisUtil.hmset("trainingId_" + trainingid + "_AlertHoldDurationTakeStashId" + stashId + "_", objectObjectHashMap); - b(); + if (alertHoldDuration.getStatus() == 1) { + redisUtil.hmset("trainingId_" + trainingid + "_AlertHoldDurationTakeStashId" + stashId + "_", objectObjectHashMap); + b(); + } } } + return "该品种下没有交易记录"; } - return "该品种下没有交易记录"; + return "400 该预警已存在"; } // 持仓时长预警对比定时任务