初始化

This commit is contained in:
2022-06-21 20:47:46 +08:00
parent b666a24a98
commit 59da3376c1
1246 changed files with 129600 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
package com.njcn.user.api;
import com.njcn.common.pojo.constant.ServerInfo;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.user.api.fallback.AuthClientFeignClientFallbackFactory;
import com.njcn.user.pojo.po.AuthClient;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
/**
* @author hongawen
* @version 1.0.0
* @date 2021年12月15日 13:27
*/
@FeignClient(value = ServerInfo.USER, path = "/authClient", fallbackFactory = AuthClientFeignClientFallbackFactory.class)
public interface AuthClientFeignClient {
/**
* 根据客户端名称获取客户端信息
* @param clientName 客户端名称
* @return 客户端信息
*/
@GetMapping("/getAuthClientByName/{clientName}")
HttpResult<AuthClient> getAuthClientByName(@PathVariable("clientName") String clientName);
}

View File

@@ -0,0 +1,48 @@
package com.njcn.user.api;
import com.njcn.common.pojo.constant.ServerInfo;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.user.api.fallback.DeptFeignClientFallbackFactory;
import com.njcn.user.pojo.dto.DeptDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
/**
* @author denghuajun
* @date 2022/1/11
* 部门相关业务对外接口
*/
@FeignClient(value = ServerInfo.USER, path = "/dept", fallbackFactory = DeptFeignClientFallbackFactory.class)
public interface DeptFeignClient {
/**
* 根据条件获取后代部门索引
* @param id 部门id
* @param type 指定部门类型
* @return 后代部门索引
*/
@PostMapping("/getDeptDescendantIndexes")
HttpResult<List<DeptDTO>> getDeptDescendantIndexes(@RequestParam("id") String id, @RequestParam("type") List<Integer> type);
/**
* 根据区域获取部门id
* @param area
* @author xy
* @return
*/
@GetMapping("/getDeptIdByArea")
HttpResult<String> getDeptIdByArea(@RequestParam("area") String area);
/**
* 根据部门id获取区域id
* @param deptId
* @author denghuajun
* @return
*/
@GetMapping("/getAreaIdByDeptId")
HttpResult<String> getAreaIdByDeptId(@RequestParam("deptId") String deptId);
}

View File

@@ -0,0 +1,45 @@
package com.njcn.user.api;
import com.njcn.common.pojo.constant.ServerInfo;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.user.api.fallback.UserFeignClientFallbackFactory;
import com.njcn.user.pojo.dto.UserDTO;
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.PutMapping;
/**
* @author hongawen
* @version 1.0.0
* @date 2021年05月08日 15:11
*/
@FeignClient(value = ServerInfo.USER,path = "/user",fallbackFactory = UserFeignClientFallbackFactory.class)
public interface UserFeignClient {
/**
* 根据登录名查询用户信息
*
* @param loginName 登录名
* @return 用户基本信息
*/
@GetMapping("/getUserByName/{loginName}")
HttpResult<UserDTO> getUserByName(@PathVariable("loginName") String loginName);
/**
* 认证后根据用户名判断用户状态
* @param loginName 登录名
* @return 校验结果
*/
@GetMapping("/judgeUserStatus/{loginName}")
HttpResult<Boolean> judgeUserStatus(@PathVariable("loginName") String loginName);
/**
* 更新用户登录认证密码错误次数
*
* @param loginName 登录名
* @return null
*/
@PutMapping("/updateUserLoginErrorTimes/{loginName}")
HttpResult<String> updateUserLoginErrorTimes(@PathVariable("loginName") String loginName);
}

View File

@@ -0,0 +1,43 @@
package com.njcn.user.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.user.api.AuthClientFeignClient;
import com.njcn.user.pojo.po.AuthClient;
import com.njcn.user.utils.UserEnumUtil;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* @author hongawen
* @version 1.0.0
* @date 2021年12月15日 13:28
*/
@Slf4j
@Component
public class AuthClientFeignClientFallbackFactory implements FallbackFactory<AuthClientFeignClient> {
/**
* 输出远程请求接口异常日志
* @param throwable RPC请求异常
*/
@Override
public AuthClientFeignClient create(Throwable throwable) {
//判断抛出异常是否为解码器抛出的业务异常
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
if(throwable.getCause() instanceof BusinessException){
BusinessException businessException = (BusinessException) throwable.getCause();
exceptionEnum = UserEnumUtil.getExceptionEnum(businessException.getResult());
}
Enum<?> finalExceptionEnum = exceptionEnum;
return new AuthClientFeignClient() {
@Override
public HttpResult<AuthClient> getAuthClientByName(String clientName) {
log.error("{}异常,降级处理,异常为:{}","根据客户端名称获取客户端信息",throwable.toString());
throw new BusinessException(finalExceptionEnum);
}
};
}
}

View File

@@ -0,0 +1,60 @@
package com.njcn.user.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.user.api.DeptFeignClient;
import com.njcn.user.pojo.dto.DeptDTO;
import com.njcn.user.utils.UserEnumUtil;
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月11日 10:21
*/
@Slf4j
@Component
public class DeptFeignClientFallbackFactory implements FallbackFactory<DeptFeignClient> {
/**
* 输出远程请求接口异常日志
*
* @param cause RPC请求异常
*/
@Override
public DeptFeignClient create(Throwable cause) {
//判断抛出异常是否为解码器抛出的业务异常
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
if (cause.getCause() instanceof BusinessException) {
BusinessException businessException = (BusinessException) cause.getCause();
exceptionEnum = UserEnumUtil.getExceptionEnum(businessException.getResult());
}
Enum<?> finalExceptionEnum = exceptionEnum;
return new DeptFeignClient() {
@Override
public HttpResult<List<DeptDTO>> getDeptDescendantIndexes(String id, List<Integer> type) {
log.error("{}异常,降级处理,异常为:{}", "根据条件获取后代部门索引", cause.toString());
throw new BusinessException(finalExceptionEnum);
}
@Override
public HttpResult<String> getDeptIdByArea(String area) {
log.error("{}异常,降级处理,异常为:{}", "根据区域索引获取部门索引", cause.toString());
throw new BusinessException(finalExceptionEnum);
}
@Override
public HttpResult<String> getAreaIdByDeptId(String deptId) {
log.error("{}异常,降级处理,异常为:{}", "根据部门索引获取区域索引", cause.toString());
throw new BusinessException(finalExceptionEnum);
}
};
}
}

View File

@@ -0,0 +1,57 @@
package com.njcn.user.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.user.api.UserFeignClient;
import com.njcn.user.pojo.dto.UserDTO;
import com.njcn.user.utils.UserEnumUtil;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* @author hongawen
* @version 1.0.0
* @date 2021年08月24日 10:21
*/
@Slf4j
@Component
public class UserFeignClientFallbackFactory implements FallbackFactory<UserFeignClient> {
/**
* 输出远程请求接口异常日志
* @param cause RPC请求异常
*/
@Override
public UserFeignClient create(Throwable cause) {
//判断抛出异常是否为解码器抛出的业务异常
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
if(cause.getCause() instanceof BusinessException){
BusinessException businessException = (BusinessException) cause.getCause();
exceptionEnum = UserEnumUtil.getExceptionEnum(businessException.getResult());
}
Enum<?> finalExceptionEnum = exceptionEnum;
return new UserFeignClient() {
@Override
public HttpResult<UserDTO> getUserByName(String loginName) {
log.error("{}异常,降级处理,异常为:{}","根据登录名查询用户信息",cause.toString());
throw new BusinessException(finalExceptionEnum);
}
@Override
public HttpResult<Boolean> judgeUserStatus(String loginName) {
log.error("{}异常,降级处理,异常为:{}","认证后根据用户名判断用户状态",cause.toString());
throw new BusinessException(finalExceptionEnum);
}
@Override
public HttpResult<String> updateUserLoginErrorTimes(String loginName) {
log.error("{}异常,降级处理,异常为:{}","更新用户登录认证密码错误次数",cause.toString());
throw new BusinessException(finalExceptionEnum);
}
};
}
}