Search in sources :

Example 31 with QueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.QueryWrapper in project Ant-Live by PinTeh.

the class UserServiceImpl method login.

@Override
public User login(String account, String password) {
    QueryWrapper<User> wrapper = new QueryWrapper<>();
    if (account.contains("@")) {
        wrapper.eq("email", account);
    } else {
        wrapper.eq("mobile", account);
    }
    User user = userMapper.selectOne(wrapper);
    if (encoder.matches(password, user.getPassword())) {
        return user;
    }
    return null;
}
Also used : User(cn.imhtb.antlive.entity.User) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)

Example 32 with QueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.QueryWrapper in project plank by MistraR.

the class Barbarossa method sellStock.

/**
 * 减仓或清仓股票
 *
 * @param date 日期
 */
private void sellStock(Date date) {
    List<HoldShares> holdShares = holdSharesMapper.selectList(new QueryWrapper<>());
    if (CollectionUtils.isNotEmpty(holdShares)) {
        for (HoldShares holdShare : holdShares) {
            if (!DateUtils.isSameDay(holdShare.getBuyTime(), date) && holdShare.getBuyTime().getTime() < date.getTime()) {
                Page<DailyRecord> selectPage = dailyRecordMapper.selectPage(new Page<>(1, 25), new QueryWrapper<DailyRecord>().eq("code", holdShare.getCode()).ge("date", DateUtils.addDays(date, -plankConfig.getDeficitMovingAverage() - 9)).le("date", date).orderByDesc("date"));
                // 今日数据明细
                DailyRecord todayRecord = selectPage.getRecords().get(0);
                List<DailyRecord> dailyRecords = selectPage.getRecords().size() >= plankConfig.getDeficitMovingAverage() ? selectPage.getRecords().subList(0, plankConfig.getDeficitMovingAverage() - 1) : selectPage.getRecords();
                // 止损均线价格
                OptionalDouble average = dailyRecords.stream().mapToDouble(dailyRecord -> dailyRecord.getClosePrice().doubleValue()).average();
                if (average.isPresent() && (todayRecord.getLowest().doubleValue() <= average.getAsDouble())) {
                    // 跌破均线,清仓
                    this.clearanceStock(holdShare, ClearanceReasonEnum.BREAK_POSITION, date, average.getAsDouble());
                    continue;
                }
                // 盘中最低收益率
                double profitLowRatio = todayRecord.getLowest().subtract(holdShare.getBuyPrice()).divide(holdShare.getBuyPrice(), 2, RoundingMode.HALF_UP).doubleValue();
                if (profitLowRatio < plankConfig.getDeficitRatio().doubleValue()) {
                    // 跌破止损线,清仓
                    this.clearanceStock(holdShare, ClearanceReasonEnum.BREAK_LOSS_LINE, date, holdShare.getBuyPrice().doubleValue() * (1 + plankConfig.getDeficitRatio().doubleValue()));
                    continue;
                }
                if (holdShare.getFifteenProfit() && profitLowRatio <= plankConfig.getProfitClearanceRatio().doubleValue()) {
                    // 收益回撤到10个点止盈清仓
                    this.clearanceStock(holdShare, ClearanceReasonEnum.TAKE_PROFIT, date, holdShare.getBuyPrice().doubleValue() * 1.1);
                    continue;
                }
                // 盘中最高收益率
                double profitHighRatio = todayRecord.getHighest().subtract(holdShare.getBuyPrice()).divide(holdShare.getBuyPrice(), 2, RoundingMode.HALF_UP).doubleValue();
                if (profitHighRatio >= plankConfig.getProfitUpperRatio().doubleValue()) {
                    // 收益25% 清仓
                    this.clearanceStock(holdShare, ClearanceReasonEnum.PROFIT_UPPER, date, holdShare.getBuyPrice().doubleValue() * (1 + plankConfig.getProfitUpperRatio().doubleValue()));
                } else if (profitHighRatio >= plankConfig.getProfitQuarterRatio().doubleValue()) {
                    // 收益20% 减至1/4仓
                    this.reduceStock(holdShare, ClearanceReasonEnum.POSITION_QUARTER, date, todayRecord, holdShare.getBuyPrice().doubleValue() * (1 + plankConfig.getProfitQuarterRatio().doubleValue()));
                } else if (profitHighRatio >= plankConfig.getProfitHalfRatio().doubleValue()) {
                    // 收益15% 减半仓
                    this.reduceStock(holdShare, ClearanceReasonEnum.POSITION_HALF, date, todayRecord, holdShare.getBuyPrice().doubleValue() * (1 + plankConfig.getProfitHalfRatio().doubleValue()));
                }
                // 持股超过x天 并且 收益不到20% 清仓
                if (Days.daysBetween(new LocalDate(holdShare.getBuyTime().getTime()), new LocalDate(date.getTime())).getDays() > plankConfig.getClearanceDay()) {
                    this.clearanceStock(holdShare, ClearanceReasonEnum.TEN_DAY, date, todayRecord.getOpenPrice().add(todayRecord.getClosePrice()).doubleValue() / 2);
                }
            }
        }
    }
}
Also used : DateUtil(cn.hutool.core.date.DateUtil) Date(java.util.Date) DailyRecord(com.mistra.plank.pojo.entity.DailyRecord) DragonList(com.mistra.plank.pojo.entity.DragonList) HoldShares(com.mistra.plank.pojo.entity.HoldShares) PlankConfig(com.mistra.plank.config.PlankConfig) Clearance(com.mistra.plank.pojo.entity.Clearance) BigDecimal(java.math.BigDecimal) Map(java.util.Map) TradeRecord(com.mistra.plank.pojo.entity.TradeRecord) Days(org.joda.time.Days) HoldSharesMapper(com.mistra.plank.mapper.HoldSharesMapper) HttpUtil(com.mistra.plank.util.HttpUtil) RoundingMode(java.math.RoundingMode) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) FundHoldingsParam(com.mistra.plank.pojo.param.FundHoldingsParam) TradeRecordMapper(com.mistra.plank.mapper.TradeRecordMapper) FundHoldingsTrackingMapper(com.mistra.plank.mapper.FundHoldingsTrackingMapper) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) Stock(com.mistra.plank.pojo.entity.Stock) UploadDataListener(com.mistra.plank.util.UploadDataListener) Objects(java.util.Objects) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) JSONObject(com.alibaba.fastjson.JSONObject) StockRealTimePrice(com.mistra.plank.pojo.dto.StockRealTimePrice) DragonListMapper(com.mistra.plank.mapper.DragonListMapper) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) OptionalDouble(java.util.OptionalDouble) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) EasyExcel(com.alibaba.excel.EasyExcel) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) JSONArray(com.alibaba.fastjson.JSONArray) CommandLineRunner(org.springframework.boot.CommandLineRunner) ExecutorService(java.util.concurrent.ExecutorService) DailyRecordMapper(com.mistra.plank.mapper.DailyRecordMapper) DateTime(org.joda.time.DateTime) IOException(java.io.IOException) DateUtils(org.apache.commons.lang3.time.DateUtils) TimeUnit(java.util.concurrent.TimeUnit) LocalDate(org.joda.time.LocalDate) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) Component(org.springframework.stereotype.Component) ClearanceReasonEnum(com.mistra.plank.pojo.enums.ClearanceReasonEnum) JSON(com.alibaba.fastjson.JSON) NamedThreadFactory(cn.hutool.core.thread.NamedThreadFactory) ForeignFundHoldingsTracking(com.mistra.plank.pojo.entity.ForeignFundHoldingsTracking) StockMapper(com.mistra.plank.mapper.StockMapper) Collections(java.util.Collections) ClearanceMapper(com.mistra.plank.mapper.ClearanceMapper) HoldShares(com.mistra.plank.pojo.entity.HoldShares) DailyRecord(com.mistra.plank.pojo.entity.DailyRecord) LocalDate(org.joda.time.LocalDate) OptionalDouble(java.util.OptionalDouble)

Example 33 with QueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.QueryWrapper in project plank by MistraR.

the class Barbarossa method analyze.

/**
 * 分析最近一个月各连板晋级率
 */
public void analyze() {
    // 4连板+的股票
    HashSet<String> fourPlankStock = new HashSet<>();
    HashMap<String, Integer> gemPlankStockNumber = new HashMap<>();
    Date date = new DateTime(DateUtils.addDays(new Date(), -30)).withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0).toDate();
    // 首板一进二胜率
    HashMap<String, BigDecimal> oneToTwo = new HashMap<>(64);
    // 二板二进三胜率
    HashMap<String, BigDecimal> twoToThree = new HashMap<>(64);
    // 三板三进四胜率
    HashMap<String, BigDecimal> threeToFour = new HashMap<>(64);
    // 四板四进五胜率
    HashMap<String, BigDecimal> fourToFive = new HashMap<>(64);
    // 五板五进六胜率
    HashMap<String, BigDecimal> fiveToSix = new HashMap<>(64);
    // 六板六进七胜率
    HashMap<String, BigDecimal> sixToSeven = new HashMap<>(64);
    List<DailyRecord> dailyRecords = dailyRecordMapper.selectList(new QueryWrapper<DailyRecord>().ge("date", date));
    Map<String, List<DailyRecord>> dateListMap = dailyRecords.stream().collect(Collectors.groupingBy(dailyRecord -> sdf.format(dailyRecord.getDate())));
    // 昨日首板
    HashMap<String, Double> yesterdayOne = new HashMap<>(64);
    // 昨日二板
    HashMap<String, Double> yesterdayTwo = new HashMap<>(64);
    // 昨日三板
    HashMap<String, Double> yesterdayThree = new HashMap<>(64);
    // 昨日四板
    HashMap<String, Double> yesterdayFour = new HashMap<>(64);
    // 昨日五板
    HashMap<String, Double> yesterdayFive = new HashMap<>(64);
    // 昨日六板
    HashMap<String, Double> yesterdaySix = new HashMap<>(64);
    do {
        List<DailyRecord> records = dateListMap.get(sdf.format(date));
        if (CollectionUtils.isNotEmpty(records)) {
            // 今日首板
            HashMap<String, Double> todayOne = new HashMap<>(64);
            // 今日二板
            HashMap<String, Double> todayTwo = new HashMap<>(32);
            // 今日三板
            HashMap<String, Double> todayThree = new HashMap<>(16);
            // 今日四板
            HashMap<String, Double> todayFour = new HashMap<>(16);
            // 今日五板
            HashMap<String, Double> todayFive = new HashMap<>(16);
            // 今日六板
            HashMap<String, Double> todaySix = new HashMap<>(16);
            // 今日七板
            HashMap<String, Double> todaySeven = new HashMap<>(16);
            for (DailyRecord dailyRecord : records) {
                double v = dailyRecord.getIncreaseRate().doubleValue();
                String name = dailyRecord.getName();
                String code = dailyRecord.getCode();
                if (code.contains("SZ30") && v > 19.4 && v < 21) {
                    gemPlankStockNumber.put(name, gemPlankStockNumber.getOrDefault(name, 0) + 1);
                }
                if ((!code.contains("SZ30") && v > 9.4 && v < 11) || (code.contains("SZ30") && v > 19.4 && v < 21)) {
                    if (yesterdaySix.containsKey(name)) {
                        // 昨日的六板,今天继续板,进阶7板
                        todaySeven.put(dailyRecord.getName(), v);
                    } else if (yesterdayFive.containsKey(name)) {
                        // 昨日的五板,今天继续板,进阶6板
                        todaySix.put(dailyRecord.getName(), v);
                    } else if (yesterdayFour.containsKey(name)) {
                        // 昨日的四板,今天继续板,进阶5板
                        todayFive.put(dailyRecord.getName(), v);
                    } else if (yesterdayThree.containsKey(name)) {
                        // 昨日的三板,今天继续板,进阶4板
                        todayFour.put(dailyRecord.getName(), v);
                    } else if (yesterdayTwo.containsKey(name)) {
                        // 昨日的二板,今天继续板,进阶3板
                        todayThree.put(dailyRecord.getName(), v);
                    } else if (yesterdayOne.containsKey(name)) {
                        // 昨日首板,今天继续板,进阶2板
                        todayTwo.put(dailyRecord.getName(), v);
                    } else if (!yesterdayOne.containsKey(name)) {
                        // 昨日没有板,今日首板
                        todayOne.put(dailyRecord.getName(), v);
                    }
                }
            }
            this.promotion(oneToTwo, todayTwo, yesterdayOne, date);
            this.promotion(twoToThree, todayThree, yesterdayTwo, date);
            this.promotion(threeToFour, todayFour, yesterdayThree, date);
            this.promotion(fourToFive, todayFive, yesterdayFour, date);
            this.promotion(fiveToSix, todaySix, yesterdayFive, date);
            this.promotion(sixToSeven, todaySeven, yesterdaySix, date);
            log.info("\n-------------------------------------------------------------------------------------------{}日-------------------------------------------------------------------------------------------" + "\n一板{}支:{}\n二板{}支:{}\n三板{}支:{}\n四板{}支:{}\n五板{}支:{}\n六板{}支:{}\n七板{}支:{}" + "\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------", sdf.format(date), todayOne.keySet().size(), new ArrayList<>(todayOne.keySet()), todayTwo.keySet().size(), new ArrayList<>(todayTwo.keySet()), todayThree.keySet().size(), new ArrayList<>(todayThree.keySet()), todayFour.keySet().size(), new ArrayList<>(todayFour.keySet()), todayFive.keySet().size(), new ArrayList<>(todayFive.keySet()), todaySix.keySet().size(), new ArrayList<>(todaySix.keySet()), todaySeven.keySet().size(), new ArrayList<>(todaySeven.keySet()));
            fourPlankStock.addAll(todayFour.keySet());
            yesterdayOne.clear();
            yesterdayOne.putAll(todayOne);
            yesterdayTwo.clear();
            yesterdayTwo.putAll(todayTwo);
            yesterdayThree.clear();
            yesterdayThree.putAll(todayThree);
            yesterdayFour.clear();
            yesterdayFour.putAll(todayFour);
            yesterdayFive.clear();
            yesterdayFive.putAll(todayFive);
            yesterdaySix.clear();
            yesterdaySix.putAll(todaySix);
        }
        date = DateUtils.addDays(date, 1);
    } while (date.getTime() < System.currentTimeMillis());
    List<String> gemPlankStockTwice = new ArrayList<>();
    for (Map.Entry<String, Integer> entry : gemPlankStockNumber.entrySet()) {
        if (entry.getValue() > 1) {
            gemPlankStockTwice.add(entry.getKey());
        }
    }
    log.info("最近一个月4连板+的股票:{}", fourPlankStock.toString().replace(" ", "").replace("[", "").replace("]", ""));
    log.info("最近一个月创业板涨停2次+的股票:{}", gemPlankStockTwice.toString().replace(" ", "").replace("[", "").replace("]", ""));
    log.info("一板>一进二平均胜率:{}", (double) Math.round(oneToTwo.values().stream().collect(Collectors.averagingDouble(BigDecimal::doubleValue)) * 100) / 100);
    log.info("二板>二进三平均胜率:{}", (double) Math.round(twoToThree.values().stream().collect(Collectors.averagingDouble(BigDecimal::doubleValue)) * 100) / 100);
    log.info("三板>三进四平均胜率:{}", (double) Math.round(threeToFour.values().stream().collect(Collectors.averagingDouble(BigDecimal::doubleValue)) * 100) / 100);
    log.info("四板>四进五平均胜率:{}", (double) Math.round(fourToFive.values().stream().collect(Collectors.averagingDouble(BigDecimal::doubleValue)) * 100) / 100);
    log.info("五板>五进六平均胜率:{}", (double) Math.round(fiveToSix.values().stream().collect(Collectors.averagingDouble(BigDecimal::doubleValue)) * 100) / 100);
    log.info("六板>六进七平均胜率:{}", (double) Math.round(sixToSeven.values().stream().collect(Collectors.averagingDouble(BigDecimal::doubleValue)) * 100) / 100);
}
Also used : DateUtil(cn.hutool.core.date.DateUtil) Date(java.util.Date) DailyRecord(com.mistra.plank.pojo.entity.DailyRecord) DragonList(com.mistra.plank.pojo.entity.DragonList) HoldShares(com.mistra.plank.pojo.entity.HoldShares) PlankConfig(com.mistra.plank.config.PlankConfig) Clearance(com.mistra.plank.pojo.entity.Clearance) BigDecimal(java.math.BigDecimal) Map(java.util.Map) TradeRecord(com.mistra.plank.pojo.entity.TradeRecord) Days(org.joda.time.Days) HoldSharesMapper(com.mistra.plank.mapper.HoldSharesMapper) HttpUtil(com.mistra.plank.util.HttpUtil) RoundingMode(java.math.RoundingMode) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) FundHoldingsParam(com.mistra.plank.pojo.param.FundHoldingsParam) TradeRecordMapper(com.mistra.plank.mapper.TradeRecordMapper) FundHoldingsTrackingMapper(com.mistra.plank.mapper.FundHoldingsTrackingMapper) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) Stock(com.mistra.plank.pojo.entity.Stock) UploadDataListener(com.mistra.plank.util.UploadDataListener) Objects(java.util.Objects) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) JSONObject(com.alibaba.fastjson.JSONObject) StockRealTimePrice(com.mistra.plank.pojo.dto.StockRealTimePrice) DragonListMapper(com.mistra.plank.mapper.DragonListMapper) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) OptionalDouble(java.util.OptionalDouble) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) EasyExcel(com.alibaba.excel.EasyExcel) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) JSONArray(com.alibaba.fastjson.JSONArray) CommandLineRunner(org.springframework.boot.CommandLineRunner) ExecutorService(java.util.concurrent.ExecutorService) DailyRecordMapper(com.mistra.plank.mapper.DailyRecordMapper) DateTime(org.joda.time.DateTime) IOException(java.io.IOException) DateUtils(org.apache.commons.lang3.time.DateUtils) TimeUnit(java.util.concurrent.TimeUnit) LocalDate(org.joda.time.LocalDate) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) Component(org.springframework.stereotype.Component) ClearanceReasonEnum(com.mistra.plank.pojo.enums.ClearanceReasonEnum) JSON(com.alibaba.fastjson.JSON) NamedThreadFactory(cn.hutool.core.thread.NamedThreadFactory) ForeignFundHoldingsTracking(com.mistra.plank.pojo.entity.ForeignFundHoldingsTracking) StockMapper(com.mistra.plank.mapper.StockMapper) Collections(java.util.Collections) ClearanceMapper(com.mistra.plank.mapper.ClearanceMapper) HashMap(java.util.HashMap) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) ArrayList(java.util.ArrayList) DailyRecord(com.mistra.plank.pojo.entity.DailyRecord) OptionalDouble(java.util.OptionalDouble) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) BigDecimal(java.math.BigDecimal) DragonList(com.mistra.plank.pojo.entity.DragonList) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 34 with QueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.QueryWrapper in project plank by MistraR.

the class Barbarossa method monitor.

/**
 * 实时监测数据 显示股票实时涨跌幅度,最高,最低价格
 */
public void monitor() {
    executorService.submit(() -> {
        try {
            List<Stock> stocks = stockMapper.selectList(new QueryWrapper<Stock>().eq("track", true));
            Map<String, Stock> stockMap = stocks.stream().collect(Collectors.toMap(Stock::getName, e -> e));
            List<StockRealTimePrice> realTimePrices = new ArrayList<>();
            while (DateUtil.hour(new Date(), true) <= 15 && DateUtil.hour(new Date(), true) >= 9) {
                for (Stock stock : stocks) {
                    String url = plankConfig.getXueQiuStockDetailUrl().replace("{code}", stock.getCode()).replace("{time}", String.valueOf(System.currentTimeMillis())).replace("{recentDayNumber}", "1");
                    String body = HttpUtil.getHttpGetResponseString(url, plankConfig.getXueQiuCookie());
                    JSONObject data = JSON.parseObject(body).getJSONObject("data");
                    JSONArray list = data.getJSONArray("item");
                    if (org.apache.commons.collections.CollectionUtils.isNotEmpty(list)) {
                        for (Object o : list) {
                            double v = ((JSONArray) o).getDoubleValue(5);
                            double rate = -(double) Math.round(((v - stock.getPurchasePrice().doubleValue()) / v) * 100) / 100;
                            realTimePrices.add(StockRealTimePrice.builder().todayRealTimePrice(v).name(stock.getName()).todayHighestPrice(((JSONArray) o).getDoubleValue(3)).todayLowestPrice(((JSONArray) o).getDoubleValue(4)).purchasePrice(stock.getPurchasePrice()).rate((int) (rate * 100)).increaseRate(((JSONArray) o).getDoubleValue(7)).build());
                        }
                    }
                }
                // 暴跌
                List<StockRealTimePrice> slump = realTimePrices.stream().filter(e -> e.getIncreaseRate() < -5).collect(Collectors.toList());
                List<StockRealTimePrice> buy = realTimePrices.stream().filter(e -> e.getRate() >= -3).collect(Collectors.toList());
                Collections.sort(realTimePrices);
                Collections.sort(slump);
                Collections.sort(buy);
                System.out.println("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
                log.error("----------------------------------------持仓----------------------------------------");
                for (StockRealTimePrice realTimePrice : realTimePrices) {
                    if (stockMap.get(realTimePrice.getName()).getShareholding()) {
                        Barbarossa.log.warn(convertLog(realTimePrice));
                    }
                }
                log.error("--------------------------------------接近建仓点--------------------------------------");
                for (StockRealTimePrice realTimePrice : buy) {
                    if (!stockMap.get(realTimePrice.getName()).getShareholding()) {
                        if (realTimePrice.getRate() >= -1) {
                            Barbarossa.log.warn(convertLog(realTimePrice));
                        } else {
                            Barbarossa.log.info(convertLog(realTimePrice));
                        }
                    }
                }
                log.error("----------------------------------------暴跌----------------------------------------");
                for (StockRealTimePrice realTimePrice : slump) {
                    if (!stockMap.get(realTimePrice.getName()).getShareholding()) {
                        Barbarossa.log.warn(convertLog(realTimePrice));
                    }
                }
                realTimePrices.clear();
                Thread.sleep(10000);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    });
}
Also used : DateUtil(cn.hutool.core.date.DateUtil) Date(java.util.Date) DailyRecord(com.mistra.plank.pojo.entity.DailyRecord) DragonList(com.mistra.plank.pojo.entity.DragonList) HoldShares(com.mistra.plank.pojo.entity.HoldShares) PlankConfig(com.mistra.plank.config.PlankConfig) Clearance(com.mistra.plank.pojo.entity.Clearance) BigDecimal(java.math.BigDecimal) Map(java.util.Map) TradeRecord(com.mistra.plank.pojo.entity.TradeRecord) Days(org.joda.time.Days) HoldSharesMapper(com.mistra.plank.mapper.HoldSharesMapper) HttpUtil(com.mistra.plank.util.HttpUtil) RoundingMode(java.math.RoundingMode) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) FundHoldingsParam(com.mistra.plank.pojo.param.FundHoldingsParam) TradeRecordMapper(com.mistra.plank.mapper.TradeRecordMapper) FundHoldingsTrackingMapper(com.mistra.plank.mapper.FundHoldingsTrackingMapper) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) Stock(com.mistra.plank.pojo.entity.Stock) UploadDataListener(com.mistra.plank.util.UploadDataListener) Objects(java.util.Objects) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) JSONObject(com.alibaba.fastjson.JSONObject) StockRealTimePrice(com.mistra.plank.pojo.dto.StockRealTimePrice) DragonListMapper(com.mistra.plank.mapper.DragonListMapper) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) OptionalDouble(java.util.OptionalDouble) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) EasyExcel(com.alibaba.excel.EasyExcel) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) JSONArray(com.alibaba.fastjson.JSONArray) CommandLineRunner(org.springframework.boot.CommandLineRunner) ExecutorService(java.util.concurrent.ExecutorService) DailyRecordMapper(com.mistra.plank.mapper.DailyRecordMapper) DateTime(org.joda.time.DateTime) IOException(java.io.IOException) DateUtils(org.apache.commons.lang3.time.DateUtils) TimeUnit(java.util.concurrent.TimeUnit) LocalDate(org.joda.time.LocalDate) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) Component(org.springframework.stereotype.Component) ClearanceReasonEnum(com.mistra.plank.pojo.enums.ClearanceReasonEnum) JSON(com.alibaba.fastjson.JSON) NamedThreadFactory(cn.hutool.core.thread.NamedThreadFactory) ForeignFundHoldingsTracking(com.mistra.plank.pojo.entity.ForeignFundHoldingsTracking) StockMapper(com.mistra.plank.mapper.StockMapper) Collections(java.util.Collections) ClearanceMapper(com.mistra.plank.mapper.ClearanceMapper) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) ArrayList(java.util.ArrayList) JSONArray(com.alibaba.fastjson.JSONArray) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) IOException(java.io.IOException) JSONObject(com.alibaba.fastjson.JSONObject) StockRealTimePrice(com.mistra.plank.pojo.dto.StockRealTimePrice) JSONObject(com.alibaba.fastjson.JSONObject) Stock(com.mistra.plank.pojo.entity.Stock)

Example 35 with QueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.QueryWrapper in project plank by MistraR.

the class Barbarossa method reduceStock.

/**
 * 减仓股票
 *
 * @param holdShare 持仓记录
 * @param clearanceReasonEnum 清仓原因
 * @param date 时间
 * @param sellPrice 清仓价格
 */
private void reduceStock(HoldShares holdShare, ClearanceReasonEnum clearanceReasonEnum, Date date, DailyRecord todayRecord, double sellPrice) {
    if (holdShare.getNumber() <= 0) {
        holdSharesMapper.delete(new QueryWrapper<HoldShares>().eq("id", holdShare.getId()));
        return;
    }
    // 卖出数量
    int number = holdShare.getNumber() <= 100 ? 100 : holdShare.getNumber() / 2;
    // 卖出金额
    double money = number * sellPrice;
    // 本次卖出部分盈利金额
    BigDecimal profit = new BigDecimal(number * (sellPrice - holdShare.getBuyPrice().doubleValue()));
    // 可用金额
    BALANCE_AVAILABLE = BALANCE_AVAILABLE.add(new BigDecimal(money));
    TradeRecord tradeRecord = new TradeRecord();
    tradeRecord.setName(holdShare.getName());
    tradeRecord.setCode(holdShare.getCode());
    tradeRecord.setDate(date);
    tradeRecord.setMoney((int) money);
    tradeRecord.setReason("减仓" + holdShare.getName() + number + "股,卖出金额" + (int) money + "元,当前可用余额" + BALANCE_AVAILABLE.intValue() + ",减仓原因" + clearanceReasonEnum.getDesc());
    tradeRecord.setBalance(BALANCE.setScale(2, RoundingMode.HALF_UP));
    tradeRecord.setAvailableBalance(BALANCE_AVAILABLE.setScale(2, RoundingMode.HALF_UP));
    tradeRecord.setPrice(new BigDecimal(sellPrice));
    tradeRecord.setNumber(number);
    tradeRecord.setType(1);
    tradeRecordMapper.insert(tradeRecord);
    if (holdShare.getNumber() - number == 0) {
        holdSharesMapper.delete(new QueryWrapper<HoldShares>().eq("id", holdShare.getId()));
        return;
    }
    holdShare.setNumber(holdShare.getNumber() - number);
    holdShare.setCost(holdShare.getBuyPrice().multiply(new BigDecimal(holdShare.getBuyNumber())).subtract(profit).divide(new BigDecimal(number), 2, RoundingMode.HALF_UP));
    holdShare.setProfit(holdShare.getProfit().add(profit));
    holdShare.setFifteenProfit(true);
    holdShare.setCurrentPrice(todayRecord.getClosePrice());
    holdShare.setRate(todayRecord.getClosePrice().subtract(holdShare.getBuyPrice()).divide(holdShare.getBuyPrice(), 2, RoundingMode.HALF_UP));
    holdSharesMapper.updateById(holdShare);
    log.info("{}日减仓 {},目前盈利 {} 元!", sdf.format(date), holdShare.getName(), holdShare.getProfit().add(profit).intValue());
}
Also used : QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) TradeRecord(com.mistra.plank.pojo.entity.TradeRecord) BigDecimal(java.math.BigDecimal)

Aggregations

QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)723 Transactional (org.springframework.transaction.annotation.Transactional)98 IPage (com.baomidou.mybatisplus.core.metadata.IPage)82 UserRolesVo (top.hcode.hoj.pojo.vo.UserRolesVo)74 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)72 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)65 ArrayList (java.util.ArrayList)61 Session (org.apache.shiro.session.Session)61 StatusFailException (top.hcode.hoj.common.exception.StatusFailException)60 StatusForbiddenException (top.hcode.hoj.common.exception.StatusForbiddenException)55 Problem (top.hcode.hoj.pojo.entity.problem.Problem)50 UpdateWrapper (com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper)45 Date (java.util.Date)44 HttpServletRequest (javax.servlet.http.HttpServletRequest)35 HashMap (java.util.HashMap)34 RequiresAuthentication (org.apache.shiro.authz.annotation.RequiresAuthentication)34 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)34 ApiOperation (io.swagger.annotations.ApiOperation)32 HttpSession (javax.servlet.http.HttpSession)31 Judge (top.hcode.hoj.pojo.entity.judge.Judge)30