package com.ruoyi.kaohe.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.KhItems;
import com.ruoyi.kaohe.service.IKhItemsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 考核项Controller
 * 
 * @author hs
 * @date 2025-06-17
 */
@RestController
@RequestMapping("/kaohe/items")
public class KhItemsController extends BaseController
{
    @Autowired
    private IKhItemsService khItemsService;

    /**
     * 查询考核项列表
     */
    @PreAuthorize("@ss.hasPermi('kaohe:items:list')")
    @GetMapping("/list")
    public TableDataInfo list(KhItems khItems)
    {
        startPage();
        List<KhItems> list = khItemsService.selectKhItemsList(khItems);
        return getDataTable(list);
    }

    /**
     * 导出考核项列表
     */
    @PreAuthorize("@ss.hasPermi('kaohe:items:export')")
    @Log(title = "考核项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KhItems khItems)
    {
        List<KhItems> list = khItemsService.selectKhItemsList(khItems);
        ExcelUtil<KhItems> util = new ExcelUtil<KhItems>(KhItems.class);
        util.exportExcel(response, list, "考核项数据");
    }

    /**
     * 获取考核项详细信息
     */
    @PreAuthorize("@ss.hasPermi('kaohe:items:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(khItemsService.selectKhItemsById(id));
    }

    /**
     * 新增考核项
     */
    @PreAuthorize("@ss.hasPermi('kaohe:items:add')")
    @Log(title = "考核项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KhItems khItems)
    {
        return toAjax(khItemsService.insertKhItems(khItems));
    }

    /**
     * 批量新增考核项
     */
    /*@PreAuthorize("@ss.hasPermi('kaohe:items:add')")
    @Log(title = "考核项", businessType = BusinessType.INSERT)
    @PostMapping("/adds")
    @Transactional
    public AjaxResult adds(@RequestBody List<KhItems> khItems)
    {
        for(KhItems item:khItems){
            khItemsService.insertKhItems(item);
        }
        return AjaxResult.success();
    }*/

    /**
     * 修改考核项
     */
    @PreAuthorize("@ss.hasPermi('kaohe:items:edit')")
    @Log(title = "考核项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KhItems khItems)
    {
        return toAjax(khItemsService.updateKhItems(khItems));
    }

    /**
     * 删除考核项
     */
    @PreAuthorize("@ss.hasPermi('kaohe:items:remove')")
    @Log(title = "考核项", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(khItemsService.deleteKhItemsByIds(ids));
    }
}
