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;
}
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);
}
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;
}
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());
}
}
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);
}
Aggregations