package com.zt.plat.module.qms.business.bus.controller.admin;

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.constraints.*;
import jakarta.validation.*;
import jakarta.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.zt.plat.framework.common.pojo.vo.BatchDeleteReqVO;
import com.zt.plat.framework.common.pojo.PageParam;
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.framework.excel.core.util.ExcelUtils;
import com.zt.plat.module.qms.business.bus.controller.vo.*;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessQCManagementSampleParameterDataDO;
import com.zt.plat.module.qms.business.bus.service.BusinessQCManagementSampleParameterDataService;
import com.zt.plat.framework.apilog.core.annotation.ApiAccessLog;
import static com.zt.plat.framework.apilog.core.enums.OperateTypeEnum.*;

@Tag(name = "管理后台 - 质控管理样检测任务参数业务表,与子样检测任务参数业务表T_BSN_ASY_TSK_PRM_DAT一样，针对标准样、管理样、质控样、监控样等样品的参数")
@RestController
@RequestMapping("/qms/business-QC-management-sample-parameter-data")
@Validated
@DeptDataPermissionIgnore(enable = "true")
public class BusinessQCManagementSampleParameterDataController implements BusinessControllerMarker {


    @Resource
    private BusinessQCManagementSampleParameterDataService businessQCManagementSampleParameterDataService;

    @PostMapping("/create")
    @Operation(summary = "创建质控管理样检测任务参数业务表,与子样检测任务参数业务表T_BSN_ASY_TSK_PRM_DAT一样，针对标准样、管理样、质控样、监控样等样品的参数")
    @PreAuthorize("@ss.hasPermission('qms:business-QC-management-sample-parameter-data:create')")
    public CommonResult<BusinessQCManagementSampleParameterDataRespVO> createBusinessQCManagementSampleParameterData(@Valid @RequestBody BusinessQCManagementSampleParameterDataSaveReqVO createReqVO) {
        return success(businessQCManagementSampleParameterDataService.createBusinessQCManagementSampleParameterData(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新质控管理样检测任务参数业务表,与子样检测任务参数业务表T_BSN_ASY_TSK_PRM_DAT一样，针对标准样、管理样、质控样、监控样等样品的参数")
    @PreAuthorize("@ss.hasPermission('qms:business-QC-management-sample-parameter-data:update')")
    public CommonResult<Boolean> updateBusinessQCManagementSampleParameterData(@Valid @RequestBody BusinessQCManagementSampleParameterDataSaveReqVO updateReqVO) {
        businessQCManagementSampleParameterDataService.updateBusinessQCManagementSampleParameterData(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除质控管理样检测任务参数业务表,与子样检测任务参数业务表T_BSN_ASY_TSK_PRM_DAT一样，针对标准样、管理样、质控样、监控样等样品的参数")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('qms:business-QC-management-sample-parameter-data:delete')")
    public CommonResult<Boolean> deleteBusinessQCManagementSampleParameterData(@RequestParam("id") Long id) {
        businessQCManagementSampleParameterDataService.deleteBusinessQCManagementSampleParameterData(id);
        return success(true);
    }

    @DeleteMapping("/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除质控管理样检测任务参数业务表,与子样检测任务参数业务表T_BSN_ASY_TSK_PRM_DAT一样，针对标准样、管理样、质控样、监控样等样品的参数")
                @PreAuthorize("@ss.hasPermission('qms:business-QC-management-sample-parameter-data:delete')")
    public CommonResult<Boolean> deleteBusinessQCManagementSampleParameterDataList(@RequestBody BatchDeleteReqVO req) {
        businessQCManagementSampleParameterDataService.deleteBusinessQCManagementSampleParameterDataListByIds(req.getIds());
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得质控管理样检测任务参数业务表,与子样检测任务参数业务表T_BSN_ASY_TSK_PRM_DAT一样，针对标准样、管理样、质控样、监控样等样品的参数")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('qms:business-QC-management-sample-parameter-data:query')")
    public CommonResult<BusinessQCManagementSampleParameterDataRespVO> getBusinessQCManagementSampleParameterData(@RequestParam("id") Long id) {
        BusinessQCManagementSampleParameterDataDO businessQCManagementSampleParameterData = businessQCManagementSampleParameterDataService.getBusinessQCManagementSampleParameterData(id);
        return success(BeanUtils.toBean(businessQCManagementSampleParameterData, BusinessQCManagementSampleParameterDataRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得质控管理样检测任务参数业务表,与子样检测任务参数业务表T_BSN_ASY_TSK_PRM_DAT一样，针对标准样、管理样、质控样、监控样等样品的参数分页")
    @PreAuthorize("@ss.hasPermission('qms:business-QC-management-sample-parameter-data:query')")
    public CommonResult<PageResult<BusinessQCManagementSampleParameterDataRespVO>> getBusinessQCManagementSampleParameterDataPage(@Valid BusinessQCManagementSampleParameterDataPageReqVO pageReqVO) {
        PageResult<BusinessQCManagementSampleParameterDataDO> pageResult = businessQCManagementSampleParameterDataService.getBusinessQCManagementSampleParameterDataPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, BusinessQCManagementSampleParameterDataRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出质控管理样检测任务参数业务表,与子样检测任务参数业务表T_BSN_ASY_TSK_PRM_DAT一样，针对标准样、管理样、质控样、监控样等样品的参数 Excel")
    @PreAuthorize("@ss.hasPermission('qms:business-QC-management-sample-parameter-data:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportBusinessQCManagementSampleParameterDataExcel(@Valid BusinessQCManagementSampleParameterDataPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<BusinessQCManagementSampleParameterDataDO> list = businessQCManagementSampleParameterDataService.getBusinessQCManagementSampleParameterDataPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "质控管理样检测任务参数业务表,与子样检测任务参数业务表T_BSN_ASY_TSK_PRM_DAT一样，针对标准样、管理样、质控样、监控样等样品的参数.xls", "数据", BusinessQCManagementSampleParameterDataRespVO.class,
                        BeanUtils.toBean(list, BusinessQCManagementSampleParameterDataRespVO.class));
    }

}