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.SysGroupCustomer;
import com.ruoyi.ibs.list.service.ISysGroupCustomerService;
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.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 分群客户关联关系,导入的客群用户存放在这里
 *
 * @author ruoyi
 * @date 2024-09-14
 */
@RestController
@RequestMapping("/system/customer")
public class SysGroupCustomerController extends BaseController {
    @Autowired
    private ISysGroupCustomerService sysGroupCustomerService;

    /**
     * 查询分群客户关联关系,导入的客群用户存放在这里列表
     */
    @PreAuthorize("@ss.hasPermi('system:customer:list')")
    @Log(title = "走访-客群圈选")
    @GetMapping("/list")
    public TableDataInfo list(SysGroupCustomer sysGroupCustomer) {
        startPage();
        List<SysGroupCustomer> list = sysGroupCustomerService.selectSysGroupCustomerList(sysGroupCustomer);
        return getDataTable(list);
    }

    /**
     * 根据客群id查询分群客户关联关系
     */
    @GetMapping("/listByGroupId")
    @Log(title = "走访-客群圈选")
    @ApiOperation("获取分群列表下客户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupId", value = "客群id", dataType = "String", dataTypeClass = String.class),
    })
    public TableDataInfo listByGroupId(String groupId) {
        startPage();
        SysGroupCustomer sysGroupCustomer = new SysGroupCustomer();
        sysGroupCustomer.setGroupId(groupId);
        List<SysGroupCustomer> list = sysGroupCustomerService.selectSysGroupCustomerList(sysGroupCustomer);
        return getDataTable(list);
    }

    /**
     * 导出分群客户关联关系,导入的客群用户存放在这里列表
     */
    @PreAuthorize("@ss.hasPermi('system:customer:export')")
    @Log(title = "走访-分群客户关联关系,导入的客群用户存放在这里", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysGroupCustomer sysGroupCustomer) {
        List<SysGroupCustomer> list = sysGroupCustomerService.selectSysGroupCustomerList(sysGroupCustomer);
        ExcelUtil<SysGroupCustomer> util = new ExcelUtil<SysGroupCustomer>(SysGroupCustomer.class);
        util.exportExcel(response, list, "分群客户关联关系,导入的客群用户存放在这里数据");
    }

    /**
     * 获取分群客户关联关系,导入的客群用户存放在这里详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:customer:query')")
    @Log(title = "走访-客群圈选")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysGroupCustomerService.selectSysGroupCustomerById(id));
    }

    /**
     * 新增分群客户关联关系,导入的客群用户存放在这里
     */
    @PreAuthorize("@ss.hasPermi('system:customer:add')")
    @Log(title = "走访-分群客户关联关系,导入的客群用户存放在这里", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysGroupCustomer sysGroupCustomer) {
        return toAjax(sysGroupCustomerService.insertSysGroupCustomer(sysGroupCustomer));
    }

    /**
     * 修改分群客户关联关系,导入的客群用户存放在这里
     */
    @PreAuthorize("@ss.hasPermi('system:customer:edit')")
    @Log(title = "走访-分群客户关联关系,导入的客群用户存放在这里", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysGroupCustomer sysGroupCustomer) {
        return toAjax(sysGroupCustomerService.updateSysGroupCustomer(sysGroupCustomer));
    }


    /**
     * 删除分群客户关联关系,导入的客群用户存放在这里
     */
    @PreAuthorize("@ss.hasPermi('system:customer:remove')")
    @Log(title = "走访-分群客户关联关系,导入的客群用户存放在这里", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysGroupCustomerService.deleteSysGroupCustomerByIds(ids));
    }
}
