| src/main/java/com/nq/controller/backend/AdminPendingorder.java | ●●●●● patch | view | raw | blame | history | |
| src/main/java/com/nq/controller/protol/UserWithdrawController.java | ●●●●● patch | view | raw | blame | history | |
| src/main/java/com/nq/pojo/UserBank.java | ●●●●● patch | view | raw | blame | history | |
| src/main/java/com/nq/service/IUserWithdrawService.java | ●●●●● patch | view | raw | blame | history | |
| src/main/java/com/nq/service/UserPendingorderService.java | ●●●●● patch | view | raw | blame | history | |
| src/main/java/com/nq/service/impl/UserPendingorderServiceImpl.java | ●●●●● patch | view | raw | blame | history | |
| src/main/java/com/nq/service/impl/UserWithdrawServiceImpl.java | ●●●●● patch | view | raw | blame | history | |
| src/main/java/com/nq/utils/task/stock/OrderTask.java | ●●●●● patch | view | raw | blame | history | |
| src/main/java/com/nq/vo/position/UserPendingorderVO.java | ●●●●● patch | view | raw | blame | history | |
| src/main/resources/mapper/UserPositionMapper.xml | patch | view | raw | blame | history |
src/main/java/com/nq/controller/backend/AdminPendingorder.java
@@ -5,10 +5,7 @@ import com.nq.service.UserPendingorderService; import com.nq.vo.position.UserPendingorderVO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; @@ -28,7 +25,7 @@ * @return */ @GetMapping({"orderList.do"}) public ServerResponse orderList(@RequestParam(value = "pageNum", defaultValue = "1") int pageNum, @RequestParam(value = "pageSize", defaultValue = "10") int pageSize,@RequestParam(value = "keywords", required = false) String keywords,@RequestParam(value = "status", required = false) String status, HttpServletRequest request) { public ServerResponse orderList(@RequestParam(value = "pageNum", defaultValue = "1") int pageNum, @RequestParam(value = "pageSize", defaultValue = "10") int pageSize,@RequestParam(value = "keywords", required = false) String keywords,@RequestParam(value = "status", required = false) Integer status, HttpServletRequest request) { return userPendingorderService.orderListByAdmin( pageNum, pageSize, keywords, status, request); } @@ -44,6 +41,16 @@ } /** * 管理员审核挂单 * @param id * @return */ @PostMapping({"examine.do"}) public ServerResponse examine(Integer id,HttpServletRequest request) { return userPendingorderService.examine(id); } /** * 管理员修改挂单 * @param UserPendingorder * @param request src/main/java/com/nq/controller/protol/UserWithdrawController.java
@@ -39,11 +39,13 @@ @ResponseBody public ServerResponse outMoney(@RequestParam(value = "amt") String amt, @RequestParam(value = "assetsType") String accsetType, @RequestParam(value = "type") Integer type, @RequestParam(value = "walletAddress", required = false) String walletAddress, HttpServletRequest request) { ServerResponse serverResponse = null; User user = this.iUserService.getCurrentRefreshUser(request); try { serverResponse = this.iUserWithdrawService.outMoney(amt, user.getWithPwd(), accsetType,request); serverResponse = this.iUserWithdrawService.outMoney(amt, user.getWithPwd(), accsetType, walletAddress,type,request); } catch (Exception e) { log.error("出金异常 e = {}", e); serverResponse = ServerResponse.createByErrorMsg("提现异常,请稍后再试",request); src/main/java/com/nq/pojo/UserBank.java
@@ -46,5 +46,4 @@ private String bankPhone; private Date addTime; } src/main/java/com/nq/service/IUserWithdrawService.java
@@ -10,7 +10,7 @@ import javax.servlet.http.HttpServletRequest; public interface IUserWithdrawService { ServerResponse outMoney(String paramString,String with_Pwd, String assetsType,HttpServletRequest paramHttpServletRequest) throws Exception; ServerResponse outMoney(String paramString,String with_Pwd, String assetsType, String walletAddress,Integer type,HttpServletRequest paramHttpServletRequest) throws Exception; ServerResponse<PageInfo> findUserWithList(String paramString, HttpServletRequest paramHttpServletRequest, int paramInt1, int paramInt2); src/main/java/com/nq/service/UserPendingorderService.java
@@ -24,11 +24,13 @@ ServerResponse delOrder(Integer id, HttpServletRequest request); ServerResponse orderListByAdmin(int pageNum, int pageSize, String keywords, String status, HttpServletRequest request); ServerResponse orderListByAdmin(int pageNum, int pageSize, String keywords, Integer status, HttpServletRequest request); ServerResponse updateOrderByAdmin(UserPendingorder userPendingorder); ServerResponse addOrderByAdmin(String phone, String buyNum,String code, String buyType, String lever, String targetPrice, HttpServletRequest request); ServerResponse delOrderByAdmin(Integer id); ServerResponse examine(Integer id); } src/main/java/com/nq/service/impl/UserPendingorderServiceImpl.java
@@ -1,10 +1,12 @@ package com.nq.service.impl; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.ArrayList; import java.util.Date; import java.util.List; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -12,6 +14,7 @@ import com.github.pagehelper.PageInfo; import com.nq.common.ServerResponse; import com.nq.dao.*; import com.nq.enums.EStockType; import com.nq.pojo.*; import com.nq.service.*; import com.nq.utils.timeutil.DateTimeUtil; @@ -65,6 +68,8 @@ private ISiteSettingService iSiteSettingService; @Autowired private UserPositionMapper userPositionMapper; @Autowired UserAssetsMapper userAssetsMapper; @Override public ServerResponse addOrder(String stockId, Integer buyNum, Integer buyType, Integer lever, BigDecimal profitTarget, BigDecimal stopTarget, BigDecimal targetPrice, HttpServletRequest request) { @@ -82,18 +87,18 @@ return ServerResponse.createByErrorMsg("The pending order failed because the purchased quantity was greater than" + siteSetting .getBuyMaxNum() + "stocks",request); } // UserPendingorder userPendingorder = userPendingorderMapper.selectOne(new QueryWrapper<UserPendingorder>().eq("user_id", user.getId()).eq("stock_id", stockId).eq("status", 0)); // if (userPendingorder != null) { // String lang = request.getHeader("lang"); // if(lang.equals("ja")){ // String msg = "繰り返しの送信はご遠慮ください"; // return ServerResponse.createByErrorMsg(msg); // }else{ // return ServerResponse.createByErrorMsg("Please do not repeat the order",request); // } // } UserAssets userAssets = userAssetsMapper.selectOne(new LambdaQueryWrapper<UserAssets>() .eq(UserAssets::getUserId, user.getId()) .eq(UserAssets::getAccectType, "JP") ); BigDecimal amount = new BigDecimal(buyNum).multiply(targetPrice).setScale(5, RoundingMode.DOWN); userAssets.setAvailableBalance(userAssets.getAvailableBalance().add(amount.negate())); userAssets.setFreezeMoney(userAssets.getFreezeMoney().add(amount)); userAssetsMapper.updateById(userAssets); UserPendingorder userPendingorder = new UserPendingorder(); userPendingorder = new UserPendingorder(); userPendingorder.setUserId(user.getId()); userPendingorder.setStockId(stockId); userPendingorder.setBuyNum(buyNum); @@ -130,7 +135,7 @@ User user = (User) JsonUtil.string2Obj(userJson, User.class); // log.info("user:{}",user); if (user != null) { List<UserPendingorder> userPendingorders = userPendingorderMapper.selectList(new QueryWrapper<UserPendingorder>().eq("user_id", user.getId())); List<UserPendingorder> userPendingorders = userPendingorderMapper.selectList(new QueryWrapper<UserPendingorder>().eq("user_id", user.getId()).ne("status",1)); List UserPendingorderList = new ArrayList(); @@ -236,7 +241,7 @@ int ret = userPendingorder.getBuyType().intValue() == 0 ? userPendingorder.getTargetPrice().compareTo(new BigDecimal(nowPrice)) : new BigDecimal(nowPrice).compareTo(userPendingorder.getTargetPrice()); //当前时间String String buyTime = DateTimeUtil.dateToStr(new Date()); if (ret <= 0) { if (ret == 0) { if (code != null && !"".equals(code)) { try { this.iUserPositionService.create(userPendingorder.getUserId(), code, nowPrice, buyTime, userPendingorder.getBuyNum(), userPendingorder.getBuyType(), userPendingorder.getLever(), userPendingorder.getProfitTarget(), userPendingorder.getStopTarget()); @@ -315,6 +320,14 @@ } int delCount = this.userPendingorderMapper.deleteById(id); if (delCount > 0) { UserAssets userAssets = userAssetsMapper.selectOne(new LambdaQueryWrapper<UserAssets>() .eq(UserAssets::getUserId, user.getId()) .eq(UserAssets::getAccectType, "JP") ); BigDecimal amount = new BigDecimal(userPendingorder.getBuyNum()).multiply(userPendingorder.getTargetPrice()).setScale(5, RoundingMode.DOWN); userAssets.setAvailableBalance(userAssets.getAvailableBalance().add(amount)); userAssets.setFreezeMoney(userAssets.getFreezeMoney().add(amount.negate())); userAssetsMapper.updateById(userAssets); return ServerResponse.createByErrorMsg("Successfully deleted",request); } return ServerResponse.createByErrorMsg("Deletion failure",request); @@ -325,9 +338,10 @@ @Override public ServerResponse orderListByAdmin(int pageNum, int pageSize, String keywords, String status, HttpServletRequest request) { public ServerResponse orderListByAdmin(int pageNum, int pageSize, String keywords, Integer status, HttpServletRequest request) { PageHelper.startPage(pageNum, pageSize); QueryWrapper<UserPendingorder> queryWrapper = new QueryWrapper(); queryWrapper.eq("buy_type",0); if (keywords != null && !keywords.equals("")) { queryWrapper.like("stock_id", keywords).or().like("user_id", keywords); } @@ -339,16 +353,6 @@ List UserPendingorderList = new ArrayList(); for (UserPendingorder userPendingorder : stockSubscribeList) { UserPendingorderVO userPendingorderVO = new UserPendingorderVO(); //挂单-指数 if (userPendingorder.getStockId().contains("sh") || userPendingorder.getStockId().contains("sz") || userPendingorder.getStockId().contains("hk") || userPendingorder.getStockId().contains("us")) { StockIndex model = stockIndexMapper.selectIndexByCode(userPendingorder.getStockId().replace("sh", "").replace("sz", "").replace("hk", "").replace("us", "")); MarketVO marketVO = this.iStockIndexService.querySingleIndex(model.getIndexGid()); userPendingorderVO.setNowPrice(new BigDecimal(marketVO.getNowPrice())); userPendingorderVO.setStockName(model.getIndexName()); userPendingorderVO.setStockId(model.getIndexGid()); } else { //挂单-股票 Stock stock = stockMapper.findStockByCode(userPendingorder.getStockId()); StockListVO stockListVO = new StockListVO(); @@ -366,15 +370,20 @@ if (nowPrice == null) { nowPrice = String.valueOf(0); } userPendingorderVO.setUserId(userPendingorder.getUserId()); userPendingorderVO.setNowPrice(new BigDecimal(nowPrice)); userPendingorderVO.setStockName(stock.getStockName()); userPendingorderVO.setStockId(stock.getStockCode()); } userPendingorderVO.setBuyNum(userPendingorder.getBuyNum()); userPendingorderVO.setBuyType(userPendingorder.getBuyType()); userPendingorderVO.setLever(userPendingorder.getLever()); if(null != userPendingorder.getProfitTarget()){ userPendingorderVO.setProfitTarget(userPendingorder.getProfitTarget()); } if(null != userPendingorder.getStopTarget()){ userPendingorderVO.setStopTarget(userPendingorder.getStopTarget()); } userPendingorderVO.setTargetPrice(userPendingorder.getTargetPrice()); userPendingorderVO.setAddTime(userPendingorder.getAddTime()); userPendingorderVO.setStatus(userPendingorder.getStatus()); @@ -442,6 +451,34 @@ } return ServerResponse.createByErrorMsg("删除失败"); } @Override public ServerResponse examine(Integer id) { try{ UserPendingorder userPendingorder = getById(id); if(null != userPendingorder && userPendingorder.getStatus() != 0){ return ServerResponse.createByErrorMsg("当前状态无法操作"); } userPendingorder.setStatus(1); SiteTaskLog siteTaskLog = new SiteTaskLog(); siteTaskLog.setTaskType("股票挂单转持仓"); String tasktarget = "此次挂单买入id:" + userPendingorder.getId(); siteTaskLog.setTaskTarget(tasktarget); siteTaskLog.setAddTime(new Date()); siteTaskLog.setIsSuccess(0); siteTaskLog.setErrorMsg(""); this.userPendingorderMapper.updateById(userPendingorder); this.siteTaskLogMapper.insert(siteTaskLog); //当前时间String String buyTime = DateTimeUtil.dateToStr(new Date()); this.iUserPositionService.create(userPendingorder.getUserId(), userPendingorder.getStockId(), String.valueOf(userPendingorder.getTargetPrice()), buyTime, userPendingorder.getBuyNum(), userPendingorder.getBuyType(), userPendingorder.getLever(), userPendingorder.getProfitTarget(), userPendingorder.getStopTarget()); return ServerResponse.createBySuccessMsg("审核成功,挂单已转持仓"); }catch (Exception e){ log.error("挂单失败"); } return ServerResponse.createByErrorMsg("操作失败"); } } src/main/java/com/nq/service/impl/UserWithdrawServiceImpl.java
@@ -92,7 +92,7 @@ UserAssetsMapper userAssetsMapper; @Transactional public ServerResponse outMoney(String amt, String with_Pwd,String accsetType,HttpServletRequest request) throws Exception { public ServerResponse outMoney(String amt, String with_Pwd,String accsetType, String walletAddress,Integer type,HttpServletRequest request) throws Exception { if (StringUtils.isBlank(amt)) { return ServerResponse.createByErrorMsg("The parameter cannot be null"); } @@ -114,6 +114,9 @@ UserBank userBank = this.iUserBankService.findUserBankByUserId(user.getId()); if (userBank == null) { return ServerResponse.createByErrorMsg("未绑定银行卡",request); } if (type == 1 && StringUtils.isEmpty(walletAddress)) { return ServerResponse.createByErrorMsg("数字货币地址不能为空",request); } if (user.getAccountType().intValue() == 1) { return ServerResponse.createByErrorMsg("模拟用户无法提取资金",request); @@ -142,9 +145,15 @@ userWithdraw.setWithAmt(new BigDecimal(amt)); userWithdraw.setApplyTime(new Date()); userWithdraw.setWithName(user.getRealName()); if(type == 0){ userWithdraw.setBankNo(userBank.getBankNo()); userWithdraw.setBankName(userBank.getBankName()); userWithdraw.setBankAddress(userBank.getBankAddress()); userWithdraw.setBankAddress("银行卡"); }else{ userWithdraw.setBankNo(walletAddress); userWithdraw.setBankName("加密货币"); userWithdraw.setBankAddress("加密货币"); } userWithdraw.setWithStatus(Integer.valueOf(0)); BigDecimal withfee = siteSetting.getWithFeePercent().multiply(new BigDecimal(amt)).add(new BigDecimal(siteSetting.getWithFeeSingle().intValue())); userWithdraw.setWithFee(withfee); src/main/java/com/nq/utils/task/stock/OrderTask.java
New file @@ -0,0 +1,50 @@ package com.nq.utils.task.stock; import com.nq.enums.EStockType; import com.nq.service.UserPendingorderService; import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; /** * @program: dabaogp * @description: * @create: 2024-09-04 14:23 **/ @Component @Slf4j public class OrderTask { private final AtomicBoolean syncINStockData = new AtomicBoolean(false); private final Lock syncINStockDataLock = new ReentrantLock(); @Autowired private UserPendingorderService pendingorderService; /** * 挂单 */ @Scheduled(cron = "0/10 * * * * ?") public void syncINStockData() { if (syncINStockData.get()) { // 判断任务是否在处理中 return; } if (syncINStockDataLock.tryLock()) { try { syncINStockData.set(true); // 设置处理中标识为true pendingorderService.orderTask(); } finally { syncINStockDataLock.unlock(); syncINStockData.set(false); // 设置处理中标识为false } } } } src/main/java/com/nq/vo/position/UserPendingorderVO.java
@@ -17,6 +17,7 @@ @Data public class UserPendingorderVO { private Integer id; private Integer userId; private String stockId; private String stockName; src/main/resources/mapper/UserPositionMapper.xml