package com.ruoyi.group.controller;

import com.github.pagehelper.Page;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataPageInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.group.domain.entity.GroupCmpmCountGongsi825;
import com.ruoyi.group.domain.entity.GroupCmpmCountLingshou825;
import com.ruoyi.group.domain.entity.GroupCustCountGongsi825;
import com.ruoyi.group.domain.entity.GroupCustCountLingshou825;
import com.ruoyi.group.service.IGroupPerformanceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Api(tags = "客群业绩统计")
@RestController
@RequestMapping("/group/performance")
public class GroupPerformanceController extends BaseController {

    @Resource
    private IGroupPerformanceService groupPerformanceService;

    @ApiOperation("查询零售客群业绩汇总列表")
    @GetMapping("/ls/list")
    public TableDataPageInfo<GroupCmpmCountLingshou825> selectLsCountList(String dt, String groupName) {
        Page<Object> page = startPage();
        List<GroupCmpmCountLingshou825> list = groupPerformanceService.selectLsCountList(dt, groupName);
        return getDataTable(list, page);
    }

    @ApiOperation("查询公司客群业绩汇总列表")
    @GetMapping("/gs/list")
    public TableDataPageInfo<GroupCmpmCountGongsi825> selectGsCountList(String dt, String groupName) {
        Page<Object> page = startPage();
        List<GroupCmpmCountGongsi825> list = groupPerformanceService.selectGsCountList(dt, groupName);
        return getDataTable(list, page);
    }

    @ApiOperation("查询零售客群客户明细")
    @GetMapping("/ls/custList")
    public TableDataPageInfo<GroupCustCountLingshou825> selectLsCustList(@RequestParam String groupId,
                                                                         String custName,
                                                                         String custIdc,
                                                                         String dt) {
        Page<Object> page = startPage();
        List<GroupCustCountLingshou825> list = groupPerformanceService.selectLsCustList(groupId, custName, custIdc, dt);
        return getDataTable(list, page);
    }

    @ApiOperation("查询公司客群客户明细")
    @GetMapping("/gs/custList")
    public TableDataPageInfo<GroupCustCountGongsi825> selectGsCustList(@RequestParam String groupId,
                                                                       String custName,
                                                                       String socialCreditCode,
                                                                       String dt) {
        Page<Object> page = startPage();
        List<GroupCustCountGongsi825> list = groupPerformanceService.selectGsCustList(groupId, custName, socialCreditCode, dt);
        return getDataTable(list, page);
    }

    @Log(title = "导出零售客群业绩汇总")
    @ApiOperation(value = "导出零售客群业绩汇总", produces = "application/octet-stream")
    @GetMapping("/exportLs")
    public void exportLs(HttpServletResponse response, String dt, String groupName) {
        try {
            ExcelUtil<GroupCmpmCountLingshou825> util = new ExcelUtil<>(GroupCmpmCountLingshou825.class);
            util.exportExcel(response, groupPerformanceService.selectLsCountList(dt, groupName), "零售客群业绩汇总");
        } catch (Exception e) {
            logger.error("导出零售客群业绩汇总失败", e);
        }
    }

    @Log(title = "导出公司客群业绩汇总")
    @ApiOperation(value = "导出公司客群业绩汇总", produces = "application/octet-stream")
    @GetMapping("/exportGs")
    public void exportGs(HttpServletResponse response, String dt, String groupName) {
        try {
            ExcelUtil<GroupCmpmCountGongsi825> util = new ExcelUtil<>(GroupCmpmCountGongsi825.class);
            util.exportExcel(response, groupPerformanceService.selectGsCountList(dt, groupName), "公司客群业绩汇总");
        } catch (Exception e) {
            logger.error("导出公司客群业绩汇总失败", e);
        }
    }

    @Log(title = "导出零售客群客户明细")
    @ApiOperation(value = "导出零售客群客户明细", produces = "application/octet-stream")
    @GetMapping("/exportLsCust")
    public void exportLsCust(HttpServletResponse response,
                             @RequestParam String groupId,
                             String custName,
                             String custIdc,
                             String dt) {
        try {
            ExcelUtil<GroupCustCountLingshou825> util = new ExcelUtil<>(GroupCustCountLingshou825.class);
            util.exportExcel(response, groupPerformanceService.selectLsCustList(groupId, custName, custIdc, dt), "零售客群客户明细");
        } catch (Exception e) {
            logger.error("导出零售客群客户明细失败", e);
        }
    }

    @Log(title = "导出公司客群客户明细")
    @ApiOperation(value = "导出公司客群客户明细", produces = "application/octet-stream")
    @GetMapping("/exportGsCust")
    public void exportGsCust(HttpServletResponse response,
                             @RequestParam String groupId,
                             String custName,
                             String socialCreditCode,
                             String dt) {
        try {
            ExcelUtil<GroupCustCountGongsi825> util = new ExcelUtil<>(GroupCustCountGongsi825.class);
            util.exportExcel(response, groupPerformanceService.selectGsCustList(groupId, custName, socialCreditCode, dt), "公司客群客户明细");
        } catch (Exception e) {
            logger.error("导出公司客群客户明细失败", e);
        }
    }
}
