zbj//1.web新增用户信息添加日志

This commit is contained in:
zhangbaojian
2023-04-13 14:27:24 +08:00
parent 77ee5f7d81
commit cba065d25c
8 changed files with 178 additions and 6 deletions

View File

@@ -0,0 +1,33 @@
package com.njcn.device.pq.api;
import com.njcn.common.pojo.constant.ServerInfo;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.device.pq.api.fallback.PqsTerminalLogsClientFallbackFactory;
import com.njcn.device.pq.api.fallback.TerminalBaseClientFallbackFactory;
import com.njcn.device.pq.pojo.po.Line;
import com.njcn.device.pq.pojo.po.PqsTerminalLogs;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
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 hongawen
* @version 1.0.0
* @date 2022年02月14日 14:02
*/
@FeignClient(value = ServerInfo.DEVICE, path = "/pqsTerminalLogs", fallbackFactory = PqsTerminalLogsClientFallbackFactory.class, contextId = "pqsTerminalLogs")
public interface PqsTerminalLogsClient {
/**
* 新增日志表数据
*
* @author zbj
* @date 2023/4/13
*/
@PostMapping("/saveLogs")
HttpResult<Object> saveLogs(@RequestBody PqsTerminalLogs pqsTerminalLogs);
}

View File

@@ -0,0 +1,46 @@
package com.njcn.device.pq.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.device.pq.api.PqsTerminalLogsClient;
import com.njcn.device.pq.api.TerminalBaseClient;
import com.njcn.device.pq.pojo.po.Line;
import com.njcn.device.pq.pojo.po.PqsTerminalLogs;
import com.njcn.device.pq.utils.DeviceEnumUtil;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* @author zbj
* @version 1.0.0
* @date 2023年04月13日 13:34
*/
@Slf4j
@Component
public class PqsTerminalLogsClientFallbackFactory implements FallbackFactory<PqsTerminalLogsClient> {
@Override
public PqsTerminalLogsClient create(Throwable throwable) {
//判断抛出异常是否为解码器抛出的业务异常
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
if (throwable.getCause() instanceof BusinessException) {
BusinessException businessException = (BusinessException) throwable.getCause();
exceptionEnum = DeviceEnumUtil.getExceptionEnum(businessException.getResult());
}
Enum<?> finalExceptionEnum = exceptionEnum;
return new PqsTerminalLogsClient()
{
@Override
public HttpResult<Object> saveLogs(PqsTerminalLogs pqsTerminalLogs) {
log.error("{}异常,降级处理,异常为:{}", "新增日志表数据", throwable.toString());
throw new BusinessException(finalExceptionEnum);
}
};
}
}

View File

@@ -0,0 +1,57 @@
package com.njcn.device.pq.controller;
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.device.pq.pojo.po.PqsTerminalLogs;
import com.njcn.device.pq.service.IPqsTerminalLogsService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.njcn.web.controller.BaseController;
/**
* <p>
* 前端控制器
* </p>
*
* @author hongawen
* @since 2023-04-13
*/
@RestController
@RequestMapping("/pqsTerminalLogs")
@RequiredArgsConstructor
public class PqsTerminalLogsController extends BaseController {
private final IPqsTerminalLogsService iPqsTerminalLogsService;
/**
* 新增日志表数据
*
* @author zbj
* @date 2023/4/13
*/
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/saveLogs")
@ApiOperation("新增日志表数据")
@ApiImplicitParam(name = "pqsTerminalLogs", value = "实体", required = true)
public HttpResult<Object> saveLogs(@RequestBody PqsTerminalLogs pqsTerminalLogs) {
String methodDescribe = getMethodDescribe("saveLogs");
boolean res = iPqsTerminalLogsService.saveLogs(pqsTerminalLogs);
if (res) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
} else {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
}
}
}

View File

@@ -2,6 +2,7 @@ package com.njcn.device.pq.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.device.pq.pojo.po.PqsTerminalLogs;
import org.springframework.stereotype.Service;
/**
* <p>
@@ -9,8 +10,9 @@ import com.njcn.device.pq.pojo.po.PqsTerminalLogs;
* </p>
*
* @author hongawen
* @since 2023-04-12
* @since 2023-04-13
*/
@Service
public interface IPqsTerminalLogsService extends IService<PqsTerminalLogs> {
boolean saveLogs(PqsTerminalLogs pqsTerminalLogs);
}

View File

@@ -8,13 +8,17 @@ import org.springframework.stereotype.Service;
/**
* <p>
* 服务实现类
* 服务实现类
* </p>
*
* @author hongawen
* @since 2023-04-12
* @since 2023-04-13
*/
@Service
public class PqsTerminalLogsServiceImpl extends ServiceImpl<PqsTerminalLogsMapper, PqsTerminalLogs> implements IPqsTerminalLogsService {
@Override
public boolean saveLogs(PqsTerminalLogs pqsTerminalLogs) {
return this.save(pqsTerminalLogs);
}
}

View File

@@ -188,7 +188,7 @@ public class TerminalMaintainServiceImpl implements TerminalMaintainService {
sbNew.append("终端运行状态: ").append(newFlag).append(";");
sbOld.append("终端运行状态: ").append(oldFlag).append(";");
sb.append(sbNew).append(sbOld);
HttpResult<DictData> dicDataByCode = dicDataFeignClient.getDicDataByCode(DicDataEnum.LINE_PARAMETER.getCode());
HttpResult<DictData> dicDataByCode = dicDataFeignClient.getDicDataByCode(DicDataEnum.DEV_PARAMETER.getCode());
DictData data = dicDataByCode.getData();
//创建对象
PqsTerminalLogs terminalLogsNew = new PqsTerminalLogs();