From b85b20aa76a54e80d250ce1bf1fe0801579eac9a Mon Sep 17 00:00:00 2001 From: xuyang <748613696@qq.com> Date: Tue, 11 Apr 2023 15:28:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../algorithm/api/DevModelFeignClient.java | 28 ++++++++++ .../DevModelFeignClientFallbackFactory.java | 52 +++++++++++++++++++ .../prepare/harmonic/utils/PublicUtil.java | 1 + 3 files changed, 81 insertions(+) create mode 100644 pqs-algorithm/algorithm-api/src/main/java/com/njcn/algorithm/api/DevModelFeignClient.java create mode 100644 pqs-algorithm/algorithm-api/src/main/java/com/njcn/algorithm/api/fallback/DevModelFeignClientFallbackFactory.java diff --git a/pqs-algorithm/algorithm-api/src/main/java/com/njcn/algorithm/api/DevModelFeignClient.java b/pqs-algorithm/algorithm-api/src/main/java/com/njcn/algorithm/api/DevModelFeignClient.java new file mode 100644 index 000000000..1896efdc7 --- /dev/null +++ b/pqs-algorithm/algorithm-api/src/main/java/com/njcn/algorithm/api/DevModelFeignClient.java @@ -0,0 +1,28 @@ +package com.njcn.algorithm.api; + +import com.njcn.algorithm.api.fallback.DevModelFeignClientFallbackFactory; +import com.njcn.algorithm.pojo.param.CsDevModelAddParm; +import com.njcn.algorithm.pojo.param.CsDevModelQueryListParm; +import com.njcn.algorithm.pojo.vo.CsDevModelPageVO; +import com.njcn.common.pojo.constant.ServerInfo; +import com.njcn.common.pojo.response.HttpResult; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; + +import java.util.List; + +/** + * @author xy + */ +@FeignClient(value = ServerInfo.ALGORITHM_BOOT, path = "/devmodel", fallbackFactory = DevModelFeignClientFallbackFactory.class,contextId = "devmodel") + +public interface DevModelFeignClient { + + @PostMapping("/addDevModel") + HttpResult addDevModel(@RequestBody @Validated CsDevModelAddParm csDevModelAddParm); + + @PostMapping("/queryEquipmentByProject") + HttpResult> queryEquipmentByProject(@RequestBody CsDevModelQueryListParm csDevModelQueryListParm); +} diff --git a/pqs-algorithm/algorithm-api/src/main/java/com/njcn/algorithm/api/fallback/DevModelFeignClientFallbackFactory.java b/pqs-algorithm/algorithm-api/src/main/java/com/njcn/algorithm/api/fallback/DevModelFeignClientFallbackFactory.java new file mode 100644 index 000000000..09cd656d0 --- /dev/null +++ b/pqs-algorithm/algorithm-api/src/main/java/com/njcn/algorithm/api/fallback/DevModelFeignClientFallbackFactory.java @@ -0,0 +1,52 @@ +package com.njcn.algorithm.api.fallback; + +import com.njcn.algorithm.api.DevModelFeignClient; +import com.njcn.algorithm.api.EquipmentFeignClient; +import com.njcn.algorithm.pojo.param.CsDevModelAddParm; +import com.njcn.algorithm.pojo.param.CsDevModelQueryListParm; +import com.njcn.algorithm.pojo.vo.CsDevModelPageVO; +import com.njcn.algorithm.pojo.vo.CsEquipmentDeliveryVO; +import com.njcn.common.pojo.enums.response.CommonResponseEnum; +import com.njcn.common.pojo.exception.BusinessException; +import com.njcn.common.pojo.response.HttpResult; +import lombok.extern.slf4j.Slf4j; +import org.springframework.cloud.openfeign.FallbackFactory; +import org.springframework.stereotype.Component; + +import java.util.List; + +/** + * 类的介绍: + * + * @author xuyang + * @version 1.0.0 + * @createTime 2023/4/10 20:09 + */ +@Slf4j +@Component +public class DevModelFeignClientFallbackFactory implements FallbackFactory { + @Override + public DevModelFeignClient 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 DevModelFeignClient() { + + @Override + public HttpResult addDevModel(CsDevModelAddParm csDevModelAddParm) { + log.error("{}异常,降级处理,异常为:{}","新增装置模板版本信息",cause.toString()); + throw new BusinessException(finalExceptionEnum); + } + + @Override + public HttpResult> queryEquipmentByProject(CsDevModelQueryListParm csDevModelQueryListParm) { + log.error("{}异常,降级处理,异常为:{}","查询模板版本信息",cause.toString()); + throw new BusinessException(finalExceptionEnum); + } + }; + } +} diff --git a/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/utils/PublicUtil.java b/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/utils/PublicUtil.java index 1c7e6e960..f81e01769 100644 --- a/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/utils/PublicUtil.java +++ b/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/utils/PublicUtil.java @@ -120,6 +120,7 @@ public class PublicUtil { if(month>=10 && i>=10){ date = year +"-"+month+"-"+i; } + date = date + " 00:00:00"; list.add(date); } return list;