<?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="org.diagbot.common.dao.mapper.StandardInfoMapper">
	<!-- 映射定义列-->
	<resultMap type="org.diagbot.common.dao.model.StandardInfo" id="standardInfoMap">
		<id property="id" column="id"/>
		<result property="code" column="code"/>
		<result property="name" column="name"/>
		<result property="status" column="status"/>
		<result property="categoryId" column="category_id"/>
		<result property="category" column="category"/>
		<result property="relationType" column="relation_type"/>
		<result property="relationId" column="relation_id"/>
		<result property="relationName" column="relation_name"/>
		<result property="remark" column="remark"/>
	</resultMap>

	<!-- 映射定义列-->
	<resultMap type="org.diagbot.common.dao.model.wrapper.StandardInfoWrapper" id="standardInfoWrapperMap">
		<id property="id" column="id"/>
		<result property="code" column="code"/>
		<result property="name" column="name"/>
		<result property="status" column="status"/>
		<result property="categoryId" column="category_id"/>
		<result property="category" column="category"/>
		<result property="relationType" column="relation_type"/>
		<result property="relationId" column="relation_id"/>
		<result property="relationName" column="relation_name"/>
		<result property="remark" column="remark"/>
	</resultMap>

	<!-- 通用查询结果列-->
	<sql id="Base_Column_List">
		 t.id, t.code,	 t.name,	 t.status,	  t.category_id,	 t.category,	 t.relation_type,	 t.relation_id,	 t.relation_name,	 t.remark
	</sql>

	<!-- 查询（根据主键ID查询） -->
	<select id="selectByPrimaryKey" resultMap="standardInfoMap" parameterType="java.lang.Long">
		 SELECT
		 <include refid="Base_Column_List" />
		 FROM kl_standard_info t
		 WHERE t.id = #{id}
	</select>

	<!-- 查询（根据主键ID查询） -->
	<select id="selectWrapperByPrimaryKey" resultMap="standardInfoWrapperMap" parameterType="java.lang.Long">
		 SELECT
		 <include refid="Base_Column_List" />
		 FROM kl_standard_info t
		 WHERE t.id = #{id}
	</select>

	<!-- 依据Map查询条件返回结果集-->
	<select id="selectList" resultMap="standardInfoMap" parameterType="java.util.Map">
		SELECT
		distinct t.name, t.category_id
		FROM kl_standard_info t WHERE category_id != '100'
		<if test="id != null and id != ''">
				 and t.id = #{id}
		</if>
		<if test="code != null and code != ''">
				 and t.code = #{code}
		</if>
		<if test="name != null and name != ''">
				 and t.name = #{name}
		</if>
		<if test="status != null and status != ''">
				 and t.status = #{status}
		</if>
		<if test="categoryId != null and categoryId != ''">
				 and t.category_id = #{categoryId}
		</if>
		<if test="category != null and category != ''">
				 and t.category = #{category}
		</if>
		<if test="relationType != null and relationType != ''">
				 and t.relation_type = #{relationType}
		</if>
		<if test="relationId != null and relationId != ''">
				 and t.relation_id = #{relationId}
		</if>
		<if test="relationName != null and relationName != ''">
				 and t.relation_name = #{relationName}
		</if>
		<if test="remark != null and remark != ''">
				 and t.remark = #{remark}
		</if>
	</select>

	<!-- 依据Map查询条件返回扩展属性结果集-->
	<select id="selectNullCategoryIdWrapper" resultMap="standardInfoWrapperMap" parameterType="java.util.Map">
		SELECT
		<include refid="Base_Column_List"/>
		FROM kl_standard_info t WHERE category_id is null or category_id = ''
	</select>

	<!-- 依据Map查询条件返回扩展属性结果集-->
	<select id="selectNotNullRelationTerm" resultMap="standardInfoMap" parameterType="java.util.Map">
		SELECT
		<include refid="Base_Column_List"/>
		FROM kl_standard_info t WHERE relation_name is not null and relation_name != ''
		<if test="relationType != null and relationType != ''">
			and relation_type = #{relationType}
		</if>
	</select>

	<!-- 依据Map查询条件返回扩展属性结果集-->
	<select id="selectListWrapper" resultMap="standardInfoWrapperMap" parameterType="java.util.Map">
		SELECT 
		<include refid="Base_Column_List"/>
		FROM kl_standard_info t WHERE 1=1 
		<if test="id != null and id != ''">
				 and t.id = #{id}
		</if>
		<if test="code != null and code != ''">
				 and t.code = #{code}
		</if>
		<if test="name != null and name != ''">
			and t.name like concat('%',#{name},'%')
		</if>
		<if test="status != null and status != ''">
				 and t.status = #{status}
		</if>
		<if test="categoryId != null and categoryId != ''">
				 and t.category_id = #{categoryId}
		</if>
		<if test="category != null and category != ''">
			and t.category like concat('%',#{category},'%')
		</if>
		<if test="relationType != null and relationType != ''">
				 and t.relation_type = #{relationType}
		</if>
		<if test="relationId != null and relationId != ''">
				 and t.relation_id = #{relationId}
		</if>
		<if test="relationName != null and relationName != ''">
				 and t.relation_name = #{relationName}
		</if>
		<if test="remark != null and remark != ''">
				 and t.remark = #{remark}
		</if>
	</select> 

	<!--删除：根据主键ID删除-->
	<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
		 DELETE FROM kl_standard_info
		 WHERE id = #{id}
	</delete>
</mapper>