refactor(event): 重构事件统计功能并迁移消息推送服务
- 移除暂态事件统计相关接口和实现方法 - 删除EventStatisticsVo相关代码 - 将设备消息推送功能从CsEventPOServiceImpl迁移到新创建的DeviceMessageService - 新增DeviceMessageFeignClient用于服务间调用 - 实现DeviceMessageController提供统一的消息推送接口
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package com.njcn.csdevice.api;
|
||||
|
||||
import com.njcn.common.pojo.constant.ServerInfo;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.csdevice.api.fallback.DeviceMessageClientFallbackFactory;
|
||||
import com.njcn.csdevice.param.DeviceMessageParam;
|
||||
import com.njcn.user.pojo.po.User;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@FeignClient(value = ServerInfo.CS_DEVICE_BOOT, path = "/deviceMessage", fallbackFactory = DeviceMessageClientFallbackFactory.class,contextId = "deviceMessage")
|
||||
public interface DeviceMessageFeignClient {
|
||||
|
||||
@PostMapping("/getEventUserByDeviceId")
|
||||
@ApiOperation("根据设备获取需要推送的用户id")
|
||||
HttpResult<List<String>> getEventUserByDeviceId(@RequestParam("devId") String devId, @RequestParam("isAdmin") Boolean isAdmin);
|
||||
|
||||
@PostMapping("/getSendUserByType")
|
||||
@ApiOperation("根据事件类型和用户id查询打开推送的用户信息")
|
||||
HttpResult<List<User>> getSendUserByType(@RequestBody DeviceMessageParam param);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.njcn.csdevice.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.csdevice.api.DeviceMessageFeignClient;
|
||||
import com.njcn.csdevice.param.DeviceMessageParam;
|
||||
import com.njcn.user.pojo.po.User;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class DeviceMessageClientFallbackFactory implements FallbackFactory<DeviceMessageFeignClient> {
|
||||
@Override
|
||||
public DeviceMessageFeignClient create(Throwable cause) {
|
||||
//判断抛出异常是否为解码器抛出的业务异常
|
||||
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
|
||||
if (cause.getCause() instanceof BusinessException) {
|
||||
BusinessException businessException = (BusinessException) cause.getCause();
|
||||
}
|
||||
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||
return new DeviceMessageFeignClient() {
|
||||
|
||||
@Override
|
||||
public HttpResult<List<String>> getEventUserByDeviceId(String devId, Boolean isAdmin) {
|
||||
log.error("{}异常,降级处理,异常为:{}","根据设备获取需要推送的用户id数据异常",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpResult<List<User>> getSendUserByType(DeviceMessageParam param) {
|
||||
log.error("{}异常,降级处理,异常为:{}","根据事件类型和用户id查询打开推送的用户信息数据异常",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.njcn.csdevice.param;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Data
|
||||
public class DeviceMessageParam {
|
||||
|
||||
@ApiModelProperty("用户id集合")
|
||||
private List<String> userList;
|
||||
|
||||
@ApiModelProperty("事件类型 0:暂态 1:稳态 2:运行 3:告警")
|
||||
private Integer eventType;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user