设备注册功能优化

This commit is contained in:
2023-10-13 10:50:38 +08:00
parent b12eb6dcea
commit 332ea634ad
17 changed files with 264 additions and 61 deletions

View File

@@ -3,6 +3,7 @@ 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.CsLineClientFallbackFactory;
import com.njcn.csdevice.pojo.param.CsLineParam;
import com.njcn.csdevice.pojo.po.CsLinePO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
@@ -32,4 +33,7 @@ public interface CsLineFeignClient {
@PostMapping("/getPositionById")
HttpResult<String> getPositionById(@RequestParam("id") String id);
@PostMapping("/updateLine")
HttpResult<String> updateLine(@RequestBody CsLineParam csLineParam);
}

View File

@@ -0,0 +1,22 @@
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.DevCapacityClientFallbackFactory;
import com.njcn.csdevice.pojo.po.CsDevCapacityPO;
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 xy
*/
@FeignClient(value = ServerInfo.CS_DEVICE_BOOT, path = "/capacity", fallbackFactory = DevCapacityClientFallbackFactory.class,contextId = "capacity")
public interface DevCapacityFeignClient {
@PostMapping("/addList")
HttpResult<List<String>> addList(@RequestBody List<CsDevCapacityPO> list);
}

View File

@@ -36,4 +36,18 @@ public interface EquipmentFeignClient {
*/
@PostMapping("/findDevByNDid")
HttpResult<CsEquipmentDeliveryPO> findDevByNDid(@RequestParam("nDid") String nDid);
/**
* 根据nDid更新软件信息
* @return
*/
@PostMapping("/updateSoftInfo")
HttpResult<String> updateSoftInfo(@RequestParam("nDid") String nDid,@RequestParam("id") String id);
/**
* 根据nDid更新模块信息
* @return
*/
@PostMapping("/updateModuleNumber")
HttpResult<String> updateModuleNumber(@RequestParam("nDid") String nDid,@RequestParam("number") Integer number);
}

View File

@@ -4,6 +4,7 @@ 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.CsLineFeignClient;
import com.njcn.csdevice.pojo.param.CsLineParam;
import com.njcn.csdevice.pojo.po.CsLinePO;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
@@ -56,6 +57,12 @@ public class CsLineClientFallbackFactory implements FallbackFactory<CsLineFeignC
log.error("{}异常,降级处理,异常为:{}","通过id查询监测点位置",cause.toString());
throw new BusinessException(finalExceptionEnum);
}
@Override
public HttpResult<String> updateLine(CsLineParam csLineParam) {
log.error("{}异常,降级处理,异常为:{}","更新监测点信息",cause.toString());
throw new BusinessException(finalExceptionEnum);
}
};
}
}

View File

@@ -0,0 +1,38 @@
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.DevCapacityFeignClient;
import com.njcn.csdevice.pojo.po.CsDevCapacityPO;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* @author xy
*/
@Slf4j
@Component
public class DevCapacityClientFallbackFactory implements FallbackFactory<DevCapacityFeignClient> {
@Override
public DevCapacityFeignClient create(Throwable cause) {
//判断抛出异常是否为解码器抛出的业务异常
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
if (cause.getCause() instanceof BusinessException) {
BusinessException businessException = (BusinessException) cause.getCause();
}
Enum<?> finalExceptionEnum = exceptionEnum;
return new DevCapacityFeignClient() {
@Override
public HttpResult<List<String>> addList(List<CsDevCapacityPO> list) {
log.error("{}异常,降级处理,异常为:{}","批量新增设备模块容量",cause.toString());
throw new BusinessException(finalExceptionEnum);
}
};
}
}

View File

@@ -59,6 +59,18 @@ public class EquipmentFeignClientFallbackFactory implements FallbackFactory<Equi
log.error("{}异常,降级处理,异常为:{}","通过nDid查询设备信息",cause.toString());
throw new BusinessException(finalExceptionEnum);
}
@Override
public HttpResult<String> updateSoftInfo(String nDid, String id) {
log.error("{}异常,降级处理,异常为:{}","更新设备软件信息",cause.toString());
throw new BusinessException(finalExceptionEnum);
}
@Override
public HttpResult<String> updateModuleNumber(String nDid, Integer number) {
log.error("{}异常,降级处理,异常为:{}","更新设备模块个数",cause.toString());
throw new BusinessException(finalExceptionEnum);
}
};
}
}