|
|
@@ -72,6 +72,12 @@ public class TaskService implements TaskServiceInterface {
|
|
|
@Resource
|
|
|
private ConsigneeMapper consigneeMapper;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private SurveyService surveyService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private SurveyTemplateMapper surveyTemplateMapper;
|
|
|
+
|
|
|
private static final int EARLY_BONUS = 1; // 提前完成奖励
|
|
|
private static final int PENALTY_MAX_DAILY = 5; // 每日最多扣分
|
|
|
private static final int LATE_GRACE_MINUTES = 10; // 10分钟内不算迟到
|
|
|
@@ -137,10 +143,12 @@ public class TaskService implements TaskServiceInterface {
|
|
|
Long firstChildId = childIds.get(0);
|
|
|
Task task = createSingleTask(currentUser, userId, executorType, firstChildId, dto);
|
|
|
taskMapper.insert(task);
|
|
|
+ ensureSurveyTemplateForTask(task);
|
|
|
// 为其他孩子创建任务实例
|
|
|
for (int i = 1; i < childIds.size(); i++) {
|
|
|
Task additionalTask = createSingleTask(currentUser, userId, executorType, childIds.get(i), dto);
|
|
|
taskMapper.insert(additionalTask);
|
|
|
+ ensureSurveyTemplateForTask(additionalTask);
|
|
|
}
|
|
|
return task.getId();
|
|
|
} else {
|
|
|
@@ -148,6 +156,7 @@ public class TaskService implements TaskServiceInterface {
|
|
|
Long memberId = childIds.isEmpty() ? null : childIds.get(0);
|
|
|
Task task = createSingleTask(currentUser, userId, executorType, memberId, dto);
|
|
|
taskMapper.insert(task);
|
|
|
+ ensureSurveyTemplateForTask(task);
|
|
|
return task.getId();
|
|
|
}
|
|
|
}
|
|
|
@@ -1386,4 +1395,59 @@ return 0; // 达到每日扣分上限
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * TASK-SYS-248: 调研任务自动模板生成(actionType=survey 时,若 actionConfig 无 surveyId 则调 AI 生成)
|
|
|
+ * 在 createTask 的 taskMapper.insert() 之后调用
|
|
|
+ */
|
|
|
+ private void ensureSurveyTemplateForTask(Task task) {
|
|
|
+ if (!"survey".equals(task.getActionType())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONObject config = parseActionConfig(task.getActionConfig());
|
|
|
+ // 已有 surveyId → 跳过
|
|
|
+ if (config != null && config.get("surveyId") != null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 从 config 或 task 属性取维度和主题
|
|
|
+ String dimension = null;
|
|
|
+ String topic = null;
|
|
|
+ if (config != null) {
|
|
|
+ dimension = config.getString("dimension");
|
|
|
+ topic = config.getString("topic");
|
|
|
+ }
|
|
|
+ if (dimension == null || dimension.isEmpty()) {
|
|
|
+ dimension = task.getDimensionCode();
|
|
|
+ }
|
|
|
+ if (topic == null || topic.isEmpty()) {
|
|
|
+ topic = task.getTitle();
|
|
|
+ }
|
|
|
+ if (topic == null || topic.isEmpty()) {
|
|
|
+ topic = "综合评估";
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ String questionsJson = surveyService.aiGenerateQuestions(dimension, topic);
|
|
|
+ SurveyTemplate tpl = new SurveyTemplate();
|
|
|
+ tpl.setTitle(task.getTitle() != null ? task.getTitle() + " - 调研" : "定期调研");
|
|
|
+ tpl.setDimension(dimension);
|
|
|
+ tpl.setQuestionsJson(questionsJson);
|
|
|
+ tpl.setCycleType("weekly");
|
|
|
+ tpl.setEnabled(1);
|
|
|
+ tpl.setAiGenerated(1);
|
|
|
+ tpl.setCreatedAt(new Date());
|
|
|
+ tpl.setUpdatedAt(new Date());
|
|
|
+ surveyTemplateMapper.insert(tpl);
|
|
|
+ // 回填 actionConfig
|
|
|
+ if (config == null) {
|
|
|
+ config = new JSONObject();
|
|
|
+ }
|
|
|
+ config.put("surveyId", tpl.getId());
|
|
|
+ task.setActionConfig(config.toJSONString());
|
|
|
+ taskMapper.updateById(task);
|
|
|
+ log.info("调研任务自动生成模板: taskId={}, templateId={}, dimension={}, topic={}",
|
|
|
+ task.getId(), tpl.getId(), dimension, topic);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("调研任务自动生成模板失败(不影响任务创建): taskId={}, error={}", task.getId(), e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|