package com.ruoyi.interfaces.controller;

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

import com.ruoyi.interfaces.domain.MdDataCate;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.interfaces.domain.MdDataItem;
import com.ruoyi.interfaces.service.IMdDataItemService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 数据项Controller
 * 
 * @author ruoyi
 * @date 2025-07-25
 */
@RestController
@RequestMapping("/data/item")
public class MdDataItemController extends BaseController
{
    @Autowired
    private IMdDataItemService mdDataItemService;

    /**
     * 查询数据项列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MdDataItem mdDataItem)
    {
        startPage();
        List<MdDataItem> list = mdDataItemService.selectMdDataItemList(mdDataItem);
        return getDataTable(list);
    }

    /**
     * 导出数据项列表
     */
    @Log(title = "数据项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MdDataItem mdDataItem)
    {
        List<MdDataItem> list = mdDataItemService.selectMdDataItemList(mdDataItem);
        ExcelUtil<MdDataItem> util = new ExcelUtil<MdDataItem>(MdDataItem.class);
        util.exportExcel(response, list, "数据项数据");
    }

    /**
     * 获取数据项详细信息
     */
    @GetMapping(value = "/{dataId}")
    public AjaxResult getInfo(@PathVariable("dataId") String dataId)
    {
        return success(mdDataItemService.selectMdDataItemByDataId(dataId));
    }




    /**
     * 新增数据项
     */
    @Log(title = "数据项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MdDataItem mdDataItem)
    {
        return toAjax(mdDataItemService.insertMdDataItem(mdDataItem));
    }

    /**
     * 修改数据项
     */
    @Log(title = "数据项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MdDataItem mdDataItem)
    {
        return toAjax(mdDataItemService.updateMdDataItem(mdDataItem));
    }

    /**
     * 删除数据项
     */
    @Log(title = "数据项", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dataIds}")
    public AjaxResult remove(@PathVariable String[] dataIds)
    {
        return toAjax(mdDataItemService.deleteMdDataItemByDataIds(dataIds));
    }
}
