<?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.ozs.appshow.mapper.SubjectManageMapper">
	<select id="listSubjectByState" resultType="com.ozs.appshow.dto.SubjectInfoDTO">
		select id,subject_name,state,update_user_id,update_time from
		apps_info_subject
		where 1=1 and state = #{state}
		<if test="subjectName != null &amp;&amp; subjectName != ''">
			and subject_name like concat('%', #{subjectName},'%')
		</if>
	</select>
	<select id="getSubjectById" resultType="com.ozs.appshow.dto.SubjectInfoDTO">
		select
		ais.id,subject_name,state,update_user_id,update_time,diu.nickname
		updateUserName from
		apps_info_subject ais left join dc_info_user diu on
		ais.update_user_id
		= diu.id
		where 1=1 and ais.id = #{id}
	</select>
	<select id="getSubjectByName" resultType="com.ozs.appshow.dto.SubjectInfoDTO">
		select
		ais.id,subject_name,state,update_user_id,update_time,diu.nickname
		updateUserName from
		apps_info_subject ais left join dc_info_user diu on
		ais.update_user_id
		= diu.id
		where 1=1
		and subject_name = #{subjectName}
	</select>
	<insert id="saveSubject" parameterType="com.ozs.appshow.dto.SubjectInfoDTO">
		insert into
		apps_info_subject(id,subject_name,state,update_user_id,update_time)
		value(uuid(),#{subjectName},#{state},#{updateUserId},now())
	</insert>
	<update id="updateSubject" parameterType="com.ozs.appshow.dto.SubjectInfoDTO">
		update
		apps_info_subject set subject_name = #{subjectName} ,
		update_user_id =
		#{updateUserId}, update_time = now()
		where id
		= #{id}
	</update>
	<delete id="removeSubject">
		delete from apps_info_subject where id = #{id}
	</delete>
	<delete id="removeRelSubjectChart">
		delete from apps_rel_subject_chart where subject_id =
		#{subjectId}
	</delete>
	<insert id="saveRelSubjectChart" parameterType="com.ozs.appshow.dto.RelSubjectChartDTO">
		insert into
		apps_rel_subject_chart(subject_id,chart_id,subject_page,row_no,col_no,row_end_no,col_end_no,if_merge)
		values
		<foreach collection="list" item="rel" separator=",">
			(#{rel.subjectId},#{rel.chartId},#{rel.subjectPage},#{rel.rowNo},#{rel.colNo},#{rel.rowEndNo},#{rel.colEndNo},#{rel.ifMerge})
		</foreach>
	</insert>
	<update id="updateSubjectState" parameterType="com.ozs.appshow.dto.SubjectInfoDTO">
		update
		apps_info_subject set
		state =
		#{state}
		where id = #{id}
	</update>
	<select id="listRelSubjectChart" resultType="com.ozs.appshow.dto.RelSubjectChartDTO">
		SELECT
		subject_id,
		chart_id,
		subject_page,
		row_no,
		col_no,
		row_end_no,
		col_end_no,
		aic.chart_name,
		aic.chart_type
		,
		arsc.if_merge
		FROM
		apps_rel_subject_chart arsc left join
		apps_info_chart aic on
		arsc.chart_id = aic.id
		where subject_id =
		#{subjectId}
	</select>
	<insert id="saveSubjectPage" parameterType="com.ozs.appshow.dto.SubjectPageInfoDTO">
		insert into
		apps_info_subject_page(subject_id,subject_page,row_count,col_count)
		values
		<foreach collection="list" item="page" separator=",">
			(#{page.subjectId},#{page.subjectPage},#{page.rowCount},#{page.colCount})
		</foreach>

	</insert>
	<select id="listSubjectPageInfo" resultType="com.ozs.appshow.dto.SubjectPageInfoDTO">
		select
		subject_id,subject_page,row_count,col_count from
		apps_info_subject_page
		where 1=1 and subject_id = #{subjectId} order by subject_page
	</select>
</mapper>