package com.ruoyi.system.domain;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysMenu;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.mapper.SysUserPostMapper;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Treeselect树结构实体类
 * 
 * @author ruoyi
 */
public class TreeSelectNew implements Serializable
{
    private static final long serialVersionUID = 1L;

    /** 节点ID */
    private Long id;

    /** 节点名称 */
    private String label;

    /** 子节点 */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<TreeSelectNew> children;

    public TreeSelectNew()
    {

    }

    public TreeSelectNew(SysDept dept)
    {
        this.id = dept.getDeptId();
        SysUser sysUser = new SysUser();
        sysUser.setDeptId(dept.getDeptId());
        SysUserMapper userMapper = SpringUtils.getBean(SysUserMapper.class);
        List<SysUser> list = userMapper.selectUserList(sysUser);
        if (dept.getDeptId() == 103) {
            SysUserPostMapper userPostMapper = SpringUtils.getBean(SysUserPostMapper.class);
            list = userPostMapper.selectGmAssistant(new SysUser());
        }
        String count = "(" + (list == null ? 0 : list.size()) + ")";
        this.label = dept.getDeptName() + count;
        this.children = dept.getChildren().stream().map(TreeSelectNew::new).collect(Collectors.toList());
    }

    public TreeSelectNew(SysMenu menu)
    {
        this.id = menu.getMenuId();
        this.label = menu.getMenuName();
        this.children = menu.getChildren().stream().map(TreeSelectNew::new).collect(Collectors.toList());
    }

    public Long getId()
    {
        return id;
    }

    public void setId(Long id)
    {
        this.id = id;
    }

    public String getLabel()
    {
        return label;
    }

    public void setLabel(String label)
    {
        this.label = label;
    }

    public List<TreeSelectNew> getChildren()
    {
        return children;
    }

    public void setChildren(List<TreeSelectNew> children)
    {
        this.children = children;
    }
}
