Просмотр исходного кода

已限时已完成考试不允许首页弹框改造导致的首页登录失败问题修复

xiexh 8 часов назад
Родитель
Сommit
9d0f521555

+ 16 - 5
ibps-provider-root/modules/provider-platform-default/src/main/java/com/lc/ibps/common/provider/DesktopFacadeProvider.java

@@ -253,15 +253,26 @@ public class DesktopFacadeProvider extends GenericProvider implements IDesktopFa
 			String currentDate = sdf.format(new Date());
 			String currentDate = sdf.format(new Date());
 			DesktopFacadeService desktopFacadeService = AppUtil.getBean(DesktopFacadeService.class);
 			DesktopFacadeService desktopFacadeService = AppUtil.getBean(DesktopFacadeService.class);
 			List<PartyUserCalendarPo> calendarPoList = calendarRepository.findByUserId(ContextUtil.getCurrentUserId());
 			List<PartyUserCalendarPo> calendarPoList = calendarRepository.findByUserId(ContextUtil.getCurrentUserId());
+			//收集dataSourceId
+			List<String> dataSourceIds = calendarPoList.stream()
+					.filter(bean -> StringUtil.isNotBlank(bean.getDataSourceId()))
+					.map(PartyUserCalendarPo::getDataSourceId)
+					.collect(Collectors.toList());
+			//批量查询考试记录(一次SQL搞定)
+			Map<String, Map<String,Object>> records = desktopFacadeService.batchQueryExamInfo(dataSourceIds);
+			//从考试记录获取dataSourceId计算出对应的考试弹窗标志
+			Map<String, String> examStatusMap = desktopFacadeService.chargeExamPassingFlag(records);
 			for (PartyUserCalendarPo bean : calendarPoList){
 			for (PartyUserCalendarPo bean : calendarPoList){
 				if (BeanUtils.isEmpty(bean.getMarkDate()) || !bean.getMarkDate().equals(currentDate)){
 				if (BeanUtils.isEmpty(bean.getMarkDate()) || !bean.getMarkDate().equals(currentDate)){
 					bean.setPopUp(1);// 标记为弹窗提醒
 					bean.setPopUp(1);// 标记为弹窗提醒
 				}
 				}
-				if(BeanUtils.isNotEmpty(bean.getDataSourceId())){
-					String flag = desktopFacadeService.chargeExamPassingStatus(bean.getDataSourceId());
-					if("pass".equals(flag)){
-						logger.warn("已限制时间考试{},id{},已通过取消弹窗提醒",bean.getTitle(),bean.getDataSourceId());
-						bean.setPopUp(0);// 取消弹窗提醒
+				// 检查考试通过状态
+				if (StringUtil.isNotBlank(bean.getDataSourceId())) {
+					String uniqueKey = bean.getDataSourceId() + "_" + ContextUtil.getCurrentUserId();
+					String flag = examStatusMap.get(uniqueKey);
+					if ("pass".equals(flag)) {
+						//logger.warn("已限制时间考试{}, id{},已通过取消弹窗提醒", bean.getTitle(), bean.getDataSourceId());
+						bean.setPopUp(0);
 					}
 					}
 				}
 				}
 			}
 			}

+ 58 - 4
ibps-provider-root/modules/provider-platform-default/src/main/java/com/lc/ibps/platform/service/DesktopFacadeService.java

@@ -1,9 +1,14 @@
 package com.lc.ibps.platform.service;
 package com.lc.ibps.platform.service;
 
 
+import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 
 import com.lc.ibps.base.framework.table.ICommonDao;
 import com.lc.ibps.base.framework.table.ICommonDao;
+import com.lc.ibps.base.web.context.ContextUtil;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
@@ -201,11 +206,44 @@ public class DesktopFacadeService {
 		}
 		}
 		return null;
 		return null;
 	}
 	}
+	/**
+	 * 使用参数化查询,防止 SQL 注入
+	 * 查询考试记录
+	 */
+	public Map<String, Map<String, Object>> batchQueryExamInfo(List<String> dataSourceIds) {
+		Map<String, Map<String, Object>> resultMap = new HashMap<>();
+
+		if (dataSourceIds == null || dataSourceIds.isEmpty()) {
+			return resultMap;
+		}
+		List<String> distinctIds = dataSourceIds.stream().distinct().collect(Collectors.toList());
+		int batchSize = 500;
+		for (int i = 0; i < distinctIds.size(); i += batchSize) {
+			int end = Math.min(i + batchSize, distinctIds.size());
+			List<String> batchIds = distinctIds.subList(i, end);
+			// 使用命名参数格式 #{p0}, #{p1}, #{p2}...
+			StringBuilder sqlBuilder = new StringBuilder("SELECT * FROM v_examination WHERE examId IN (");
+			for (int j = 0; j < batchIds.size(); j++) {
+				if (j > 0) {
+					sqlBuilder.append(",");
+				}
+				sqlBuilder.append("#{p").append(j).append("}");
+			}
+			sqlBuilder.append(")");
+
+			List<Map<String, Object>> records = (List<Map<String, Object>>) commonDao.query(sqlBuilder.toString(), batchIds.toArray());
+			for (Map<String, Object> record : records) {
+				String uniqueKey = record.get("examId") + "_" + record.get("examinee");
+				resultMap.put(uniqueKey, record);
+			}
+		}
+		return resultMap;
+	}
 
 
-	public String chargeExamPassingStatus(String dataSourceId) {
+	public String chargeExamPassingStatus(Map<String, Object> record) {
 		//List<Map<String,Object>> list = desktopFacadeDao.selectExamViewInfo(dataSourceId);
 		//List<Map<String,Object>> list = desktopFacadeDao.selectExamViewInfo(dataSourceId);
-		String sql = " select * from v_examination where examId ='"+dataSourceId+"' limit 1;";
-		Map<String,Object> record = commonDao.queryOne(sql);
+		//String sql = " select * from v_examination where examId ='"+dataSourceId+"' limit 1;";
+		//Map<String,Object> record = commonDao.queryOne(sql);
 		if (record == null || record.isEmpty()) {
 		if (record == null || record.isEmpty()) {
 			return "empt";//未发布考试或者非考试弹窗
 			return "empt";//未发布考试或者非考试弹窗
 		}
 		}
@@ -243,5 +281,21 @@ public class DesktopFacadeService {
 		}
 		}
 		return flag;
 		return flag;
 	}
 	}
-	
+
+	public Map<String, String> chargeExamPassingFlag(Map<String, Map<String, Object>> records) {
+		Map<String, String> examStatusMap = new HashMap<>();
+		if (records == null || records.isEmpty()) {
+			return examStatusMap;
+		}
+		for (Map.Entry<String, Map<String, Object>> entry : records.entrySet()) {
+			String examId = entry.getKey();
+			Map<String, Object> record = entry.getValue();
+			// 使用 examId + examinee 作为唯一key
+			//String examinee = record.get("examinee") != null ? record.get("examinee").toString() : "";
+			//String uniqueKey = examId + "_" + examinee;
+			String status = chargeExamPassingStatus(record);
+			examStatusMap.put(examId, status);
+		}
+		return examStatusMap;
+	}
 }
 }