package com.ruoyi.ibs.tabs.controller;

import java.rmi.ServerException;
import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.vo.DeptUserTreeVo;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.ibs.tabs.domain.dto.ListTabDTO;
import com.ruoyi.ibs.tabs.domain.dto.TabAddDTO;
import com.ruoyi.ibs.tabs.domain.dto.TabEditDTO;
import com.ruoyi.ibs.tabs.domain.entity.CustTabListInfo;
import com.ruoyi.ibs.tabs.domain.vo.CustTabIdDetailVO;
import com.ruoyi.ibs.tabs.domain.vo.CustTabListVo;
import com.ruoyi.ibs.tabs.domain.vo.PotListVo;
import com.ruoyi.ibs.tabs.domain.vo.TopTabVo;
import com.ruoyi.ibs.tabs.service.ICustTabListInfoService;
import com.ruoyi.system.service.ISysDeptService;
import io.swagger.annotations.*;
import org.springframework.beans.BeanUtils;
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.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 指标层级关系Controller
 * 
 * @author ruoyi
 * @date 2024-12-30
 */
@RestController
@Api(tags = "指标层级关系Controller")
@RequestMapping("/system/tabs/")

public class CustTabListInfoController extends BaseController
{
    @Autowired
    private ICustTabListInfoService custTabListInfoService;

    @Autowired
    private ISysDeptService iSysDeptService;



    @GetMapping("/listTopTab")
    @Log(title = "指标层级-查询指标文件夹")
    @ApiOperation("查询指标文件夹")
    public R<List<TopTabVo>> listTopTab(@ApiParam(value = "指标大类名") String tabTypeName,@ApiParam(value = "指标类型") String custType    )
    {
        return  R.ok(custTabListInfoService.selectTopTabList(tabTypeName,custType));

    }



    @GetMapping("/listPot")
    @Log(title = "指标层级-查询指标口径")
    @ApiOperation("查询指标口径")
    public R<List<PotListVo>> listPot(String tabThresholdType)
    {
        return  R.ok(custTabListInfoService.listPot(tabThresholdType));
    }

    /**
     * 查询指标层级关系列表
     */
//    @PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/listTab")
    @Log(title = "指标层级-查询指标列表")
    @ApiOperation("查询指标列表")
    public R<List<CustTabListVo>> listTab(ListTabDTO listTabDTO)
    {
        startPage();
        return R.ok(  custTabListInfoService.listTab(listTabDTO));
    }



//    /**
//     * 导出指标层级关系列表
//     */
//    @PreAuthorize("@ss.hasPermi('system:info:export')")
//    @Log(title = "指标层级-指标层级关系", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, CustTabListInfo custTabListInfo)
//    {
//        List<CustTabListInfo> list = custTabListInfoService.selectCustTabListInfoList(custTabListInfo);
//        ExcelUtil<CustTabListInfo> util = new ExcelUtil<CustTabListInfo>(CustTabListInfo.class);
//        util.exportExcel(response, list, "指标层级关系数据");
//    }

    /**
     * 获取指标层级关系详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/{id}")
    @Log(title = "指标层级-查询指标详情")
    @ApiOperation("查询指标详情")
    public R<CustTabIdDetailVO> getInfo(@PathVariable("id") Long id)
    {
        return R.ok(custTabListInfoService.selectCustTabListInfoById(id));
    }

    /**
     * 新增指标层级关系
     */
//    @PreAuthorize("@ss.hasPermi('system:info:add')")
    @Log(title = "指标层级-指标层级关系", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增指标层级关系")
    public R<Object> add(@RequestBody TabAddDTO tabAddDTO) throws ServerException {
        return R.ok(custTabListInfoService.insertCustTabListInfo(tabAddDTO));
    }

    /**
     * 修改指标层级关系
     */
//    @PreAuthorize("@ss.hasPermi('system:info:edit')")
    @Log(title = "指标层级-指标层级关系", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改指标层级关系")
    public R<Object> edit(@RequestBody TabEditDTO tabDTO) throws ServerException {
        return R.ok(custTabListInfoService.updateCustTabListInfo(tabDTO));
    }

    /**
     * 删除指标层级关系
     */
//    @PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "指标层级-删除指标层级关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    @ApiOperation("删除指标层级关系")
    public R<Object> remove(@PathVariable Long id) throws ServerException {
        return R.ok(custTabListInfoService.deleteCustTabListInfoById(id));
    }

    @Log(title = "指标层级-查询柜员树", businessType = BusinessType.DELETE)
    @GetMapping("/deptUser")
    @ApiOperation("查询柜员树")
    public R<DeptUserTreeVo> deptUser(Long deptId)  {
        return R.ok(iSysDeptService.deptUser(deptId));
    }

    @Log(title = "指标层级-启动停用", businessType = BusinessType.UPDATE)
    @PutMapping("/isStart")
    @ApiOperation("启动停用")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "status", value = "0为停用，1为启动", dataType = "String", dataTypeClass = String.class),
    })
    public R<Object> edit(Long id,String status) throws ServerException {
        return R.ok(custTabListInfoService.isStart(id,status));
    }
}
