Search in sources :

Example 6 with BizException

use of com.albedo.java.common.core.exception.BizException in project albedo by somowhere.

the class AliPayServiceImpl method toPayAsPc.

@Override
public String toPayAsPc(AlipayConfigDo alipay, TradeVo trade) throws Exception {
    ArgumentAssert.notNull(alipay.getId(), () -> new BizException("请先添加相应配置,再操作"));
    AlipayClient alipayClient = new DefaultAlipayClient(alipay.getGatewayUrl(), alipay.getAppId(), alipay.getPrivateKey(), alipay.getFormat(), alipay.getCharset(), alipay.getPublicKey(), alipay.getSignType());
    // 创建API对应的request(电脑网页版)
    AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
    // 订单完成后返回的页面和异步通知地址
    request.setReturnUrl(alipay.getReturnUrl());
    request.setNotifyUrl(alipay.getNotifyUrl());
    // 填充订单参数
    request.setBizContent("{" + "    \"out_trade_no\":\"" + trade.getOutTradeNo() + "\"," + "    \"product_code\":\"FAST_INSTANT_TRADE_PAY\"," + "    \"total_amount\":" + trade.getTotalAmount() + "," + "    \"subject\":\"" + trade.getSubject() + "\"," + "    \"body\":\"" + trade.getBody() + "\"," + "    \"extend_params\":{" + "    \"sys_service_provider_id\":\"" + alipay.getSysServiceProviderId() + "\"" + "    }" + // 填充业务参数
    "  }");
    // 调用SDK生成表单, 通过GET方式,口可以获取url
    return alipayClient.pageExecute(request, "GET").getBody();
}
Also used : BizException(com.albedo.java.common.core.exception.BizException) DefaultAlipayClient(com.alipay.api.DefaultAlipayClient) AlipayClient(com.alipay.api.AlipayClient) DefaultAlipayClient(com.alipay.api.DefaultAlipayClient) AlipayTradePagePayRequest(com.alipay.api.request.AlipayTradePagePayRequest)

Example 7 with BizException

use of com.albedo.java.common.core.exception.BizException in project albedo by somowhere.

the class WebUtil method getClientId.

/**
 * 从request 获取CLIENT_ID
 *
 * @return
 */
@SneakyThrows
public String[] getClientId(ServerHttpRequest request) {
    String header = request.getHeaders().getFirst(HttpHeaders.AUTHORIZATION);
    if (header == null || !header.startsWith(CommonConstants.BASIC_)) {
        throw new BizException("请求头中client信息为空");
    }
    byte[] base64Token = header.substring(6).getBytes(StandardCharsets.UTF_8);
    byte[] decoded;
    try {
        decoded = Base64.decode(base64Token);
    } catch (IllegalArgumentException e) {
        throw new BizException("Failed to decode basic authentication token");
    }
    String token = new String(decoded, StandardCharsets.UTF_8);
    int delim = token.indexOf(":");
    if (delim == -1) {
        throw new BizException("Invalid basic authentication token");
    }
    return new String[] { token.substring(0, delim), token.substring(delim + 1) };
}
Also used : BizException(com.albedo.java.common.core.exception.BizException) SneakyThrows(lombok.SneakyThrows)

Example 8 with BizException

use of com.albedo.java.common.core.exception.BizException in project albedo by somowhere.

the class SchemeServiceImpl method previewCode.

@Override
public Map<String, Object> previewCode(String id, String username) {
    Map<String, Object> result = Maps.newHashMap();
    SchemeDto schemeDto = super.getOneDto(id);
    // 查询主表及字段列
    TableDto tableDto = tableService.getOneDto(schemeDto.getTableId());
    ArgumentAssert.notNull(tableDto, "无法找到业务表ID为" + id + "的数据");
    tableDto.setColumnList(Optional.ofNullable(tableColumnService.list(Wrappers.<TableColumnDo>query().eq(TableColumnDo.F_SQL_GENTABLEID, tableDto.getId()))).orElseThrow(() -> new BizException("业务列信息不存在")).stream().map(item -> tableColumnService.copyBeanToDto(item)).collect(Collectors.toList()));
    Collections.sort(tableDto.getColumnList());
    // 获取所有代码模板
    GenConfig config = GenUtil.getConfig();
    // 获取模板列表
    List<TemplateVo> templateList = GenUtil.getTemplateList(config, schemeDto.getCategory(), false);
    List<TemplateVo> childTableTemplateList = GenUtil.getTemplateList(config, schemeDto.getCategory(), true);
    // 如果有子表模板,则需要获取子表列表
    if (childTableTemplateList.size() > 0) {
        tableDto.setChildList(Optional.ofNullable(tableRepository.selectList(Wrappers.<TableDo>lambdaQuery().eq(TableDo::getParentTable, tableDto.getId()))).orElseThrow(() -> new BizException("业务表不存在")).stream().map(item -> tableService.copyBeanToDto(item)).collect(Collectors.toList()));
    }
    // 生成子表模板代码
    if (tableDto.getChildList() == null) {
        tableDto.setChildList(Lists.newArrayList());
    }
    for (TableDto childTable : tableDto.getChildList()) {
        Collections.sort(childTable.getColumnList());
        childTable.setCategory(schemeDto.getCategory());
        schemeDto.setTableDto(childTable);
        Map<String, Object> childTableModel = GenUtil.getDataModel(schemeDto);
        for (TemplateVo tpl : childTableTemplateList) {
            String content = FreeMarkers.renderString(StringUtil.trimToEmpty(tpl.getContent()), childTableModel);
            result.put(FreeMarkers.renderString(tpl.getFileName(), childTableModel), content);
        }
    }
    tableDto.setCategory(schemeDto.getCategory());
    // 生成主表模板代码
    schemeDto.setTableDto(tableDto);
    Map<String, Object> model = GenUtil.getDataModel(schemeDto);
    for (TemplateVo tpl : templateList) {
        String content = FreeMarkers.renderString(StringUtil.trimToEmpty(tpl.getContent()), model);
        result.put(FreeMarkers.renderString(tpl.getFileName(), model), content);
    }
    return result;
}
Also used : TableDo(com.albedo.java.modules.gen.domain.TableDo) GenConfig(com.albedo.java.modules.gen.domain.xml.GenConfig) BizException(com.albedo.java.common.core.exception.BizException) TableColumnDo(com.albedo.java.modules.gen.domain.TableColumnDo) TemplateVo(com.albedo.java.modules.gen.domain.vo.TemplateVo) TableDto(com.albedo.java.modules.gen.domain.dto.TableDto) SchemeDto(com.albedo.java.modules.gen.domain.dto.SchemeDto)

Example 9 with BizException

use of com.albedo.java.common.core.exception.BizException in project albedo by somowhere.

the class LocalFileChunkStrategyImpl method copyFile.

@Override
protected void copyFile(File file) {
    String inputFile = Paths.get(fileProperties.getLocal().getStoragePath(), file.getPath()).toString();
    String filename = randomFileName(file.getUniqueFileName());
    String outputFile = Paths.get(fileProperties.getLocal().getStoragePath(), StrUtil.subBefore(file.getPath(), "/" + file.getUniqueFileName(), true), filename).toString();
    try {
        FileUtil.copy(inputFile, outputFile, true);
    } catch (IORuntimeException e) {
        log.error("复制文件异常", e);
        throw new BizException("复制文件异常");
    }
    file.setUniqueFileName(filename);
    String url = file.getUrl();
    String newUrl = StrUtil.subPre(url, StrUtil.lastIndexOfIgnoreCase(url, StrPool.SLASH) + 1);
    file.setUrl(newUrl + filename);
}
Also used : IORuntimeException(cn.hutool.core.io.IORuntimeException) BizException(com.albedo.java.common.core.exception.BizException)

Example 10 with BizException

use of com.albedo.java.common.core.exception.BizException in project albedo by somowhere.

the class ZipUtils method zipFilesByInputStream.

public static void zipFilesByInputStream(Map<String, String> fileMap, Long fileSize, String extName, HttpServletRequest request, HttpServletResponse response) throws Exception {
    HttpURLConnection connection = null;
    response.setContentType("application/octet-stream; charset=utf-8");
    String downloadFileName;
    String agent = request.getHeader("USER-AGENT");
    if (agent != null && agent.toLowerCase().indexOf(AGENT_FIREFOX) > 0) {
        downloadFileName = "=?UTF-8?B?" + (new String(Base64.encodeBase64((extName).getBytes(StandardCharsets.UTF_8)))) + "?=";
    } else {
        // ~ \ / |:"<>?   这些字符不能被替换,因为系统允许文件名有这些字符!!
        downloadFileName = URLEncoder.encode(extName, "UTF-8").replaceAll("\\+", "%20").replaceAll("%28", "\\(").replaceAll("%29", "\\)").replaceAll("%3B", StrPool.SEMICOLON).replaceAll("%40", StrPool.AT).replaceAll("%23", "\\#").replaceAll("%26", "\\&").replaceAll("%2C", "\\,").replaceAll("%2B", StrPool.PLUS).replaceAll("%25", StrPool.PERCENT).replaceAll("%21", StrPool.EXCLAMATION_MARK).replaceAll("%5E", StrPool.HAT).replaceAll("%24", "\\$").replaceAll("%7E", StrPool.TILDA).replaceAll("%60", StrPool.BACKTICK).replaceAll("%5B", StrPool.LEFT_SQ_BRACKET).replaceAll("%3D", StrPool.EQUALS).replaceAll("%5D", StrPool.RIGHT_SQ_BRACKET).replaceAll("%5C", "\\\\").replaceAll("%27", StrPool.SINGLE_QUOTE).replaceAll("%2F", StrPool.SLASH).replaceAll("%7B", StrPool.LEFT_BRACE).replaceAll("%7D", StrPool.RIGHT_BRACE).replaceAll("%7C", "\\|").replaceAll("%3A", "\\:").replaceAll("%22", "\\\"").replaceAll("%3C", "\\<").replaceAll("%3E", "\\>").replaceAll("%3F", "\\?");
        log.info("downloadFileName={}", downloadFileName);
    }
    response.setHeader("Content-Disposition", "attachment;fileName=" + downloadFileName);
    // 加了这个下载会报错?
    // if (fileSize != null && fileSize > 0) {
    // response.setHeader("Content-Length", String.valueOf(fileSize));
    // }
    ServletOutputStream out = response.getOutputStream();
    if (fileMap.size() == 1) {
        String url = null;
        for (Map.Entry<String, String> entry : fileMap.entrySet()) {
            url = entry.getValue();
        }
        try {
            connection = getConnection(url);
            ZipUtils.downloadFile(connection.getInputStream(), out);
        } catch (Exception e) {
            throw new BizException("文件地址连接超时", e);
        }
        return;
    }
    try (ZipOutputStream zos = new ZipOutputStream(out);
        BufferedOutputStream bos = new BufferedOutputStream(zos)) {
        for (Map.Entry<String, String> entry : fileMap.entrySet()) {
            String fileName = entry.getKey();
            String url = entry.getValue();
            BufferedInputStream bis = null;
            try {
                connection = getConnection(url);
                bis = new BufferedInputStream(connection.getInputStream());
                zos.putNextEntry(new ZipEntry(fileName));
                int len;
                byte[] buf = new byte[10 * 1024];
                while ((len = bis.read(buf, 0, buf.length)) != -1) {
                    bos.write(buf, 0, len);
                }
                bos.flush();
            } catch (Exception e) {
                log.warn("打包下载多个文件异常, fileName=" + fileName + ",url=" + url, e);
            } finally {
                if (connection != null) {
                    connection.disconnect();
                }
                if (bis != null) {
                    bis.close();
                }
                zos.closeEntry();
            }
        }
    }
}
Also used : ServletOutputStream(javax.servlet.ServletOutputStream) BizException(com.albedo.java.common.core.exception.BizException) ZipEntry(java.util.zip.ZipEntry) BizException(com.albedo.java.common.core.exception.BizException) HttpURLConnection(java.net.HttpURLConnection) ZipOutputStream(java.util.zip.ZipOutputStream) Map(java.util.Map)

Aggregations

BizException (com.albedo.java.common.core.exception.BizException)22 UserDo (com.albedo.java.modules.sys.domain.UserDo)3 SneakyThrows (lombok.SneakyThrows)3 RoleDo (com.albedo.java.modules.sys.domain.RoleDo)2 AlipayClient (com.alipay.api.AlipayClient)2 DefaultAlipayClient (com.alipay.api.DefaultAlipayClient)2 IORuntimeException (cn.hutool.core.io.IORuntimeException)1 TableColumnDo (com.albedo.java.modules.gen.domain.TableColumnDo)1 TableDo (com.albedo.java.modules.gen.domain.TableDo)1 SchemeDto (com.albedo.java.modules.gen.domain.dto.SchemeDto)1 TableDto (com.albedo.java.modules.gen.domain.dto.TableDto)1 TemplateVo (com.albedo.java.modules.gen.domain.vo.TemplateVo)1 GenConfig (com.albedo.java.modules.gen.domain.xml.GenConfig)1 Job (com.albedo.java.modules.quartz.domain.Job)1 DictCacheKeyBuilder (com.albedo.java.modules.sys.cache.DictCacheKeyBuilder)1 DeptDo (com.albedo.java.modules.sys.domain.DeptDo)1 DictDo (com.albedo.java.modules.sys.domain.DictDo)1 LogOperateDo (com.albedo.java.modules.sys.domain.LogOperateDo)1 MenuDo (com.albedo.java.modules.sys.domain.MenuDo)1 RoleMenuDo (com.albedo.java.modules.sys.domain.RoleMenuDo)1