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

import cn.qinys.platform.base.utils.SpringUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import cn.qinys.platform.entity.upms.UpmsMenuPermissionBase;
import cn.qinys.platform.upms.api.mapper.UpmsMenuPermissionBaseMapper;
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 MenuPageResp 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<UpmsMenuPermissionBase> permissions;

    private List<MenuPageResp> children;


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

}
