You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
4.3 KiB

<?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="com.zh.project0512.mapper.TaskMapper">
<resultMap id="taskListMap" type="com.zh.project0512.model.Task">
<id property="id" column="id"/>
<collection property="tagList" ofType="java.util.Map" autoMapping="false">
<id column="tagId" property="id"/>
<result column="tagTitle" property="title"/>
</collection>
<collection property="brandList" ofType="java.util.Map" autoMapping="false">
<id column="brandId" property="id"/>
<result column="brandName" property="name"/>
</collection>
<collection property="referenceList" ofType="java.util.Map" autoMapping="false">
<id column="referenceId" property="id"/>
<result column="referenceTitle" property="title"/>
<result column="referenceType" property="type"/>
<result column="referenceFileUrl" property="fileUrl"/>
<result column="referenceCoverUrl" property="coverUrl"/>
</collection>
<collection property="teachRefeList" ofType="java.util.Map" autoMapping="false">
<result column="teachRefeFileUrl" property="teachRefeFileUrl"/>
<result column="teachRefeType" property="teachRefeType"/>
</collection>
</resultMap>
<select id="list" resultMap="taskListMap">
SELECT
t1.*,t2.tagId,t3.title as tagTitle,t4.brandId,t5.name as brandName,r1.fileUrl as teachRefeFileUrl,r1.type as teachRefeType
<if test='openid!=null'>
,(SELECT count(*)!=0 from userTask as t4,user as t5
WHERE t1.id = t4.taskId and t4.userId = t5.id and t5.openid = #{openid} ) as isReceived
</if>
from task as t1
<!-- left JOIN ( SELECT taskTag.*,tag.title from tag,taskTag WHERE taskTag.tagId = tag.id ) AS t2-->
<!-- on t1.id =t2.taskId-->
<!-- LEFT JOIN ( SELECT taskBrand.*,brand.name from brand,taskBrand WHERE taskBrand.brandId = brand.id ) as t3-->
<!-- on t1.id = t3.taskId-->
LEFT JOIN taskTag as t2 on t1.id = t2.taskId LEFT JOIN tag as t3 on t3.id = t2.tagId
LEFT JOIN taskBrand as t4 on t1.id = t4.taskId LEFT JOIN brand as t5 on t5.id = t4.brandId
LEFT JOIN taskTeachRefe as r1 on t1.id = r1.taskId
WHERE t1.id in
<foreach collection="list" index="index" item="item" open="(" separator="," close=")">#{item}</foreach>
<if test="tagIdList !=null and tagIdList.size()!=0 ">
and t1.id in (SELECT taskId from taskTag WHERE taskTag.tagId in
<foreach collection="tagIdList" index="index" item="item" open="(" separator="," close=")">#{item}</foreach>
)
</if>
<if test="brandIdList !=null and brandIdList.size()!=0 ">
and t1.id in (SELECT referenceId from taskBrand WHERE taskBrand.brandId in
<foreach collection="brandIdList" index="index" item="item" open="(" separator="," close=")">#{item}
</foreach>
)
</if>
<if test='ew != null'>
<if test='ew.nonEmptyOfWhere'>
AND
</if>
${ew.SqlSegment}
</if>
ORDER BY updateAt DESC,creatAt DESC
</select>
<select id="detailById" resultMap="taskListMap">
SELECT
t1.*,t2.tagId,t2.title as tagTitle,t3.brandId,t3.name as brandName,t4.referenceId,t4.title as referenceTitle,
t4.type as referenceType,t4.fileUrl as referenceFileUrl,t4.coverUrl as referenceCoverUrl
<if test='openid!=null'>
,(SELECT count(*)!=0 from userTask as t4,user as t5
WHERE t1.id = t4.taskId and t4.userId = t5.id and t5.openid = #{openid} ) as isReceived
</if>
from task as t1
left JOIN ( SELECT taskTag.*,tag.title from tag,taskTag WHERE taskTag.tagId = tag.id ) AS t2
on t1.id =t2.taskId
LEFT JOIN ( SELECT taskBrand.*,brand.name from brand,taskBrand WHERE taskBrand.brandId = brand.id ) as t3
on t1.id = t3.taskId
LEFT JOIN ( SELECT taskReference.*,reference.title,reference.type,reference.fileUrl,reference.coverUrl from
reference,taskReference WHERE taskReference.referenceId = reference.id ) as t4
on t1.id = t4.taskId
WHERE t1.id =#{id}
</select>
</mapper>