package com.ruoyi.tcZz.controller;

import com.ruoyi.common.annotation.Log;
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.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.tcZz.domain.TcJbsjndfltj;
import com.ruoyi.tcZz.domain.TcJgdw;
import com.ruoyi.tcZz.service.ITcJgdwService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

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

/**
 * 监管单位Controller
 *
 * @author ruoyi
 * @date 2023-10-13
 */
@RestController
@Api(tags = "监管单位")
@RequestMapping("/tcZz/networkSecurity/jgdw")
public class TcJgdwController extends BaseController {
    @Autowired
    private ITcJgdwService tcJgdwService;

    /**
     * 查询监管单位列表
     */
    @PreAuthorize("@ss.hasPermi('tcZz/networkSecurity:jgdw:list')")
    @GetMapping("/list")
    public TableDataInfo list(TcJgdw tcJgdw) {
        startPage();
        List<TcJgdw> list = tcJgdwService.selectTcJgdwList(tcJgdw);
        return getDataTable(list);
    }

    /**
     * 导出监管单位列表
     */
    @PreAuthorize("@ss.hasPermi('tcZz/networkSecurity:jgdw:export')")
    @Log(title = "监管单位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TcJgdw tcJgdw) {
        List<TcJgdw> list = tcJgdwService.selectTcJgdwList(tcJgdw);
        ExcelUtil<TcJgdw> util = new ExcelUtil<TcJgdw>(TcJgdw.class);
        util.exportExcel(response, list, "监管单位数据");
    }

    /**
     * 获取监管单位详细信息
     */
    @PreAuthorize("@ss.hasPermi('tcZz/networkSecurity:jgdw:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(tcJgdwService.selectTcJgdwById(id));
    }

    /**
     * 新增监管单位
     */
    @PreAuthorize("@ss.hasPermi('tcZz/networkSecurity:jgdw:add')")
    @Log(title = "监管单位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TcJgdw tcJgdw) {
        return toAjax(tcJgdwService.insertTcJgdw(tcJgdw));
    }

    /**
     * 修改监管单位
     */
    @PreAuthorize("@ss.hasPermi('tcZz/networkSecurity:jgdw:edit')")
    @Log(title = "监管单位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TcJgdw tcJgdw) {
        return toAjax(tcJgdwService.updateTcJgdw(tcJgdw));
    }

    /**
     * 删除监管单位
     */
    @PreAuthorize("@ss.hasPermi('tcZz/networkSecurity:jgdw:remove')")
    @Log(title = "监管单位", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tcJgdwService.deleteTcJgdwByIds(ids));
    }


    /**
     * 查询监管单位列表
     */
    @ApiOperation(value = "查询监管单位列表", response = TcJgdw.class)
    @GetMapping("/ListNoToken")
    public TableDataInfo ListNoToken(TcJgdw tcJgdw) {
        startPage();
        List<TcJgdw> list = tcJgdwService.selectTcJgdwList(tcJgdw);
        return getDataTable(list);
    }


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

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

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

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