package com.zt.plat.module.qms.office.supplier.controller.admin;

import com.zt.plat.module.qms.office.supplier.controller.vo.SupplierEvaluationAtPageReqVO;
import com.zt.plat.module.qms.office.supplier.controller.vo.SupplierEvaluationAtRespVO;
import com.zt.plat.module.qms.office.supplier.controller.vo.SupplierEvaluationAtSaveReqVO;
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 com.zt.plat.framework.business.annotation.FileUploadController;
import com.zt.plat.framework.business.controller.AbstractFileUploadController;

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 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.framework.apilog.core.annotation.ApiAccessLog;
import static com.zt.plat.framework.apilog.core.enums.OperateTypeEnum.*;

import com.zt.plat.module.qms.office.supplier.dal.dataobject.SupplierEvaluationAtDO;
import com.zt.plat.module.qms.office.supplier.service.SupplierEvaluationAtService;

@Tag(name = "管理后台 - 供应商评价关系")
@RestController
@RequestMapping("/qms/supplier-evaluation-at")
@Validated
@DeptDataPermissionIgnore(enable = "true")
@FileUploadController(source = "qms.supplierevaluationat")
public class SupplierEvaluationAtController extends AbstractFileUploadController implements BusinessControllerMarker{

    static {
        FileUploadController annotation = SupplierEvaluationAtController.class.getAnnotation(FileUploadController.class);
        if (annotation != null) {
        setFileUploadInfo(annotation);
        }
    }

    @Resource
    private SupplierEvaluationAtService supplierEvaluationAtService;

    @PostMapping("/create")
    @Operation(summary = "创建供应商评价关系")
//    @PreAuthorize("@ss.hasPermission('qms:supplier-evaluation-at:create')")
    public CommonResult<SupplierEvaluationAtRespVO> createSupplierEvaluationAt(@Valid @RequestBody SupplierEvaluationAtSaveReqVO createReqVO) {
        return success(supplierEvaluationAtService.createSupplierEvaluationAt(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新供应商评价关系")
//    @PreAuthorize("@ss.hasPermission('qms:supplier-evaluation-at:update')")
    public CommonResult<Boolean> updateSupplierEvaluationAt(@Valid @RequestBody SupplierEvaluationAtSaveReqVO updateReqVO) {
        supplierEvaluationAtService.updateSupplierEvaluationAt(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除供应商评价关系")
    @Parameter(name = "id", description = "编号", required = true)
//    @PreAuthorize("@ss.hasPermission('qms:supplier-evaluation-at:delete')")
    public CommonResult<Boolean> deleteSupplierEvaluationAt(@RequestParam("id") Long id) {
        supplierEvaluationAtService.deleteSupplierEvaluationAt(id);
        return success(true);
    }

    @DeleteMapping("/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除供应商评价关系")
//                @PreAuthorize("@ss.hasPermission('qms:supplier-evaluation-at:delete')")
    public CommonResult<Boolean> deleteSupplierEvaluationAtList(@RequestBody BatchDeleteReqVO req) {
        supplierEvaluationAtService.deleteSupplierEvaluationAtListByIds(req.getIds());
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得供应商评价关系")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
//    @PreAuthorize("@ss.hasPermission('qms:supplier-evaluation-at:query')")
    public CommonResult<SupplierEvaluationAtRespVO> getSupplierEvaluationAt(@RequestParam("id") Long id) {
        SupplierEvaluationAtDO supplierEvaluationAt = supplierEvaluationAtService.getSupplierEvaluationAt(id);
        return success(BeanUtils.toBean(supplierEvaluationAt, SupplierEvaluationAtRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得供应商评价关系分页")
//    @PreAuthorize("@ss.hasPermission('qms:supplier-evaluation-at:query')")
    public CommonResult<PageResult<SupplierEvaluationAtRespVO>> getSupplierEvaluationAtPage(@Valid SupplierEvaluationAtPageReqVO pageReqVO) {
        PageResult<SupplierEvaluationAtDO> pageResult = supplierEvaluationAtService.getSupplierEvaluationAtPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, SupplierEvaluationAtRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出供应商评价关系 Excel")
//    @PreAuthorize("@ss.hasPermission('qms:supplier-evaluation-at:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportSupplierEvaluationAtExcel(@Valid SupplierEvaluationAtPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<SupplierEvaluationAtDO> list = supplierEvaluationAtService.getSupplierEvaluationAtPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "供应商评价关系.xls", "数据", SupplierEvaluationAtRespVO.class,
                        BeanUtils.toBean(list, SupplierEvaluationAtRespVO.class));
    }

}