src/main/java/com/nq/controller/protol/UserController.java
@@ -285,9 +285,9 @@ @RequestMapping({"upload.do"}) @ResponseBody public ServerResponse upload(HttpSession session, @RequestParam(value = "upload_file", required = false) MultipartFile file, HttpServletRequest request) { String path = request.getSession().getServletContext().getRealPath("upload"); ServerResponse serverResponse = this.iFileUploadService.upload(file, path); // String path = request.getSession().getServletContext().getRealPath("upload"); String path = PropertiesUtil.getProperty("ftp.server.upload.dirs"); ServerResponse serverResponse = this.iFileUploadService.uploadFile(file); if (serverResponse.isSuccess()) { String targetFileName = serverResponse.getData().toString(); String url = PropertiesUtil.getProperty("ftp.server.http.prefix") + targetFileName; src/main/java/com/nq/service/IFileUploadService.java
@@ -6,4 +6,6 @@ public interface IFileUploadService { ServerResponse upload(MultipartFile paramMultipartFile, String paramString); ServerResponse uploadFile(MultipartFile paramMultipartFile); } src/main/java/com/nq/service/impl/FileUploadServiceImpl.java
@@ -1,12 +1,18 @@ package com.nq.service.impl; import cn.hutool.core.util.StrUtil; import com.google.common.collect.Lists; import com.nq.common.ServerResponse; import com.nq.service.IFileUploadService; import com.nq.utils.FTPUtil; import java.io.File; import java.io.IOException; import java.time.LocalDate; import java.util.HashMap; import java.util.Map; import java.util.UUID; import com.nq.utils.PropertiesUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; @@ -22,6 +28,91 @@ private static final Logger log = LoggerFactory.getLogger(FileUploadServiceImpl.class); @Override public ServerResponse uploadFile(MultipartFile file) { // 兼容c端组件上传原理 String fileType = file.getOriginalFilename(); if (StrUtil.isEmpty(fileType) || fileType.contains("blob")) { fileType = "blob.png"; } String fileName = file.getOriginalFilename(); String fileExtentionName = fileName.substring(fileName.lastIndexOf(".") + 1); // 生成唯一的文件名 String id = UUID.randomUUID().toString(); String path = LocalDate.now() + "/" + id + "." + fileExtentionName; // 确保目标文件夹存在 File targetDir = new File(PropertiesUtil.getProperty("loca.images.dir") + "/" + LocalDate.now()); if (!targetDir.exists()) { targetDir.mkdirs(); } // 构建本地文件路径 File localFile = new File(targetDir, id + "." + fileExtentionName); // 打印上传路径 log.info("LocalFileUploadService uploadFile localFilePath: {}", localFile.getAbsolutePath()); try { // 将文件保存到本地 file.transferTo(localFile); } catch (IOException e) { log.error("LocalFileUploadService uploadFile IOException", e.getMessage(), e); } // 返回相对路径 return ServerResponse.createBySuccess(path); } // public ServerResponse uploadFile(MultipartFile file) { // // 兼容c端组件上传原理 // // String fileName = file.getOriginalFilename(); // // // String fileExtentionName = fileName.substring(fileName.lastIndexOf(".") + 1); // // // String uploadFileName = UUID.randomUUID() + "." + fileExtentionName; // // String path = LocalDate.now() + "/" + uploadFileName; // // // 确保目标文件夹存在 // File targetDir = new File(PropertiesUtil.getProperty("ftp.server.http.prefix") + "/" + LocalDate.now()); // if (!targetDir.exists()) { // targetDir.mkdirs(); // } // // // 构建本地文件路径 // File localFile = new File(targetDir, uploadFileName); // // // 打印上传路径 // log.info("LocalFileUploadService uploadFile localFilePath: {}", localFile.getAbsolutePath()); // // try { // // 将文件保存到本地 // file.transferTo(localFile); // // // 如果需要自定义元数据,可以在此处理 // Map<String, String> metadata = new HashMap<>(); // metadata.put("x-amz-meta-myVal", "test"); // 如果需要元数据,可以放在文件名或其他地方 // // // // } catch (IOException e) { // log.error("LocalFileUploadService uploadFile IOException", e.getMessage(), e); // log.error("上传文件异常 , 错误信息 = {}", e); // } // // 返回相对路径 // return ServerResponse.createBySuccess(path); // } public ServerResponse upload(MultipartFile file, String path) { String fileName = file.getOriginalFilename(); src/main/java/com/nq/service/impl/UserPositionServiceImpl.java
@@ -715,13 +715,15 @@ BigDecimal all_sell_amt = now_price.multiply(new BigDecimal(buy_num.intValue())); BigDecimal profitLoss = new BigDecimal("0"); if ("買漲".equals(userPosition.getOrderDirection())) { if ("买涨".equals(userPosition.getOrderDirection())) { log.info("買賣方向:{}", "漲"); profitLoss = all_sell_amt.subtract(all_buy_amt).multiply(new BigDecimal(userPosition.getOrderLever())).setScale(2,4); // profitLoss = all_sell_amt.subtract(all_buy_amt).multiply(new BigDecimal(userPosition.getOrderLever())).setScale(2,4); profitLoss = all_sell_amt.subtract(all_buy_amt).setScale(2,4); } else { log.info("買賣方向:{}", "跌"); profitLoss = all_buy_amt.subtract(all_sell_amt).multiply(new BigDecimal(userPosition.getOrderLever())).setScale(2,4); // profitLoss = all_buy_amt.subtract(all_sell_amt).multiply(new BigDecimal(userPosition.getOrderLever())).setScale(2,4); profitLoss = all_buy_amt.subtract(all_sell_amt).setScale(2,4); } log.info("買入總金額 = {} , 賣出總金額 = {} , 盈虧 = {}", new Object[]{all_buy_amt, all_sell_amt, profitLoss}); @@ -813,6 +815,7 @@ return ServerResponse.createBySuccessMsg("平倉成功!"); } //用户追加保证金操作 public ServerResponse addmargin(String positionSn, int doType, BigDecimal marginAdd) throws Exception { @@ -1629,6 +1632,7 @@ userPositionVO.setProfitAndLose(positionProfitVO.getProfitAndLose()); userPositionVO.setAllProfitAndLose(positionProfitVO.getAllProfitAndLose()); userPositionVO.setNow_price(positionProfitVO.getNowPrice()); userPositionVO.setAllProfitAndLoseStr(positionProfitVO.getAllProfitAndLoseStr()); return userPositionVO; @@ -1637,12 +1641,14 @@ public PositionProfitVO getPositionProfitVO(UserPosition position) { BigDecimal profitAndLose = new BigDecimal("0"); BigDecimal allProfitAndLose = new BigDecimal("0"); String allProfitAndLoseStr = ""; String nowPrice = ""; if (position.getSellOrderId() != null) { BigDecimal subPrice = position.getSellOrderPrice().subtract(position.getBuyOrderPrice()); profitAndLose = subPrice.multiply(new BigDecimal(position.getOrderNum().intValue())).multiply(new BigDecimal(position.getOrderLever())).setScale(2,4); // profitAndLose = subPrice.multiply(new BigDecimal(position.getOrderNum().intValue())).multiply(new BigDecimal(position.getOrderLever())).setScale(2,4); profitAndLose = subPrice.multiply(new BigDecimal(position.getOrderNum().intValue())).setScale(2,4); if ("买跌".equals(position.getOrderDirection())) { profitAndLose = profitAndLose.negate(); } @@ -1671,10 +1677,14 @@ //总盈亏= 浮动盈亏 – 手续费 – 印花税 – 留仓费 – 点差费 allProfitAndLose = profitAndLose.subtract(position.getOrderFee()).subtract(position.getOrderSpread()).subtract(position.getOrderStayFee()).subtract(position.getSpreadRatePrice()); //改成盈亏百分比 BigDecimal allProfitAndLoseStrTemp = new BigDecimal(nowPrice).subtract(position.getBuyOrderPrice()).divide(position.getBuyOrderPrice(), 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100)).setScale(2,4); allProfitAndLoseStr = allProfitAndLoseStrTemp.toString() + "%"; } PositionProfitVO positionProfitVO = new PositionProfitVO(); positionProfitVO.setProfitAndLose(profitAndLose); positionProfitVO.setAllProfitAndLose(allProfitAndLose); positionProfitVO.setAllProfitAndLoseStr(allProfitAndLoseStr); positionProfitVO.setNowPrice(nowPrice); return positionProfitVO; src/main/java/com/nq/service/impl/UserServiceImpl.java
@@ -1820,13 +1820,27 @@ // BigDecimal userAllAmt = user.getUserAmt(); BigDecimal userAllAmt = user.getEnableAmt(); userAllAmt = userAllAmt.add(allProfitAndLose); userInfoVO.setUserAmt(userAllAmt); userInfoVO.setEnableIndexAmt(user.getEnableIndexAmt()); userInfoVO.setEnaleWithdrawAmt(user.getEnaleWithdrawAmt()); userInfoVO.setHkAmt(user.getHkAmt()); BigDecimal historyProfitLoss = new BigDecimal(0); BigDecimal buyAmtAutual = new BigDecimal(0); List<UserPosition> userPositionscc = this.userPositionMapper.findMyPositionByCodeAndSpell(user.getId(), "", "", 0); if (userPositionscc.size() > 0) { for (UserPosition position : userPositionscc) { buyAmtAutual = buyAmtAutual.add(position.getBuyOrderPrice() .multiply(new BigDecimal(position.getOrderNum())) .divide(new BigDecimal(position.getOrderLever()), 2, RoundingMode.HALF_UP)); } } userInfoVO.setBuyAmtAutual(buyAmtAutual); userAllAmt = userAllAmt.add(buyAmtAutual); userInfoVO.setUserAmt(userAllAmt); List<UserPosition> userPositions = this.userPositionMapper.findMyPositionByCodeAndSpell(user.getId(), "", "", 1); if (userPositions.size() > 0) { @@ -1916,7 +1930,8 @@ if (position.getSellOrderId() != null) { BigDecimal subPrice = position.getSellOrderPrice().subtract(position.getBuyOrderPrice()); profitAndLose = subPrice.multiply(new BigDecimal(position.getOrderNum().intValue())).multiply(new BigDecimal(position.getOrderLever())).setScale(2,4); // profitAndLose = subPrice.multiply(new BigDecimal(position.getOrderNum().intValue())).multiply(new BigDecimal(position.getOrderLever())).setScale(2,4); profitAndLose = subPrice.multiply(new BigDecimal(position.getOrderNum().intValue())).setScale(2,4); if ("买跌".equals(position.getOrderDirection())) { profitAndLose = profitAndLose.negate(); } @@ -1937,7 +1952,8 @@ } BigDecimal subPrice = (new BigDecimal(nowPrice)).subtract(position.getBuyOrderPrice()); profitAndLose = subPrice.multiply(new BigDecimal(position.getOrderNum().intValue())).multiply(new BigDecimal(position.getOrderLever())).setScale(2,4); // profitAndLose = subPrice.multiply(new BigDecimal(position.getOrderNum().intValue())).multiply(new BigDecimal(position.getOrderLever())).setScale(2,4); profitAndLose = subPrice.multiply(new BigDecimal(position.getOrderNum().intValue())).setScale(2,4); if ("买跌".equals(position.getOrderDirection())) { profitAndLose = profitAndLose.negate(); } src/main/java/com/nq/service/impl/UserWithdrawServiceImpl.java
@@ -169,7 +169,7 @@ synchronized (UserWithdrawServiceImpl.class){ //可取港币资金 BigDecimal hkAmt=user.getHkAmt(); BigDecimal hkAmt=user.getEnaleWithdrawAmt(); int compareAmt = hkAmt.compareTo(new BigDecimal(amt)); @@ -181,7 +181,7 @@ BigDecimal reckon_hkAmt = hkAmt.subtract(new BigDecimal(amt)); user.setHkAmt(reckon_hkAmt); user.setEnaleWithdrawAmt(reckon_hkAmt); log.info("提现前,港币金额={},提现后,港币金额={}",hkAmt,reckon_hkAmt); src/main/java/com/nq/utils/stock/sina/SinaStockApi.java
@@ -40,8 +40,8 @@ // System.out.println(sina_url + stockGid); // sina_result = HttpClientRequest.doGet(sina_url + stockGid); // System.out.println("请求返回:"+sina_result); System.out.println("http://36.138.182.213:8088/crypto/getSinaStock?stockGid=" + stockGid); sina_result = HttpClientRequest.doGet("http://36.138.182.213:8088/crypto/getSinaStock?stockGid=" + stockGid); System.out.println("http://36.138.182.213:7001/crypto/getSinaStock?stockGid=" + stockGid); sina_result = HttpClientRequest.doGet("http://36.138.182.213:7001/crypto/getSinaStock?stockGid=" + stockGid); System.out.println("请求返回:"+sina_result); } catch (Exception e) { log.error("获取股票行情出错,错误信息 = {}", e); src/main/java/com/nq/vo/position/PositionProfitVO.java
@@ -10,6 +10,7 @@ private BigDecimal allProfitAndLose; private String allProfitAndLoseStr; public void setNowPrice(String nowPrice) { this.nowPrice = nowPrice; @@ -71,5 +72,12 @@ return this.allProfitAndLose; } public String getAllProfitAndLoseStr() { return allProfitAndLoseStr; } public void setAllProfitAndLoseStr(String allProfitAndLoseStr) { this.allProfitAndLoseStr = allProfitAndLoseStr; } } src/main/java/com/nq/vo/position/UserPositionVO.java
@@ -59,6 +59,7 @@ private Integer orderStayDays; private BigDecimal profitAndLose; private BigDecimal allProfitAndLose; private String allProfitAndLoseStr; private String now_price; private String stockPlate; /*点差费金额*/ @@ -182,6 +183,14 @@ this.stockPlate = stockPlate; } public String getAllProfitAndLoseStr() { return allProfitAndLoseStr; } public void setAllProfitAndLoseStr(String allProfitAndLoseStr) { this.allProfitAndLoseStr = allProfitAndLoseStr; } public boolean equals(Object o) { if (o == this) return true; if (!(o instanceof UserPositionVO)) return false; src/main/java/com/nq/vo/user/UserInfoVO.java
@@ -52,6 +52,7 @@ private BigDecimal allIndexFreezAmt; private BigDecimal allFuturesProfitAndLose; private BigDecimal allFuturesFreezAmt; private BigDecimal buyAmtAutual; /** * 杠杆倍数,多个用/分割 */ src/main/resources/application.properties
@@ -9,6 +9,7 @@ ftp.user=ftp_red ftp.pass=ftp_red ftp.server.http.prefix=https://ftp.stockcardsnow.com/ loca.images.dir=/www/wwwroot/ftp.stockcardsnow.com/ #ftp.server.ip=47.56.200.145 #ftp.user=ofsuccess #ftp.pass=fdymdM34HHsS8iB6