修改代码格式

pull/1/head
yz
parent e43fee0498
commit 73d0ead566

@ -64,7 +64,7 @@ public class MemberController {
@PostMapping("getMemberById")
public ResultEntity getMember(@RequestBody String memberId) {
Member member = memberService.selectByPrimaryKey(memberId);
Double availableFunds = getAvailableFunds(member);
Double availableFunds = memberService.getAvailableFunds(member);
member.setAvailableFunds(availableFunds);
return new ResultEntity(HttpStatus.OK, "根据成员ID获取成员对象", member);
}
@ -164,56 +164,6 @@ public class MemberController {
return new ResultEntity<PageInfo<Member>>(members);
}
//获取可用资金
public Double getAvailableFunds(Member member){
Double positionProfitLoss = flashTotalPositionProfitLoss(member.getMemberId());
if (positionProfitLoss==null){
positionProfitLoss=0.0;
}
Double initialCapital = member.getInitialCapital();//初始资金
Double totalAssets = initialCapital+positionProfitLoss;
Double netValue = bigDecimalUtils.add(totalAssets, positionProfitLoss);
Double cumulativeProfitLoss = member.getCumulativeProfitLoss(); //累计盈亏
if(cumulativeProfitLoss==null){
member.setCumulativeProfitLoss(0.0);
}
Double marginUsed = member.getMarginUsed(); //获取已用保证金
if (marginUsed==null){
marginUsed=0.0;
}
return bigDecimalUtils.sub(netValue, marginUsed);
}
public Double flashTotalPositionProfitLoss(String memberId) {
List<TakeStash> takeStashList = takeStashService.selectAllByMemberIdAndStatus(memberId, 0);
Double totalProfitAndLoss = 0.0;
for (int i = 0; i < takeStashList.size(); i++) {
TakeStash takeStash = takeStashList.get(i);
String buySellType = takeStash.getBuySellType(); //买入或卖出
String tradingCode = takeStash.getTradingCode(); //交易品种
Double priceTransaction = takeStash.getPriceTransaction(); //交易价格
Double volumeTransaction = takeStash.getVolumeTransaction(); //交易量
ForexMarketData forexData = forexMarketDateUtil.getForexMarketDateByCode(tradingCode);
Double nowBuyPic = forexData.getBuyPic(); //当前买价
Double nowSellPic = Double.valueOf(forexData.getSellPic()); //当前卖价
Double profitAndLoss;
if (tradingCode.startsWith("USD")) { //美元在前
if (Constant.BUY_BUYSELLTYPE.equals(buySellType)) { //买
profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * Constant.LEVERQUANTITY / nowSellPic;
} else { //卖
profitAndLoss = (priceTransaction - nowBuyPic) * volumeTransaction * Constant.LEVERQUANTITY / nowBuyPic;
}
} else { //美元在后
if (Constant.BUY_BUYSELLTYPE.equals(buySellType)) { //买
profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * Constant.LEVERQUANTITY;
} else { //卖
profitAndLoss = (nowBuyPic - priceTransaction) * volumeTransaction * Constant.LEVERQUANTITY;
}
}
totalProfitAndLoss = totalProfitAndLoss + profitAndLoss;
totalProfitAndLoss = bigDecimalUtils.mul(totalProfitAndLoss, 1, 2);
}
return totalProfitAndLoss;
}
}

@ -271,7 +271,7 @@ public class TakeStashController {
takeStash.setTimeTransactionClose(new Date());
takeStashService.updateByPrimaryKeySelective(takeStash);
wainingService.compareMarginLevels(member.getMemberId(), member.getTrainingId());//更改可用保证金后 调用预警
// wainingService.compareMarginLevels(member.getMemberId(), member.getTrainingId());//更改可用保证金后 调用预警
return new ResultEntity(HttpStatus.OK, "平仓成功");
}
@ -408,7 +408,7 @@ public class TakeStashController {
takeStash.setTimeTransactionClose(new Date());
takeStashService.updateByPrimaryKeySelective(takeStash);
wainingService.compareMarginLevels(member.getMemberId(), member.getTrainingId());//更改可用保证金后 调用预警
// wainingService.compareMarginLevels(member.getMemberId(), member.getTrainingId());//更改可用保证金后 调用预警
}

@ -16,6 +16,7 @@ import com.sztzjy.forex.trading_trading.util.RedisUtil;
import com.sztzjy.forex.trading_trading.util.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
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;
@ -113,7 +114,7 @@ public class TradingController {
Double sellPic = Double.valueOf(forexData.getSellPic());//当前买价
Double priceTransaction=0.0; //记录当前交易价格(买价或卖价)
Member member = memberService.getMemberByMemberIdAndTrainingId(memberId, trainingId);
Double availableFunds = getAvailableFunds(member); //获取账户可用资金
Double availableFunds = memberService.getAvailableFunds(member); //获取账户可用资金
Double margin = 0.0; //记录所需保证金
Boolean stopLossWinFlag=false;
if (null != stopLoss || null != stopWin) { //判断止损止赢是否合理 如果stopLoss stopWin都为null则跳过
@ -125,9 +126,11 @@ public class TradingController {
}
//如果方式为卖 则止损高于卖价 获利低于买价
if (transactionType.equals("sjkc")) {//市价开仓
if(priceCommission!=-1){
buyPic=priceCommission;
sellPic=priceCommission;
if(priceCommission!=null){
if(priceCommission!=-1){
buyPic=priceCommission;
sellPic=priceCommission;
}
}
String stashId = IdUtil.simpleUUID(); //设置市价开仓ID
if (tradingCode.startsWith("USD")) { //美元在前
@ -265,7 +268,7 @@ public class TradingController {
}
member.setOpeningTrades(openingTrades++);//设置开仓次数
memberService.updateByPrimaryKeySelective(member);
wainingService.compareMarginLevels(member.getMemberId(),member.getTrainingId());//更改可用保证金后 调用预警
// wainingService.compareMarginLevels(member.getMemberId(),member.getTrainingId());//更改可用保证金后 调用预警
}
//判断止损止赢 逻辑:如果方式为买 则止损低于买价 获利高于买价 / 如果方式为卖 则止损高于卖价 获利低于买价 (可以只传一个参数)
@ -449,56 +452,4 @@ public class TradingController {
return margin;
}
//获取可用资金
public Double getAvailableFunds(Member member){
Double positionProfitLoss = flashTotalPositionProfitLoss(member.getMemberId());
if (positionProfitLoss==null){
positionProfitLoss=0.0;
}
Double initialCapital = member.getInitialCapital();//初始资金
Double totalAssets = initialCapital+positionProfitLoss;
Double netValue = bigDecimalUtils.add(totalAssets, positionProfitLoss);
Double cumulativeProfitLoss = member.getCumulativeProfitLoss(); //累计盈亏
if(cumulativeProfitLoss==null){
member.setCumulativeProfitLoss(0.0);
}
Double marginUsed = member.getMarginUsed(); //获取已用保证金
if (marginUsed==null){
marginUsed=0.0;
}
return bigDecimalUtils.sub(netValue, marginUsed);
}
public Double flashTotalPositionProfitLoss(String memberId) {
List<TakeStash> takeStashList = takeStashService.selectAllByMemberIdAndStatus(memberId, 0);
Double totalProfitAndLoss = 0.0;
for (int i = 0; i < takeStashList.size(); i++) {
TakeStash takeStash = takeStashList.get(i);
String buySellType = takeStash.getBuySellType(); //买入或卖出
String tradingCode = takeStash.getTradingCode(); //交易品种
Double priceTransaction = takeStash.getPriceTransaction(); //交易价格
Double volumeTransaction = takeStash.getVolumeTransaction(); //交易量
ForexMarketData forexData = forexMarketDateUtil.getForexMarketDateByCode(tradingCode);
Double nowBuyPic = forexData.getBuyPic(); //当前买价
Double nowSellPic = Double.valueOf(forexData.getSellPic()); //当前卖价
Double profitAndLoss;
if (tradingCode.startsWith("USD")) { //美元在前
if (Constant.BUY_BUYSELLTYPE.equals(buySellType)) { //买
profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * Constant.PEACEQUANTITY / nowSellPic;
} else { //卖
profitAndLoss = (priceTransaction - nowBuyPic) * volumeTransaction * Constant.PEACEQUANTITY / nowBuyPic;
}
} else { //美元在后
if (Constant.BUY_BUYSELLTYPE.equals(buySellType)) { //买
profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * Constant.PEACEQUANTITY;
} else { //卖
profitAndLoss = (priceTransaction-nowBuyPic) * volumeTransaction * Constant.PEACEQUANTITY;
}
}
totalProfitAndLoss = totalProfitAndLoss + profitAndLoss;
totalProfitAndLoss = bigDecimalUtils.mul(totalProfitAndLoss, 1, 2);
}
return totalProfitAndLoss;
}
}

@ -2,11 +2,16 @@ package com.sztzjy.forex.trading_trading.service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sztzjy.forex.trading_trading.config.Constant;
import com.sztzjy.forex.trading_trading.config.security.JwtUser;
import com.sztzjy.forex.trading_trading.dto.MemberVO;
import com.sztzjy.forex.trading_trading.entity.ForexMarketData;
import com.sztzjy.forex.trading_trading.entity.Member;
import com.sztzjy.forex.trading_trading.entity.MemberExample;
import com.sztzjy.forex.trading_trading.entity.TakeStash;
import com.sztzjy.forex.trading_trading.mappers.MemberMapper;
import com.sztzjy.forex.trading_trading.util.BigDecimalUtils;
import com.sztzjy.forex.trading_trading.util.ForexMarketDateUtil;
import com.sztzjy.forex.trading_trading.util.excel.ExcelData;
import com.sztzjy.forex.trading_trading.util.excel.ExcelProvider;
import com.sztzjy.forex.trading_trading.util.file.IFileUtil;
@ -30,6 +35,12 @@ public class MemberService {
MemberMapper memberMapper;
@Autowired
IFileUtil fileUtil;
@Autowired
TakeStashService takeStashService;
@Autowired
BigDecimalUtils bigDecimalUtils;
@Autowired
ForexMarketDateUtil forexMarketDateUtil;
public Member getMemberByMemberIdAndTrainingId(String memberId, String trainingId) {
MemberExample example = new MemberExample();
@ -242,4 +253,56 @@ public class MemberService {
example.createCriteria().andTrainingIdEqualTo(trainingId).andStudentNumberNotIn(studentNumbers);
memberMapper.deleteByExample(example);
}
//获取可用资金
public Double getAvailableFunds(Member member){
Double positionProfitLoss = flashTotalPositionProfitLoss(member.getMemberId());
if (positionProfitLoss==null){
positionProfitLoss=0.0;
}
Double initialCapital = member.getInitialCapital();//初始资金
Double totalAssets = initialCapital+positionProfitLoss;
Double netValue = bigDecimalUtils.add(totalAssets, positionProfitLoss);
Double cumulativeProfitLoss = member.getCumulativeProfitLoss(); //累计盈亏
if(cumulativeProfitLoss==null){
member.setCumulativeProfitLoss(0.0);
}
Double marginUsed = member.getMarginUsed(); //获取已用保证金
if (marginUsed==null){
marginUsed=0.0;
}
return bigDecimalUtils.sub(netValue, marginUsed);
}
public Double flashTotalPositionProfitLoss(String memberId) {
List<TakeStash> takeStashList = takeStashService.selectAllByMemberIdAndStatus(memberId, 0);
Double totalProfitAndLoss = 0.0;
for (int i = 0; i < takeStashList.size(); i++) {
TakeStash takeStash = takeStashList.get(i);
String buySellType = takeStash.getBuySellType(); //买入或卖出
String tradingCode = takeStash.getTradingCode(); //交易品种
Double priceTransaction = takeStash.getPriceTransaction(); //交易价格
Double volumeTransaction = takeStash.getVolumeTransaction(); //交易量
ForexMarketData forexData = forexMarketDateUtil.getForexMarketDateByCode(tradingCode);
Double nowBuyPic = forexData.getBuyPic(); //当前买价
Double nowSellPic = Double.valueOf(forexData.getSellPic()); //当前卖价
Double profitAndLoss;
if (tradingCode.startsWith("USD")) { //美元在前
if (Constant.BUY_BUYSELLTYPE.equals(buySellType)) { //买
profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * Constant.PEACEQUANTITY / nowSellPic;
} else { //卖
profitAndLoss = (priceTransaction - nowBuyPic) * volumeTransaction * Constant.PEACEQUANTITY / nowBuyPic;
}
} else { //美元在后
if (Constant.BUY_BUYSELLTYPE.equals(buySellType)) { //买
profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * Constant.PEACEQUANTITY;
} else { //卖
profitAndLoss = (priceTransaction-nowBuyPic) * volumeTransaction * Constant.PEACEQUANTITY;
}
}
totalProfitAndLoss = totalProfitAndLoss + profitAndLoss;
totalProfitAndLoss = bigDecimalUtils.mul(totalProfitAndLoss, 1, 2);
}
return totalProfitAndLoss;
}
}

Loading…
Cancel
Save