You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
252 lines
7.6 KiB
252 lines
7.6 KiB
2 years ago
|
package com.fr.plugin.permission.action;
|
||
|
import java.io.PrintWriter;
|
||
|
import java.util.*;
|
||
|
import javax.servlet.http.HttpServletRequest;
|
||
|
import javax.servlet.http.HttpServletResponse;
|
||
|
|
||
|
import com.fr.decision.webservice.bean.entry.EntryBean;
|
||
|
import com.fr.decision.webservice.bean.entry.HomePageBean;
|
||
|
import com.fr.decision.webservice.bean.entry.TemplateBean;
|
||
|
import com.fr.decision.webservice.v10.entry.EntryService;
|
||
|
import com.fr.decision.authority.data.User;
|
||
|
import com.fr.decision.webservice.v10.user.UserService;
|
||
|
import com.fr.fs.cache.EntryTypeAndID;
|
||
|
import com.fr.fs.cache.decision.category.impl.memory.EntryTreeFolderNode;
|
||
|
import com.fr.fs.control.EntryControl;
|
||
|
import com.fr.fs.control.UserControl;
|
||
|
import com.fr.fs.privilege.base.FSPrivilegeTools;
|
||
|
import com.fr.fs.schedule.entry.ReportletEntry;
|
||
|
import com.fr.fs.web.platform.entry.Entry;
|
||
|
import com.fr.fs.web.platform.entry.EntryConstants;
|
||
|
import com.fr.general.ComparatorUtils;
|
||
|
import com.fr.general.FRLogger;
|
||
|
import com.fr.json.JSONArray;
|
||
|
import com.fr.json.JSONException;
|
||
|
import com.fr.log.FineLoggerFactory;
|
||
|
import com.fr.stable.CodeUtils;
|
||
|
import com.fr.stable.StableUtils;
|
||
|
import com.fr.stable.StringUtils;
|
||
|
import com.fr.web.core.ActionNoSessionCMD;
|
||
|
import com.fr.web.utils.WebUtils;
|
||
|
//http://localhost:8075/webroot/decision/view/report?op=permission&cmd=display&user=eoco
|
||
|
public class DirectoryPath extends ActionNoSessionCMD {
|
||
|
private static String paraPath="&__bypagesize__=false&op=h5&username=";
|
||
|
private static String domain="https://xxx.com.cn";
|
||
|
@Override
|
||
|
public String getCMD() {
|
||
|
return "display";
|
||
|
}
|
||
|
@Override
|
||
|
public void actionCMD(HttpServletRequest req, HttpServletResponse res) throws Exception {
|
||
|
PrintWriter out = WebUtils.createPrintWriter(res);
|
||
|
getDisplay(req, out);
|
||
|
out.flush();
|
||
|
out.close();
|
||
|
}
|
||
|
|
||
|
private int getId(String id){
|
||
|
String[] ids = id.split("-");
|
||
|
String last = ids[ids.length -1];
|
||
|
try{
|
||
|
int a = Integer.parseInt(last);
|
||
|
return a;
|
||
|
}
|
||
|
catch(Exception ex){
|
||
|
ex.printStackTrace();
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
protected void getDisplay(HttpServletRequest req,PrintWriter print){
|
||
|
String username = WebUtils.getHTTPRequestParameter(req, "user");
|
||
|
String callback=WebUtils.getHTTPRequestParameter(req, "callback");
|
||
|
com.fr.json.JSONObject outObject= com.fr.json.JSONObject.create();
|
||
|
JSONArray result=JSONArray.create();
|
||
|
try {
|
||
|
User user = UserService.getInstance().getUserByUserName(username);
|
||
|
if(user==null){
|
||
|
outObject.put("reportlets", result);
|
||
|
String out=StringUtils.isBlank(callback)?outObject.toString():callback+"("+outObject.toString()+")";
|
||
|
print.write(out);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
List<EntryBean> entryBeans2 = EntryService.getInstance().getAllEntries(user.getId());
|
||
|
|
||
|
if(entryBeans2.size() > 0){
|
||
|
|
||
|
Map<String,DirNode> idEntryBeanMap = new HashMap<>();
|
||
|
List<DirNode> allNodes = new ArrayList<>();
|
||
|
for(EntryBean bean : entryBeans2){
|
||
|
DirNode dirNode = new DirNode();
|
||
|
dirNode.id = bean.getId();
|
||
|
dirNode.pid = bean.getpId();
|
||
|
dirNode.text = bean.getText();
|
||
|
dirNode.path = bean.getPath();
|
||
|
dirNode.child = new ArrayList<>();
|
||
|
idEntryBeanMap.put(dirNode.id ,dirNode);
|
||
|
allNodes.add(dirNode);
|
||
|
}
|
||
|
|
||
|
List<DirNode> noParentNodes = new ArrayList<>();
|
||
|
|
||
|
for(DirNode dNode : allNodes){
|
||
|
DirNode parent = idEntryBeanMap.get(dNode.pid);
|
||
|
if(parent != null){
|
||
|
parent.child.add(dNode);
|
||
|
}
|
||
|
else{
|
||
|
dNode.text = "管理目录";
|
||
|
noParentNodes.add(dNode);
|
||
|
}
|
||
|
}
|
||
|
iterateChild(result,noParentNodes,req,username);
|
||
|
FineLoggerFactory.getLogger().info( "noParentNodes:"+noParentNodes.size());
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
if(result.length() > 0){
|
||
|
com.fr.json.JSONObject re = (com.fr.json.JSONObject)result.get(0);
|
||
|
JSONArray result1 = (JSONArray)re.get("child");
|
||
|
if(result1 != null){
|
||
|
outObject.put("reportlets",result1);
|
||
|
}
|
||
|
else{
|
||
|
outObject.put("reportlets",JSONArray.create());
|
||
|
}
|
||
|
}
|
||
|
else{
|
||
|
outObject.put("reportlets",JSONArray.create());
|
||
|
}
|
||
|
|
||
|
|
||
|
String out=StringUtils.isBlank(callback)?outObject.toString():callback+"("+outObject.toString()+")";
|
||
|
print.write(out);
|
||
|
} catch (Exception e) {
|
||
|
FRLogger.getLogger().errorWithServerLevel(e.getMessage(), e);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void iterateChild(JSONArray result,List<DirNode> nodes,HttpServletRequest req,String username) throws JSONException {
|
||
|
for(DirNode node : nodes){
|
||
|
com.fr.json.JSONObject childJson = com.fr.json.JSONObject.create();
|
||
|
result.put(childJson);
|
||
|
childJson.put("id", getId(node.id));
|
||
|
childJson.put("name", node.text);
|
||
|
childJson.put("url", getNewUrlByPath(req,username,node.path));
|
||
|
JSONArray resultChilds = JSONArray.create();
|
||
|
childJson.put("child",resultChilds);
|
||
|
if(node.child != null && node.child.size() > 0){
|
||
|
iterateChild(resultChilds,node.child,req,username);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 得到新的url
|
||
|
* @param req
|
||
|
* @param type
|
||
|
* @param id
|
||
|
* @param username
|
||
|
* @return
|
||
|
*/
|
||
|
protected String getUrl(HttpServletRequest req,int type,long id,String username){
|
||
|
String url="";
|
||
|
Entry entry = EntryControl.getInstance().getEntry(type, id);
|
||
|
if(entry instanceof ReportletEntry){
|
||
|
ReportletEntry re=(ReportletEntry)entry;
|
||
|
url=re.getWebletPath();
|
||
|
String reportpara="reportlet=";
|
||
|
if(url.endsWith(".frm")){
|
||
|
reportpara="formlet=";
|
||
|
}
|
||
|
url=domain+req.getRequestURI().toString()+"?"+reportpara+url+paraPath+username;
|
||
|
}
|
||
|
return CodeUtils.cjkEncode(url);
|
||
|
}
|
||
|
|
||
|
protected String getNewUrlByEntryBean(HttpServletRequest req,String username,EntryBean bean){
|
||
|
String url="";
|
||
|
if(bean != null){
|
||
|
if(bean instanceof HomePageBean) {
|
||
|
HomePageBean re = (HomePageBean) bean;
|
||
|
url = re.getMobileHomePage();
|
||
|
if (StringUtils.isEmpty(url)) {
|
||
|
url = re.getPcHomePage();
|
||
|
}
|
||
|
if (StringUtils.isEmpty(url)) {
|
||
|
url = re.getPadHomePage();
|
||
|
}
|
||
|
String reportpara = "reportlet=";
|
||
|
if (url.endsWith(".frm")) {
|
||
|
reportpara = "formlet=";
|
||
|
}
|
||
|
url = domain + req.getRequestURI().toString() + "?" + reportpara + url + paraPath + username;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return CodeUtils.cjkEncode(url);
|
||
|
}
|
||
|
|
||
|
|
||
|
protected String getNewUrlByPath(HttpServletRequest req,String username,String path){
|
||
|
String url="";
|
||
|
if(StringUtils.isNotEmpty(path)){
|
||
|
url = path;
|
||
|
String reportpara = "reportlet=";
|
||
|
if (url.endsWith(".frm")) {
|
||
|
reportpara = "formlet=";
|
||
|
}
|
||
|
url = domain + req.getRequestURI().toString() + "?" + reportpara + url + paraPath + username;
|
||
|
}
|
||
|
|
||
|
return CodeUtils.cjkEncode(url);
|
||
|
}
|
||
|
/**
|
||
|
* 的到新的JSONArray
|
||
|
* @param req
|
||
|
* @param oldArr
|
||
|
* @param resultArr
|
||
|
* @param username
|
||
|
* @throws JSONException
|
||
|
*/
|
||
|
protected void copyJSONArray(HttpServletRequest req,JSONArray oldArr,JSONArray resultArr,String username) throws JSONException{
|
||
|
int len=oldArr.length();
|
||
|
for(int i=0;i<len;i++){
|
||
|
com.fr.json.JSONObject oldObj=oldArr.getJSONObject(i);
|
||
|
com.fr.json.JSONObject resultObj= com.fr.json.JSONObject.create();
|
||
|
String id=oldObj.optString("id").substring(1);//去掉第一位的,第一位是type
|
||
|
// System.out.println(">>>>>> id:"+id);
|
||
|
resultObj.put("id", id);
|
||
|
resultObj.put("name", oldObj.optString("text"));
|
||
|
JSONArray resultChilds=JSONArray.create();
|
||
|
if(oldObj.optBoolean("hasChildren")&&oldObj.has("ChildNodes")){
|
||
|
JSONArray childs=oldObj.getJSONArray("ChildNodes");
|
||
|
copyJSONArray(req,childs,resultChilds,username);
|
||
|
}
|
||
|
String url=getUrl(req,oldObj.optInt("type"), Long.valueOf(id),username);
|
||
|
resultObj.put("url", url);
|
||
|
resultObj.put("child", resultChilds);
|
||
|
|
||
|
resultArr.put(resultObj);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
class DirNode{
|
||
|
public String id;
|
||
|
public String pid;
|
||
|
|
||
|
public String text;
|
||
|
public String path;
|
||
|
|
||
|
public DirNode parent;
|
||
|
|
||
|
public List<DirNode> child;
|
||
|
|
||
|
|
||
|
}
|