package com.ruoyi.ibs.customerselect.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.enums.BusinessType;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.ibs.customerselect.domain.ListSelectByUser;
import com.ruoyi.ibs.customerselect.domain.ListSelectForUser;
import com.ruoyi.ibs.customerselect.service.IListSelectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 清单查询 控制类
 *
 * @author ruoyi
 */
@Api(tags = "清单查询管理")
@RestController
@RequestMapping("/system/listselectlist")
public class ListSelectController extends BaseController {

    @Autowired
    IListSelectService listSelectService;

    /**
     * 获取清单查询列表信息
     */
//    @PreAuthorize("@ss.hasPermi('system:getListInfo')")
    @GetMapping("/list")
    @Log(title = "清单查询管理-获取清单列表")
    @ApiOperation("获取清单列表")
    public TableDataPageInfo list(ListSelectByUser listSelectByUser)
    {
        Page<Object> page = startPage();
        List<ListSelectByUser> list = listSelectService.getListInfoByUser(listSelectByUser);
        return getDataTable(list ,page);
    }


    /**
     * 获取清单客户列表信息
     */
//    @PreAuthorize("@ss.hasPermi('system:getCustListInfo')")
    @GetMapping("/custlist")
    @Log(title = "清单查询管理-获取客户清单列表")
    @ApiOperation("获取客户清单列表")
    public TableDataPageInfo custList(ListSelectForUser listSelectForUser)
    {
        Page<Object> page = startPage();
        List<ListSelectForUser> custList = listSelectService.getCustListInfoByUser(listSelectForUser );
        return getDataTable(custList ,page);
    }


    /**
     * 批量导出分群客户
     */
//   @PreAuthorize("@ss.hasPermi('system:custlist:export')")
    @Log(title = "清单查询管理-批量导出分群客户", businessType = BusinessType.IMPORT)
    @ApiOperation("批量导出清单列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupId", value = "客群id", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "campaignId", value = "客群id", dataType = "String", dataTypeClass = String.class),
    })
    @PostMapping("/export")
    public void export(HttpServletResponse response, String custPattern,String groupId, String campaignId,Long deptId,@RequestParam(value = "custIds" , required = true) List<String> custIds) throws Exception{
        if(groupId.isEmpty() || custIds.isEmpty()){
            throw new ServiceException("请选择需要导出的数据！");
        }
        listSelectService.selectListExportByGroupId(response,custPattern,groupId,campaignId,deptId,custIds);
    }



}
