<?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="pwc.taxtech.atms.dao.ModelConfigMapper">
  <resultMap id="BaseResultMap" type="pwc.taxtech.atms.entitiy.ModelConfig">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <id column="ID" jdbcType="VARCHAR" property="ID" />
    <result column="CategoryID" jdbcType="VARCHAR" property="categoryID" />
    <result column="ModelID" jdbcType="VARCHAR" property="modelID" />
    <result column="CreateTime" jdbcType="TIMESTAMP" property="createTime" />
    <result column="UpdateTime" jdbcType="TIMESTAMP" property="updateTime" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    ID, CategoryID, ModelID, CreateTime, UpdateTime
  </sql>
  <select id="selectByExample" parameterType="pwc.taxtech.atms.entitiy.ModelConfigExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from ModelConfig
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select 
    <include refid="Base_Column_List" />
    from ModelConfig
    where ID = #{ID,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    delete from ModelConfig
    where ID = #{ID,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteByExample" parameterType="pwc.taxtech.atms.entitiy.ModelConfigExample">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    delete from ModelConfig
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="pwc.taxtech.atms.entitiy.ModelConfig">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    insert into ModelConfig (ID, CategoryID, ModelID, 
      CreateTime, UpdateTime)
    values (#{ID,jdbcType=VARCHAR}, #{categoryID,jdbcType=VARCHAR}, #{modelID,jdbcType=VARCHAR}, 
      #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="pwc.taxtech.atms.entitiy.ModelConfig">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    insert into ModelConfig
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="ID != null">
        ID,
      </if>
      <if test="categoryID != null">
        CategoryID,
      </if>
      <if test="modelID != null">
        ModelID,
      </if>
      <if test="createTime != null">
        CreateTime,
      </if>
      <if test="updateTime != null">
        UpdateTime,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="ID != null">
        #{ID,jdbcType=VARCHAR},
      </if>
      <if test="categoryID != null">
        #{categoryID,jdbcType=VARCHAR},
      </if>
      <if test="modelID != null">
        #{modelID,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null">
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="pwc.taxtech.atms.entitiy.ModelConfigExample" resultType="java.lang.Long">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select count(*) from ModelConfig
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update ModelConfig
    <set>
      <if test="record.ID != null">
        ID = #{record.ID,jdbcType=VARCHAR},
      </if>
      <if test="record.categoryID != null">
        CategoryID = #{record.categoryID,jdbcType=VARCHAR},
      </if>
      <if test="record.modelID != null">
        ModelID = #{record.modelID,jdbcType=VARCHAR},
      </if>
      <if test="record.createTime != null">
        CreateTime = #{record.createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.updateTime != null">
        UpdateTime = #{record.updateTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update ModelConfig
    set ID = #{record.ID,jdbcType=VARCHAR},
      CategoryID = #{record.categoryID,jdbcType=VARCHAR},
      ModelID = #{record.modelID,jdbcType=VARCHAR},
      CreateTime = #{record.createTime,jdbcType=TIMESTAMP},
      UpdateTime = #{record.updateTime,jdbcType=TIMESTAMP}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="pwc.taxtech.atms.entitiy.ModelConfig">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update ModelConfig
    <set>
      <if test="categoryID != null">
        CategoryID = #{categoryID,jdbcType=VARCHAR},
      </if>
      <if test="modelID != null">
        ModelID = #{modelID,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        CreateTime = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null">
        UpdateTime = #{updateTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where ID = #{ID,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="pwc.taxtech.atms.entitiy.ModelConfig">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update ModelConfig
    set CategoryID = #{categoryID,jdbcType=VARCHAR},
      ModelID = #{modelID,jdbcType=VARCHAR},
      CreateTime = #{createTime,jdbcType=TIMESTAMP},
      UpdateTime = #{updateTime,jdbcType=TIMESTAMP}
    where ID = #{ID,jdbcType=VARCHAR}
  </update>
  <select id="selectByExampleWithRowbounds" parameterType="pwc.taxtech.atms.entitiy.ModelConfigExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from ModelConfig
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
	<resultMap id="getModelListByIndustryResult" type="pwc.taxtech.atms.dto.ModelProfileDto">
		<id column="ID" jdbcType="VARCHAR" property="ID" />
		<result column="Name" jdbcType="VARCHAR" property="name" />
		<result column="CategoryID" jdbcType="VARCHAR" property="categoryID" />
		<result column="CategoryString" jdbcType="VARCHAR" property="categoryString" />
		<result column="OrgID" jdbcType="VARCHAR" property="orgID" />
		<result column="OrganizationName" jdbcType="VARCHAR" property="organizationName" />
		<result column="Type" jdbcType="INTEGER" property="type" />
		<result column="Feature" jdbcType="INTEGER" property="feature" />
		<result column="IsStatus" jdbcType="INTEGER" property="isStatus" />
		<result column="Code" jdbcType="VARCHAR" property="code" />
		<result column="IndustryId" jdbcType="VARCHAR" property="industryID" />
		<result column="IndustryName" jdbcType="VARCHAR" property="industryName" />
		<result column="Description" jdbcType="VARCHAR" property="description" />
		<result column="RuleType" jdbcType="INTEGER" property="ruleType" />
		<result column="IsFilter" jdbcType="INTEGER" property="isFilter" />
		<result column="ServiceTypeID" jdbcType="VARCHAR" property="serviceTypeID" />
		<result column="ServiceTypeName" jdbcType="VARCHAR" property="serviceTypeName" />
	</resultMap>
	<select id="getModelListByIndustry" parameterType="map" resultMap="getModelListByIndustryResult">
		SELECT 
		    m.ID,
		    m.Name,
		    mc.CategoryID,
		    cat.Category AS CategoryString,
		    cat.OrganizationID AS OrgID,
		    org.Name AS OrganizationName,
		    m.Type,
		    m.Feature,
		    m.IsStatus,
		    m.Code,
		    org.IndustryID AS IndustryId,
		    i.Name AS IndustryName,
		    m.Description,
		    m.RuleType,
		    m.IsFilter,
		    msc.ServiceTypeID,
		    st.Name AS ServiceTypeName
		FROM
		    Model m
		        JOIN
		    ModelConfig mc ON m.ID = mc.ModelID
		        JOIN
		    ModelCategory cat ON mc.CategoryID = cat.ID
		        JOIN
		    Organization org ON cat.organizationID = org.ID
		        JOIN
		    ModelServiceConfig msc ON m.ID = msc.ModelID
		        JOIN
		    ServiceType st ON msc.ServiceTypeID = st.ID
		        JOIN
		    Industry i ON org.IndustryID = i.ID
		WHERE org.IndustryID=#{industryID,jdbcType=VARCHAR} and st.ID = #{serviceTypeID,jdbcType=VARCHAR}
		ORDER BY m.code
	</select>
</mapper>