package com.ruoyi.custclient.controller;

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

import com.ruoyi.custclient.service.ILabelCodeService;
import org.springframework.beans.factory.annotation.Autowired;
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 com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.LabelCode;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 标签Controller
 * 
 * @author ruoyi
 * @date 2024-10-17
 */
@RestController
@RequestMapping("/code")
public class LabelCodeController extends BaseController
{
    @Autowired
    private ILabelCodeService labelCodeService;

    /**
     * 查询标签列表
     */
    @RequiresPermissions("system:code:list")
    @GetMapping("/list")
    public TableDataInfo list(LabelCode labelCode)
    {
        startPage();
        List<LabelCode> list = labelCodeService.selectLabelCodeList(labelCode);
        return getDataTable(list);
    }

    /**
     * 导出标签列表
     */
    @RequiresPermissions("system:code:export")
    @Log(title = "标签", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LabelCode labelCode)
    {
        List<LabelCode> list = labelCodeService.selectLabelCodeList(labelCode);
        ExcelUtil<LabelCode> util = new ExcelUtil<LabelCode>(LabelCode.class);
        util.exportExcel(response, list, "标签数据");
    }

    /**
     * 获取标签详细信息
     */
    @RequiresPermissions("system:code:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(labelCodeService.selectLabelCodeById(id));
    }

    /**
     * 新增标签
     */
    @RequiresPermissions("system:code:add")
    @Log(title = "标签", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LabelCode labelCode)
    {
        return toAjax(labelCodeService.insertLabelCode(labelCode));
    }

    /**
     * 修改标签
     */
    @RequiresPermissions("system:code:edit")
    @Log(title = "标签", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LabelCode labelCode)
    {
        return toAjax(labelCodeService.updateLabelCode(labelCode));
    }

    /**
     * 删除标签
     */
    @RequiresPermissions("system:code:remove")
    @Log(title = "标签", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(labelCodeService.deleteLabelCodeByIds(ids));
    }
}
