package com.zt.plat.module.base.controller.admin.erpmonthproductiveplancheck;



import com.zt.plat.module.base.controller.admin.erpmonthproductiveplancheck.vo.ErpMonthProductivePlanCheckDetailPageReqVO;
import com.zt.plat.module.base.controller.admin.erpmonthproductiveplancheck.vo.ErpMonthProductivePlanCheckDetailRespVO;
import com.zt.plat.module.base.controller.admin.erpmonthproductiveplancheck.vo.ErpMonthProductivePlanCheckDetailSaveReqVO;
import com.zt.plat.module.base.dal.dataobject.erpmonthproductiveplancheck.ErpMonthProductivePlanCheckDetailDO;
import com.zt.plat.module.base.service.erpmonthproductiveplancheck.ErpMonthProductivePlanCheckDetailService;
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 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.*;


@Tag(name = "管理后台 - ERP月度产品计划核对明细")
@RestController
@RequestMapping("/base/erp-month-productive-plan-check-detail")
@Validated
public class ErpMonthProductivePlanCheckDetailController implements BusinessControllerMarker {


    @Resource
    private ErpMonthProductivePlanCheckDetailService erpMonthProductivePlanCheckDetailService;

    @PostMapping("/create")
    @Operation(summary = "创建ERP月度产品计划核对明细")
    @PreAuthorize("@ss.hasPermission('base:erp-month-productive-plan-check-detail:create')")
    public CommonResult<ErpMonthProductivePlanCheckDetailRespVO> createErpMonthProductivePlanCheckDetail(@Valid @RequestBody ErpMonthProductivePlanCheckDetailSaveReqVO createReqVO) {
        return success(erpMonthProductivePlanCheckDetailService.createErpMonthProductivePlanCheckDetail(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新ERP月度产品计划核对明细")
    @PreAuthorize("@ss.hasPermission('base:erp-month-productive-plan-check-detail:update')")
    public CommonResult<Boolean> updateErpMonthProductivePlanCheckDetail(@Valid @RequestBody ErpMonthProductivePlanCheckDetailSaveReqVO updateReqVO) {
        erpMonthProductivePlanCheckDetailService.updateErpMonthProductivePlanCheckDetail(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除ERP月度产品计划核对明细")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('base:erp-month-productive-plan-check-detail:delete')")
    public CommonResult<Boolean> deleteErpMonthProductivePlanCheckDetail(@RequestParam("id") Long id) {
        erpMonthProductivePlanCheckDetailService.deleteErpMonthProductivePlanCheckDetail(id);
        return success(true);
    }

    @DeleteMapping("/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除ERP月度产品计划核对明细")
                @PreAuthorize("@ss.hasPermission('base:erp-month-productive-plan-check-detail:delete')")
    public CommonResult<Boolean> deleteErpMonthProductivePlanCheckDetailList(@RequestBody BatchDeleteReqVO req) {
        erpMonthProductivePlanCheckDetailService.deleteErpMonthProductivePlanCheckDetailListByIds(req.getIds());
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得ERP月度产品计划核对明细")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('base:erp-month-productive-plan-check-detail:query')")
    public CommonResult<ErpMonthProductivePlanCheckDetailRespVO> getErpMonthProductivePlanCheckDetail(@RequestParam("id") Long id) {
        ErpMonthProductivePlanCheckDetailDO erpMonthProductivePlanCheckDetail = erpMonthProductivePlanCheckDetailService.getErpMonthProductivePlanCheckDetail(id);
        return success(BeanUtils.toBean(erpMonthProductivePlanCheckDetail, ErpMonthProductivePlanCheckDetailRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得ERP月度产品计划核对明细分页")
    @PreAuthorize("@ss.hasPermission('base:erp-month-productive-plan-check-detail:query')")
    public CommonResult<PageResult<ErpMonthProductivePlanCheckDetailRespVO>> getErpMonthProductivePlanCheckDetailPage(@Valid ErpMonthProductivePlanCheckDetailPageReqVO pageReqVO) {
        PageResult<ErpMonthProductivePlanCheckDetailDO> pageResult = erpMonthProductivePlanCheckDetailService.getErpMonthProductivePlanCheckDetailPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, ErpMonthProductivePlanCheckDetailRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出ERP月度产品计划核对明细 Excel")
    @PreAuthorize("@ss.hasPermission('base:erp-month-productive-plan-check-detail:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportErpMonthProductivePlanCheckDetailExcel(@Valid ErpMonthProductivePlanCheckDetailPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<ErpMonthProductivePlanCheckDetailDO> list = erpMonthProductivePlanCheckDetailService.getErpMonthProductivePlanCheckDetailPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "ERP月度产品计划核对明细.xls", "数据", ErpMonthProductivePlanCheckDetailRespVO.class,
                        BeanUtils.toBean(list, ErpMonthProductivePlanCheckDetailRespVO.class));
    }

}