package cn.ezhizao.project.business.lable.controller;

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

import cn.ezhizao.common.utils.poi.ExcelUtil;
import cn.ezhizao.project.business.lable.domain.BizLable;
import cn.ezhizao.project.business.lable.service.IBizLableService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.ezhizao.framework.aspectj.lang.annotation.Log;
import cn.ezhizao.framework.aspectj.lang.enums.BusinessType;

import cn.ezhizao.framework.web.controller.BaseController;
import cn.ezhizao.framework.web.domain.AjaxResult;
import cn.ezhizao.framework.web.page.TableDataInfo;

/**
 * 客户标签Controller
 *
 * @author ruoyi
 * @date 2024-06-12
 */
@RestController
@RequestMapping("/business/lable")
public class BizLableController extends BaseController {
    @Resource
    private IBizLableService bizLableService;

    /**
     * 查询客户标签列表
     */
    @PreAuthorize("@ss.hasPermi('business:lable:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizLable bizLable) throws NoSuchFieldException, IllegalAccessException {
        setTenantId(bizLable);
        startPage();
        List<BizLable> list = bizLableService.getList(bizLable);
        return getDataTable(list);
    }

    @GetMapping("/getList")
    public AjaxResult getList( ) throws NoSuchFieldException, IllegalAccessException {
        Long tenantId = getTenantId();
        BizLable bizLable = new BizLable();
        bizLable.setTenantId(tenantId);
        setTenantId(bizLable);
        List<BizLable> list = bizLableService.getList(bizLable);
        return AjaxResult.success(list);
    }

    /**
     * 导出客户标签列表
     */
    @PreAuthorize("@ss.hasPermi('business:lable:export')")
    @Log(title = "客户标签", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizLable bizLable) throws NoSuchFieldException, IllegalAccessException {
        setTenantId(bizLable);
        List<BizLable> list = bizLableService.getList(bizLable);
        ExcelUtil<BizLable> util = new ExcelUtil<BizLable>(BizLable.class);
        util.exportExcel(response, list, "客户标签数据");
    }

    /**
     * 获取客户标签详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:lable:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(bizLableService.getById(id));
    }

    /**
     * 新增客户标签
     */
    @PreAuthorize("@ss.hasPermi('business:lable:add')")
    @Log(title = "客户标签", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizLable bizLable) throws NoSuchFieldException, IllegalAccessException {
        setTenantId(bizLable);
        return toAjax(bizLableService.save(bizLable));
    }

    /**
     * 修改客户标签
     */
    @PreAuthorize("@ss.hasPermi('business:lable:edit')")
    @Log(title = "客户标签", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizLable bizLable) throws NoSuchFieldException, IllegalAccessException {
        setTenantId(bizLable);
        return toAjax(bizLableService.updateById(bizLable));
    }

    /**
     * 删除客户标签
     */
    @PreAuthorize("@ss.hasPermi('business:lable:remove')")
    @Log(title = "客户标签", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids) {
        return toAjax(bizLableService.removeBatchByIds(ids));
    }
}
