package com.njcn.system.controller;


import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.OperateType;
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.common.utils.LogUtil;
import com.njcn.system.pojo.po.RocketmqMsgErrorLog;
import com.njcn.system.service.IRocketmqMsgErrorLogService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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>
 * rocketmq消息处理记录表 前端控制器
 * </p>
 *
 * @author hongawen
 * @since 2023-08-17
 */
@Slf4j
@RestController
@RequestMapping("/rocketmqMsgErrorLog")
@RequiredArgsConstructor
public class RocketmqMsgErrorLogController extends BaseController {

    private final IRocketmqMsgErrorLogService rocketmqMsgErrorLogService;

    /**
     * 新增消息异常记录
     *
     * @param rocketmqMsgErrorLog 消息异常数据
     */
    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.ADD)
    @PostMapping("/add")
    @ApiOperation("新增消息异常记录")
    @ApiImplicitParam(name = "rocketmqMsgErrorLog", value = "消息异常数据", required = true)
    public HttpResult<Object> add(@RequestBody RocketmqMsgErrorLog rocketmqMsgErrorLog) {
        String methodDescribe = getMethodDescribe("add");
        LogUtil.njcnDebug(log, "{}，消息异常数据：{}", methodDescribe, rocketmqMsgErrorLog);
        boolean result = rocketmqMsgErrorLogService.save(rocketmqMsgErrorLog);
        if (result) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
        } else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
        }
    }


}

