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.
122 lines
3.7 KiB
122 lines
3.7 KiB
4 years ago
|
package com.fr.plugin.cogons.handler;
|
||
|
|
||
|
import com.fr.base.TableData;
|
||
|
import com.fr.base.TemplateUtils;
|
||
|
import com.fr.decision.fun.impl.BaseHttpHandler;
|
||
|
import com.fr.file.TableDataConfig;
|
||
|
import com.fr.general.data.DataModel;
|
||
|
import com.fr.plugin.cogons.utils.FRUserUtils;
|
||
|
import com.fr.plugin.cogons.utils.FRUtils;
|
||
|
import com.fr.plugin.cogons.utils.ResponseUtils;
|
||
|
import com.fr.plugin.cogons.utils.Utils;
|
||
|
import com.fr.plugin.transform.FunctionRecorder;
|
||
|
import com.fr.script.Calculator;
|
||
|
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 java.util.HashMap;
|
||
|
import java.util.Map;
|
||
|
|
||
|
@FunctionRecorder
|
||
|
public class ShowCogons extends BaseHttpHandler {
|
||
|
|
||
|
|
||
|
public ShowCogons() {
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public RequestMethod getMethod() {
|
||
|
return RequestMethod.GET;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public String getPath() {
|
||
|
return "/showCogons";
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public boolean isPublic() {
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception {
|
||
|
boolean isIE = isIEBrowser(req);
|
||
|
//获取请求参数
|
||
|
String action = req.getParameter("action");
|
||
|
|
||
|
if(isIE){
|
||
|
action = Utils.encodeCH(action);
|
||
|
}
|
||
|
//当前登录名
|
||
|
String username = null;
|
||
|
try {
|
||
|
username = FRUserUtils.getCurrentUser(req).getUserName();
|
||
|
} catch (Exception e) {
|
||
|
ResponseUtils.failedResponse(res,"获取当前登录用户失败");
|
||
|
}
|
||
|
|
||
|
//获取orgId
|
||
|
// String orgId = "11";
|
||
|
String orgId = getOrgId(username);
|
||
|
|
||
|
if(Utils.isNullStr(orgId)){
|
||
|
ResponseUtils.failedResponse(res,"获取"+username+"orgId失败!");
|
||
|
}
|
||
|
|
||
|
Map<String, String> parameterMap = new HashMap<String, String>();
|
||
|
String path = "/com/fr/plugin/cogons/html/cogons.html";
|
||
|
parameterMap.put("action", action);
|
||
|
parameterMap.put("orgId", orgId);
|
||
|
String macPage = TemplateUtils.renderTemplate(path, parameterMap);
|
||
|
WebUtils.printAsString(res, macPage);
|
||
|
}
|
||
|
|
||
|
private static String getOrgId(String username){
|
||
|
FRUtils.FRLogInfo("username:"+username);
|
||
|
|
||
|
//orgid
|
||
|
String orgId = "";
|
||
|
//获取服务器数据集
|
||
|
TableData userInfo = TableDataConfig.getInstance().getTableData("userInfo");
|
||
|
DataModel userInfoDM = userInfo.createDataModel(Calculator.createCalculator());
|
||
|
|
||
|
try{
|
||
|
//获取行号
|
||
|
int rowCount = userInfoDM.getRowCount();
|
||
|
FRUtils.FRLogInfo("rowCount " + rowCount);
|
||
|
//获取用户id,机构号列号
|
||
|
int useridIndex = userInfoDM.getColumnIndex("用户ID");
|
||
|
int orgidIndex = userInfoDM.getColumnIndex("核心机构号");
|
||
|
|
||
|
for(int i =0;i<rowCount;i++){
|
||
|
String userId =String.valueOf(userInfoDM.getValueAt(i,useridIndex));
|
||
|
|
||
|
if(username.equals(userId)){
|
||
|
orgId = String.valueOf(userInfoDM.getValueAt(i,orgidIndex));
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}catch (Exception e){
|
||
|
FRUtils.FRLogError("获取orgId异常:"+e.getMessage());
|
||
|
}
|
||
|
|
||
|
return orgId;
|
||
|
}
|
||
|
|
||
|
public boolean isIEBrowser(HttpServletRequest request) {
|
||
|
String[] IEBrowserSignals = {"MSIE", "Trident", "Edge"};
|
||
|
String userAgent = request.getHeader("User-Agent");
|
||
|
for (String signal : IEBrowserSignals) {
|
||
|
if (userAgent.contains(signal)){
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
|