|
@@ -1,6 +1,5 @@
|
|
|
package com.xc.service.impl;
|
|
|
|
|
|
-import com.qiniu.util.Json;
|
|
|
import com.xc.dao.*;
|
|
|
import com.xc.pojo.*;
|
|
|
import com.xc.service.*;
|
|
@@ -10,7 +9,6 @@ import com.google.common.collect.Lists;
|
|
|
import com.xc.common.ServerResponse;
|
|
|
import com.xc.service.*;
|
|
|
import com.xc.utils.DateTimeUtil;
|
|
|
-import com.xc.utils.IndexDbCreatedUtil;
|
|
|
import com.xc.utils.KeyUtils;
|
|
|
import com.xc.utils.stock.BuyAndSellUtils;
|
|
|
import com.xc.utils.stock.GeneratePosition;
|
|
@@ -109,19 +107,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-// userPositions.stream().forEach(userPosition -> {
|
|
|
-// if("做多".equals(userPosition.getOrderDirection())){
|
|
|
-// // 现价大于等于委托价
|
|
|
-// if (buyOrderPrice.compareTo(userPosition.getBuyOrderPrice()) > -1){
|
|
|
-// toFulfill(userPosition, buyOrderPrice);
|
|
|
-// }
|
|
|
-// }else{
|
|
|
-// // 现价小于或者等于委托价
|
|
|
-// if (buyOrderPrice.compareTo(userPosition.getBuyOrderPrice()) < 1){
|
|
|
-// toFulfill(userPosition, buyOrderPrice);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// });
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -367,8 +352,9 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
for (IndexInfo indexInfo : indexInfoList) {
|
|
|
if (StringUtils.isNotEmpty(indexInfo.getDataDbName())) {
|
|
|
try {
|
|
|
- String nowPriceStr = getNowPriceStrByDbName(indexInfo.getDataDbName());
|
|
|
- nowPrice = BigDecimal.valueOf(Double.valueOf(nowPriceStr));
|
|
|
+ //每支code获取现价
|
|
|
+ StockListVO stockListVO = dbStockService.getStockListVO(indexInfo.getCode());
|
|
|
+ nowPrice = new BigDecimal(stockListVO.getNowPrice());
|
|
|
indexMap.put(indexInfo.getCnName(), nowPrice);
|
|
|
} catch (Exception e) {
|
|
|
// 数据库不存在
|
|
@@ -382,25 +368,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
if(judgeIsCloseOut(userPosition, nowPrice)){
|
|
|
closeOut(userPosition.getId(), null);
|
|
|
}
|
|
|
-// if("做多".equals(userPosition.getOrderDirection())){
|
|
|
-// if(nowPrice.compareTo(userPosition.getTargetprofit()) > -1){
|
|
|
-// // 当前价格 大于等于 止盈价格 进行平仓操作
|
|
|
-// closeOut(userPosition.getId());
|
|
|
-// }
|
|
|
-// else if(nowPrice.compareTo(userPosition.getStoploss()) < 1){
|
|
|
-// // 当前价格 小于等于 止损价格 进行平仓操作
|
|
|
-// closeOut(userPosition.getId());
|
|
|
-// }
|
|
|
-// }else{
|
|
|
-// if(nowPrice.compareTo(userPosition.getStoploss()) > -1){
|
|
|
-// // 当前价格 大于等于 止损价格 进行平仓操作
|
|
|
-// closeOut(userPosition.getId());
|
|
|
-// }
|
|
|
-// else if(nowPrice.compareTo(userPosition.getTargetprofit()) < 1){
|
|
|
-// // 当前价格 小于等于 止盈价格 进行平仓操作
|
|
|
-// closeOut(userPosition.getId());
|
|
|
-// }
|
|
|
-// }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -412,8 +379,9 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
for (IndexInfo indexInfo : indexInfoList) {
|
|
|
if (StringUtils.isNotEmpty(indexInfo.getDataDbName())) {
|
|
|
try {
|
|
|
- String nowPriceStr = getNowPriceStrByDbName(indexInfo.getDataDbName());
|
|
|
- nowPrice = BigDecimal.valueOf(Double.valueOf(nowPriceStr));
|
|
|
+ //每支code获取现价
|
|
|
+ StockListVO stockListVO = dbStockService.getStockListVO(indexInfo.getCode());
|
|
|
+ nowPrice = new BigDecimal(stockListVO.getNowPrice());
|
|
|
indexMap.put(indexInfo.getCnName(), nowPrice);
|
|
|
} catch (Exception e) {
|
|
|
// 数据库不存在
|
|
@@ -421,7 +389,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
// 获取有设置止盈的账号
|
|
|
List<UserPosition> userPositionList = userPositionMapper.selectPositionByStopProfitTarget();
|
|
|
for(UserPosition userPosition : userPositionList){
|
|
@@ -429,26 +396,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
if(judgeIsCloseOut(userPosition, nowPrice)){
|
|
|
closeOut(userPosition.getId(), null);
|
|
|
}
|
|
|
-// //判断做多 做空
|
|
|
-// if("做多".equals(userPosition.getOrderDirection())){
|
|
|
-// if(nowPrice.compareTo(userPosition.getTargetprofit()) > -1){
|
|
|
-// // 当前价格 大于等于 止盈价格 进行平仓操作
|
|
|
-// closeOut(userPosition.getId());
|
|
|
-// }
|
|
|
-// else if(nowPrice.compareTo(userPosition.getStoploss()) < 1){
|
|
|
-// // 当前价格 小于等于 止损价格 进行平仓操作
|
|
|
-// closeOut(userPosition.getId());
|
|
|
-// }
|
|
|
-// }else{
|
|
|
-// if(nowPrice.compareTo(userPosition.getStoploss()) > -1){
|
|
|
-// // 当前价格 大于等于 止损价格 进行平仓操作
|
|
|
-// closeOut(userPosition.getId());
|
|
|
-// }
|
|
|
-// else if(nowPrice.compareTo(userPosition.getTargetprofit()) < 1){
|
|
|
-// // 当前价格 小于等于 止盈价格 进行平仓操作
|
|
|
-// closeOut(userPosition.getId());
|
|
|
-// }
|
|
|
-// }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -491,7 +438,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
User user = userMapper.selectByPrimaryKey(userId);
|
|
|
BigDecimal enableAmt = user.getEnableAmt();
|
|
|
BigDecimal allAmt = user.getUserAmt();
|
|
|
-
|
|
|
// 当前用户需要的总过夜费
|
|
|
int demurrageSum = userPositionMapper.selectUserDemurrageSum(userId);
|
|
|
if(-1 == enableAmt.compareTo(new BigDecimal(demurrageSum))){
|
|
@@ -507,41 +453,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
for(UserPosition userPosition : userPositionList){
|
|
|
orderStayFee = new BigDecimal(indexMap.get(userPosition.getStockName())).multiply(BigDecimal.valueOf(userPosition.getOrderNum()));
|
|
|
userPosition.setOrderStayFee(userPosition.getOrderStayFee().add(orderStayFee));
|
|
|
- // 修改用户资金
|
|
|
-// UserCashDetail ucd = new UserCashDetail();
|
|
|
-// ucd.setPositionId(userPosition.getId());
|
|
|
-// ucd.setAgentId(user.getAgentId());
|
|
|
-// ucd.setAgentName(user.getAgentName());
|
|
|
-// ucd.setUserId(user.getId());
|
|
|
-// ucd.setUserName(user.getRealName());
|
|
|
-// ucd.setDeType("留仓费");
|
|
|
-// ucd.setDeAmt(new BigDecimal(-demurrageSum));
|
|
|
-// ucd.setDeSummary("货币," + userPosition.getStockCode() + "/" + userPosition.getStockName() + ",扣过夜费:-" + orderStayFee);
|
|
|
-// ucd.setAddTime(new Date());
|
|
|
-// ucd.setIsRead(Integer.valueOf(0));
|
|
|
-// int insertSxfCount = this.userCashDetailMapper.insert(ucd);
|
|
|
-
|
|
|
-// UserCapitalDetail userCapitalDetail = new UserCapitalDetail();
|
|
|
-// userCapitalDetail.setAgentId(user.getAgentId());
|
|
|
-// userCapitalDetail.setAgentName(user.getAgentName());
|
|
|
-// userCapitalDetail.setUserId(user.getId());
|
|
|
-// userCapitalDetail.setUserName(user.getRealName());
|
|
|
-// userCapitalDetail.setPositionId(userPosition.getId());
|
|
|
-// userCapitalDetail.setDeType(3);
|
|
|
-// userCapitalDetail.setIsRead(Integer.valueOf(0));
|
|
|
-// userCapitalDetail.setOrderNum(userPosition.getOrderNum());
|
|
|
-// userCapitalDetail.setBuyFeeAmt(new BigDecimal(0));
|
|
|
-// userCapitalDetail.setOrderSpread(new BigDecimal(0));
|
|
|
-// userCapitalDetail.setOrderStayFee(orderStayFee);
|
|
|
-// userCapitalDetail.setAllProfit(new BigDecimal(0));
|
|
|
-// userCapitalDetail.setStockName(userPosition.getStockName());
|
|
|
-// userCapitalDetail.setStockCode(userPosition.getStockCode());
|
|
|
-// int insertSxfCount = this.userCashDetailMapper.insertUserCapitalDetail(userCapitalDetail);
|
|
|
-// if (insertSxfCount > 0) {
|
|
|
-// log.info("【过夜费】保存明细记录成功");
|
|
|
-// } else {
|
|
|
-// log.error("过夜费】保存明细记录出错");
|
|
|
-// }
|
|
|
// 修改持仓表过夜费
|
|
|
userPositionMapper.updateOrderStayFee(userPosition);
|
|
|
}
|
|
@@ -588,7 +499,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
log.error("用户撤单】修改用户金额出错");
|
|
|
throw new Exception("用户撤单】修改用户金额出错");
|
|
|
}
|
|
|
-
|
|
|
int res = this.userPositionMapper.deleteByPrimaryKey(positionId);
|
|
|
if (res>0){
|
|
|
return ServerResponse.createBySuccess("撤单成功");
|
|
@@ -666,26 +576,20 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
return ServerResponse.createByErrorMsg("挂单价格不在价差范围内");
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
// 用户可用资金
|
|
|
BigDecimal user_enable_amt = user.getEnableAmt();
|
|
|
-
|
|
|
// 委托价 * 购买手数
|
|
|
BigDecimal buy_amt_autual = buyOrderPrice.multiply(new BigDecimal(buyNum));
|
|
|
log.info("用户可用金额 = {} 实际购买金额 = {}", user_enable_amt, buy_amt_autual);
|
|
|
-
|
|
|
// 手续费
|
|
|
BigDecimal position_freez = new BigDecimal(buyNum*stock.getTransFee());
|
|
|
-
|
|
|
//冻结保证金
|
|
|
BigDecimal depositFreezeAmt = new BigDecimal(buyNum*stock.getDepositAmt());
|
|
|
BigDecimal subtractDepositFreezeAmt = user_enable_amt.subtract(depositFreezeAmt).subtract(position_freez);
|
|
|
-
|
|
|
log.info("挂单冻结保证金="+depositFreezeAmt);
|
|
|
// depositFreezeAmt = depositFreezeAmt.add(position_freez);
|
|
|
log.info("挂单冻结手续费="+position_freez);
|
|
|
log.info("挂单冻结金额="+depositFreezeAmt);
|
|
|
-
|
|
|
// 保证金和手续费 大于 用户可用资金 挂单失败
|
|
|
if ((depositFreezeAmt.add(position_freez)).compareTo(user.getEnableAmt()) > -1){
|
|
|
log.info("用户余额不足冻结保证金");
|
|
@@ -700,7 +604,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
log.error("用户交易挂单】修改用户金额出错");
|
|
|
throw new Exception("用户交易挂单】修改用户金额出错");
|
|
|
}
|
|
|
-
|
|
|
UserPosition userPosition = new UserPosition();
|
|
|
userPosition.setPositionType(user.getAccountType());
|
|
|
userPosition.setPositionSn(KeyUtils.getUniqueKey());
|
|
@@ -715,7 +618,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
userPosition.setBuyOrderTime(new Date());
|
|
|
userPosition.setBuyOrderPrice(buyOrderPrice);
|
|
|
userPosition.setOrderDirection((buyType == 0) ? "做多" : "做空");
|
|
|
-
|
|
|
userPosition.setOrderNum(buyNum);
|
|
|
if (stock.getStockPlate() != null) {
|
|
|
userPosition.setStockPlate(stock.getStockPlate());
|
|
@@ -732,7 +634,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
userPosition.setDepositFreezeAmt(depositFreezeAmt);
|
|
|
userPosition.setEntryOrders(1);
|
|
|
int insertPositionCount = this.userPositionMapper.insertSelective(userPosition);
|
|
|
-
|
|
|
// UserCapitalDetail userCapitalDetail = new UserCapitalDetail();
|
|
|
// userCapitalDetail.setAgentId(user.getAgentId());
|
|
|
// userCapitalDetail.setAgentName(user.getAgentName());
|
|
@@ -748,7 +649,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
// userCapitalDetail.setStockName(stock.getStockName());
|
|
|
// userCapitalDetail.setStockCode(stock.getStockCode());
|
|
|
// int insertSxfCount = this.userCashDetailMapper.insertUserCapitalDetail(userCapitalDetail);
|
|
|
-
|
|
|
if (insertPositionCount > 0) {
|
|
|
log.info("【用户交易挂单】保存持仓记录成功");
|
|
|
} else {
|
|
@@ -929,19 +829,15 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
|
|
|
public ServerResponse sell(String positionSn, int doType) throws Exception {
|
|
|
log.info("【用户交易平仓】 positionSn = {} , dotype = {}", positionSn, Integer.valueOf(doType));
|
|
|
-
|
|
|
SiteSetting siteSetting = this.iSiteSettingService.getSiteSetting();
|
|
|
-
|
|
|
UserPosition userPosition = this.userPositionMapper.findPositionBySn(positionSn);
|
|
|
if (userPosition == null) {
|
|
|
return ServerResponse.createByErrorMsg("平仓失败,订单不存在");
|
|
|
}
|
|
|
-
|
|
|
if (siteSetting == null) {
|
|
|
log.error("平仓出错,网站设置表不存在");
|
|
|
return ServerResponse.createByErrorMsg("下单失败,系统设置错误");
|
|
|
}
|
|
|
-
|
|
|
if (doType != 0) {
|
|
|
// 交易时间
|
|
|
String am_begin = siteSetting.getTransAmBegin();
|
|
@@ -955,94 +851,69 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
return ServerResponse.createByErrorMsg("平仓失败,不在交易时段内");
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
User user = this.userMapper.selectByPrimaryKey(userPosition.getUserId());
|
|
|
if (user.getIsLock().intValue() == 1) {
|
|
|
return ServerResponse.createByErrorMsg("平仓失败,用户已被锁定");
|
|
|
}
|
|
|
-
|
|
|
if (userPosition.getSellOrderId() != null) {
|
|
|
return ServerResponse.createByErrorMsg("平仓失败,此订单已平仓");
|
|
|
}
|
|
|
-
|
|
|
if (1 == userPosition.getIsLock().intValue()) {
|
|
|
return ServerResponse.createByErrorMsg("平仓失败 " + userPosition.getLockMsg());
|
|
|
}
|
|
|
-
|
|
|
Stock stock = stockMapper.findStockByName(userPosition.getStockName());
|
|
|
- StockIndexDF stockIndexDF = getStockIndexDFByDbName(stock.getDataDbName());
|
|
|
- StockListVO stockListVO = SinaStockApi.assembleStockListVO(stockIndexDF);
|
|
|
-
|
|
|
+ // 获取股票最新价格
|
|
|
+ StockListVO stockListVO = dbStockService.getStockListVO(stock.getStockGid());
|
|
|
BigDecimal now_price = new BigDecimal(stockListVO.getNowPrice());
|
|
|
if (now_price.compareTo(new BigDecimal("0")) != 1) {
|
|
|
log.error("货币 = {} 收到报价 = {}", userPosition.getStockName(), now_price);
|
|
|
return ServerResponse.createByErrorMsg("报价0,平仓失败,请稍后再试");
|
|
|
}
|
|
|
-
|
|
|
double stock_crease = stockListVO.getHcrate().doubleValue();
|
|
|
-
|
|
|
BigDecimal zsPrice = new BigDecimal(stockListVO.getPreclose_px());
|
|
|
-
|
|
|
BigDecimal ztPrice = zsPrice.multiply(new BigDecimal("0.1")).add(zsPrice);
|
|
|
ztPrice = ztPrice.setScale(2, 4);
|
|
|
BigDecimal chaPrice = ztPrice.subtract(zsPrice);
|
|
|
-
|
|
|
BigDecimal ztRate = chaPrice.multiply(new BigDecimal("100")).divide(zsPrice, 2, RoundingMode.HALF_UP);
|
|
|
-
|
|
|
ztRate = ztRate.negate();
|
|
|
log.info("货币当前涨跌幅 = {} 跌停幅度 = {}", Double.valueOf(stock_crease), ztRate);
|
|
|
if ((new BigDecimal(String.valueOf(stock_crease))).compareTo(ztRate) == 0 && "做多"
|
|
|
.equals(userPosition.getOrderDirection())) {
|
|
|
return ServerResponse.createByErrorMsg("当前货币已跌停不能卖出");
|
|
|
}
|
|
|
-
|
|
|
Integer buy_num = userPosition.getOrderNum();
|
|
|
-
|
|
|
BigDecimal all_buy_amt = userPosition.getOrderTotalPrice();
|
|
|
BigDecimal all_sell_amt = now_price.multiply(new BigDecimal(buy_num.intValue()));
|
|
|
-
|
|
|
BigDecimal profitLoss = new BigDecimal("0");
|
|
|
if ("做多".equals(userPosition.getOrderDirection())) {
|
|
|
log.info("买卖方向:{}", "涨");
|
|
|
-
|
|
|
profitLoss = all_sell_amt.subtract(all_buy_amt);
|
|
|
} else {
|
|
|
log.info("买卖方向:{}", "跌");
|
|
|
profitLoss = all_buy_amt.subtract(all_sell_amt);
|
|
|
}
|
|
|
log.info("买入总金额 = {} , 卖出总金额 = {} , 盈亏 = {}", new Object[]{all_buy_amt, all_sell_amt, profitLoss});
|
|
|
-
|
|
|
BigDecimal user_all_amt = user.getUserAmt();
|
|
|
BigDecimal user_enable_amt = user.getEnableAmt();
|
|
|
log.info("用户原本总资金 = {} , 可用 = {}", user_all_amt, user_enable_amt);
|
|
|
-
|
|
|
BigDecimal buy_fee_amt = userPosition.getOrderFee();
|
|
|
log.info("买入手续费 = {}", buy_fee_amt);
|
|
|
-
|
|
|
BigDecimal orderSpread = userPosition.getOrderSpread();
|
|
|
log.info("点差 = {}", orderSpread);
|
|
|
-
|
|
|
BigDecimal orderStayFee = userPosition.getOrderStayFee();
|
|
|
log.info("留仓费 = {}", orderStayFee);
|
|
|
-
|
|
|
BigDecimal sell_fee_amt = all_sell_amt.multiply(siteSetting.getSellFee()).setScale(2, 4);
|
|
|
log.info("卖出手续费 = {}", sell_fee_amt);
|
|
|
-
|
|
|
BigDecimal all_fee_amt = buy_fee_amt.add(sell_fee_amt).add(orderSpread).add(orderStayFee);
|
|
|
log.info("总的手续费费用 = {}", all_fee_amt);
|
|
|
-
|
|
|
userPosition.setSellOrderId(GeneratePosition.getPositionId());
|
|
|
userPosition.setSellOrderPrice(now_price);
|
|
|
userPosition.setSellOrderTime(new Date());
|
|
|
-
|
|
|
BigDecimal order_fee_all = buy_fee_amt.add(sell_fee_amt);
|
|
|
userPosition.setOrderFee(order_fee_all);
|
|
|
-
|
|
|
userPosition.setProfitAndLose(profitLoss);
|
|
|
-
|
|
|
BigDecimal all_profit = profitLoss.subtract(all_fee_amt);
|
|
|
userPosition.setAllProfitAndLose(all_profit);
|
|
|
-
|
|
|
int updatePositionCount = this.userPositionMapper.updateByPrimaryKeySelective(userPosition);
|
|
|
if (updatePositionCount > 0) {
|
|
|
log.info("【用户平仓】修改浮动盈亏记录成功");
|
|
@@ -1050,12 +921,9 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
log.error("用户平仓】修改浮动盈亏记录出错");
|
|
|
throw new Exception("用户平仓】修改浮动盈亏记录出错");
|
|
|
}
|
|
|
-
|
|
|
BigDecimal freez_amt = all_buy_amt.divide(new BigDecimal(userPosition.getOrderLever().intValue()), 2, 4);
|
|
|
-
|
|
|
BigDecimal reckon_all = user_all_amt.add(all_profit);
|
|
|
BigDecimal reckon_enable = user_enable_amt.add(all_profit).add(freez_amt);
|
|
|
-
|
|
|
log.info("用户平仓后的总资金 = {} , 可用资金 = {}", reckon_all, reckon_enable);
|
|
|
user.setUserAmt(reckon_all);
|
|
|
user.setEnableAmt(reckon_enable);
|
|
@@ -1066,20 +934,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
log.error("用户平仓】修改用户金额出错");
|
|
|
throw new Exception("用户平仓】修改用户金额出错");
|
|
|
}
|
|
|
-
|
|
|
-// UserCashDetail ucd = new UserCashDetail();
|
|
|
-// ucd.setPositionId(userPosition.getId());
|
|
|
-// ucd.setAgentId(user.getAgentId());
|
|
|
-// ucd.setAgentName(user.getAgentName());
|
|
|
-// ucd.setUserId(user.getId());
|
|
|
-// ucd.setUserName(user.getRealName());
|
|
|
-// ucd.setDeType("总盈亏");
|
|
|
-// ucd.setDeAmt(all_profit);
|
|
|
-// ucd.setDeSummary("卖出货币," + userPosition.getStockCode() + "/" + userPosition.getStockName() + ",手续费:" + buy_fee_amt + ",盈亏:" + all_profit + ",点差:" + orderSpread + ",留仓费:" + orderStayFee);
|
|
|
-// ucd.setAddTime(new Date());
|
|
|
-// ucd.setIsRead(Integer.valueOf(0));
|
|
|
-// int insertSxfCount = this.userCashDetailMapper.insert(ucd);
|
|
|
-
|
|
|
UserCapitalDetail userCapitalDetail = new UserCapitalDetail();
|
|
|
userCapitalDetail.setAgentId(user.getAgentId());
|
|
|
userCapitalDetail.setAgentName(user.getAgentName());
|
|
@@ -1102,7 +956,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
log.error("用户平仓】保存明细记录出错");
|
|
|
throw new Exception("用户平仓】保存明细记录出错");
|
|
|
}
|
|
|
-
|
|
|
return ServerResponse.createBySuccessMsg("平仓成功!");
|
|
|
}
|
|
|
|
|
@@ -1313,23 +1166,18 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
|
|
|
public ServerResponse listByAgent(Integer positionType, Integer state, Integer userId, Integer agentId, String positionSn, String beginTime, String endTime, HttpServletRequest request, int pageNum, int pageSize) {
|
|
|
AgentUser currentAgent = this.iAgentUserService.getCurrentAgent(request);
|
|
|
-
|
|
|
-
|
|
|
if (agentId != null) {
|
|
|
AgentUser agentUser = this.agentUserMapper.selectByPrimaryKey(agentId);
|
|
|
if (agentUser.getParentId() != currentAgent.getId()) {
|
|
|
return ServerResponse.createByErrorMsg("不能查询非下级代理用户持仓");
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
Integer searchId = null;
|
|
|
if (agentId == null) {
|
|
|
searchId = currentAgent.getId();
|
|
|
} else {
|
|
|
searchId = agentId;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
Timestamp begin_time = null;
|
|
|
if (StringUtils.isNotBlank(beginTime)) {
|
|
|
begin_time = DateTimeUtil.searchStrToTimestamp(beginTime);
|
|
@@ -1338,16 +1186,14 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
if (StringUtils.isNotBlank(endTime)) {
|
|
|
end_time = DateTimeUtil.searchStrToTimestamp(endTime);
|
|
|
}
|
|
|
-
|
|
|
PageHelper.startPage(pageNum, pageSize);
|
|
|
-
|
|
|
Map<String, IndexInfo> indexMap = new HashMap<>();
|
|
|
List<IndexInfo> indexInfoList = stockMapper.selectStockList();
|
|
|
for (IndexInfo indexInfo : indexInfoList) {
|
|
|
if (StringUtils.isNotEmpty(indexInfo.getDataDbName())) {
|
|
|
try {
|
|
|
- String nowPriceStr = getNowPriceStrByDbName(indexInfo.getDataDbName());
|
|
|
- BigDecimal nowPrice = BigDecimal.valueOf(Double.valueOf(nowPriceStr));
|
|
|
+ StockListVO stockListVO = dbStockService.getStockListVO(indexInfo.getCode());
|
|
|
+ BigDecimal nowPrice = new BigDecimal(stockListVO.getNowPrice());
|
|
|
indexInfo.setNowPrice(nowPrice);
|
|
|
} catch (Exception e) {
|
|
|
// 数据库不存在
|
|
@@ -1357,24 +1203,17 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
indexMap.put(indexInfo.getCnName(), indexInfo);
|
|
|
}
|
|
|
List<UserPosition> userPositions = this.userPositionMapper.listByAgent(positionType, state, userId, searchId, positionSn, begin_time, end_time);
|
|
|
-
|
|
|
List<AgentPositionVO> agentPositionVOS = Lists.newArrayList();
|
|
|
for (UserPosition position : userPositions) {
|
|
|
AgentPositionVO agentPositionVO = assembleAgentPositionVO(position, state, indexMap);
|
|
|
agentPositionVOS.add(agentPositionVO);
|
|
|
}
|
|
|
-
|
|
|
PageInfo pageInfo = new PageInfo(userPositions);
|
|
|
pageInfo.setList(agentPositionVOS);
|
|
|
-
|
|
|
return ServerResponse.createBySuccess(pageInfo);
|
|
|
}
|
|
|
|
|
|
public ServerResponse getIncome(Integer agentId, Integer positionType, String beginTime, String endTime) {
|
|
|
-// if (StringUtils.isBlank(beginTime) || StringUtils.isBlank(endTime)) {
|
|
|
-// return ServerResponse.createByErrorMsg("时间不能为空");
|
|
|
-// }
|
|
|
-
|
|
|
Timestamp begin_time = null;
|
|
|
if (StringUtils.isNotBlank(beginTime)) {
|
|
|
begin_time = DateTimeUtil.searchStrToTimestamp(beginTime);
|
|
@@ -1405,8 +1244,8 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
for (IndexInfo indexInfo : indexInfoList) {
|
|
|
if (StringUtils.isNotEmpty(indexInfo.getDataDbName())) {
|
|
|
try {
|
|
|
- String nowPriceStr = getNowPriceStrByDbName(indexInfo.getDataDbName());
|
|
|
- nowPrice = BigDecimal.valueOf(Double.valueOf(nowPriceStr));
|
|
|
+ StockListVO stockListVO = dbStockService.getStockListVO(indexInfo.getCode());
|
|
|
+ nowPrice = new BigDecimal(stockListVO.getNowPrice());
|
|
|
indexInfo.setNowPrice(nowPrice);
|
|
|
} catch (Exception e) {
|
|
|
// 数据库不存在
|
|
@@ -1440,8 +1279,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
|
|
|
public ServerResponse listByAdmin(Integer agentId, Integer positionType, Integer state, Integer userId, String positionSn, String beginTime, String endTime, int pageNum, int pageSize) {
|
|
|
PageHelper.startPage(pageNum, pageSize);
|
|
|
-
|
|
|
-
|
|
|
Timestamp begin_time = null;
|
|
|
if (StringUtils.isNotBlank(beginTime)) {
|
|
|
begin_time = DateTimeUtil.searchStrToTimestamp(beginTime);
|
|
@@ -1450,17 +1287,14 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
if (StringUtils.isNotBlank(endTime)) {
|
|
|
end_time = DateTimeUtil.searchStrToTimestamp(endTime);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
List<UserPosition> userPositions = this.userPositionMapper.listByAgent(positionType, state, userId, agentId, positionSn, begin_time, end_time);
|
|
|
-
|
|
|
Map<String, IndexInfo> indexMap = new HashMap<>();
|
|
|
List<IndexInfo> indexInfoList = stockMapper.selectStockList();
|
|
|
for (IndexInfo indexInfo : indexInfoList) {
|
|
|
if (StringUtils.isNotEmpty(indexInfo.getDataDbName())) {
|
|
|
try {
|
|
|
- String nowPriceStr = getNowPriceStrByDbName(indexInfo.getDataDbName());
|
|
|
- BigDecimal nowPrice = BigDecimal.valueOf(Double.valueOf(nowPriceStr));
|
|
|
+ StockListVO stockListVO = dbStockService.getStockListVO(indexInfo.getCode());
|
|
|
+ BigDecimal nowPrice = new BigDecimal(stockListVO.getNowPrice());
|
|
|
indexInfo.setNowPrice(nowPrice);
|
|
|
} catch (Exception e) {
|
|
|
// 数据库不存在
|
|
@@ -1469,17 +1303,14 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
}
|
|
|
indexMap.put(indexInfo.getCnName(), indexInfo);
|
|
|
}
|
|
|
-
|
|
|
List<AdminPositionVO> adminPositionVOS = Lists.newArrayList();
|
|
|
for (UserPosition position : userPositions) {
|
|
|
IndexInfo indexInfo = indexMap.get(position.getStockName());
|
|
|
AdminPositionVO adminPositionVO = assembleAdminPositionVO(position, state, indexMap);
|
|
|
adminPositionVOS.add(adminPositionVO);
|
|
|
}
|
|
|
-
|
|
|
PageInfo pageInfo = new PageInfo(userPositions);
|
|
|
pageInfo.setList(adminPositionVOS);
|
|
|
-
|
|
|
return ServerResponse.createBySuccess(pageInfo);
|
|
|
}
|
|
|
|
|
@@ -1501,7 +1332,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
|
|
|
return ServerResponse.createByErrorMsg("参数不能为空");
|
|
|
}
|
|
|
-
|
|
|
User user = this.userMapper.selectByPrimaryKey(userId);
|
|
|
if (user == null) {
|
|
|
return ServerResponse.createByErrorMsg("用户不存在");
|
|
@@ -1509,34 +1339,24 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
if (user.getAccountType().intValue() != 1) {
|
|
|
return ServerResponse.createByErrorMsg("正式用户不能生成持仓单");
|
|
|
}
|
|
|
-
|
|
|
Stock stock = (Stock) this.iStockService.findStockByCode(stockCode).getData();
|
|
|
if (stock == null) {
|
|
|
return ServerResponse.createByErrorMsg("货币不存在");
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
SiteSetting siteSetting = this.iSiteSettingService.getSiteSetting();
|
|
|
if (siteSetting == null) {
|
|
|
log.error("下单出错,网站设置表不存在");
|
|
|
return ServerResponse.createByErrorMsg("下单失败,系统设置错误");
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
BigDecimal user_enable_amt = user.getEnableAmt();
|
|
|
-
|
|
|
BigDecimal buy_amt = (new BigDecimal(buyPrice)).multiply(new BigDecimal(buyNum.intValue()));
|
|
|
BigDecimal buy_amt_autual = buy_amt.divide(new BigDecimal(lever.intValue()), 2, 4);
|
|
|
-
|
|
|
-
|
|
|
int compareUserAmtInt = user_enable_amt.compareTo(buy_amt_autual);
|
|
|
log.info("用户可用金额 = {} 实际购买金额 = {}", user_enable_amt, buy_amt_autual);
|
|
|
log.info("比较 用户金额 和 实际 购买金额 = {}", Integer.valueOf(compareUserAmtInt));
|
|
|
if (compareUserAmtInt == -1) {
|
|
|
return ServerResponse.createByErrorMsg("下单失败,用户可用金额小于" + buy_amt_autual + "元");
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
BigDecimal reckon_enable = user_enable_amt.subtract(buy_amt_autual);
|
|
|
user.setEnableAmt(reckon_enable);
|
|
|
int updateUserCount = this.userMapper.updateByPrimaryKeySelective(user);
|
|
@@ -1545,8 +1365,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
} else {
|
|
|
log.error("用户交易下单】修改用户金额出错");
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
UserPosition userPosition = new UserPosition();
|
|
|
userPosition.setPositionType(Integer.valueOf(1));
|
|
|
userPosition.setPositionSn(KeyUtils.getUniqueKey());
|
|
@@ -1560,48 +1378,29 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
userPosition.setBuyOrderId(GeneratePosition.getPositionId());
|
|
|
userPosition.setBuyOrderTime(DateTimeUtil.strToDate(buyTime));
|
|
|
userPosition.setBuyOrderPrice(new BigDecimal(buyPrice));
|
|
|
- userPosition.setOrderDirection((buyType.intValue() == 0) ? "做多" : "做空");
|
|
|
-
|
|
|
+ userPosition.setOrderDirection((buyType == 0) ? "做多" : "做空");
|
|
|
userPosition.setOrderNum(buyNum);
|
|
|
-
|
|
|
-
|
|
|
- userPosition.setIsLock(Integer.valueOf(0));
|
|
|
-
|
|
|
-
|
|
|
+ userPosition.setIsLock(0);
|
|
|
userPosition.setOrderLever(lever);
|
|
|
-
|
|
|
-
|
|
|
userPosition.setOrderTotalPrice(buy_amt);
|
|
|
-
|
|
|
-
|
|
|
BigDecimal buy_fee_amt = buy_amt.multiply(siteSetting.getBuyFee()).setScale(2, 4);
|
|
|
log.info("创建模拟持仓 手续费(配资后总资金 * 百分比) = {}", buy_fee_amt);
|
|
|
userPosition.setOrderFee(buy_fee_amt);
|
|
|
-
|
|
|
-
|
|
|
BigDecimal buy_yhs_amt = buy_amt.multiply(siteSetting.getDutyFee()).setScale(2, 4);
|
|
|
log.info("创建模拟持仓 点差(配资后总资金 * 百分比) = {}", buy_yhs_amt);
|
|
|
userPosition.setOrderSpread(buy_yhs_amt);
|
|
|
-
|
|
|
-
|
|
|
BigDecimal profit_and_lose = new BigDecimal("0");
|
|
|
userPosition.setProfitAndLose(profit_and_lose);
|
|
|
-
|
|
|
-
|
|
|
BigDecimal all_profit_and_lose = profit_and_lose.subtract(buy_fee_amt).subtract(buy_yhs_amt);
|
|
|
userPosition.setAllProfitAndLose(all_profit_and_lose);
|
|
|
-
|
|
|
-
|
|
|
- userPosition.setOrderStayDays(Integer.valueOf(0));
|
|
|
+ userPosition.setOrderStayDays(0);
|
|
|
userPosition.setOrderStayFee(new BigDecimal("0"));
|
|
|
-
|
|
|
int insertPositionCount = this.userPositionMapper.insert(userPosition);
|
|
|
if (insertPositionCount > 0) {
|
|
|
log.info("【创建模拟持仓】保存记录成功");
|
|
|
} else {
|
|
|
log.error("【创建模拟持仓】保存记录出错");
|
|
|
}
|
|
|
-
|
|
|
return ServerResponse.createBySuccess("生成模拟持仓成功");
|
|
|
}
|
|
|
|
|
@@ -1611,22 +1410,18 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
|
|
|
public void doClosingStayTask() {
|
|
|
List<UserPosition> userPositions = this.userPositionMapper.findAllStayPosition();
|
|
|
-
|
|
|
-
|
|
|
if (userPositions.size() > 0) {
|
|
|
- log.info("查询到正在持仓的订单数量 = {}", Integer.valueOf(userPositions.size()));
|
|
|
-
|
|
|
+ log.info("查询到正在持仓的订单数量 = {}", userPositions.size());
|
|
|
for (UserPosition position : userPositions) {
|
|
|
int stayDays = GetStayDays.getDays(GetStayDays.getBeginDate(position.getBuyOrderTime()));
|
|
|
-
|
|
|
log.info("");
|
|
|
- log.info("开始处理 持仓订单id = {} 订单号 = {} 用户id = {} realName = {} 留仓天数 = {}", new Object[]{position
|
|
|
+ log.info("开始处理 持仓订单id = {} 订单号 = {} 用户id = {} realName = {} 留仓天数 = {}", position
|
|
|
.getId(), position.getPositionSn(), position.getUserId(), position
|
|
|
- .getNickName(), Integer.valueOf(stayDays)});
|
|
|
+ .getNickName(), stayDays);
|
|
|
if (stayDays != 0) {
|
|
|
- log.info(" 开始收取 {} 天 留仓费", Integer.valueOf(stayDays));
|
|
|
+ log.info(" 开始收取 {} 天 留仓费", stayDays);
|
|
|
try {
|
|
|
- closingStayTask(position, Integer.valueOf(stayDays));
|
|
|
+ closingStayTask(position, stayDays);
|
|
|
} catch (Exception e) {
|
|
|
log.error("doClosingStayTask = ", e);
|
|
|
}
|
|
@@ -1634,14 +1429,11 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
log.info("持仓订单 = {} ,持仓天数0天,不需要处理...", position.getId());
|
|
|
}
|
|
|
log.info("修改留仓费 处理结束。");
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
SiteTaskLog stl = new SiteTaskLog();
|
|
|
stl.setTaskType("扣除留仓费");
|
|
|
stl.setAddTime(new Date());
|
|
|
- stl.setIsSuccess(Integer.valueOf(0));
|
|
|
+ stl.setIsSuccess(0);
|
|
|
stl.setTaskTarget("扣除留仓费,订单数量为" + userPositions.size());
|
|
|
this.siteTaskLogMapper.insert(stl);
|
|
|
} else {
|
|
@@ -1659,24 +1451,15 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
log.error("修改留仓费出错,网站设置表不存在");
|
|
|
return ServerResponse.createByErrorMsg("修改留仓费出错,网站设置表不存在");
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
BigDecimal stayFee = position.getOrderTotalPrice().multiply(siteSetting.getStayFee());
|
|
|
-
|
|
|
BigDecimal allStayFee = stayFee.multiply(new BigDecimal(stayDays.intValue()));
|
|
|
-
|
|
|
log.info("总留仓费 = {}", allStayFee);
|
|
|
-
|
|
|
-
|
|
|
position.setOrderStayFee(allStayFee);
|
|
|
position.setOrderStayDays(stayDays);
|
|
|
-
|
|
|
BigDecimal all_profit = position.getAllProfitAndLose().subtract(allStayFee);
|
|
|
position.setAllProfitAndLose(all_profit);
|
|
|
-
|
|
|
int updateCount = this.userPositionMapper.updateByPrimaryKeySelective(position);
|
|
|
if (updateCount > 0) {
|
|
|
-
|
|
|
User user = this.userMapper.selectByPrimaryKey(position.getUserId());
|
|
|
UserCashDetail ucd = new UserCashDetail();
|
|
|
ucd.setPositionId(position.getId());
|
|
@@ -1695,8 +1478,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
log.error("【closingStayTask收持仓费】修改持仓记录出错");
|
|
|
throw new Exception("【closingStayTask收持仓费】修改持仓记录出错");
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
log.info("=======================================================");
|
|
|
return ServerResponse.createBySuccess();
|
|
|
}
|
|
@@ -1707,9 +1488,7 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
|
|
|
private AdminPositionVO assembleAdminPositionVO(UserPosition position, Integer state, Map<String, IndexInfo> indexMap) {
|
|
|
AdminPositionVO adminPositionVO = new AdminPositionVO();
|
|
|
-
|
|
|
adminPositionVO.setId(position.getId());
|
|
|
-
|
|
|
adminPositionVO.setPositionSn(position.getPositionSn());
|
|
|
adminPositionVO.setPositionType(position.getPositionType());
|
|
|
adminPositionVO.setUserId(position.getUserId());
|
|
@@ -1733,12 +1512,9 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
adminPositionVO.setOrderSpread(position.getOrderSpread());
|
|
|
adminPositionVO.setOrderStayFee(position.getOrderStayFee());
|
|
|
adminPositionVO.setOrderStayDays(position.getOrderStayDays());
|
|
|
-
|
|
|
adminPositionVO.setIsLock(position.getIsLock());
|
|
|
adminPositionVO.setLockMsg(position.getLockMsg());
|
|
|
-
|
|
|
adminPositionVO.setStockPlate(position.getStockPlate());
|
|
|
-
|
|
|
// 计算浮动盈亏 如果是平仓的就不需要计算了 直接去数据库中的
|
|
|
if(1 != state){
|
|
|
PositionProfitVO positionProfitVO = getPositionProfitVO(position, indexMap);
|
|
@@ -1757,7 +1533,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
|
|
|
private AgentPositionVO assembleAgentPositionVO(UserPosition position, Integer state, Map<String, IndexInfo> indexMap) {
|
|
|
AgentPositionVO agentPositionVO = new AgentPositionVO();
|
|
|
-
|
|
|
agentPositionVO.setId(position.getId());
|
|
|
agentPositionVO.setPositionSn(position.getPositionSn());
|
|
|
agentPositionVO.setPositionType(position.getPositionType());
|
|
@@ -1782,14 +1557,10 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
agentPositionVO.setOrderSpread(position.getOrderSpread());
|
|
|
agentPositionVO.setOrderStayFee(position.getOrderStayFee());
|
|
|
agentPositionVO.setOrderStayDays(position.getOrderStayDays());
|
|
|
-
|
|
|
agentPositionVO.setIsLock(position.getIsLock());
|
|
|
agentPositionVO.setLockMsg(position.getLockMsg());
|
|
|
-
|
|
|
agentPositionVO.setStockPlate(position.getStockPlate());
|
|
|
-
|
|
|
// PositionProfitVO positionProfitVO = getPositionProfitVO(position, indexMap);
|
|
|
-
|
|
|
// 计算浮动盈亏 如果是平仓的就不需要计算了 直接去数据库中的
|
|
|
if(1 != state){
|
|
|
PositionProfitVO positionProfitVO = getPositionProfitVO(position, indexMap);
|
|
@@ -1801,8 +1572,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
agentPositionVO.setProfitAndLose(position.getProfitAndLose());
|
|
|
agentPositionVO.setAllProfitAndLose(position.getAllProfitAndLose());
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
// agentPositionVO.setProfitAndLose(positionProfitVO.getProfitAndLose());
|
|
|
// agentPositionVO.setAllProfitAndLose(positionProfitVO.getAllProfitAndLose());
|
|
|
// agentPositionVO.setNow_price(positionProfitVO.getNowPrice());
|
|
@@ -1812,7 +1581,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
|
|
|
private UserPositionVO assembleUserPositionVO(UserPosition position) {
|
|
|
UserPositionVO userPositionVO = new UserPositionVO();
|
|
|
-
|
|
|
userPositionVO.setId(position.getId());
|
|
|
userPositionVO.setPositionType(position.getPositionType());
|
|
|
userPositionVO.setPositionSn(position.getPositionSn());
|
|
@@ -1839,11 +1607,9 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
userPositionVO.setOrderSpread(position.getOrderSpread());
|
|
|
userPositionVO.setOrderStayFee(position.getOrderStayFee());
|
|
|
userPositionVO.setOrderStayDays(position.getOrderStayDays());
|
|
|
-
|
|
|
userPositionVO.setStoploss(position.getStoploss());
|
|
|
userPositionVO.setTargetprofit(position.getTargetprofit());
|
|
|
userPositionVO.setStockPlate(position.getStockPlate());
|
|
|
-
|
|
|
// PositionProfitVO positionProfitVO = getPositionProfitVO(position);
|
|
|
userPositionVO.setProfitAndLose(position.getProfitAndLose());
|
|
|
userPositionVO.setAllProfitAndLose(position.getAllProfitAndLose());
|
|
@@ -1870,7 +1636,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
// allProfitAndLose = yk.add(position.getOrderFee());
|
|
|
allProfitAndLose = yk;
|
|
|
profitAndLose = yk;
|
|
|
-
|
|
|
// 计算风险率
|
|
|
User user = userMapper.selectByPrimaryKey(position.getUserId());
|
|
|
List<UserPosition> userPositionAll = this.userPositionMapper.findMyPositionByCodeAndSpell(user.getId(), null, null, 0);
|
|
@@ -1928,58 +1693,58 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public StockIndexDF getStockIndexDFByDbName(String dbName){
|
|
|
- String dbTableName = IndexDbCreatedUtil.createdDbTableNameByTime(dbName, new Date());
|
|
|
- StockIndexDF stockIndexDF;
|
|
|
- try {
|
|
|
- stockIndexDF = stockMapper.selectStockDateByDf(dbTableName);
|
|
|
- if(null == stockIndexDF){
|
|
|
- // 当月数据还没有 先获取上个月的
|
|
|
- Calendar c = Calendar.getInstance();
|
|
|
- c.setTime(new Date());
|
|
|
- c.add(Calendar.MONTH, -1);
|
|
|
- Date lastMonth = c.getTime();
|
|
|
- dbTableName = IndexDbCreatedUtil.createdDbTableNameByTime(dbName, lastMonth);
|
|
|
- stockIndexDF = stockMapper.selectStockDateByDf(dbTableName);
|
|
|
- }
|
|
|
- return stockIndexDF;
|
|
|
- }catch (Exception e){
|
|
|
- // 当月数据还没有 先获取上个月的
|
|
|
- Calendar c = Calendar.getInstance();
|
|
|
- c.setTime(new Date());
|
|
|
- c.add(Calendar.MONTH, -1);
|
|
|
- Date lastMonth = c.getTime();
|
|
|
- dbTableName = IndexDbCreatedUtil.createdDbTableNameByTime(dbName, lastMonth);
|
|
|
- stockIndexDF = stockMapper.selectStockDateByDf(dbTableName);
|
|
|
- return stockIndexDF;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public String getNowPriceStrByDbName(String dbName){
|
|
|
- String dbTableName = IndexDbCreatedUtil.createdDbTableNameByTime(dbName, new Date());
|
|
|
- String nowPriceStr;
|
|
|
- try {
|
|
|
- nowPriceStr = stockMapper.selectNowPrice(dbTableName);
|
|
|
- if(null == nowPriceStr){
|
|
|
- // 当月数据还没有 先获取上个月的
|
|
|
- Calendar c = Calendar.getInstance();
|
|
|
- c.setTime(new Date());
|
|
|
- c.add(Calendar.MONTH, -1);
|
|
|
- Date lastMonth = c.getTime();
|
|
|
- dbTableName = IndexDbCreatedUtil.createdDbTableNameByTime(dbName, lastMonth);
|
|
|
- nowPriceStr = stockMapper.selectNowPrice(dbTableName);
|
|
|
- }
|
|
|
- return nowPriceStr;
|
|
|
- }catch (Exception e){
|
|
|
- Calendar c = Calendar.getInstance();
|
|
|
- c.setTime(new Date());
|
|
|
- c.add(Calendar.MONTH, -1);
|
|
|
- Date lastMonth = c.getTime();
|
|
|
- dbTableName = IndexDbCreatedUtil.createdDbTableNameByTime(dbName, lastMonth);
|
|
|
- nowPriceStr = stockMapper.selectNowPrice(dbTableName);
|
|
|
- return nowPriceStr;
|
|
|
- }
|
|
|
- }
|
|
|
+// public StockIndexDF getStockIndexDFByDbName(String dbName){
|
|
|
+// String dbTableName = IndexDbCreatedUtil.createdDbTableNameByTime(dbName, new Date());
|
|
|
+// StockIndexDF stockIndexDF;
|
|
|
+// try {
|
|
|
+// stockIndexDF = stockMapper.selectStockDateByDf(dbTableName);
|
|
|
+// if(null == stockIndexDF){
|
|
|
+// // 当月数据还没有 先获取上个月的
|
|
|
+// Calendar c = Calendar.getInstance();
|
|
|
+// c.setTime(new Date());
|
|
|
+// c.add(Calendar.MONTH, -1);
|
|
|
+// Date lastMonth = c.getTime();
|
|
|
+// dbTableName = IndexDbCreatedUtil.createdDbTableNameByTime(dbName, lastMonth);
|
|
|
+// stockIndexDF = stockMapper.selectStockDateByDf(dbTableName);
|
|
|
+// }
|
|
|
+// return stockIndexDF;
|
|
|
+// }catch (Exception e){
|
|
|
+// // 当月数据还没有 先获取上个月的
|
|
|
+// Calendar c = Calendar.getInstance();
|
|
|
+// c.setTime(new Date());
|
|
|
+// c.add(Calendar.MONTH, -1);
|
|
|
+// Date lastMonth = c.getTime();
|
|
|
+// dbTableName = IndexDbCreatedUtil.createdDbTableNameByTime(dbName, lastMonth);
|
|
|
+// stockIndexDF = stockMapper.selectStockDateByDf(dbTableName);
|
|
|
+// return stockIndexDF;
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// public String getNowPriceStrByDbName(String dbName){
|
|
|
+// String dbTableName = IndexDbCreatedUtil.createdDbTableNameByTime(dbName, new Date());
|
|
|
+// String nowPriceStr;
|
|
|
+// try {
|
|
|
+// nowPriceStr = stockMapper.selectNowPrice(dbTableName);
|
|
|
+// if(null == nowPriceStr){
|
|
|
+// // 当月数据还没有 先获取上个月的
|
|
|
+// Calendar c = Calendar.getInstance();
|
|
|
+// c.setTime(new Date());
|
|
|
+// c.add(Calendar.MONTH, -1);
|
|
|
+// Date lastMonth = c.getTime();
|
|
|
+// dbTableName = IndexDbCreatedUtil.createdDbTableNameByTime(dbName, lastMonth);
|
|
|
+// nowPriceStr = stockMapper.selectNowPrice(dbTableName);
|
|
|
+// }
|
|
|
+// return nowPriceStr;
|
|
|
+// }catch (Exception e){
|
|
|
+// Calendar c = Calendar.getInstance();
|
|
|
+// c.setTime(new Date());
|
|
|
+// c.add(Calendar.MONTH, -1);
|
|
|
+// Date lastMonth = c.getTime();
|
|
|
+// dbTableName = IndexDbCreatedUtil.createdDbTableNameByTime(dbName, lastMonth);
|
|
|
+// nowPriceStr = stockMapper.selectNowPrice(dbTableName);
|
|
|
+// return nowPriceStr;
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
public Integer getTodayOrderNum(String stockName){
|
|
|
return userPositionMapper.selectTodayOrderNum(stockName);
|