| | |
| | | |
| | | |
| | | public static <T> ServerResponse<T> createBySuccessMsg(String msg,HttpServletRequest request) { |
| | | return new ServerResponse(ResponseCode.SUCCESS.getCode(), new GoogleTranslateUtil().translate(msg,request.getHeader(LANG))); |
| | | return new ServerResponse(ResponseCode.SUCCESS.getCode(), msg); |
| | | } |
| | | |
| | | public static <T> ServerResponse<T> createBySuccess(T data) { |
| | |
| | | |
| | | |
| | | public static <T> ServerResponse<T> createBySuccess(String data,HttpServletRequest request) { |
| | | return new ServerResponse(ResponseCode.SUCCESS.getCode(), new GoogleTranslateUtil().translate(data,request.getHeader(LANG))); |
| | | return new ServerResponse(ResponseCode.SUCCESS.getCode(), data); |
| | | } |
| | | |
| | | public static <T> ServerResponse<T> createBySuccess(String msg, T data) { |
| | |
| | | return new ServerResponse(ResponseCode.ERROR.getCode(), errormsg); |
| | | } |
| | | public static <T> ServerResponse<T> createByErrorMsg(String errormsg, HttpServletRequest request) { |
| | | return new ServerResponse(ResponseCode.ERROR.getCode(), new GoogleTranslateUtil().translate(errormsg,request.getHeader(LANG))); |
| | | return new ServerResponse(ResponseCode.ERROR.getCode(), errormsg); |
| | | } |
| | | public static <T> ServerResponse<T> createByErrorMsg(String errormsg, String langFrom ,String lang) throws Exception { |
| | | return new ServerResponse(ResponseCode.ERROR.getCode(), new GoogleTranslateUtil().translate(langFrom,lang,errormsg)); |
| | | return new ServerResponse(ResponseCode.ERROR.getCode(), errormsg); |
| | | } |
| | | |
| | | |
| | |
| | | httpServletResponse.setCharacterEncoding("UTF-8"); |
| | | httpServletResponse.setContentType("application/json;charset=UTF-8"); |
| | | PrintWriter writer = httpServletResponse.getWriter(); |
| | | writer.print( new Gson().toJson(ServerResponse.createByErrorCodeMsg(401,googleTranslateUtil.translate("请登录",lang )))); |
| | | writer.print( new Gson().toJson(ServerResponse.createByErrorCodeMsg(401,"请登录"))); |
| | | writer.flush(); |
| | | writer.close(); |
| | | return false; |
| | |
| | | } |
| | | } |
| | | |
| | | @RequestMapping({"juhenewpayNotify.do"}) |
| | | @ResponseBody |
| | | public JSONObject juhenewpayNotify(HttpServletRequest request, HttpServletResponse response) throws IOException { |
| | | System.out.println("============开始回调==============="); |
| | | LinkedMap map = new LinkedMap(); |
| | | String orderno = (String) request.getParameter("orderno"); |
| | | String amount = (String) request.getParameter("payamount"); |
| | | String[] arr = orderno.split("_"); |
| | | map.put("payamount", request.getParameter("payamount")); |
| | | map.put("orderno", orderno); |
| | | map.put("status", (String) request.getParameter("status")); |
| | | log.info("回调创建订单前map==="+map.toString()); |
| | | // @RequestMapping({"juhenewpayNotify.do"}) |
| | | // @ResponseBody |
| | | // public JSONObject juhenewpayNotify(HttpServletRequest request, HttpServletResponse response) throws IOException { |
| | | // System.out.println("============开始回调==============="); |
| | | // LinkedMap map = new LinkedMap(); |
| | | // String orderno = (String) request.getParameter("orderno"); |
| | | // String amount = (String) request.getParameter("payamount"); |
| | | // String[] arr = orderno.split("_"); |
| | | // map.put("payamount", request.getParameter("payamount")); |
| | | // map.put("orderno", orderno); |
| | | // map.put("status", (String) request.getParameter("status")); |
| | | // log.info("回调创建订单前map==="+map.toString()); |
| | | // |
| | | // JSONObject jsonObj = new JSONObject(); |
| | | // Map<String,Object> json = new HashMap<String,Object>(); |
| | | // |
| | | // |
| | | // if ("1".equals((String) request.getParameter("status"))) { |
| | | // // 这里编写用户业务逻辑代码,如存储订单状态,自动发货等 |
| | | // //TODO |
| | | // if (amount != null & !StringUtils.isEmpty(amount)) { |
| | | // System.out.println("============更新用户金额==============="); |
| | | // Double aDouble = Double.valueOf(amount); |
| | | // Integer integer = aDouble.intValue(); |
| | | // //判断是否回调成功 |
| | | // UserRecharge userRecharge = this.userRechargeMapper.findUserRechargeByOrderSn(orderno); |
| | | // if(userRecharge == null){ |
| | | // System.out.println("============充值完成==============="); |
| | | // iUserRechargeService.createOrder(Integer.valueOf(arr[0]), 1, aDouble.intValue(), orderno); |
| | | // jsonObj.put("reason", "success"); |
| | | // } else { |
| | | // System.out.println("============充值失败,已回调成功无需重复回调==============="); |
| | | // jsonObj.put("reason", "error"); |
| | | // } |
| | | // } else{ |
| | | // jsonObj.put("reason", "error"); |
| | | // } |
| | | // System.out.println("============回调成功并结束==============="); |
| | | // //jsonObj.putAll(map); |
| | | // return jsonObj; |
| | | // } else { |
| | | // System.out.println("============回调失败并结束==============="); |
| | | // jsonObj.put("reason", "error"); |
| | | // return jsonObj; |
| | | // } |
| | | // |
| | | // } |
| | | |
| | | JSONObject jsonObj = new JSONObject(); |
| | | Map<String,Object> json = new HashMap<String,Object>(); |
| | | |
| | | |
| | | if ("1".equals((String) request.getParameter("status"))) { |
| | | // 这里编写用户业务逻辑代码,如存储订单状态,自动发货等 |
| | | //TODO |
| | | if (amount != null & !StringUtils.isEmpty(amount)) { |
| | | System.out.println("============更新用户金额==============="); |
| | | Double aDouble = Double.valueOf(amount); |
| | | Integer integer = aDouble.intValue(); |
| | | //判断是否回调成功 |
| | | UserRecharge userRecharge = this.userRechargeMapper.findUserRechargeByOrderSn(orderno); |
| | | if(userRecharge == null){ |
| | | System.out.println("============充值完成==============="); |
| | | iUserRechargeService.createOrder(Integer.valueOf(arr[0]), 1, aDouble.intValue(), orderno); |
| | | jsonObj.put("reason", "success"); |
| | | } else { |
| | | System.out.println("============充值失败,已回调成功无需重复回调==============="); |
| | | jsonObj.put("reason", "error"); |
| | | } |
| | | } else{ |
| | | jsonObj.put("reason", "error"); |
| | | } |
| | | System.out.println("============回调成功并结束==============="); |
| | | //jsonObj.putAll(map); |
| | | return jsonObj; |
| | | } else { |
| | | System.out.println("============回调失败并结束==============="); |
| | | jsonObj.put("reason", "error"); |
| | | return jsonObj; |
| | | } |
| | | |
| | | } |
| | | |
| | | @RequestMapping({"juheh5payNotify.do"}) |
| | | @ResponseBody |
| | | public void juheh5payNotify(HttpServletRequest request, HttpServletResponse response) throws IOException { |
| | | System.out.println("============开始回调==============="); |
| | | LinkedMap map = new LinkedMap(); |
| | | String orderno = (String) request.getParameter("name"); |
| | | String amount = (String) request.getParameter("money"); |
| | | String[] arr = orderno.split("_"); |
| | | map.put("money", request.getParameter("money")); |
| | | map.put("name", orderno); |
| | | log.info("回调创建订单前map==="+map.toString()); |
| | | |
| | | JSONObject jsonObj = new JSONObject(); |
| | | Map<String,Object> json = new HashMap<String,Object>(); |
| | | |
| | | |
| | | //if ("200".equals((String) request.getParameter("status"))) { |
| | | // 这里编写用户业务逻辑代码,如存储订单状态,自动发货等 |
| | | //TODO |
| | | if (amount != null & !StringUtils.isEmpty(amount)) { |
| | | System.out.println("============更新用户金额==============="); |
| | | Double aDouble = Double.valueOf(amount); |
| | | Integer integer = aDouble.intValue(); |
| | | //判断是否回调成功 |
| | | UserRecharge userRecharge = this.userRechargeMapper.findUserRechargeByOrderSn(orderno); |
| | | if(userRecharge == null){ |
| | | System.out.println("============充值完成==============="); |
| | | iUserRechargeService.createOrder(Integer.valueOf(arr[0]), 1, aDouble.intValue(), orderno); |
| | | } else { |
| | | System.out.println("============充值失败,已回调成功无需重复回调==============="); |
| | | } |
| | | } else{ |
| | | } |
| | | System.out.println("============回调成功并结束==============="); |
| | | //jsonObj.putAll(map); |
| | | response.getWriter().write("success"); |
| | | /*} else { |
| | | System.out.println("============回调失败并结束==============="); |
| | | response.getWriter().write("error"); |
| | | }*/ |
| | | |
| | | } |
| | | // @RequestMapping({"juheh5payNotify.do"}) |
| | | // @ResponseBody |
| | | // public void juheh5payNotify(HttpServletRequest request, HttpServletResponse response) throws IOException { |
| | | // System.out.println("============开始回调==============="); |
| | | // LinkedMap map = new LinkedMap(); |
| | | // String orderno = (String) request.getParameter("name"); |
| | | // String amount = (String) request.getParameter("money"); |
| | | // String[] arr = orderno.split("_"); |
| | | // map.put("money", request.getParameter("money")); |
| | | // map.put("name", orderno); |
| | | // log.info("回调创建订单前map==="+map.toString()); |
| | | // |
| | | // JSONObject jsonObj = new JSONObject(); |
| | | // Map<String,Object> json = new HashMap<String,Object>(); |
| | | // |
| | | // |
| | | // //if ("200".equals((String) request.getParameter("status"))) { |
| | | // // 这里编写用户业务逻辑代码,如存储订单状态,自动发货等 |
| | | // //TODO |
| | | // if (amount != null & !StringUtils.isEmpty(amount)) { |
| | | // System.out.println("============更新用户金额==============="); |
| | | // Double aDouble = Double.valueOf(amount); |
| | | // Integer integer = aDouble.intValue(); |
| | | // //判断是否回调成功 |
| | | // UserRecharge userRecharge = this.userRechargeMapper.findUserRechargeByOrderSn(orderno); |
| | | // if(userRecharge == null){ |
| | | // System.out.println("============充值完成==============="); |
| | | // iUserRechargeService.createOrder(Integer.valueOf(arr[0]), 1, aDouble.intValue(), orderno); |
| | | // } else { |
| | | // System.out.println("============充值失败,已回调成功无需重复回调==============="); |
| | | // } |
| | | // } else{ |
| | | // } |
| | | // System.out.println("============回调成功并结束==============="); |
| | | // //jsonObj.putAll(map); |
| | | // response.getWriter().write("success"); |
| | | // /*} else { |
| | | // System.out.println("============回调失败并结束==============="); |
| | | // response.getWriter().write("error"); |
| | | // }*/ |
| | | // |
| | | // } |
| | | |
| | | @RequestMapping({"flyNotify.do"}) |
| | | @ResponseBody |
| | |
| | | UserLoginResultVO resultVO = new UserLoginResultVO(); |
| | | resultVO.setKey(pc_cookie_name); |
| | | resultVO.setToken(token); |
| | | return ServerResponse.createBySuccess(new GoogleTranslateUtil().translate("登录成功",request.getHeader("lang")), resultVO); |
| | | return ServerResponse.createBySuccess(resultVO ); |
| | | } |
| | | return serverResponse; |
| | | } |
| | |
| | | //添加用户列表 用户信息 |
| | | @RequestMapping({"addSimulatedAccount.do"}) |
| | | @ResponseBody |
| | | public ServerResponse addSimulatedAccount(HttpServletRequest request, @RequestParam(value = "agentId", required = false) Integer agentId, @RequestParam("phone") String phone, @RequestParam("amt") String amt, @RequestParam("accountType") Integer accountType, @RequestParam("pwd") String pwd) { |
| | | public ServerResponse addSimulatedAccount(HttpServletRequest request, @RequestParam(value = "agentId", required = false) Integer agentId, |
| | | @RequestParam("phone") String phone, @RequestParam("amt") String amt, |
| | | @RequestParam("accountType") Integer accountType, @RequestParam("pwd") String pwd) { |
| | | return this.iUserService.addSimulatedAccount(agentId, phone, pwd, amt, accountType, request); |
| | | } |
| | | |
| | |
| | | //创建资金管理 充值订单 |
| | | @RequestMapping({"createOrder.do"}) |
| | | @ResponseBody |
| | | public ServerResponse createOrder(@RequestParam(value = "userId", required = false) Integer userId, @RequestParam(value = "state", required = false) Integer state, @RequestParam(value = "amt", required = false) Integer amt, @RequestParam(value = "payChannel", required = false) String payChannel) { |
| | | return this.iUserRechargeService.createOrder(userId, state, amt, payChannel); |
| | | public ServerResponse createOrder(@RequestParam(value = "userId", required = false) Integer userId, |
| | | @RequestParam(value = "state", required = false) Integer state, |
| | | @RequestParam(value = "amt", required = false) Integer amt, |
| | | @RequestParam(value = "accountType", required = true) String accountType, |
| | | @RequestParam(value = "payChannel", required = false) String payChannel) { |
| | | return this.iUserRechargeService.createOrder(userId, state, amt, payChannel,accountType); |
| | | } |
| | | |
| | | //删除资金管理 充值列表订单信息 |
| | |
| | | @RequestParam(value = "password")String password, |
| | | @RequestParam(value = "startTime")String startTime, |
| | | @RequestParam(value = "endTime")String endTime, |
| | | @RequestParam(value = "discount") String discount, |
| | | @RequestParam(value = "period")Integer period) { |
| | | return stockDzService.addByAdmin(stockCode,stockNum,password,startTime,endTime,discount,period); |
| | | return stockDzService.addByAdmin(stockCode,stockNum,password,startTime,endTime,period); |
| | | } |
| | | /** |
| | | * 删除大宗 |
| | |
| | | } |
| | | } |
| | | User user = this.iUserService.getCurrentRefreshUser(request); |
| | | UserAssets userAssets = userAssetsServices.assetsByTypeAndUserId("IN", user.getId()); |
| | | UserAssets userAssets = userAssetsServices.assetsByTypeAndUserId("MAS", user.getId()); |
| | | if(userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0){ |
| | | return ServerResponse.createByErrorMsg("请先缴清待补资金", request); |
| | | } |
| | |
| | | //用户平仓操作 |
| | | @RequestMapping({"sell.do"}) |
| | | @ResponseBody |
| | | public ServerResponse sell(HttpServletRequest request, @RequestParam("positionSn") String positionSn, @RequestParam("closeNumber") Integer closeNumber) { |
| | | return this.iUserPositionService.sell(positionSn,closeNumber, 1,request); |
| | | public ServerResponse sell(HttpServletRequest request, @RequestParam("positionSn") String positionSn) { |
| | | return this.iUserPositionService.sell(positionSn, 1); |
| | | } |
| | | |
| | | |
| | |
| | | @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"); |
| | | try { |
| | | String path = request.getSession().getServletContext().getRealPath("upload"); |
| | | |
| | | ServerResponse serverResponse = this.iFileUploadService.upload(file, path); |
| | | if (serverResponse.isSuccess()) { |
| | | String targetFileName = serverResponse.getData().toString(); |
| | | String url = PropertiesUtil.getProperty("ftp.server.http.prefix") + targetFileName; |
| | | ServerResponse serverResponse = this.iFileUploadService.upload(file, path); |
| | | if (serverResponse.isSuccess()) { |
| | | String targetFileName = serverResponse.getData().toString(); |
| | | String url = PropertiesUtil.getProperty("ftp.server.http.prefix") + targetFileName; |
| | | Map fileMap = Maps.newHashMap(); |
| | | fileMap.put("uri", targetFileName); |
| | | fileMap.put("url", url); |
| | | |
| | | |
| | | Map fileMap = Maps.newHashMap(); |
| | | fileMap.put("uri", targetFileName); |
| | | fileMap.put("url", url); |
| | | |
| | | return ServerResponse.createBySuccess(fileMap); |
| | | return ServerResponse.createBySuccess(fileMap); |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | log.error("上传失败",e); |
| | | } |
| | | return serverResponse; |
| | | return ServerResponse.createByErrorMsg("上传失败"); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | |
| | | |
| | | US("US","美国股票","5",PropertiesUtil.getProperty("US_HTTP_API"),PropertiesUtil.getProperty("US_KEY"),"USD","$"), |
| | | // US("US","美国股票","5",PropertiesUtil.getProperty("US_HTTP_API"),PropertiesUtil.getProperty("US_KEY"),"USD","$"), |
| | | // HK("HK","香港股票","39",PropertiesUtil.getProperty("HK_HTTP_API"),PropertiesUtil.getProperty("HK_KEY"),"HKD","HK$"), |
| | | // MAS("MAS","马来西亚股票","42",PropertiesUtil.getProperty("MAS_HTTP_API"),PropertiesUtil.getProperty("MAS_KEY"),"MYR","RM"), |
| | | MAS("MAS","马来西亚股票","42",PropertiesUtil.getProperty("MY_HTTP_API"),PropertiesUtil.getProperty("MY_KEY"),"MAS","RM"), |
| | | SGP("SGP","新加坡股票","36",PropertiesUtil.getProperty("SGP_HTTP_API"),PropertiesUtil.getProperty("SGP_KEY"),"SGP","S$"); |
| | | // |
| | | IN("IN","印度股票","14", PropertiesUtil.getProperty("IN_HTTP_API"),PropertiesUtil.getProperty("IN_KEY"),"INR","₹"); |
| | | // IN("IN","印度股票","14", PropertiesUtil.getProperty("IN_HTTP_API"),PropertiesUtil.getProperty("IN_KEY"),"INR","₹"); |
| | | // TH("TH","泰国股票","41",PropertiesUtil.getProperty("TH_HTTP_API"),PropertiesUtil.getProperty("TH_KEY")), |
| | | // HG("HG","韩国股票","11",PropertiesUtil.getProperty("HG_HTTP_API"),PropertiesUtil.getProperty("HG_KEY")), |
| | | // SZHB("SZHB","数字货币","41",PropertiesUtil.getProperty("SZHB_HTTP_API"),PropertiesUtil.getProperty("SZHB_KEY")); |
| | |
| | | } |
| | | |
| | | public static EStockType getEStockTypeByCode(String code){ |
| | | if(EStockType.US.getCode().equals(code)){ |
| | | return US; |
| | | if(EStockType.MAS.getCode().equals(code)){ |
| | | return MAS; |
| | | |
| | | }else if(EStockType.IN.getCode().equals(code)){ |
| | | return IN; |
| | | }else if(EStockType.SGP.getCode().equals(code)){ |
| | | return SGP; |
| | | } |
| | | return US; |
| | | return MAS; |
| | | } |
| | | |
| | | public String getContryId() { |
| | |
| | | |
| | | ServerResponse updateState(Integer paramInteger1, Integer paramInteger2) throws Exception; |
| | | |
| | | ServerResponse createOrder(Integer paramInteger1, Integer paramInteger2, Integer paramInteger3, String paramString); |
| | | ServerResponse createOrder(Integer paramInteger1, Integer paramInteger2, Integer paramInteger3, String paramString,String accountType); |
| | | |
| | | ServerResponse del(Integer paramInteger); |
| | | |
| | |
| | | |
| | | ServerResponse getDzList(); |
| | | |
| | | ServerResponse addByAdmin(String stockCode, String stockNum, String password, String startTime, String endTime, String discount,Integer period); |
| | | ServerResponse addByAdmin(String stockCode, String stockNum, String password, String startTime, String endTime,Integer period); |
| | | |
| | | ServerResponse getDzListByAdmin(String keywords); |
| | | |
| | |
| | | |
| | | UserAssets userAssets = userAssetsMapper.selectOne(new LambdaQueryWrapper<UserAssets>() |
| | | .eq(UserAssets::getUserId, orderEchoBean.getUserId()) |
| | | .eq(UserAssets::getAccectType, "IN") |
| | | .eq(UserAssets::getAccectType, "MAS") |
| | | ); |
| | | userAssets.setAvailableBalance(userAssets.getAvailableBalance().subtract(money)); |
| | | userAssets.setFreezeMoney(userAssets.getFreezeMoney().add(money)); |
| | |
| | | BigDecimal aml = incomeAmount.add(money); |
| | | UserAssets userAssets = userAssetsMapper.selectOne(new LambdaQueryWrapper<UserAssets>() |
| | | .eq(UserAssets::getUserId, orderEchoBean.getUserId()) |
| | | .eq(UserAssets::getAccectType, "IN") |
| | | .eq(UserAssets::getAccectType, "MAS") |
| | | ); |
| | | if (userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0) { |
| | | continue; |
| | |
| | | @Transactional |
| | | @Override |
| | | public void RealTimeDataProcess(EStockType eStockType, StockRealTimeBean timeBean) { |
| | | QueryWrapper<UserPosition> upQuery = new QueryWrapper<>(); |
| | | upQuery.eq("stock_code",timeBean.getPid()); |
| | | upQuery.isNotNull("sell_order_id"); |
| | | // 查询未平仓的价格 |
| | | List<UserPosition> userPositionList = userPositionMapper.selectList(upQuery); |
| | | for (int i = 0; i <userPositionList.size() ; i++) { |
| | | UserPosition userPosition = userPositionList.get(i); |
| | | BigDecimal bigDecimal = new BigDecimal(timeBean.getLast()).subtract(userPosition.getBuyOrderPrice()) |
| | | .multiply(new BigDecimal(userPosition.getOrderNum())); |
| | | if(!userPosition.getOrderDirection().equals("买涨")){ |
| | | bigDecimal = bigDecimal.negate(); |
| | | } |
| | | userPosition.setProfitAndLose(bigDecimal); |
| | | userPosition.setAllProfitAndLose(bigDecimal); |
| | | userPositionMapper.updateById(userPosition); |
| | | } |
| | | |
| | | |
| | | RedisKeyUtil.setCacheRealTimeStock(eStockType,timeBean); |
| | | |
| | | } |
| | | } |
| | |
| | | import com.nq.dao.StockMapper; |
| | | import com.nq.dao.StockSettingMapper; |
| | | import com.nq.enums.EConfigKey; |
| | | import com.nq.enums.EStockType; |
| | | import com.nq.pojo.*; |
| | | import com.nq.service.IPriceServices; |
| | | import com.nq.service.IStockConfigServices; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.BufferedReader; |
| | | import java.io.InputStreamReader; |
| | | import java.io.*; |
| | | import java.lang.reflect.Type; |
| | | import java.math.BigDecimal; |
| | | import java.io.BufferedReader; |
| | |
| | | if(stockSetting.getType().equals("0")){ |
| | | return new BigDecimal(stockSetting.getPrice()); |
| | | }else{ |
| | | String s = doGet(stock.getStockCode()); |
| | | String s = doPost(stock); |
| | | if(null != s){ |
| | | Map<String, Object> stringObjectMap = jsonToMap(s); |
| | | return new BigDecimal(stringObjectMap.get("last").toString()).multiply(new BigDecimal(stockSetting.getPrice())); |
| | |
| | | } |
| | | } |
| | | |
| | | String s = doGet(stock.getStockCode()); |
| | | String s = doPost(stock); |
| | | if(null != s) { |
| | | Map<String, Object> stringObjectMap = jsonToMap(s); |
| | | return new BigDecimal(stringObjectMap.get("last").toString()); |
| | |
| | | @Override |
| | | public Map<String, Object> getNewStock(String stockCode) { |
| | | Stock stock = stockMapper.selectOne(new QueryWrapper<Stock>().eq("stock_code",stockCode)); |
| | | String s = doGet(stock.getStockCode()); |
| | | String s = doPost(stock); |
| | | if(null != s){ |
| | | Map<String, Object> stringObjectMap = jsonToMap(s); |
| | | return stringObjectMap; |
| | |
| | | } |
| | | } |
| | | |
| | | public String doGet(String pid){ |
| | | String apiUrl = PropertiesUtil.getProperty("US_HTTP_API")+"stock?pid="+pid+"&key="+PropertiesUtil.getProperty("US_KEY"); |
| | | try { |
| | | URL url = new URL(apiUrl); |
| | | HttpURLConnection connection = (HttpURLConnection) url.openConnection(); |
| | | connection.setRequestMethod("GET"); |
| | | |
| | | BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); |
| | | String inputLine; |
| | | StringBuffer response = new StringBuffer(); |
| | | |
| | | while ((inputLine = in.readLine()) != null) { |
| | | response.append(inputLine); |
| | | } |
| | | in.close(); |
| | | return response.toString(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | public String doPost(Stock stock) { |
| | | EStockType eStockType = EStockType.getEStockTypeByCode(stock.getStockType()); |
| | | String apiUrl = eStockType.getStockUrl()+"stock?version=v1&key="+eStockType.getStockKey(); |
| | | Map<String, Object> paramMap = new HashMap<>(); |
| | | paramMap.put("pid",stock.getStockCode()); |
| | | String r = HttpClientRequest.doPost(apiUrl, paramMap); |
| | | return r; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public BigDecimal getNowPrice(String stockCode, String stockType) { |
| | | BigDecimal nowPrice = getNowPrice(stockCode); |
| | |
| | | |
| | | @Override |
| | | public void grabNews() { |
| | | addNews(1, PropertiesUtil.getProperty("IN_NEW_HTTP_API") + "stock-markets?key=" + PropertiesUtil.getProperty("IN_NEW_KEY") + "&type=6"); |
| | | addNews(1, PropertiesUtil.getProperty("MY_HTTP_API") + "stock-markets?key=" + PropertiesUtil.getProperty("MY_KEY") + "&type=6"); |
| | | addNews(1, PropertiesUtil.getProperty("SGP_HTTP_API") + "stock-markets?key=" + PropertiesUtil.getProperty("SGP_KEY") + "&type=6"); |
| | | } |
| | | |
| | | private void addNews(Integer type, String url) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public ServerResponse addByAdmin(String stockCode, String stockNum, String password, String startTime, String endTime, String discount,Integer period) { |
| | | if (stockCode == null || stockCode.equals("")||stockNum == null || stockNum.equals("")||password == null || discount == null|| discount.equals("")|| |
| | | public ServerResponse addByAdmin(String stockCode, String stockNum, String password, String startTime, String endTime, Integer period) { |
| | | if (stockCode == null || stockCode.equals("")||stockNum == null || stockNum.equals("")||password == null || |
| | | password.equals("")|| startTime == null || startTime.equals("")||endTime == null || endTime.equals("") || period == null){ |
| | | return ServerResponse.createByErrorMsg("参数不能为空"); |
| | | } |
| | |
| | | stockDz.setPassword(password); |
| | | stockDz.setStartTime(DateTimeUtil.strToDate(startTime)); |
| | | stockDz.setEndTime(DateTimeUtil.strToDate(endTime)); |
| | | stockDz.setDiscount(new BigDecimal(discount)); |
| | | stockDz.setDiscount(new BigDecimal(0)); |
| | | stockDz.setPeriod(period); |
| | | int res = stockDzMapper.insert(stockDz); |
| | | if (res > 0) { |
| | |
| | | List<Stock> stockList = new ArrayList<>(); |
| | | if (stockType.equals("99")) { |
| | | PageHelper.startPage(pageNum, pageSize); |
| | | stockList.addAll(stockMapper.findZtStockListByKeyWords(keyWords, stockPlate, "IN", Integer.valueOf(0))); |
| | | stockList.addAll(stockMapper.findZtStockListByKeyWords(keyWords, stockPlate, "MAS", Integer.valueOf(0))); |
| | | } else if (stockType.equals("100")) { |
| | | User user = iUserService.getCurrentRefreshUser(request); |
| | | if (user == null) { |
| | |
| | | @Override |
| | | public ServerResponse getStockByType(int pageNum, int pageSize, String orderBy, String keyWords, String stockType, HttpServletRequest request) { |
| | | List<Stock> stockList = new ArrayList<>(); |
| | | if(stockType.equals("dz")){ |
| | | if(stockType.equals("DZ")){ |
| | | PageHelper.startPage(pageNum, pageSize); |
| | | stockList.addAll(stockMapper.findStockTypeDz(orderBy,stockType, keyWords)); |
| | | }else{ |
| | |
| | | if (stockList.size() > 0){ |
| | | stockListVOS.addAll(Objects.requireNonNull(StockApi.getStockReailTimes(stockList))); |
| | | } |
| | | |
| | | // Create a list to hold Futures |
| | | List<CompletableFuture<Void>> futures = new ArrayList<>(); |
| | | |
| | | // Use CompletableFuture to perform asynchronous processing for each stockListVO |
| | | // for (StockListVO stockListVO : stockListVOS) { |
| | | // CompletableFuture<Void> future = CompletableFuture.runAsync(() -> { |
| | | // stockListVO.setNowPrice(iPriceServices.getNowPrice(stockListVO.getCode(), stockType).toString()); |
| | | // Map<String, Object> newStock = iPriceServices.getNewStock(stockListVO.getCode()); |
| | | // stockListVO.setHcrateP(newStock.get("pcp").toString()); |
| | | // }); |
| | | // futures.add(future); |
| | | // } |
| | | // |
| | | // // Wait for all futures to complete |
| | | // CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join(); |
| | | |
| | | RPageInfo pageInfo = new RPageInfo(); |
| | | pageInfo.setList(stockListVOS); |
| | | pageInfo.setStockType(stockType); |
| | |
| | | |
| | | @Override |
| | | public UserAssets assetsByTypeAndUserId(String accetType, Integer userId) { |
| | | if(accetType.equals("SZHB")){ |
| | | accetType = "US"; |
| | | } |
| | | QueryWrapper<UserAssets> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("accect_type",accetType); |
| | | queryWrapper.eq("user_id",userId); |
| | |
| | | } |
| | | }else{ |
| | | if(type.equals("2")){ |
| | | return userRechargeService.createOrder(userAssets.getUserId(),1,bigAmt.intValue(),"1"); |
| | | return userRechargeService.createOrder(userAssets.getUserId(),1,bigAmt.intValue(),"1",userAssets.getAccectType()); |
| | | }else{ |
| | | |
| | | |
| | |
| | | |
| | | @Override |
| | | public BigDecimal getAvailableBalance(String accetType, Integer userId) { |
| | | if(accetType.equals("SZHB")){ |
| | | accetType = "US"; |
| | | } |
| | | return assetsByTypeAndUserId(accetType,userId).getAvailableBalance(); |
| | | } |
| | | |
| | |
| | | |
| | | UserAssets userAssets = userAssetsMapper.selectOne(new LambdaQueryWrapper<UserAssets>() |
| | | .eq(UserAssets::getUserId, user.getId()) |
| | | .eq(UserAssets::getAccectType, "IN") |
| | | .eq(UserAssets::getAccectType, "MAS") |
| | | ); |
| | | BigDecimal amount = new BigDecimal(buyNum).multiply(targetPrice).setScale(5, RoundingMode.DOWN); |
| | | userAssets.setAvailableBalance(userAssets.getAvailableBalance().add(amount.negate())); |
| | |
| | | if (delCount > 0) { |
| | | UserAssets userAssets = userAssetsMapper.selectOne(new LambdaQueryWrapper<UserAssets>() |
| | | .eq(UserAssets::getUserId, user.getId()) |
| | | .eq(UserAssets::getAccectType, "IN") |
| | | .eq(UserAssets::getAccectType, "MAS") |
| | | ); |
| | | BigDecimal amount = new BigDecimal(userPendingorder.getBuyNum()).multiply(userPendingorder.getTargetPrice()).setScale(5, RoundingMode.DOWN); |
| | | userAssets.setAvailableBalance(userAssets.getAvailableBalance().add(amount)); |
| | |
| | | SiteSetting siteSetting = iSiteSettingService.getSiteSetting(); |
| | | StockRealTimeBean stockRealTimeBean = RedisKeyUtil.getCacheRealTimeStock(stock); |
| | | BigDecimal pcp = new BigDecimal(stockRealTimeBean.getPcp()); |
| | | SiteVipRob siteVipRob = iSiteVipRobService.getByStockCode(stock.getStockCode()); |
| | | // 检查VIP抢筹功能是否开启且用户符合条件 |
| | | if (null != siteVipRob && siteVipRob.getStatus() == 1 && pcp.compareTo(siteVipRob.getStockChg()) >= 0) { |
| | | // 检查密码是否为空 |
| | | if (StringUtils.isBlank(password)) { |
| | | return ServerResponse.createByErrorMsg("VIP抢筹秘钥错误", request); |
| | | } |
| | | // 检查交易数量是否达到最低要求 |
| | | if (buyNum < siteVipRob.getLowestTrade()) { |
| | | return ServerResponse.createByErrorMsg("VIP抢筹秘最低交易数量为" + siteVipRob.getLowestTrade(), request); |
| | | } |
| | | // 检查VIP密码是否正确 |
| | | if (!siteSetting.getVipPassword().equals(password)) { |
| | | return ServerResponse.createByErrorMsg("VIP抢筹秘钥错误", request); |
| | | } |
| | | } |
| | | // SiteVipRob siteVipRob = iSiteVipRobService.getByStockCode(stock.getStockCode()); |
| | | // // 检查VIP抢筹功能是否开启且用户符合条件 |
| | | // if (null != siteVipRob && siteVipRob.getStatus() == 1 && pcp.compareTo(siteVipRob.getStockChg()) >= 0) { |
| | | // // 检查密码是否为空 |
| | | // if (StringUtils.isBlank(password)) { |
| | | // return ServerResponse.createByErrorMsg("VIP抢筹秘钥错误", request); |
| | | // } |
| | | // // 检查交易数量是否达到最低要求 |
| | | // if (buyNum < siteVipRob.getLowestTrade()) { |
| | | // return ServerResponse.createByErrorMsg("VIP抢筹秘最低交易数量为" + siteVipRob.getLowestTrade(), request); |
| | | // } |
| | | // // 检查VIP密码是否正确 |
| | | // if (!siteSetting.getVipPassword().equals(password)) { |
| | | // return ServerResponse.createByErrorMsg("VIP抢筹秘钥错误", request); |
| | | // } |
| | | // } |
| | | BigDecimal buyAmt = nowPrice.multiply(new BigDecimal(buyNum)).divide(new BigDecimal(lever)); |
| | | BigDecimal orderFree = siteSettingBuyFee.multiply(buyAmt); |
| | | |
| | |
| | | |
| | | UserAssets userAssets = userAssetsMapper.selectOne(new LambdaQueryWrapper<UserAssets>() |
| | | .eq(UserAssets::getUserId, userPosition.getUserId()) |
| | | .eq(UserAssets::getAccectType, "IN") |
| | | .eq(UserAssets::getAccectType, "MAS") |
| | | ); |
| | | if(userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0){ |
| | | return ServerResponse.createByErrorMsg("请先缴清待补资金", request); |
| | |
| | | userPosition.setStockCode(stock.getStockCode()); |
| | | userPosition.setStockSpell(stock.getStockSpell()); |
| | | userPosition.setStockName(userStockSubscribe.getNewName()); |
| | | StringBuffer gid = new StringBuffer(); |
| | | gid.append(stockSubscribe.getStockType()!=null?stockSubscribe.getStockType():""); |
| | | gid.append(userStockSubscribe.getNewCode()!=null?userStockSubscribe.getNewCode():"stock code invaild"); |
| | | userPosition.setStockGid(gid.toString()); |
| | | userPosition.setStockGid(stock.getStockType()); |
| | | userPosition.setBuyOrderId(GeneratePosition.getPositionId()); |
| | | userPosition.setBuyOrderTime(new Date()); |
| | | userPosition.setBuyOrderPrice(userStockSubscribe.getBuyPrice()); |
| | |
| | | if (siteProduct.getRealNameDisplay() && user.getIsLock().intValue() == 1) { |
| | | return ServerResponse.createByErrorMsg("Order failed, account has been locked"); |
| | | } |
| | | UserAssets userAssets = userAssetsServices.assetsByTypeAndUserId("IN", user.getId()); |
| | | UserAssets userAssets = userAssetsServices.assetsByTypeAndUserId("MAS", user.getId()); |
| | | if(userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0){ |
| | | return ServerResponse.createByErrorMsg("请先缴清待补资金", request); |
| | | } |
| | |
| | | for (UserPosition position : list) { |
| | | UserAssets userAssets = userAssetsMapper.selectOne(new LambdaQueryWrapper<UserAssets>() |
| | | .eq(UserAssets::getUserId, position.getUserId()) |
| | | .eq(UserAssets::getAccectType, "IN") |
| | | .eq(UserAssets::getAccectType, "MAS") |
| | | ); |
| | | if(userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0){ |
| | | continue; |
| | |
| | | } |
| | | |
| | | |
| | | public ServerResponse createOrder(Integer userId, Integer state, Integer amt, String payChannel) { |
| | | public ServerResponse createOrder(Integer userId, Integer state, Integer amt, String payChannel,String accountType) { |
| | | if (userId == null || state == null || amt == null) { |
| | | return ServerResponse.createByErrorMsg("参数不能为空"); |
| | | } |
| | |
| | | userRecharge.setPayTime(new Date()); |
| | | userRecharge.setOrderStatus(Integer.valueOf(1)); |
| | | userRecharge.setPayId(1); |
| | | userAssetsServices.availablebalanceChange(EStockType.US.getCode(), |
| | | userAssetsServices.availablebalanceChange(EStockType.getEStockTypeByCode(accountType).getCode(), |
| | | userId,EUserAssets.TOP_UP,new BigDecimal(amt),"",""); |
| | | int insertCount = this.userRechargeMapper.insert(userRecharge); |
| | | if (insertCount > 0) { |
| | |
| | | if (user.getIsLogin().intValue() == 1) { |
| | | return ServerResponse.createByErrorMsg("登录失败。账户锁定",request); |
| | | } |
| | | userAssetsServices.assetsByTypeAndUserId(EStockType.US.getCode(),user.getId()); |
| | | userAssetsServices.assetsByTypeAndUserId(EStockType.IN.getCode(),user.getId()); |
| | | userAssetsServices.assetsByTypeAndUserId(EStockType.MAS.getCode(),user.getId()); |
| | | userAssetsServices.assetsByTypeAndUserId(EStockType.SGP.getCode(),user.getId()); |
| | | this.iSiteLoginLogService.saveLog(user, request); |
| | | return ServerResponse.createBySuccess(user); |
| | | } |
| | |
| | | userPositions = userPositionMapper. |
| | | findMyPositionByCodeAndSpell(userId, |
| | | "","", |
| | | 0, "IN"); |
| | | 0, "MAS"); |
| | | |
| | | |
| | | List<UserPositionVO> userPositionVOS = Lists.newArrayList(); |
| | |
| | | |
| | | int insertCount = this.userMapper.insert(user); |
| | | dbUser = userMapper.selectOne(queryWrapper); |
| | | userAssetsServices.getAvailableBalance(EStockType.US.getCode(),dbUser.getId() ); |
| | | userAssetsServices.availablebalanceChange(EStockType.US.getCode(),dbUser.getId(),EUserAssets.TOP_UP,new BigDecimal(amt),"",""); |
| | | userAssetsServices.getAvailableBalance(EStockType.MAS.getCode(),dbUser.getId() ); |
| | | userAssetsServices.getAvailableBalance(EStockType.SGP.getCode(),dbUser.getId() ); |
| | | // userAssetsServices.availablebalanceChange(EStockType.US.getCode(),dbUser.getId(),EUserAssets.TOP_UP,new BigDecimal(amt),"",""); |
| | | if (insertCount > 0) { |
| | | return ServerResponse.createBySuccessMsg("Success"); |
| | | } |
| | |
| | | package com.nq.service.impl; |
| | | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.nq.common.ServerResponse; |
| | | import com.nq.dao.StockSubscribeMapper; |
| | | import com.nq.dao.UserAssetsMapper; |
| | | import com.nq.dao.UserMapper; |
| | | import com.nq.dao.UserStockSubscribeMapper; |
| | | import com.nq.dao.*; |
| | | import com.nq.enums.EStockType; |
| | | import com.nq.enums.EUserAssets; |
| | | import com.nq.pojo.*; |
| | |
| | | @Autowired |
| | | UserAssetsMapper userAssetsMapper; |
| | | |
| | | @Autowired |
| | | StockMapper stockMapper; |
| | | |
| | | /** |
| | | * 用户新股申购 |
| | | * @param model |
| | |
| | | return ServerResponse.createByErrorMsg("参数错误",request); |
| | | } |
| | | User user = iUserService.getCurrentRefreshUser(request); |
| | | UserAssets userAssets = iUserAssetsServices.assetsByTypeAndUserId("IN",user.getId()); |
| | | UserAssets userAssets = iUserAssetsServices.assetsByTypeAndUserId("MAS",user.getId()); |
| | | if (model.getNewCode() != null) { |
| | | StockSubscribe stockSubscribe = stockSubscribeMapper.selectOne(new QueryWrapper<StockSubscribe>() |
| | | .eq("code", model.getNewCode()).eq("type",model.getType())); |
| | |
| | | if (stockSubscribe == null) { |
| | | return ServerResponse.createByErrorMsg("新的股票代码不存在",request); |
| | | } |
| | | if (model.getApplyNums() == null || model.getApplyNums() > stockSubscribe.getOrderNumber()|| model.getApplyNums() < 500) { |
| | | return ServerResponse.createByErrorMsg("最小起订量是500,最大值" |
| | | if (model.getApplyNums() == null || model.getApplyNums() > stockSubscribe.getOrderNumber()) { |
| | | return ServerResponse.createByErrorMsg("最大申购数量:" |
| | | + stockSubscribe.getOrderNumber(),request); |
| | | } |
| | | if(stockSubscribe.getType() == 1){ |
| | |
| | | model.setBond(stockSubscribe.getPrice().multiply(BigDecimal.valueOf(model.getApplyNumber()))); |
| | | model.setDbMoney(model.getDbMoney()); |
| | | //客户中签直接扣除客户账户可用资金 |
| | | UserAssets userAssets = iUserAssetsServices.assetsByTypeAndUserId("IN", userStockSubscribe.getUserId()); |
| | | Stock stock = stockMapper.selectOne(new LambdaQueryWrapper<>(Stock.class).eq(Stock::getStockCode, model.getNewCode())); |
| | | UserAssets userAssets = iUserAssetsServices.assetsByTypeAndUserId(stock.getStockType(), userStockSubscribe.getUserId()); |
| | | if(null == userAssets){ |
| | | return ServerResponse.createByErrorMsg("客户资金账户不存在"); |
| | | } |
| | |
| | | User user = this.userMapper.selectById(userWithdraw.getUserId()); |
| | | |
| | | |
| | | UserAssets userAssets = iUserAssetsServices.assetsByTypeAndUserId("IN", user.getId()); |
| | | UserAssets userAssets = iUserAssetsServices.assetsByTypeAndUserId("MAS", user.getId()); |
| | | if (userAssets == null) { |
| | | return ServerResponse.createByErrorMsg("用户资金账户不存在"); |
| | | } |
| | |
| | | if (user == null) { |
| | | return ServerResponse.createByErrorMsg("用户不存在"); |
| | | } |
| | | UserAssets userAssets = iUserAssetsServices.assetsByTypeAndUserId("IN", user.getId()); |
| | | UserAssets userAssets = iUserAssetsServices.assetsByTypeAndUserId("MAS", user.getId()); |
| | | if (userAssets == null) { |
| | | return ServerResponse.createByErrorMsg("用户资金账户不存在"); |
| | | } |
| | |
| | | private UserPendingorderService pendingorderService; |
| | | |
| | | |
| | | @Scheduled(cron = "0 0/1 * * * ?") |
| | | public void orderTask() { |
| | | pendingorderService.orderTask(); |
| | | } |
| | | // @Scheduled(cron = "0 0/1 * * * ?") |
| | | // public void orderTask() { |
| | | // pendingorderService.orderTask(); |
| | | // } |
| | | } |
| | |
| | | /* |
| | | * 新聞資訊抓取 |
| | | * */ |
| | | @Scheduled(cron = "0 0/5 * * * ?") |
| | | @Scheduled(cron = "0 0/1 * * * ?") |
| | | public void NewsInfoTask() { |
| | | if (NewsInfoTask.get()) { // 判断任务是否在处理中 |
| | | return; |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /* |
| | | * 新聞公告抓取 |
| | | * */ |
| | | // @Scheduled(cron = "0 0/30 9-20 * * ?") |
| | | // public void ArtInfoTask() { |
| | | // this.iSiteArticleService.grabArticle(); |
| | | // } |
| | | } |
| | |
| | | private final AtomicBoolean ballot = new AtomicBoolean(false); |
| | | |
| | | |
| | | @Scheduled(cron = "0 0/10 * * * ?") |
| | | @Scheduled(cron = "0 0/1 * * * ?") |
| | | public void ballot() { |
| | | if (ballot.get()) { // 判断任务是否在处理中 |
| | | return; |
| | |
| | | List<UserStockSubscribe> userStockSubscribes = userStockSubscribeMapper.selectList(new LambdaQueryWrapper<UserStockSubscribe>() |
| | | .eq(UserStockSubscribe::getStatus, 3)); |
| | | userStockSubscribes.forEach(f->{ |
| | | UserAssets userAssets = userAssetsServices.assetsByTypeAndUserId("IN",f.getUserId()); |
| | | UserAssets userAssets = userAssetsServices.assetsByTypeAndUserId("MAS",f.getUserId()); |
| | | if(null != userAssets && userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) == 0){ |
| | | f.setStatus(4); |
| | | userStockSubscribeMapper.updateById(f); |
| | |
| | | |
| | | private static final Logger log = LoggerFactory.getLogger(StockTask.class); |
| | | |
| | | private final AtomicBoolean syncMASStockData = new AtomicBoolean(false); |
| | | |
| | | private final Lock syncMASStockDataLock = new ReentrantLock(); |
| | | |
| | | private final AtomicBoolean syncINStockData = new AtomicBoolean(false); |
| | | private final AtomicBoolean syncSGPStockData = new AtomicBoolean(false); |
| | | |
| | | private final Lock syncINStockDataLock = new ReentrantLock(); |
| | | private final Lock syncSGPStockDataLock = new ReentrantLock(); |
| | | |
| | | /** |
| | | * 同步系统所需要的股票 |
| | | * 同步马来西亚系统所需要的股票 |
| | | */ |
| | | @Scheduled(cron = "0/5 * * * * ?") |
| | | public void syncINStockData() { |
| | | if (syncINStockData.get()) { // 判断任务是否在处理中 |
| | | @Scheduled(cron = "0 0/1 * * * ?") |
| | | public void syncMASStockData() { |
| | | if (syncMASStockData.get()) { // 判断任务是否在处理中 |
| | | return; |
| | | } |
| | | if (syncINStockDataLock.tryLock()) { |
| | | if (syncMASStockDataLock.tryLock()) { |
| | | try { |
| | | syncINStockData.set(true); // 设置处理中标识为true |
| | | loadAllStock(EStockType.IN); |
| | | syncMASStockData.set(true); // 设置处理中标识为true |
| | | loadAllStock(EStockType.MAS); |
| | | } finally { |
| | | syncINStockDataLock.unlock(); |
| | | syncINStockData.set(false); // 设置处理中标识为false |
| | | syncMASStockDataLock.unlock(); |
| | | syncMASStockData.set(false); // 设置处理中标识为false |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 同步美国股票 |
| | | * 新加坡系统所需要的股票 |
| | | */ |
| | | // @Scheduled(cron = "0 0/30 * * * ?") |
| | | public void loadStockCompanies() { |
| | | loadAllCompanies(); |
| | | } |
| | | |
| | | /** |
| | | * 同步美国股票 |
| | | * */ |
| | | @Scheduled(cron = "0/10 * * * * ?") |
| | | public void synsUSStockData(){ |
| | | loadAllStock(EStockType.US); |
| | | public void syncSGPStockData() { |
| | | if (syncSGPStockData.get()) { // 判断任务是否在处理中 |
| | | return; |
| | | } |
| | | if (syncSGPStockDataLock.tryLock()) { |
| | | try { |
| | | syncSGPStockData.set(true); // 设置处理中标识为true |
| | | loadAllStock(EStockType.SGP); |
| | | } finally { |
| | | syncSGPStockDataLock.unlock(); |
| | | syncSGPStockData.set(false); // 设置处理中标识为false |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 加载公司信息 |
| | |
| | | } catch ( |
| | | Exception e) { |
| | | log.error("同步出错", e); |
| | | } |
| | | } |
| | | |
| | | private final AtomicBoolean stockConstraint = new AtomicBoolean(false); |
| | | |
| | | /** |
| | | * 强制平仓 |
| | | */ |
| | | // @Scheduled(cron = "0/1 * * * * ?") |
| | | public void stockConstraint() { |
| | | if (stockConstraint.get()) { // 判断任务是否在处理中 |
| | | return; |
| | | } |
| | | if (stockConstraintLock.tryLock()) { |
| | | try { |
| | | stockConstraint.set(true); // 设置处理中标识为true |
| | | List<UserPosition> userPositions = userPositionMapper.selectList(new LambdaQueryWrapper<UserPosition>().isNull(UserPosition::getSellOrderId)); |
| | | if (CollectionUtils.isNotEmpty(userPositions)) { |
| | | userPositionService.stockConstraint(userPositions); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error("强制平仓任务错误:" + e.getMessage()); |
| | | } finally { |
| | | stockConstraintLock.unlock(); |
| | | stockConstraint.set(false); // 设置处理中标识为false |
| | | } |
| | | } else { |
| | | log.info("强制平仓任务--------->上次任务还未执行完成,本次任务忽略"); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | Map<String, WebSocketClient> retMap = new HashMap<>(2); |
| | | try { |
| | | WebsocketRunClient websocketRunClient = new WebsocketRunClient(new URI(PropertiesUtil.getProperty("US_WS_URL")),EStockType.US); |
| | | WebsocketRunClient websocketRunClient = new WebsocketRunClient(new URI(PropertiesUtil.getProperty("SGP_WS_URL")),EStockType.SGP); |
| | | websocketRunClient.connect(); |
| | | websocketRunClient.setConnectionLostTimeout(0); |
| | | new Thread(() -> { |
| | |
| | | |
| | | Map<String, WebSocketClient> retMap = new HashMap<>(2); |
| | | try { |
| | | WebSocketInClient webSocketInClient = new WebSocketInClient(new URI(PropertiesUtil.getProperty("IN_WS_URL")),EStockType.IN); |
| | | WebSocketInClient webSocketInClient = new WebSocketInClient(new URI(PropertiesUtil.getProperty("MY_WS_URL")),EStockType.MAS); |
| | | webSocketInClient.connect(); |
| | | webSocketInClient.setConnectionLostTimeout(0); |
| | | new Thread(() -> { |
| | |
| | | import com.nq.service.IMandatoryLiquidationService; |
| | | import com.nq.service.impl.MandatoryLiquidationService; |
| | | import com.nq.utils.ApplicationContextRegisterUtil; |
| | | import com.nq.utils.redis.RedisKeyUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.http.HttpResponse; |
| | | import org.apache.http.client.HttpClient; |
| | | import org.apache.http.client.entity.UrlEncodedFormEntity; |
| | | import org.apache.http.client.methods.HttpPost; |
| | | import org.apache.http.impl.client.HttpClients; |
| | | import org.apache.http.message.BasicNameValuePair; |
| | | import org.java_websocket.client.WebSocketClient; |
| | | import org.java_websocket.handshake.ServerHandshake; |
| | | import org.springframework.context.ApplicationContext; |
| | | |
| | | import java.io.IOException; |
| | | import java.lang.reflect.Type; |
| | | import java.net.URI; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | |
| | | **/ |
| | | @Slf4j |
| | | public class WebSocketInClient extends WebSocketClient { |
| | | private static HttpClient httpClient = HttpClients.createDefault(); // 单例化 HttpClient |
| | | |
| | | |
| | | private static HttpPost httpPost; |
| | | static { |
| | | httpPost = new HttpPost("http://127.0.0.1:8001/api/sendNotification"); // 初始化 HttpPost |
| | | } |
| | | |
| | | private EStockType eStockType; |
| | | public WebSocketInClient(URI serverUri, |
| | | EStockType eStockType |
| | |
| | | @Override |
| | | public void onMessage(String s) { |
| | | try { |
| | | ApplicationContext act = ApplicationContextRegisterUtil.getApplicationContext(); |
| | | MandatoryLiquidationService liquidationService = (MandatoryLiquidationService) act.getBean(IMandatoryLiquidationService.class); |
| | | StockRealTimeBean stockDetailBean = new Gson().fromJson(s, StockRealTimeBean.class); |
| | | liquidationService.RealTimeDataProcess(eStockType,stockDetailBean); |
| | | RedisKeyUtil.setCacheRealTimeStock(eStockType,stockDetailBean); |
| | | send(s); |
| | | }catch (Exception e){ |
| | | |
| | | log.error("websocket 马来西亚 错误:"+s); |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void onClose(int i, String s, boolean b) { |
| | | log.info("websocket 印度股票 关闭"+1); |
| | | log.info("websocket 马来西亚 关闭"+1); |
| | | } |
| | | |
| | | @Override |
| | | public void onError(Exception e) { |
| | | log.info("websocket 错误"); |
| | | } |
| | | |
| | | public void send(String message) { |
| | | try { |
| | | // 准备 form-data 参数 |
| | | List<BasicNameValuePair> params = new ArrayList<>(); |
| | | params.add(new BasicNameValuePair("message", message)); |
| | | |
| | | // 设置编码格式为 UTF-8 |
| | | UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, StandardCharsets.UTF_8); |
| | | httpPost.setEntity(entity); // 设置 HttpPost 对象的参数 |
| | | |
| | | // 发送请求 |
| | | HttpResponse response = httpClient.execute(httpPost); |
| | | |
| | | // 处理响应 |
| | | int statusCode = response.getStatusLine().getStatusCode(); |
| | | } catch (IOException e) { |
| | | log.error("Http 请求错误", e); |
| | | } |
| | | } |
| | | } |
| | |
| | | import com.nq.utils.ApplicationContextRegisterUtil; |
| | | import com.nq.utils.redis.RedisKeyUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.http.HttpResponse; |
| | | import org.apache.http.client.HttpClient; |
| | | import org.apache.http.client.entity.UrlEncodedFormEntity; |
| | | import org.apache.http.client.methods.HttpPost; |
| | | import org.apache.http.impl.client.HttpClients; |
| | | import org.apache.http.message.BasicNameValuePair; |
| | | import org.java_websocket.client.WebSocketClient; |
| | | import org.java_websocket.handshake.ServerHandshake; |
| | | import org.springframework.context.ApplicationContext; |
| | | |
| | | import java.io.IOException; |
| | | import java.lang.reflect.Type; |
| | | import java.net.URI; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Slf4j |
| | | public class WebsocketRunClient extends WebSocketClient { |
| | | |
| | | private static HttpClient httpClient = HttpClients.createDefault(); // 单例化 HttpClient |
| | | |
| | | |
| | | private static HttpPost httpPost; |
| | | static { |
| | | httpPost = new HttpPost("http://127.0.0.1:8002/api/sendNotification"); // 初始化 HttpPost |
| | | } |
| | | |
| | | private EStockType eStockType; |
| | | public WebsocketRunClient(URI serverUri, |
| | |
| | | @Override |
| | | public void onMessage(String s) { |
| | | try { |
| | | ApplicationContext act = ApplicationContextRegisterUtil.getApplicationContext(); |
| | | MandatoryLiquidationService liquidationService = (MandatoryLiquidationService) act.getBean(IMandatoryLiquidationService.class); |
| | | StockRealTimeBean stockDetailBean = new Gson().fromJson(s, StockRealTimeBean.class); |
| | | liquidationService.RealTimeDataProcess(eStockType,stockDetailBean); |
| | | RedisKeyUtil.setCacheRealTimeStock(eStockType,stockDetailBean); |
| | | send(s); |
| | | }catch (Exception e){ |
| | | |
| | | log.error("websocket 新加坡 错误:"+s); |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void onClose(int i, String s, boolean b) { |
| | | log.info("websocket 美国股票 关闭"+1); |
| | | log.info("websocket 新加坡 关闭"+1); |
| | | } |
| | | |
| | | @Override |
| | | public void onError(Exception e) { |
| | | log.info("websocket 错误"); |
| | | } |
| | | |
| | | public void send(String message) { |
| | | try { |
| | | // 准备 form-data 参数 |
| | | List<BasicNameValuePair> params = new ArrayList<>(); |
| | | params.add(new BasicNameValuePair("message", message)); |
| | | |
| | | // 设置编码格式为 UTF-8 |
| | | UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, StandardCharsets.UTF_8); |
| | | httpPost.setEntity(entity); // 设置 HttpPost 对象的参数 |
| | | |
| | | // 发送请求 |
| | | HttpResponse response = httpClient.execute(httpPost); |
| | | |
| | | // 处理响应 |
| | | int statusCode = response.getStatusLine().getStatusCode(); |
| | | } catch (IOException e) { |
| | | log.error("Http 请求错误", e); |
| | | } |
| | | } |
| | | } |
| | |
| | | US_WS_URL = ws://ws-us.js-stock.top |
| | | US_KEY = 9sudfjhwdsosdfZyBL4KDa00h |
| | | |
| | | #新加坡股票key的地址 |
| | | SGP_HTTP_API = http://api-sg.js-stock.top/ |
| | | SGP_WS_URL = ws://api-sg-ws.js-stock.top |
| | | SGP_KEY = 7rQvdwEYDvsNFwT8VmE9 |
| | | |
| | | #马来西亚股票key的地址 |
| | | MY_HTTP_API = http://api-my.js-stock.top/ |
| | | MY_WS_URL = ws://api-my-ws.js-stock.top |
| | | MY_KEY = WgPXdkgCexNXNnoMM46v |
| | | |
| | | |
| | | #股票key的地址 |
| | | IN_HTTP_API = https://data.is4vc.com/v1/ |
| | |
| | | datasource: |
| | | type: com.alibaba.druid.pool.DruidDataSource |
| | | driverClassName: com.mysql.cj.jdbc.Driver |
| | | url: jdbc:mysql://127.0.0.1:3306/stock?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 |
| | | url: jdbc:mysql://127.0.0.1:3306/dzh?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 |
| | | # url: jdbc:mysql://127.0.0.1:3306/cgstock?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 |
| | | username: root |
| | | password: 123456 |
| | |
| | | <include refid="Base_Column_List"/> |
| | | FROM stock |
| | | |
| | | where stock_type = #{stockType} |
| | | where 1=1 |
| | | |
| | | <if test="keyWords != null and keyWords != '' "> |
| | | and (stock_spell like concat('%',#{keyWords},'%') or stock_name like concat('%',#{keyWords},'%') ) |
| | |
| | | <if test="stockSpell != null and stockSpell != '' "> |
| | | and stock_spell like CONCAT('%','${stockSpell}','%') |
| | | </if> |
| | | <!-- <if test="stockType != null and stockType!= ''">--> |
| | | <!-- and stock_gid = #{stockType}--> |
| | | <!-- </if>--> |
| | | <if test="stockType != null and stockType!= ''"> |
| | | and stock_gid = #{stockType} |
| | | </if> |
| | | |
| | | |
| | | </where> |