| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471 |
- package ss;
- import java.io.Serial;
- import jakarta.servlet.annotation.WebServlet;
- import jakarta.servlet.http.HttpServlet;
- import jakarta.servlet.http.HttpServletRequest;
- import jakarta.servlet.http.HttpServletResponse;
- import jakarta.servlet.http.HttpSession;
- import org.apache.commons.lang3.StringUtils;
- import org.apache.logging.log4j.LogManager;
- import org.apache.logging.log4j.Logger;
- import base.SsC;
- import ss.db.SqlCmd;
- import ss.db.Db;
- import ss.log.SsLog;
- import ss.page.PageU;
- import ss.serv.ServC;
- import ss.user.UserC;
- import ss.user.UserDevRunB;
- import ss.user.UserRunB;
- import ss.user.UserU;
- // 来自 MisIndexAction implements Action。Lin
- @WebServlet(WebC.SPATH_initLogin)
- public class IndexS extends HttpServlet {
- @Serial
- private static final long serialVersionUID = 1L;
-
- private static final String FORWARD_REDIRECT = "wdIndexforwardRedirect"; // 去掉 public,VisitUtil 并过来了。Lin
- // 增加,去掉 e.printStackTrace(),改用 log4j -- 按 IDEA 规范。Lin
- private static final Logger log4j = LogManager.getLogger(IndexS.class);
- /*
- // 有时是 Get 方法,有时是 Post 方法。Lin
- @Override
- protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- this.doPost(req, resp);
- }
- // 来自 @Override(implements Action)
- // MisIndexAction.service(HttpServletRequest request, HttpServletResponse response)。Lin
- @Override
- protected void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- */
- @Override
- protected void service(HttpServletRequest request, HttpServletResponse response) {
- HttpSession session = request.getSession(); // 再增加,不重复取。Lin
- // ActionErrors errors = new ActionErrors();
- // ActionForward forward = new ActionForward();
- // if(checkAgentIsMobile(request.getHeader("User-Agent")) && new
- // File(CoreConstVars.webRoot+"/mobile/index.html").exists()){
- // Cookie cookie = getCookie("device",request.getCookies());
- // if(cookie == null || cookie.getValue().equalsIgnoreCase("app")){
- // forward.setPath("/mobile/index.html");
- // return forward;
- // }
- // }
- // Boolean isMobile=checkAgentIsMobile(request.getHeader("User-Agent"));
- // if (isMobile) {
- // Cookie cookie = getCookie("device", request.getCookies());
- // if (cookie == null || cookie.getValue().equalsIgnoreCase("app")) {
- // forward.setRedirect(true);
- // }
- // }
- // return value
- // GeneralDBAccess gdba = GeneralDBAccess
- // .getInstance(ConstVars.DB_JDNI_NAME);
- try {
- // 读取输入的URL
- /* 再改,增加 session(HttpSession),不重复取。Lin
- String indexPath = getMisIndexPath(request); // VisitUtil.,移过来了。Lin
- */ String indexPath = getMisIndexPath(request, session); // VisitUtil.,移过来了。Lin
- // setUserInfoIntoRequest(request);
- boolean redirect = false;
- String atrStr = (String) request.getAttribute(FORWARD_REDIRECT); // 增加,处理空值。Lin
- if (atrStr != null && atrStr.equals("1")) {
- // forward.setRedirect(true);
- redirect = true;
- }
- if (StringUtils.isBlank(indexPath)) { // 去掉 StrU.isNull(),直接用 StringUtils.isBlank()。Lin
- SsLog.print("没有找到首页:"+ request.getServerName());
- response.sendError(HttpServletResponse.SC_BAD_REQUEST,
- "home page not found: " + request.getServerName());
- return;
- }
- // autoLogin默认值为1,表示如果session已经存在已登录用户就不用再登录了
- /* 增加,处理空值。Lin
- Boolean autoLogin = "0".equals(request.getParameter("autoLogin")) ? false : true;
- */
- boolean autoLogin = false;
- atrStr = request.getParameter("autoLogin");
- if (atrStr != null && atrStr.equals("1"))
- autoLogin = true;
- Object level = session.getAttribute(UserC.LOGIN_level); // = request.getSession().。Lin
- // CoreConstVars.SESSION_LOGIN_LEVEL。Lin
- // 已登录用户打开首页自动跳转
- /* 再改,增加 UserU.rdOrigUserBySess(session),便于维护。Lin
- WdYh yh = (WdYh) request.getSession().getAttribute(
- ServiceConst.WD_YYH);
- */ UserRunB yh = UserU.rdOrigUserBySess(session);
- if (autoLogin
- && yh != null
- // && yh.getGxhym() != null // 去掉 .gxhym,不能放在 UserPo 里。Lin
- && level != null
- && level.toString().equals(UserC.LOGIN_sysLevel)) {
- // CoreConstVars.LOGIN_LEVEL_SYS_LOGIN。Lin
- response.sendRedirect(WebC.PPATH_home); // yh.getGxhym()。去掉 .gxhym,直接用 WebC.PPATH_home。Lin
- return ;
- }
- // forward.setPath(indexPath);
- if (redirect) {
- response.sendRedirect(indexPath);
- } else {
- request.getRequestDispatcher(indexPath).forward(request, response);
- }
- } catch (Exception e) {
- /* 改,去掉 e.printStackTrace(),改用 log4j -- 按 IDEA 规范。Lin
- e.printStackTrace();
- */ log4j.error("IndexS.service( 异常", e);
- // errors.add("name", new ActionError("id"));
- /* 再改。IDEA:Empty 'finally' block。Lin
- } finally {
- // gdba.close();
- */
- }
- // if (!errors.isEmpty()) {
- // saveErrors(request, errors);
- // }
- // return; // 再去掉,IDEA:'return' is unnecessary as the last statement in a 'void' method。Lin
- }
-
-
- /**
- * 计算获取首页位置
- *
- * @param request;
- * @return String
- */
- // 来自 VisitUtil.getMisIndexPath(HttpServletRequest request)。Lin
- /* 再改,增加 session(HttpSession),不重复取。Lin
- private static String getMisIndexPath(HttpServletRequest request) {
- */ private static String getMisIndexPath(HttpServletRequest request, HttpSession session) {
- /* 再去掉,移到用到的地方 'try' with sources。Lin
- Db wdgdba_maybe_null = null; // 只是在 if 里用到,不用 'try' with sources。Lin
- */
- try {
- // String appName=WdLoginUtil.getLoginedAppName(request); // 去掉,不支持多个应用 -- 需要时用 SsC.APP_name。Lin
- // boolean userCookie = false;
- boolean secondHomePage;
- // String userid =
- // request.getParameter(CoreConstVars.COOKIE_USERID);
- String logintoken = request.getParameter(UserC.LOGIN_token); // CoreConstVars.REQUEST_LOGIN_TOKEN。Lin
- // if (request.getCookies() != null) {
- // for (Cookie c : request.getCookies()) {
- // if (c.getName().equals(CoreConstVars.COOKIE_USERID)) {
- // userCookie = true;
- // userid = c.getValue();
- // request.setAttribute(CoreConstVars.COOKIE_USERID, userid);
- // }
- // // if(c.getName().equals(CoreConstVars.COOKIE_USER))
- // // userCookie=true;
- // }
- // }
- //
- // String requestuserid =
- // request.getParameter(CoreConstVars.COOKIE_USERID);
- String deviceid = request.getParameter(UserC.DEV_id); // CoreConstVars.REQUEST_DEVICEID。Lin
- /* 再改用 UserDevRunB,从业务的 RysbPo 分开 -- 剥离 SS。Lin
- RysbPo yhsb = null; // Yhsb。Lin
- */ UserDevRunB yhsb = null;
- if (StringUtils.isNotBlank(logintoken) && StringUtils.isNotBlank(deviceid)) {
- // 去掉 StrU.notNull(),直接用 StringUtils.isNotBlank()。Lin
- /* 去掉 VisitUtil.initWDgdba(),直接把内容移上来。Lin
- wdgdba_maybe_null = initWDgdba(wdgdba_maybe_null);
- */
- /// 来自 VisitUtil.(GeneralDBAccess) initWDgdba(GeneralDBAccess wdgdba)。Lin
- // "减少获取gdba连接数,用到才调用"
- // return wdgdba != null ? wdgdba : GeneralDBAccess
- // .getInstance(ConstVars.DB_JDNI_NAME);
- /* 再改,IDEA:Condition 'wdgdba_maybe_null == null' is always 'true'。Lin
- wdgdba_maybe_null = (wdgdba_maybe_null == null)? Db.makeConn() : wdgdba_maybe_null;
- */
- /* 再改,用 'try' with sources。Lin
- wdgdba_maybe_null = Db.makeConn();
- */ try (Db wdgdba_maybe_null = Db.makeConn()) {
- ///
- /* 再改用 UserDevRunB,从业务的 RysbPo 分开 -- 剥离 SS。Lin
- yhsb = findYhsb11(logintoken, deviceid, wdgdba_maybe_null);
- */ yhsb = selUserDevRunB(logintoken, deviceid, wdgdba_maybe_null);
- request.setAttribute(UserC.DEV_nofind, (yhsb == null) ? "1" : "0"); // CoreConstVars.LOGIN_PAGE_YHSB_EXPIRES。Lin
- /// 再增加,用 'try' with sources。Lin
- }
- ///
- }
- // if (StringUtil.notNull(requestuserid)) {
- // userid = requestuserid;
- // userCookie = true;
- // }
- // 跳到第二个首页
- // 请求发现homepage=1,不用第二首页
- secondHomePage = (yhsb != null) && (!request.getParameter("homepage").equals("1"));
- // secondHomePage=false;
- /* 去掉,不支持多个应用。Lin
- * 去掉 ApplicationLogin,去掉 application.xml
- String serverName = request.getServerName();
- WebApp webapp = null;
- ApplicationLogin login = null;
- for (WebApp app : WD.getSysWD().getAppMap().values()) {
- if (app.getApplicationConfig().getApplicationLoginMap().containsKey(serverName)) {
- webapp = app;
- login = webapp.getApplicationConfig().getApplicationLoginMap().get(serverName);
- }
- }
- if (webapp == null||login==null) {// 域名不在配置文件
- String sqlcmd = null;
- String wzid = null;
- String ymid = null;
-
- wdgdba_maybe_null = (wdgdba_maybe_null == null)? SsDb.makeConn() : wdgdba_maybe_null;
- // initWDgdba(wdgdba_maybe_null)。去掉 VisitUtil.initWDgdba(),直接把内容移上来。Lin
-
- // if (checkAgentIsMobile(request.getHeader("User-Agent"))) {
- // Cookie cookie = getCookie("device", request.getCookies());
- // if (cookie == null || cookie.getValue().equalsIgnoreCase("app")) {
- // wdgdba_maybe_null.select(sqlcmd);
- // if (wdgdba_maybe_null.getRowCount() == 0) {
- // return null;
- // } else {
- // wzid = wdgdba_maybe_null.getColumnAsString("wzid");
- // request.setAttribute("wzid", wzid);
- // String xmdm = wd.core.web.WebUtil.getYyhByWzid(wdgdba_maybe_null, wzid);
- // request.getSession().setAttribute(CoreConstVars.SESSION_WZID, wzid);
- // request.getSession().setAttribute(CoreConstVars.XMMC, xmdm);
- // PageObject pageobj = WebUtil.findPageObjectById("wz", PageObject.BJLBM_MOBILE_SY, xmdm);
- // if ( pageobj != null) {
- // // 重定向
- // request.setAttribute(IndexAction.FORWARD_REDIRECT, "1");
- //
- // if (ConstVars.IS_DEVELOP_MODE) {
- // return "/service?wdApplication=" + xmdm + "&wdService=loadMobileHtml&code=wz&bjlbm=85&xmmc=" + xmdm + "&appbrower=1" + "&wzid=" + wzid;
- // } else {
- // return "/service?wdApplication=" + xmdm + "&wdService=loadMobileHtml&code=wz&bjlbm=85&xmmc=" + xmdm + "&appbrower=3" + "&wzid=" + wzid;
- // }
- // } else {
- // sqlcmd = "select ymid,wzid from ym where sfqy=1 and ymlbm=1 and wzid in(" + sqlcmd + ") order by length(dm||'0')";
- // wdgdba_maybe_null.select(sqlcmd);
- // if (wdgdba_maybe_null.getRowCount() == 1) {
- // wzid = wdgdba_maybe_null.getColumnAsString("wzid");
- // ymid = wdgdba_maybe_null.getColumnAsString("ymid");
- // request.getSession().setAttribute(CoreConstVars.SESSION_WZID, wzid);
- // return "/web/loadWebPage.do?" + wzid + ConstVars.YHZH_SEPT + ymid + ConstVars.YHZH_SEPT + "0" + ConstVars.YHZH_SEPT + ConstVars.PAGE_FIRST;
- // }
- // }
- //
- // //
- // }
- // }
- // } else {
- // sqlcmd = "SELECT wzid FROM wz WHERE regexp_like(lower(ym),'(*;)?" + shuRuUrl + "(;*)?')";
- // sqlcmd = "select ymid,wzid from ym where sfqy=1 and ymlbm=1 and wzid in(" + sqlcmd + ") order by length(dm||'0')";
- // wdgdba_maybe_null.select(sqlcmd);
- //
- // if (wdgdba_maybe_null.getRowCount() == 0) {
- // return null;
- // }
- //
- //
- // wzid = wdgdba_maybe_null.getColumnAsString("wzid");
- // ymid = wdgdba_maybe_null.getColumnAsString("ymid");
- //
- VisitPath res= getIndexPath(serverName, wdgdba_maybe_null);
- if(res==null||res.getYmid()==null)return null;
- ymid=res.getYmid();
- wzid=res.getWzid();
-
- if(WebUtil.checkAgentIsMobile(request)&&WebUtil.findPageObjectById((ConstVars.IS_DEVELOP_MODE?"wz":wd.core.util.FileAssistant.encriptDesignId("wz")), PageObject.BJLBM_MOBILE_SY, appName)!=null){
- request.setAttribute(MisIndexAction.FORWARD_REDIRECT, "1");
- return "/service?wdApplication=" + appName + "&wdService=loadMobileHtml&code="+(ConstVars.IS_DEVELOP_MODE?"wz":wd.core.util.FileAssistant.encriptDesignId("wz"))+"&bjlbm=85&xmmc=" + appName + "&wzid=" + wzid+ "&appbrower=1"+(ConstVars.IS_DEVELOP_MODE?"1":"3");
- }else{
- request.getSession().setAttribute(CoreConstVars.SESSION_WZID, wzid);
- return "/web/loadWebPage.do?" + wzid + ConstVars.YHZH_SEPT + ymid + ConstVars.YHZH_SEPT + "0" + ConstVars.YHZH_SEPT + ConstVars.PAGE_FIRST;
- }
- // }
- } else {
- */
- /* 去掉 ApplicationLogin。Lin
- * 再增加 session(HttpSession),不重复取。Lin
- request.getSession().setAttribute(CoreConstVars.SESSIOJ_PROJECT_URL_DESC, login.getDesc());
- */ session.setAttribute(WebC.REQ_appDesc, SsC.APP_desc); // request.getSession().。Lin
- //GlobalFilter work----------------------
- // if (StringUtil.isNull(WdLoginUtil.getLoginedAppName(request))) {
- // request.getSession().setAttribute(CoreConstVars.XMMC, webapp.getName());
- // }
- // 移动端页面
- // if (ApplicationLogin.TYPE_APPLICATION.equals(login.getType()) && checkAgentIsMobile(request.getHeader("User-Agent"))) {
- // Cookie cookie = getCookie("device", request.getCookies());
- // if (cookie == null || cookie.getValue().equalsIgnoreCase("app")) {
- // String xmdm = webapp.getName();
- //
- // PageObject pageobj = WebUtil.findPageObjectById("wz", PageObject.BJLBM_MOBILE_SY, xmdm);
- // if (pageobj != null) {
- // if (ConstVars.IS_DEVELOP_MODE) {
- // return "/service?wdApplication=" + xmdm + "&wdService=loadMobileHtml&code=wz&bjlbm=85&xmmc=" + xmdm + "&appbrower=1";
- // } else {
- // return "/service?wdApplication=" + xmdm + "&wdService=loadMobileHtml&code=wz&bjlbm=85&xmmc=" + xmdm + "&appbrower=3";
- // }
- // } else {
- // String result = null;
- //
- // result = login.getLoginMap().get("firstLogin").getPath();
- //
- // return result;
- // }
- //
- // }
- // } else {
-
- String result;
- // 登录页2
- /* 去掉 appName。Lin
- * 去掉 wdApplication=、bjlbm=85、xmmc=
- if(WebUtil.checkAgentIsMobile(request)&&WebUtil.findPageObjectById("wz", PageObject.BJLBM_MOBILE_SY, appName)!=null){
- result="/service?wdApplication=" + appName + "&wdService=loadMobileHtml&code="
- +(ConstVars.IS_DEVELOP_MODE?"wz":wd.core.util.FileAssistant.encriptDesignId("wz"))
- +"&bjlbm=85&xmmc=" + appName + "&appbrower="+(ConstVars.IS_DEVELOP_MODE?"1":"3");
- */
- if (WebU.isMdByReq(request) && AppB.pageMap.get("wz") != null) {
- result = ServC.SPATH_root +"?"+ ServC.URL_ssServ +"=loadMobileHtml&code="
- + ((AppB.inDebug)?"wz" : PageU.md5PageName("wz"))
- + "&appbrower="+ ((AppB.inDebug)? "1" : "3");
- request.setAttribute(FORWARD_REDIRECT, "1"); // 去掉 MisIndexAction.,合并了。Lin
- /* 去掉 ApplicationLogin。Lin
- }else if (secondHomePage && login.getLoginMap().containsKey("login")) {
- result = login.getLoginMap().get("login").getPath();
- request.setAttribute(CoreConstVars.LOGIN_PAGE_YHSB, yhsb);
- setUserInfoIntoRequest(request, yhsb.getYhid());
- }else {
- result = login.getLoginMap().get("firstLogin").getPath();
- }
- */
- } else if (secondHomePage) {
- result = WebC.PPATH_login;
- /// 应该是传输给 "/login.jsp" 的参数。Lin
- request.setAttribute(UserC.DEV_userDevRunB, yhsb); // CoreConstVars.LOGIN_PAGE_YHSB。Lin
- ///
- /* 再去掉,写 Request."userinfo" -- 没用到,用到再弄。Lin
- setUserInfoIntoRequest(request, yhsb.getRyid());
- */
- } else {
- result = WebC.PPATH_fstLogin;
- }
- return result;
- // }
- // } // 相应地去掉。Lin
- } catch (Exception e) {
- /* 改,去掉 e.printStackTrace(),改用 log4j -- 按 IDEA 规范。Lin
- e.printStackTrace();
- */ log4j.error("IndexS.getMisIndexPath() 异常", e);
- /* 再去掉,用 'try' with sources。Lin
- } finally {
- if (wdgdba_maybe_null != null)
- wdgdba_maybe_null.close();
- */
- }
- return null;
- }
-
- // 来自 VisitUtil.setUserInfoIntoRequest(HttpServletRequest request,Long userid)。Lin
- // userid 改为 long
- /* 再去掉,写 Request."userinfo" -- 没用到,用到再弄。Lin
- private static void setUserInfoIntoRequest(HttpServletRequest request, long userid) {
- /// * 去掉 appName,不支持多个应用。Lin
- // String appName = WdLoginUtil.getLoginedAppName(request);
- // WebApp app;
- // if (userid==null) {
- // } else if (StringUtil.isNull(appName)) {
- // System.out.println("获取不到appname");
- // } else if ((app = WD.getApp(appName)) == null) {
- // System.out.println("找不到app:" + appName);
- // } else {
- /// *
- /// * 直接用 SsDb.makeConn(),使用默认 JNDI。Lin
- // String jndi = app.getDefaultDbJndiName();
- // try (GeneralDBAccess gdbadc = GeneralDBAccess.getInstance(jndi)) {
- /// *
- try (Db gdbadc = Db.makeConn()) {
- /// * 去掉 WD 数据库。Lin
- // String sql = "select ry.ryid,yh.zh,ry.xm,ry.yszwj from ry join wd.yh on ry.ryid=yh.yhid where ry.ryid=:RYID";
- /// *
- String sql = "select RYID,ZH,XM,YSZWJ from RY where RYID=:ryid";
- SqlCmd sqlc = new SqlCmd(sql); // SqlCommandImpl。Lin
- sqlc.wrLongParm("ryid", userid); // .setString()。Lin
- gdbadc.selMapListByC(sqlc) // .selectAsMapList(。Lin
- .stream()
- .findFirst()
- .ifPresent(map -> request.setAttribute("userinfo", map));
- } catch (Exception e) {
- SsLog.print("用户信息查询失败:" + userid);
- }
- // } // 去掉 appName。Lin
- }
- */
-
- // 来自 VisitUtil.(Yhsb) findYhsb11(String logintoken, String deviceId, GeneralDBAccess wdgdba)。Lin
- /* 再改用 UserDevRunB,从业务的 RysbPo 分开 -- 剥离 SS。Lin
- private static RysbPo findYhsb11(String logintoken, String deviceId, Db wdgdba) throws Exception {
- */ private static UserDevRunB selUserDevRunB(String logintoken, String deviceId, Db wdgdba) throws Exception {
- if (StringUtils.isNotBlank(deviceId) && StringUtils.isNotBlank(logintoken)) {
- // 去掉 StrU.notNull(),直接用 StringUtils.isNotBlank()。Lin
- /* 去掉 WD 数据库。Lin
- SqlCommandImpl cmd = new SqlCommandImpl(
- "select * from wd.yhsb where bs=:bs and token=:token");
- */
- /* 再改用 UserDevRunB,从业务的 RysbPo 分开 -- 剥离 SS。Lin
- SqlCmd cmd = new SqlCmd("select * from RYSB where BS=:bs and LP=:token");
- */ SqlCmd cmd = new SqlCmd("select SFZCSPB from RYSB where BS=:bs and LP=:lp");
- cmd.wrStrParm("lp", logintoken); // .setString()。Lin
- cmd.wrStrParm("bs", deviceId); // .setString()。Lin
- SsLog.print("index.do:" + cmd);
- wdgdba.doSelByC(cmd);
- if (wdgdba.rowNum == 1) {
- /* 再改用 UserDevRunB,从业务的 RysbPo 分开 -- 剥离 SS。Lin
- RysbPo yhsb = new RysbPo(); // Yhsb。Lin
- wdgdba.loadPo(yhsb); // getValuesIntoBean()。Lin
- return yhsb;
- */
- UserDevRunB yhsb = new UserDevRunB();
- yhsb.id = deviceId;
- yhsb.token = logintoken;
- yhsb.isFormChk = wdgdba.rdBoolCol("sfzcspb");
- return yhsb;
- }
- }
- return null;
- }
- }
|