<?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.jeeplus.business.knowledge.mapper.KnowledgeShareDetailMapper">

	<select id="findList" resultType="com.jeeplus.business.knowledge.service.dto.KnowledgeShareListDto">
		SELECT
			a.id,
			a.create_by_id,
			b.`name` AS createName,
			a.create_time,
			a.update_by_id,
			a.update_time,
			a.del_flag,
			a.type_id,
			a.title,
			a.detail,
			(SELECT count(0) FROM knowledge_share_visit b WHERE a.id = b.detail_id AND b.del_flag = 0) AS visit_num,
			(SELECT count(0) FROM knowledge_share_comment c WHERE a.id = c.detail_id AND c.del_flag = 0) AS comment_num
		FROM knowledge_share_detail a
		LEFT JOIN sys_user b ON a.create_by_id = b.id
		WHERE a.del_flag = 0
		<if test="detail.typeId != null and detail.typeId != ''">
			AND a.type_id = #{detail.typeId}
		</if>
		<if test="detail.title != null and detail.title != ''">
			AND a.title LIKE CONCAT ('%', #{detail.title}, '%')
		</if>
		<if test="detail.createById != null and detail.createById != ''">
			AND b.id = #{detail.createById}
		</if>
		ORDER BY a.update_time DESC
	</select>

	<select id="findDtos" resultType="com.jeeplus.sys.service.dto.WorkAttachmentInfoDTO">
		SELECT
			id,
			url,
			attachment_name AS `name`,
			create_by_id AS `by`,
			create_time
		FROM
			work_attachment
		WHERE
			del_flag = 0
			AND attachment_id = #{id}
	</select>

</mapper>
