package com.red.circle.console.app.command.admin.query;

import com.red.circle.console.app.dto.clienobject.admin.ComboCO;
import com.red.circle.console.infra.database.rds.entity.admin.Menu;
import com.red.circle.console.infra.database.rds.enums.MenuTypeEnum;
import com.red.circle.console.infra.database.rds.service.admin.MenuService;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 查询父级菜单(下拉框).
 *
 * @author pengliang on 2023/5/12
 */
@Component
@RequiredArgsConstructor
public class MenuComboQryExe {

  private final MenuService menuService;

  public List<ComboCO> execute() {
    return menuService.query().select(Menu::getId, Menu::getMenuName)
        .in(Menu::getMenuType, MenuTypeEnum.CATALOG, MenuTypeEnum.MENU)
        .entitys(e -> {
          ComboCO combo = new ComboCO();
          combo.setId(e.getId());
          combo.setName(e.getMenuName());
          return combo;
        });
  }

}
