package com.njcn.csdevice.controller.equipment;

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.csdevice.pojo.po.CsUpgradeLogs;
import com.njcn.csdevice.service.CsUpgradeLogsService;
import com.njcn.web.controller.BaseController;
import com.njcn.web.utils.RequestUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
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.*;

import java.util.List;

/**
 * @author caozehui
 * @data 2026-04-23
 */
@Slf4j
@RestController
@RequestMapping("/csUpgradeLogs")
@Api(tags = "装置升级日志")
@AllArgsConstructor
@Validated
public class CsUpgradeLogsController extends BaseController {
    private final CsUpgradeLogsService csUpgradeLogsService;

    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.ADD)
    @PostMapping("/add")
    @ApiOperation("新增升级日志")
    @ApiImplicitParam(name = "csUpgradeLogs", value = "日志参数", required = true)
    public HttpResult add(@RequestBody CsUpgradeLogs csUpgradeLogs) {
        csUpgradeLogs.setUserName(RequestUtil.getUsername());
        csUpgradeLogs.setLoginName(RequestUtil.getLoginName());
        String methodDescribe = getMethodDescribe("add");
        return HttpResultUtil.assembleCommonResponseResult(csUpgradeLogsService.save(csUpgradeLogs) ? CommonResponseEnum.SUCCESS : CommonResponseEnum.FAIL, null, methodDescribe);
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.ADD)
    @GetMapping("/getByDevId")
    @ApiOperation("查询指定devId的所有升级日志")
    @ApiImplicitParam(name = "devId", value = "装置Id", required = true)
    public HttpResult<List<CsUpgradeLogs>> getByDevId(@RequestParam("devId") String devId) {
        String methodDescribe = getMethodDescribe("getByDevId");
        List<CsUpgradeLogs> result = csUpgradeLogsService.lambdaQuery().eq(CsUpgradeLogs::getDevId, devId).list();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }
}
