package cn.qinys.platform.upms.api.resp;

import cn.qinys.platform.base.utils.SpringUtil;
import cn.qinys.platform.entity.upms.UpmsMenuPermission;
import cn.qinys.platform.upms.api.mapper.UpmsMenuPermissionMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Description:
 *
 * @author tanlie
 * Date: 2024/2/5 15:39
 */
@Data
public class RoleMenusTreeResp implements Serializable {

    private Integer id;

    private String component;

    private String hidden;

    private String icon;

    private String keepAlive;

    private Boolean leaf;

    private Integer ord;

    private Integer parentId;

    private String path;

    private String title;

    private List<UpmsMenuPermission> permissions;

    private List<RoleMenusTreeResp> children;

    public List<UpmsMenuPermission> getPermissions() {
        UpmsMenuPermissionMapper mapper = SpringUtil.getBean(UpmsMenuPermissionMapper.class);
        QueryWrapper<UpmsMenuPermission> wrapper = new QueryWrapper<>();
        wrapper.eq("menu_id", id);
        wrapper.orderByAsc("id");
        List<UpmsMenuPermission> res = mapper.selectList(wrapper);
        return res == null ? new ArrayList<>() : res;
    }

}
