package com.ruoyi.zongzhi.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.zongzhi.domain.TcDengbaoUnit;
import com.ruoyi.zongzhi.service.ITcDengbaoUnitService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 等保单位Controller
 *
 * @author ruoyi
 * @date 2023-08-10
 */
@RestController
@RequestMapping("/zongzhi/dengbaounit")
@Api(tags = " 等保单位")
public class TcDengbaoUnitController extends BaseController {
    @Autowired
    private ITcDengbaoUnitService tcDengbaoUnitService;

    /**
     * ·
     * 查询等保单位列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TcDengbaoUnit tcDengbaoUnit) {
        startPage();
        List<TcDengbaoUnit> list = tcDengbaoUnitService.selectTcDengbaoUnitList(tcDengbaoUnit);
        return getDataTable(list);
    }

    /**
     * 导出等保单位列表
     */

    @PostMapping("/export")
    public void export(HttpServletResponse response, TcDengbaoUnit tcDengbaoUnit) {
        List<TcDengbaoUnit> list = tcDengbaoUnitService.selectTcDengbaoUnitList(tcDengbaoUnit);
        ExcelUtil<TcDengbaoUnit> util = new ExcelUtil<TcDengbaoUnit>(TcDengbaoUnit.class);
        util.exportExcel(response, list, "等保单位数据");
    }

    /**
     * 获取等保单位详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(tcDengbaoUnitService.selectTcDengbaoUnitById(id));
    }

    /**
     * 新增等保单位
     */
    @PostMapping
    public AjaxResult add(@RequestBody TcDengbaoUnit tcDengbaoUnit) {
        tcDengbaoUnit.setIsStatus(true);
        return toAjax(tcDengbaoUnitService.insertTcDengbaoUnit(tcDengbaoUnit));
    }

    /**
     * 修改等保单位
     */
    @PutMapping
    public AjaxResult edit(@RequestBody TcDengbaoUnit tcDengbaoUnit) {
        return toAjax(tcDengbaoUnitService.updateTcDengbaoUnit(tcDengbaoUnit));
    }

    /**
     * 删除等保单位
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tcDengbaoUnitService.deleteTcDengbaoUnitByIds(ids));
    }
}
