用户消息配置对外接口

This commit is contained in:
2023-09-12 19:22:50 +08:00
parent c1559369e7
commit 995b665ae4
5 changed files with 99 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
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.AppInfoSetFeignClientFallbackFactory;
import com.njcn.user.pojo.po.app.AppInfoSet;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.List;
/**
* @author xuyang
* @version 1.0.0
* @date 2023年09月12日 19:11
*/
@FeignClient(value = ServerInfo.USER,path = "/appInfoSet",fallbackFactory = AppInfoSetFeignClientFallbackFactory.class,contextId = "appInfoSet")
public interface AppInfoSetFeignClient {
@PostMapping("/getListById")
HttpResult<List<AppInfoSet>> getListById(@RequestBody List<String> list);
}

View File

@@ -0,0 +1,47 @@
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.AppInfoSetFeignClient;
import com.njcn.user.pojo.po.app.AppInfoSet;
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 hongawen
* @version 1.0.0
* @date 2021年08月24日 10:21
*/
@Slf4j
@Component
public class AppInfoSetFeignClientFallbackFactory implements FallbackFactory<AppInfoSetFeignClient> {
/**
* 输出远程请求接口异常日志
* @param cause RPC请求异常
*/
@Override
public AppInfoSetFeignClient 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 AppInfoSetFeignClient() {
@Override
public HttpResult<List<AppInfoSet>> getListById(List<String> list) {
log.error("{}异常,降级处理,异常为:{}","根据用户id查询消息配置信息",cause.toString());
throw new BusinessException(finalExceptionEnum);
}
};
}
}

View File

@@ -22,6 +22,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore; import springfox.documentation.annotations.ApiIgnore;
import java.util.List;
/** /**
* <p> * <p>
* 前端控制器 * 前端控制器
@@ -69,5 +71,15 @@ public class AppInfoSetController extends BaseController {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
} }
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/getListById")
@ApiOperation("根据用户id查询消息配置信息")
@ApiImplicitParam(name = "list", value = "用户集合", required = true)
public HttpResult<List<AppInfoSet>> getListById(@RequestBody List<String> list){
String methodDescribe = getMethodDescribe("getListById");
List<AppInfoSet> result = appInfoSetService.getListById(list);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
} }

View File

@@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.user.pojo.param.AppInfoSetParam; import com.njcn.user.pojo.param.AppInfoSetParam;
import com.njcn.user.pojo.po.app.AppInfoSet; import com.njcn.user.pojo.po.app.AppInfoSet;
import java.util.List;
/** /**
* <p> * <p>
* 服务类 * 服务类
@@ -18,4 +20,11 @@ public interface IAppInfoSetService extends IService<AppInfoSet> {
*/ */
void updateAppInfo(AppInfoSetParam param); void updateAppInfo(AppInfoSetParam param);
/**
* 根据用户集合查询数据
* @param list
* @return
*/
List<AppInfoSet> getListById(List<String> list);
} }

View File

@@ -9,6 +9,8 @@ import com.njcn.web.utils.RequestUtil;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
/** /**
* <p> * <p>
* 服务实现类 * 服务实现类
@@ -27,4 +29,9 @@ public class AppInfoSetServiceImpl extends ServiceImpl<AppInfoSetMapper, AppInfo
appInfoSet.setUserId(RequestUtil.getUserIndex()); appInfoSet.setUserId(RequestUtil.getUserIndex());
this.updateById(appInfoSet); this.updateById(appInfoSet);
} }
@Override
public List<AppInfoSet> getListById(List<String> list) {
return this.lambdaQuery().in(AppInfoSet::getUserId,list).list();
}
} }