Merge branch 'feature/REQ-1040' into 'master'
Feature/req 1040 See merge request universal/infrastructure/backend/nanopart!1
This commit is contained in:
commit
c2224ae4d5
1
.gitattibutes
Normal file
1
.gitattibutes
Normal file
@ -0,0 +1 @@
|
||||
nanopart-server/src/main/resources/bootstrap.yml merge=ours
|
||||
39
.gitignore
vendored
Normal file
39
.gitignore
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
HELP.md
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
application-local.yml
|
||||
*.log
|
||||
|
||||
rebel.xml
|
||||
.flattened-pom.xml
|
||||
3
Dockerfile
Normal file
3
Dockerfile
Normal file
@ -0,0 +1,3 @@
|
||||
FROM registry.cn-hangzhou.aliyuncs.com/axzo-k8s/jdk1.8-fc:v1
|
||||
COPY nanopart-server/target/nanopart-server.jar ./nanopart-server.jar
|
||||
ENTRYPOINT [{ENTRYPOINT}]
|
||||
19
README.md
19
README.md
@ -0,0 +1,19 @@
|
||||
# 项目介绍
|
||||
一个通用的聚合服务:通用黑名单服务
|
||||
|
||||
# vm参数
|
||||
## dev环境
|
||||
-Dspring.datasource.url=jdbc:mysql://116.63.13.181:3311/pudge-dev?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&serverTimezone=Asia/Shanghai&useSSL=true&verifyServerCertificate=false&rewriteBatchedStatements=true
|
||||
-Dspring.redis.host=123.249.44.111
|
||||
-Dspring.redis.port=31270
|
||||
-Dspring.redis.password=Kjgnj93JKj3je
|
||||
-DCUSTOM_ENV=dev
|
||||
-Dserver.port=8080
|
||||
|
||||
## test环境
|
||||
-Dspring.datasource.url=jdbc:mysql://124.70.43.174:3306/pudge?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&serverTimezone=Asia/Shanghai&useSSL=true&verifyServerCertificate=false&rewriteBatchedStatements=true
|
||||
-Dspring.redis.host=123.249.44.111
|
||||
-Dspring.redis.port=31276
|
||||
-Dspring.redis.password=Kjgnj93JKj3je
|
||||
-DCUSTOM_ENV=test
|
||||
-Dserver.port=8080
|
||||
2
RELEASE.md
Normal file
2
RELEASE.md
Normal file
@ -0,0 +1,2 @@
|
||||
# 发布记录
|
||||
|
||||
26
black-list/black-list-api/pom.xml
Normal file
26
black-list/black-list-api/pom.xml
Normal file
@ -0,0 +1,26 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>cn.axzo.nanopart</groupId>
|
||||
<artifactId>black-list</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>black-list-api</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>black-list-api</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-openfeign-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.axzo.framework</groupId>
|
||||
<artifactId>axzo-common-domain</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@ -0,0 +1,55 @@
|
||||
package cn.axzo.nanopart.api;
|
||||
|
||||
import cn.axzo.framework.domain.web.result.ApiResult;
|
||||
import cn.axzo.nanopart.api.request.BlackAndWhiteListReq;
|
||||
import cn.axzo.nanopart.api.response.BlackAndWhiteListResp;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author: chenwenjian
|
||||
* @date: 2023/8/11 16:28
|
||||
* @description: 黑白名单api
|
||||
* @modifiedBy:
|
||||
* @version: 1.0
|
||||
*/
|
||||
@FeignClient(name = "nanopart", url = "http://nanopart:8080")
|
||||
public interface BlackAndWhiteListApi {
|
||||
|
||||
/**
|
||||
* 创建黑名单或白名单
|
||||
* @param req 包含type,module,params三个字段
|
||||
* @return 记录id
|
||||
*/
|
||||
@PostMapping("api/black-white-list/create")
|
||||
ApiResult<Long> create(@RequestBody @Validated BlackAndWhiteListReq req);
|
||||
|
||||
/**
|
||||
* 删除黑名单或白名单
|
||||
* @param req 包含type,module,params三个字段
|
||||
* @return void
|
||||
*/
|
||||
@PostMapping("api/black-white-list/delete")
|
||||
ApiResult<Void> delete(@RequestBody @Validated BlackAndWhiteListReq req);
|
||||
|
||||
/**
|
||||
* 查询黑名单或白名单
|
||||
* @param req 包含type,module,params三个字段
|
||||
* @return 黑白名单记录列表
|
||||
*/
|
||||
@PostMapping("api/black-white-list/query")
|
||||
ApiResult<List<BlackAndWhiteListResp>> detail(@RequestBody @Validated BlackAndWhiteListReq req);
|
||||
|
||||
/**
|
||||
* 判断指定模块、指定参数记录是否在黑名单或白名单中
|
||||
* @param req 包含type,module,params三个字段
|
||||
* @return 若记录存在则返回true,否则返回false
|
||||
*/
|
||||
@PostMapping("api/black-white-list/is-in")
|
||||
ApiResult<Boolean> isInBlackOrWhiteList(@RequestBody @Validated BlackAndWhiteListReq req);
|
||||
|
||||
}
|
||||
@ -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 {
|
||||
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
package cn.axzo.nanopart.api.constant;
|
||||
|
||||
/**
|
||||
* @author: chenwenjian
|
||||
* @date: 2023/8/14 9:38
|
||||
* @description:
|
||||
* @modifiedBy:
|
||||
* @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}$";
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
package cn.axzo.nanopart.api.constant.enums;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author: chenwenjian
|
||||
* @date: 2023/8/17 14:17
|
||||
* @description: 名单类型枚举
|
||||
* @modifiedBy:
|
||||
* @version: 1.0
|
||||
*/
|
||||
public enum ListTypeEnum {
|
||||
|
||||
/**
|
||||
* 黑名单
|
||||
*/
|
||||
BLACK_LIST(0,"黑名单"),
|
||||
/**
|
||||
* 白名单
|
||||
*/
|
||||
WHITE_LIST(1,"白名单");
|
||||
|
||||
private final Integer value;
|
||||
private final String description;
|
||||
|
||||
public Integer getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
ListTypeEnum(Integer value, String description) {
|
||||
this.value = value;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public static ListTypeEnum getByType(Integer value){
|
||||
return Arrays.stream(values()).filter(l -> l.getValue().equals(value)).findFirst().orElse(null);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
package cn.axzo.nanopart.api.request;
|
||||
|
||||
|
||||
import cn.axzo.nanopart.api.constant.NanopartConstant;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Pattern;
|
||||
|
||||
|
||||
/**
|
||||
* @author: chenwenjian
|
||||
* @date: 2023/8/14 17:23
|
||||
* @description:
|
||||
* @modifiedBy:
|
||||
* @version: 1.0
|
||||
*/
|
||||
@Data
|
||||
public class BlackAndWhiteListInReq {
|
||||
|
||||
@NotBlank(message = "模块名称不能为空格")
|
||||
private String module;
|
||||
|
||||
@Pattern(regexp = NanopartConstant.PHONE_REGEXP,message = "手机号格式错误")
|
||||
private String phone;
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
package cn.axzo.nanopart.api.request;
|
||||
|
||||
import cn.axzo.nanopart.api.constant.enums.ListTypeEnum;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author: chenwenjian
|
||||
* @date: 2023/8/11 16:40
|
||||
* @description:
|
||||
* @modifiedBy:
|
||||
* @version: 1.0
|
||||
*/
|
||||
@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,37 @@
|
||||
package cn.axzo.nanopart.api.response;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author: chenwenjian
|
||||
* @date: 2023/8/11 16:49
|
||||
* @description:
|
||||
* @modifiedBy:
|
||||
* @version: 1.0
|
||||
*/
|
||||
@Data
|
||||
public class BlackAndWhiteListResp {
|
||||
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 模块名
|
||||
*/
|
||||
private String module;
|
||||
|
||||
/**
|
||||
* 参数
|
||||
*/
|
||||
private Map<String,Object> param;
|
||||
|
||||
private Date createAt;
|
||||
|
||||
private Date updateAt;
|
||||
|
||||
private Long createBy;
|
||||
|
||||
private Long updateBy;
|
||||
}
|
||||
@ -0,0 +1,2 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
cn.axzo.nanopart.api.config.NanopartApiAutoConfiguration
|
||||
37
black-list/black-list-service/pom.xml
Normal file
37
black-list/black-list-service/pom.xml
Normal file
@ -0,0 +1,37 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>cn.axzo.nanopart</groupId>
|
||||
<artifactId>black-list</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>black-list-service</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>black-list-service</name>
|
||||
|
||||
<dependencies>
|
||||
<!--mybatis-plus-->
|
||||
<dependency>
|
||||
<groupId>cn.axzo.framework</groupId>
|
||||
<artifactId>axzo-mybatisplus-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<!-- druid -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.axzo.basics</groupId>
|
||||
<artifactId>basics-common</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.axzo.nanopart</groupId>
|
||||
<artifactId>black-list-api</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@ -0,0 +1,23 @@
|
||||
package cn.axzo.nanopart.server.config;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author: chenwenjian
|
||||
* @date: 2023/8/15 17:49
|
||||
* @description:
|
||||
* @modifiedBy:
|
||||
* @version: 1.0
|
||||
*/
|
||||
@Configuration
|
||||
public class MybatisPlusConfig {
|
||||
|
||||
@Bean
|
||||
public JacksonTypeHandler getJacksonTypeHandler(){
|
||||
return new JacksonTypeHandler(Map.class);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
package cn.axzo.nanopart.server.controller;
|
||||
|
||||
|
||||
import cn.axzo.framework.domain.web.result.ApiResult;
|
||||
import cn.axzo.nanopart.api.BlackAndWhiteListApi;
|
||||
import cn.axzo.nanopart.api.request.BlackAndWhiteListReq;
|
||||
import cn.axzo.nanopart.api.response.BlackAndWhiteListResp;
|
||||
import cn.axzo.nanopart.server.service.BlackAndWhiteListService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author: chenwenjian
|
||||
* @date: 2023/8/11 17:59
|
||||
* @description:
|
||||
* @modifiedBy:
|
||||
* @version: 1.0`
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class BlackAndWhiteListController implements BlackAndWhiteListApi {
|
||||
|
||||
private final BlackAndWhiteListService blackAndWhiteListService;
|
||||
@Override
|
||||
public ApiResult<Long> create(BlackAndWhiteListReq req) {
|
||||
return blackAndWhiteListService.create(req);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResult<Void> delete(BlackAndWhiteListReq req) {
|
||||
return blackAndWhiteListService.delete(req);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResult<List<BlackAndWhiteListResp>> detail(BlackAndWhiteListReq req) {
|
||||
return blackAndWhiteListService.detail(req);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResult<Boolean> isInBlackOrWhiteList(BlackAndWhiteListReq req) {
|
||||
return blackAndWhiteListService.isInBlackOrWhiteList(req);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
package cn.axzo.nanopart.server.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class HealthCheckController {
|
||||
|
||||
/**
|
||||
* 探活
|
||||
*/
|
||||
@GetMapping("/checkDeath")
|
||||
public String checkDeath() {
|
||||
return "hello";
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
package cn.axzo.nanopart.server.dao.entity;
|
||||
|
||||
|
||||
import cn.axzo.framework.data.mybatisplus.model.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author: chenwenjian
|
||||
* @date: 2023/8/11 15:19
|
||||
* @description: 黑白名单表对应实体
|
||||
* @modifiedBy:
|
||||
* @version: 1.0
|
||||
*/
|
||||
@Data
|
||||
@TableName(value = "saas_black_white_list",autoResultMap = true)
|
||||
public class SaasBlackWhiteList extends BaseEntity<SaasBlackWhiteList> {
|
||||
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 模块名
|
||||
*/
|
||||
private String module;
|
||||
|
||||
/**
|
||||
* 参数
|
||||
*/
|
||||
@TableField(value = "param",typeHandler = JacksonTypeHandler.class)
|
||||
private Map<String,Object> param;
|
||||
|
||||
private Long createBy;
|
||||
|
||||
private Long updateBy;
|
||||
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
package cn.axzo.nanopart.server.dao.mapper;
|
||||
|
||||
import cn.axzo.nanopart.server.dao.entity.SaasBlackWhiteList;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @author: chenwenjian
|
||||
* @date: 2023/8/11 16:17
|
||||
* @description: 黑白名单Mapper
|
||||
* @modifiedBy:
|
||||
* @version: 1.0
|
||||
*/
|
||||
@Mapper
|
||||
public interface BlackAndWhiteListMapper extends BaseMapper<SaasBlackWhiteList> {
|
||||
}
|
||||
@ -0,0 +1,78 @@
|
||||
package cn.axzo.nanopart.server.dao.repository;
|
||||
|
||||
|
||||
import cn.axzo.basics.common.BeanMapper;
|
||||
import cn.axzo.nanopart.api.request.BlackAndWhiteListReq;
|
||||
import cn.axzo.nanopart.server.dao.entity.SaasBlackWhiteList;
|
||||
import cn.axzo.nanopart.server.dao.mapper.BlackAndWhiteListMapper;
|
||||
import cn.azxo.framework.common.utils.StringUtils;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author: chenwenjian
|
||||
* @date: 2023/8/11 16:23
|
||||
* @description: 黑白名单数据库访问层
|
||||
* @modifiedBy:
|
||||
* @version: 1.0
|
||||
*/
|
||||
@Slf4j
|
||||
@Repository
|
||||
@RequiredArgsConstructor
|
||||
public class BlackAndWhiteListRepository extends ServiceImpl<BlackAndWhiteListMapper, SaasBlackWhiteList> {
|
||||
|
||||
private final BlackAndWhiteListMapper blackAndWhiteListMapper;
|
||||
|
||||
public Long create(BlackAndWhiteListReq req){
|
||||
SaasBlackWhiteList blackWhiteList = BeanMapper.copyBean(req, SaasBlackWhiteList.class, (req1, saasBlackWhiteList) -> saasBlackWhiteList.setType(req1.getType().getValue()));
|
||||
Date nowTime = new Date(System.currentTimeMillis());
|
||||
blackWhiteList.setCreateAt(nowTime);
|
||||
blackWhiteList.setUpdateAt(nowTime);
|
||||
blackAndWhiteListMapper.insert(blackWhiteList);
|
||||
return blackWhiteList.getId();
|
||||
}
|
||||
|
||||
public Void delete(BlackAndWhiteListReq req) {
|
||||
List<SaasBlackWhiteList> blackWhiteLists = detail(req);
|
||||
if (CollectionUtil.isNotEmpty(blackWhiteLists)){
|
||||
blackWhiteLists.forEach(saasBlackWhiteList -> {
|
||||
lambdaUpdate().eq(SaasBlackWhiteList::getId,saasBlackWhiteList.getId())
|
||||
.eq(SaasBlackWhiteList::getIsDelete,0)
|
||||
.set(SaasBlackWhiteList::getIsDelete,saasBlackWhiteList.getId())
|
||||
.update();
|
||||
log.info("deleted record:{}", JSONObject.valueToString(saasBlackWhiteList));
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<SaasBlackWhiteList> detail(BlackAndWhiteListReq req) {
|
||||
QueryWrapper<SaasBlackWhiteList> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("type",req.getType().getValue())
|
||||
.eq(StringUtils.isNotBlank(req.getModule()),"module",req.getModule())
|
||||
.eq("is_delete",0)
|
||||
.groupBy("type","param");
|
||||
buildQueryWrapper(queryWrapper, req.getParam(), "");
|
||||
return blackAndWhiteListMapper.selectList(queryWrapper);
|
||||
}
|
||||
|
||||
private void buildQueryWrapper(QueryWrapper<SaasBlackWhiteList> queryWrapper, Map<String, Object> params, String prefix) {
|
||||
params.forEach((key, value) -> {
|
||||
String fullKey = prefix.isEmpty() ? key : prefix + "." + key;
|
||||
if (value instanceof Map) {
|
||||
buildQueryWrapper(queryWrapper, (Map<String, Object>) value, fullKey);
|
||||
} else {
|
||||
queryWrapper.eq("param->>'$." + fullKey + "'", value);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
package cn.axzo.nanopart.server.service;
|
||||
|
||||
import cn.axzo.framework.domain.web.result.ApiResult;
|
||||
import cn.axzo.nanopart.api.request.BlackAndWhiteListReq;
|
||||
import cn.axzo.nanopart.api.response.BlackAndWhiteListResp;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @author: chenwenjian
|
||||
* @date: 2023/8/11 17:00
|
||||
* @description:
|
||||
* @modifiedBy:
|
||||
* @version: 1.0
|
||||
*/
|
||||
public interface BlackAndWhiteListService {
|
||||
|
||||
ApiResult<Long> create(BlackAndWhiteListReq req);
|
||||
|
||||
ApiResult<Void> delete(BlackAndWhiteListReq req);
|
||||
|
||||
ApiResult<List<BlackAndWhiteListResp>> detail(BlackAndWhiteListReq req);
|
||||
|
||||
ApiResult<Boolean> isInBlackOrWhiteList(BlackAndWhiteListReq req);
|
||||
|
||||
}
|
||||
@ -0,0 +1,85 @@
|
||||
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;
|
||||
import cn.axzo.nanopart.server.dao.repository.BlackAndWhiteListRepository;
|
||||
import cn.axzo.nanopart.server.service.BlackAndWhiteListService;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author: chenwenjian
|
||||
* @date: 2023/8/11 17:04
|
||||
* @description: 黑白名单service层
|
||||
* @modifiedBy:
|
||||
* @version: 1.0
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class BlackAndWhiteListServiceImpl implements BlackAndWhiteListService {
|
||||
|
||||
private final BlackAndWhiteListRepository blackAndWhiteListRepository;
|
||||
|
||||
/**
|
||||
* 新增一条黑白名单记录
|
||||
* @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 包含type,module和param三个字段
|
||||
* @return null
|
||||
*/
|
||||
@Override
|
||||
public ApiResult<Void> delete(BlackAndWhiteListReq req) {
|
||||
return ApiResult.ok(blackAndWhiteListRepository.delete(req));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询指定条件的所有黑白名单记录
|
||||
* @param req 包含type,module和param三个字段
|
||||
* @return 记录列表
|
||||
*/
|
||||
@Override
|
||||
public ApiResult<List<BlackAndWhiteListResp>> detail(BlackAndWhiteListReq req) {
|
||||
List<SaasBlackWhiteList> saasBlackWhiteLists = blackAndWhiteListRepository.detail(req);
|
||||
List<BlackAndWhiteListResp> blackAndWhiteListResps = BeanMapper.copyList(saasBlackWhiteLists, BlackAndWhiteListResp.class);
|
||||
return ApiResult.ok(blackAndWhiteListResps);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否存在指定条件的黑白名单记录
|
||||
* @param req 包含type,module和param三个字段
|
||||
* @return 记录存在返回true,否则返回false
|
||||
*/
|
||||
@Override
|
||||
public ApiResult<Boolean> isInBlackOrWhiteList(BlackAndWhiteListReq req) {
|
||||
List<SaasBlackWhiteList> blackWhiteLists = blackAndWhiteListRepository.detail(req);
|
||||
return ApiResult.ok(CollectionUtil.isNotEmpty(blackWhiteLists));
|
||||
}
|
||||
}
|
||||
29
black-list/pom.xml
Normal file
29
black-list/pom.xml
Normal file
@ -0,0 +1,29 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>cn.axzo.nanopart</groupId>
|
||||
<artifactId>nanopart</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>black-list</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>black-list</name>
|
||||
|
||||
|
||||
<modules>
|
||||
<module>black-list-api</module>
|
||||
<module>black-list-service</module>
|
||||
</modules>
|
||||
|
||||
<!-- <dependencies>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>cn.axzo.infra</groupId>-->
|
||||
<!-- <artifactId>axzo-bom</artifactId>-->
|
||||
<!-- <version>2.0.0-SNAPSHOT</version>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- </dependencies>-->
|
||||
</project>
|
||||
121
deployment.yaml
Normal file
121
deployment.yaml
Normal file
@ -0,0 +1,121 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: { ProjectName }
|
||||
spec:
|
||||
minReadySeconds: 2
|
||||
replicas: 1
|
||||
strategy:
|
||||
rollingUpdate:
|
||||
maxSurge: 1
|
||||
maxUnavailable: 0
|
||||
type: RollingUpdate
|
||||
selector:
|
||||
matchLabels:
|
||||
app: { ProjectName }
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: { ProjectName }
|
||||
prometheus: { PROMETHEUS }
|
||||
logging: '{LOGGING}'
|
||||
spec:
|
||||
affinity:
|
||||
nodeAffinity:
|
||||
requiredDuringSchedulingIgnoredDuringExecution:
|
||||
nodeSelectorTerms:
|
||||
- matchExpressions:
|
||||
- key: work
|
||||
operator: In
|
||||
values:
|
||||
- { nodeSelector }
|
||||
podAntiAffinity:
|
||||
preferredDuringSchedulingIgnoredDuringExecution:
|
||||
- podAffinityTerm:
|
||||
labelSelector:
|
||||
matchExpressions:
|
||||
- key: app
|
||||
operator: In
|
||||
values:
|
||||
- { ProjectName }
|
||||
topologyKey: kubernetes.io/hostname
|
||||
weight: 100
|
||||
terminationGracePeriodSeconds: 60 ##k8s将会给应用发送SIGTERM信号,可以用来正确、优雅地关闭应用,默认为30秒
|
||||
containers:
|
||||
- name: { ProjectName }
|
||||
image: harbor.axzo.cn/{namespace}/{ProjectName}:{BUILD_ID}
|
||||
imagePullPolicy: Always
|
||||
livenessProbe: #该pod是存活的,不存活则需要重启
|
||||
httpGet:
|
||||
path: /checkDeath
|
||||
port: { port }
|
||||
scheme: HTTP
|
||||
initialDelaySeconds: 60 ## equals to the maximum startup time of the application + couple of seconds
|
||||
timeoutSeconds: 5
|
||||
successThreshold: 1
|
||||
failureThreshold: 5
|
||||
readinessProbe: #kubernetes认为该pod是启动成功的
|
||||
httpGet:
|
||||
path: /checkDeath
|
||||
port: { port }
|
||||
scheme: HTTP
|
||||
initialDelaySeconds: 30 ## equals to minimum startup time of the application
|
||||
timeoutSeconds: 5
|
||||
successThreshold: 1
|
||||
failureThreshold: 5
|
||||
volumeMounts:
|
||||
- name: tz-config
|
||||
mountPath: /etc/localtime
|
||||
- name: jmx-exporter
|
||||
mountPath: /data
|
||||
env:
|
||||
- name: NACOS_HOST
|
||||
value: { NACOS_HOST }
|
||||
- name: NACOS_PORT
|
||||
value: "{NACOS_PORT}"
|
||||
- name: NACOS_NAMESPACE_ID
|
||||
value: { NACOS_NAMESPACE_ID }
|
||||
- name: NACOS_PROFILES_ACTIVE
|
||||
value: { NACOS_PROFILES_ACTIVE }
|
||||
- name: MY_POD_NAME
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: metadata.name
|
||||
- name: MY_POD_NAMESPACE
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: metadata.namespace
|
||||
- name: POD_IP
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: status.podIP
|
||||
ports:
|
||||
- containerPort: { port }
|
||||
resources:
|
||||
limits:
|
||||
memory: { limitMemory }
|
||||
requests:
|
||||
memory: { requestsMemory }
|
||||
imagePullSecrets:
|
||||
- name: harbor
|
||||
volumes:
|
||||
- name: tz-config
|
||||
hostPath:
|
||||
path: /usr/share/zoneinfo/Asia/Shanghai
|
||||
- name: jmx-exporter
|
||||
persistentVolumeClaim:
|
||||
claimName: jmx
|
||||
|
||||
---
|
||||
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: { ProjectName }
|
||||
spec:
|
||||
ports:
|
||||
- name: tcp
|
||||
port: { port }
|
||||
clusterIP: None
|
||||
selector:
|
||||
app: { ProjectName }
|
||||
106
nanopart-server/pom.xml
Normal file
106
nanopart-server/pom.xml
Normal file
@ -0,0 +1,106 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>cn.axzo.nanopart</groupId>
|
||||
<artifactId>nanopart</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>nanopart-server</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>nanopart-server</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.axzo.framework</groupId>
|
||||
<artifactId>axzo-web-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.axzo.framework</groupId>
|
||||
<artifactId>axzo-spring-cloud-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.axzo.framework</groupId>
|
||||
<artifactId>axzo-consumer-spring-cloud-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.axzo.framework</groupId>
|
||||
<artifactId>axzo-processor-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<!--mybatis-plus-->
|
||||
<dependency>
|
||||
<groupId>cn.axzo.framework</groupId>
|
||||
<artifactId>axzo-mybatisplus-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<!-- swagger-yapi -->
|
||||
<dependency>
|
||||
<groupId>cn.axzo.framework</groupId>
|
||||
<artifactId>axzo-swagger-yapi-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<!-- druid -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.axzo.framework</groupId>
|
||||
<artifactId>axzo-logger-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.axzo.framework</groupId>
|
||||
<artifactId>axzo-test-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.axzo.pokonyan</groupId>
|
||||
<artifactId>pokonyan</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.axzo.nanopart</groupId>
|
||||
<artifactId>black-list-api</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.axzo.nanopart</groupId>
|
||||
<artifactId>black-list-service</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>nanopart-server</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/java</directory>
|
||||
<includes>
|
||||
<include>**/*.xml</include>
|
||||
</includes>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@ -0,0 +1,17 @@
|
||||
package cn.axzo.nanopart;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
||||
@MapperScan(value = {"cn.axzo.**.mapper"})
|
||||
@SpringBootApplication
|
||||
@EnableFeignClients(basePackages = {
|
||||
"cn.axzo.nanopart.api"
|
||||
})
|
||||
public class NanopartApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(NanopartApplication.class, args);
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
45
nanopart-server/src/main/resources/application.yml
Normal file
45
nanopart-server/src/main/resources/application.yml
Normal file
@ -0,0 +1,45 @@
|
||||
spring:
|
||||
application:
|
||||
name: nanopart
|
||||
jackson:
|
||||
time-zone: GMT+8
|
||||
serialization:
|
||||
write-dates-as-timestamps: true
|
||||
generator:
|
||||
write-bigdecimal-as-plain: true
|
||||
deserialization:
|
||||
fail-on-unknown-properties: false
|
||||
read-unknown-enum-values-as-null: true
|
||||
|
||||
mybatis-plus:
|
||||
configuration:
|
||||
auto-mapping-behavior: full
|
||||
map-underscore-to-camel-case: true
|
||||
global-config:
|
||||
db-config:
|
||||
id-type: auto
|
||||
logic-delete-value: id #逻辑已删除值(默认为 1)
|
||||
logic-not-delete-value: 0 #逻辑未删除值(默认为 0)
|
||||
logic-delete-field: isDelete #逻辑删除字段
|
||||
|
||||
logging:
|
||||
level:
|
||||
com.alibaba.nacos.client.config.impl: WARN
|
||||
|
||||
management:
|
||||
endpoint:
|
||||
metrics:
|
||||
enabled: true
|
||||
prometheus:
|
||||
enabled: true
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: "*"
|
||||
metrics:
|
||||
export:
|
||||
prometheus:
|
||||
enabled: true
|
||||
|
||||
knife4j:
|
||||
enable: true
|
||||
15
nanopart-server/src/main/resources/bootstrap.yml
Normal file
15
nanopart-server/src/main/resources/bootstrap.yml
Normal file
@ -0,0 +1,15 @@
|
||||
spring:
|
||||
application:
|
||||
name: nanopart
|
||||
cloud:
|
||||
nacos:
|
||||
config:
|
||||
server-addr: ${NACOS_HOST:dev-nacos.axzo.cn}:${NACOS_PORT:80}
|
||||
file-extension: yaml
|
||||
namespace: ${NACOS_NAMESPACE_ID:35eada10-9574-4db8-9fea-bc6a4960b6c7}
|
||||
prefix: ${spring.application.name}
|
||||
profiles:
|
||||
active: ${NACOS_PROFILES_ACTIVE:dev}
|
||||
include: swagger
|
||||
main:
|
||||
allow-bean-definition-overriding: true
|
||||
10
nanopart-server/src/main/resources/logback-spring.xml
Normal file
10
nanopart-server/src/main/resources/logback-spring.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE xml>
|
||||
<configuration>
|
||||
<!-- 导入安心筑全局日志配置 -->
|
||||
<include resource="logback/logback-axzo.xml" />
|
||||
<!-- 覆盖开发环境日志配置 -->
|
||||
<springProfile name="local,dev">
|
||||
<logger name="cn.axzo" level="DEBUG" />
|
||||
</springProfile>
|
||||
</configuration>
|
||||
@ -0,0 +1,38 @@
|
||||
package cn.axzo.nanopart;
|
||||
|
||||
import cn.axzo.framework.domain.web.result.ApiResult;
|
||||
import cn.axzo.nanopart.api.BlackAndWhiteListApi;
|
||||
import cn.axzo.nanopart.api.request.BlackAndWhiteListReq;
|
||||
import cn.axzo.nanopart.api.response.BlackAndWhiteListResp;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author: chenwenjian
|
||||
* @date: 2023/8/16 17:24
|
||||
* @description:
|
||||
* @modifiedBy:
|
||||
* @version: 1.0
|
||||
*/
|
||||
@SpringBootTest
|
||||
public class NanopartApplicationTests {
|
||||
|
||||
@Resource
|
||||
private BlackAndWhiteListApi blackAndWhiteListApi;
|
||||
|
||||
@Test
|
||||
void contextLoad(){
|
||||
BlackAndWhiteListReq blackAndWhiteListReq = new BlackAndWhiteListReq();
|
||||
blackAndWhiteListReq.setModule("cms-login");
|
||||
HashMap<String, Object> hashMap = new HashMap<>();
|
||||
hashMap.put("phone","17870574155");
|
||||
blackAndWhiteListReq.setParam(hashMap);
|
||||
|
||||
ApiResult<List<BlackAndWhiteListResp>> detail = blackAndWhiteListApi.detail(blackAndWhiteListReq);
|
||||
System.out.println(detail.getData().toString());
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,43 @@
|
||||
package cn.axzo.nanopart.config;
|
||||
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import feign.RequestInterceptor;
|
||||
import feign.RequestTemplate;
|
||||
import feign.Target.HardCodedTarget;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Map;
|
||||
|
||||
@Configuration
|
||||
@Slf4j
|
||||
@Profile({"dev", "local"})
|
||||
public class FeignConfig implements RequestInterceptor {
|
||||
|
||||
private static String POD_NAMESPACE;
|
||||
|
||||
static {
|
||||
Map<String, String> env = System.getenv();
|
||||
if (env != null) {
|
||||
POD_NAMESPACE = env.get("MY_POD_NAMESPACE");
|
||||
}
|
||||
log.info("init FeignConfig, POD_NAMESPACE value is {}", POD_NAMESPACE);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public void apply(RequestTemplate requestTemplate) {
|
||||
if (POD_NAMESPACE == null) {
|
||||
HardCodedTarget target = (HardCodedTarget) requestTemplate.feignTarget();
|
||||
String url = requestTemplate.feignTarget().url();
|
||||
url = url.replace("http://nanopart:8080", "http://127.0.0.1:8080");
|
||||
requestTemplate.target(url);
|
||||
Field field = ReflectUtil.getField(target.getClass(), "url");
|
||||
field.setAccessible(true);
|
||||
field.set(target, url);
|
||||
}
|
||||
}
|
||||
}
|
||||
94
pom.xml
Normal file
94
pom.xml
Normal file
@ -0,0 +1,94 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>cn.axzo.infra</groupId>
|
||||
<artifactId>axzo-parent</artifactId>
|
||||
<version>2.4.13.5</version>
|
||||
</parent>
|
||||
|
||||
<groupId>cn.axzo.nanopart</groupId>
|
||||
<artifactId>nanopart</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>${revision}</version>
|
||||
|
||||
<name>nanopart</name>
|
||||
|
||||
<properties>
|
||||
<revision>2.0.0-SNAPSHOT</revision>
|
||||
<axzo-bom.version>2.0.0-SNAPSHOT</axzo-bom.version>
|
||||
<axzo-dependencies.version>2.0.0-SNAPSHOT</axzo-dependencies.version>
|
||||
<lombok.version>1.18.22</lombok.version>
|
||||
<mapstruct.version>1.4.2.Final</mapstruct.version>
|
||||
</properties>
|
||||
|
||||
<modules>
|
||||
<module>black-list</module>
|
||||
<module>nanopart-server</module>
|
||||
</modules>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<!-- 导入axzo通用api依赖 -->
|
||||
<dependency>
|
||||
<groupId>cn.axzo.infra</groupId>
|
||||
<artifactId>axzo-bom</artifactId>
|
||||
<version>${axzo-bom.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.axzo.infra</groupId>
|
||||
<artifactId>axzo-dependencies</artifactId>
|
||||
<version>${axzo-dependencies.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- lombok -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- maven-compiler-plugin 插件,解决 Lombok + MapStruct 组合 -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct-processor</artifactId>
|
||||
<version>${mapstruct.version}</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>axzo</id>
|
||||
<name>axzo repository</name>
|
||||
<url>https://nexus.axzo.cn/repository/axzo/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
</project>
|
||||
Loading…
Reference in New Issue
Block a user