Commit c2f61cde by 潘诗林

fix:预学习弹窗不展示学习完成的和未生成案例的

1 parent 50f4524e
package cn.com.glsx.dj.staff.dto.prelearn;
import lombok.Data;
import java.io.Serializable;
/**
* 产品剧本数量统计DTO
*/
@Data
public class ProductScriptCountDTO implements Serializable {
private static final long serialVersionUID = 1L;
/** 活动产品ID */
private Integer activityProductId;
/** READY剧本数量 */
private Integer readyCount;
}
package cn.com.glsx.dj.staff.mapper; package cn.com.glsx.dj.staff.mapper;
import cn.com.glsx.dj.staff.dto.prelearn.ProductScriptCountDTO;
import cn.com.glsx.dj.staff.model.PreLearnProductScript; import cn.com.glsx.dj.staff.model.PreLearnProductScript;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
...@@ -43,4 +44,19 @@ public interface PreLearnProductScriptMapper extends OreMapper<PreLearnProductSc ...@@ -43,4 +44,19 @@ public interface PreLearnProductScriptMapper extends OreMapper<PreLearnProductSc
@Param("id") Integer id, @Param("id") Integer id,
@Param("errorMsg") String errorMsg, @Param("errorMsg") String errorMsg,
@Param("aiStatus") String aiStatus); @Param("aiStatus") String aiStatus);
/**
* 批量查询哪些活动有READY状态的剧本(去重activityId)
*/
List<Integer> selectActivityIdsWithReadyScripts(
@Param("activityIds") List<Integer> activityIds,
@Param("aiStatus") String aiStatus);
/**
* 查询指定活动下各产品的READY剧本数量(按产品分组)
*/
List<ProductScriptCountDTO> countReadyByActivityGroupByProduct(
@Param("activityId") Integer activityId,
@Param("productIds") List<Integer> productIds,
@Param("aiStatus") String aiStatus);
} }
...@@ -54,4 +54,12 @@ public interface PreLearnStaffProductStatusMapper extends OreMapper<PreLearnStaf ...@@ -54,4 +54,12 @@ public interface PreLearnStaffProductStatusMapper extends OreMapper<PreLearnStaf
int countTotalStaff( int countTotalStaff(
@Param("startTime") Date startTime, @Param("startTime") Date startTime,
@Param("endTime") Date endTime); @Param("endTime") Date endTime);
/**
* 批量查询员工在多个活动下的已学套餐
*/
List<PreLearnStaffProductStatus> selectLearnedByStaffAndActivities(
@Param("staffUuid") String staffUuid,
@Param("activityIds") List<Integer> activityIds,
@Param("status") Integer status);
} }
...@@ -25,6 +25,7 @@ import cn.com.glsx.framework.core.exception.RpcServiceException; ...@@ -25,6 +25,7 @@ import cn.com.glsx.framework.core.exception.RpcServiceException;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.annotation.DubboReference;
...@@ -100,10 +101,10 @@ public class PreLearnStaffService { ...@@ -100,10 +101,10 @@ public class PreLearnStaffService {
return popupDTO; return popupDTO;
} }
// 2. 获取 Redis 今日已弹活动集合 // 2. 获取 Redis 今日已弹活动集合,先筛掉已弹窗的活动
Set<String> todayPoppedIds = preLearnPopupService.getTodayPoppedIds(staffUuid,merchantId); Set<String> todayPoppedIds = preLearnPopupService.getTodayPoppedIds(staffUuid, merchantId);
// 3. 逐个活动筛选 // 3. 逐个活动筛选(按优先级顺序,找到第一个即停止)
ActivityCandidate candidate = new ActivityCandidate(); ActivityCandidate candidate = new ActivityCandidate();
for (MarketingActivityDetailRespDTO activity : activeActivities) { for (MarketingActivityDetailRespDTO activity : activeActivities) {
// 3a. 该活动今日已弹窗 -> 跳过 // 3a. 该活动今日已弹窗 -> 跳过
...@@ -112,18 +113,14 @@ public class PreLearnStaffService { ...@@ -112,18 +113,14 @@ public class PreLearnStaffService {
} }
// 3b. 获取主推套餐 // 3b. 获取主推套餐
List<MarketingActivityProductRespDTO> mainPackages = activity.getProductRespDTOS();
if (CollectionUtils.isEmpty(mainPackages)) {
continue;
}
// 只取主推套餐
List<MarketingActivityProductRespDTO> mainPushProducts = activity.getProductRespDTOS().stream() List<MarketingActivityProductRespDTO> mainPushProducts = activity.getProductRespDTOS().stream()
.filter(p -> p.getIsMainPush() != null && p.getIsMainPush() == 1) .filter(p -> p.getIsMainPush() != null && p.getIsMainPush() == 1)
.collect(Collectors.toList()); .collect(Collectors.toList());
if (CollectionUtils.isEmpty(mainPushProducts)) { if (CollectionUtils.isEmpty(mainPushProducts)) {
continue; continue;
} }
// 3c. 查询已学套餐
// 3c. 查询该员工在此活动下的已学套餐,筛出未学套餐
List<PreLearnStaffProductStatus> learnedStatuses = List<PreLearnStaffProductStatus> learnedStatuses =
preLearnStaffProductStatusMapper.selectLearnedByStaffAndActivity( preLearnStaffProductStatusMapper.selectLearnedByStaffAndActivity(
staffUuid, activity.getActivityId(), PreLearnStatusEnum.STUDIED.getValue()); staffUuid, activity.getActivityId(), PreLearnStatusEnum.STUDIED.getValue());
...@@ -131,17 +128,37 @@ public class PreLearnStaffService { ...@@ -131,17 +128,37 @@ public class PreLearnStaffService {
.map(PreLearnStaffProductStatus::getActivityProductId) .map(PreLearnStaffProductStatus::getActivityProductId)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
// 3d. 计算未学差集 List<Integer> unlearnedProductIds = mainPushProducts.stream()
List<MarketingActivityProductRespDTO> unlearnedPackages = mainPackages.stream() .map(MarketingActivityProductRespDTO::getProductId)
.filter(p -> !learnedProductIds.contains(p.getProductId())) .filter(productId -> !learnedProductIds.contains(productId))
.collect(Collectors.toList()); .collect(Collectors.toList());
// 全部已学 → 跳过
// 3e. 该活动已全部学完 -> 剔除 if (CollectionUtils.isEmpty(unlearnedProductIds)) continue;
if (!unlearnedPackages.isEmpty()) {
candidate.setActivity(activity); // 3d. 一次性查询该活动下所有产品的READY案例数量
candidate.setLearnedProductIds(learnedProductIds); List<ProductScriptCountDTO> readyCountList = preLearnProductScriptMapper
break; .countReadyByActivityGroupByProduct(activity.getActivityId(), unlearnedProductIds,AiStatusEnum.READY.getValue());
// 3e. 检查未学套餐中是否有可用案例(READY且有未读)
boolean hasAvailableCase = false;
Map<Integer, Boolean> scriptReadiness = new HashMap<>();
if (readyCountList != null) {
for (ProductScriptCountDTO dto : readyCountList) {
Integer activityProductId = dto.getActivityProductId();
Integer readyCount = dto.getReadyCount();
scriptReadiness.put(activityProductId, readyCount > 0);
//有一个套餐可以读,则弹窗
if (readyCount > 0){
hasAvailableCase = true;
}
}
} }
if (!hasAvailableCase) continue;
// 3f. 选中该活动,停止遍历(附带已缓存的scriptReadiness避免二次查询)
candidate.setActivity(activity);
candidate.setLearnedProductIds(learnedProductIds);
candidate.setScriptReadiness(scriptReadiness);
break;
} }
// 4. 无候选活动 -> 不弹窗 // 4. 无候选活动 -> 不弹窗
...@@ -149,11 +166,10 @@ public class PreLearnStaffService { ...@@ -149,11 +166,10 @@ public class PreLearnStaffService {
return popupDTO; return popupDTO;
} }
// 6. 写入 Redis,标记该活动今日已弹窗(在返回数据之前) // 5. 写入 Redis,标记该活动今日已弹窗
preLearnPopupService.markPopped(staffUuid,merchantId, candidate.getActivity().getActivityId()); preLearnPopupService.markPopped(staffUuid, merchantId, candidate.getActivity().getActivityId());
// 组装弹窗响应 // 6. 组装弹窗响应
return buildPopupResponse(staffUuid, candidate); return buildPopupResponse(staffUuid, candidate);
} }
...@@ -169,9 +185,8 @@ public class PreLearnStaffService { ...@@ -169,9 +185,8 @@ public class PreLearnStaffService {
for (MarketingActivityProductRespDTO pkg : activity.getProductRespDTOS()) { for (MarketingActivityProductRespDTO pkg : activity.getProductRespDTOS()) {
Integer productId = pkg.getProductId(); Integer productId = pkg.getProductId();
boolean isLearned = learnedProductIds.contains(productId); boolean isLearned = learnedProductIds.contains(productId);
boolean scriptReady = preLearnProductScriptMapper.countByActivityAndProduct( boolean scriptReady = Boolean.TRUE.equals(
activity.getActivityId(), productId, candidate.getScriptReadiness() != null ? candidate.getScriptReadiness().get(productId) : null);
AiStatusEnum.READY.getValue()) > 0;
PackageLearningItemDTO item = PackageLearningItemDTO.builder() PackageLearningItemDTO item = PackageLearningItemDTO.builder()
.activityProductId(productId) .activityProductId(productId)
...@@ -581,5 +596,8 @@ public class PreLearnStaffService { ...@@ -581,5 +596,8 @@ public class PreLearnStaffService {
private static class ActivityCandidate { private static class ActivityCandidate {
private MarketingActivityDetailRespDTO activity; private MarketingActivityDetailRespDTO activity;
private Set<Integer> learnedProductIds; private Set<Integer> learnedProductIds;
/** 套餐是否有READY案例(productId → hasReady),由getHomePopup预查后传入,避免buildPopupResponse重复DB查询 */
private Map<Integer, Boolean> scriptReadiness;
} }
} }
...@@ -84,4 +84,27 @@ ...@@ -84,4 +84,27 @@
WHERE id = #{id} WHERE id = #{id}
</update> </update>
<select id="selectActivityIdsWithReadyScripts" resultType="java.lang.Integer">
SELECT DISTINCT activity_id
FROM dj_prelearn_product_script
WHERE activity_id IN
<foreach collection="activityIds" item="aid" open="(" separator="," close=")">
#{aid}
</foreach>
AND ai_status = #{aiStatus}
</select>
<select id="countReadyByActivityGroupByProduct" resultType="cn.com.glsx.dj.staff.dto.prelearn.ProductScriptCountDTO">
SELECT activity_product_id AS activityProductId, COUNT(*) AS readyCount
FROM dj_prelearn_product_script
WHERE activity_id = #{activityId} AND ai_status = #{aiStatus}
<if test="productIds != null and productIds.size > 0">
and activity_product_id in
<foreach collection="productIds" item="productId" open="(" separator="," close=")">
#{productId}
</foreach>
</if>
GROUP BY activity_product_id
</select>
</mapper> </mapper>
...@@ -79,4 +79,16 @@ ...@@ -79,4 +79,16 @@
WHERE created_date BETWEEN #{startTime} AND #{endTime} WHERE created_date BETWEEN #{startTime} AND #{endTime}
</select> </select>
<select id="selectLearnedByStaffAndActivities" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List" />
FROM dj_prelearn_staff_product_status
WHERE staff_uuid = #{staffUuid}
AND activity_id IN
<foreach collection="activityIds" item="aid" open="(" separator="," close=")">
#{aid}
</foreach>
AND status = #{status}
</select>
</mapper> </mapper>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!