package com.njcn.device.pq.controller;


import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.device.biz.pojo.vo.TerminalSelectTreeVO;
import com.njcn.device.pq.pojo.param.DeviceInfoParam;
import com.njcn.device.pq.pojo.vo.DeptLineTreeVO;
import com.njcn.device.pq.pojo.vo.TerminalTree;
import com.njcn.device.pq.service.TerminalTreeService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * pqs
 * 终端树控制器
 * @author cdf
 * @date 2021/7/19
 */
@Slf4j
@Api(tags = "终端树管理")
@RestController
@RequiredArgsConstructor
@RequestMapping("/terminalTree")
public class TerminalTreeController extends BaseController {

    private final TerminalTreeService terminalTreeService;

    @Value("${isJb}")
    private Boolean isJb;

    /**
     * 获取终端台账设备树
     * @author cdf
     * @date 2021/7/19
     */
    @ApiOperation("获取终端树")
    @OperateInfo(info = LogEnum.BUSINESS_MEDIUM)
    @GetMapping("getTerminalTree")
    public HttpResult<List<TerminalTree>> getTerminalTree(){
        String methodDescribe = getMethodDescribe("getTerminalTree");
        List<TerminalTree> tree;
        if(isJb){
            tree= terminalTreeService.getJbNewTerminalTree();
        }else{
            tree= terminalTreeService.getTerminalTree();
        }

        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, tree, methodDescribe);
    }

    /**
     * 获取设备树给前端下拉选择
     */
    @ApiOperation("获取简单的终端树")
    @OperateInfo(info = LogEnum.BUSINESS_MEDIUM)
    @GetMapping("getTerminalSelectTree")
    public HttpResult<List<TerminalSelectTreeVO>> getTerminalSelectTree(Integer level){
        String methodDescribe = getMethodDescribe("getTerminalSelectTree");
        List<TerminalSelectTreeVO> tree = terminalTreeService.getTerminalSelectTree(level);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, tree, methodDescribe);
    }


    /**
     * 获取终端台账设备树
     * @author cdf
     * @date 2021/7/19
     */

    @ApiOperation("获取5层终端树")
    @OperateInfo(info = LogEnum.BUSINESS_MEDIUM)
    @PostMapping("getTerminalTreeForFive")
    @ApiImplicitParam(name = "deviceInfoParam", value = "台账查询参数", required = true)
    public HttpResult<List<TerminalTree>> getTerminalTreeForFive(@RequestBody @Validated DeviceInfoParam deviceInfoParam){
        String methodDescribe = getMethodDescribe("getTerminalTreeForFive");
        List<TerminalTree> tree = terminalTreeService.getTerminalTreeForFive(deviceInfoParam);

        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, tree, methodDescribe);
    }

    /**
     * 根据省份获取部门监测点树
     * @author dhj
     * @date 2022/1/14
     */

    @ApiOperation("根据省份获取部门监测点树")
    @GetMapping("getDeptBindDeptLineTree")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deptId", value = "部门id", required = false),
            @ApiImplicitParam(name = "deptType", value = "部门类型", required = true),
            @ApiImplicitParam(name = "id", value = "区域id", required = false),
            @ApiImplicitParam(name = "type", value = "区域类型", required = true)
    })
    public HttpResult<List<DeptLineTreeVO>> getDeptBindDeptLineTree(@RequestParam("deptId")String deptId, @RequestParam("deptType")Integer deptType,@RequestParam("id")String id, @RequestParam("type")Integer type){
        String methodDescribe = getMethodDescribe("getDeptBindDeptLineTree");
        List<DeptLineTreeVO> tree = terminalTreeService.getDeptBindDeptLineTree(deptId,deptType,id,type);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, tree, methodDescribe);
    }

}
