package com.njcn.product.cnuser.user.controller;


import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.tree.Tree;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.LogUtil;
import com.njcn.product.cnuser.user.pojo.vo.DeptAllTreeVO;
import com.njcn.product.cnuser.user.service.IDeptService;
import com.njcn.web.controller.BaseController;
import com.njcn.web.utils.HttpResultUtil;
import io.swagger.annotations.*;
import lombok.AllArgsConstructor;
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;
import java.util.Objects;

/**
 * <p>
 * 前端控制器(部门信息)
 * </p>
 *
 * @author hongawen
 * @since 2021-12-13
 */
@Validated
@Slf4j
@RestController
@RequestMapping("/dept")
@Api(tags = "部门管理")
@AllArgsConstructor
public class DeptController extends BaseController {

    private final IDeptService deptService;




    /**
     * 根据登录用户获取部门树
     */
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @GetMapping("/loginDeptTree")
    @ApiOperation("根据登录用户获取部门树")
    public HttpResult<Object> loginDeptTree(@RequestParam("deptIndex")String deptIndex) {
        String methodDescribe = getMethodDescribe("loginDeptTree");
        List<DeptAllTreeVO> result = deptService.loginDeptTree(deptIndex);
        if (!result.isEmpty()) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
        } else {

            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.NO_DATA, null, methodDescribe);
        }
    }



}

