<?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.unis.base.server.dao.XzqhDao'>
  
  <!--lipenghe-->
  <!--无表注释  单表[TY_XZQHB]表
        和实体基础映射-->
  <resultMap id='ResultMapBase' type='com.unis.base.server.entity.XzqhDO'>
    <id column='QHID' jdbcType='VARCHAR' property='qhid' /><!--无字段注释 #<主键><唯一><检索><非空>-->
    <result column='XZQH' jdbcType='VARCHAR' property='xzqh' /><!--无字段注释 #<检索>-->
    <result column='FZDW' jdbcType='VARCHAR' property='fzdw' /><!--无字段注释 #<检索>-->
    <result column='XZQHMC' jdbcType='VARCHAR' property='xzqhmc' /><!--无字段注释 #<检索>-->
    <result column='FZDWBM' jdbcType='VARCHAR' property='fzdwbm' /><!--无字段注释 #<检索>-->
  </resultMap>
  
  <!--[TY_XZQHB]表基础列-->
  <sql id='Column_Base_List'>
    QHID, XZQH, FZDW, XZQHMC, FZDWBM
  </sql>
  
  <!--[TY_XZQHB]带别名的表基础列,别名为大写表名-->
  <sql id='Column_Alias_List'>
    A.QHID, A.XZQH, A.FZDW, A.XZQHMC, A.FZDWBM
  </sql>
  
  <!--[TY_XZQHB]表 order by 条件-->
  <sql id='Order_By_Clause'>
    ORDER BY QHID DESC
  </sql>
  
  <!--[TY_XZQHB]表 order by 条件-->
  <sql id='Order_By_Alias_Clause'>
    ORDER BY A.QHID DESC
  </sql>
  
  <!--批量插入全部字段,[GBase Server]特别注意:批量插入全部字段时,数据库默认值会不起效-->
  <insert id='insertBatchEntityList'>
    insert into TY_XZQHB (QHID, XZQH, FZDW, 
      XZQHMC, FZDWBM)  SELECT * FROM 
    <foreach close=')' collection='list' index='index' item='item' open='(' separator='UNION ALL'>
       SELECT #{item.qhid,jdbcType=VARCHAR}, #{item.xzqh,jdbcType=VARCHAR}, #{item.fzdw,jdbcType=VARCHAR}, 
        #{item.xzqhmc,jdbcType=VARCHAR}, #{item.fzdwbm,jdbcType=VARCHAR} FROM DUAL 
    </foreach>
  </insert>
  
  <!--更改状态-->
  <update id='updateStatusByEntity'>
    update TY_XZQHB
    <set>
      <if test='fzdwbm != null'>
        FZDWBM = #{fzdwbm,jdbcType=VARCHAR},
      </if>
      <if test='xzqhmc != null'>
        XZQHMC = #{xzqhmc,jdbcType=VARCHAR},
      </if>
    </set>
    <where>
      <!--此处为必填条件,如不满足则不执行,以免更新全部-->
      <choose>
        <when test='qhid !=null and qhid != ""'>
          AND QHID = #{qhid,jdbcType=VARCHAR}
        </when>
        <otherwise>
          AND 1=0
        </otherwise>
      </choose>
    </where>
  </update>
  
  <!--根据实体批量更新全部字段,[GBase Server]批量更新全部字段-->
  <update id='updateBatchByEntityList' parameterType='java.util.List'>
    <foreach collection='list' index='index' item='item' separator=';'>
      update TY_XZQHB
      set XZQH = #{item.xzqh,jdbcType=VARCHAR},
        FZDW = #{item.fzdw,jdbcType=VARCHAR},
        XZQHMC = #{item.xzqhmc,jdbcType=VARCHAR},
        FZDWBM = #{item.fzdwbm,jdbcType=VARCHAR}
      <where>
        <!--此处为必填条件,如不满足则不执行,以免更新全部-->
        <choose>
          <when test='item.qhid !=null and item.qhid != ""'>
            QHID = #{item.qhid,jdbcType=VARCHAR}
          </when>
          <otherwise>
            AND 1=0
          </otherwise>
        </choose>
        <!--此处可添加状态条件等-->
        <!--
        <if test='item.datastatus!=null'>
          AND DATASTATUS = #{item.datastatus,jdbcType=DECIMAL}
        </if>
        -->
      </where>
    </foreach>
  </update>
  
  <!--根据实体某些属性更新全部字段-->
  <update id='updateByEntity'>
    update TY_XZQHB
    set XZQH = #{xzqh,jdbcType=VARCHAR},
      FZDW = #{fzdw,jdbcType=VARCHAR},
      XZQHMC = #{xzqhmc,jdbcType=VARCHAR},
      FZDWBM = #{fzdwbm,jdbcType=VARCHAR}
    <where>
      <!--此处为必填条件,如不满足则不执行,以免更新全部-->
      <choose>
        <when test='qhid !=null and qhid != ""'>
          AND QHID = #{qhid,jdbcType=VARCHAR}
        </when>
        <otherwise>
          AND 1=0
        </otherwise>
      </choose>
      <!--此处可添加状态条件等-->
      <!--
      <if test='datastatus!=null'>
        AND DATASTATUS = #{datastatus,jdbcType=DECIMAL}
      </if>
      -->
    </where>
  </update>
  
  <!--根据实体不为空的属性,选择性更新字段-->
  <update id='updateByEntitySelective'>
    update TY_XZQHB
    <set>
      <if test='xzqh != null'>
        XZQH = #{xzqh,jdbcType=VARCHAR},
      </if>
      <if test='fzdw != null'>
        FZDW = #{fzdw,jdbcType=VARCHAR},
      </if>
      <if test='xzqhmc != null'>
        XZQHMC = #{xzqhmc,jdbcType=VARCHAR},
      </if>
      <if test='fzdwbm != null'>
        FZDWBM = #{fzdwbm,jdbcType=VARCHAR},
      </if>
    </set>
    <where>
      <!--此处为必填条件,如不满足则不执行,以免更新全部-->
      <choose>
        <when test='qhid !=null and qhid != ""'>
          AND QHID = #{qhid,jdbcType=VARCHAR}
        </when>
        <otherwise>
          AND 1=0
        </otherwise>
      </choose>
      <!--此处可添加状态条件等-->
      <!--
      <if test='datastatus!=null'>
        AND DATASTATUS = #{datastatus,jdbcType=DECIMAL}
      </if>
      -->
    </where>
  </update>
  
  <!--[真删除]根据实体的某些属性进行单条或者批量删除
          此处不支持id集合的形式,如有其他情况自行添加-->
  <delete id='deleteByEntity'>
    DELETE FROM TY_XZQHB
    <where>
      <!--此处为必填条件,如不满足则不执行,以免更新全部-->
      <choose>
        <when test='qhid !=null and qhid != ""'>
          AND QHID = #{qhid,jdbcType=VARCHAR}
        </when>
        <otherwise>
          AND 1=0
        </otherwise>
      </choose>
      <!--此处可添加状态条件等-->
      <!--
      <if test='datastatus!=null'>
        AND DATASTATUS = #{datastatus,jdbcType=DECIMAL}
      </if>
      -->
    </where>
  </delete>
  
  <!--[假删除]根据实体的某些属性进行单条或者批量删除
          此处不支持id集合的形式,如有其他情况自行添加-->
  <update id='deleteShamByEntity'>
    update TY_XZQHB
    set 
    DATASTATUS = #{datastatus,jdbcType=DECIMAL}
    <where>
      <!--此处为必填条件,如不满足则不执行,以免更新全部-->
      <choose>
        <when test='qhid !=null and qhid != ""'>
          AND QHID = #{qhid,jdbcType=VARCHAR}
        </when>
        <otherwise>
          AND 1=0
        </otherwise>
      </choose>
    </where>
  </update>
  
  <!--根据实体的某些属性查询数量-->
  <select id='selectCountByEntity' resultType='java.lang.Integer'>
    SELECT 
    COUNT(1)
    FROM TY_XZQHB
    <where>
      <!--自定义配置的检索条件-->
      <if test='qhid !=null and qhid != ""'>
        AND QHID = #{qhid,jdbcType=VARCHAR}
      </if>
      <if test='xzqh !=null and xzqh != ""'>
        AND XZQH = #{xzqh,jdbcType=VARCHAR}
      </if>
      <if test='fzdw !=null and fzdw != ""'>
        AND FZDW LIKE CONCAT('%',CONCAT(#{fzdw,jdbcType=VARCHAR},'%'))
      </if>
      <if test='xzqhmc !=null and xzqhmc != ""'>
        AND XZQHMC LIKE CONCAT('%',CONCAT(#{xzqhmc,jdbcType=VARCHAR},'%'))
      </if>
      <if test='fzdwbm !=null and fzdwbm != ""'>
        AND FZDWBM = #{fzdwbm,jdbcType=VARCHAR}
      </if>
      <!--if条件要注意,以免误删除或者更新全部-->
      <!--此处可添加状态条件等-->
      <!--
      <if test='datastatus!=null'>
        AND DATASTATUS = #{datastatus,jdbcType=DECIMAL}
      </if>
      -->
    </where>
  </select>
  
  <!--根据实体的唯一属性查询数量-->
  <select id='selectCountById' resultType='java.lang.Integer'>
    SELECT 
    COUNT(1)
    FROM TY_XZQHB
    <where>
      <if test='qhid !=null and qhid != ""'>
        OR QHID = #{qhid,jdbcType=VARCHAR}
      </if>
    </where>
  </select>
  
  <!--根据实体的业务唯一属性(且非指定主键数据)判断是否存在-->
  <select id='selectExistsByEntity' resultType='java.lang.Integer'>
    SELECT
    COUNT(1)
    FROM TY_XZQHB
    <where>
      <if test='qhid !=null and qhid != ""'>
        AND QHID != #{qhid,jdbcType=VARCHAR}
      </if>
      <!--此处可添加状态条件等-->
      <!--
      <if test='datastatus!=null'>
        AND DATASTATUS = #{datastatus,jdbcType=DECIMAL}
      </if>
      -->
    </where>
  </select>
  
  <!--根据实体(唯一标示)查询一条数据,如id,联合主键,业务唯一标示等,多种方式均可,但要保证数据唯一
          此处只使用系统id,如有其他情况自行添加-->
  <select id='selectById' resultType='com.unis.base.common.vo.XzqhVO'>
    SELECT 
    <include refid='Column_Base_List' />
    FROM TY_XZQHB
    <where>
      <!--此处为必填条件,如不满足则不执行,以免查询全部-->
      <choose>
        <when test='qhid !=null and qhid != ""'>
          AND QHID = #{qhid,jdbcType=VARCHAR}
        </when>
        <otherwise>
          AND 1=0
        </otherwise>
      </choose>
      <!--此处可添加状态条件等-->
      <!--
      <if test='datastatus!=null'>
        AND DATASTATUS = #{datastatus,jdbcType=DECIMAL}
      </if>
      -->
    </where>
  </select>
  
  <!--根据实体的某些属性查询分页数据
          此处选取其中1-2个字段,需要根据实际情况修改-->
  <select id='selectPageByEntity' resultType='com.unis.base.common.vo.XzqhVO'>
    SELECT 
    <include refid='Column_Base_List' />
    FROM TY_XZQHB
    <where>
      <!--自定义配置的检索条件-->
      <if test='qhid !=null and qhid != ""'>
        AND QHID = #{qhid,jdbcType=VARCHAR}
      </if>
      <if test='xzqh !=null and xzqh != ""'>
        AND XZQH = #{xzqh,jdbcType=VARCHAR}
      </if>
      <if test='fzdw !=null and fzdw != ""'>
        AND FZDW LIKE CONCAT('%',CONCAT(#{fzdw,jdbcType=VARCHAR},'%'))
      </if>
      <if test='xzqhmc !=null and xzqhmc != ""'>
        AND XZQHMC LIKE CONCAT('%',CONCAT(#{xzqhmc,jdbcType=VARCHAR},'%'))
      </if>
      <if test='fzdwbm !=null and fzdwbm != ""'>
        AND FZDWBM = #{fzdwbm,jdbcType=VARCHAR}
      </if>
      <!--if条件要注意,以免误删除或者更新全部-->
      <!--此处可添加状态条件等-->
      <!--
      <if test='datastatus!=null'>
        AND DATASTATUS = #{datastatus,jdbcType=DECIMAL}
      </if>
      -->
    </where>
  </select>
  
  <!--根据实体的某些属性查询列表
          此处选取其中1-2个字段,需要根据实际情况修改-->
  <select id='selectByEntity' resultType='com.unis.base.common.vo.XzqhVO'>
    SELECT 
    <include refid='Column_Base_List' />
    FROM TY_XZQHB
    <where>
      <!--自定义配置的检索条件-->
      <if test='qhid !=null and qhid != ""'>
        AND QHID = #{qhid,jdbcType=VARCHAR}
      </if>
      <if test='xzqh !=null and xzqh != ""'>
        AND XZQH = #{xzqh,jdbcType=VARCHAR}
      </if>
      <if test='fzdw !=null and fzdw != ""'>
        AND FZDW LIKE CONCAT('%',CONCAT(#{fzdw,jdbcType=VARCHAR},'%'))
      </if>
      <if test='xzqhmc !=null and xzqhmc != ""'>
        AND XZQHMC LIKE CONCAT('%',CONCAT(#{xzqhmc,jdbcType=VARCHAR},'%'))
      </if>
      <if test='fzdwbm !=null and fzdwbm != ""'>
        AND FZDWBM = #{fzdwbm,jdbcType=VARCHAR}
      </if>
      <!--if条件要注意,以免误删除或者更新全部-->
      <!--此处可添加状态条件等-->
      <!--
      <if test='datastatus!=null'>
        AND DATASTATUS = #{datastatus,jdbcType=DECIMAL}
      </if>
      -->
    </where>
    <include refid='Order_By_Clause' />
  </select>
</mapper>