|  |  | 
 |  |  |         // 开仓价 | 
 |  |  |         BigDecimal openPrice = holdOrderEntity.getOpeningPrice(); | 
 |  |  |         // 设置的止盈止损价 | 
 |  |  |         BigDecimal price = profitOrLessDto.getPrice(); | 
 |  |  |         BigDecimal stopProfitPrice = profitOrLessDto.getStopProfitPrice(); | 
 |  |  |  | 
 |  |  |         BigDecimal stopLessPrice = profitOrLessDto.getStopLessPrice(); | 
 |  |  |  | 
 |  |  |         // 开多 | 
 |  |  |         if (ContractHoldOrderEntity.OPENING_TYPE_MORE == holdOrderEntity.getOpeningType()) { | 
 |  |  |             if (ProfitOrLessDto.TYPE_PROFIT == profitOrLessDto.getType()) { | 
 |  |  |             if (stopProfitPrice != null) { | 
 |  |  |                 // 当前价大于开仓价 | 
 |  |  |                 if (newPrice.compareTo(openPrice) > 0) { | 
 |  |  |                     // 如果止盈价小于当前价 | 
 |  |  |                     if (price.compareTo(newPrice) < 0) { | 
 |  |  |                     if (stopProfitPrice.compareTo(newPrice) < 0) { | 
 |  |  |                         return Result.fail("止盈价必须高于当前价"); | 
 |  |  |                     } | 
 |  |  |                 } else { | 
 |  |  |                     if (price.compareTo(openPrice) < 0) { | 
 |  |  |                     if (stopProfitPrice.compareTo(openPrice) < 0) { | 
 |  |  |                         return Result.fail("止盈价必须高于开仓价"); | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |             } else { | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             if (stopLessPrice != null) { | 
 |  |  |                 if (newPrice.compareTo(openPrice) > 0) { | 
 |  |  |                     if (price.compareTo(openPrice) > 0) { | 
 |  |  |                     if (stopLessPrice.compareTo(openPrice) > 0) { | 
 |  |  |                         return Result.fail("止损价必须低于开仓价"); | 
 |  |  |                     } | 
 |  |  |                 } else { | 
 |  |  |                     if (price.compareTo(newPrice) > 0) { | 
 |  |  |                     if (stopLessPrice.compareTo(newPrice) > 0) { | 
 |  |  |                         return Result.fail("止损价必须低于当前价"); | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |             // 开空 | 
 |  |  |         } else { | 
 |  |  |             if (ProfitOrLessDto.TYPE_PROFIT == profitOrLessDto.getType()) { | 
 |  |  |             if (stopProfitPrice != null) { | 
 |  |  |                 if (newPrice.compareTo(openPrice) > 0) { | 
 |  |  |                     if (price.compareTo(openPrice) > 0) { | 
 |  |  |                     if (stopProfitPrice.compareTo(openPrice) > 0) { | 
 |  |  |                         return Result.fail("止损价必须低于开仓价"); | 
 |  |  |                     } | 
 |  |  |                 } else { | 
 |  |  |                     if (price.compareTo(newPrice) > 0) { | 
 |  |  |                     if (stopProfitPrice.compareTo(newPrice) > 0) { | 
 |  |  |                         return Result.fail("止损价必须低于当前价"); | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |             } else { | 
 |  |  |             } | 
 |  |  |             if (stopLessPrice != null) { | 
 |  |  |                 if (newPrice.compareTo(openPrice) > 0) { | 
 |  |  |                     if (price.compareTo(newPrice) < 0) { | 
 |  |  |                     if (stopLessPrice.compareTo(newPrice) < 0) { | 
 |  |  |                         return Result.fail("止损价必须高于当前价"); | 
 |  |  |                     } | 
 |  |  |                 } else { | 
 |  |  |                     if (price.compareTo(openPrice) < 0) { | 
 |  |  |                     if (stopLessPrice.compareTo(openPrice) < 0) { | 
 |  |  |                         return Result.fail("止损价必须高于开仓价"); | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         if (ProfitOrLessDto.TYPE_PROFIT == profitOrLessDto.getType()) { | 
 |  |  |             holdOrderEntity.setStopProfitPrice(price); | 
 |  |  |         } else { | 
 |  |  |             holdOrderEntity.setStopLossPrice(price); | 
 |  |  |         } | 
 |  |  |         holdOrderEntity.setStopProfitPrice(stopProfitPrice); | 
 |  |  |         holdOrderEntity.setStopLossPrice(stopLessPrice); | 
 |  |  |  | 
 |  |  |         int i = contractHoldOrderDao.updateById(holdOrderEntity); | 
 |  |  |         if (i > 0) { | 
 |  |  |             OrderModel model = null; | 
 |  |  |             if (ContractHoldOrderEntity.OPENING_TYPE_MORE == holdOrderEntity.getOpeningType()) { | 
 |  |  |                 // 开多止盈 | 
 |  |  |                 if (ProfitOrLessDto.TYPE_PROFIT == profitOrLessDto.getType()) { | 
 |  |  |                     model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_MORE_STOP_PROFIT.getValue(), price.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol()); | 
 |  |  |                     // 开多止损 | 
 |  |  |                 } else { | 
 |  |  |                     model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_MORE_STOP_LESS.getValue(), price.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol()); | 
 |  |  |                 if (stopProfitPrice != null) { | 
 |  |  |                     model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_MORE_STOP_PROFIT.getValue(), stopProfitPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol()); | 
 |  |  |                 } | 
 |  |  |                 // 开多止损 | 
 |  |  |                 if (stopLessPrice != null) { | 
 |  |  |                     model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_MORE_STOP_LESS.getValue(), stopLessPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol()); | 
 |  |  |                 } | 
 |  |  |             } else { | 
 |  |  |                 // 开空止盈 | 
 |  |  |                 if (ProfitOrLessDto.TYPE_PROFIT == profitOrLessDto.getType()) { | 
 |  |  |                     model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_LESS_STOP_PROFIT.getValue(), price.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol()); | 
 |  |  |                     // 开空止损 | 
 |  |  |                 } else { | 
 |  |  |                     model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_LESS_STOP_LESS.getValue(), price.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol()); | 
 |  |  |                 if (stopProfitPrice != null) { | 
 |  |  |                     model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_LESS_STOP_PROFIT.getValue(), stopProfitPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol()); | 
 |  |  |                 } | 
 |  |  |                 // 开空止损 | 
 |  |  |                 if (stopLessPrice != null) { | 
 |  |  |                     model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_LESS_STOP_LESS.getValue(), stopLessPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol()); | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |             producer.sendPriceOperate(JSONObject.toJSONString(model)); |