<?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="cn.com.countrygarden.bi.main.dao.dup.CaseFieldInfoMapper">
    <resultMap id="BaseResultMap" type="cn.com.countrygarden.bi.main.model.dup.CaseFieldInfo">
        <!--
          WARNING - @mbg.generated
        -->
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="organ_name" jdbcType="VARCHAR" property="organName"/>
        <result column="organ_code" jdbcType="VARCHAR" property="organCode"/>
        <result column="comm_name" jdbcType="VARCHAR" property="commName"/>
        <result column="comm_id" jdbcType="VARCHAR" property="commId"/>
        <result column="case_field_name" jdbcType="VARCHAR" property="caseFieldName"/>
        <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
        <result column="created_by" jdbcType="VARCHAR" property="createdBy"/>
        <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
        <result column="updated_by" jdbcType="VARCHAR" property="updatedBy"/>
        <result column="is_delete" jdbcType="INTEGER" property="isDelete"/>
        <result column="remark" jdbcType="VARCHAR" property="remark"/>
    </resultMap>


    <!--添加案场基础信息-->
    <insert id="insertCaseFieldInfo" parameterType="cn.com.countrygarden.bi.main.model.dup.CaseFieldInfo">
    <![CDATA[

      insert into case_field_info (organ_name,organ_code,comm_name,comm_id,case_field_name,remark,create_date,created_by)
      VALUES (
        #{organName },
        #{organCode },
        #{commName },
        #{commId },
        #{caseFieldName },
        #{remark },
        now(),
        #{createdBy }
      )

        ]]>
  </insert>

    <!--修改案场基础信息-->
    <update id="modifyCaseFieldInfo" parameterType="cn.com.countrygarden.bi.main.model.dup.CaseFieldInfo">
      UPDATE case_field_info
      set organ_name = #{organName },
       organ_code= #{organCode },
       comm_name =  #{commName },
        comm_id = #{commId },
        case_field_name = #{caseFieldName },
        remark=#{remark},
        update_date = now(),
        updated_by = #{updatedBy }
       where id = #{id}
    </update>

    <!--软删除案场基础信息-->
    <update id="deleteCaseFieldInfoById" parameterType="Map">
        <![CDATA[
          UPDATE case_field_info AS t SET t.is_delete = 1, t.updated_by = #{userCode, jdbcType=VARCHAR},t.update_date=now()
          WHERE id = #{id, jdbcType=INTEGER}
        ]]>
    </update>

    <!--查询案场基础信息-->
    <select id="queryCaseFieldInfo" parameterType="Map" resultMap="BaseResultMap">
        select * from case_field_info
        <where>
            is_delete = 0
            <if test="caseFieldId != null and caseFieldId!='null' and caseFieldId !=''">
                and id = #{caseFieldId}
            </if>
            <if test="organCode != null and organCode!='null' and organCode !=''">
                and organ_code = #{organCode}
            </if>
            <if test="commId != null and commId!='null' and commId !=''">
                and comm_id = #{commId}
            </if>
            <if test="organs!=null and organs.size()>0">
                <![CDATA[
                  AND organ_code IN
                ]]>
                <foreach item="item" index="index" collection="organs" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="commIds!=null and commIds.size()>0">
                <![CDATA[
                  AND comm_id IN
                ]]>
                <foreach item="item" index="index" collection="commIds" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </where>
        order by id desc

        <if test="page != null and size != null">
            <![CDATA[
            LIMIT #{page, jdbcType=INTEGER}, #{size, jdbcType=INTEGER}
        ]]>
        </if>

    </select>

    <select id="queryTotal" parameterType="Map" resultType="java.lang.Integer">
        select count(*) from case_field_info
        <where>
            is_delete = 0
            <if test="caseFieldId != null and caseFieldId!='null' and caseFieldId !=''">
                and id = #{caseFieldId}
            </if>
            <if test="organCode != null and organCode!='null' and organCode !=''">
                and organ_code = #{organCode}
            </if>
            <if test="commId != null and commId!='null' and commId !=''">
                and comm_id = #{commId}
            </if>
            <if test="commIds!=null and commIds.size()>0">
                <![CDATA[
                  AND comm_id IN
                ]]>
                <foreach item="item" index="index" collection="commIds" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </where>
    </select>

    <select id="queryById" parameterType="Map" resultMap="BaseResultMap">
        select * from case_field_info where id = #{id}
    </select>
</mapper>