package com.njcn.system.controller;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.OperateType;
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.common.utils.LogUtil;
import com.njcn.system.pojo.param.DictDataParam;
import com.njcn.system.pojo.param.DictTreeParam;
import com.njcn.system.pojo.po.DictData;
import com.njcn.system.pojo.po.SysDicTreePO;
import com.njcn.system.pojo.vo.DictDataVO;
import com.njcn.system.pojo.vo.DictTreeVO;
import com.njcn.system.service.IDictDataService;
import com.njcn.system.service.SysDicTreePOService;
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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author hongawen
 * @since 2021-12-13
 */
@Validated
@Slf4j
@Api(tags = "字典树操作")
@RestController
@RequestMapping("/dictTree")
@RequiredArgsConstructor
public class DictTreeController extends BaseController {

    private final SysDicTreePOService sysDicTreePOService;

    /**
     * 分页查询字典类型数据
     */
//    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
//    @PostMapping("/list")
//    @ApiOperation("查询字典数据")
//    @ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
//    public HttpResult<Page<DictDataVO>> list(@RequestBody @Validated DictDataParam.DictDataQueryParam queryParam) {
//        String methodDescribe = getMethodDescribe("list");
//        LogUtil.njcnDebug(log, "{}，查询数据为：{}", methodDescribe, queryParam);
//        Page<DictDataVO> result = dictDataService.listDictData(queryParam);
//        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
//    }


    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.ADD)
    @PostMapping("/add")
    @ApiOperation("新增字典树数据")
    @ApiImplicitParam(name = "dictTreeParam", value = "字典数据", required = true)
    public HttpResult<Object> add(@RequestBody @Validated DictTreeParam dictTreeParam) {
        String methodDescribe = getMethodDescribe("add");
        LogUtil.njcnDebug(log, "{}，字典数据为：{}", methodDescribe, dictTreeParam);
        boolean result = sysDicTreePOService.addDictTree(dictTreeParam);
        if (result) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
        } else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
        }
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.QUERY)
    @PostMapping("/query")
    @ApiOperation("根据pid查询字典树")
    public HttpResult<List<DictTreeVO>> query(@RequestParam("pid") String pid) {
        String methodDescribe = getMethodDescribe("query");
        LogUtil.njcnDebug(log, "{}，字典数据为：{}", methodDescribe, pid);
        List<DictTreeVO> result = sysDicTreePOService.queryByPid(pid);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);

    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.QUERY)
    @PostMapping("/queryByCode")
    @ApiOperation("根据Code查询字典树")
    public HttpResult<DictTreeVO> queryByCode(@RequestParam("code") String code) {
        String methodDescribe = getMethodDescribe("queryByCode");
        LogUtil.njcnDebug(log, "{}，字典数据为：{}", methodDescribe, code);
        DictTreeVO result = sysDicTreePOService.queryByCode(code);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);

    }
    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.QUERY)
    @PostMapping("/queryByid")
    @ApiOperation("根据id查询字典树最底层")
    public HttpResult<List<DictTreeVO>> queryByid(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("queryByid");
        LogUtil.njcnDebug(log, "{}，字典数据为：{}", methodDescribe, id);
        List<DictTreeVO> result = sysDicTreePOService.queryByid(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);

    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.QUERY)
    @PostMapping("/queryById")
    @ApiOperation("根据id查询数据")
    public HttpResult<SysDicTreePO> queryById(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("queryById");
        LogUtil.njcnDebug(log, "{}，字典数据为：{}", methodDescribe, id);
        SysDicTreePO result = sysDicTreePOService.queryById(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }



}

