use of com.diboot.core.exception.BusinessException in project diboot by dibo-software.
the class DefaultExceptionHandler method handleException.
/**
* 统一异常处理类
* @param request
* @param e
* @return
*/
@ExceptionHandler(Exception.class)
public Object handleException(HttpServletRequest request, Exception e) {
HttpStatus status = getStatus(request);
Map<String, Object> map;
if (e instanceof BusinessException) {
map = ((BusinessException) e).toMap();
} else if (e.getCause() instanceof BusinessException) {
map = ((BusinessException) e.getCause()).toMap();
} else if (e instanceof InvalidUsageException) {
map = ((InvalidUsageException) e).toMap();
} else if (e.getCause() instanceof InvalidUsageException) {
map = ((InvalidUsageException) e.getCause()).toMap();
} else {
map = new HashMap<>(8);
map.put("code", status.value());
String msg = buildMsg(status, e);
map.put("msg", msg);
}
log.warn("请求处理异常", e);
return new ResponseEntity<>(map, HttpStatus.OK);
}
use of com.diboot.core.exception.BusinessException in project diboot by dibo-software.
the class DictionaryServiceExtImpl method createDictAndChildren.
@Override
@Transactional(rollbackFor = Exception.class)
public boolean createDictAndChildren(DictionaryVO dictVO) {
Dictionary dictionary = dictVO;
dictionary.setIsDeletable(true).setIsEditable(true);
if (!super.createEntity(dictionary)) {
log.warn("新建数据字典定义失败,type=" + dictVO.getType());
return false;
}
List<Dictionary> children = dictVO.getChildren();
this.buildSortId(children);
if (V.notEmpty(children)) {
for (Dictionary dict : children) {
dict.setParentId(dictionary.getId()).setType(dictionary.getType()).setIsDeletable(dictionary.getIsDeletable()).setIsEditable(dictionary.getIsEditable());
}
// 批量保存
boolean success = super.createEntities(children);
if (!success) {
String errorMsg = "新建数据字典子项失败,type=" + dictVO.getType();
log.warn(errorMsg);
throw new BusinessException(Status.FAIL_OPERATION, errorMsg);
}
}
return true;
}
use of com.diboot.core.exception.BusinessException in project diboot by dibo-software.
the class DictionaryServiceExtImpl method updateDictAndChildren.
@Override
@Transactional(rollbackFor = Exception.class)
public boolean updateDictAndChildren(DictionaryVO dictVO) {
Dictionary oldDictionary = super.getEntity(dictVO.getId());
// 将DictionaryVO转化为Dictionary
Dictionary dictionary = dictVO;
dictionary.setIsDeletable(oldDictionary.getIsDeletable()).setIsEditable(oldDictionary.getIsEditable());
if (!super.updateEntity(dictionary)) {
log.warn("更新数据字典定义失败,type=" + dictVO.getType());
return false;
}
// 获取原 子数据字典list
QueryWrapper<Dictionary> queryWrapper = new QueryWrapper();
queryWrapper.lambda().eq(Dictionary::getParentId, dictVO.getId());
List<Dictionary> oldDictList = super.getEntityList(queryWrapper);
List<Dictionary> newDictList = dictVO.getChildren();
Set<Long> dictItemIds = new HashSet<>();
this.buildSortId(newDictList);
if (V.notEmpty(newDictList)) {
for (Dictionary dict : newDictList) {
dict.setType(dictVO.getType()).setParentId(dictVO.getId()).setIsDeletable(dictionary.getIsDeletable()).setIsEditable(dictionary.getIsEditable());
if (V.notEmpty(dict.getId())) {
dictItemIds.add(dict.getId());
if (!super.updateEntity(dict)) {
log.warn("更新字典子项失败,itemName=" + dict.getItemName());
throw new BusinessException(Status.FAIL_EXCEPTION, "更新字典子项异常");
}
} else {
if (!super.createEntity(dict)) {
log.warn("新建字典子项失败,itemName=" + dict.getItemName());
throw new BusinessException(Status.FAIL_EXCEPTION, "新建字典子项异常");
}
}
}
}
if (V.notEmpty(oldDictList)) {
for (Dictionary dict : oldDictList) {
if (!dictItemIds.contains(dict.getId())) {
if (!super.deleteEntity(dict.getId())) {
log.warn("删除子数据字典失败,itemName=" + dict.getItemName());
throw new BusinessException(Status.FAIL_EXCEPTION, "删除字典子项异常");
}
}
}
}
return true;
}
use of com.diboot.core.exception.BusinessException in project diboot by dibo-software.
the class SSOAuthServiceImpl method applyToken.
@Override
public String applyToken(AuthCredential credential) {
BaseJwtAuthToken authToken = initBaseJwtAuthToken(credential);
try {
Subject subject = SecurityUtils.getSubject();
subject.login(authToken);
if (subject.isAuthenticated()) {
log.debug("申请token成功!authtoken={}", authToken.getCredentials());
saveLoginTrace(authToken, true);
// 跳转到首页
return (String) authToken.getCredentials();
} else {
log.error("认证失败");
saveLoginTrace(authToken, false);
throw new BusinessException(Status.FAIL_OPERATION, "认证失败");
}
} catch (Exception e) {
log.error("登录异常", e);
saveLoginTrace(authToken, false);
throw new BusinessException(Status.FAIL_OPERATION, e.getMessage());
}
}
use of com.diboot.core.exception.BusinessException in project diboot by dibo-software.
the class EncryptCredential method getAuthCredential.
/**
* 获取认证信息
*
* @return
*/
public <T extends AuthCredential> T getAuthCredential(IEncryptStrategy encryptor, Class<? extends AuthCredential> authCredentialCls) {
try {
String decryptContent = encryptor.decrypt(ciphertext);
T result = (T) JSON.parseObject(decryptContent, authCredentialCls);
String errMsg = V.validateBeanErrMsg(result);
if (V.notEmpty(errMsg)) {
throw new BusinessException(Status.FAIL_INVALID_PARAM, errMsg);
}
return result;
} catch (Exception e) {
log.error("获取认证信息失败!", e);
throw new BusinessException(e.getMessage());
}
}
Aggregations