package com.ruoyi.ibs.list.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ibs.list.domain.SysCampaignGroupCustomer;
import com.ruoyi.ibs.list.service.ISysCampaignGroupCustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 活动分群客户关联关系，推送成功后，插入一条记录Controller
 *
 * @author ruoyi
 * @date 2024-09-14
 */
@RestController
@RequestMapping("/system/customer/group")
public class SysCampaignGroupCustomerController extends BaseController {
    @Autowired
    private ISysCampaignGroupCustomerService sysCampaignGroupCustomerService;

    /**
     * 查询活动分群客户关联关系，推送成功后，插入一条记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:customer:list')")
    @Log(title = "走访-活动分群客户列表")
    @GetMapping("/list")
    public TableDataInfo list(SysCampaignGroupCustomer sysCampaignGroupCustomer) {
        startPage();
        List<SysCampaignGroupCustomer> list = sysCampaignGroupCustomerService.selectSysCampaignGroupCustomerList(sysCampaignGroupCustomer);
        return getDataTable(list);
    }

    /**
     * 导出活动分群客户关联关系，推送成功后，插入一条记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:customer:export')")
    @Log(title = "走访-活动分群客户关联关系，推送成功后，插入一条记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysCampaignGroupCustomer sysCampaignGroupCustomer) {
        List<SysCampaignGroupCustomer> list = sysCampaignGroupCustomerService.selectSysCampaignGroupCustomerList(sysCampaignGroupCustomer);
        ExcelUtil<SysCampaignGroupCustomer> util = new ExcelUtil<SysCampaignGroupCustomer>(SysCampaignGroupCustomer.class);
        util.exportExcel(response, list, "活动分群客户关联关系，推送成功后，插入一条记录数据");
    }

    /**
     * 获取活动分群客户关联关系，推送成功后，插入一条记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:customer:query')")
    @GetMapping(value = "/{id}")
    @Log(title = "走访-查询活动分群客户详情")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysCampaignGroupCustomerService.selectSysCampaignGroupCustomerById(id));
    }

    /**
     * 新增活动分群客户关联关系，推送成功后，插入一条记录
     */
    @PreAuthorize("@ss.hasPermi('system:customer:add')")
    @Log(title = "走访-活动分群客户关联关系，推送成功后，插入一条记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysCampaignGroupCustomer sysCampaignGroupCustomer) {
        return toAjax(sysCampaignGroupCustomerService.insertSysCampaignGroupCustomer(sysCampaignGroupCustomer));
    }

    /**
     * 修改活动分群客户关联关系，推送成功后，插入一条记录
     */
    @PreAuthorize("@ss.hasPermi('system:customer:edit')")
    @Log(title = "走访-活动分群客户关联关系，推送成功后，插入一条记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysCampaignGroupCustomer sysCampaignGroupCustomer) {
        return toAjax(sysCampaignGroupCustomerService.updateSysCampaignGroupCustomer(sysCampaignGroupCustomer));
    }

    /**
     * 删除活动分群客户关联关系，推送成功后，插入一条记录
     */
    @PreAuthorize("@ss.hasPermi('system:customer:remove')")
    @Log(title = "走访-活动分群客户关联关系，推送成功后，插入一条记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysCampaignGroupCustomerService.deleteSysCampaignGroupCustomerByIds(ids));
    }


}
