Commit b3176264 by 向延琳

电量client

1 parent 7b187db5
package cn.com.glsx.stdinterface.api;
import cn.com.glsx.stdinterface.dto.DevicePowerDTO;
import cn.com.glsx.stdinterface.factory.FreqRecordFallbackFactory;
import com.glsx.plat.core.web.R;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
/**
* @author xiangyanlin
* @date 2022/4/12
*/
@FeignClient(name = "ne-shield-standard-interfaces", path = "/nesi/battery", fallbackFactory = FreqRecordFallbackFactory.class, decode404 = true)
public interface BatteryClient {
/**
* 保存电量信息
*
* @param devicePowerDTO
*/
@PostMapping(value = "/save")
R saveBatteryInfo(DevicePowerDTO devicePowerDTO);
}
......@@ -2,6 +2,7 @@ package cn.com.glsx.stdinterface.api;
import cn.com.glsx.stdinterface.dto.DeviceJourneyDTO;
import cn.com.glsx.stdinterface.factory.FreqRecordFallbackFactory;
import cn.com.glsx.stdinterface.factory.JourneyFallbackFactory;
import com.glsx.plat.core.web.R;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
......@@ -12,7 +13,7 @@ import org.springframework.web.bind.annotation.PostMapping;
* @author xiangyanlin
* @date 2022/4/7
*/
@FeignClient(name = "ne-shield-standard-interfaces", path = "/nesi/journey", fallbackFactory = FreqRecordFallbackFactory.class, decode404 = true)
@FeignClient(name = "ne-shield-standard-interfaces", path = "/nesi/journey", fallbackFactory = JourneyFallbackFactory.class, decode404 = true)
public interface JourneyClient {
/**
......@@ -20,6 +21,6 @@ public interface JourneyClient {
*
* @param deviceJourneyDTO
*/
@PostMapping(value = "/saveDeviceJourney")
@PostMapping(value = "/save")
R saveDeviceJourney(DeviceJourneyDTO deviceJourneyDTO);
}
package cn.com.glsx.stdinterface.dto;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.Id;
import java.io.Serializable;
import java.util.Date;
/**
* @author xiangyanlin
* @date 2022/4/12
*/
@Data
public class DevicePowerDTO implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 电量主键ID
*/
private Long id;
/**
* 设备序列号
*/
private String sn;
/**
* 车辆、设备关系id
*/
private Integer vdId;
/**
* 电量上传时间
*/
private Date alarmTime;
/**
* 设备剩余电量
*/
private Integer soc;
/**
* 创建时间|入库时间
*/
private Date createdDate;
/**
* 创建人用户id
*/
private Long createdBy;
/**
* 更新时间
*/
private Date updatedDate;
/**
* 更新人用户id
*/
private Long updatedBy;
}
package cn.com.glsx.stdinterface.factory;
import cn.com.glsx.stdinterface.api.BatteryClient;
import cn.com.glsx.stdinterface.fallback.BatteryFallbackImpl;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;
/**
* @author xiangyanlin
* @date 2022/4/12
*/
@Component
public class BatteryFallbackFactory implements FallbackFactory<BatteryClient> {
@Override
public BatteryClient create(Throwable throwable) {
BatteryFallbackImpl fallback = new BatteryFallbackImpl();
fallback.setCause(throwable);
return fallback;
}
}
......@@ -3,12 +3,14 @@ package cn.com.glsx.stdinterface.factory;
import cn.com.glsx.stdinterface.api.JourneyClient;
import cn.com.glsx.stdinterface.fallback.JourneyFallbackImpl;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;
/**
* 里程
* @author xiangyanlin
* @date 2022/4/8
*/
@Component
public class JourneyFallbackFactory implements FallbackFactory<JourneyClient> {
@Override
......
package cn.com.glsx.stdinterface.fallback;
import cn.com.glsx.stdinterface.api.BatteryClient;
import cn.com.glsx.stdinterface.dto.DevicePowerDTO;
import com.glsx.plat.core.web.R;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* @author xiangyanlin
* @date 2022/4/12
*/
@Slf4j
@Component
public class BatteryFallbackImpl implements BatteryClient {
@Setter
private Throwable cause;
@Override
public R saveBatteryInfo(DevicePowerDTO devicePowerDTO) {
log.warn("DevicePowerDTO 熔断啦 {}", cause.getMessage());
return R.ok("服务异常");
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!