package com.cf.imes.module.system.controller.admin.funds.delay;

import com.cf.imes.framework.common.pojo.CommonResult;
import com.cf.imes.framework.common.pojo.PageParam;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.framework.excel.core.util.ExcelUtils;
import com.cf.imes.module.system.controller.admin.funds.delay.vo.ProductDelayPageReqVO;
import com.cf.imes.module.system.controller.admin.funds.delay.vo.ProductDelayRespVO;
import com.cf.imes.module.system.controller.admin.funds.delay.vo.ProductDelaySaveReqVO;
import com.cf.imes.module.system.service.funds.delay.ProductDelayService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

import static com.cf.imes.framework.common.pojo.CommonResult.success;

/**
 * @author Gqr
 * @since 2025/9/15 11:18
 */
@Tag(name = "管理后台 - 产品延期管理")
@RestController
@RequestMapping("/system/product/delay")
@Validated
public class ProductDelayController {
    @Resource
    private ProductDelayService productDelayService;

    @PostMapping()
    @Operation(summary = "新增组织延期")
    public CommonResult<Long> createProductDelay(@RequestBody @Valid ProductDelaySaveReqVO productDelaySaveReqVO){
        return success(productDelayService.createProductDelay(productDelaySaveReqVO));
    }

    @GetMapping("/page")
    @Operation(summary = "获取组织延期记录分页")
    public CommonResult<PageResult<ProductDelayRespVO>> getProductDelayPage(@Valid ProductDelayPageReqVO pageReqVO) {
        return success(productDelayService.getPage(pageReqVO));
    }

    @GetMapping("/export")
    @Operation(summary = "导出组织延期记录")
    public void exportProductDelay(@Valid ProductDelayPageReqVO pageReqVO,
                                   HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<ProductDelayRespVO> list = productDelayService.getPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "延期记录表.xls", "数据", ProductDelayRespVO.class, list);
    }
}
