package com.njcn.supervision.controller.databank;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.LibTemplateParam;
import com.njcn.supervision.pojo.po.databank.LibTemplate;
import com.njcn.supervision.service.databank.LibTemplateService;
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.*;

/**
 * Description:
 * Date: 2024/9/10  16:49【需求编号】
 *
 * @author clam
 * @version V1.0.0
 */
@Slf4j
@RestController
@RequestMapping("/libtemplate")
@Api(tags = "模版库")
@AllArgsConstructor
public class LibTemplateController extends BaseController {

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

    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.UPDATE)
    @PostMapping("/updateTemplate")
    @ApiOperation("更新")
    @ApiImplicitParam(name = "paramUpdate", value = "实体参数", required = true)
    public HttpResult<String> updateTemplate(@RequestBody @Validated LibTemplateParam.LibTemplateParamUpdate paramUpdate) {
        String methodDescribe = getMethodDescribe("updateTemplate");
        String id = libTemplateService.updateTemplate(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 = libTemplateService.lambdaUpdate().set(LibTemplate::getStatus, 0).eq(LibTemplate::getId, id).update();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, update, methodDescribe);
    }

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

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/pageQuery")
    @ApiOperation("分页查询案例库")
    @ApiImplicitParam(name = "param", value = "参数", required = true)
    public HttpResult<Page<LibTemplate>> pageQuery(@RequestBody @Validated LibTemplateParam.LibTemplateParamQuery param) {
        String methodDescribe = getMethodDescribe("pageQuery");
        Page<LibTemplate> list = libTemplateService.pageQuery(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }
}
