feat: openFeign微服务之间远程调用
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
package com.schisandra.system.api;
|
||||
|
||||
import com.schisandra.system.entity.Result;
|
||||
import com.schisandra.system.entity.SchisandraSysConfigDTO;
|
||||
import feign.Param;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
@FeignClient("schisandra-cloud-storage-system-dev")
|
||||
public interface SmsConfigFeignService {
|
||||
@RequestMapping(value = "/system/getConfigByKey",method = RequestMethod.GET)
|
||||
Result<SchisandraSysConfigDTO> getConfigByKey(@RequestParam(value = "key") String key);
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
api 对外接口
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.schisandra.system.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Result<T> {
|
||||
|
||||
private Boolean success;
|
||||
|
||||
private Integer code;
|
||||
|
||||
private String message;
|
||||
|
||||
private T data;
|
||||
|
||||
public static Result ok(){
|
||||
Result result = new Result();
|
||||
result.setSuccess(true);
|
||||
result.setCode(ResultCodeEnum.SUCCESS.getCode());
|
||||
result.setMessage(ResultCodeEnum.SUCCESS.getDesc());
|
||||
return result;
|
||||
}
|
||||
|
||||
public static <T> Result ok(T data){
|
||||
Result result = new Result();
|
||||
result.setSuccess(true);
|
||||
result.setCode(ResultCodeEnum.SUCCESS.getCode());
|
||||
result.setMessage(ResultCodeEnum.SUCCESS.getDesc());
|
||||
result.setData(data);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Result fail(){
|
||||
Result result = new Result();
|
||||
result.setSuccess(false);
|
||||
result.setCode(ResultCodeEnum.FAIL.getCode());
|
||||
result.setMessage(ResultCodeEnum.FAIL.getDesc());
|
||||
return result;
|
||||
}
|
||||
|
||||
public static <T> Result fail(T data){
|
||||
Result result = new Result();
|
||||
result.setSuccess(false);
|
||||
result.setCode(ResultCodeEnum.FAIL.getCode());
|
||||
result.setMessage(ResultCodeEnum.FAIL.getDesc());
|
||||
result.setData(data);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.schisandra.system.entity;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum ResultCodeEnum {
|
||||
|
||||
SUCCESS(200,"成功"),
|
||||
FAIL(500,"失败");
|
||||
|
||||
public int code;
|
||||
|
||||
public String desc;
|
||||
|
||||
ResultCodeEnum(int code,String desc){
|
||||
this.code = code;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public static ResultCodeEnum getByCode(int codeVal){
|
||||
for(ResultCodeEnum resultCodeEnum : ResultCodeEnum.values()){
|
||||
if(resultCodeEnum.code == codeVal){
|
||||
return resultCodeEnum;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.schisandra.system.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* dto
|
||||
*
|
||||
* @author landaiqing
|
||||
* @since 2024-05-11 22:45:55
|
||||
*/
|
||||
@Data
|
||||
public class SchisandraSysConfigDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
private String configName;
|
||||
|
||||
/**
|
||||
* 参数键
|
||||
*/
|
||||
private String configKey;
|
||||
|
||||
/**
|
||||
* 参数值
|
||||
*/
|
||||
private String configValue;
|
||||
|
||||
/**
|
||||
* 创建者
|
||||
*/
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 系统内置(0是 1否)
|
||||
*/
|
||||
private Integer configType;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createDate;
|
||||
|
||||
/**
|
||||
* 更新者
|
||||
*/
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateDate;
|
||||
|
||||
/**
|
||||
* 备注信息
|
||||
*/
|
||||
private String remarks;
|
||||
|
||||
/**
|
||||
* 是否删除 0未删除 1已删除
|
||||
*/
|
||||
private Integer isDeleted;
|
||||
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
api 实体
|
||||
@@ -8,15 +8,15 @@ import com.schisandra.system.application.dto.SchisandraSysConfigDTO;
|
||||
import com.schisandra.system.common.entity.Result;
|
||||
import com.schisandra.system.domain.entity.SchisandraSysConfigBO;
|
||||
import com.schisandra.system.domain.service.SchisandraSysConfigDomainService;
|
||||
import feign.Param;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* controller
|
||||
* controller
|
||||
*
|
||||
* @author landaiqing
|
||||
* @since 2024-05-11 22:45:55
|
||||
@@ -119,4 +119,16 @@ public class SchisandraSysConfigController {
|
||||
|
||||
}
|
||||
|
||||
@RequestMapping(value = "getConfigByKey",method = RequestMethod.GET)
|
||||
public Result<SchisandraSysConfigDTO> getConfigByKey(@RequestParam(value = "key") String key) {
|
||||
try {
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("SchisandraSysConfigController.getConfigByKey.key:{}", key);
|
||||
}
|
||||
return Result.ok(schisandraSysConfigDomainService.getConfigByKey(key));
|
||||
} catch (Exception e) {
|
||||
return Result.fail("配置信息获取失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,4 +19,5 @@ public interface SchisandraSysConfigDTOConverter {
|
||||
|
||||
SchisandraSysConfigBO convertDTOToBO(SchisandraSysConfigDTO schisandraSysConfigDTO);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -17,5 +17,6 @@ public interface SchisandraSysConfigBOConverter {
|
||||
SchisandraSysConfigBOConverter INSTANCE = Mappers.getMapper(SchisandraSysConfigBOConverter.class);
|
||||
|
||||
SchisandraSysConfig convertBOToEntity(SchisandraSysConfigBO schisandraSysConfigBO);
|
||||
SchisandraSysConfigBO convertEntityToBO(SchisandraSysConfig schisandraSysConfig);
|
||||
|
||||
}
|
||||
|
||||
@@ -25,4 +25,5 @@ public interface SchisandraSysConfigDomainService {
|
||||
*/
|
||||
Boolean delete(SchisandraSysConfigBO schisandraSysConfigBO);
|
||||
|
||||
Object getConfigByKey(String key);
|
||||
}
|
||||
|
||||
@@ -46,4 +46,14 @@ public class SchisandraSysConfigDomainServiceImpl implements SchisandraSysConfig
|
||||
return schisandraSysConfigService.update(schisandraSysConfig) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SchisandraSysConfigBO getConfigByKey(String key) {
|
||||
SchisandraSysConfig schisandraSysConfig= schisandraSysConfigService.getConfigByKey(key);
|
||||
SchisandraSysConfigBO schisandraSysConfigBO = SchisandraSysConfigBOConverter.INSTANCE.convertEntityToBO(schisandraSysConfig);
|
||||
if (schisandraSysConfigBO == null){
|
||||
return null;
|
||||
}
|
||||
return schisandraSysConfigBO;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -48,4 +48,5 @@ public interface SchisandraSysConfigService {
|
||||
*/
|
||||
SchisandraSysConfig queryByCondition(SchisandraSysConfig schisandraSysConfig);
|
||||
|
||||
SchisandraSysConfig getConfigByKey(String key);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.schisandra.system.infra.basic.service.impl;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.schisandra.system.infra.basic.entity.SchisandraSysConfig;
|
||||
import com.schisandra.system.infra.basic.dao.SchisandraSysConfigDao;
|
||||
@@ -93,4 +94,10 @@ public class SchisandraSysConfigServiceImpl implements SchisandraSysConfigServic
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public SchisandraSysConfig getConfigByKey(String key) {
|
||||
return schisandraSysConfigDao.selectOne(new QueryWrapper<SchisandraSysConfig>().eq("config_key", key)
|
||||
.eq("is_deleted", 0));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,6 +39,14 @@
|
||||
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.schisandra.system</groupId>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
server:
|
||||
port: 4000
|
||||
port: 5000
|
||||
spring:
|
||||
datasource:
|
||||
username: root
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
spring:
|
||||
application:
|
||||
name: schisandra-cloud-storage-oss-dev
|
||||
name: schisandra-cloud-storage-system-dev
|
||||
profiles:
|
||||
active: dev
|
||||
cloud:
|
||||
|
||||
Reference in New Issue
Block a user