package com.ag.web.agCommon;

import com.wb.util.DbUtil;

import javax.servlet.http.HttpServletRequest;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/3/14.
 */
public class AgCommonService {
    public  List check(HttpServletRequest request, String menuId, List datalist) throws Exception{
        //定义两个变量
        String postion = String.valueOf(0);
        String parentMenu = "";
        Map dataMap = new HashMap<>();
        dataMap.put("menuId",menuId);
        String sql = " select * from wb_menu where parent_menu = (select parent_menu from wb_menu where menu_id='"+menuId+"')\n" +
                "         order by order_index";
        ResultSet data = (ResultSet) DbUtil.run(request,sql);
        int i=0;
        while (data.next()){
            if(menuId.equals(data.getString("MENU_ID"))){
                postion = String.valueOf(i);
                parentMenu = (String) data.getString("PARENT_MENU");
                break;
            }
            i++;
        }
        if(!parentMenu.equals("-1")){
            datalist.add(postion);
            check(request,parentMenu,datalist);
        }else{
            datalist.add(postion);
        }
        return datalist;
    }
}
