初始化
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
package com.njcn.system.api;
|
||||
|
||||
import com.njcn.common.pojo.constant.ServerInfo;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.system.api.fallback.AreaFeignClientFallbackFactory;
|
||||
import com.njcn.system.pojo.dto.AreaTreeDTO;
|
||||
import com.njcn.system.pojo.po.Area;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author denghuajun
|
||||
* @version 1.0.0
|
||||
* @date 2022年01月05日 15:11
|
||||
*/
|
||||
@FeignClient(value = ServerInfo.SYSTEM,path = "/area",fallbackFactory = AreaFeignClientFallbackFactory.class)
|
||||
public interface AreaFeignClient {
|
||||
|
||||
/**
|
||||
* 根据行政区域id查询详情
|
||||
*
|
||||
* @param id 行政区域id
|
||||
* @return 行政区域基本信息
|
||||
*/
|
||||
@GetMapping("/selectIdArea/{id}")
|
||||
HttpResult<Area> selectIdArea(@PathVariable("id") String id);
|
||||
|
||||
/**
|
||||
* 根据行政区域id查询详情
|
||||
*
|
||||
* @param list 行政区域id集合
|
||||
* @return 行政区域基本信息
|
||||
*/
|
||||
@PostMapping("/areaNameByList")
|
||||
HttpResult<List<Area>> areaNameByList(@RequestBody List<String> list);
|
||||
|
||||
/**
|
||||
* 查询所有的行政区域树
|
||||
*/
|
||||
@PostMapping("/areaDeptTree")
|
||||
HttpResult<List<AreaTreeDTO>> areaDeptTree(@RequestParam("id")String id , @RequestParam("type")Integer type);
|
||||
|
||||
/**
|
||||
* 根据区域id获取省份信息
|
||||
*/
|
||||
@PostMapping("/areaPro")
|
||||
HttpResult<Area> areaPro(@RequestParam("id")String id , @RequestParam("type")Integer type);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 根据行政区域名称查询详细
|
||||
*
|
||||
* @param name 行政区域名称
|
||||
* @return 行政区域详情
|
||||
*/
|
||||
@GetMapping("/selectAreaByName/{name}")
|
||||
HttpResult<Area> selectAreaByName(@PathVariable("name") String name);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.njcn.system.api;
|
||||
|
||||
import com.njcn.common.pojo.constant.ServerInfo;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.system.api.fallback.ConfigFeignClientFallbackFactory;
|
||||
import com.njcn.system.pojo.po.Config;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
/**
|
||||
* @author denghuajun
|
||||
* @version 1.0.0
|
||||
* @date 2022年01月05日 15:11
|
||||
*/
|
||||
@FeignClient(value = ServerInfo.SYSTEM, path = "/config", fallbackFactory = ConfigFeignClientFallbackFactory.class)
|
||||
public interface ConfigFeignClient {
|
||||
|
||||
/**
|
||||
* 获取系统配置
|
||||
*
|
||||
* @return 配置信息
|
||||
*/
|
||||
@GetMapping("/getSysConfig")
|
||||
HttpResult<Config> getSysConfig();
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.njcn.system.api;
|
||||
|
||||
|
||||
import com.njcn.common.pojo.constant.ServerInfo;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.system.api.fallback.DicDataFeignClientFallbackFactory;
|
||||
|
||||
import com.njcn.system.pojo.po.DictData;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.awt.image.RenderedImage;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* pqs
|
||||
*
|
||||
* @author cdf
|
||||
* @date 2021/6/24
|
||||
*/
|
||||
@FeignClient(value = ServerInfo.SYSTEM, path = "/dictData", fallbackFactory = DicDataFeignClientFallbackFactory.class)
|
||||
public interface DicDataFeignClient {
|
||||
|
||||
@GetMapping("/getDicDataById")
|
||||
HttpResult<DictData> getDicDataById(@RequestParam("dicIndex") String dicIndex);
|
||||
|
||||
@GetMapping("/getDicDataByTypeName")
|
||||
HttpResult<List<DictData>> getDicDataByTypeName(@RequestParam("dictTypeName") String dictTypeName);
|
||||
|
||||
@GetMapping("/getDicDataByName")
|
||||
HttpResult<DictData> getDicDataByName(@RequestParam("dicName") String dicName);
|
||||
|
||||
@GetMapping("/getLoadTypeBySys")
|
||||
HttpResult<List<DictData>> getLoadTypeBySys();
|
||||
|
||||
/**
|
||||
* 后台新增字典数据
|
||||
*
|
||||
* @param dicTypeName 类型名称
|
||||
* @param dicDataName 数据名称
|
||||
* @return 新增后的字典数据
|
||||
*/
|
||||
@GetMapping("/addDicData")
|
||||
HttpResult<DictData> addDicData(@RequestParam("dicTypeName") String dicTypeName, @RequestParam("dicDataName") String dicDataName);
|
||||
|
||||
/**
|
||||
* 根据字典类型名称&数据名称获取字典数据
|
||||
*
|
||||
* @param dicTypeName 字典类型名称
|
||||
* @param dicDataName 字典数据名称
|
||||
* @return 字典数据
|
||||
*/
|
||||
@GetMapping("/getDicDataByNameAndTypeName")
|
||||
HttpResult<DictData> getDicDataByNameAndTypeName(@RequestParam("dicTypeName") String dicTypeName, @RequestParam("dicDataName") String dicDataName);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.njcn.system.api;
|
||||
|
||||
import com.njcn.common.pojo.constant.ServerInfo;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.system.api.fallback.AreaFeignClientFallbackFactory;
|
||||
import com.njcn.system.pojo.po.Theme;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
|
||||
/**
|
||||
* @author 徐扬
|
||||
*/
|
||||
@FeignClient(value = ServerInfo.SYSTEM,path = "/theme",fallbackFactory = AreaFeignClientFallbackFactory.class)
|
||||
public interface ThemeFeignClient {
|
||||
|
||||
/**
|
||||
* 功能描述: 获取当前主题
|
||||
* @return
|
||||
* @author xy
|
||||
* @date 2022/2/14 11:30
|
||||
*/
|
||||
@GetMapping("/getTheme")
|
||||
HttpResult<Theme> getTheme();
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package com.njcn.system.api.fallback;
|
||||
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.system.api.AreaFeignClient;
|
||||
import com.njcn.system.pojo.dto.AreaTreeDTO;
|
||||
import com.njcn.system.pojo.po.Area;
|
||||
import com.njcn.system.utils.SystemEnumUtil;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author denghuajun
|
||||
* @version 1.0.0
|
||||
* @date 2022年01月05日 15:08
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class AreaFeignClientFallbackFactory implements FallbackFactory<AreaFeignClient> {
|
||||
|
||||
|
||||
/**
|
||||
* 输出远程请求接口异常日志
|
||||
* @param cause RPC请求异常
|
||||
*/
|
||||
@Override
|
||||
public AreaFeignClient create(Throwable cause) {
|
||||
//判断抛出异常是否为解码器抛出的业务异常
|
||||
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
|
||||
if(cause.getCause() instanceof BusinessException){
|
||||
BusinessException businessException = (BusinessException) cause.getCause();
|
||||
exceptionEnum = SystemEnumUtil.getExceptionEnum(businessException.getResult());
|
||||
}
|
||||
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||
return new AreaFeignClient() {
|
||||
@Override
|
||||
public HttpResult<Area> selectIdArea(String id) {
|
||||
log.error("{}异常,降级处理,异常为:{}","根据行政区域id查询详情",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpResult<List<Area>> areaNameByList(List<String> list) {
|
||||
log.error("{}异常,降级处理,异常为:{}","根据行政区域id集合查询名称",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpResult<List<AreaTreeDTO>> areaDeptTree(String id, Integer type) {
|
||||
log.error("{}异常,降级处理,异常为:{}","查询区域详情",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpResult<Area> areaPro(String id, Integer type) {
|
||||
log.error("{}异常,降级处理,异常为:{}","根据区域id查询省份信息",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpResult<Area> selectAreaByName(String name) {
|
||||
log.error("{}异常,降级处理,异常为:{}","根据行政区域名称查询详细",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.njcn.system.api.fallback;
|
||||
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.system.api.ConfigFeignClient;
|
||||
import com.njcn.system.pojo.po.Config;
|
||||
import com.njcn.system.utils.SystemEnumUtil;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author denghuajun
|
||||
* @version 1.0.0
|
||||
* @date 2022年01月05日 15:08
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class ConfigFeignClientFallbackFactory implements FallbackFactory<ConfigFeignClient> {
|
||||
|
||||
|
||||
/**
|
||||
* 输出远程请求接口异常日志
|
||||
* @param cause RPC请求异常
|
||||
*/
|
||||
@Override
|
||||
public ConfigFeignClient create(Throwable cause) {
|
||||
//判断抛出异常是否为解码器抛出的业务异常
|
||||
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
|
||||
if(cause.getCause() instanceof BusinessException){
|
||||
BusinessException businessException = (BusinessException) cause.getCause();
|
||||
exceptionEnum = SystemEnumUtil.getExceptionEnum(businessException.getResult());
|
||||
}
|
||||
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||
return new ConfigFeignClient() {
|
||||
@Override
|
||||
public HttpResult<Config> getSysConfig() {
|
||||
log.error("{}异常,降级处理,异常为:{}","获取系统配置",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.njcn.system.api.fallback;
|
||||
|
||||
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.system.api.DicDataFeignClient;
|
||||
import com.njcn.system.pojo.po.DictData;
|
||||
import com.njcn.system.utils.SystemEnumUtil;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2021年09月09日 15:19
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class DicDataFeignClientFallbackFactory implements FallbackFactory<DicDataFeignClient> {
|
||||
@Override
|
||||
public DicDataFeignClient create(Throwable cause) {
|
||||
//判断抛出异常是否为解码器抛出的业务异常
|
||||
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
|
||||
if(cause.getCause() instanceof BusinessException){
|
||||
BusinessException businessException = (BusinessException) cause.getCause();
|
||||
exceptionEnum = SystemEnumUtil.getExceptionEnum(businessException.getResult());
|
||||
}
|
||||
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||
return new DicDataFeignClient() {
|
||||
@Override
|
||||
public HttpResult<DictData> getDicDataById(String dicIndex) {
|
||||
log.error("{}异常,降级处理,异常为:{}","根据字典索引获取字典数据",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpResult<List<DictData>> getDicDataByTypeName(String dictTypeName) {
|
||||
log.error("{}异常,降级处理,异常为:{}","根据字典类型名称获取字典数据集合",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpResult<DictData> getDicDataByName(String dicName) {
|
||||
log.error("{}异常,降级处理,异常为:{}","根据字典名称获取字典数据",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpResult<List<DictData>> getLoadTypeBySys() {
|
||||
log.error("{}异常,降级处理,异常为:{}","根据系统类型获取不同指标参数",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpResult<DictData> addDicData(String dicTypeName, String dicDataName) {
|
||||
log.error("{}异常,降级处理,异常为:{}","后台新增字典数据",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpResult<DictData> getDicDataByNameAndTypeName(String typeName, String dicDataName) {
|
||||
log.error("{}异常,降级处理,异常为:{}","根据字典类型名称&数据名称获取字典数据",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.njcn.system.api.fallback;
|
||||
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.system.api.ThemeFeignClient;
|
||||
import com.njcn.system.pojo.po.Theme;
|
||||
import com.njcn.system.utils.SystemEnumUtil;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author denghuajun
|
||||
* @version 1.0.0
|
||||
* @date 2022年01月05日 15:08
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class ThemeFeignClientFallbackFactory implements FallbackFactory<ThemeFeignClient> {
|
||||
|
||||
|
||||
/**
|
||||
* 输出远程请求接口异常日志
|
||||
* @param cause RPC请求异常
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ThemeFeignClient create(Throwable cause) {
|
||||
//判断抛出异常是否为解码器抛出的业务异常
|
||||
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
|
||||
if(cause.getCause() instanceof BusinessException){
|
||||
BusinessException businessException = (BusinessException) cause.getCause();
|
||||
exceptionEnum = SystemEnumUtil.getExceptionEnum(businessException.getResult());
|
||||
}
|
||||
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||
return new ThemeFeignClient() {
|
||||
@Override
|
||||
public HttpResult<Theme> getTheme() {
|
||||
log.error("{}异常,降级处理,异常为:{}","获取当前主题",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user