package com.zehong.web.controller.safe;

import com.zehong.common.annotation.Log;
import com.zehong.common.core.controller.BaseController;
import com.zehong.common.core.domain.AjaxResult;
import com.zehong.common.core.page.TableDataInfo;
import com.zehong.common.enums.BusinessType;
import com.zehong.common.utils.poi.ExcelUtil;
import com.zehong.system.domain.TSafeTrainLedger;
import com.zehong.system.service.ITSafeTrainLedgerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 安全培训台账Controller
 * 
 * @author zehong
 * @date 2026-03-27
 */
@RestController
@RequestMapping("/safe/train")
public class TSafeTrainLedgerController extends BaseController
{
    @Autowired
    private ITSafeTrainLedgerService tSafeTrainLedgerService;

    /**
     * 查询安全培训台账列表
     */
    //@PreAuthorize("@ss.hasPermi('system:ledger:list')")
    @GetMapping("/list")
    public TableDataInfo list(TSafeTrainLedger tSafeTrainLedger)
    {
        startPage();
        List<TSafeTrainLedger> list = tSafeTrainLedgerService.selectTSafeTrainLedgerList(tSafeTrainLedger);
        return getDataTable(list);
    }

    /**
     * 导出安全培训台账列表
     */
    //@PreAuthorize("@ss.hasPermi('system:ledger:export')")
    @Log(title = "安全培训台账", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TSafeTrainLedger tSafeTrainLedger)
    {
        List<TSafeTrainLedger> list = tSafeTrainLedgerService.selectTSafeTrainLedgerList(tSafeTrainLedger);
        ExcelUtil<TSafeTrainLedger> util = new ExcelUtil<TSafeTrainLedger>(TSafeTrainLedger.class);
        return util.exportExcel(list, "安全培训台账数据");
    }

    /**
     * 获取安全培训台账详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:ledger:query')")
    @GetMapping(value = "/{trainId}")
    public AjaxResult getInfo(@PathVariable("trainId") Long trainId)
    {
        return AjaxResult.success(tSafeTrainLedgerService.selectTSafeTrainLedgerById(trainId));
    }

    /**
     * 新增安全培训台账
     */
    //@PreAuthorize("@ss.hasPermi('system:ledger:add')")
    @Log(title = "安全培训台账", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TSafeTrainLedger tSafeTrainLedger)
    {
        return toAjax(tSafeTrainLedgerService.insertTSafeTrainLedger(tSafeTrainLedger));
    }

    /**
     * 修改安全培训台账
     */
    //@PreAuthorize("@ss.hasPermi('system:ledger:edit')")
    @Log(title = "安全培训台账", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TSafeTrainLedger tSafeTrainLedger)
    {
        return toAjax(tSafeTrainLedgerService.updateTSafeTrainLedger(tSafeTrainLedger));
    }

    /**
     * 删除安全培训台账
     */
    //@PreAuthorize("@ss.hasPermi('system:ledger:remove')")
    @Log(title = "安全培训台账", businessType = BusinessType.DELETE)
	@DeleteMapping("/{trainIds}")
    public AjaxResult remove(@PathVariable Long[] trainIds)
    {
        return toAjax(tSafeTrainLedgerService.deleteTSafeTrainLedgerByIds(trainIds));
    }
}
