package com.usky.iot.controller.web;


import com.usky.common.core.utils.poi.ExcelUtil;
import com.usky.common.core.bean.ApiResult;
import com.usky.common.core.bean.CommonPage;
import com.usky.iot.domain.CrmCustomInfo;
import com.usky.iot.service.CrmCustomInfoService;
import com.usky.iot.service.vo.CrmCustomInfoExportVO;
import com.usky.iot.service.vo.CrmCustomInfoRequestVO;
import com.usky.iot.service.vo.CrmCustomInfoStatisticVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * <p>
 * 客户管理信息表 前端控制器
 * </p>
 *
 * @author han
 * @since 2023-06-26
 */
@RestController
@RequestMapping("/crmCustomInfo")
public class CrmCustomInfoController {

    @Autowired
    private CrmCustomInfoService crmCustomInfoService;

    /**
     * 新增
     * @param crmCustomInfo
     * @return
     */
    @PostMapping
    public ApiResult<Void> add(@RequestBody CrmCustomInfo crmCustomInfo){
        crmCustomInfoService.add(crmCustomInfo);
        return ApiResult.success();
    }

    /**
     * 修改
     * @param crmCustomInfo
     * @return
     */
    @PutMapping
    public ApiResult<Void> edit(@RequestBody CrmCustomInfo crmCustomInfo){
        crmCustomInfoService.edit(crmCustomInfo);
        return ApiResult.success();
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public ApiResult<Void> remove(@PathVariable("id") Integer id){
        crmCustomInfoService.remove(id);
        return ApiResult.success();
    }

    /**
     * 分页
     * @param crmCustomInfoRequestVO
     * @return
     */
    @PostMapping("/page")
    public ApiResult<CommonPage<CrmCustomInfo>> page(@RequestBody CrmCustomInfoRequestVO crmCustomInfoRequestVO){
        return ApiResult.success(crmCustomInfoService.page(crmCustomInfoRequestVO));
    }

    /**
     * 统计
     * @param crmCustomInfoRequestVO
     * @return
     */
    @PostMapping("statistic")
    public ApiResult<List<CrmCustomInfoStatisticVO>> statistic(@RequestBody CrmCustomInfoRequestVO crmCustomInfoRequestVO){
        return ApiResult.success(crmCustomInfoService.statistic(crmCustomInfoRequestVO));
    }

    @PostMapping("export")
    public void export(@RequestBody CrmCustomInfoRequestVO crmCustomInfoRequestVO, HttpServletResponse response)throws IOException {
        List<CrmCustomInfoExportVO> list = crmCustomInfoService.recordListExport(crmCustomInfoRequestVO);
        ExcelUtil<CrmCustomInfoExportVO> util = new ExcelUtil<CrmCustomInfoExportVO>(CrmCustomInfoExportVO.class);
        util.exportExcel(response,list,"客户管理信息","客户管理信息");

    }

}

