Ver código fonte

管理员上报bug调整、登录添加验证适配

徐滕 1 semana atrás
pai
commit
5b6418aded

+ 22 - 16
src/main/java/com/jeeplus/common/security/shiro/session/JedisSessionDAO.java

@@ -47,16 +47,17 @@ public class JedisSessionDAO extends AbstractSessionDAO implements SessionDAO {
         }
 		
 		HttpServletRequest request = Servlets.getRequest();
+		boolean isSkipFullWrite = false;
 		if (request != null){
 			String uri = request.getServletPath();
 			// 如果是静态文件,则不更新SESSION
 			if (Servlets.isStaticFile(uri)){
 				return;
 			}
-			// 如果是视图文件,则不更新SESSION
+			// 如果是视图文件,则跳过完整序列化写入,但仍需刷新Redis TTL
 			if (StringUtils.startsWith(uri, Global.getConfig("web.view.prefix"))
 					&& StringUtils.endsWith(uri, Global.getConfig("web.view.suffix"))){
-				return;
+				isSkipFullWrite = true;
 			}
 			// 手动控制不更新SESSION
 			if (Global.NO.equals(request.getParameter("updateSession"))){
@@ -66,21 +67,23 @@ public class JedisSessionDAO extends AbstractSessionDAO implements SessionDAO {
 		
 		Jedis jedis = null;
 		try {
-			
 			jedis = JedisUtils.getResource();
+			String sessionKey = sessionKeyPrefix + session.getId();
 			
-			// 获取登录者编号
-			PrincipalCollection pc = (PrincipalCollection)session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY);
-			String principalId = pc != null ? pc.getPrimaryPrincipal().toString() : StringUtils.EMPTY;
-			
-			jedis.hset(sessionKeyPrefix, session.getId().toString(), principalId + "|" + session.getTimeout() + "|" + session.getLastAccessTime().getTime());
-			jedis.set(JedisUtils.getBytesKey(sessionKeyPrefix + session.getId()), JedisUtils.toBytes(session));
+			if (!isSkipFullWrite) {
+				// 获取登录者编号
+				PrincipalCollection pc = (PrincipalCollection)session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY);
+				String principalId = pc != null ? pc.getPrimaryPrincipal().toString() : StringUtils.EMPTY;
+				
+				jedis.hset(sessionKeyPrefix, session.getId().toString(), principalId + "|" + session.getTimeout() + "|" + session.getLastAccessTime().getTime());
+				jedis.set(JedisUtils.getBytesKey(sessionKey), JedisUtils.toBytes(session));
+			}
 			
-			// 设置超期时间
+			// 始终刷新Redis TTL,防止JSP请求时TTL不续期导致会话过期丢失
 			int timeoutSeconds = (int)(session.getTimeout() / 1000);
-			jedis.expire((sessionKeyPrefix + session.getId()), timeoutSeconds);
+			jedis.expire(sessionKey, timeoutSeconds);
 
-			logger.debug("update {} {}", session.getId(), request != null ? request.getRequestURI() : "");
+			logger.debug("update {} {} skipFullWrite={}", session.getId(), request != null ? request.getRequestURI() : "", isSkipFullWrite);
 		} catch (Exception e) {
 			logger.error("update {} {}", session.getId(), request != null ? request.getRequestURI() : "", e);
 		} finally {
@@ -237,10 +240,8 @@ public class JedisSessionDAO extends AbstractSessionDAO implements SessionDAO {
 		Jedis jedis = null;
 		try {
 			jedis = JedisUtils.getResource();
-//			if (jedis.exists(sessionKeyPrefix + sessionId)){
-				session = (Session)JedisUtils.toObject(jedis.get(
+			session = (Session)JedisUtils.toObject(jedis.get(
 						JedisUtils.getBytesKey(sessionKeyPrefix + sessionId)));
-//			}
 			logger.debug("doReadSession {} {}", sessionId, request != null ? request.getRequestURI() : "");
 		} catch (Exception e) {
 			logger.error("doReadSession {} {}", sessionId, request != null ? request.getRequestURI() : "", e);
@@ -258,8 +259,13 @@ public class JedisSessionDAO extends AbstractSessionDAO implements SessionDAO {
 	@Override
     public Session readSession(Serializable sessionId) throws UnknownSessionException {
     	try{
-        	return super.readSession(sessionId);
+        	Session session = super.readSession(sessionId);
+        	if (session == null) {
+        		logger.warn("readSession returned null for sessionId={}, session may have been lost", sessionId);
+        	}
+        	return session;
     	}catch (UnknownSessionException e) {
+			logger.warn("readSession UnknownSessionException for sessionId={}", sessionId);
 			return null;
 		}
     }

+ 1 - 0
src/main/java/com/jeeplus/modules/projectrecord/service/AdminProjectReportedImportService.java

@@ -497,6 +497,7 @@ public class AdminProjectReportedImportService extends CrudService<AdminProjectR
         String returnResult = HttpPostTool.doPost(url, encryptByAes);
         HashMap hashMap = JSON.parseObject(returnResult, HashMap.class);
         if(!"1".equals(hashMap.get("code"))){
+            System.out.println("上报失败:" + hashMap.get("msg").toString());
             return "上报失败:" + hashMap.get("msg").toString();
         }
         //修改项目上报表中状态

+ 3 - 0
src/main/java/com/jeeplus/modules/projectrecord/web/AdminProjectReportedImportController.java

@@ -291,6 +291,9 @@ public class AdminProjectReportedImportController extends BaseController {
                         reportedConsultant.setWcyysrbl(ruralReportConsultant.getWcyysrbl());
                         reportedConsultant.setWcyysr(ruralReportConsultant.getWcyysr());
                         reportedConsultant.setRoleFlag(ruralReportConsultant.getRoleFlag());
+                        if(StringUtils.isNotBlank(ruralReportConsultant.getWordnr())){
+                            reportedConsultant.setWordnr(ruralReportConsultant.getWordnr());
+                        }
                         reportedConsultant.setId(ruralReportConsultant.getId());
                         reportedConsultantList.add(reportedConsultant);
                     }

+ 11 - 0
src/main/java/com/jeeplus/modules/ruralprojectrecords/service/RuralProjectMessageNewService.java

@@ -5240,6 +5240,17 @@ public class RuralProjectMessageNewService extends CrudService<RuralProjectMessa
      */
     public List<RuralReportConsultant> getReportedConsultantsList(String reportedId){
         List<RuralReportConsultant> list=projectcontentinfoDao.getReportedConsultantsList(reportedId);
+        /*for (RuralReportConsultant consultant : list) {
+           //如果咨询员不为空,并且咨询员资格证号为空,则需要去获取信息
+            if(StringUtils.isBlank(consultant.getZhucezigezhID())){
+                List<WorkStaffCertificate> certificateList = this.getCertificateByUser(consultant.getZixunyuan());
+                for (WorkStaffCertificate certificateInfo: certificateList) {
+                    if (certificateInfo.getName().equals("161")) {
+                        consultant.setZhucezigezhID(certificateInfo.getNum());
+                    }
+                }
+            }
+        }*/
         return list;
     }
 

+ 14 - 0
src/main/java/com/jeeplus/modules/ruralprojectrecords/service/RuralProjectMessageService.java

@@ -3807,6 +3807,20 @@ public class RuralProjectMessageService extends CrudService<RuralProjectMessageD
      */
     public List<RuralReportConsultant> getReportedConsultantsList(String reportedId){
         List<RuralReportConsultant> list=projectcontentinfoDao.getReportedConsultantsList(reportedId);
+        for (RuralReportConsultant consultant : list) {
+            //如果咨询员不为空,并且咨询员资格证号为空,则需要去获取信息
+            if(StringUtils.isBlank(consultant.getZhucezigezhID())){
+                List<WorkStaffCertificate> certificateList = this.getCertificateByUser(consultant.getZixunyuan());
+                for (WorkStaffCertificate certificateInfo: certificateList) {
+                    if (certificateInfo.getName().equals("161")) {
+                        consultant.setZhucezigezhID(certificateInfo.getNum());
+                    }
+                }
+            }
+            if(StringUtils.isBlank(consultant.getWordnr())) {
+                consultant.setWordnr("审核");
+            }
+        }
         return list;
     }
 

+ 4 - 0
src/main/resources/spring-context-shiro.xml

@@ -153,6 +153,10 @@
         当跳出SHIRO SERVLET时如ERROR-PAGE容器会为JSESSIONID重新分配值导致登录会话丢失! -->
     <bean id="sessionIdCookie" class="org.apache.shiro.web.servlet.SimpleCookie">
         <constructor-arg name="name" value="jeeplus.session.id"/>
+        <property name="path" value="/"/>
+        <property name="httpOnly" value="true"/>
+        <!-- 设置Cookie持久化生存时间7天(单位秒),防止移动端浏览器内存回收时丢失临时Cookie导致会话丢失 -->
+        <property name="maxAge" value="604800"/>
     </bean>
 
 <!-- ***********************************     Redis缓存    ******************************************** -->