package com.ruoyi.web.controller.business.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.AiUserLabel;
import com.ruoyi.business.service.IAiUserLabelService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户标签Controller
 * 
 * @author max
 * @date 2023-05-14
 */
@Controller
@RequestMapping("/business/label")
public class AiUserLabelController extends BaseController
{
    private String prefix = "business/label";

    @Autowired
    private IAiUserLabelService aiUserLabelService;

    @RequiresPermissions("business:label:view")
    @GetMapping()
    public String label()
    {
        return prefix + "/label";
    }

    /**
     * 查询用户标签列表
     */
    @RequiresPermissions("business:label:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AiUserLabel aiUserLabel)
    {
        startPage();
        List<AiUserLabel> list = aiUserLabelService.selectAiUserLabelList(aiUserLabel);
        return getDataTable(list);
    }

    /**
     * 导出用户标签列表
     */
    @RequiresPermissions("business:label:export")
    @Log(title = "用户标签", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AiUserLabel aiUserLabel)
    {
        List<AiUserLabel> list = aiUserLabelService.selectAiUserLabelList(aiUserLabel);
        ExcelUtil<AiUserLabel> util = new ExcelUtil<AiUserLabel>(AiUserLabel.class);
        return util.exportExcel(list, "用户标签数据");
    }

    /**
     * 新增用户标签
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户标签
     */
    @RequiresPermissions("business:label:add")
    @Log(title = "用户标签", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AiUserLabel aiUserLabel)
    {
        return toAjax(aiUserLabelService.insertAiUserLabel(aiUserLabel));
    }

    /**
     * 修改用户标签
     */
    @RequiresPermissions("business:label:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        AiUserLabel aiUserLabel = aiUserLabelService.selectAiUserLabelById(id);
        mmap.put("aiUserLabel", aiUserLabel);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户标签
     */
    @RequiresPermissions("business:label:edit")
    @Log(title = "用户标签", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AiUserLabel aiUserLabel)
    {
        return toAjax(aiUserLabelService.updateAiUserLabel(aiUserLabel));
    }

    /**
     * 删除用户标签
     */
    @RequiresPermissions("business:label:remove")
    @Log(title = "用户标签", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(aiUserLabelService.deleteAiUserLabelByIds(ids));
    }
}
