package com.zt.plat.module.qms.common.data.controller.admin;

import com.zt.plat.module.qms.common.data.controller.vo.DataKeyCheckPageReqVO;
import com.zt.plat.module.qms.common.data.controller.vo.DataKeyCheckRespVO;
import com.zt.plat.module.qms.common.data.controller.vo.DataKeyCheckSaveReqVO;
import com.zt.plat.module.qms.common.data.dal.dataobject.DataKeyCheckDO;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import com.zt.plat.framework.business.interceptor.BusinessControllerMarker;

import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import jakarta.validation.*;

import com.zt.plat.framework.common.pojo.vo.BatchDeleteReqVO;
import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.common.pojo.CommonResult;
import com.zt.plat.framework.common.util.object.BeanUtils;
import com.zt.plat.framework.datapermission.core.annotation.DeptDataPermissionIgnore;

import static com.zt.plat.framework.common.pojo.CommonResult.success;

import com.zt.plat.module.qms.common.data.service.DataKeyCheckService;

@Tag(name = "管理后台 - 数据重复校验")
@RestController
@RequestMapping("/qms/data-key-check")
@Validated
@DeptDataPermissionIgnore(enable = "true")
public class DataKeyCheckController implements BusinessControllerMarker {


    @Resource
    private DataKeyCheckService dataKeyCheckService;

    @PostMapping("/create")
    @Operation(summary = "创建数据重复校验")
    @PreAuthorize("@ss.hasPermission('qms:data-key-check:create')")
    public CommonResult<DataKeyCheckRespVO> createDataKeyCheck(@Valid @RequestBody DataKeyCheckSaveReqVO createReqVO) {
        return success(dataKeyCheckService.createDataKeyCheck(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新数据重复校验")
    @PreAuthorize("@ss.hasPermission('qms:data-key-check:update')")
    public CommonResult<Boolean> updateDataKeyCheck(@Valid @RequestBody DataKeyCheckSaveReqVO updateReqVO) {
        dataKeyCheckService.updateDataKeyCheck(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除数据重复校验")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('qms:data-key-check:delete')")
    public CommonResult<Boolean> deleteDataKeyCheck(@RequestParam("id") String id) {
        dataKeyCheckService.deleteDataKeyCheck(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得数据重复校验")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('qms:data-key-check:query')")
    public CommonResult<DataKeyCheckRespVO> getDataKeyCheck(@RequestParam("id") String id) {
        DataKeyCheckDO dataKeyCheck = dataKeyCheckService.getDataKeyCheck(id);
        return success(BeanUtils.toBean(dataKeyCheck, DataKeyCheckRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得数据重复校验分页")
    @PreAuthorize("@ss.hasPermission('qms:data-key-check:query')")
    public CommonResult<PageResult<DataKeyCheckRespVO>> getDataKeyCheckPage(@Valid DataKeyCheckPageReqVO pageReqVO) {
        PageResult<DataKeyCheckDO> pageResult = dataKeyCheckService.getDataKeyCheckPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, DataKeyCheckRespVO.class));
    }


}