package com.huijy.web.controller.management;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
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.huijy.common.annotation.Log;
import com.huijy.common.core.controller.BaseController;
import com.huijy.common.core.domain.AjaxResult;
import com.huijy.common.enums.BusinessType;
import com.huijy.management.domain.Label;
import com.huijy.management.service.ILabelService;
import com.huijy.common.utils.poi.ExcelUtil;
import com.huijy.common.core.page.TableDataInfo;

/**
 * 标签管理Controller
 *
 * @author luobo
 * @date 2021-08-30
 */
@RestController
@RequestMapping("/management/label")
public class LabelController extends BaseController
{
    @Autowired
    private ILabelService labelService;

    /**
     * 查询标签管理列表
     */
    @PreAuthorize("@ss.hasPermi('management:label:list')")
    @GetMapping("/list")
    public TableDataInfo list(Label label)
    {
        startPage();
        List<Label> list = labelService.selectLabelList(label);
        return getDataTable(list);
    }
    @GetMapping("/list/{type}")
    public AjaxResult select(@PathVariable String type){
        Label label = new Label();
        label.setMarkerType(type);
        List<Label> list = labelService.selectLabelList(label);
        return AjaxResult.success(list);
    }

    /**
     * 导出标签管理列表
     */
    @PreAuthorize("@ss.hasPermi('management:label:export')")
    @Log(title = "标签管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Label label)
    {
        List<Label> list = labelService.selectLabelList(label);
        ExcelUtil<Label> util = new ExcelUtil<Label>(Label.class);
        return util.exportExcel(list, "标签管理数据");
    }

    /**
     * 获取标签管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('management:label:query')")
    @GetMapping(value = "/{labelId}")
    public AjaxResult getInfo(@PathVariable("labelId") Long labelId)
    {
        return AjaxResult.success(labelService.selectLabelByLabelId(labelId));
    }

    /**
     * 新增标签管理
     */
    @PreAuthorize("@ss.hasPermi('management:label:add')")
    @Log(title = "标签管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Label label)
    {
        return toAjax(labelService.insertLabel(label));
    }

    /**
     * 修改标签管理
     */
    @PreAuthorize("@ss.hasPermi('management:label:edit')")
    @Log(title = "标签管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Label label)
    {
        return toAjax(labelService.updateLabel(label));
    }

    /**
     * 删除标签管理
     */
    @PreAuthorize("@ss.hasPermi('management:label:remove')")
    @Log(title = "标签管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{labelIds}")
    public AjaxResult remove(@PathVariable Long[] labelIds)
    {
        return toAjax(labelService.deleteLabelByLabelIds(labelIds));
    }
}
