package com.ruoyi.custclient.controller;

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

import com.ruoyi.custclient.domain.LabelCode;
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.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;

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

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

    /**
     * 导出标签组code列表
     */
    @RequiresPermissions("laber:code:export")
    @Log(title = "标签组code", 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, "标签组code数据");
    }

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

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

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

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