<?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.flowable.mapper.MyNoticeListMapper">

	<update id="readAll">
		UPDATE my_notice_list
			SET type = 1
		WHERE
			del_flag = 0
			AND create_user = #{name}
	</update>

	<select id="selectPage" resultType="com.jeeplus.flowable.model.MyNoticeList">
		select
		  a.id,
		  a.create_by_id,
		  a.create_time,
		  a.update_by_id,
		  a.update_time,
		  a.del_flag,
		  a.task_id,
		  a.title,
		  a.def_id,
		  a.task_name,
		  a.link,
		  a.create_user,
		  a.create_time,
		  a.type,
		  a.repetition_count,
		  a.notice_id,
		  su.name as "noticeName"
		from
		  my_notice_list a
		left join sys_user su on a.notice_id = su.id
		${ew.customSqlSegment}
	</select>

	<select id="getRepetitionCountBymyNotice" resultType="com.jeeplus.flowable.model.MyNoticeList">
		select
		  a.id,
		  a.create_by_id,
		  a.create_time,
		  a.update_by_id,
		  a.update_time,
		  a.del_flag,
		  a.task_id,
		  a.title,
		  a.def_id,
		  a.task_name,
		  a.link,
		  a.create_user,
		  a.create_time,
		  a.type,
		  a.repetition_count,
		  a.notice_id
		from
		  my_notice_list a
		<where>
			a.del_flag = 0
			and a.notice_id = #{noticeId}
			and a.task_name = #{taskName}
		</where>
	</select>
    <select id="getTaskInfoByID" resultType="com.jeeplus.flowable.model.ActRuTaskInfo">
		select
		  ID_ as "id",
		  REV_ as "rev",
		  EXECUTION_ID_ as "executionId",
		  PROC_INST_ID_ as "procInstId",
		  PROC_DEF_ID_ as "procDefId",
		  TASK_DEF_ID_ as "taskDefId",
		  SCOPE_ID_ as "scopeId",
		  SUB_SCOPE_ID_ as "subScopeId",
		  SCOPE_TYPE_ as "scopeType",
		  SCOPE_DEFINITION_ID_ as "scopeDefinitionId",
		  NAME_ as "name",
		  PARENT_TASK_ID_ as "parentTaskId",
		  DESCRIPTION_ as "description",
		  TASK_DEF_KEY_ as "taskDefKey",
		  OWNER_ as "owner",
		  ASSIGNEE_ as "assignee",
		  DELEGATION_ as "delegation",
		  PRIORITY_ as "priority",
		  CREATE_TIME_ as "createTime",
		  DUE_DATE_ as "dueDate",
		  CATEGORY_ as "category",
		  SUSPENSION_STATE_ as "suspensionState",
		  TENANT_ID_ as "tenantId",
		  FORM_KEY_ as "formKey",
		  CLAIM_TIME_ as "claimTime",
		  IS_COUNT_ENABLED_ as "isCountEnabled",
		  VAR_COUNT_ as "varCount",
		  ID_LINK_COUNT_ as "idLinkCount",
		  SUB_TASK_COUNT_  as "subTaskCount"
		from
		  act_ru_task
		where EXECUTION_ID_= #{id}
		order by CREATE_TIME_ desc
		limit 1
	</select>
    <select id="selectNoticePage" resultType="com.jeeplus.flowable.model.MyNoticeList">
		SELECT
		 a.id, a.create_by_id, a.create_time,
		 a.update_by_id, a.update_time, a.del_flag, a.task_id,
		 a.title, a.def_id, a.task_name, a.link, a.create_user, a.create_time,
		 a.type, a.repetition_count, a.notice_id, su.name AS "noticeName"
		 FROM my_notice_list a
		 LEFT JOIN sys_user su ON a.notice_id = su.id
		 ${ew.customSqlSegment}
	</select>
	<select id="selectInfo" resultType="com.jeeplus.flowable.model.MyNoticeList">
		SELECT id, task_id, title, def_id, task_name, link, create_user, create_time, notice_name, notice_id, type, repetition_count, create_by_id, update_time, update_by_id, del_flag, tenant_id
 		FROM my_notice_list
 		${ew.customSqlSegment}
	</select>
    <select id="getRepetitionCountBymyNoticeTitle" resultType="com.jeeplus.flowable.model.MyNoticeList">
		select
		a.id,
		a.create_by_id,
		a.create_time,
		a.update_by_id,
		a.update_time,
		a.del_flag,
		a.task_id,
		a.title,
		a.def_id,
		a.task_name,
		a.link,
		a.create_user,
		a.create_time,
		a.type,
		a.repetition_count,
		a.notice_id
		from
		my_notice_list a
		<where>
			a.del_flag = 0
			and a.notice_id = #{noticeId}
			and a.title = #{title}
			and a.type = 0
		</where>
	</select>
    <select id="selectNoticePage2" resultType="com.jeeplus.flowable.model.MyNoticeList">
		SELECT
		 a.id, a.create_by_id, a.create_time,
		 a.update_by_id, a.update_time, a.del_flag, a.task_id,
		 a.title, a.def_id, a.task_name, a.link, a.create_user, a.create_time,
		 a.type, a.repetition_count, a.notice_id, su.name AS "noticeName"
		 FROM my_notice_list a
		 LEFT JOIN sys_user su ON a.notice_id = su.id
		 ${ew.customSqlSegment}
	</select>

    <insert id="insertMyNotice">
		insert into my_notice_list (
		  id,
		  create_by_id,
		  create_date,
		  update_by_id,
		  update_time,
		  del_flag,
		  task_id,
		  title,
		  def_id,
		  task_name,
		  link,
		  create_user,
		  create_time,
		  notice_name,
		  notice_id,
		  `type`,
		  repetition_count
		)
		values
		  (
			#{id},
			#{createById},
			#{createTime},
			#{updateById},
			#{updateTime},
			#{delFlag},
			#{taskId},
			#{title},
			#{defId},
			#{taskName},
			#{link},
			#{createUser},
			#{createTime},
			#{noticeName},
			#{noticeId},
			#{type},
			#{repetitionCount}
		  ) ;
	</insert>

	<update id="updateMyNotice">
		update my_notice_list
		set `type` = 0,
		repetition_count = #{repetitionCount}
		where id = #{id}
	</update>


	<update id="portionRead">
		UPDATE my_notice_list
			SET type = 1
		<where>
			del_flag = 0
			and id in
			<foreach collection="idList" open="(" close=")" separator="," item="id">
				#{id}
			</foreach>
		</where>
	</update>
	<update id="updateInfoById">
		update my_notice_list set type = 1 where id = #{id}
	</update>
</mapper>
