package com.ruoyi.tcZz.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.tcZz.domain.TcGzdt;
import com.ruoyi.tcZz.domain.TcIdcdw;
import com.ruoyi.tcZz.service.ITcIdcdwService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

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

/**
 * IDC单位Controller
 *
 * @author ruoyi
 * @date 2023-10-13
 */
@RestController
@Api(tags = "IDC单位")
@RequestMapping("/tcZz/networkSecurity/idcdw")
public class TcIdcdwController extends BaseController {
    @Autowired
    private ITcIdcdwService tcIdcdwService;

    /**
     * 查询 IDC单位列表
     */
    @ApiOperation(value = "查询IDC单位列表", response = TcIdcdw.class)
    @GetMapping("/list")
    public TableDataInfo list(TcIdcdw tcIdcdw) {
        startPage();
        List<TcIdcdw> list = tcIdcdwService.selectTcIdcdwList(tcIdcdw);
        return getDataTable(list);
    }

    /**
     * 导出 IDC单位列表
     */
    @ApiOperation(value = "导出IDC单位列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response, TcIdcdw tcIdcdw) {
        List<TcIdcdw> list = tcIdcdwService.selectTcIdcdwList(tcIdcdw);
        ExcelUtil<TcIdcdw> util = new ExcelUtil<TcIdcdw>(TcIdcdw.class);
        util.exportExcel(response, list, " IDC单位数据");
    }

    /**
     * 获取IDC单位详细信息
     */
    @ApiOperation(value = "获取IDC单位详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(tcIdcdwService.selectTcIdcdwById(id));
    }

    /**
     * 新增 IDC单位
     */
    @ApiOperation(value = "新增IDC单位")
    @PostMapping
    public AjaxResult add(@RequestBody TcIdcdw tcIdcdw) {
        return toAjax(tcIdcdwService.insertTcIdcdw(tcIdcdw));
    }

    /**
     * 修改 IDC单位
     */
    @ApiOperation(value = "修改IDC单位")
    @PutMapping
    public AjaxResult edit(@RequestBody TcIdcdw tcIdcdw) {
        return toAjax(tcIdcdwService.updateTcIdcdw(tcIdcdw));
    }

    /**
     * 删除 IDC单位
     */
    @ApiOperation(value = "删除IDC单位")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tcIdcdwService.deleteTcIdcdwByIds(ids));
    }

    /**
     * 导入
     */
    @ApiOperation("通用导入excel信息")
    @PostMapping("/common/importExcel")
    public AjaxResult importExcel(MultipartFile file) throws Exception {
        ExcelUtil<TcIdcdw> util = new ExcelUtil<TcIdcdw>(TcIdcdw.class);
        List<TcIdcdw> tcIdcdwList = util.importExcel(file.getInputStream());
        tcIdcdwService.importUser(tcIdcdwList);
        return AjaxResult.success();
    }

    /**
     * 批量启用禁用
     *
     * @param isStatus 启用禁用状态
     * @return
     */

    @ApiOperation("批量启用禁用")
    @GetMapping("/isStatus")
    public AjaxResult isStatus(@RequestParam("isStatus") Integer isStatus, @RequestParam("ids") List<String> ids) {
        tcIdcdwService.updateByisStatus(isStatus, ids);
        return AjaxResult.success();
    }

    @ApiOperation("通用下载excel模板")
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<TcIdcdw> util = new ExcelUtil<TcIdcdw>(TcIdcdw.class);
        util.importTemplateExcel(response, " IDC单位");
    }
}
