package com.xinelu.manage.controller.labelfieldinfo;

import com.xinelu.common.annotation.Log;
import com.xinelu.common.core.controller.BaseController;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.common.core.page.TableDataInfo;
import com.xinelu.common.enums.BusinessType;
import com.xinelu.common.utils.poi.ExcelUtil;
import com.xinelu.manage.domain.labelfieldinfo.LabelFieldInfo;
import com.xinelu.manage.dto.labelfieldinfo.LabelFieldInfoAddDTO;
import com.xinelu.manage.service.labelfieldinfo.ILabelFieldInfoService;
import com.xinelu.manage.vo.labelfieldinfo.LabelFieldTreeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 标签字段信息Controller
 *
 * @author xinelu
 * @date 2024-03-11
 */
@Api(tags = "字段信息控制器")
@RestController
@RequestMapping("/manage/labelfieldinfo")
public class LabelFieldInfoController extends BaseController {
    @Resource
    private ILabelFieldInfoService labelFieldInfoService;

    /**
     * 查询标签字段信息列表
     */
    @ApiOperation("查询标签字段信息列表")
    @PreAuthorize("@ss.hasPermi('manage:labelfieldinfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(LabelFieldInfo labelFieldInfo) {
        startPage();
        List<LabelFieldInfo> list = labelFieldInfoService.selectLabelFieldInfoList(labelFieldInfo);
        return getDataTable(list);
    }

    /**
     * 查询标签字段信息列表 不分页
     */
    @GetMapping("/labelFieldInfoList")
    public AjaxResult labelFieldInfoList(LabelFieldInfo labelFieldInfo) {
        return AjaxResult.success(labelFieldInfoService.selectLabelFieldInfoList(labelFieldInfo));
    }

    /**
     * 查询标签字段信息列表树图
     */
    @GetMapping("/labelFieldList")
    public List<LabelFieldTreeVO> labelFieldList(Long taskPartitionDictId, String fieldType) {
        return labelFieldInfoService.labelFieldList(taskPartitionDictId, fieldType);
    }

    /**
     * 导出标签字段信息列表
     */
    @ApiOperation("导出标签字段信息列表")
    @PreAuthorize("@ss.hasPermi('manage:labelfieldinfo:export')")
    @Log(title = "标签字段信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LabelFieldInfo labelFieldInfo) {
        List<LabelFieldInfo> list = labelFieldInfoService.selectLabelFieldInfoList(labelFieldInfo);
        ExcelUtil<LabelFieldInfo> util = new ExcelUtil<LabelFieldInfo>(LabelFieldInfo.class);
        util.exportExcel(response, list, "标签字段信息数据");
    }

    /**
     * 获取标签字段信息详细信息
     */
    @ApiOperation("获取标签字段信息详细信息")
    @PreAuthorize("@ss.hasPermi('manage:labelfieldinfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(labelFieldInfoService.selectLabelFieldInfoById(id));
    }

    /**
     * 批量新增标签字段信息
     */
    @ApiOperation("批量新增标签字段信息")
    @PreAuthorize("@ss.hasPermi('manage:labelfieldinfo:add')")
    @Log(title = "标签字段信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody LabelFieldInfoAddDTO labelFieldInfoAddDTO) {
        return toAjax(labelFieldInfoService.insertLabelFieldInfoList(labelFieldInfoAddDTO));
    }

    /**
     * 修改标签字段信息
     */
    @ApiOperation("修改标签字段信息")
    @PreAuthorize("@ss.hasPermi('manage:labelfieldinfo:edit')")
    @Log(title = "标签字段信息", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody LabelFieldInfo labelFieldInfo) {
        return toAjax(labelFieldInfoService.updateLabelFieldInfo(labelFieldInfo));
    }

    /**
     * 删除标签字段信息
     */
    @ApiOperation("删除标签字段信息")
    @PreAuthorize("@ss.hasPermi('manage:labelfieldinfo:remove')")
    @Log(title = "标签字段信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(labelFieldInfoService.deleteLabelFieldInfoByIds(ids));
    }

    /**
     * 任务类型分组
     */
    @GetMapping("/taskTypeGrouping")
    public AjaxResult taskTypeGrouping() {
        return labelFieldInfoService.taskTypeGrouping();
    }
}
