package com.ruoyi.kaohe.controller;

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

import com.ruoyi.kaohe.domain.KhItems;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
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.kaohe.domain.KhTemItem;
import com.ruoyi.kaohe.service.IKhTemItemService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 模板考核项关联Controller
 * 
 * @author hs
 * @date 2025-06-17
 */
@RestController
@RequestMapping("/kaohe/tem_item")
public class KhTemItemController extends BaseController
{
    @Autowired
    private IKhTemItemService khTemItemService;

    /**
     * 查询模板考核项关联列表
     */
    @PreAuthorize("@ss.hasPermi('kaohe:tem_item:list')")
    @GetMapping("/list")
    public TableDataInfo list(KhTemItem khTemItem)
    {
        startPage();
        List<KhTemItem> list = khTemItemService.selectKhTemItemList(khTemItem);
        return getDataTable(list);
    }

    /**
     * 导出模板考核项关联列表
     */
    @PreAuthorize("@ss.hasPermi('kaohe:tem_item:export')")
    @Log(title = "模板考核项关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KhTemItem khTemItem)
    {
        List<KhTemItem> list = khTemItemService.selectKhTemItemList(khTemItem);
        ExcelUtil<KhTemItem> util = new ExcelUtil<KhTemItem>(KhTemItem.class);
        util.exportExcel(response, list, "模板考核项关联数据");
    }

    /**
     * 获取模板考核项关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('kaohe:tem_item:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(khTemItemService.selectKhTemItemById(id));
    }

    /**
     * 新增模板考核项关联
     */
    @PreAuthorize("@ss.hasPermi('kaohe:tem_item:add')")
    @Log(title = "模板考核项关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KhTemItem khTemItem)
    {
        return toAjax(khTemItemService.insertKhTemItem(khTemItem));
    }

    /**
     * 批量新增
     */
/*    @PreAuthorize("@ss.hasPermi('kaohe:tem_item:add')")
    @Log(title = "模板考核项关联", businessType = BusinessType.INSERT)
    @PostMapping("/adds")
    @Transactional
    public AjaxResult adds(@RequestBody List<KhTemItem> khTemItems)
    {
        for(KhTemItem khTemItem:khTemItems){
            khTemItemService.insertKhTemItem(khTemItem);
        }
        return AjaxResult.success();
    }*/

    /**
     * 修改模板考核项关联
     */
    @PreAuthorize("@ss.hasPermi('kaohe:tem_item:edit')")
    @Log(title = "模板考核项关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KhTemItem khTemItem)
    {
        return toAjax(khTemItemService.updateKhTemItem(khTemItem));
    }

    /**
     * 删除模板考核项关联
     */
    @PreAuthorize("@ss.hasPermi('kaohe:tem_item:remove')")
    @Log(title = "模板考核项关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(khTemItemService.deleteKhTemItemByIds(ids));
    }
}
