<?xml version="1.0" encoding="UTF-8"?>
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
<mapper namespace="cn.stylefeng.guns.modular.business.mapper.MentalTestRecordMapper">
|
|
<select id="myTestTopic" resultType="cn.stylefeng.guns.modular.business.dto.MentalTestMyTestTopicDTO">
|
(SELECT omt.id AS id,
|
omt.order_no AS orderNo,
|
o.id AS mentalTestRecordId,
|
o.create_time AS createTime,
|
o.answer_no AS answerNo,
|
omt.status_flag AS statusFlag,
|
omt.is_back AS isBack,
|
omt.test_flag AS testFlag,
|
tt.id AS topicId,
|
tt.status_flag AS topicStatus,
|
tt.title,
|
tt.class_id,
|
tt.intro,
|
tt.image,
|
tt.test_type,
|
tt.test_amount,
|
tt.consult_one,
|
tt.consult_amount,
|
tt.test_people_num,
|
tt.test_set_num
|
FROM t_mental_test_record o
|
LEFT JOIN t_order_mental_test omt ON o.answer_no = omt.order_no
|
LEFT JOIN t_mental_test_topic tt ON o.topic_id = tt.id
|
<where>
|
<if test="userId != null">
|
AND o.user_id = #{userId}
|
</if>
|
<if test="topicId != null">
|
AND o.topic_id = #{topicId}
|
</if>
|
</where>
|
)
|
UNION ALL
|
(SELECT o.id AS id,
|
o.order_no AS orderNo,
|
NULL AS mentalTestRecordId,
|
o.create_time AS createTime,
|
NULL AS answerNo,
|
o.status_flag AS statusFlag,
|
o.is_back AS isBack,
|
o.test_flag AS testFlag,
|
tt.id AS topicId,
|
tt.status_flag AS topicStatus,
|
tt.title,
|
tt.class_id,
|
tt.intro,
|
tt.image,
|
tt.test_type,
|
tt.test_amount,
|
tt.consult_one,
|
tt.consult_amount,
|
tt.test_people_num,
|
tt.test_set_num
|
FROM t_order_mental_test o
|
LEFT JOIN t_mental_test_topic tt ON o.goods_id = tt.id
|
<where> order_no NOT IN (SELECT answer_no FROM t_mental_test_record)
|
AND o.status_flag = 1
|
<if test="userId != null">
|
AND o.user_id = #{userId}
|
</if>
|
<if test="topicId != null">
|
AND o.topic_id = #{topicId}
|
</if>
|
</where>
|
)
|
</select>
|
<!--<select id="myTestTopic" resultType="cn.stylefeng.guns.modular.business.dto.MentalTestMyTestTopicDTO">
|
SELECT
|
o.*,
|
tt.status_flag topicStatus,
|
tt.title,
|
tt.class_id,
|
tt.intro,
|
tt.image,
|
tt.test_type,
|
tt.test_amount,
|
tt.consult_one,
|
tt.consult_amount,
|
tt.test_people_num,
|
tt.test_set_num
|
FROM
|
t_mental_test_record o
|
LEFT JOIN t_mental_test_topic tt ON tt.id = o.topic_id
|
<where>
|
<if test="userId != null">
|
AND o.user_id = #{userId}
|
</if>
|
<if test="topicId != null">
|
AND o.topic_id = #{topicId}
|
</if>
|
</where>
|
ORDER BY o.create_time DESC
|
</select>-->
|
|
<select id="myTestRecordTopicByMentalAppointmentId" resultType="cn.stylefeng.guns.modular.business.dto.MentalTestMyTestRecordTopicDTO">
|
SELECT
|
o.*,
|
tt.status_flag topicStatus,
|
tt.title,
|
tt.class_id,
|
tt.intro,
|
tt.image,
|
tt.test_type,
|
tt.test_amount,
|
tt.consult_one,
|
tt.consult_amount,
|
tt.test_people_num,
|
tt.test_set_num
|
FROM
|
t_mental_test_record o
|
LEFT JOIN t_mental_test_topic tt ON tt.id = o.topic_id
|
<where>
|
<if test="mentalAppointmentId != null">
|
AND o.mental_appointment_id = #{mentalAppointmentId}
|
</if>
|
<if test="mentalAppointmentIdList != null">
|
AND o.mental_appointment_id IN
|
<foreach collection="mentalAppointmentIdList" item="item" open="(" close=")" separator=",">
|
#{item}
|
</foreach>
|
</if>
|
</where>
|
ORDER BY o.create_time DESC
|
</select>
|
|
<select id="myTestOrder" resultType="cn.stylefeng.guns.modular.business.dto.MentalTestMyTestOrderDTO">
|
SELECT
|
o.*,
|
tt.id topicId,
|
tt.status_flag topicStatus,
|
tt.title,
|
tt.class_id,
|
tt.intro,
|
tt.image,
|
tt.test_type,
|
tt.test_amount,
|
tt.consult_one,
|
tt.consult_amount,
|
tt.test_people_num,
|
tt.test_set_num
|
FROM
|
t_order_mental_test o
|
LEFT JOIN t_mental_test_topic tt ON tt.id = o.goods_id
|
<where>
|
AND o.status_flag = 1 AND ( ( tt.test_type = 0 AND o.test_flag = 1 ) OR tt.test_type = 1 OR o.is_back = 1 )
|
<if test="userId != null">
|
AND o.user_id = #{userId}
|
</if>
|
<if test="topicId != null">
|
AND o.goods_id = #{topicId}
|
</if>
|
</where>
|
ORDER BY o.create_time DESC
|
</select>
|
|
<select id="getPage" resultType="cn.stylefeng.guns.modular.business.dto.MentalTestRecordPageDTO">
|
SELECT
|
tt.*,
|
o.create_time,
|
tu.nick_name,
|
tu.telephone
|
FROM
|
t_mental_test_record o
|
LEFT JOIN t_mental_test_topic tt ON tt.id = o.topic_id
|
LEFT JOIN toc_customer tu ON tu.customer_id = o.user_id
|
<where>
|
<if test="title != null and title != ''">
|
AND tt.title LIKE CONCAT('%', #{title}, '%')
|
</if>
|
<if test="testType != null">
|
AND tt.test_type = #{testType}
|
</if>
|
<if test="nickName != null and nickName != ''">
|
AND tu.nick_name LIKE CONCAT('%', #{nickName}, '%')
|
</if>
|
<if test="telephone != null and telephone != ''">
|
AND tu.telephone LIKE CONCAT('%', #{telephone}, '%')
|
</if>
|
</where>
|
ORDER BY o.create_time DESC
|
</select>
|
|
</mapper>
|