package com.fr.plugin.http.handler; import com.fr.decision.webservice.bean.entry.EntryBean; import com.fr.decision.webservice.v10.entry.EntryService; import com.fr.decision.webservice.v10.login.LoginService; import com.fr.decision.webservice.v10.user.UserService; import com.fr.json.JSONArray; import com.fr.log.FineLoggerFactory; import com.fanruan.api.log.LogKit; import com.fr.decision.fun.impl.BaseHttpHandler; import com.fr.plugin.TOPPConfig; import com.fr.stable.StringUtils; import com.fr.third.fasterxml.jackson.databind.ObjectMapper; import com.fr.third.springframework.web.bind.annotation.RequestMethod; import com.fr.web.utils.WebUtils; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.BufferedReader; import java.util.ArrayList; import java.util.List; public class GETGetTopMenu1Handler extends BaseHttpHandler { @Override public RequestMethod getMethod() { return RequestMethod.GET; } @Override public String getPath() { return "/getTopMenu"; } @Override public boolean isPublic() { return false; } @Override public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception { EntryService instance = EntryService.getInstance(); String username = LoginService.getInstance().getUserNameFromRequest(req); String currentUserId = UserService.getInstance().getCurrentUserId(username); List allEntries = instance.getAllEntries(currentUserId); //找出配置的root TOPPConfig config = TOPPConfig.getInstance(); String topNav = config.getTopNav(); EntryBean top=null; for (EntryBean allEntry : allEntries) { if (StringUtils.equals(topNav,allEntry.getText())) { top=allEntry; break; } } List result = new ArrayList<>(); if(top!=null){ //找他的儿子 for (EntryBean allEntry : allEntries) { if (StringUtils.equals(allEntry.getpId(),top.getId())) { result.add(allEntry); } } } ObjectMapper mapper = new ObjectMapper(); String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(result); WebUtils.printAsJSON(res, new JSONArray(json)); } }