Browse Source

アンケート回答集計結果作成

quyx@nextosd.com 5 months ago
parent
commit
e027692bd1

+ 12 - 0
yamada-fcbi/src/main/java/jp/yamada/fcbi/controller/YmdfSurveyController.java

@@ -68,6 +68,18 @@ public class YmdfSurveyController extends BaseController
     }
 
     /**
+     *  アンケート回答詳細の取得
+     */
+    @PreAuthorize("@ss.hasPermi('system:survey:list')")
+    @GetMapping("/answer")
+    public TableDataInfo answerList(YmdfSurvey ymdfSurvey)
+    {
+        startPage();
+        List<YmdfSurvey> list = ymdfSurveyService.selectYmdfSurveyAnswerList(ymdfSurvey);
+        return getDataTable(list);
+    }
+
+    /**
      * 地域ツリー構造データの取得
      * @return 統一フォーマットのMap応答
      */

+ 6 - 0
yamada-fcbi/src/main/java/jp/yamada/fcbi/domain/YmdfSurvey.java

@@ -89,6 +89,12 @@ public class YmdfSurvey extends BaseEntity
     private String relatedRegion;
     private Integer questionCount;
 
+    private String sortOrder;
+    private String questionText;
+    private String questionType;
+    private String answerText;
+    private String options;
+
     @Excel(name = "FC会員名")
     private String fcMemberName;
     @Excel(name = "回答状態")

+ 8 - 0
yamada-fcbi/src/main/java/jp/yamada/fcbi/mapper/YmdfSurveyMapper.java

@@ -41,6 +41,14 @@ public interface YmdfSurveyMapper
     List<YmdfSurvey> selectYmdfSurveyDetailsList(YmdfSurvey ymdfSurvey);
 
     /**
+     * アンケート回答詳細の取得
+     *
+     * @param ymdfSurvey アンケート回答詳細の取得
+     * @return アンケート回答詳細の取得
+     */
+    List<YmdfSurvey> selectYmdfSurveyAnswerList(YmdfSurvey ymdfSurvey);
+
+    /**
      * クエリー領域のツリー構造データ
      * @return 地域ツリーを含むMapオブジェクト
      */

+ 8 - 0
yamada-fcbi/src/main/java/jp/yamada/fcbi/service/IYmdfSurveyService.java

@@ -40,6 +40,14 @@ public interface IYmdfSurveyService
     public List<YmdfSurvey> selectYmdfSurveyDetailsList(YmdfSurvey ymdfSurvey);
 
     /**
+     * アンケート回答詳細の取得
+     *
+     * @param ymdfSurvey アンケート回答詳細の取得
+     * @return アンケート回答詳細の取得
+     */
+    public List<YmdfSurvey> selectYmdfSurveyAnswerList(YmdfSurvey ymdfSurvey);
+
+    /**
      * 地域ツリー構造データの取得
      * @return 地域ツリーJSON構造
      */

+ 12 - 0
yamada-fcbi/src/main/java/jp/yamada/fcbi/service/impl/YmdfSurveyServiceImpl.java

@@ -104,6 +104,18 @@ public class YmdfSurveyServiceImpl implements IYmdfSurveyService
     }
 
     /**
+     * アンケート回答詳細の取得
+     *
+     * @param ymdfSurvey アンケート回答詳細の取得
+     * @return アンケート回答詳細の取得
+     */
+    @Override
+    public List<YmdfSurvey> selectYmdfSurveyAnswerList(YmdfSurvey ymdfSurvey)
+    {
+        return ymdfSurveyMapper.selectYmdfSurveyAnswerList(ymdfSurvey);
+    }
+
+    /**
      * 新增調査アンケート主(時間制御と状態管理を含む)
      *
      * @param ymdfSurveyParam 調査アンケート主(時間制御と状態管理を含む)

+ 84 - 0
yamada-fcbi/src/main/resources/mapper/fcbi/YmdfSurveyMapper.xml

@@ -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"/>