package cn.iocoder.yudao.module.inspection.controller;

import cn.iocoder.yudao.module.inspection.entity.DlInspectionProject;
import cn.iocoder.yudao.module.inspection.service.DlInspectionProjectService;
import cn.iocoder.yudao.module.inspection.vo.DlInspectionProjectPageReqVO;
import cn.iocoder.yudao.module.inspection.vo.DlInspectionProjectRespVO;
import cn.iocoder.yudao.module.inspection.vo.DlInspectionProjectSaveReqVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;


@Tag(name = "管理后台 - 检测项目")
@RestController
@RequestMapping("/admin-api/inspection/dl-inspection-project")
@Validated
public class DlInspectionProjectController {

    @Resource
    private DlInspectionProjectService dlInspectionProjectService;

    @PostMapping("/create")
    @Operation(summary = "创建检测项目")
//    @PreAuthorize("@ss.hasPermission('inspection:dl-inspection-project:create')")
    public CommonResult<String> createDlInspectionProject(@Valid @RequestBody DlInspectionProjectSaveReqVO createReqVO) {
        return success(dlInspectionProjectService.createDlInspectionProject(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新检测项目")
//    @PreAuthorize("@ss.hasPermission('inspection:dl-inspection-project:update')")
    public CommonResult<Boolean> updateDlInspectionProject(@Valid @RequestBody DlInspectionProjectSaveReqVO updateReqVO) {
        dlInspectionProjectService.updateDlInspectionProject(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除检测项目")
    @Parameter(name = "id", description = "编号", required = true)
//    @PreAuthorize("@ss.hasPermission('inspection:dl-inspection-project:delete')")
    public CommonResult<Boolean> deleteDlInspectionProject(@RequestParam("id") String id) {
        dlInspectionProjectService.deleteDlInspectionProject(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得检测项目")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
//    @PreAuthorize("@ss.hasPermission('inspection:dl-inspection-project:query')")
    public CommonResult<DlInspectionProjectRespVO> getDlInspectionProject(@RequestParam("id") String id) {
        DlInspectionProject dlInspectionProject = dlInspectionProjectService.getDlInspectionProject(id);
        return success(BeanUtils.toBean(dlInspectionProject, DlInspectionProjectRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得检测项目分页")
//    @PreAuthorize("@ss.hasPermission('inspection:dl-inspection-project:query')")
    public CommonResult<IPage<DlInspectionProjectRespVO>> getDlInspectionProjectPage(@Valid DlInspectionProjectPageReqVO pageReqVO,
                                                                                          @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                                                          @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        IPage page = new Page<>(pageNo, pageSize);
        IPage<DlInspectionProjectRespVO> pageResult = dlInspectionProjectService.getDlInspectionProjectPage(page,pageReqVO);
        return success(pageResult);
    }


}