新版仿ok交易所-后端
1
zj
8 hours ago be8c9767089b5e52ed462ea1d083d846e7420a45
trading-order-admin/src/main/java/com/yami/trading/api/controller/exchange/ApiChannelBlockchainController.java
@@ -85,33 +85,12 @@
     */
    @RequestMapping(action + "list.action")
    public Object list() throws IOException {
        List<ChannelBlockchain> data = new ArrayList<ChannelBlockchain>();
        String partyId = SecurityUtils.getUser().getUserId();
        User party = userService.getById(partyId);
        List<PartyBlockchain> list = partyBlockchainService.findByUserName(party.getUserName());
        if (null != list && !list.isEmpty()) {
            data = list.stream().map(dict -> {
                String qrImage = dict.getQrImage();
                String chainAddress = dict.getAddress();
                String chainName = dict.getChainName();
                String coinSymbol = dict.getCoinSymbol();
                String autoStr = dict.getAuto();
                boolean auto = autoStr.equals("Y") ? true : false;
                ChannelBlockchain cbc = new ChannelBlockchain();
                cbc.setBlockchainName(chainName);
                cbc.setBlockchain_name(chainName);
                cbc.setAddress(chainAddress);
                cbc.setCoin(coinSymbol);
                cbc.setAuto(auto);
                cbc.setImg(qrImage);
                return cbc;
            }).collect(Collectors.toList());
        }
        if (data.isEmpty()) data = channelBlockchainService.list();
        List<ChannelBlockchain> data = buildAddressList(party, null);
        for (int i = 0; i < data.size(); i++) {
            data.get(i).setBlockchain_name(data.get(i).getBlockchainName());
            if (1 == this.sysparaService.find("can_recharge").getInteger()) {
                // 允许在线充值,展示二维码
                if (!StringUtils.isNullOrEmpty(data.get(i).getImg())) {
                    String path = Constants.WEB_URL + "/public/showimg!showImg.action?imagePath=" + data.get(i).getImg();
                    data.get(i).setImg(path);
@@ -127,31 +106,12 @@
    @GetMapping(action + "getBlockchainName.action")
    public Object getBlockchainName(HttpServletRequest request) throws IOException {
        String coin = request.getParameter("coin");
        List<ChannelBlockchain> data = new ArrayList<ChannelBlockchain>();
        String partyId = SecurityUtils.getUser().getUserId();
        User party = userService.getById(partyId);
        if (0 == this.sysparaService.find("can_recharge").getInteger()) {
            return Result.failed("请联系客服充值");
        }
        List<PartyBlockchain> list = partyBlockchainService.findByUserNameAndCoinSymbol(party.getUserName(), coin);
        if (null != list && !list.isEmpty()) {
            data = list.stream().map(dict -> {
                String qrImage = dict.getQrImage();
                String chainAddress = dict.getAddress();
                String chainName = dict.getChainName();
                String coinSymbol = dict.getCoinSymbol();
                String autoStr = dict.getAuto();
                boolean auto = autoStr.equals("Y") ? true : false;
                ChannelBlockchain cbc = new ChannelBlockchain();
                cbc.setBlockchain_name(chainName);
                cbc.setAddress(chainAddress);
                cbc.setCoin(coinSymbol);
                cbc.setAuto(auto);
                cbc.setImg(qrImage);
                return cbc;
            }).collect(Collectors.toList());
        }
        if (data.isEmpty()) data = this.channelBlockchainService.findByCoin(coin.toLowerCase());
        List<ChannelBlockchain> data = buildAddressList(party, coin);
        for (int i = 0; i < data.size(); i++) {
            data.get(i).setBlockchain_name(data.get(i).getBlockchainName());
            if (1 == this.sysparaService.find("can_recharge").getInteger()) {
@@ -160,8 +120,6 @@
                    config.setMargin(3);
                    String qr = QrCodeUtil.generateAsBase64(data.get(i).getAddress(), config, "png");
                    data.get(i).setImgStr(qr);
//                    data.get(i).setImgStr("/public/showimg!showImg.action?imagePath=" + data.get(i).getImg());
//                    data.get(i).setImg(path);
                }
            } else {
                data.get(i).setImg(null);
@@ -170,6 +128,35 @@
            }
        }
        return Result.succeed(data);
    }
    private List<ChannelBlockchain> buildAddressList(User party, String coin) {
        List<ChannelBlockchain> templates = StringUtils.isNullOrEmpty(coin)
                ? channelBlockchainService.list()
                : channelBlockchainService.findByCoin(coin.toLowerCase());
        List<PartyBlockchain> partyList = StringUtils.isNullOrEmpty(coin)
                ? partyBlockchainService.findByUserName(party.getUserName())
                : partyBlockchainService.findByUserNameAndCoinSymbol(party.getUserName(), coin);
        Map<String, String> customAddresses = new HashMap<>();
        for (PartyBlockchain pb : partyList) {
            customAddresses.put(addressKey(pb.getCoinSymbol(), pb.getChainName()), pb.getAddress());
        }
        return templates.stream().map(template -> {
            ChannelBlockchain cbc = new ChannelBlockchain();
            cbc.setUuid(template.getUuid());
            cbc.setCoin(template.getCoin());
            cbc.setBlockchainName(template.getBlockchainName());
            cbc.setBlockchain_name(template.getBlockchainName());
            cbc.setAuto(template.isAuto());
            cbc.setImg(template.getImg());
            String key = addressKey(template.getCoin(), template.getBlockchainName());
            cbc.setAddress(customAddresses.getOrDefault(key, template.getAddress()));
            return cbc;
        }).collect(Collectors.toList());
    }
    private String addressKey(String coin, String chain) {
        return (coin == null ? "" : coin.toLowerCase()) + "|" + (chain == null ? "" : chain.toLowerCase());
    }
    /**
@@ -423,7 +410,7 @@
            Response response = okHttpClient.newCall(requestParm).execute();
            result = response.body().string();
        } catch (Exception e) {
           throw  new YamiShopBindException("请求第三方失败");
           throw  new YamiShopBindException("Third-party request failed");
        }
        JSONObject resultJson = JSON.parseObject(result);
        Integer code = resultJson.getInteger("code");