package com.usky.website.controller.web;


import com.usky.common.core.bean.ApiResult;
import com.usky.common.core.bean.CommonPage;
import com.usky.common.core.utils.poi.ExcelUtil;
import com.usky.website.domain.SiteReview;
import com.usky.website.service.SiteReviewService;
import com.usky.website.service.vo.SiteReviewExportVO;
import com.usky.website.service.vo.SiteReviewRequestVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;
import retrofit2.http.POST;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * <p>
 * 官网_客户信息反馈表 前端控制器
 * </p>
 *
 * @author zyj
 * @since 2024-01-12
 */
@RestController
@RequestMapping("/siteReview")
public class SiteReviewController {
    @Autowired
    private SiteReviewService siteReviewService;

    /**
     * 新增
     *
     * @param siteReview
     * @return
     */
    @PostMapping
    public ApiResult<Void> add(@RequestBody SiteReview siteReview){
        siteReviewService.add(siteReview);
        return ApiResult.success();
    }

    /**
     * 分页
     *
     * @param requestVO
     * @return
     */
    @PostMapping("page")
    public ApiResult<CommonPage<SiteReview>> page(@RequestBody SiteReviewRequestVO requestVO){
        return ApiResult.success(siteReviewService.page(requestVO));
    }

    /**
     * 反馈填报
     *
     * @param siteReview
     * @return
     */
    @PutMapping
    public ApiResult<Void> edit(@RequestBody SiteReview siteReview){
        siteReviewService.edit(siteReview);
        return ApiResult.success();
    }

    @PostMapping("export")
    public void export(@RequestBody SiteReviewRequestVO requestVO, HttpServletResponse response) throws IOException{
        List<SiteReviewExportVO> list = siteReviewService.recordListExport(requestVO);
        ExcelUtil<SiteReviewExportVO> util = new ExcelUtil<SiteReviewExportVO>(SiteReviewExportVO.class);
        util.exportExcel(response,list,"客户信息反馈表","客户信息反馈");

    }

}

