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.common.log.annotation.Log;
import com.usky.common.log.enums.BusinessType;
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
     */
    @Log(title = "新增-客户信息渠道", businessType = BusinessType.INSERT)
    @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
     */
    @Log(title = "修改-客户信息反馈表", businessType = BusinessType.UPDATE)
    @PutMapping
    public ApiResult<Void> edit(@RequestBody SiteReview siteReview){
        siteReviewService.edit(siteReview);
        return ApiResult.success();
    }

    @Log(title = "导出-客户信息反馈表", businessType = BusinessType.EXPORT)
    @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,"客户信息反馈表","客户信息反馈");

    }

}

