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.ObjTts;
import com.goldenwater.slaj.ttsa.service.IObjTtsService;

@RestController
@RequestMapping("/ttsa/objtts")
public class ObjTtsController extends BaseController {
    @Autowired
    private IObjTtsService objTtsService;

    @GetMapping("/list")
    public TableDataInfo list(ObjTts objTts) {
        startPage();
        List<ObjTts> list = objTtsService.selectObjTtsList(objTts);
        return getDataTable(list);
    }

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

    @PostMapping
    public AjaxResult add(@RequestBody ObjTts objTts) {
        return toAjax(objTtsService.insertObjTts(objTts));
    }

    @PutMapping
    public AjaxResult edit(@RequestBody ObjTts objTts) {
        return toAjax(objTtsService.updateObjTts(objTts));
    }

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

    @Log(title = "三类人员信息管理", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('ttsa:objtts:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ObjTts objTts) {
        List<ObjTts> list = objTtsService.selectObjTtsList(objTts);
        ExcelUtil<ObjTts> util = new ExcelUtil<ObjTts>(ObjTts.class);
        util.exportExcel(response, list, "三类人员信息管理数据");
    }
}
