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.LibAlgorithmParam;
import com.njcn.supervision.pojo.po.databank.LibAlgorithm;
import com.njcn.supervision.service.databank.LibAlgorithmService;
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  14:26【需求编号】
 *
 * @author clam
 * @version V1.0.0
 */
@Slf4j
@RestController
@RequestMapping("/libalgorithm")
@Api(tags = "算法库")
@AllArgsConstructor
public class LibAlgorithmController  extends BaseController {

    private final LibAlgorithmService libAlgorithmService;

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

    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.UPDATE)
    @PostMapping("/updateAlgorithmLibrary")
    @ApiOperation("更新")
    @ApiImplicitParam(name = "paramUpdate", value = "实体参数", required = true)
    public HttpResult<String> updateAlgorithmLibrary(@RequestBody @Validated LibAlgorithmParam.LibAlgorithmParamUpdate paramUpdate) {
        String methodDescribe = getMethodDescribe("updateAlgorithmLibrary");
        String id = libAlgorithmService.updateAlgorithmLibrary(paramUpdate);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, id, methodDescribe);
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @GetMapping("/queryAllAlgorithmLibrary")
    @ApiOperation("查询所有算法库树结构")
    public HttpResult<List<LibAlgorithm>> queryAllAlgorithmLibrary() {
        String methodDescribe = getMethodDescribe("queryAll");
        List<LibAlgorithm> result = libAlgorithmService.queryAll();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @GetMapping("/queryById")
    @ApiOperation("根据id查询")
    public HttpResult<LibAlgorithm> queryById(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("queryById");
        LibAlgorithm result = libAlgorithmService.lambdaQuery().eq(LibAlgorithm::getId,id).one();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, 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 = libAlgorithmService.lambdaUpdate().set(LibAlgorithm::getStatus, 0).eq(LibAlgorithm::getId, id).update();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, update, methodDescribe);
    }
}
