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

@RestController
@RequestMapping("/ttsa/ttsacertchacomp")
public class BisTtsaCertChaCompController extends BaseController {
    @Autowired
    private IBisTtsaCertChaCompService bisTtsaCertChaCompService;

    @GetMapping("/list")
    public TableDataInfo list(BisTtsaCertChaComp bisTtsaCertChaComp) {
        startPage();
        List<BisTtsaCertChaComp> list = bisTtsaCertChaCompService.selectBisTtsaCertChaCompList(bisTtsaCertChaComp);
        return getDataTable(list);
    }

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

    @PostMapping
    public AjaxResult add(@RequestBody BisTtsaCertChaComp bisTtsaCertChaComp) {
        return toAjax(bisTtsaCertChaCompService.insertBisTtsaCertChaComp(bisTtsaCertChaComp));
    }

    @PutMapping
    public AjaxResult edit(@RequestBody BisTtsaCertChaComp bisTtsaCertChaComp) {
        return toAjax(bisTtsaCertChaCompService.updateBisTtsaCertChaComp(bisTtsaCertChaComp));
    }

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

    @Log(title = "单位变更管理", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('ttsa:ttsacertchacomp:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, BisTtsaCertChaComp bisTtsaCertChaComp) {
        List<BisTtsaCertChaComp> list = bisTtsaCertChaCompService.selectBisTtsaCertChaCompList(bisTtsaCertChaComp);
        ExcelUtil<BisTtsaCertChaComp> util = new ExcelUtil<BisTtsaCertChaComp>(BisTtsaCertChaComp.class);
        util.exportExcel(response, list, "单位变更管理数据");
    }
}
