From 41bc089a838c108a945706096a2b874cbcdd8486 Mon Sep 17 00:00:00 2001
From: zj <1772600164@qq.com>
Date: Fri, 30 May 2025 12:01:33 +0800
Subject: [PATCH] 1

---
 src/main/java/project/project/web/admin/AdminContractOrderController.java |  165 ++++++++++++++++++++++++++----------------------------
 1 files changed, 80 insertions(+), 85 deletions(-)

diff --git a/src/main/java/project/project/web/admin/AdminContractOrderController.java b/src/main/java/project/project/web/admin/AdminContractOrderController.java
index 58c4475..d158d8c 100644
--- a/src/main/java/project/project/web/admin/AdminContractOrderController.java
+++ b/src/main/java/project/project/web/admin/AdminContractOrderController.java
@@ -1,4 +1,4 @@
-package project.project.web.admin;
+package project.web.admin;
 
 import java.math.BigDecimal;
 import java.text.DecimalFormat;
@@ -11,6 +11,7 @@
 
 import javax.servlet.http.HttpServletRequest;
 
+import db.util.QpUtil;
 import org.apache.commons.lang3.ObjectUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -54,22 +55,22 @@
 
 	@Autowired
 	private LogService logService;
-	
+
 	@Autowired
 	private ItemService itemService;
-	
+
 	@Autowired
 	private DataService dataService;
-	
+
 	@Autowired
 	private SecUserService secUserService;
-	
+
 	@Autowired
 	private ContractOrderService contractOrderService;
-	
+
 	@Autowired
 	private AdjustmentValueService adjustmentValueService;
-	
+
 	@Autowired
 	private AdminContractOrderService adminContractOrderService;
 
@@ -77,7 +78,7 @@
 	private WalletService walletService;
 
 	private final String action = "normal/adminContractOrderAction!";
-	
+
 	private static final Logger logger = LoggerFactory.getLogger(AdminContractOrderController.class);
 
 	/**
@@ -96,7 +97,7 @@
 
 		ModelAndView modelAndView = new ModelAndView();
 		modelAndView.setViewName("contract_order_list");
-		
+
 		int pageNo=1;
 		Page page=null;
 		int pageSize=30;
@@ -105,10 +106,10 @@
 			String loginPartyId = this.getLoginPartyId();
 			page = this.adminContractOrderService.pagedQuery(pageNo, pageSize, ContractOrder.STATE_SUBMITTED,
 					rolename_para, loginPartyId, start_time, end_time, name_para, order_no_para);
-			
+
 			List<Map> list = page.getElements();
 			for (int i = 0; i < list.size(); i++) {
-				Map map = list.get(i);				
+				Map map = list.get(i);
 				if (null == map.get("rolename")) {
 					map.put("roleNameDesc", "");
 				} else {
@@ -126,15 +127,16 @@
 				 * 计算全仓收益 保证金
 				 */
 				double profit = 0;
-				List<ContractOrder> contractOrders = contractOrderService.findSubmitted(this.getLoginPartyId(), null, null);
+				List<ContractOrder> contractOrders = contractOrderService.findSubmitted(map.get("party_id").toString(), null, null);
 				for (int f = 0; f < contractOrders.size(); f++) {
 					ContractOrder close_line = contractOrders.get(f);
 					if(close_line.getProfit() > 0){
 						profit = Arith.add(profit, Arith.add(close_line.getProfit(), close_line.getDeposit()));
 					}else{
 						profit = Arith.add(profit, close_line.getDeposit());
-					}				}
-				Wallet wallet = this.walletService.saveWalletByPartyId(this.getLoginPartyId());
+					}
+				}
+				Wallet wallet = this.walletService.saveWalletByPartyId(map.get("party_id").toString());
 				double totleMoney = wallet.getMoney();
 				profit = Arith.add(profit,totleMoney);
 
@@ -142,40 +144,33 @@
 				if (map.get("direction") != null) {
 					String direction = map.get("direction").toString();
 					double liquidationPrice;
-					double deposit = depositOpen + profit;
+					double deposit =  profit;
+
 					if(leverRate == 1){
 						liquidationPrice = 0;
 					}else {
 						if ("sell".equals(direction)) {
-							liquidationPrice = tradeAvgPrice + (deposit / div);
+							double lossPercentage = deposit / (Arith.mul(Double.parseDouble(map.get("volume").toString()), Double.parseDouble(map.get("unit_amount").toString())));
+							double priceIncrease = lossPercentage * tradeAvgPrice;
+							liquidationPrice = tradeAvgPrice + priceIncrease;
 						} else {
-							liquidationPrice = (mul * tradeAvgPrice) / (deposit + mul);
+							double lossPercentage = deposit / (Arith.mul(Double.parseDouble(map.get("volume").toString()), Double.parseDouble(map.get("unit_amount").toString())));
+							double priceDrop = lossPercentage * tradeAvgPrice;
+							liquidationPrice = tradeAvgPrice - priceDrop;
 						}
 					}
 					DecimalFormat dfs = new DecimalFormat("#.#####");
 					String formattedPrice = dfs.format(liquidationPrice);
+					// 检查是否为负数
+					if (Double.parseDouble(formattedPrice) < 0) {
+						formattedPrice = "0";
+					}
 					map.put("qiangPing", formattedPrice);
 				}
-
-//				double currentPrice = Double.parseDouble(map.get("trade_avg_price").toString());
-//
-//				double leve = Double.parseDouble(map.get("lever_rate").toString());
-//				//得到强平价格
-//				if(null != map.get("direction")){
-//					double liquidationPrice;
-//					if(map.get("direction").equals("sell")){
-//						liquidationPrice = currentPrice * (1 + (1 / leve));
-//					}else{
-//						liquidationPrice = currentPrice * (1 - 1 / leve);
-//					}
-//					DecimalFormat df = new DecimalFormat("#.#####");
-//					String formattedPrice = df.format(liquidationPrice);
-//					map.put("qiangPing",formattedPrice);
-//				}
 			}
 
 			List<Item> items = this.itemService.cacheGetAll();
-			SysparaService sysparaService =ApplicationUtil.getBean(SysparaService.class);	
+			SysparaService sysparaService =ApplicationUtil.getBean(SysparaService.class);
 			Syspara syspara = sysparaService.find("symbol_sort");
 			if(ObjectUtils.isNotEmpty(syspara)) {
 				String[] symbolArr = syspara.getValue().split(",");
@@ -194,15 +189,15 @@
 							items.add(i, item_3);
 							continue;
 						}
-					}				
+					}
 				}
-			}			
+			}
 
 			Map<String, String> symbols = new LinkedHashMap<String, String>();
 			for (Item item : items) {
 				symbols.put(item.getSymbol(), item.getName());
 			}
-			
+
 			modelAndView.addObject("symbols", symbols);
 
 		} catch (BusinessException e) {
@@ -243,20 +238,20 @@
 
 		ModelAndView modelAndView = new ModelAndView();
 		modelAndView.setViewName("contract_order_list_content");
-		
+
 		int pageNo=1;
 		Page page=null;
 		int pageSize=30;
 		try {
 			pageNo=checkAndSetPageNo(pageNoStr);
-			
+
 			String loginPartyId = getLoginPartyId();
 			page = this.adminContractOrderService.pagedQuery(pageNo, pageSize, ContractOrder.STATE_SUBMITTED,
 					rolename_para, loginPartyId, start_time, end_time, name_para, order_no_para);
 
 			List<Map> list = page.getElements();
 			for (int i = 0; i < list.size(); i++) {
-				Map map = list.get(i);				
+				Map map = list.get(i);
 				if (null == map.get("rolename")) {
 					map.put("roleNameDesc", "");
 				} else {
@@ -289,38 +284,45 @@
 				 * 计算全仓收益 保证金
 				 */
 				double profit = 0;
-				List<ContractOrder> contractOrders = contractOrderService.findSubmitted(this.getLoginPartyId(), null, null);
+				List<ContractOrder> contractOrders = contractOrderService.findSubmitted(map.get("party_id").toString(), null, null);
 				for (int f = 0; f < contractOrders.size(); f++) {
 					ContractOrder close_line = contractOrders.get(f);
 					if(close_line.getProfit() > 0){
 						profit = Arith.add(profit, Arith.add(close_line.getProfit(), close_line.getDeposit()));
 					}else{
 						profit = Arith.add(profit, close_line.getDeposit());
-					}
-				}
-				Wallet wallet = this.walletService.saveWalletByPartyId(this.getLoginPartyId());
+					}				}
+				Wallet wallet = this.walletService.saveWalletByPartyId(map.get("party_id").toString());
 				double totleMoney = wallet.getMoney();
 				profit = Arith.add(profit,totleMoney);
-
 
 				if (map.get("direction") != null) {
 					String direction = map.get("direction").toString();
 					double liquidationPrice;
-					double deposit = depositOpen + profit;
+					double deposit =  profit;
+
 					if(leverRate == 1){
 						liquidationPrice = 0;
 					}else {
 						if ("sell".equals(direction)) {
-							liquidationPrice = tradeAvgPrice + (deposit / div);
+							double lossPercentage = deposit / (Arith.mul(Double.parseDouble(map.get("volume").toString()), Double.parseDouble(map.get("unit_amount").toString())));
+							double priceIncrease = lossPercentage * tradeAvgPrice;
+							liquidationPrice = tradeAvgPrice + priceIncrease;
 						} else {
-							liquidationPrice = (mul * tradeAvgPrice) / (deposit + mul);
+							double lossPercentage = deposit / (Arith.mul(Double.parseDouble(map.get("volume").toString()), Double.parseDouble(map.get("unit_amount").toString())));
+							double priceDrop = lossPercentage * tradeAvgPrice;
+							liquidationPrice = tradeAvgPrice - priceDrop;
 						}
 					}
-
 					DecimalFormat dfs = new DecimalFormat("#.#####");
 					String formattedPrice = dfs.format(liquidationPrice);
+					// 检查是否为负数
+					if (Double.parseDouble(formattedPrice) < 0) {
+						formattedPrice = "0";
+					}
 					map.put("qiangPing", formattedPrice);
 				}
+
 
 			}
 
@@ -352,19 +354,16 @@
 	@RequestMapping(action + "showModal.action")
 	public String showModal(HttpServletRequest request) {
 		String symbol = request.getParameter("symbol");
-		
+
 		Map<String, Object> resultMap = new HashMap<String, Object>();
-		
+
 		try {
-			
-			if (!StringUtils.isNullOrEmpty(this.getLoginPartyId())) {
-				throw new BusinessException("无权限");
-			}		
-			
+
+
 			Realtime realtime = this.dataService.realtime(symbol).get(0);
 
 			Item item = this.itemService.cacheBySymbol(symbol, false);
-			
+
 			Double currentValue = this.adjustmentValueService.getCurrentValue(symbol);
 			if (null == currentValue) {
 				resultMap.put("adjust_value", 0D);
@@ -396,7 +395,7 @@
 
 	/**
 	 * 调整 页面计算
-	 * 
+	 *
 	 * type 0增加一个pips;1减少一个pips;2直接修改调整值;
 	 * value 调整值
 	 */
@@ -407,25 +406,21 @@
 		String value = request.getParameter("value");
 
 		Map<String, Object> resultMap = new HashMap<String, Object>();
-		
+
 		try {
-			
-			if (!StringUtils.isNullOrEmpty(this.getLoginPartyId())) {
-				throw new BusinessException("无权限");
-			}
 
 			String error = this.verif(type, value);
 			if (!StringUtils.isNullOrEmpty(error)) {
 				throw new BusinessException(error);
 			}
-			
+
 			int type_int = Integer.valueOf(request.getParameter("type")).intValue();
 			double value_double = Double.valueOf(request.getParameter("value")).doubleValue();
-			
+
 			Realtime realtime = this.dataService.realtime(symbol).get(0);
 
 			Item item = this.itemService.cacheBySymbol(symbol, false);
-			
+
 			Double currentValue = this.adjustmentValueService.getCurrentValue(symbol);
 			if (null == currentValue) {
 				resultMap.put("new_price", realtime.getClose());
@@ -434,7 +429,7 @@
 			}
 
 			double temp;
-			
+
 			if (0 == type_int) {
 				temp = Arith.add(value_double, item.getPips());
 				// 调整量
@@ -456,7 +451,7 @@
 			} else {
 				resultMap.put("adjust_value", Arith.add(temp, currentValue));
 			}
-			
+
 			AdjustmentValue delayValue = this.adjustmentValueService.getDelayValue(symbol);
 			if (delayValue != null) {
 				resultMap.put("delay_value", delayValue.getValue());
@@ -477,7 +472,7 @@
 
 	/**
 	 * 调整
-	 * 
+	 *
 	 * value 调整值
 	 * second 延迟秒
 	 */
@@ -487,7 +482,7 @@
 		String value = request.getParameter("value");
 		String second = request.getParameter("second");
 		String username_login = request.getParameter("username_login");
-		
+
 		String order_no_para = request.getParameter("order_no_para");
 		String name_para = request.getParameter("name_para");
 		String rolename_para = request.getParameter("rolename_para");
@@ -496,25 +491,25 @@
 
 		ModelAndView modelAndView = new ModelAndView();
 		modelAndView.setViewName("redirect:/" + action + "list.action");
-		
+
 		try {
 
 			String error = this.verifAdjust(second, value);
 			if (!StringUtils.isNullOrEmpty(error)) {
 				throw new BusinessException(error);
 			}
-			
+
 			double value_double = Double.valueOf(request.getParameter("value"));
 			double second_double = Double.valueOf(request.getParameter("second"));
-			
+
 			Double currentValue = this.adjustmentValueService.getCurrentValue(symbol);
 			if (null == currentValue) {
 				Realtime realtime = this.dataService.realtime(symbol).get(0);
 				currentValue = realtime.getClose();
 			}
-			
+
 			SecUser sec = this.secUserService.findUserByLoginName(this.getUsername_login());
-			
+
 			String log = MessageFormat.format("ip:" + this.getIp() + ",管理员调整行情,币种:{0},原值:{1},调整值:{2},调整时间:{3}", symbol,
 					new BigDecimal(currentValue).toPlainString(), new BigDecimal(value_double).toPlainString(), second_double);
 
@@ -522,7 +517,7 @@
 
 			saveLog(sec, username_login, log);
 			ThreadUtils.sleep(1000);
-			
+
 			modelAndView.addObject("order_no_para", order_no_para);
 			modelAndView.addObject("name_para", name_para);
 			modelAndView.addObject("rolename_para", rolename_para);
@@ -553,14 +548,14 @@
 		modelAndView.setViewName("redirect:/" + action + "list.action");
 
 		try {
-			
+
 			ContractOrder order = this.contractOrderService.findByOrderNo(order_no);
 			if (order != null) {
 				CloseDelayThread lockDelayThread = new CloseDelayThread(order.getPartyId().toString(), order_no, this.contractOrderService);
 				Thread t = new Thread(lockDelayThread);
 				t.start();
 			}
-			
+
 		} catch (BusinessException e) {
 			modelAndView.addObject("error", e.getMessage());
 			return modelAndView;
@@ -586,7 +581,7 @@
 	}
 
 	protected String verif(String type, String value) {
-		
+
 		if (StringUtils.isNullOrEmpty(type)) {
 			return "限制天数必填";
 		}
@@ -606,7 +601,7 @@
 //		if (Double.valueOf(value).doubleValue() < 0) {
 //			return "调整值不能小于0";
 //		}
-		
+
 		return null;
 	}
 
@@ -628,7 +623,7 @@
 //		if (Double.valueOf(value).doubleValue() <= 0) {
 //			return "调整值不能小于等于0";
 //		}
-		
+
 		return null;
 	}
 
@@ -641,11 +636,11 @@
 		private ContractOrderService contractOrderService;
 
 		public void run() {
-			
+
 			try {
-				
+
 				while (true) {
-					
+
 					if (this.contractOrderService.lock(order_no)) {
 						this.contractOrderService.saveClose(partyId, order_no);
 						// 处理完退出
@@ -653,7 +648,7 @@
 					}
 					ThreadUtils.sleep(500);
 				}
-				
+
 			} catch (Throwable t) {
 				logger.error("error:", t);
 			} finally {

--
Gitblit v1.9.3