Search in sources :

Example 1 with BusinessException

use of top.longmarch.lmcore.exception.BusinessException in project longmarch by yuyueqty.

the class AppProductServiceImpl method createSign.

@Override
public AppProductApi createSign(String appId, String apiId) {
    AppProduct appProduct = this.getById(appId);
    if (appProduct == null) {
        throw new BusinessException(5000, "无效的appid");
    }
    AppApiInfo appApiInfo = appApiInfoService.getById(apiId);
    if (appApiInfo == null) {
        throw new BusinessException(5000, "无效的apiId");
    }
    AppProductApi productApi = appProductApiService.getOne(new LambdaQueryWrapper<AppProductApi>().eq(AppProductApi::getAppProductId, appId).eq(AppProductApi::getAppApiId, apiId));
    if (productApi == null) {
        throw new BusinessException(5000, "接口未授权");
    }
    // 初始化请求头信息
    SignatureHeaders signatureHeaders = new SignatureHeaders();
    signatureHeaders.setAppid(String.valueOf(appProduct.getAppId()));
    signatureHeaders.setAppSecret(appProduct.getAppSecret());
    signatureHeaders.setNonce(SignatureUtils.generateNonce());
    signatureHeaders.setTimestamp(String.valueOf(System.currentTimeMillis()));
    List<String> pathParams = new ArrayList<>();
    pathParams.add(SignatureUtils.encode(appApiInfo.getUrl(), signatureHeaders.getAppSecret()));
    signatureHeaders.setSignature(SignatureUtils.signature(signatureHeaders, pathParams, null, null));
    productApi.setTimestamp(signatureHeaders.getTimestamp());
    productApi.setNonce(signatureHeaders.getNonce());
    productApi.setSignature(signatureHeaders.getSignature());
    LambdaUpdateWrapper<AppProductApi> wrapper = Wrappers.lambdaUpdate();
    wrapper.set(AppProductApi::getSignature, signatureHeaders.getSignature()).set(AppProductApi::getNonce, signatureHeaders.getNonce()).set(AppProductApi::getTimestamp, signatureHeaders.getTimestamp());
    wrapper.eq(AppProductApi::getAppProductId, appId).eq(AppProductApi::getAppApiId, apiId);
    appProductApiService.update(wrapper);
    return productApi;
}
Also used : BusinessException(top.longmarch.lmcore.exception.BusinessException) AppProductApi(top.longmarch.sign.entity.AppProductApi) ArrayList(java.util.ArrayList) SignatureHeaders(top.longmarch.sign.util.SignatureHeaders) AppProduct(top.longmarch.sign.entity.AppProduct) AppApiInfo(top.longmarch.sign.entity.AppApiInfo)

Example 2 with BusinessException

use of top.longmarch.lmcore.exception.BusinessException in project longmarch by yuyueqty.

the class AppProductServiceImpl method getAppByAppId.

@Override
public AppDTO getAppByAppId(String appId, String uri, String method) {
    AppProduct appProduct = this.getById(appId);
    if (appProduct == null) {
        throw new BusinessException(5000, "无效的appid");
    }
    List<AppApiInfo> appApiInfos = appApiInfoService.list(new LambdaQueryWrapper<AppApiInfo>().eq(AppApiInfo::getUrl, uri).eq(AppApiInfo::getMethod, method));
    if (CollectionUtil.isEmpty(appApiInfos)) {
        throw new BusinessException(5000, "无效的api接口");
    }
    AppApiInfo appApiInfo = appApiInfos.get(0);
    AppProductApi productApi = appProductApiService.getOne(new LambdaQueryWrapper<AppProductApi>().eq(AppProductApi::getAppProductId, appProduct.getAppId()).eq(AppProductApi::getAppApiId, appApiInfo.getId()));
    if (productApi == null) {
        throw new BusinessException(5000, "接口未授权");
    }
    return new AppDTO(appProduct, appApiInfo, productApi);
}
Also used : BusinessException(top.longmarch.lmcore.exception.BusinessException) AppProductApi(top.longmarch.sign.entity.AppProductApi) AppDTO(top.longmarch.sign.dto.AppDTO) AppProduct(top.longmarch.sign.entity.AppProduct) AppApiInfo(top.longmarch.sign.entity.AppApiInfo)

Example 3 with BusinessException

use of top.longmarch.lmcore.exception.BusinessException in project longmarch by yuyueqty.

the class SysTableBodyServiceImpl method show.

@Override
public List<SysTableTitle> show(String code, Map<String, Object> params) {
    SysTableBody sysTableBody = getSysTableBody(code);
    Object dataSource = params.get("dataSource");
    if (dataSource == null) {
        throw new BusinessException(5000, "数据源不能为空");
    }
    String id = String.valueOf(params.get("id"));
    if (StrUtil.isBlank(id)) {
        throw new BusinessException(5000, "数据主键不能为空");
    }
    switchingDataSource(dataSource.toString(), sysTableBody.getDataSource());
    String tableName = sysTableBody.getTableName();
    if (StrUtil.isBlank(tableName)) {
        throw new BusinessException(5000, String.format("%s表名未设置", tableName));
    }
    List<SysTableTitle> titles = sysAutoMapper.columns(tableName);
    String sql = buildShowSql(titles, tableName, id);
    LinkedHashMap<String, Object> titleValueMap = sysAutoMapper.show(sql);
    List<String> strings = null;
    String updateField = sysTableBody.getUpdateField();
    if (StrUtil.isNotBlank(updateField)) {
        strings = Arrays.asList(updateField.split(","));
    }
    for (SysTableTitle title : titles) {
        Object value = titleValueMap.get(title.getField());
        title.setValue(value);
        if (strings != null && strings.size() > 0) {
            title.setIsEdit(strings.contains(title.getField()));
        }
    }
    return titles;
}
Also used : SysTableBody(top.longmarch.lmsys.entity.SysTableBody) BusinessException(top.longmarch.lmcore.exception.BusinessException) SysTableTitle(top.longmarch.lmsys.entity.SysTableTitle)

Example 4 with BusinessException

use of top.longmarch.lmcore.exception.BusinessException in project longmarch by yuyueqty.

the class SysTableBodyServiceImpl method exportData.

@DS("master")
@SuppressWarnings("unchecked")
@Override
public void exportData(String code, String dataSource, Map<String, Object> params, HttpServletResponse response, HttpServletRequest request) {
    SysTableBody sysTableBody = getSysTableBody(code);
    List<SysTableTitle> sysTableTitles = sysTableTitleService.tableTitleList(sysTableBody.getId());
    if (CollectionUtil.isEmpty(sysTableTitles)) {
        throw new BusinessException(5000, "统计SQL未配置字段");
    }
    List<ExcelExportEntity> exportEntityList = sysTableTitles.stream().map(e -> new ExcelExportEntity(e.getLabel(), e.getField())).collect(Collectors.toList());
    Map<String, Object> newParams = PageFactory.buildMap(dataSource, params);
    String cacheKey = getCacheKey(STATISTICS_EXPORT, code, newParams.toString());
    Object data = CacheUtil.get(cacheKey);
    List<LinkedHashMap<String, Object>> mapList = null;
    if (data != null && IS_CACHE) {
        mapList = (List<LinkedHashMap<String, Object>>) data;
    } else {
        try {
            switchingDataSource(dataSource, sysTableBody.getDataSource());
            mapList = sysAutoMapper.list(newParams, sysTableBody.getSqlText());
            if (CollectionUtil.isNotEmpty(mapList)) {
                CacheUtil.put(cacheKey, mapList, TIME_OUT);
            }
        } catch (Exception ignored) {
        // TODO do nothing
        }
    }
    if (mapList != null && mapList.size() > 0) {
        ExportParams exportParams = new ExportParams(sysTableBody.getLabel(), sysTableBody.getLabel());
        exportParams.setType(ExcelType.XSSF);
        Workbook workbook = ExcelExportUtil.exportExcel(exportParams, exportEntityList, mapList);
        DownLoadUtil.downLoad(response, request, workbook, sysTableBody.getCode());
    }
}
Also used : java.util(java.util) ExcelExportUtil(cn.afterturn.easypoi.excel.ExcelExportUtil) ExportParams(cn.afterturn.easypoi.excel.entity.ExportParams) PersistenceException(org.apache.ibatis.exceptions.PersistenceException) BusinessException(top.longmarch.lmcore.exception.BusinessException) PageFactory(top.longmarch.lmcore.common.PageFactory) RequiredArgsConstructor(lombok.RequiredArgsConstructor) TableTitleDTO(top.longmarch.lmsys.dto.TableTitleDTO) SysAutoMapper(top.longmarch.lmsys.mapper.SysAutoMapper) DS(com.baomidou.dynamic.datasource.annotation.DS) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) DynamicRoutingDataSource(com.baomidou.dynamic.datasource.DynamicRoutingDataSource) DownLoadUtil(top.longmarch.lmcore.utils.upload.DownLoadUtil) Function(java.util.function.Function) ISysTableRelService(top.longmarch.lmsys.service.ISysTableRelService) MD5(cn.hutool.crypto.digest.MD5) JSONUtil(cn.hutool.json.JSONUtil) HttpServletRequest(javax.servlet.http.HttpServletRequest) Service(org.springframework.stereotype.Service) TableTitleVO(top.longmarch.lmsys.vo.TableTitleVO) ServiceImpl(com.baomidou.mybatisplus.extension.service.impl.ServiceImpl) Wrappers(com.baomidou.mybatisplus.core.toolkit.Wrappers) ExcelExportEntity(cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity) CollectionUtil(cn.hutool.core.collection.CollectionUtil) SysTableTitle(top.longmarch.lmsys.entity.SysTableTitle) ISysTableTitleService(top.longmarch.lmsys.service.ISysTableTitleService) CacheUtil(top.longmarch.lmcore.cache.CacheUtil) ExcelType(cn.afterturn.easypoi.excel.entity.enmus.ExcelType) HttpServletResponse(javax.servlet.http.HttpServletResponse) ISysTableBodyService(top.longmarch.lmsys.service.ISysTableBodyService) Collectors(java.util.stream.Collectors) SearchSuper(top.longmarch.lmcore.common.SearchSuper) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) StrUtil(cn.hutool.core.util.StrUtil) Slf4j(lombok.extern.slf4j.Slf4j) Workbook(org.apache.poi.ss.usermodel.Workbook) DynamicDataSourceContextHolder(com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder) SysTableRel(top.longmarch.lmsys.entity.SysTableRel) SysTableBodyMapper(top.longmarch.lmsys.mapper.SysTableBodyMapper) Data(lombok.Data) JSONArray(cn.hutool.json.JSONArray) IPage(com.baomidou.mybatisplus.core.metadata.IPage) SysTableBody(top.longmarch.lmsys.entity.SysTableBody) SysTableTitle(top.longmarch.lmsys.entity.SysTableTitle) ExcelExportEntity(cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity) PersistenceException(org.apache.ibatis.exceptions.PersistenceException) BusinessException(top.longmarch.lmcore.exception.BusinessException) Workbook(org.apache.poi.ss.usermodel.Workbook) SysTableBody(top.longmarch.lmsys.entity.SysTableBody) ExportParams(cn.afterturn.easypoi.excel.entity.ExportParams) BusinessException(top.longmarch.lmcore.exception.BusinessException) DS(com.baomidou.dynamic.datasource.annotation.DS)

Example 5 with BusinessException

use of top.longmarch.lmcore.exception.BusinessException in project longmarch by yuyueqty.

the class SysUserServiceImpl method unlock.

@Override
public Boolean unlock(Long userId) {
    SysUser sysUser = getById(userId);
    if (sysUser == null) {
        throw new BusinessException(5000, "账号不存在");
    }
    CacheUtil.remove(String.format(Constant.ACCOUNT_LOGIN_TRY_LOCK, sysUser.getUsername()));
    SysUser sysUserUpdate = new SysUser();
    sysUserUpdate.setId(userId);
    sysUserUpdate.setLockStatus(StatusEnum.YES.getCode());
    return this.updateById(sysUserUpdate);
}
Also used : BusinessException(top.longmarch.lmcore.exception.BusinessException) SysUser(top.longmarch.lmsys.entity.SysUser)

Aggregations

BusinessException (top.longmarch.lmcore.exception.BusinessException)12 SysTableBody (top.longmarch.lmsys.entity.SysTableBody)4 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)3 SysTableTitle (top.longmarch.lmsys.entity.SysTableTitle)3 SysUser (top.longmarch.lmsys.entity.SysUser)3 java.util (java.util)2 Collectors (java.util.stream.Collectors)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 CacheUtil (top.longmarch.lmcore.cache.CacheUtil)2 AppApiInfo (top.longmarch.sign.entity.AppApiInfo)2 AppProduct (top.longmarch.sign.entity.AppProduct)2 AppProductApi (top.longmarch.sign.entity.AppProductApi)2 ExcelExportUtil (cn.afterturn.easypoi.excel.ExcelExportUtil)1 ExportParams (cn.afterturn.easypoi.excel.entity.ExportParams)1 ExcelType (cn.afterturn.easypoi.excel.entity.enmus.ExcelType)1 ExcelExportEntity (cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity)1 CollectionUtil (cn.hutool.core.collection.CollectionUtil)1 StrUtil (cn.hutool.core.util.StrUtil)1 MD5 (cn.hutool.crypto.digest.MD5)1 JSONArray (cn.hutool.json.JSONArray)1