refactor: 更改子查询为join
This commit is contained in:
parent
940f41930f
commit
c4852d5e7e
|
|
@ -7,111 +7,6 @@
|
|||
where course_id = #{id}
|
||||
</update>
|
||||
<select id="selectCourse" resultType="Map">
|
||||
SELECT
|
||||
c.classify_id AS classifyId,
|
||||
c.course_id AS courseId,
|
||||
c.course_label AS courseLabel,
|
||||
c.create_time AS createTime,
|
||||
c.details,
|
||||
c.img,
|
||||
c.banner_img AS bannerImg,
|
||||
c.status,
|
||||
c.is_delete AS isDelete,
|
||||
c.msg_type AS msgType,
|
||||
c.msg_url AS msgUrl,
|
||||
c.pay_num AS payNum,
|
||||
c.price,
|
||||
c.wholesale_price AS wholesalePrice,
|
||||
c.is_over AS isOver,
|
||||
c.title,
|
||||
c.is_price AS isPrice,
|
||||
c.title_img AS titleImg,
|
||||
c.update_time AS updateTime,
|
||||
cc.classification_name AS classificationName,
|
||||
c.course_type AS courseType,
|
||||
c.banner_id AS bannerId,
|
||||
b.name AS bannerName,
|
||||
0 AS viewCounts,
|
||||
c.dy_img_id AS dyImgId,
|
||||
c.dy_course_id AS dyCourseId,
|
||||
c.wx_course_id AS wxCourseId,
|
||||
c.wx_show AS wxShow,
|
||||
c.dy_show AS dyShow,
|
||||
c.sort,
|
||||
ROUND(10000 * RAND(), 0) AS goodNum,
|
||||
d.courseDetailsCount,
|
||||
NULL AS courseDetailsName,
|
||||
NULL AS courseDetailsId,
|
||||
ROUND(10000 * RAND(), 0) AS weekGoodNum,
|
||||
0 AS isRecommend
|
||||
FROM
|
||||
course AS c
|
||||
LEFT JOIN
|
||||
course_classification AS cc ON c.classify_id = cc.classification_id
|
||||
LEFT JOIN
|
||||
banner AS b ON b.id = c.banner_id
|
||||
LEFT JOIN
|
||||
(SELECT course_id, COUNT(*) AS courseDetailsCount
|
||||
FROM course_details
|
||||
GROUP BY course_id) AS d ON c.course_id = d.course_id
|
||||
LEFT JOIN
|
||||
(SELECT course_id FROM course_details WHERE good = 1) AS gd ON c.course_id = gd.course_id
|
||||
WHERE
|
||||
c.is_delete = 0
|
||||
<if test='null != wxShow and wxShow == 1'>
|
||||
AND c.wx_show = #{wxShow}
|
||||
</if>
|
||||
<if test='null != wxShow and wxShow == 2'>
|
||||
AND (c.wx_show = #{wxShow} OR c.wx_show IS NULL)
|
||||
</if>
|
||||
<if test='null != dyShow and dyShow == 1'>
|
||||
AND c.dy_show = #{dyShow}
|
||||
</if>
|
||||
<if test='null != dyShow and dyShow == 2'>
|
||||
AND (c.dy_show = #{dyShow} OR c.dy_show IS NULL)
|
||||
</if>
|
||||
<if test='null != title'>
|
||||
AND c.title LIKE CONCAT('%', #{title}, '%')
|
||||
</if>
|
||||
<if test='null != classifyId and classifyId != 0'>
|
||||
AND c.classify_id = #{classifyId}
|
||||
</if>
|
||||
<if test='null != bannerId and bannerId != 0'>
|
||||
AND c.banner_id = #{bannerId}
|
||||
</if>
|
||||
<if test="classifyId == 0">
|
||||
AND c.is_recommend = 1
|
||||
</if>
|
||||
<if test="over != null">
|
||||
AND c.is_over = #{over}
|
||||
</if>
|
||||
<if test="isRecommend != null and isRecommend != -1">
|
||||
AND gd.course_id IS NOT NULL
|
||||
</if>
|
||||
<if test="status != null and status != 0">
|
||||
AND c.status = #{status}
|
||||
</if>
|
||||
<if test="isPrice != null">
|
||||
AND c.is_price = #{isPrice}
|
||||
</if>
|
||||
<if test="wxCourse != null">
|
||||
AND c.wx_course_id IS NOT NULL
|
||||
</if>
|
||||
<if test="dyCourse != null">
|
||||
AND c.dy_status = 4
|
||||
</if>
|
||||
<if test="sort == null">
|
||||
ORDER BY c.sort ASC, c.create_time DESC
|
||||
</if>
|
||||
<if test="sort != null and sort == 1">
|
||||
ORDER BY goodNum DESC
|
||||
</if>
|
||||
<if test="sort != null and sort == 2">
|
||||
ORDER BY weekGoodNum DESC
|
||||
</if>;
|
||||
|
||||
|
||||
<!--
|
||||
SELECT
|
||||
c.classify_id as classifyId,
|
||||
c.course_id as courseId,
|
||||
|
|
@ -144,7 +39,7 @@
|
|||
c.dy_show as dyShow,
|
||||
c.sort,
|
||||
round(10000*rand(),0) as goodNum,
|
||||
(select count(*) from course_details d where d.course_id=c.course_id ) as courseDetailsCount,
|
||||
cd.course_details_count as courseDetailsCount, -- Replaced subquery with left join count
|
||||
null AS courseDetailsName,
|
||||
null AS courseDetailsId,
|
||||
round(10000*rand(),0) as weekGoodNum,
|
||||
|
|
@ -152,62 +47,170 @@
|
|||
FROM
|
||||
course AS c
|
||||
LEFT JOIN course_classification AS cc ON c.classify_id = cc.classification_id
|
||||
left join banner as b on b.id=c.banner_id
|
||||
LEFT JOIN banner AS b ON b.id = c.banner_id
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
course_id,
|
||||
COUNT(*) as course_details_count
|
||||
FROM
|
||||
course_details
|
||||
GROUP BY
|
||||
course_id
|
||||
) AS cd ON c.course_id = cd.course_id
|
||||
WHERE
|
||||
1 = 1
|
||||
AND c.is_delete = 0
|
||||
<if test='null != wxShow and wxShow==1'>
|
||||
and c.wx_show = #{wxShow}
|
||||
AND c.wx_show = #{wxShow}
|
||||
</if>
|
||||
<if test='null != wxShow and wxShow==2'>
|
||||
and (c.wx_show = #{wxShow} or c.wx_show is null)
|
||||
AND (c.wx_show = #{wxShow} OR c.wx_show IS NULL)
|
||||
</if>
|
||||
<if test='null != dyShow and dyShow==1'>
|
||||
and c.dy_show = #{dyShow}
|
||||
AND c.dy_show = #{dyShow}
|
||||
</if>
|
||||
<if test='null != dyShow and dyShow==2'>
|
||||
and (c.dy_show = #{dyShow} or c.dy_show is null)
|
||||
AND (c.dy_show = #{dyShow} OR c.dy_show IS NULL)
|
||||
</if>
|
||||
<if test='null != title'>
|
||||
and c.title LIKE CONCAT('%', #{title}, '%')
|
||||
AND c.title LIKE CONCAT('%', #{title}, '%')
|
||||
</if>
|
||||
<if test='null!= classifyId and classifyId!=0'>
|
||||
and c.classify_id = #{classifyId}
|
||||
<if test='null != classifyId and classifyId != 0'>
|
||||
AND c.classify_id = #{classifyId}
|
||||
</if>
|
||||
<if test='null!= bannerId and bannerId!=0'>
|
||||
and c.banner_id = #{bannerId}
|
||||
<if test='null != bannerId and bannerId != 0'>
|
||||
AND c.banner_id = #{bannerId}
|
||||
</if>
|
||||
<if test="classifyId==0">
|
||||
and c.is_recommend=1
|
||||
<if test="classifyId == 0">
|
||||
AND c.is_recommend = 1
|
||||
</if>
|
||||
<if test="over!=null">
|
||||
and c.is_over=#{over}
|
||||
<if test="over != null">
|
||||
AND c.is_over = #{over}
|
||||
</if>
|
||||
<if test="isRecommend!=null and isRecommend!=-1">
|
||||
and c.course_id in (select course_id from course_details where good=1)
|
||||
<if test="isRecommend != null and isRecommend != -1">
|
||||
AND c.course_id IN (SELECT course_id FROM course_details WHERE good = 1)
|
||||
</if>
|
||||
<if test="status!=null and status!=0">
|
||||
and c.status=#{status}
|
||||
<if test="status != null and status != 0">
|
||||
AND c.status = #{status}
|
||||
</if>
|
||||
<if test="isPrice!=null">
|
||||
and c.is_price=#{isPrice}
|
||||
<if test="isPrice != null">
|
||||
AND c.is_price = #{isPrice}
|
||||
</if>
|
||||
<if test="wxCourse!=null">
|
||||
and c.wx_course_id is not null
|
||||
<if test="wxCourse != null">
|
||||
AND c.wx_course_id IS NOT NULL
|
||||
</if>
|
||||
<if test="dyCourse!=null">
|
||||
and c.dy_status=4
|
||||
<if test="dyCourse != null">
|
||||
AND c.dy_status = 4
|
||||
</if>
|
||||
<if test="sort==null">
|
||||
order by c.sort asc,c.create_time desc
|
||||
<if test="sort == null">
|
||||
ORDER BY c.sort ASC, c.create_time DESC
|
||||
</if>
|
||||
<if test="sort!=null and sort==1">
|
||||
order by goodNum desc
|
||||
<if test="sort != null and sort == 1">
|
||||
ORDER BY goodNum DESC
|
||||
</if>
|
||||
<if test="sort!=null and sort==2">
|
||||
order by weekGoodNum desc
|
||||
<if test="sort != null and sort == 2">
|
||||
ORDER BY weekGoodNum DESC
|
||||
</if>
|
||||
-->
|
||||
|
||||
|
||||
|
||||
<!--
|
||||
SELECT
|
||||
c.classify_id as classifyId,
|
||||
c.course_id as courseId,
|
||||
c.course_label as courseLabel,
|
||||
c.create_time createTime,
|
||||
c.details,
|
||||
c.img,
|
||||
c.banner_img as bannerImg,
|
||||
c.status,
|
||||
c.is_delete as isDelete,
|
||||
c.msg_type msgType,
|
||||
c.msg_url as msgUrl,
|
||||
c.pay_num as payNum,
|
||||
c.price,
|
||||
c.wholesale_price as wholesalePrice,
|
||||
c.is_over as isOver,
|
||||
c.title,
|
||||
c.is_price as isPrice,
|
||||
c.title_img as titleImg,
|
||||
c.update_time as updateTime,
|
||||
cc.classification_name as classificationName,
|
||||
c.course_type as courseType,
|
||||
c.banner_id as bannerId,
|
||||
b.name as bannerName,
|
||||
0 as viewCounts,
|
||||
c.dy_img_id as dyImgId,
|
||||
c.dy_course_id as dyCourseId,
|
||||
c.wx_course_id as wxCourseId,
|
||||
c.wx_show as wxShow,
|
||||
c.dy_show as dyShow,
|
||||
c.sort,
|
||||
round(10000*rand(),0) as goodNum,
|
||||
(select count(*) from course_details d where d.course_id=c.course_id ) as courseDetailsCount,
|
||||
null AS courseDetailsName,
|
||||
null AS courseDetailsId,
|
||||
round(10000*rand(),0) as weekGoodNum,
|
||||
0 as isRecommend
|
||||
FROM
|
||||
course AS c
|
||||
LEFT JOIN course_classification AS cc ON c.classify_id = cc.classification_id
|
||||
left join banner as b on b.id=c.banner_id
|
||||
WHERE
|
||||
1 = 1
|
||||
AND c.is_delete = 0
|
||||
<if test='null != wxShow and wxShow==1'>
|
||||
and c.wx_show = #{wxShow}
|
||||
</if>
|
||||
<if test='null != wxShow and wxShow==2'>
|
||||
and (c.wx_show = #{wxShow} or c.wx_show is null)
|
||||
</if>
|
||||
<if test='null != dyShow and dyShow==1'>
|
||||
and c.dy_show = #{dyShow}
|
||||
</if>
|
||||
<if test='null != dyShow and dyShow==2'>
|
||||
and (c.dy_show = #{dyShow} or c.dy_show is null)
|
||||
</if>
|
||||
<if test='null != title'>
|
||||
and c.title LIKE CONCAT('%', #{title}, '%')
|
||||
</if>
|
||||
<if test='null!= classifyId and classifyId!=0'>
|
||||
and c.classify_id = #{classifyId}
|
||||
</if>
|
||||
<if test='null!= bannerId and bannerId!=0'>
|
||||
and c.banner_id = #{bannerId}
|
||||
</if>
|
||||
<if test="classifyId==0">
|
||||
and c.is_recommend=1
|
||||
</if>
|
||||
<if test="over!=null">
|
||||
and c.is_over=#{over}
|
||||
</if>
|
||||
<if test="isRecommend!=null and isRecommend!=-1">
|
||||
and c.course_id in (select course_id from course_details where good=1)
|
||||
</if>
|
||||
<if test="status!=null and status!=0">
|
||||
and c.status=#{status}
|
||||
</if>
|
||||
<if test="isPrice!=null">
|
||||
and c.is_price=#{isPrice}
|
||||
</if>
|
||||
<if test="wxCourse!=null">
|
||||
and c.wx_course_id is not null
|
||||
</if>
|
||||
<if test="dyCourse!=null">
|
||||
and c.dy_status=4
|
||||
</if>
|
||||
<if test="sort==null">
|
||||
order by c.sort asc,c.create_time desc
|
||||
</if>
|
||||
<if test="sort!=null and sort==1">
|
||||
order by goodNum desc
|
||||
</if>
|
||||
<if test="sort!=null and sort==2">
|
||||
order by weekGoodNum desc
|
||||
</if>
|
||||
-->
|
||||
</select>
|
||||
|
||||
<select id="selectCourseAdmin" resultType="Map">
|
||||
|
|
|
|||
Loading…
Reference in New Issue