package com.fjhx.service.common.impl;

import com.alibaba.fastjson.JSONObject;
import com.fjhx.service.common.CommonService;
import com.fjhx.utils.TreeUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.system.entity.Dept;
import org.springblade.system.feign.ISysClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description:
 * @ClassName: CommonServiceImpl
 * @Author: linqt
 * @Date: 2022/11/29 11:57
 * @Version: 1.0
 */
@Service
public class CommonServiceImpl implements CommonService {

    @Autowired
    private ISysClient iSysClient;

    /**
     * 获取部门树
     *
     * @return
     */
    @Override
    public List<JSONObject> deptTree() {
        List<Dept> depts = iSysClient.getDepts();
        if (Func.isEmpty(depts)) {
            return new ArrayList<>();
        }

        return TreeUtil.buildTreeObj(depts);
    }
}
