Bladeren bron

知识库积分部分功能提交,典型案例(原创和转载)审核处理变更

徐滕 4 weken geleden
bovenliggende
commit
faf91238d2

+ 203 - 9
src/main/java/com/jeeplus/modules/WorkKnowledgeBase/service/WorkKnowledgeBaseShareService.java

@@ -96,6 +96,9 @@ public class WorkKnowledgeBaseShareService extends CrudService<WorkKnowledgeBase
     private WorkKnowledgeExpertDao expertDao;
 
     @Autowired
+    private WorkKnowledgeExpertService expertService;
+
+    @Autowired
     private WorkKnowledgePointCategoryDao categoryDao;
 
     @Autowired
@@ -255,10 +258,17 @@ public class WorkKnowledgeBaseShareService extends CrudService<WorkKnowledgeBase
         
         // 判断是否为问答答疑分类
         boolean isQaCategory = false;
+        boolean isTypicalCase = false; // 是否为典型案例分类
+        
         if (StringUtils.isNotBlank(shareInfo.getTreeNodeId())) {
             WorkKnowledgeBaseTreeInfo treeInfo = getTreeInfoById(shareInfo.getTreeNodeId());
-            if (treeInfo != null && "问答答疑".equals(treeInfo.getTreeName())) {
-                isQaCategory = true;
+            if (treeInfo != null) {
+                if ("问答答疑".equals(treeInfo.getTreeName())) {
+                    isQaCategory = true;
+                }
+                if ("典型案例".equals(treeInfo.getTreeName())) {
+                    isTypicalCase = true;
+                }
             }
         }
         
@@ -277,6 +287,7 @@ public class WorkKnowledgeBaseShareService extends CrudService<WorkKnowledgeBase
             // 问答分类不需要设置submitAuditUserId和auditStartDate
         } else {
             // ========== 非问答分类:走原有审核流程 ==========
+            // 典型案例分类也走正常审核流程,根据有无附件判断状态
             if (isNew) {
                 // 新增:无文件草稿0,有文件未审核 1
                 shareInfo.setAuditStatus(hasValidAttachment ? AUDIT_STATUS_PENDING : AUDIT_STATUS_DRAFT);
@@ -415,15 +426,43 @@ public class WorkKnowledgeBaseShareService extends CrudService<WorkKnowledgeBase
             throw new RuntimeException("您已审核过该文件,不可重复审核");
         }
         
-        // 查询treeName,判断是否需要评分
+        // 查询treeName,判断是否需要评分以及审核权限
         boolean needsScore = false;
+        boolean isTypicalCaseOriginal = false; // 典型案例(原创)
+        boolean isTypicalCaseReprint = false;  // 典型案例(转载)
+        
         if (StringUtils.isNotBlank(entity.getTreeNodeId())) {
             WorkKnowledgeBaseTreeInfo treeInfo = getTreeInfoById(entity.getTreeNodeId());
-            if (treeInfo != null && ("技术总结".equals(treeInfo.getTreeName()) || "培训心得".equals(treeInfo.getTreeName()))) {
-                needsScore = true;
-                // 验证评分必填
-                if (score == null) {
-                    throw new RuntimeException("请输入评分分数");
+            if (treeInfo != null) {
+                String treeName = treeInfo.getTreeName();
+                
+                // 技术总结/培训心得:需要评分
+                if ("技术总结".equals(treeName) || "培训心得".equals(treeName)) {
+                    needsScore = true;
+                    // 验证评分必填
+                    if (score == null) {
+                        throw new RuntimeException("请输入评分分数");
+                    }
+                }
+                
+                // 典型案例分类:根据contentAttribute区分
+                if ("典型案例".equals(treeName)) {
+                    if ("0".equals(entity.getContentAttribute())) {
+                        // 典型案例(原创):需要专家审核,使用评分机制
+                        isTypicalCaseOriginal = true;
+                        needsScore = true;
+                        // 校验当前用户是否为专家
+                        boolean isExpert = expertService.isUserBound(auditUserId);
+                        if (!isExpert) {
+                            throw new RuntimeException("典型案例(原创)只有专家可以审核");
+                        }
+                        if (score == null) {
+                            throw new RuntimeException("请输入评分分数");
+                        }
+                    } else if ("1".equals(entity.getContentAttribute())) {
+                        // 典型案例(转载):所有人可审核,使用固定分值
+                        isTypicalCaseReprint = true;
+                    }
                 }
             }
         }
@@ -451,7 +490,13 @@ public class WorkKnowledgeBaseShareService extends CrudService<WorkKnowledgeBase
             entity.preUpdate();
             dao.updateAuditStatus(entity);
             // 本轮审核通过:根据分类类型执行不同的积分发放逻辑
-            if (needsScore) {
+            if (isTypicalCaseReprint) {
+                // 典型案例(转载):使用"典型案例(转载)"分类的固定分值
+                grantPointsForTypicalCaseReprint(entity, startTime);
+            } else if (isTypicalCaseOriginal) {
+                // 典型案例(原创):使用"典型案例(原创)"分类的评分平均分
+                grantPointsWithScoreForTypicalCaseOriginal(entity, startTime);
+            } else if (needsScore) {
                 // 技术总结/培训心得:使用评分平均分
                 grantPointsWithScore(entity, startTime);
             } else {
@@ -584,6 +629,24 @@ public class WorkKnowledgeBaseShareService extends CrudService<WorkKnowledgeBase
         String currentUserId = UserUtils.getUser().getId();
         // 提交审核人不可审核自己的文件
         if (currentUserId.equals(entity.getSubmitAuditUserId())) return false;
+        
+        // 检查是否为典型案例(原创),只有专家可以审核
+        boolean isTypicalCaseOriginal = false;
+        if (StringUtils.isNotBlank(entity.getTreeNodeId())) {
+            WorkKnowledgeBaseTreeInfo treeInfo = getTreeInfoById(entity.getTreeNodeId());
+            if (treeInfo != null && "典型案例".equals(treeInfo.getTreeName()) && "0".equals(entity.getContentAttribute())) {
+                isTypicalCaseOriginal = true;
+            }
+        }
+        
+        // 典型案例(原创):只有专家可以审核
+        if (isTypicalCaseOriginal) {
+            boolean isExpert = expertService.isUserBound(currentUserId);
+            if (!isExpert) {
+                return false;
+            }
+        }
+        
         // 本轮未审核过的用户可审核(按 audit_start_date 隔离历史记录)
         return auditRecordDao.countByFileIdAndUserIdSinceTime(entity.getId(), currentUserId, entity.getAuditStartDate()) == 0;
     }
@@ -688,6 +751,75 @@ public class WorkKnowledgeBaseShareService extends CrudService<WorkKnowledgeBase
             }
         }
     }
+
+    /**
+     * 典型案例(原创)分类的积分发放逻辑:创建人获得评分平均分,审核人获得固定审核积分
+     * 使用“典型案例(原创)”分类对应的积分规则
+     */
+    private void grantPointsWithScoreForTypicalCaseOriginal(WorkKnowledgeBaseShareInfo entity, Date startTime) {
+        if (entity == null) {
+            return;
+        }
+        String shareId = entity.getId();
+        
+        // 查询“典型案例(原创)”分类对应的积分规则
+        List<WorkKnowledgePointCategory> categories = findCategoriesByName("典型案例(原创)");
+        if (categories == null || categories.isEmpty()) {
+            return;
+        }
+        
+        String categoryId = categories.get(0).getId();
+        // 查询该分类下rule_type=1(创建积分)的规则
+        WorkKnowledgeBasePointRule createRule = pointRuleDao.findByCategoryIdAndRuleType(categoryId, "1");
+        // 查询该分类下rule_type=2(审核积分)的规则
+        WorkKnowledgeBasePointRule auditRule = pointRuleDao.findByCategoryIdAndRuleType(categoryId, "2");
+        
+        // 计算专家评分的平均分(仅用于创建人)
+        Integer averageScore = null;
+        List<WorkKnowledgeBaseAuditRecord> records = auditRecordDao.findByFileIdSinceTime(shareId, startTime);
+        if (records != null && !records.isEmpty()) {
+            int totalScore = 0;
+            int scoreCount = 0;
+            for (WorkKnowledgeBaseAuditRecord record : records) {
+                if (record.getAuditResult() != null && record.getAuditResult() == 1
+                        && record.getScore() != null) {
+                    totalScore += record.getScore();
+                    scoreCount++;
+                }
+            }
+            if (scoreCount > 0) {
+                averageScore = Math.round((float) totalScore / scoreCount);
+            }
+        }
+        
+        // 1、提交审核人获得创建积分(使用平均分)
+        String submitUserId = entity.getSubmitAuditUserId();
+        if (StringUtils.isNotBlank(submitUserId) && averageScore != null && createRule != null) {
+            insertPointDetail(submitUserId, shareId, POINT_CHANGE_CREATE, categoryId, createRule.getId(), averageScore);
+        }
+        
+        // 2、本轮审核人各获得审核积分(使用固定审核积分值)
+        if (records == null || records.isEmpty() || auditRule == null || StringUtils.isBlank(auditRule.getPointValue())) {
+            return;
+        }
+        Integer auditPointValue = null;
+        try {
+            auditPointValue = Integer.parseInt(auditRule.getPointValue());
+        } catch (NumberFormatException e) {
+            return;
+        }
+        if (auditPointValue <= 0) {
+            return;
+        }
+        Set<String> grantedUserIds = new HashSet<>();
+        for (WorkKnowledgeBaseAuditRecord record : records) {
+            if (record.getAuditResult() != null && record.getAuditResult() == 1
+                    && StringUtils.isNotBlank(record.getAuditUserId())
+                    && grantedUserIds.add(record.getAuditUserId())) {
+                insertPointDetail(record.getAuditUserId(), shareId, POINT_CHANGE_AUDIT, categoryId, auditRule.getId(), auditPointValue);
+            }
+        }
+    }
     
     /**
      * 其他分类的积分发放逻辑:使用固定积分值
@@ -744,6 +876,68 @@ public class WorkKnowledgeBaseShareService extends CrudService<WorkKnowledgeBase
     }
 
     /**
+     * 典型案例(转载)分类的积分发放逻辑:使用固定分值,所有人可审核
+     */
+    private void grantPointsForTypicalCaseReprint(WorkKnowledgeBaseShareInfo entity, Date startTime) {
+        if (entity == null) {
+            return;
+        }
+        String shareId = entity.getId();
+        
+        // 查询“典型案例(转载)”分类对应的积分规则
+        List<WorkKnowledgePointCategory> categories = findCategoriesByName("典型案例(转载)");
+        if (categories == null || categories.isEmpty()) {
+            return;
+        }
+        
+        String categoryId = categories.get(0).getId();
+        // 查询该分类下rule_type=1(创建积分)的规则
+        WorkKnowledgeBasePointRule createRule = pointRuleDao.findByCategoryIdAndRuleType(categoryId, "1");
+        // 查询该分类下rule_type=2(审核积分)的规则
+        WorkKnowledgeBasePointRule auditRule = pointRuleDao.findByCategoryIdAndRuleType(categoryId, "2");
+        
+        // 1、提交审核人获得创建积分(使用固定值)
+        String submitUserId = entity.getSubmitAuditUserId();
+        if (StringUtils.isNotBlank(submitUserId) && createRule != null && StringUtils.isNotBlank(createRule.getPointValue())) {
+            Integer createPoint = null;
+            try {
+                createPoint = Integer.parseInt(createRule.getPointValue());
+            } catch (NumberFormatException e) {
+                createPoint = null;
+            }
+            if (createPoint != null && createPoint > 0) {
+                insertPointDetail(submitUserId, shareId, POINT_CHANGE_CREATE, categoryId, createRule.getId(), createPoint);
+            }
+        }
+        
+        // 2、本轮三位审核人各获得审核积分(使用固定值)
+        if (auditRule == null || StringUtils.isBlank(auditRule.getPointValue())) {
+            return;
+        }
+        Integer auditPointValue = null;
+        try {
+            auditPointValue = Integer.parseInt(auditRule.getPointValue());
+        } catch (NumberFormatException e) {
+            return;
+        }
+        if (auditPointValue <= 0) {
+            return;
+        }
+        List<WorkKnowledgeBaseAuditRecord> records = auditRecordDao.findByFileIdSinceTime(shareId, startTime);
+        if (records == null || records.isEmpty()) {
+            return;
+        }
+        Set<String> grantedUserIds = new HashSet<>();
+        for (WorkKnowledgeBaseAuditRecord record : records) {
+            if (record.getAuditResult() != null && record.getAuditResult() == 1
+                    && StringUtils.isNotBlank(record.getAuditUserId())
+                    && grantedUserIds.add(record.getAuditUserId())) {
+                insertPointDetail(record.getAuditUserId(), shareId, POINT_CHANGE_AUDIT, categoryId, auditRule.getId(), auditPointValue);
+            }
+        }
+    }
+
+    /**
      * 插入一条积分明细记录
      */
     private void insertPointDetail(String userId, String shareId, Integer changeType, String categoryId, String ruleId, Integer point) {

+ 13 - 0
src/main/java/com/jeeplus/modules/WorkKnowledgeBase/web/WorkKnowledgeBaseShareController.java

@@ -244,6 +244,19 @@ public class WorkKnowledgeBaseShareController extends BaseController {
                         }
                     }
                 }
+                
+                // 如果是典型案例(原创),查询“典型案例(原创)”分类对应的积分规则
+                if ("典型案例".equals(treeName) && "0".equals(workKnowledgeBaseShareInfo.getContentAttribute())) {
+                    List<WorkKnowledgePointCategory> categories = shareService.findCategoriesByName("典型案例(原创)");
+                    if (categories != null && !categories.isEmpty()) {
+                        String categoryId = categories.get(0).getId();
+                        // 查询该分类下rule_type=1(创建积分)的规则
+                        WorkKnowledgeBasePointRule rule = pointRuleService.findByCategoryIdAndRuleType(categoryId, "1");
+                        if (rule != null) {
+                            model.addAttribute("pointRule", rule);
+                        }
+                    }
+                }
             }
         }
 

+ 35 - 4
src/main/webapp/webpage/modules/WorkKnowledgeBase/workKnowledgeBaseShareDetail.jsp

@@ -21,8 +21,8 @@
                     opinion = '同意';
                 }
                 
-                // 如果是技术总结或培训心得,需要验证评分
-                <c:if test="${treeName == '技术总结' || treeName == '培训心得'}">
+                // 如果是技术总结、培训心得或典型案例(原创),需要验证评分
+                <c:if test="${treeName == '技术总结' || treeName == '培训心得' || (treeName == '典型案例' && entity.contentAttribute == '0')}">
                     var scoreValue = $('#scoreValue').val();
                     if (!scoreValue || scoreValue.trim() === '') {
                         top.layer.msg('请输入评分分数', {icon: 2});
@@ -67,7 +67,7 @@
                 data: { 
                     id: '${entity.id}', 
                     auditOpinion: opinion,
-                    <c:if test="${treeName == '技术总结' || treeName == '培训心得'}">
+                    <c:if test="${treeName == '技术总结' || treeName == '培训心得' || (treeName == '典型案例' && entity.contentAttribute == '0')}">
                     score: $('#scoreValue').val()
                     </c:if>
                 },
@@ -409,6 +409,22 @@
                         </div>
                     </c:if>
                 </c:if>
+                <!-- 如果是典型案例(原创),显示评分输入框 -->
+                <c:if test="${treeName == '典型案例' && entity.contentAttribute == '0'}">
+                    <c:if test="${pointRule != null}">
+                        <div class="layui-item layui-col-sm12 lw6">
+                            <label class="layui-form-label"><span class="require-item">*</span>评分分数:</label>
+                            <div class="layui-input-block">
+                                <input type="number" id="scoreValue" class="form-control layui-input"
+                                       min="${pointRule.pointMin}" max="${pointRule.pointMax}" step="1"
+                                       placeholder="请输入${pointRule.pointMin}-${pointRule.pointMax}之间的正整数" />
+                                <div id="scoreTip" style="color:#999;font-size:12px;margin-top:5px;">
+                                    评分范围:<span style="color:#999;">${pointRule.pointMin} - ${pointRule.pointMax}</span> 分(仅允许正整数)
+                                </div>
+                            </div>
+                        </div>
+                    </c:if>
+                </c:if>
                 <div class="layui-item layui-col-sm12 lw6 with-textarea">
                     <label class="layui-form-label">审核意见:</label>
                     <div class="layui-input-block">
@@ -446,6 +462,10 @@
                         <c:if test="${treeName == '技术总结' || treeName == '培训心得'}">
                             <th>评分分数</th>
                         </c:if>
+                        <!-- 典型案例(原创)也需要显示评分 -->
+                        <c:if test="${treeName == '典型案例' && entity.contentAttribute == '0'}">
+                            <th>评分分数</th>
+                        </c:if>
                         <th>审核意见</th>
                     </tr>
                     </thead>
@@ -464,11 +484,22 @@
                             <c:if test="${treeName == '技术总结' || treeName == '培训心得'}">
                                 <td>${record.score != null ? record.score : '-'}</td>
                             </c:if>
+                            <!-- 典型案例(原创)也需要显示评分 -->
+                            <c:if test="${treeName == '典型案例' && entity.contentAttribute == '0'}">
+                                <td>${record.score != null ? record.score : '-'}</td>
+                            </c:if>
                             <td>${record.auditOpinion != null && record.auditOpinion != '' ? record.auditOpinion : '-'}</td>
                         </tr>
                     </c:forEach>
                     <c:if test="${empty auditRecords}">
-                        <tr><td colspan="4" style="text-align:center;color:#999;">暂无审核记录</td></tr>
+                        <c:choose>
+                            <c:when test="${treeName == '技术总结' || treeName == '培训心得' || (treeName == '典型案例' && entity.contentAttribute == '0')}">
+                                <tr><td colspan="5" style="text-align:center;color:#999;">暂无审核记录</td></tr>
+                            </c:when>
+                            <c:otherwise>
+                                <tr><td colspan="4" style="text-align:center;color:#999;">暂无审核记录</td></tr>
+                            </c:otherwise>
+                        </c:choose>
                     </c:if>
                     </tbody>
                 </table>

+ 5 - 1
src/main/webapp/webpage/modules/WorkKnowledgeBase/workKnowledgeBaseShareList.jsp

@@ -725,7 +725,11 @@
                     : (d.createbyid === d.userid);
 
                 // 判断是否为需要专家审核的特殊分类
-                var needsExpertAudit = (d.treeName === '技术总结' || d.treeName === '培训心得');
+                // 技术总结/培训心得:需要专家审核
+                // 典型案例(原创)contentAttribute=0:需要专家审核
+                // 典型案例(转载)contentAttribute=1:所有人可审核
+                var needsExpertAudit = (d.treeName === '技术总结' || d.treeName === '培训心得')
+                    || (d.treeName === '典型案例' && d.contentAttribute === '0');
                 // 判断当前用户是否有审核权限(管理员、专家或普通分类)
                 var canAudit = !isCreator && !d.currentUserAudited && (d.isAdmin || d.isExpert || !needsExpertAudit);