<?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.hzya.frame.u9c.unitgroup.dao.impl.VU9cUnitGroupDaoImpl">

    <resultMap id="get-VU9cUnitGroupEntity-result" type="com.hzya.frame.u9c.unitgroup.entity.VU9cUnitGroupEntity" >
        <result property="unitgroupcode" column="unitGroupCode" jdbcType="VARCHAR"/>
        <result property="unitgroupname" column="unitGroupName" jdbcType="VARCHAR"/>
        <result property="unitname" column="unitName" jdbcType="VARCHAR"/>
        <result property="status" column="status" jdbcType="VARCHAR"/>
        <result property="baseunit" column="baseUnit" jdbcType="VARCHAR"/>
    </resultMap>
    <!-- 查询的字段-->
    <sql id = "VU9cUnitGroupEntity_Base_Column_List">
        unitGroupCode
       ,unitGroupName 
        ,unitName 
        ,status 
        ,baseUnit 
     </sql>
 <!-- 查询 采用==查询 -->
 <select id="entity_list_base" resultMap="get-VU9cUnitGroupEntity-result" parameterType = "com.hzya.frame.u9c.unitgroup.entity.VU9cUnitGroupEntity">
    select
    <include refid="VU9cUnitGroupEntity_Base_Column_List" />
    from v_u9c_unit_group
    <trim prefix="where" prefixOverrides="and"> 
        <if test="unitgroupcode != null and unitgroupcode != ''"> and unitGroupCode = #{unitgroupcode} </if>
        <if test="unitgroupname != null and unitgroupname != ''"> and unitGroupName = #{unitgroupname} </if>
        <if test="unitname != null and unitname != ''"> and unitName = #{unitname} </if>
        <if test="status != null and status != ''"> and status = #{status} </if>
        <if test="baseunit != null and baseunit != ''"> and baseUnit = #{baseunit} </if>
        and sts='Y'
    </trim>
    <if test=" sort == ''.toString() "> order by sorts asc</if>
    <if test=" sort !='' and sort!=null and order !='' and order!=null ">order by ${sort} ${order}</if>
</select>
    
<!-- 查询符合条件的数量 -->
<select id="entity_count" resultType="Integer" parameterType = "com.hzya.frame.u9c.unitgroup.entity.VU9cUnitGroupEntity">
        select  count(1)   from v_u9c_unit_group
    <trim prefix="where" prefixOverrides="and"> 
        <if test="unitgroupcode != null and unitgroupcode != ''"> and unitGroupCode = #{unitgroupcode} </if>
        <if test="unitgroupname != null and unitgroupname != ''"> and unitGroupName = #{unitgroupname} </if>
        <if test="unitname != null and unitname != ''"> and unitName = #{unitname} </if>
        <if test="status != null and status != ''"> and status = #{status} </if>
        <if test="baseunit != null and baseunit != ''"> and baseUnit = #{baseunit} </if>
        and sts='Y'
    </trim>
    <if test=" sort ==''.toString() "> order by sorts asc</if>
	<if test=" sort !='' and sort!=null and order !='' and order!=null "> order by ${sort} ${order}</if>
    </select>

    <!-- 分页查询列表 采用like格式 -->
<select id="entity_list_like" resultMap="get-VU9cUnitGroupEntity-result" parameterType = "com.hzya.frame.u9c.unitgroup.entity.VU9cUnitGroupEntity">
    select
    <include refid="VU9cUnitGroupEntity_Base_Column_List" />
    from v_u9c_unit_group
    <trim prefix="where" prefixOverrides="and"> 
        <if test="unitgroupcode != null and unitgroupcode != ''"> and unitGroupCode like concat('%',#{unitgroupcode},'%') </if>
        <if test="unitgroupname != null and unitgroupname != ''"> and unitGroupName like concat('%',#{unitgroupname},'%') </if>
        <if test="unitname != null and unitname != ''"> and unitName like concat('%',#{unitname},'%') </if>
        <if test="status != null and status != ''"> and status like concat('%',#{status},'%') </if>
        <if test="baseunit != null and baseunit != ''"> and baseUnit like concat('%',#{baseunit},'%') </if>
        and sts='Y'
    </trim>
    <if test=" sort == ''.toString() "> order by sorts asc</if>
    <if test=" sort !='' and sort!=null and order !='' and order!=null ">order by ${sort} ${order}</if>
</select>

<!-- 查询列表 字段采用or格式 -->
<select id="VU9cUnitGroupentity_list_or" resultMap="get-VU9cUnitGroupEntity-result" parameterType = "com.hzya.frame.u9c.unitgroup.entity.VU9cUnitGroupEntity">
    select
    <include refid="VU9cUnitGroupEntity_Base_Column_List" />
    from v_u9c_unit_group
    <trim prefix="where" prefixOverrides="and"> 
        <if test="unitgroupcode != null and unitgroupcode != ''"> or unitGroupCode = #{unitgroupcode} </if>
        <if test="unitgroupname != null and unitgroupname != ''"> or unitGroupName = #{unitgroupname} </if>
        <if test="unitname != null and unitname != ''"> or unitName = #{unitname} </if>
        <if test="status != null and status != ''"> or status = #{status} </if>
        <if test="baseunit != null and baseunit != ''"> or baseUnit = #{baseunit} </if>
        and sts='Y'
    </trim>
    <if test=" sort == ''.toString() "> order by sorts asc</if>
    <if test=" sort !='' and sort!=null and order !='' and order!=null ">order by ${sort} ${order}</if>
</select>

<!--新增所有列-->
<insert id="entity_insert" parameterType = "com.hzya.frame.u9c.unitgroup.entity.VU9cUnitGroupEntity" keyProperty="" useGeneratedKeys="true">
    insert into v_u9c_unit_group(
  <trim suffix="" suffixOverrides=",">
       <if test="unitgroupcode != null and unitgroupcode != ''"> unitGroupCode , </if>
        <if test="unitgroupname != null and unitgroupname != ''"> unitGroupName , </if>
        <if test="unitname != null and unitname != ''"> unitName , </if>
        <if test="status != null and status != ''"> status , </if>
        <if test="baseunit != null and baseunit != ''"> baseUnit , </if>
    <if test="sts == null ">sts,</if>
  </trim>
  )values(
 <trim suffix="" suffixOverrides=",">
       <if test="unitgroupcode != null and unitgroupcode != ''"> #{unitgroupcode} ,</if>
        <if test="unitgroupname != null and unitgroupname != ''"> #{unitgroupname} ,</if>
        <if test="unitname != null and unitname != ''"> #{unitname} ,</if>
        <if test="status != null and status != ''"> #{status} ,</if>
        <if test="baseunit != null and baseunit != ''"> #{baseunit} ,</if>
    <if test="sts == null ">'Y',</if>
  </trim>
  )  
</insert>
<!-- 批量新增 -->
<insert id="entityInsertBatch" keyProperty="" useGeneratedKeys="true">
  insert into v_u9c_unit_group(unitGroupCode, unitGroupName, unitName, status, baseUnit,  sts) 
    values
    <foreach collection="entities" item="entity" separator=",">
    (#{entity.unitgroupcode},#{entity.unitgroupname},#{entity.unitname},#{entity.status},#{entity.baseunit}, 'Y')
    </foreach>
</insert>
<!-- 批量新增或者修改-->
<insert id="entityInsertOrUpdateBatch" keyProperty="" useGeneratedKeys="true">
    insert into v_u9c_unit_group(unitGroupCode, unitGroupName, unitName, status, baseUnit)
    values
    <foreach collection="entities" item="entity" separator=",">
    (#{entity.unitgroupcode}, #{entity.unitgroupname}, #{entity.unitname}, #{entity.status}, #{entity.baseunit})
    </foreach>
    on duplicate key update
    unitGroupCode = values(unitGroupCode),
    unitGroupName = values(unitGroupName),
    unitName = values(unitName),
    status = values(status),
    baseUnit = values(baseUnit)</insert>
<!--通过主键修改方法-->
<update id="entity_update" parameterType = "com.hzya.frame.u9c.unitgroup.entity.VU9cUnitGroupEntity" >
update v_u9c_unit_group  set
<trim suffix="" suffixOverrides=",">
    <if test="unitgroupcode != null and unitgroupcode != ''"> unitGroupCode = #{unitgroupcode},</if>
    <if test="unitgroupname != null and unitgroupname != ''"> unitGroupName = #{unitgroupname},</if>
    <if test="unitname != null and unitname != ''"> unitName = #{unitname},</if>
    <if test="status != null and status != ''"> status = #{status},</if>
    <if test="baseunit != null and baseunit != ''"> baseUnit = #{baseunit},</if>
</trim>
where  id= #{id}
</update>
<!-- 逻辑删除 -->
<update id="entity_logicDelete" parameterType = "com.hzya.frame.u9c.unitgroup.entity.VU9cUnitGroupEntity" >
update v_u9c_unit_group  set sts= 'N'
where  id= #{id}
</update>
<!-- 多条件逻辑删除 -->
<update id="entity_logicDelete_Multi_Condition" parameterType = "com.hzya.frame.u9c.unitgroup.entity.VU9cUnitGroupEntity" >
update v_u9c_unit_group  set sts= 'N' 
 <trim prefix="where" prefixOverrides="and"> 
        <if test="unitgroupcode != null and unitgroupcode != ''"> or unitGroupCode = #{unitgroupcode} </if>
        <if test="unitgroupname != null and unitgroupname != ''"> or unitGroupName = #{unitgroupname} </if>
        <if test="unitname != null and unitname != ''"> or unitName = #{unitname} </if>
        <if test="status != null and status != ''"> or status = #{status} </if>
        <if test="baseunit != null and baseunit != ''"> or baseUnit = #{baseunit} </if>
        and sts='Y'
    </trim>
</update>
<!--通过主键删除-->
<delete id="deleteById">
    delete from v_u9c_unit_group where  id= #{id}
</delete>

</mapper>

