package com.xinelu.manage.controller.labelfieldcontent;

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.labelfieldcontent.LabelFieldContent;
import com.xinelu.manage.dto.labelfieldcontent.LabelFieldContentAddDTO;
import com.xinelu.manage.service.labelfieldcontent.ILabelFieldContentService;
import com.xinelu.manage.vo.labelfieldcontent.LabelField;
import com.xinelu.manage.vo.labelfieldcontent.LabelFieldAndPartitionDict;
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
 */
@RestController
@RequestMapping("/manage/labelfieldcontent")
public class LabelFieldContentController extends BaseController {
    @Resource
    private ILabelFieldContentService labelFieldContentService;

    /**
     * 查询标签字段内容信息列表
     */
    @PreAuthorize("@ss.hasPermi('manage:labelfieldcontent:list')")
    @GetMapping("/list")
    public TableDataInfo list(LabelFieldContent labelFieldContent) {
        startPage();
        List<LabelFieldContent> list = labelFieldContentService.selectLabelFieldContentList(labelFieldContent);
        return getDataTable(list);
    }

    /**
     * 导出标签字段内容信息列表
     */
    @PreAuthorize("@ss.hasPermi('manage:labelfieldcontent:export')")
    @Log(title = "标签字段内容信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LabelFieldContent labelFieldContent) {
        List<LabelFieldContent> list = labelFieldContentService.selectLabelFieldContentList(labelFieldContent);
        ExcelUtil<LabelFieldContent> util = new ExcelUtil<LabelFieldContent>(LabelFieldContent.class);
        util.exportExcel(response, list, "标签字段内容信息数据");
    }

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

    /**
     * 批量新增标签字段内容信息
     */
    @PreAuthorize("@ss.hasPermi('manage:labelfieldcontent:add')")
    @Log(title = "标签字段内容信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody LabelFieldContentAddDTO labelFieldContentAddDTO) {
        return toAjax(labelFieldContentService.insertLabelFieldContents(labelFieldContentAddDTO));
    }

    /**
     * 修改标签字段内容信息
     */
    @PreAuthorize("@ss.hasPermi('manage:labelfieldcontent:edit')")
    @Log(title = "标签字段内容信息", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody LabelFieldContent labelFieldContent) {
        return toAjax(labelFieldContentService.updateLabelFieldContent(labelFieldContent));
    }

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

    /**
     * 分组信息
     */
    @GetMapping("/groupingContent")
    public AjaxResult groupingContent(Long patientId) {
        return labelFieldContentService.groupingContent(patientId);
    }

    /**
     * 画像查询
     */
    @GetMapping("/groupingValue")
    public List<LabelFieldAndPartitionDict> groupingValue(Long taskPartitionDictId, Long patientId) {
        return labelFieldContentService.groupingValue(taskPartitionDictId, patientId);
    }

    /**
     * 画像内容新增
     */
    @PostMapping("/insertLabelField")
    public AjaxResult insertLabelField(@RequestBody LabelField labelField) {
        return labelFieldContentService.insertLabelField(labelField);
    }

}
