package com.njcn.supervision.controller.databank;

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.supervision.pojo.param.databank.LibStandardParam;
import com.njcn.supervision.pojo.po.databank.LibStandard;
import com.njcn.supervision.service.databank.LibStandardService;
import com.njcn.web.controller.BaseController;
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;

/**
 * Description:
 * Date: 2024/9/10  16:26【需求编号】
 *
 * @author clam
 * @version V1.0.0
 */
@Slf4j
@RestController
@RequestMapping("/libstandard")
@Api(tags = "标准库")
@AllArgsConstructor
public class LibStandardController extends BaseController {

    private final LibStandardService libStandardService;
    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.ADD)
    @PostMapping("/add")
    @ApiOperation("新增")
    @ApiImplicitParam(name = "libStandardParam", value = "实体参数", required = true)
    public HttpResult<LibStandard> add(@RequestBody @Validated LibStandardParam libStandardParam) {
        String methodDescribe = getMethodDescribe("add");
        LibStandard add = libStandardService.add(libStandardParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, add, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.UPDATE)
    @PostMapping("/updateStandardLibrary")
    @ApiOperation("更新")
    @ApiImplicitParam(name = "paramUpdate", value = "实体参数", required = true)
    public HttpResult<String> updateStandardLibrary(@RequestBody @Validated LibStandardParam.LibStandardParamUpdate paramUpdate) {
        String methodDescribe = getMethodDescribe("updateStandardLibrary");
        String id = libStandardService.updateStandardLibrary(paramUpdate);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, id, methodDescribe);
    }
    @OperateInfo(info = LogEnum.SYSTEM_COMMON,operateType = OperateType.DELETE)
    @GetMapping("/deleteyById")
    @ApiOperation("通过id删除")
    public HttpResult<Boolean> deleteyById(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("deleteyById");
        boolean update = libStandardService.lambdaUpdate().set(LibStandard::getStatus, 0).eq(LibStandard::getId, id).update();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, update, methodDescribe);
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @GetMapping("/queryById")
    @ApiOperation("根据id查询")
    public HttpResult<LibStandard> queryById(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("queryById");
        LibStandard result = libStandardService.lambdaQuery().eq(LibStandard::getId,id).one();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @GetMapping("/queryAll")
    @ApiOperation("查询所有标准库树结构")
    public HttpResult<List<LibStandard>> queryAll() {
        String methodDescribe = getMethodDescribe("queryAll");
        List<LibStandard> result = libStandardService.queryAll();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }
}
