package com.goldenwater.slaj.ttsa.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.goldenwater.common.annotation.Log;
import com.goldenwater.common.core.controller.BaseController;
import com.goldenwater.common.core.domain.AjaxResult;
import com.goldenwater.common.core.page.TableDataInfo;
import com.goldenwater.common.enums.BusinessType;
import com.goldenwater.common.utils.poi.ExcelUtil;
import com.goldenwater.slaj.ttsa.domain.ObjTtsa;
import com.goldenwater.slaj.ttsa.service.IObjTtsaService;

@RestController
@RequestMapping("/ttsa/objttsa")
public class ObjTtsaController extends BaseController {
    @Autowired
    private IObjTtsaService objTtsaService;

    @GetMapping("/list")
    public TableDataInfo list(ObjTtsa objTtsa) {
        startPage();
        List<ObjTtsa> list = objTtsaService.selectObjTtsaList(objTtsa);
        return getDataTable(list);
    }

    @GetMapping("/{guid}")
    public AjaxResult getInfo(@PathVariable String guid) {
        return AjaxResult.success(objTtsaService.selectObjTtsaByGuid(guid));
    }

    @PostMapping
    public AjaxResult add(@RequestBody ObjTtsa objTtsa) {
        return toAjax(objTtsaService.insertObjTtsa(objTtsa));
    }

    @PutMapping
    public AjaxResult edit(@RequestBody ObjTtsa objTtsa) {
        return toAjax(objTtsaService.updateObjTtsa(objTtsa));
    }

    @DeleteMapping("/{guids}")
    public AjaxResult remove(@PathVariable String[] guids) {
        return toAjax(objTtsaService.deleteObjTtsaByGuids(guids));
    }

    @Log(title = "安全考核申请管理", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('ttsa:objttsa:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ObjTtsa objTtsa) {
        List<ObjTtsa> list = objTtsaService.selectObjTtsaList(objTtsa);
        ExcelUtil<ObjTtsa> util = new ExcelUtil<ObjTtsa>(ObjTtsa.class);
        util.exportExcel(response, list, "安全考核申请管理数据");
    }
}
