package com.siwei.rsmonitoring.controller;

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

import com.siwei.common.core.domain.R;
import com.siwei.common.security.annotation.InnerAuth;
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.siwei.common.log.annotation.Log;
import com.siwei.common.log.enums.BusinessType;
import com.siwei.common.security.annotation.RequiresPermissions;
import com.siwei.rsmonitoring.domain.TDkAuditflowType;
import com.siwei.rsmonitoring.service.ITDkAuditflowTypeService;
import com.siwei.common.core.web.controller.BaseController;
import com.siwei.common.core.web.domain.AjaxResult;
import com.siwei.common.core.utils.poi.ExcelUtil;
import com.siwei.common.core.web.page.TableDataInfo;

/**
 * 地块的审核流程类型Controller
 *
 * @author siwei
 * @date 2025-01-20
 */
@RestController
@RequestMapping("/auditflow/type")
public class TDkAuditflowTypeController extends BaseController {
    @Autowired
    private ITDkAuditflowTypeService tDkAuditflowTypeService;

    /**
     * 查询地块的审核流程类型列表
     */
    @RequiresPermissions("rsmonitoring:auditflow:type:list")
    @GetMapping("/list")
    public TableDataInfo list(TDkAuditflowType tDkAuditflowType) {
        startPage();
        List<TDkAuditflowType> list = tDkAuditflowTypeService.selectTDkAuditflowTypeList(tDkAuditflowType);
        return getDataTable(list);
    }

    /**
     * 导出地块的审核流程类型列表
     */
    @RequiresPermissions("rsmonitoring:auditflow:type:export")
    @Log(title = "地块的审核流程类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TDkAuditflowType tDkAuditflowType) {
        List<TDkAuditflowType> list = tDkAuditflowTypeService.selectTDkAuditflowTypeList(tDkAuditflowType);
        ExcelUtil<TDkAuditflowType> util = new ExcelUtil<TDkAuditflowType>(TDkAuditflowType.class);
        util.exportExcel(response, list, "地块的审核流程类型数据");
    }

    /**
     * 获取地块的审核流程类型详细信息
     */
    @RequiresPermissions("rsmonitoring:auditflow:type:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(tDkAuditflowTypeService.selectTDkAuditflowTypeById(id));
    }

    /**
     * 新增地块的审核流程类型
     */
    @RequiresPermissions("rsmonitoring:auditflow:type:add")
    @Log(title = "地块的审核流程类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TDkAuditflowType tDkAuditflowType) {
        return toAjax(tDkAuditflowTypeService.insertTDkAuditflowType(tDkAuditflowType));
    }

    /**
     * 緩存地块的審核流程類型
     * <br>
     * 内部调用不启动日志3.
     */
    @InnerAuth
    @PostMapping("cache")
    public R<Boolean> cache() {
        tDkAuditflowTypeService.cacheTDkAuditflowType();
        return R.ok(true);
    }

    /**
     * 修改地块的审核流程类型
     */
    @RequiresPermissions("rsmonitoring:auditflow:type:edit")
    @Log(title = "地块的审核流程类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TDkAuditflowType tDkAuditflowType) {
        return toAjax(tDkAuditflowTypeService.updateTDkAuditflowType(tDkAuditflowType));
    }

    /**
     * 删除地块的审核流程类型
     */
    @RequiresPermissions("rsmonitoring:auditflow:type:remove")
    @Log(title = "地块的审核流程类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(tDkAuditflowTypeService.deleteTDkAuditflowTypeByIds(ids));
    }


    /**
     * 查询地块的审核流程类型列表
     */
    //@RequiresPermissions(value = {"rsmonitoring:auditflow:type:tree"})
    @Log(title = "地块的审核流程类型树结构查询", businessType = BusinessType.OTHER)
    @GetMapping("/tree")
    public AjaxResult tree() {
        return success(tDkAuditflowTypeService.selectTDkAuditflowTypeTree());
    }

}
