|
@@ -378,6 +378,101 @@ public class WorkKnowledgeBasePointExchangeService extends CrudService<WorkKnowl
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
|
+ * 预览兑换明细(只读,不写DB)
|
|
|
|
|
+ * 计算每个用户的兑换情况:当前积分、预计兑换量、兑换后剩余
|
|
|
|
|
+ * @param exchangeType 兑换类型:basic-基础积分, contribution-贡献积分
|
|
|
|
|
+ * @return 预览用的用户积分数据列表(只包含满足兑换条件的用户)
|
|
|
|
|
+ */
|
|
|
|
|
+ public List<WorkKnowledgeBasePoint> previewExchange(String exchangeType) {
|
|
|
|
|
+ // 1. 根据兑换类型获取有对应积分的用户ID列表
|
|
|
|
|
+ String columnId = "basic".equals(exchangeType) ? "1" : "2";
|
|
|
|
|
+ List<String> userIdList = pointDetailDao.findUserIdsByColumnId(columnId);
|
|
|
|
|
+
|
|
|
|
|
+ if (userIdList == null || userIdList.isEmpty()) {
|
|
|
|
|
+ return new java.util.ArrayList<>();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 读取兑换规则
|
|
|
|
|
+ Integer firstThreshold = getRuleValueByType("91");
|
|
|
|
|
+ Integer nonFirstThreshold = getRuleValueByType("92");
|
|
|
|
|
+ Integer stepValue = getRuleValueByType("93");
|
|
|
|
|
+ if (firstThreshold == null) firstThreshold = 300;
|
|
|
|
|
+ if (nonFirstThreshold == null) nonFirstThreshold = 100;
|
|
|
|
|
+ if (stepValue == null) stepValue = 100;
|
|
|
|
|
+
|
|
|
|
|
+ // 记录参与预览的用户ID
|
|
|
|
|
+ java.util.Set<String> previewUserIds = new java.util.HashSet<>();
|
|
|
|
|
+ Map<String, Integer> previewExchangedBasicMap = new HashMap<>();
|
|
|
|
|
+ Map<String, Integer> previewExchangedContribMap = new HashMap<>();
|
|
|
|
|
+ Map<String, Integer> previewOriginalBasicMap = new HashMap<>();
|
|
|
|
|
+ Map<String, Integer> previewOriginalContribMap = new HashMap<>();
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 逐用户计算兑换情况(不写DB)
|
|
|
|
|
+ for (String userId : userIdList) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ if ("basic".equals(exchangeType)) {
|
|
|
|
|
+ int basicPoints = pointDetailDao.sumUserPointByColumnId(userId, "1");
|
|
|
|
|
+ previewOriginalBasicMap.put(userId, basicPoints);
|
|
|
|
|
+
|
|
|
|
|
+ WorkKnowledgeBaseUserExchangeFlag flag = exchangeFlagDao.getByUserId(userId);
|
|
|
|
|
+ boolean isFirstExchange = (flag == null || flag.getIsFirstExchanged() == 0 || flag.getIsFirstExchanged() == null);
|
|
|
|
|
+ int threshold = isFirstExchange ? firstThreshold : nonFirstThreshold;
|
|
|
|
|
+ int basicExchanged = 0;
|
|
|
|
|
+ if (basicPoints >= threshold) {
|
|
|
|
|
+ basicExchanged = (basicPoints / stepValue) * stepValue;
|
|
|
|
|
+ if (basicExchanged > 0) {
|
|
|
|
|
+ previewUserIds.add(userId);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ previewExchangedBasicMap.put(userId, basicExchanged);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if ("contribution".equals(exchangeType)) {
|
|
|
|
|
+ int contributionPoints = pointDetailDao.sumUserPointByColumnId(userId, "2");
|
|
|
|
|
+ previewOriginalContribMap.put(userId, contributionPoints);
|
|
|
|
|
+
|
|
|
|
|
+ if (contributionPoints > 0) {
|
|
|
|
|
+ previewUserIds.add(userId);
|
|
|
|
|
+ previewExchangedContribMap.put(userId, contributionPoints);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 查询所有用户的积分汇总
|
|
|
|
|
+ List<WorkKnowledgeBasePoint> allUsers = pointDetailDao.findAllUserPointSummary();
|
|
|
|
|
+
|
|
|
|
|
+ // 5. 过滤出满足兑换条件的用户,组装预览数据
|
|
|
|
|
+ List<WorkKnowledgeBasePoint> previewList = new java.util.ArrayList<>();
|
|
|
|
|
+ for (WorkKnowledgeBasePoint item : allUsers) {
|
|
|
|
|
+ if (!previewUserIds.contains(item.getUserId())) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ int exBasic = previewExchangedBasicMap.containsKey(item.getUserId()) ? previewExchangedBasicMap.get(item.getUserId()) : 0;
|
|
|
|
|
+ int exContrib = previewExchangedContribMap.containsKey(item.getUserId()) ? previewExchangedContribMap.get(item.getUserId()) : 0;
|
|
|
|
|
+ int currentBasic = item.getBasicPoint() != null ? item.getBasicPoint() : 0;
|
|
|
|
|
+ int currentContrib = item.getContributionPoint() != null ? item.getContributionPoint() : 0;
|
|
|
|
|
+ int origBasic = previewOriginalBasicMap.containsKey(item.getUserId()) ? previewOriginalBasicMap.get(item.getUserId()) : 0;
|
|
|
|
|
+ int origContrib = previewOriginalContribMap.containsKey(item.getUserId()) ? previewOriginalContribMap.get(item.getUserId()) : 0;
|
|
|
|
|
+
|
|
|
|
|
+ item.setExchangedBasicPoint(exBasic);
|
|
|
|
|
+ item.setExchangedContributionPoint(exContrib);
|
|
|
|
|
+ item.setOriginalBasicPoint(origBasic);
|
|
|
|
|
+ item.setOriginalContributionPoint(origContrib);
|
|
|
|
|
+ // 预览时的剩余 = 当前积分 - 预计兑换量
|
|
|
|
|
+ item.setRemainingBasicPoint(currentBasic - exBasic);
|
|
|
|
|
+ item.setRemainingContributionPoint(currentContrib - exContrib);
|
|
|
|
|
+
|
|
|
|
|
+ previewList.add(item);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return previewList;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
* 根据rule_type获取规则配置的point_value值
|
|
* 根据rule_type获取规则配置的point_value值
|
|
|
* @param ruleType 规则类型(91/92/93)
|
|
* @param ruleType 规则类型(91/92/93)
|
|
|
* @return 规则值,如果不存在返回null
|
|
* @return 规则值,如果不存在返回null
|