package com.ruoyi.zongzhi.controller;

import java.util.List;
import io.swagger.annotations.Api;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zongzhi.domain.TcIdcUnit;
import com.ruoyi.zongzhi.service.ITcIdcUnitService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * IDC单位Controller
 * 
 * @author ruoyi
 * @date 2023-08-10
 */
@RestController
@RequestMapping("/zongzhi/idcunit")
@Api(tags = " IDC单位")
public class TcIdcUnitController extends BaseController
{
    @Autowired
    private ITcIdcUnitService tcIdcUnitService;

    /**
     * 查询IDC单位列表
     */

    @GetMapping("/list")
    public TableDataInfo list(TcIdcUnit tcIdcUnit)
    {
        startPage();
        List<TcIdcUnit> list = tcIdcUnitService.selectTcIdcUnitList(tcIdcUnit);
        return getDataTable(list);
    }

    /**
     * 导出IDC单位列表
     */

    @PostMapping("/export")
    public void export(HttpServletResponse response, TcIdcUnit tcIdcUnit)
    {
        List<TcIdcUnit> list = tcIdcUnitService.selectTcIdcUnitList(tcIdcUnit);
        ExcelUtil<TcIdcUnit> util = new ExcelUtil<TcIdcUnit>(TcIdcUnit.class);
        util.exportExcel(response, list, "IDC单位数据");
    }

    /**
     * 获取IDC单位详细信息
     */

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tcIdcUnitService.selectTcIdcUnitById(id));
    }

    /**
     * 新增IDC单位
     */

    @PostMapping
    public AjaxResult add(@RequestBody TcIdcUnit tcIdcUnit)
    {
        tcIdcUnit.setIsStatus(true);
        return toAjax(tcIdcUnitService.insertTcIdcUnit(tcIdcUnit));
    }

    /**
     * 修改IDC单位
     */

    @PutMapping
    public AjaxResult edit(@RequestBody TcIdcUnit tcIdcUnit)
    {
        return toAjax(tcIdcUnitService.updateTcIdcUnit(tcIdcUnit));
    }

    /**
     * 删除IDC单位
     */

	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tcIdcUnitService.deleteTcIdcUnitByIds(ids));
    }
}
