package com.test.test.controller;

import java.util.List;

import com.test.test.domain.UiElement;
import com.test.test.domain.qo.UiElementQO;
import com.test.test.service.IUiElementService;
import jakarta.servlet.http.HttpServletResponse;
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.test.common.annotation.Log;
import com.test.common.core.controller.BaseController;
import com.test.common.core.domain.AjaxResult;
import com.test.common.enums.BusinessType;
import com.test.common.utils.poi.ExcelUtil;
import com.test.common.core.page.TableDataInfo;

/**
 * ui元素Controller
 * 
 * @author test
 * @date 2025-04-22
 */
@RestController
@RequestMapping("/test/element")
public class UiElementController extends BaseController
{
    @Autowired
    private IUiElementService uiElementService;

    /**
     * 查询ui元素列表
     */
//    @PreAuthorize("@ss.hasPermi('system:element:list')")
    @GetMapping("/list")
    public TableDataInfo list(UiElementQO uiElement)
    {
        startPage();
        List<UiElement> list = uiElementService.selectUiElementListNew(uiElement);
        return getDataTable(list);
    }



    /**
     * 获取ui元素详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:element:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(uiElementService.selectUiElementById(id));
    }

    /**
     * 新增ui元素
     */
//    @PreAuthorize("@ss.hasPermi('system:element:add')")
    @Log(title = "ui元素", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody UiElement uiElement)
    {
        return toAjax(uiElementService.insertUiElement(uiElement));
    }

    /**
     * 修改ui元素
     */
//    @PreAuthorize("@ss.hasPermi('system:element:edit')")
    @Log(title = "ui元素", businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    public AjaxResult edit(@RequestBody UiElement uiElement)
    {
        return toAjax(uiElementService.updateUiElement(uiElement));
    }

    /**
     * 删除ui元素
     */
//    @PreAuthorize("@ss.hasPermi('system:element:remove')")
    @Log(title = "ui元素", businessType = BusinessType.UPDATE)
	@PutMapping("delete/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(uiElementService.deleteUiElementByIds(ids));
    }



    //    /**
//     * 导出ui元素列表
//     */
//    @PreAuthorize("@ss.hasPermi('system:element:export')")
//    @Log(title = "ui元素", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, UiElement uiElement)
//    {
//        List<UiElement> list = uiElementService.selectUiElementList(uiElement);
//        ExcelUtil<UiElement> util = new ExcelUtil<UiElement>(UiElement.class);
//        util.exportExcel(response, list, "ui元素数据");
//    }
}
