Merge branch 'dev' into test
This commit is contained in:
commit
970fbb454d
@ -0,0 +1,9 @@
|
||||
package cn.axzo.nanopart.api.config;
|
||||
|
||||
import cn.axzo.nanopart.api.constant.NanopartConstant;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
||||
@EnableFeignClients(NanopartConstant.BASIC_FEIGN_PACKAGE)
|
||||
public class NanopartApiAutoConfiguration {
|
||||
|
||||
}
|
||||
@ -8,5 +8,7 @@ package cn.axzo.nanopart.api.constant;
|
||||
* @version: 1.0
|
||||
*/
|
||||
public class NanopartConstant {
|
||||
|
||||
public static final String BASIC_FEIGN_PACKAGE = "cn.axzo.nanopart.api";
|
||||
public static final String PHONE_REGEXP = "^1[3456789]\\d{9}$";
|
||||
}
|
||||
@ -17,11 +17,20 @@ import java.util.Map;
|
||||
@Data
|
||||
public class BlackAndWhiteListReq {
|
||||
|
||||
/**
|
||||
* 名单类型,0为黑名单,1为白名单
|
||||
*/
|
||||
@NotNull(message = "名单类型错误")
|
||||
private ListTypeEnum type;
|
||||
|
||||
/**
|
||||
* 模块名,自主定义,例:cms-login
|
||||
*/
|
||||
@NotBlank(message = "模块名不能为空")
|
||||
private String module;
|
||||
|
||||
/**
|
||||
* 限制条件,如:phone:13698745673
|
||||
*/
|
||||
private Map<String,Object> param;
|
||||
}
|
||||
|
||||
@ -0,0 +1,2 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
cn.axzo.nanopart.api.config.NanopartApiAutoConfiguration
|
||||
@ -59,7 +59,8 @@ public class BlackAndWhiteListRepository extends ServiceImpl<BlackAndWhiteListMa
|
||||
QueryWrapper<SaasBlackWhiteList> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("type",req.getType().getValue())
|
||||
.eq(StringUtils.isNotBlank(req.getModule()),"module",req.getModule())
|
||||
.eq("is_delete",0);
|
||||
.eq("is_delete",0)
|
||||
.groupBy("type","param");
|
||||
buildQueryWrapper(queryWrapper, req.getParam(), "");
|
||||
return blackAndWhiteListMapper.selectList(queryWrapper);
|
||||
}
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
package cn.axzo.nanopart.server.service.impl;
|
||||
|
||||
import cn.axzo.basics.common.BeanMapper;
|
||||
import cn.axzo.basics.common.exception.ServiceException;
|
||||
import cn.axzo.framework.domain.web.result.ApiResult;
|
||||
import cn.axzo.nanopart.api.constant.enums.ListTypeEnum;
|
||||
import cn.axzo.nanopart.api.request.BlackAndWhiteListReq;
|
||||
import cn.axzo.nanopart.api.response.BlackAndWhiteListResp;
|
||||
import cn.axzo.nanopart.server.dao.entity.SaasBlackWhiteList;
|
||||
@ -30,18 +32,27 @@ public class BlackAndWhiteListServiceImpl implements BlackAndWhiteListService {
|
||||
|
||||
/**
|
||||
* 新增一条黑白名单记录
|
||||
* @param req 包含module和param两个字段
|
||||
* @param req 包含type,module和param三个字段
|
||||
* @return 记录id
|
||||
*/
|
||||
@Override
|
||||
public ApiResult<Long> create(BlackAndWhiteListReq req) {
|
||||
// 黑白名单创建互斥,若存在于黑名单中则不允许存在于白名单中,反之亦然
|
||||
BlackAndWhiteListReq reverseReq = BeanMapper.copyBean(req, BlackAndWhiteListReq.class, (req1, req2) -> req2.setType((req1.getType().equals(ListTypeEnum.BLACK_LIST)) ? ListTypeEnum.WHITE_LIST : ListTypeEnum.BLACK_LIST));
|
||||
if (isInBlackOrWhiteList(reverseReq).getData()){
|
||||
throw new ServiceException("该记录已存在于"+reverseReq.getType().getDescription()+"中,不能创建对应"+req.getType().getDescription());
|
||||
}
|
||||
// 同类型名单内唯一性校验
|
||||
if (isInBlackOrWhiteList(req).getData()){
|
||||
throw new ServiceException("该记录已存在于"+req.getType().getDescription()+"中");
|
||||
}
|
||||
return ApiResult.ok(blackAndWhiteListRepository.create(req));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定条件的所有黑白名单记录
|
||||
*
|
||||
* @param req 包含module和param两个字段
|
||||
* @param req 包含type,module和param三个字段
|
||||
* @return null
|
||||
*/
|
||||
@Override
|
||||
@ -51,7 +62,7 @@ public class BlackAndWhiteListServiceImpl implements BlackAndWhiteListService {
|
||||
|
||||
/**
|
||||
* 查询指定条件的所有黑白名单记录
|
||||
* @param req 包含module和param两个字段
|
||||
* @param req 包含type,module和param三个字段
|
||||
* @return 记录列表
|
||||
*/
|
||||
@Override
|
||||
@ -63,7 +74,7 @@ public class BlackAndWhiteListServiceImpl implements BlackAndWhiteListService {
|
||||
|
||||
/**
|
||||
* 判断是否存在指定条件的黑白名单记录
|
||||
* @param req 包含module和param两个字段
|
||||
* @param req 包含type,module和param三个字段
|
||||
* @return 记录存在返回true,否则返回false
|
||||
*/
|
||||
@Override
|
||||
|
||||
@ -0,0 +1,56 @@
|
||||
package cn.axzo.nanopart.config.exception;
|
||||
|
||||
import cn.axzo.framework.domain.web.result.ApiResult;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.validation.BindException;
|
||||
import org.springframework.validation.ObjectError;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author: chenwenjian
|
||||
* @date: 2023/8/17 17:04
|
||||
* @description: 统一异常处理
|
||||
* @modifiedBy:
|
||||
* @version: 1.0
|
||||
*/
|
||||
@Slf4j
|
||||
@Order(value = 0)
|
||||
@RestControllerAdvice
|
||||
public class ExceptionAdviceHandler {
|
||||
|
||||
@ExceptionHandler(cn.axzo.basics.common.exception.ServiceException.class)
|
||||
public ApiResult<Void> basicsServiceExceptionHandler(cn.axzo.basics.common.exception.ServiceException e) {
|
||||
log.warn("业务异常", e);
|
||||
return ApiResult.err(e.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionHandler(cn.axzo.core.service.ServiceException.class)
|
||||
public ApiResult<Void> coreServiceExceptionHandler(cn.axzo.core.service.ServiceException e) {
|
||||
log.warn("业务异常", e);
|
||||
return ApiResult.err(e.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionHandler(cn.axzo.framework.domain.ServiceException.class)
|
||||
public ApiResult<Void> domainServiceExceptionHandler(cn.axzo.framework.domain.ServiceException e){
|
||||
log.warn("业务异常", e);
|
||||
return ApiResult.err(e.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionHandler(BindException.class)
|
||||
public ApiResult<Void> bindExceptionHandler(BindException e) {
|
||||
log.warn("业务异常", e);
|
||||
List<ObjectError> allErrors = e.getBindingResult().getAllErrors();
|
||||
if (CollectionUtils.isEmpty(allErrors)) {
|
||||
return ApiResult.err("操作失败 请联系系统管理员");
|
||||
}
|
||||
ObjectError objectError = allErrors.get(0);
|
||||
String objectErrorDefaultMessage = objectError.getDefaultMessage();
|
||||
return ApiResult.err(objectErrorDefaultMessage);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user