From 50c5896b715165ddb097e08841f9ec77d69b1bc7 Mon Sep 17 00:00:00 2001 From: yz <3614508250@qq.com> Date: Thu, 27 Jun 2024 17:42:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8C=81=E4=BB=93=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E9=80=BB=E8=BE=91=E3=80=81=E6=96=B0=E5=A2=9E=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=AE=9E=E8=AE=AD=E3=80=81=E4=BF=AE=E6=94=B9=E5=AE=9E?= =?UTF-8?q?=E8=AE=AD=E6=96=B0=E5=8A=9F=E8=83=BD=E3=80=81=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=8F=82=E8=B5=9B=E4=BA=BA=E6=95=B0BUG=20?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=83=A8=E5=88=86=E5=B9=B3=E4=BB=93=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=20=E4=BF=AE=E6=94=B9=E5=88=B7=E6=96=B0=E3=80=81?= =?UTF-8?q?=E7=9B=91=E5=90=AC=E9=97=B4=E9=9A=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/TakeStashController.java | 369 +++++--- .../controller/TrainingController.java | 50 +- .../forex/trading_trading/dto/TrainingBO.java | 3 +- .../trading_trading/entity/Training.java | 142 ++-- .../entity/TrainingExample.java | 94 ++- .../mappers/TrainingMapper.java | 22 +- .../service/ScheduledTask.java | 25 +- src/main/resources/mappers/TrainingMapper.xml | 794 +++++++++--------- 8 files changed, 882 insertions(+), 617 deletions(-) diff --git a/src/main/java/com/sztzjy/forex/trading_trading/controller/TakeStashController.java b/src/main/java/com/sztzjy/forex/trading_trading/controller/TakeStashController.java index 0625d0e..5643437 100644 --- a/src/main/java/com/sztzjy/forex/trading_trading/controller/TakeStashController.java +++ b/src/main/java/com/sztzjy/forex/trading_trading/controller/TakeStashController.java @@ -21,10 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.math.BigDecimal; import java.text.DecimalFormat; @@ -64,28 +61,28 @@ public class TakeStashController { public ResultEntity getTakeStashList(@RequestBody JSONObject jsonObject) { Integer pageIndex = jsonObject.getInteger("index"); Integer pageSize = jsonObject.getInteger("size"); - String trainingStatus=jsonObject.getString("trainingStatus"); + String trainingStatus = jsonObject.getString("trainingStatus"); TakeStash takeStash = jsonObject.getObject("takeStash", TakeStash.class); String trainingId = takeStash.getTrainingId(); - if(trainingId==null || "".equals(trainingId)){ - trainingId=Constant.PRACTICE_TRAINING_ID; + if (trainingId == null || "".equals(trainingId)) { + trainingId = Constant.PRACTICE_TRAINING_ID; } PageInfo pageInfo = takeStashService.findTakeStashByTrainingIdAndMemberIdAndStatus(trainingId, takeStash.getMemberId(), takeStash.getStatus(), pageIndex, pageSize); List takeStashList = pageInfo.getList(); List takeStashVOList = new ArrayList<>(); for (int i = 0; i < takeStashList.size(); i++) { TakeStashVO takeStashVO = new TakeStashVO(takeStashList.get(i)); - if(Constant.TRAINING_STATUS_FINISHED.equals(trainingStatus)){ //实训结束后 + if (Constant.TRAINING_STATUS_FINISHED.equals(trainingStatus)) { //实训结束后 takeStashVO.setCurrentPrice(takeStashList.get(i).getTradingMargin()); //将trading_margin保存到CurrentPrice返回 trading_margin为实训结束后的价格 记录实训结束后实时价格 takeStashVO.setProfitAndLoss(takeStashList.get(i).getProfitAndLossByClose()); //profit_and_loss_by_close 保存实训结束后的盈亏 } takeStashVOList.add(takeStashVO); } - if(!Constant.TRAINING_STATUS_FINISHED.equals(trainingStatus)){ + if (!Constant.TRAINING_STATUS_FINISHED.equals(trainingStatus)) { if (takeStash.getStatus() == 0) { takeStashVOList = flashProfitAndLoss(takeStashVOList).getBody().getData(); } - }else { + } else { } PageInfo voPageInfo = new PageInfo<>(); @@ -134,7 +131,7 @@ public class TakeStashController { profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * Constant.PEACEQUANTITY; takeStashVO.setCurrentPrice(nowSellPic); } else { //卖 - profitAndLoss = (priceTransaction-nowBuyPic) * volumeTransaction * Constant.PEACEQUANTITY; + profitAndLoss = (priceTransaction - nowBuyPic) * volumeTransaction * Constant.PEACEQUANTITY; takeStashVO.setCurrentPrice(nowBuyPic); } } @@ -171,7 +168,7 @@ public class TakeStashController { if (Constant.BUY_BUYSELLTYPE.equals(buySellType)) { //买 profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * Constant.PEACEQUANTITY; } else { //卖 - profitAndLoss = (priceTransaction-nowBuyPic) * volumeTransaction * Constant.PEACEQUANTITY; + profitAndLoss = (priceTransaction - nowBuyPic) * volumeTransaction * Constant.PEACEQUANTITY; } } totalProfitAndLoss = totalProfitAndLoss + profitAndLoss; @@ -192,7 +189,7 @@ public class TakeStashController { ForexMarketData forexData = tradingController.getMarketQuotationByCode(tradingCode).getBody().getData(); TakeStash takeStash = new TakeStash(); takeStash.setStashId(stashId); - boolean flag=false; + boolean flag = false; if (null != stopLoss || null != stopWin) { //判断止损止赢是否合理 如果stopLoss stopWin都为null则跳过 boolean winOrLossStopBoolean = tradingController.getWinOrLossStop(stopLoss, stopWin, buySellType, forexData); if (winOrLossStopBoolean == false) { @@ -200,43 +197,159 @@ public class TakeStashController { } if (null != stopLoss) { takeStash.setStopLoss(stopLoss); - flag=true; + flag = true; } if (null != stopWin) { takeStash.setStopWin(stopWin); - flag=true; + flag = true; } } TakeStash takeStashGet = takeStashService.selectByPrimaryKey(stashId); - if(flag==true){ //代表需要新增到redis中 + if (flag == true) { //代表需要新增到redis中 redisUtil.del("*stashId_" + stashId + "*"); Set keys = redisUtil.keys("*stashId_" + stashId + "*"); - Map map=new HashMap(); - if(stopLoss==null){ - map.put("stopLoss",-1.0); - }else { - map.put("stopLoss",stopLoss); + Map map = new HashMap(); + if (stopLoss == null) { + map.put("stopLoss", -1.0); + } else { + map.put("stopLoss", stopLoss); } - if(stopWin==null){ - map.put("stopWin",-1.0); - }else { - map.put("stopWin",stopWin); + if (stopWin == null) { + map.put("stopWin", -1.0); + } else { + map.put("stopWin", stopWin); } - map.put("stashId",stashId); - map.put("buySellType",buySellType); - map.put("tradingCode",tradingCode); - map.put("transactionVolume",takeStashGet.getVolumeTransaction()); - map.put("priceTransaction",takeStashGet.getPriceTransaction()); - map.put("memberId",takeStashGet.getMemberId()); - map.put("trainingId",takeStashGet.getTrainingId()); - redisUtil.hmset("trainingId_"+takeStashGet.getTrainingId()+"_stashId_"+stashId,map); - }else { - redisUtil.del("trainingId_"+takeStashGet.getTrainingId()+"_stashId_"+stashId); + map.put("stashId", stashId); + map.put("buySellType", buySellType); + map.put("tradingCode", tradingCode); + map.put("transactionVolume", takeStashGet.getVolumeTransaction()); + map.put("priceTransaction", takeStashGet.getPriceTransaction()); + map.put("memberId", takeStashGet.getMemberId()); + map.put("trainingId", takeStashGet.getTrainingId()); + redisUtil.hmset("trainingId_" + takeStashGet.getTrainingId() + "_stashId_" + stashId, map); + } else { + redisUtil.del("trainingId_" + takeStashGet.getTrainingId() + "_stashId_" + stashId); } takeStashService.updateWinLossByPrimaryKey(takeStash); return new ResultEntity(HttpStatus.OK, "修改持仓成功"); } + //当前持仓部分平仓 + //1生成新的历史记录 + //2修改该持仓的持仓量 + @AnonymousAccess + @PostMapping("sectionCloseTakeStash") + public ResultEntity sectionCloseTakeStash(@RequestBody JSONObject jsonObject, @RequestParam Double volumeTransaction) { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + return new ResultEntity(HttpStatus.BAD_REQUEST, "请稍后再试"); + } + String stashId = jsonObject.getString("stashId"); + String memberId = jsonObject.getString("memberId"); + TakeStash takeStashNew = takeStashService.selectByPrimaryKey(stashId); + Member member = memberService.selectByPrimaryKey(memberId); + String buySellType = takeStashNew.getBuySellType(); + String tradingCode = takeStashNew.getTradingCode(); + if (volumeTransaction.compareTo(takeStashNew.getVolumeTransaction()) >= 0 || volumeTransaction <= 0) { + return new ResultEntity(HttpStatus.BAD_REQUEST, "部分平仓交易量有误"); + } +// Double volumeTransaction = takeStashNew.getVolumeTransaction(); + Double priceTransaction = takeStashNew.getPriceTransaction(); //获取进仓时交易价格 + String trainingId = takeStashNew.getTrainingId(); + Double priceTransactionCloser = 0.0; //记录出仓时交易价格 + ForexMarketData forexData = forexMarketDateUtil.getForexMarketDateByCode(tradingCode); + Double profitAndLoss = 0.0; //盈亏 + Double nowSellPic = Double.valueOf(forexData.getSellPic());//当前卖价 + Double nowBuyPic = forexData.getBuyPic(); //当前买价 + Double margin = 0.0; //记录保证金变化量 + if (tradingCode.startsWith("USD")) { //美元在前 返还资金表达式为 + //可用保证金计算 + margin = startUSDMarginNeed(trainingId, memberId, 0, tradingCode, buySellType, volumeTransaction); + if (Constant.BUY_BUYSELLTYPE.equals(buySellType)) { //如果持仓方向为买 则平仓方向为卖 + priceTransactionCloser = nowSellPic; + profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * Constant.PEACEQUANTITY / nowSellPic; + } else if (Constant.SELL_BUYSELLTYPE.equals(buySellType)) { //如果持仓方向为卖 则平仓方向为买 可用资金=可用资金+当前买价*1000*买卖手 + priceTransactionCloser = nowBuyPic; + profitAndLoss = (priceTransaction - nowBuyPic) * volumeTransaction * Constant.PEACEQUANTITY / nowBuyPic; + } + } else { //美元在后 + margin = endUSDMarginNeed(trainingId, memberId, 0, tradingCode, buySellType, takeStashNew.getVolumeTransaction(), priceTransaction); + if (Constant.BUY_BUYSELLTYPE.equals(buySellType)) { //如果持仓方向为买 则平仓方向为卖 可用资金=可用资金+1000*买卖手 + priceTransactionCloser = nowSellPic; + profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * Constant.PEACEQUANTITY; + } else if (Constant.SELL_BUYSELLTYPE.equals(buySellType)) { //如果持仓方向为卖 则平仓方向为买 可用资金=可用资金+当前买价*1000*买卖手 + priceTransactionCloser = nowBuyPic; + profitAndLoss = (priceTransaction - nowBuyPic) * volumeTransaction * Constant.PEACEQUANTITY; + } + } + + Double marginUsed = member.getMarginUsed();//未修改前member表中成员保证金 + marginUsed = bigDecimalUtils.mul(marginUsed - margin, 1, 2); //修改成员保证金 + //处理保证金为负数的情况和保证金未释放的情况 + List takeStashList = takeStashService.selectAllByMemberIdAndStatus(memberId, 0); + if (takeStashList == null || takeStashList.size() == 0 || takeStashList.size() == 1) { + marginUsed = 0.0; + } + if (marginUsed < 0) { + marginUsed = 0.0; + } + member.setMarginUsed(marginUsed); + Integer closingTrades = member.getClosingTrades(); + if (closingTrades == null) { + closingTrades = 1; + } + member.setClosingTrades(closingTrades++); + Double cumulativeProfitLoss = member.getCumulativeProfitLoss(); //为修改前member表中的累积盈亏 + cumulativeProfitLoss = cumulativeProfitLoss + profitAndLoss; + member.setCumulativeProfitLoss(bigDecimalUtils.mul(cumulativeProfitLoss, 1, 2)); //修改累计盈亏 + member.setYield(bigDecimalUtils.div(cumulativeProfitLoss, member.getInitialCapital(), 8)); //修改收益率 + memberService.updateByPrimaryKeySelective(member); + flashTotalPositionProfitLoss(member.getMemberId()); + + + //修改部分平仓的持有量 + TakeStash takeStash = new TakeStash(); + takeStash.setStashId(stashId); + takeStash.setVolumeTransaction(bigDecimalUtils.sub(takeStashNew.getVolumeTransaction(), volumeTransaction)); + takeStashService.updateByPrimaryKeySelective(takeStash); + + takeStashNew.setStashId(String.valueOf(UUID.randomUUID())); + takeStashNew.setOrderNumber(String.valueOf(UUID.randomUUID())); + takeStashNew.setStatus(2); + takeStashNew.setPriceTransactionClose(priceTransactionCloser); + takeStashNew.setProfitAndLossByClose(bigDecimalUtils.mul(profitAndLoss, 1, 2)); + takeStashNew.setTimeTransactionClose(new Date()); + takeStashService.updateByPrimaryKeySelective(takeStashNew); + redisUtil.del("trainingId_" + takeStashNew.getTrainingId() + "_stashId_" + stashId); + + //判断该持仓是否有止损止盈 + if (takeStashNew.getStopLoss() != null || takeStashNew.getStopWin() != null) { + Map map = new HashMap(); + if (takeStashNew.getStopLoss() == null) { + map.put("stopLoss", -1.0); + } else { + map.put("stopLoss", takeStashNew.getStopLoss()); + } + if (takeStashNew.getStopWin() == null) { + map.put("stopWin", -1.0); + } else { + map.put("stopWin", takeStashNew.getStopWin()); + } + map.put("stashId", stashId); + map.put("buySellType", buySellType); + map.put("tradingCode", takeStashNew.getTradingCode()); + map.put("transactionVolume", bigDecimalUtils.mul(profitAndLoss, 1, 2)); + map.put("priceTransaction", takeStashNew.getPriceTransaction()); + map.put("memberId", memberId); + map.put("trainingId", trainingId); + redisUtil.hmset("trainingId_" + trainingId + "_stashId_" + stashId, map); + } +// wainingService.compareMarginLevels(member.getMemberId(), member.getTrainingId());//更改可用保证金后 调用预警 + + return new ResultEntity(HttpStatus.OK, "平仓成功"); + } + //当前持仓平仓 status设置为2 @Transactional @@ -261,10 +374,10 @@ public class TakeStashController { Double profitAndLoss = 0.0; //盈亏 Double nowSellPic = Double.valueOf(forexData.getSellPic());//当前卖价 Double nowBuyPic = forexData.getBuyPic(); //当前买价 - Double margin=0.0; //记录保证金变化量 + Double margin = 0.0; //记录保证金变化量 if (tradingCode.startsWith("USD")) { //美元在前 返还资金表达式为 //可用保证金计算 - margin = startUSDMarginNeed(trainingId,memberId,0,tradingCode,buySellType,volumeTransaction); + margin = startUSDMarginNeed(trainingId, memberId, 0, tradingCode, buySellType, volumeTransaction); if (Constant.BUY_BUYSELLTYPE.equals(buySellType)) { //如果持仓方向为买 则平仓方向为卖 priceTransactionCloser = nowSellPic; profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * Constant.PEACEQUANTITY / nowSellPic; @@ -273,36 +386,36 @@ public class TakeStashController { profitAndLoss = (priceTransaction - nowBuyPic) * volumeTransaction * Constant.PEACEQUANTITY / nowBuyPic; } } else { //美元在后 - margin =endUSDMarginNeed(trainingId,memberId,0,tradingCode,buySellType,takeStashNew.getVolumeTransaction(),priceTransaction); + margin = endUSDMarginNeed(trainingId, memberId, 0, tradingCode, buySellType, takeStashNew.getVolumeTransaction(), priceTransaction); if (Constant.BUY_BUYSELLTYPE.equals(buySellType)) { //如果持仓方向为买 则平仓方向为卖 可用资金=可用资金+1000*买卖手 priceTransactionCloser = nowSellPic; profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * Constant.PEACEQUANTITY; } else if (Constant.SELL_BUYSELLTYPE.equals(buySellType)) { //如果持仓方向为卖 则平仓方向为买 可用资金=可用资金+当前买价*1000*买卖手 priceTransactionCloser = nowBuyPic; - profitAndLoss = ( priceTransaction - nowBuyPic ) * volumeTransaction * Constant.PEACEQUANTITY; + profitAndLoss = (priceTransaction - nowBuyPic) * volumeTransaction * Constant.PEACEQUANTITY; } } Double marginUsed = member.getMarginUsed();//未修改前member表中成员保证金 - marginUsed = bigDecimalUtils.mul(marginUsed-margin,1,2); //修改成员保证金 + marginUsed = bigDecimalUtils.mul(marginUsed - margin, 1, 2); //修改成员保证金 //处理保证金为负数的情况和保证金未释放的情况 List takeStashList = takeStashService.selectAllByMemberIdAndStatus(memberId, 0); - if (takeStashList==null || takeStashList.size()==0 || takeStashList.size()==1){ - marginUsed=0.0; + if (takeStashList == null || takeStashList.size() == 0 || takeStashList.size() == 1) { + marginUsed = 0.0; } - if(marginUsed<0){ - marginUsed=0.0; + if (marginUsed < 0) { + marginUsed = 0.0; } member.setMarginUsed(marginUsed); Integer closingTrades = member.getClosingTrades(); - if(closingTrades==null){ - closingTrades=1; + if (closingTrades == null) { + closingTrades = 1; } member.setClosingTrades(closingTrades++); Double cumulativeProfitLoss = member.getCumulativeProfitLoss(); //为修改前member表中的累积盈亏 - cumulativeProfitLoss=cumulativeProfitLoss+profitAndLoss; - member.setCumulativeProfitLoss(bigDecimalUtils.mul(cumulativeProfitLoss,1,2)); //修改累计盈亏 - member.setYield(bigDecimalUtils.div(cumulativeProfitLoss,member.getInitialCapital(),8)); //修改收益率 + cumulativeProfitLoss = cumulativeProfitLoss + profitAndLoss; + member.setCumulativeProfitLoss(bigDecimalUtils.mul(cumulativeProfitLoss, 1, 2)); //修改累计盈亏 + member.setYield(bigDecimalUtils.div(cumulativeProfitLoss, member.getInitialCapital(), 8)); //修改收益率 memberService.updateByPrimaryKeySelective(member); flashTotalPositionProfitLoss(member.getMemberId()); @@ -311,10 +424,10 @@ public class TakeStashController { takeStash.setStashId(stashId); takeStash.setStatus(2); takeStash.setPriceTransactionClose(priceTransactionCloser); - takeStash.setProfitAndLossByClose(bigDecimalUtils.mul(profitAndLoss,1,2)); + takeStash.setProfitAndLossByClose(bigDecimalUtils.mul(profitAndLoss, 1, 2)); takeStash.setTimeTransactionClose(new Date()); takeStashService.updateByPrimaryKeySelective(takeStash); - redisUtil.del("trainingId_"+takeStashNew.getTrainingId()+"_stashId_"+stashId); + redisUtil.del("trainingId_" + takeStashNew.getTrainingId() + "_stashId_" + stashId); // wainingService.compareMarginLevels(member.getMemberId(), member.getTrainingId());//更改可用保证金后 调用预警 @@ -322,130 +435,130 @@ public class TakeStashController { } //美元在后 返回保证金变化量 公式((sell交易量*交易价格+sell交易量*价格+...)/交易总量+(buy交易量*交易价格+buy交易量*价格+...)/交易总量)*合约量/杠杆倍数*sellbuy最高交易量 - public Double endUSDMarginNeed(String trainingId,String memberId,int status,String tradingCode,String buySellType,Double transactionVolume,Double priceTransaction){ - Double margin=0.0; + public Double endUSDMarginNeed(String trainingId, String memberId, int status, String tradingCode, String buySellType, Double transactionVolume, Double priceTransaction) { + Double margin = 0.0; //获取持仓表中tradingCode所有buysell情况 根据trainingId和memberId查询交易品种=tradingCode的所有数据 - List takeStashList=takeStashService.findTakeStashByTrainingIdAndMemberIdAndStatusAndTradingCode(trainingId,memberId,status,tradingCode); - Double buyTotalMargin=0.0; //类型为买的 交易量*交易价格之和 - Double sellTotalMargin=0.0; //类型为卖的 交易量*交易价格之和 - Double totalVolumeTransaction=0.0; //交易总量 - Double buyTotalVolumeTransaction=0.0; //buy类型交易总量 - Double sellTotalVolumeTransaction=0.0; //sell类型交易总量 - Double highVolumeTransaction=0.0; //记录buy/sell类型交易总量中较高的一个 - if(takeStashList.size()==1){ - if(Constant.BUY_BUYSELLTYPE.equals(buySellType)){ - margin=transactionVolume*priceTransaction*Constant.LEVERQUANTITY; - }else { - margin=transactionVolume*priceTransaction*Constant.LEVERQUANTITY; + List takeStashList = takeStashService.findTakeStashByTrainingIdAndMemberIdAndStatusAndTradingCode(trainingId, memberId, status, tradingCode); + Double buyTotalMargin = 0.0; //类型为买的 交易量*交易价格之和 + Double sellTotalMargin = 0.0; //类型为卖的 交易量*交易价格之和 + Double totalVolumeTransaction = 0.0; //交易总量 + Double buyTotalVolumeTransaction = 0.0; //buy类型交易总量 + Double sellTotalVolumeTransaction = 0.0; //sell类型交易总量 + Double highVolumeTransaction = 0.0; //记录buy/sell类型交易总量中较高的一个 + if (takeStashList.size() == 1) { + if (Constant.BUY_BUYSELLTYPE.equals(buySellType)) { + margin = transactionVolume * priceTransaction * Constant.LEVERQUANTITY; + } else { + margin = transactionVolume * priceTransaction * Constant.LEVERQUANTITY; } return margin; - }else if(takeStashList.size()>1){ + } else if (takeStashList.size() > 1) { for (int i = 0; i < takeStashList.size(); i++) { TakeStash takeStash = takeStashList.get(i); String buySellTypeTakeStash = takeStash.getBuySellType(); Double volumeTransactionTakeStash = takeStash.getVolumeTransaction(); //持仓交易量 Double priceTransactionTakeStash = takeStash.getPriceTransaction(); //持仓交易价格 - if(Constant.BUY_BUYSELLTYPE.equals(buySellTypeTakeStash)){ - buyTotalMargin=buyTotalMargin+volumeTransactionTakeStash*priceTransactionTakeStash; - buyTotalVolumeTransaction=buyTotalVolumeTransaction+volumeTransactionTakeStash; - }else { - sellTotalMargin=sellTotalMargin+volumeTransactionTakeStash*priceTransactionTakeStash; - sellTotalVolumeTransaction=sellTotalVolumeTransaction+volumeTransactionTakeStash; + if (Constant.BUY_BUYSELLTYPE.equals(buySellTypeTakeStash)) { + buyTotalMargin = buyTotalMargin + volumeTransactionTakeStash * priceTransactionTakeStash; + buyTotalVolumeTransaction = buyTotalVolumeTransaction + volumeTransactionTakeStash; + } else { + sellTotalMargin = sellTotalMargin + volumeTransactionTakeStash * priceTransactionTakeStash; + sellTotalVolumeTransaction = sellTotalVolumeTransaction + volumeTransactionTakeStash; } - totalVolumeTransaction=totalVolumeTransaction+volumeTransactionTakeStash; + totalVolumeTransaction = totalVolumeTransaction + volumeTransactionTakeStash; } - }else { + } else { return 0.0; } - if (buyTotalVolumeTransaction>=sellTotalVolumeTransaction){ //设置平仓前 sell\buy的最高交易交易总量 - highVolumeTransaction=buyTotalVolumeTransaction; - }else { - highVolumeTransaction=sellTotalVolumeTransaction; + if (buyTotalVolumeTransaction >= sellTotalVolumeTransaction) { //设置平仓前 sell\buy的最高交易交易总量 + highVolumeTransaction = buyTotalVolumeTransaction; + } else { + highVolumeTransaction = sellTotalVolumeTransaction; } //获取相同tradingCode持仓表总使用保证金 - Double totalMargin=(buyTotalMargin+sellTotalMargin)/totalVolumeTransaction*Constant.LEVERQUANTITY*highVolumeTransaction; + Double totalMargin = (buyTotalMargin + sellTotalMargin) / totalVolumeTransaction * Constant.LEVERQUANTITY * highVolumeTransaction; //获取去除平仓数据后的相同tradingCode持仓表总使用保证金 - if(Constant.BUY_BUYSELLTYPE.equals(buySellType)){ - if (buyTotalVolumeTransaction-transactionVolume>=sellTotalVolumeTransaction){ //设置平仓后 sell\buy的最高交易交易总量 - highVolumeTransaction=buyTotalVolumeTransaction; - }else { - highVolumeTransaction=sellTotalVolumeTransaction; + if (Constant.BUY_BUYSELLTYPE.equals(buySellType)) { + if (buyTotalVolumeTransaction - transactionVolume >= sellTotalVolumeTransaction) { //设置平仓后 sell\buy的最高交易交易总量 + highVolumeTransaction = buyTotalVolumeTransaction; + } else { + highVolumeTransaction = sellTotalVolumeTransaction; } - }else { - if ( sellTotalVolumeTransaction-transactionVolume>=buyTotalVolumeTransaction){ //设置平仓后 sell\buy的最高交易交易总量 - highVolumeTransaction=sellTotalVolumeTransaction; - }else { - highVolumeTransaction=buyTotalVolumeTransaction; + } else { + if (sellTotalVolumeTransaction - transactionVolume >= buyTotalVolumeTransaction) { //设置平仓后 sell\buy的最高交易交易总量 + highVolumeTransaction = sellTotalVolumeTransaction; + } else { + highVolumeTransaction = buyTotalVolumeTransaction; } } - Double totalMarginRemoveCloseTakeStash=0.0; - totalMarginRemoveCloseTakeStash=(buyTotalMargin+sellTotalMargin-transactionVolume*priceTransaction)/(totalVolumeTransaction-transactionVolume)*Constant.LEVERQUANTITY*highVolumeTransaction; - margin=totalMargin-totalMarginRemoveCloseTakeStash; + Double totalMarginRemoveCloseTakeStash = 0.0; + totalMarginRemoveCloseTakeStash = (buyTotalMargin + sellTotalMargin - transactionVolume * priceTransaction) / (totalVolumeTransaction - transactionVolume) * Constant.LEVERQUANTITY * highVolumeTransaction; + margin = totalMargin - totalMarginRemoveCloseTakeStash; return margin; } //美元在前 返回保证金变化量 - public Double startUSDMarginNeed(String trainingId,String memberId,int status,String tradingCode,String buySellType,Double transactionVolume){ - Double margin=0.0; + public Double startUSDMarginNeed(String trainingId, String memberId, int status, String tradingCode, String buySellType, Double transactionVolume) { + Double margin = 0.0; //获取持仓表中tradingCode所有buysell情况 根据trainingId和memberId查询交易品种=tradingCode的所有数据 - List takeStashList=takeStashService.findTakeStashByTrainingIdAndMemberIdAndStatusAndTradingCode(trainingId,memberId,status,tradingCode); - Double buyTotalVolumeTransaction=0.0; - Double sellTotalVolumeTransaction=0.0; - if(takeStashList.size()==1){ - margin=transactionVolume*Constant.LEVERQUANTITY; + List takeStashList = takeStashService.findTakeStashByTrainingIdAndMemberIdAndStatusAndTradingCode(trainingId, memberId, status, tradingCode); + Double buyTotalVolumeTransaction = 0.0; + Double sellTotalVolumeTransaction = 0.0; + if (takeStashList.size() == 1) { + margin = transactionVolume * Constant.LEVERQUANTITY; return margin; - }else if (takeStashList.size()>1){ + } else if (takeStashList.size() > 1) { for (int i = 0; i < takeStashList.size(); i++) { TakeStash takeStash = takeStashList.get(i); String buySellTypeTakeStash = takeStash.getBuySellType(); - if(Constant.BUY_BUYSELLTYPE.equals(buySellTypeTakeStash)){ - buyTotalVolumeTransaction=buyTotalVolumeTransaction+takeStash.getVolumeTransaction(); - }else { - sellTotalVolumeTransaction=sellTotalVolumeTransaction+takeStash.getVolumeTransaction(); + if (Constant.BUY_BUYSELLTYPE.equals(buySellTypeTakeStash)) { + buyTotalVolumeTransaction = buyTotalVolumeTransaction + takeStash.getVolumeTransaction(); + } else { + sellTotalVolumeTransaction = sellTotalVolumeTransaction + takeStash.getVolumeTransaction(); } } - }else { - margin=0.0; + } else { + margin = 0.0; } - if(Constant.BUY_BUYSELLTYPE.equals(buySellType)){ - if(buyTotalVolumeTransaction>=sellTotalVolumeTransaction){ - if(buyTotalVolumeTransaction-transactionVolume>=sellTotalVolumeTransaction){ - margin=transactionVolume*Constant.LEVERQUANTITY; - }else { - margin=(buyTotalVolumeTransaction-sellTotalVolumeTransaction)*Constant.LEVERQUANTITY; + if (Constant.BUY_BUYSELLTYPE.equals(buySellType)) { + if (buyTotalVolumeTransaction >= sellTotalVolumeTransaction) { + if (buyTotalVolumeTransaction - transactionVolume >= sellTotalVolumeTransaction) { + margin = transactionVolume * Constant.LEVERQUANTITY; + } else { + margin = (buyTotalVolumeTransaction - sellTotalVolumeTransaction) * Constant.LEVERQUANTITY; } - }else { - margin=0.0; + } else { + margin = 0.0; } - }else { - if(sellTotalVolumeTransaction>=buyTotalVolumeTransaction){ - if(sellTotalVolumeTransaction-transactionVolume>=buyTotalVolumeTransaction){ - margin=transactionVolume*Constant.LEVERQUANTITY; - }else { - margin=(sellTotalVolumeTransaction-buyTotalVolumeTransaction)*Constant.LEVERQUANTITY; + } else { + if (sellTotalVolumeTransaction >= buyTotalVolumeTransaction) { + if (sellTotalVolumeTransaction - transactionVolume >= buyTotalVolumeTransaction) { + margin = transactionVolume * Constant.LEVERQUANTITY; + } else { + margin = (sellTotalVolumeTransaction - buyTotalVolumeTransaction) * Constant.LEVERQUANTITY; } - }else { - margin=0.0; + } else { + margin = 0.0; } } return margin; } - public void updateMemberAndTakeStash(String memberId, String stashId , Double profitLoss,Double margin,Double priceTransactionCloser) { //margin平仓后保证金变化量 + public void updateMemberAndTakeStash(String memberId, String stashId, Double profitLoss, Double margin, Double priceTransactionCloser) { //margin平仓后保证金变化量 Member member = memberService.selectByPrimaryKey(memberId); Double marginUsed = member.getMarginUsed();//未修改前member表中成员保证金 marginUsed = bigDecimalUtils.sub(marginUsed, margin); //修改成员保证金 - member.setMarginUsed(bigDecimalUtils.mul(marginUsed,1,2)); + member.setMarginUsed(bigDecimalUtils.mul(marginUsed, 1, 2)); Integer closingTrades = member.getClosingTrades(); member.setClosingTrades(closingTrades++); Double cumulativeProfitLoss = member.getCumulativeProfitLoss(); //为修改前member表中的累积盈亏 - cumulativeProfitLoss=bigDecimalUtils.add(cumulativeProfitLoss, profitLoss); - member.setCumulativeProfitLoss(bigDecimalUtils.mul(cumulativeProfitLoss,1,2)); //修改累计盈亏 - member.setYield(bigDecimalUtils.mul(bigDecimalUtils.div(cumulativeProfitLoss,member.getInitialCapital()),1,8)); //修改收益率 + cumulativeProfitLoss = bigDecimalUtils.add(cumulativeProfitLoss, profitLoss); + member.setCumulativeProfitLoss(bigDecimalUtils.mul(cumulativeProfitLoss, 1, 2)); //修改累计盈亏 + member.setYield(bigDecimalUtils.mul(bigDecimalUtils.div(cumulativeProfitLoss, member.getInitialCapital()), 1, 8)); //修改收益率 memberService.updateByPrimaryKeySelective(member); flashTotalPositionProfitLoss(member.getMemberId()); @@ -453,7 +566,7 @@ public class TakeStashController { takeStash.setStashId(stashId); takeStash.setStatus(2); takeStash.setPriceTransactionClose(priceTransactionCloser); - takeStash.setProfitAndLossByClose(bigDecimalUtils.mul(profitLoss,1,2)); //盈亏=返还资金-进仓时使用的保证金 + takeStash.setProfitAndLossByClose(bigDecimalUtils.mul(profitLoss, 1, 2)); //盈亏=返还资金-进仓时使用的保证金 takeStash.setTimeTransactionClose(new Date()); takeStashService.updateByPrimaryKeySelective(takeStash); diff --git a/src/main/java/com/sztzjy/forex/trading_trading/controller/TrainingController.java b/src/main/java/com/sztzjy/forex/trading_trading/controller/TrainingController.java index c0c2f78..dcaa3d8 100644 --- a/src/main/java/com/sztzjy/forex/trading_trading/controller/TrainingController.java +++ b/src/main/java/com/sztzjy/forex/trading_trading/controller/TrainingController.java @@ -10,9 +10,11 @@ import com.sztzjy.forex.trading_trading.config.Constant; import com.sztzjy.forex.trading_trading.config.security.JwtUser; import com.sztzjy.forex.trading_trading.config.security.TokenProvider; import com.sztzjy.forex.trading_trading.dto.TrainingBO; -import com.sztzjy.forex.trading_trading.entity.GradeWeight; -import com.sztzjy.forex.trading_trading.entity.Member; -import com.sztzjy.forex.trading_trading.entity.Training; +import com.sztzjy.forex.trading_trading.entity.*; +import com.sztzjy.forex.trading_trading.mappers.MarginWarningMapper; +import com.sztzjy.forex.trading_trading.mappers.MarketWarningMapper; +import com.sztzjy.forex.trading_trading.mappers.MemberMapper; +import com.sztzjy.forex.trading_trading.mappers.TrainingMapper; import com.sztzjy.forex.trading_trading.service.GradeWeightService; import com.sztzjy.forex.trading_trading.service.MemberService; import com.sztzjy.forex.trading_trading.service.TrainingService; @@ -49,7 +51,15 @@ public class TrainingController { private final GradeWeightService gradeWeightService; @Autowired + MarginWarningMapper marginWarningMapper; + @Autowired + MarketWarningMapper marketWarningMapper; + @Autowired RedisUtil redisUtil; + @Autowired + TrainingMapper trainingMapper; + @Autowired + MemberMapper memberMapper; @Permission(codes = PermissionType.TRAINING_MANAGEMENT_ADD) @@ -68,6 +78,7 @@ public class TrainingController { studentInfos.addAll(bo.getAddUserInfos()); } List members = buildMembers(studentInfos, training); +// List members = buildMembers(studentInfos, training); if (members != null && members.size() > 0) memberService.insertAll(members); training.setPeopleCount(members.size()); GradeWeight gradeWeight = gradeWeightService.findBySchoolId(currentUser.getSchoolId()) == null @@ -88,7 +99,16 @@ public class TrainingController { @ApiOperation("教师端----删除指定实训记录") @PostMapping("deleteById") public ResultEntity deleteById(@ApiParam("实训记录id") @RequestParam String trainingId) { + if(Constant.PRACTICE_TRAINING_ID.equals(trainingId)){ + return new ResultEntity(HttpStatus.BAD_REQUEST,"删除异常"); + } trainingService.delete(trainingId); + MarginWarningExample marginWarningExample = new MarginWarningExample(); + marginWarningExample.createCriteria().andTrainingidEqualTo(trainingId); + marginWarningMapper.deleteByExample(marginWarningExample); + MarketWarningExample marketWarningExample = new MarketWarningExample(); + marketWarningExample.createCriteria().andTariningidEqualTo(trainingId); + marketWarningMapper.deleteByExample(marketWarningExample); //TODO 同步删除member表数据 // memberService return new ResultEntity(HttpStatus.OK); @@ -105,6 +125,23 @@ public class TrainingController { return new ResultEntity(HttpStatus.OK); } + @ApiOperation("教师端----修改实训结束日期") + @PostMapping("updateTrainingEndTime") + public ResultEntity updateTrainingEndTime(@ApiParam("实训记录id") @RequestParam String trainingId, + @ApiParam("实训结束日期") @RequestParam Long endTime) { + Training training = trainingMapper.selectByPrimaryKey(trainingId); + if(training==null){ + return new ResultEntity(HttpStatus.OK,"实训不存在"); + } + if(Constant.TRAINING_STATUS_FINISHED.equals(training.getStatus())){ + return new ResultEntity(HttpStatus.BAD_REQUEST,"该实训已结束"); + } + Date date = new Date(endTime); + training.setEndTime(date); + trainingMapper.updateByPrimaryKey(training); + return new ResultEntity(HttpStatus.OK); + } + @Permission(codes = PermissionType.TRAINING_MANAGEMENT_SEARCH) @ApiOperation("教师端----根据实训记录id查询实训记录") @@ -234,7 +271,7 @@ public class TrainingController { member.setMajor(String.valueOf(map.get("majorName"))); member.setStudentNumber(String.valueOf(map.get("studentNo"))); member.setTrainingName(training.getTrainingName()); - member.setInitialCapital(1000000.0); + member.setInitialCapital(training.getInitialCapital()); member.setMarginUsed(0.0); member.setCumulativeProfitLoss(0.0); member.setOpeningTrades(0); @@ -309,7 +346,12 @@ public class TrainingController { if(resultInfos==null||resultInfos.size()==0){ return new ResultEntity(HttpStatus.OK,new ArrayList<>()); } + //更新参数人数 memberService.insertAll(buildMembers(resultInfos, training)); + int peopleCount = training.getPeopleCount(); + int stuSize = resultInfos.size(); + training.setPeopleCount(peopleCount+stuSize); + trainingMapper.updateByPrimaryKey(training); memberService.deleteMembersByTrainingIdNotInStudentInfos(trainingId,studentNos); return new ResultEntity(HttpStatus.OK, insertNames); } diff --git a/src/main/java/com/sztzjy/forex/trading_trading/dto/TrainingBO.java b/src/main/java/com/sztzjy/forex/trading_trading/dto/TrainingBO.java index f868d72..28c1d8e 100644 --- a/src/main/java/com/sztzjy/forex/trading_trading/dto/TrainingBO.java +++ b/src/main/java/com/sztzjy/forex/trading_trading/dto/TrainingBO.java @@ -33,5 +33,6 @@ public class TrainingBO { private List classId; @ApiModelProperty("单个新增的用户信息") private List> addUserInfos; - + @ApiModelProperty("初始资金") + private Double initial; } diff --git a/src/main/java/com/sztzjy/forex/trading_trading/entity/Training.java b/src/main/java/com/sztzjy/forex/trading_trading/entity/Training.java index ece643f..8c16525 100644 --- a/src/main/java/com/sztzjy/forex/trading_trading/entity/Training.java +++ b/src/main/java/com/sztzjy/forex/trading_trading/entity/Training.java @@ -16,9 +16,8 @@ public class Training { * This field was generated by MyBatis Generator. * This field corresponds to the database column sys_training.training_id * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ - @ApiModelProperty("任务id") private String trainingId; /** @@ -26,9 +25,8 @@ public class Training { * This field was generated by MyBatis Generator. * This field corresponds to the database column sys_training.people_count * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ - @ApiModelProperty("当前实训人数") private Integer peopleCount; /** @@ -36,9 +34,8 @@ public class Training { * This field was generated by MyBatis Generator. * This field corresponds to the database column sys_training.start_time * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ - @ApiModelProperty("实训开始日期") private Date startTime; /** @@ -46,9 +43,8 @@ public class Training { * This field was generated by MyBatis Generator. * This field corresponds to the database column sys_training.end_time * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ - @ApiModelProperty("实训结束日期") private Date endTime; /** @@ -56,9 +52,8 @@ public class Training { * This field was generated by MyBatis Generator. * This field corresponds to the database column sys_training.status * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ - @ApiModelProperty("实训状态 NOT_STARTED:未开始,ONGOING:进行中,FINISHED:已结束") private String status; /** @@ -66,9 +61,8 @@ public class Training { * This field was generated by MyBatis Generator. * This field corresponds to the database column sys_training.creator_id * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ - @ApiModelProperty("实训创建人id") private Integer creatorId; /** @@ -76,9 +70,8 @@ public class Training { * This field was generated by MyBatis Generator. * This field corresponds to the database column sys_training.create_school * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ - @ApiModelProperty("实训创建人所属学校") private String createSchool; /** @@ -86,9 +79,8 @@ public class Training { * This field was generated by MyBatis Generator. * This field corresponds to the database column sys_training.training_name * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ - @ApiModelProperty("实训名称") private String trainingName; /** @@ -96,9 +88,8 @@ public class Training { * This field was generated by MyBatis Generator. * This field corresponds to the database column sys_training.creator_name * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ - @ApiModelProperty("实训创建人姓名") private String creatorName; /** @@ -106,9 +97,8 @@ public class Training { * This field was generated by MyBatis Generator. * This field corresponds to the database column sys_training.create_time * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ - @ApiModelProperty("实训创建时间") private Date createTime; /** @@ -116,9 +106,8 @@ public class Training { * This field was generated by MyBatis Generator. * This field corresponds to the database column sys_training.update_time * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ - @ApiModelProperty("实训更新时间") private Date updateTime; /** @@ -126,9 +115,8 @@ public class Training { * This field was generated by MyBatis Generator. * This field corresponds to the database column sys_training.school_id * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ - @ApiModelProperty("实训所属学校id") private Integer schoolId; /** @@ -136,18 +124,26 @@ public class Training { * This field was generated by MyBatis Generator. * This field corresponds to the database column sys_training.weight_id * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ - @ApiModelProperty("实训所引用的权重id:学生收益率评分规则") private String weightId; + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column sys_training.initial_capital + * + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 + */ + private Double initialCapital; + /** * This method was generated by MyBatis Generator. * This method returns the value of the database column sys_training.training_id * * @return the value of sys_training.training_id * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ public String getTrainingId() { return trainingId; @@ -159,7 +155,7 @@ public class Training { * * @param trainingId the value for sys_training.training_id * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ public void setTrainingId(String trainingId) { this.trainingId = trainingId == null ? null : trainingId.trim(); @@ -171,7 +167,7 @@ public class Training { * * @return the value of sys_training.people_count * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ public Integer getPeopleCount() { return peopleCount; @@ -183,7 +179,7 @@ public class Training { * * @param peopleCount the value for sys_training.people_count * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ public void setPeopleCount(Integer peopleCount) { this.peopleCount = peopleCount; @@ -195,7 +191,7 @@ public class Training { * * @return the value of sys_training.start_time * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ public Date getStartTime() { return startTime; @@ -207,7 +203,7 @@ public class Training { * * @param startTime the value for sys_training.start_time * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ public void setStartTime(Date startTime) { this.startTime = startTime; @@ -219,7 +215,7 @@ public class Training { * * @return the value of sys_training.end_time * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ public Date getEndTime() { return endTime; @@ -231,7 +227,7 @@ public class Training { * * @param endTime the value for sys_training.end_time * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ public void setEndTime(Date endTime) { this.endTime = endTime; @@ -243,7 +239,7 @@ public class Training { * * @return the value of sys_training.status * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ public String getStatus() { return status; @@ -255,7 +251,7 @@ public class Training { * * @param status the value for sys_training.status * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ public void setStatus(String status) { this.status = status == null ? null : status.trim(); @@ -267,7 +263,7 @@ public class Training { * * @return the value of sys_training.creator_id * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ public Integer getCreatorId() { return creatorId; @@ -279,7 +275,7 @@ public class Training { * * @param creatorId the value for sys_training.creator_id * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ public void setCreatorId(Integer creatorId) { this.creatorId = creatorId; @@ -291,7 +287,7 @@ public class Training { * * @return the value of sys_training.create_school * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ public String getCreateSchool() { return createSchool; @@ -303,7 +299,7 @@ public class Training { * * @param createSchool the value for sys_training.create_school * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ public void setCreateSchool(String createSchool) { this.createSchool = createSchool == null ? null : createSchool.trim(); @@ -315,7 +311,7 @@ public class Training { * * @return the value of sys_training.training_name * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ public String getTrainingName() { return trainingName; @@ -327,7 +323,7 @@ public class Training { * * @param trainingName the value for sys_training.training_name * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ public void setTrainingName(String trainingName) { this.trainingName = trainingName == null ? null : trainingName.trim(); @@ -339,7 +335,7 @@ public class Training { * * @return the value of sys_training.creator_name * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ public String getCreatorName() { return creatorName; @@ -351,7 +347,7 @@ public class Training { * * @param creatorName the value for sys_training.creator_name * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ public void setCreatorName(String creatorName) { this.creatorName = creatorName == null ? null : creatorName.trim(); @@ -363,7 +359,7 @@ public class Training { * * @return the value of sys_training.create_time * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ public Date getCreateTime() { return createTime; @@ -375,7 +371,7 @@ public class Training { * * @param createTime the value for sys_training.create_time * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ public void setCreateTime(Date createTime) { this.createTime = createTime; @@ -387,7 +383,7 @@ public class Training { * * @return the value of sys_training.update_time * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ public Date getUpdateTime() { return updateTime; @@ -399,13 +395,23 @@ public class Training { * * @param updateTime the value for sys_training.update_time * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ public void setUpdateTime(Date updateTime) { this.updateTime = updateTime; } - + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column sys_training.school_id + * + * @return the value of sys_training.school_id + * + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 + */ + public Integer getSchoolId() { + return schoolId; + } /** * This method was generated by MyBatis Generator. @@ -413,23 +419,19 @@ public class Training { * * @param schoolId the value for sys_training.school_id * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ public void setSchoolId(Integer schoolId) { this.schoolId = schoolId; } - public Integer getSchoolId() { - return schoolId; - } - /** * This method was generated by MyBatis Generator. * This method returns the value of the database column sys_training.weight_id * * @return the value of sys_training.weight_id * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ public String getWeightId() { return weightId; @@ -441,12 +443,36 @@ public class Training { * * @param weightId the value for sys_training.weight_id * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ public void setWeightId(String weightId) { this.weightId = weightId == null ? null : weightId.trim(); } + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column sys_training.initial_capital + * + * @param initialCapital the value for sys_training.initial_capital + * + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 + */ + public void setInitialCapital(Double initialCapital) { + this.initialCapital = initialCapital; + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column sys_training.initial_capital + * + * @return the value of sys_training.initial_capital + * + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 + */ + public Double getInitialCapital() { + return initialCapital; + } + public static Training buildTraining(TrainingBO bo, JwtUser currentUser) { Training training = new Training(); @@ -472,7 +498,11 @@ public class Training { training.status = startTime > now ? "NOT_STARTED" : "ONGOING"; training.createTime = new Date(); training.updateTime = new Date(); + training.initialCapital=bo.getInitial(); return training; } + + + } \ No newline at end of file diff --git a/src/main/java/com/sztzjy/forex/trading_trading/entity/TrainingExample.java b/src/main/java/com/sztzjy/forex/trading_trading/entity/TrainingExample.java index 43501ec..87b11ee 100644 --- a/src/main/java/com/sztzjy/forex/trading_trading/entity/TrainingExample.java +++ b/src/main/java/com/sztzjy/forex/trading_trading/entity/TrainingExample.java @@ -9,7 +9,7 @@ public class TrainingExample { * This field was generated by MyBatis Generator. * This field corresponds to the database table sys_training * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ protected String orderByClause; @@ -17,7 +17,7 @@ public class TrainingExample { * This field was generated by MyBatis Generator. * This field corresponds to the database table sys_training * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ protected boolean distinct; @@ -25,7 +25,7 @@ public class TrainingExample { * This field was generated by MyBatis Generator. * This field corresponds to the database table sys_training * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ protected List oredCriteria; @@ -33,7 +33,7 @@ public class TrainingExample { * This method was generated by MyBatis Generator. * This method corresponds to the database table sys_training * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ public TrainingExample() { oredCriteria = new ArrayList<>(); @@ -43,7 +43,7 @@ public class TrainingExample { * This method was generated by MyBatis Generator. * This method corresponds to the database table sys_training * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ public void setOrderByClause(String orderByClause) { this.orderByClause = orderByClause; @@ -53,7 +53,7 @@ public class TrainingExample { * This method was generated by MyBatis Generator. * This method corresponds to the database table sys_training * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ public String getOrderByClause() { return orderByClause; @@ -63,7 +63,7 @@ public class TrainingExample { * This method was generated by MyBatis Generator. * This method corresponds to the database table sys_training * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ public void setDistinct(boolean distinct) { this.distinct = distinct; @@ -73,7 +73,7 @@ public class TrainingExample { * This method was generated by MyBatis Generator. * This method corresponds to the database table sys_training * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ public boolean isDistinct() { return distinct; @@ -83,7 +83,7 @@ public class TrainingExample { * This method was generated by MyBatis Generator. * This method corresponds to the database table sys_training * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ public List getOredCriteria() { return oredCriteria; @@ -93,7 +93,7 @@ public class TrainingExample { * This method was generated by MyBatis Generator. * This method corresponds to the database table sys_training * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ public void or(Criteria criteria) { oredCriteria.add(criteria); @@ -103,7 +103,7 @@ public class TrainingExample { * This method was generated by MyBatis Generator. * This method corresponds to the database table sys_training * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ public Criteria or() { Criteria criteria = createCriteriaInternal(); @@ -115,7 +115,7 @@ public class TrainingExample { * This method was generated by MyBatis Generator. * This method corresponds to the database table sys_training * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ public Criteria createCriteria() { Criteria criteria = createCriteriaInternal(); @@ -129,7 +129,7 @@ public class TrainingExample { * This method was generated by MyBatis Generator. * This method corresponds to the database table sys_training * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ protected Criteria createCriteriaInternal() { Criteria criteria = new Criteria(); @@ -140,7 +140,7 @@ public class TrainingExample { * This method was generated by MyBatis Generator. * This method corresponds to the database table sys_training * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ public void clear() { oredCriteria.clear(); @@ -152,7 +152,7 @@ public class TrainingExample { * This class was generated by MyBatis Generator. * This class corresponds to the database table sys_training * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ protected abstract static class GeneratedCriteria { protected List criteria; @@ -1034,13 +1034,73 @@ public class TrainingExample { addCriterion("weight_id not between", value1, value2, "weightId"); return (Criteria) this; } + + public Criteria andInitialCapitalIsNull() { + addCriterion("initial_capital is null"); + return (Criteria) this; + } + + public Criteria andInitialCapitalIsNotNull() { + addCriterion("initial_capital is not null"); + return (Criteria) this; + } + + public Criteria andInitialCapitalEqualTo(Double value) { + addCriterion("initial_capital =", value, "initialCapital"); + return (Criteria) this; + } + + public Criteria andInitialCapitalNotEqualTo(Double value) { + addCriterion("initial_capital <>", value, "initialCapital"); + return (Criteria) this; + } + + public Criteria andInitialCapitalGreaterThan(Double value) { + addCriterion("initial_capital >", value, "initialCapital"); + return (Criteria) this; + } + + public Criteria andInitialCapitalGreaterThanOrEqualTo(Double value) { + addCriterion("initial_capital >=", value, "initialCapital"); + return (Criteria) this; + } + + public Criteria andInitialCapitalLessThan(Double value) { + addCriterion("initial_capital <", value, "initialCapital"); + return (Criteria) this; + } + + public Criteria andInitialCapitalLessThanOrEqualTo(Double value) { + addCriterion("initial_capital <=", value, "initialCapital"); + return (Criteria) this; + } + + public Criteria andInitialCapitalIn(List values) { + addCriterion("initial_capital in", values, "initialCapital"); + return (Criteria) this; + } + + public Criteria andInitialCapitalNotIn(List values) { + addCriterion("initial_capital not in", values, "initialCapital"); + return (Criteria) this; + } + + public Criteria andInitialCapitalBetween(Double value1, Double value2) { + addCriterion("initial_capital between", value1, value2, "initialCapital"); + return (Criteria) this; + } + + public Criteria andInitialCapitalNotBetween(Double value1, Double value2) { + addCriterion("initial_capital not between", value1, value2, "initialCapital"); + return (Criteria) this; + } } /** * This class was generated by MyBatis Generator. * This class corresponds to the database table sys_training * - * @mbg.generated do_not_delete_during_merge Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated do_not_delete_during_merge Fri Jun 21 13:41:49 CST 2024 */ public static class Criteria extends GeneratedCriteria { protected Criteria() { @@ -1052,7 +1112,7 @@ public class TrainingExample { * This class was generated by MyBatis Generator. * This class corresponds to the database table sys_training * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ public static class Criterion { private String condition; diff --git a/src/main/java/com/sztzjy/forex/trading_trading/mappers/TrainingMapper.java b/src/main/java/com/sztzjy/forex/trading_trading/mappers/TrainingMapper.java index 77e6f49..43e20c8 100644 --- a/src/main/java/com/sztzjy/forex/trading_trading/mappers/TrainingMapper.java +++ b/src/main/java/com/sztzjy/forex/trading_trading/mappers/TrainingMapper.java @@ -18,7 +18,7 @@ public interface TrainingMapper { * This method was generated by MyBatis Generator. * This method corresponds to the database table sys_training * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ long countByExample(TrainingExample example); @@ -26,7 +26,7 @@ public interface TrainingMapper { * This method was generated by MyBatis Generator. * This method corresponds to the database table sys_training * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ int deleteByExample(TrainingExample example); @@ -34,7 +34,7 @@ public interface TrainingMapper { * This method was generated by MyBatis Generator. * This method corresponds to the database table sys_training * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ int deleteByPrimaryKey(String trainingId); @@ -42,7 +42,7 @@ public interface TrainingMapper { * This method was generated by MyBatis Generator. * This method corresponds to the database table sys_training * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ int insert(Training record); @@ -50,7 +50,7 @@ public interface TrainingMapper { * This method was generated by MyBatis Generator. * This method corresponds to the database table sys_training * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ int insertSelective(Training record); @@ -58,7 +58,7 @@ public interface TrainingMapper { * This method was generated by MyBatis Generator. * This method corresponds to the database table sys_training * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ List selectByExample(TrainingExample example); @@ -66,7 +66,7 @@ public interface TrainingMapper { * This method was generated by MyBatis Generator. * This method corresponds to the database table sys_training * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ Training selectByPrimaryKey(String trainingId); @@ -74,7 +74,7 @@ public interface TrainingMapper { * This method was generated by MyBatis Generator. * This method corresponds to the database table sys_training * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ int updateByExampleSelective(@Param("record") Training record, @Param("example") TrainingExample example); @@ -82,7 +82,7 @@ public interface TrainingMapper { * This method was generated by MyBatis Generator. * This method corresponds to the database table sys_training * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ int updateByExample(@Param("record") Training record, @Param("example") TrainingExample example); @@ -90,7 +90,7 @@ public interface TrainingMapper { * This method was generated by MyBatis Generator. * This method corresponds to the database table sys_training * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ int updateByPrimaryKeySelective(Training record); @@ -98,7 +98,7 @@ public interface TrainingMapper { * This method was generated by MyBatis Generator. * This method corresponds to the database table sys_training * - * @mbg.generated Thu Jul 06 12:03:59 CST 2023 + * @mbg.generated Fri Jun 21 13:41:49 CST 2024 */ int updateByPrimaryKey(Training record); diff --git a/src/main/java/com/sztzjy/forex/trading_trading/service/ScheduledTask.java b/src/main/java/com/sztzjy/forex/trading_trading/service/ScheduledTask.java index 75bf1c1..d2a88c0 100644 --- a/src/main/java/com/sztzjy/forex/trading_trading/service/ScheduledTask.java +++ b/src/main/java/com/sztzjy/forex/trading_trading/service/ScheduledTask.java @@ -99,7 +99,7 @@ public class ScheduledTask { log.info("--------真实数据插入成功------"); } - //每10秒执行一次 根据真实汇率数据生成模拟汇率数据 + //每1秒执行一次 根据真实汇率数据生成模拟汇率数据 @Scheduled(cron = "0/1 * * * * ?") public void insertSimulatedForexMarketData() { //获取batchId相同的最后入库的数据 @@ -221,19 +221,27 @@ public class ScheduledTask { int decimalInt = Integer.parseInt(decimalPart); // 对最后一位进行减一操作 - int randomNumber = random.nextInt(7); + int randomNumber = random.nextInt(9); if(randomNumber==1){ decimalInt=decimalInt-1; }else if(randomNumber==2){ - decimalInt=decimalInt-2; + decimalInt=decimalInt-1; }else if(randomNumber==3){ - decimalInt=decimalInt-3; + decimalInt=decimalInt-1; }else if(randomNumber==4){ - decimalInt=decimalInt+1; + decimalInt=decimalInt-1; }else if(randomNumber==5){ - decimalInt=decimalInt+2; + decimalInt=decimalInt+1; }else if(randomNumber==6){ - decimalInt=decimalInt+3; + decimalInt=decimalInt+1; + }else if(randomNumber==7){ + decimalInt=decimalInt+1; + }else if(randomNumber==8){ + decimalInt=decimalInt+1; + }else if(randomNumber==8){ + decimalInt=decimalInt+2; + }else if(randomNumber==8){ + decimalInt=decimalInt-2; } // 构造新的数字 @@ -252,7 +260,8 @@ public class ScheduledTask { //监听止损止盈 根据code获取当前买卖价格 如果价格高于/低于止损止盈 则按照止损止盈的值进行平仓 //查询实训表中状态为1的所有实训并获取ID 获取持仓表中所有状态为0 且止损和止盈不为空的所有数据 获取当前价位如果 - @Scheduled(cron = "0 */2 * * * ?") +// @Scheduled(cron = "0 */2 * * * ?") //每两分钟触发一次 + @Scheduled(cron = "0/30 * * * * ?") //每30秒钟触发一次 public void monitorStopLossProfit() { List forexDateList = redisUtil.get("ForexDateList"); Map forexDateMap = new HashMap(); diff --git a/src/main/resources/mappers/TrainingMapper.xml b/src/main/resources/mappers/TrainingMapper.xml index 5720686..bb9b9f7 100644 --- a/src/main/resources/mappers/TrainingMapper.xml +++ b/src/main/resources/mappers/TrainingMapper.xml @@ -1,427 +1,437 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - and ${criterion.condition} - - - and ${criterion.condition} #{criterion.value} - - - and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} - - - and ${criterion.condition} - - #{listItem} - - - - - - - - - - - - - - - - - - - and ${criterion.condition} - - - and ${criterion.condition} #{criterion.value} - - - and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} - - - and ${criterion.condition} - - #{listItem} - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + - - - - - training_id, people_count, start_time, end_time, status, creator_id, create_school, - training_name, creator_name, create_time, update_time, school_id, weight_id - - - - - - delete from sys_training - where training_id = #{trainingId,jdbcType=VARCHAR} - - - - delete from sys_training - - - - - - - insert into sys_training (training_id, people_count, start_time, - end_time, status, creator_id, - create_school, training_name, creator_name, - create_time, update_time, school_id, - weight_id) - values (#{trainingId,jdbcType=VARCHAR}, #{peopleCount,jdbcType=INTEGER}, #{startTime,jdbcType=TIMESTAMP}, - #{endTime,jdbcType=TIMESTAMP}, #{status,jdbcType=VARCHAR}, #{creatorId,jdbcType=INTEGER}, - #{createSchool,jdbcType=VARCHAR}, #{trainingName,jdbcType=VARCHAR}, #{creatorName,jdbcType=VARCHAR}, - #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, #{schoolId,jdbcType=INTEGER}, - #{weightId,jdbcType=VARCHAR}) - - - - insert into sys_training - - - training_id, - - - people_count, - - - start_time, - - - end_time, - - - status, - - - creator_id, - - - create_school, - - - training_name, - - - creator_name, - - - create_time, - - - update_time, - - - school_id, - - - weight_id, - - - - - #{trainingId,jdbcType=VARCHAR}, - - - #{peopleCount,jdbcType=INTEGER}, - - - #{startTime,jdbcType=TIMESTAMP}, - - - #{endTime,jdbcType=TIMESTAMP}, - - - #{status,jdbcType=VARCHAR}, - - - #{creatorId,jdbcType=INTEGER}, - - - #{createSchool,jdbcType=VARCHAR}, - - - #{trainingName,jdbcType=VARCHAR}, - - - #{creatorName,jdbcType=VARCHAR}, - - - #{createTime,jdbcType=TIMESTAMP}, - - - #{updateTime,jdbcType=TIMESTAMP}, - - - #{schoolId,jdbcType=INTEGER}, - - - #{weightId,jdbcType=VARCHAR}, - - - - - - - update sys_training - - - training_id = #{record.trainingId,jdbcType=VARCHAR}, - - - people_count = #{record.peopleCount,jdbcType=INTEGER}, - - - start_time = #{record.startTime,jdbcType=TIMESTAMP}, - - - end_time = #{record.endTime,jdbcType=TIMESTAMP}, - - - status = #{record.status,jdbcType=VARCHAR}, - - - creator_id = #{record.creatorId,jdbcType=INTEGER}, - - - create_school = #{record.createSchool,jdbcType=VARCHAR}, - - - training_name = #{record.trainingName,jdbcType=VARCHAR}, - - - creator_name = #{record.creatorName,jdbcType=VARCHAR}, - - - create_time = #{record.createTime,jdbcType=TIMESTAMP}, - - - update_time = #{record.updateTime,jdbcType=TIMESTAMP}, - - - school_id = #{record.schoolId,jdbcType=INTEGER}, - - - weight_id = #{record.weightId,jdbcType=VARCHAR}, - - - - + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + - - - - update sys_training - set training_id = #{record.trainingId,jdbcType=VARCHAR}, + + + + + + training_id, people_count, start_time, end_time, status, creator_id, create_school, + training_name, creator_name, create_time, update_time, school_id, weight_id, initial_capital + + + + + + delete from sys_training + where training_id = #{trainingId,jdbcType=VARCHAR} + + + + delete from sys_training + + + + + + + insert into sys_training (training_id, people_count, start_time, + end_time, status, creator_id, + create_school, training_name, creator_name, + create_time, update_time, school_id, + weight_id, initial_capital) + values (#{trainingId,jdbcType=VARCHAR}, #{peopleCount,jdbcType=INTEGER}, #{startTime,jdbcType=TIMESTAMP}, + #{endTime,jdbcType=TIMESTAMP}, #{status,jdbcType=VARCHAR}, #{creatorId,jdbcType=INTEGER}, + #{createSchool,jdbcType=VARCHAR}, #{trainingName,jdbcType=VARCHAR}, #{creatorName,jdbcType=VARCHAR}, + #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, #{schoolId,jdbcType=INTEGER}, + #{weightId,jdbcType=VARCHAR}, #{initialCapital,jdbcType=DOUBLE}) + + + + insert into sys_training + + + training_id, + + + people_count, + + + start_time, + + + end_time, + + + status, + + + creator_id, + + + create_school, + + + training_name, + + + creator_name, + + + create_time, + + + update_time, + + + school_id, + + + weight_id, + + + initial_capital, + + + + + #{trainingId,jdbcType=VARCHAR}, + + + #{peopleCount,jdbcType=INTEGER}, + + + #{startTime,jdbcType=TIMESTAMP}, + + + #{endTime,jdbcType=TIMESTAMP}, + + + #{status,jdbcType=VARCHAR}, + + + #{creatorId,jdbcType=INTEGER}, + + + #{createSchool,jdbcType=VARCHAR}, + + + #{trainingName,jdbcType=VARCHAR}, + + + #{creatorName,jdbcType=VARCHAR}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + #{updateTime,jdbcType=TIMESTAMP}, + + + #{schoolId,jdbcType=INTEGER}, + + + #{weightId,jdbcType=VARCHAR}, + + + #{initialCapital,jdbcType=DOUBLE}, + + + + + + + update sys_training + + + training_id = #{record.trainingId,jdbcType=VARCHAR}, + + people_count = #{record.peopleCount,jdbcType=INTEGER}, + + start_time = #{record.startTime,jdbcType=TIMESTAMP}, + + end_time = #{record.endTime,jdbcType=TIMESTAMP}, + + status = #{record.status,jdbcType=VARCHAR}, + + creator_id = #{record.creatorId,jdbcType=INTEGER}, + + create_school = #{record.createSchool,jdbcType=VARCHAR}, + + training_name = #{record.trainingName,jdbcType=VARCHAR}, + + creator_name = #{record.creatorName,jdbcType=VARCHAR}, + + create_time = #{record.createTime,jdbcType=TIMESTAMP}, + + update_time = #{record.updateTime,jdbcType=TIMESTAMP}, + + school_id = #{record.schoolId,jdbcType=INTEGER}, - weight_id = #{record.weightId,jdbcType=VARCHAR} - - - - - - - update sys_training - - - people_count = #{peopleCount,jdbcType=INTEGER}, - - - start_time = #{startTime,jdbcType=TIMESTAMP}, - - - end_time = #{endTime,jdbcType=TIMESTAMP}, - - - status = #{status,jdbcType=VARCHAR}, - - - creator_id = #{creatorId,jdbcType=INTEGER}, - - - create_school = #{createSchool,jdbcType=VARCHAR}, - - - training_name = #{trainingName,jdbcType=VARCHAR}, - - - creator_name = #{creatorName,jdbcType=VARCHAR}, - - - create_time = #{createTime,jdbcType=TIMESTAMP}, - - - update_time = #{updateTime,jdbcType=TIMESTAMP}, - - - school_id = #{schoolId,jdbcType=INTEGER}, - - - weight_id = #{weightId,jdbcType=VARCHAR}, - - - where training_id = #{trainingId,jdbcType=VARCHAR} - - - - update sys_training - set people_count = #{peopleCount,jdbcType=INTEGER}, + + + weight_id = #{record.weightId,jdbcType=VARCHAR}, + + + initial_capital = #{record.initialCapital,jdbcType=DOUBLE}, + + + + + + + + + update sys_training + set training_id = #{record.trainingId,jdbcType=VARCHAR}, + people_count = #{record.peopleCount,jdbcType=INTEGER}, + start_time = #{record.startTime,jdbcType=TIMESTAMP}, + end_time = #{record.endTime,jdbcType=TIMESTAMP}, + status = #{record.status,jdbcType=VARCHAR}, + creator_id = #{record.creatorId,jdbcType=INTEGER}, + create_school = #{record.createSchool,jdbcType=VARCHAR}, + training_name = #{record.trainingName,jdbcType=VARCHAR}, + creator_name = #{record.creatorName,jdbcType=VARCHAR}, + create_time = #{record.createTime,jdbcType=TIMESTAMP}, + update_time = #{record.updateTime,jdbcType=TIMESTAMP}, + school_id = #{record.schoolId,jdbcType=INTEGER}, + weight_id = #{record.weightId,jdbcType=VARCHAR}, + initial_capital = #{record.initialCapital,jdbcType=DOUBLE} + + + + + + + update sys_training + + + people_count = #{peopleCount,jdbcType=INTEGER}, + + start_time = #{startTime,jdbcType=TIMESTAMP}, + + end_time = #{endTime,jdbcType=TIMESTAMP}, + + status = #{status,jdbcType=VARCHAR}, + + creator_id = #{creatorId,jdbcType=INTEGER}, + + create_school = #{createSchool,jdbcType=VARCHAR}, + + training_name = #{trainingName,jdbcType=VARCHAR}, + + creator_name = #{creatorName,jdbcType=VARCHAR}, + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + update_time = #{updateTime,jdbcType=TIMESTAMP}, + + school_id = #{schoolId,jdbcType=INTEGER}, - weight_id = #{weightId,jdbcType=VARCHAR} - where training_id = #{trainingId,jdbcType=VARCHAR} - - select * from training - + ORDER BY ${safeOrderByClause}