|
|
@@ -25,6 +25,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
|
<result property="answeredQuestions" column="answered_questions"/>
|
|
|
<result property="unansweredQuestions" column="unanswered_questions"/>
|
|
|
<result property="completionRate" column="completion_rate"/>
|
|
|
+ <result property="sortOrder" column="sort_order" />
|
|
|
+ <result property="questionText" column="question_text" />
|
|
|
+ <result property="questionType" column="question_type" />
|
|
|
+ <result property="answerText" column="answer_text" />
|
|
|
+ <result column="options" property="options"/>
|
|
|
</resultMap>
|
|
|
|
|
|
<sql id="selectYmdfSurveyVo">
|
|
|
@@ -72,6 +77,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
|
|
|
|
<sql id="selectYmdfSurveyAnswerListVo">
|
|
|
SELECT
|
|
|
+ s.survey_id AS survey_id,
|
|
|
s.survey_code AS survey_code,
|
|
|
s.title AS title,
|
|
|
m.fc_member_name AS fc_member_name,
|
|
|
@@ -131,6 +137,84 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
|
</where>
|
|
|
</select>
|
|
|
|
|
|
+ <select id="selectYmdfSurveyAnswerList" parameterType="YmdfSurvey" resultMap="YmdfSurveyResult">
|
|
|
+ SELECT
|
|
|
+ s.survey_id AS survey_id,
|
|
|
+ s.survey_code AS survey_code,
|
|
|
+ s.title AS title,
|
|
|
+ -- アンケート基本情報(追加)
|
|
|
+ s.public_mode AS public_mode,
|
|
|
+ s.public_start_time AS public_start_time,
|
|
|
+ s.public_end_time AS public_end_time,
|
|
|
+
|
|
|
+ -- 質問と回答情報(元のロジック)
|
|
|
+ a.option_id AS option_id,
|
|
|
+ q.sort_order AS sort_order,
|
|
|
+ q.question_id AS question_id,
|
|
|
+ q.question_text AS question_text,
|
|
|
+ q.question_type AS question_type,
|
|
|
+ q.required AS required,
|
|
|
+ -- 選択式質問(3,4,5):is_answered標識付きのoptions配列を生成
|
|
|
+ CASE
|
|
|
+ WHEN q.question_type IN ('3', '4', '5') THEN
|
|
|
+ CONCAT(
|
|
|
+ '[',
|
|
|
+ GROUP_CONCAT(
|
|
|
+ JSON_OBJECT(
|
|
|
+ 'option_id', o.id,
|
|
|
+ 'option_text', o.option_text,
|
|
|
+ 'sort_order', o.sort_order,
|
|
|
+ 'is_answered', FIND_IN_SET(o.sort_order, REPLACE(a.option_id, '/', ',')) > 0
|
|
|
+ )
|
|
|
+ ORDER BY o.sort_order ASC
|
|
|
+ SEPARATOR ','
|
|
|
+ ),
|
|
|
+ ']'
|
|
|
+ )
|
|
|
+ ELSE NULL
|
|
|
+ END AS options,
|
|
|
+ -- テキスト式質問の回答内容+
|
|
|
+
|
|
|
+ CASE
|
|
|
+ WHEN q.question_type IN ('1', '2') THEN a.answer_text
|
|
|
+ ELSE NULL
|
|
|
+ END AS answer_text
|
|
|
+ FROM
|
|
|
+ -- 主テーブル:アンケート表
|
|
|
+ ymdf_survey s
|
|
|
+-- 質問テーブルと結合
|
|
|
+ INNER JOIN ymdf_survey_question q
|
|
|
+ ON s.survey_id = q.survey_id -- アンケートIDで結合
|
|
|
+ AND q.del_flag = 0
|
|
|
+-- 選択肢テーブルと結合(選択式質問のみ)
|
|
|
+ LEFT JOIN ymdf_survey_option o
|
|
|
+ ON q.question_id = o.question_id
|
|
|
+ AND o.del_flag = 0
|
|
|
+ AND q.question_type IN ('3', '4', '5') -- 選択式質問のみ選択肢を結合
|
|
|
+-- 回答テーブルと結合(ユーザーの回答)
|
|
|
+ INNER JOIN ymdf_survey_answer a
|
|
|
+ ON q.question_id = a.question_id
|
|
|
+ AND a.survey_id = s.survey_id -- 対象アンケートの回答を結合
|
|
|
+ AND a.del_flag = 0
|
|
|
+ WHERE
|
|
|
+ s.survey_id = 'S1142081669432750080' -- 対象アンケートID
|
|
|
+ AND s.del_flag = 0 -- 削除済みのアンケートを除外
|
|
|
+ GROUP BY
|
|
|
+ -- グループ化フィールドにアンケート情報を追加
|
|
|
+ s.public_mode,
|
|
|
+ s.public_start_time,
|
|
|
+ s.public_end_time,
|
|
|
+ a.option_id,
|
|
|
+ a.question_id,
|
|
|
+ q.question_id,
|
|
|
+ q.question_text,
|
|
|
+ q.question_type,
|
|
|
+ q.required,
|
|
|
+ a.answer_text
|
|
|
+ ORDER BY
|
|
|
+ q.sort_order ASC -- 質問のソート順に並び替え
|
|
|
+ </select>
|
|
|
+
|
|
|
<select id="selectYmdfSurveyDetailsList" parameterType="YmdfSurvey" resultMap="YmdfSurveyResult">
|
|
|
SELECT * FROM (
|
|
|
<include refid="selectYmdfSurveyAnswerListVo"/>
|