From f86f18817d2d69ae7bef253f0f68d9c895dabdd8 Mon Sep 17 00:00:00 2001 From: xy <748613696@qq.com> Date: Thu, 19 Sep 2024 14:25:17 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E4=BF=A1=E6=81=AF=E5=AF=B9?= =?UTF-8?q?=E5=A4=96=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../csdevice/api/CsSoftInfoFeignClient.java | 27 +++++++++++ .../CsSoftInfoClientFallbackFactory.java | 46 +++++++++++++++++++ .../csdevice/pojo/vo/DeviceManagerVO.java | 2 +- .../equipment/CsSoftInfoController.java | 30 ++++++++++-- .../csdevice/mapper/CsSoftInfoMapper.java | 2 +- .../csdevice/service/ICsSoftInfoService.java | 2 +- .../impl/CsEquipmentDeliveryServiceImpl.java | 1 - .../service/impl/CsSoftInfoServiceImpl.java | 2 +- 8 files changed, 102 insertions(+), 10 deletions(-) create mode 100644 cs-device/cs-device-api/src/main/java/com/njcn/csdevice/api/CsSoftInfoFeignClient.java create mode 100644 cs-device/cs-device-api/src/main/java/com/njcn/csdevice/api/fallback/CsSoftInfoClientFallbackFactory.java diff --git a/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/api/CsSoftInfoFeignClient.java b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/api/CsSoftInfoFeignClient.java new file mode 100644 index 0000000..372929b --- /dev/null +++ b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/api/CsSoftInfoFeignClient.java @@ -0,0 +1,27 @@ +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.CsSoftInfoClientFallbackFactory; +import com.njcn.csdevice.pojo.po.CsSoftInfoPO; +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; + +/** + * @author xy + */ +@FeignClient(value = ServerInfo.CS_DEVICE_BOOT, path = "/csSoftInfo", fallbackFactory = CsSoftInfoClientFallbackFactory.class,contextId = "csSoftInfo") +public interface CsSoftInfoFeignClient { + + @PostMapping("/findSoftInfo") + HttpResult findSoftInfo(@RequestParam("id") String id); + + @PostMapping("/saveSoftInfo") + HttpResult saveSoftInfo(@RequestBody CsSoftInfoPO po); + + @PostMapping("/removeSoftInfo") + HttpResult removeSoftInfo(@RequestParam("id") String id); + +} diff --git a/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/api/fallback/CsSoftInfoClientFallbackFactory.java b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/api/fallback/CsSoftInfoClientFallbackFactory.java new file mode 100644 index 0000000..7319329 --- /dev/null +++ b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/api/fallback/CsSoftInfoClientFallbackFactory.java @@ -0,0 +1,46 @@ +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.CsSoftInfoFeignClient; +import com.njcn.csdevice.pojo.po.CsSoftInfoPO; +import feign.hystrix.FallbackFactory; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * @author xy + */ +@Slf4j +@Component +public class CsSoftInfoClientFallbackFactory implements FallbackFactory { + @Override + public CsSoftInfoFeignClient create(Throwable cause) { + //判断抛出异常是否为解码器抛出的业务异常 + Enum exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK; + if (cause.getCause() instanceof BusinessException) { + BusinessException businessException = (BusinessException) cause.getCause(); + } + Enum finalExceptionEnum = exceptionEnum; + return new CsSoftInfoFeignClient() { + @Override + public HttpResult findSoftInfo(String id) { + log.error("{}异常,降级处理,异常为:{}","获取装置软件信息",cause.toString()); + throw new BusinessException(finalExceptionEnum); + } + + @Override + public HttpResult saveSoftInfo(CsSoftInfoPO po) { + log.error("{}异常,降级处理,异常为:{}","保存软件程序",cause.toString()); + throw new BusinessException(finalExceptionEnum); + } + + @Override + public HttpResult removeSoftInfo(String id) { + log.error("{}异常,降级处理,异常为:{}","删除软件程序",cause.toString()); + throw new BusinessException(finalExceptionEnum); + } + }; + } +} diff --git a/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/pojo/vo/DeviceManagerVO.java b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/pojo/vo/DeviceManagerVO.java index f8da36e..e94d1fb 100644 --- a/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/pojo/vo/DeviceManagerVO.java +++ b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/pojo/vo/DeviceManagerVO.java @@ -46,7 +46,7 @@ public class DeviceManagerVO { private String appVersion; @ApiModelProperty(value = "应用程序发布日期") - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") + @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8") private LocalDateTime appDate; @ApiModelProperty(value = "应用程序校验码") diff --git a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/controller/equipment/CsSoftInfoController.java b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/controller/equipment/CsSoftInfoController.java index 47d8054..31bb08d 100644 --- a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/controller/equipment/CsSoftInfoController.java +++ b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/controller/equipment/CsSoftInfoController.java @@ -1,13 +1,14 @@ package com.njcn.csdevice.controller.equipment; -import com.njcn.access.pojo.po.CsSoftInfoPO; import com.njcn.common.pojo.annotation.OperateInfo; import com.njcn.common.pojo.enums.common.LogEnum; import com.njcn.common.pojo.enums.response.CommonResponseEnum; import com.njcn.common.pojo.response.HttpResult; import com.njcn.common.utils.HttpResultUtil; import com.njcn.csdevice.mapper.CsSoftInfoMapper; +import com.njcn.csdevice.pojo.po.CsSoftInfoPO; +import com.njcn.csdevice.service.ICsSoftInfoService; import com.njcn.web.controller.BaseController; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -15,10 +16,7 @@ import io.swagger.annotations.ApiOperation; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; /** *

@@ -37,6 +35,7 @@ import org.springframework.web.bind.annotation.RestController; public class CsSoftInfoController extends BaseController { private final CsSoftInfoMapper csSoftInfoMapper; + private final ICsSoftInfoService csSoftInfoService; @OperateInfo(info = LogEnum.BUSINESS_COMMON) @PostMapping("/findSoftInfo") @@ -48,5 +47,26 @@ public class CsSoftInfoController extends BaseController { return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, po, methodDescribe); } + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @PostMapping("/saveSoftInfo") + @ApiOperation("保存程序软件信息") + @ApiImplicitParam(name = "id", value = "id", required = true) + public HttpResult saveSoftInfo(@RequestBody CsSoftInfoPO po){ + String methodDescribe = getMethodDescribe("saveSoftInfo"); + csSoftInfoService.save(po); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); + } + + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @PostMapping("/removeSoftInfo") + @ApiOperation("删除程序软件信息") + @ApiImplicitParam(name = "id", value = "id", required = true) + public HttpResult removeSoftInfo(@RequestParam String id){ + String methodDescribe = getMethodDescribe("removeSoftInfo"); + csSoftInfoService.removeById(id); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); + } + + } diff --git a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/mapper/CsSoftInfoMapper.java b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/mapper/CsSoftInfoMapper.java index 647013b..35c300b 100644 --- a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/mapper/CsSoftInfoMapper.java +++ b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/mapper/CsSoftInfoMapper.java @@ -1,7 +1,7 @@ package com.njcn.csdevice.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.njcn.access.pojo.po.CsSoftInfoPO; +import com.njcn.csdevice.pojo.po.CsSoftInfoPO; /** *

diff --git a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/ICsSoftInfoService.java b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/ICsSoftInfoService.java index f4e57c2..8f41f7b 100644 --- a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/ICsSoftInfoService.java +++ b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/ICsSoftInfoService.java @@ -1,7 +1,7 @@ package com.njcn.csdevice.service; import com.baomidou.mybatisplus.extension.service.IService; -import com.njcn.access.pojo.po.CsSoftInfoPO; +import com.njcn.csdevice.pojo.po.CsSoftInfoPO; /** *

diff --git a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsEquipmentDeliveryServiceImpl.java b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsEquipmentDeliveryServiceImpl.java index 622b0ad..ada272d 100644 --- a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsEquipmentDeliveryServiceImpl.java +++ b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsEquipmentDeliveryServiceImpl.java @@ -18,7 +18,6 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.njcn.access.api.AskDeviceDataFeignClient; -import com.njcn.access.pojo.po.CsSoftInfoPO; import com.njcn.common.pojo.exception.BusinessException; import com.njcn.csdevice.constant.DataParam; import com.njcn.csdevice.enums.AlgorithmResponseEnum; diff --git a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsSoftInfoServiceImpl.java b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsSoftInfoServiceImpl.java index e1f3a3b..1e2ced6 100644 --- a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsSoftInfoServiceImpl.java +++ b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsSoftInfoServiceImpl.java @@ -1,8 +1,8 @@ package com.njcn.csdevice.service.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.njcn.access.pojo.po.CsSoftInfoPO; import com.njcn.csdevice.mapper.CsSoftInfoMapper; +import com.njcn.csdevice.pojo.po.CsSoftInfoPO; import com.njcn.csdevice.service.ICsSoftInfoService; import org.springframework.stereotype.Service;