<?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.iocoder.yudao.module.system.dal.mysql.positionmap.PositionMapMapper">

    <!--
        一般情况下，尽可能使用 Mapper 进行 CRUD 增删改查即可。
        无法满足的场景，例如说多表关联查询，才使用 XML 编写 SQL。
        代码生成器暂时只生成 Mapper XML 文件本身，更多推荐 MybatisX 快速开发插件来生成查询。
        文档可见：https://www.iocoder.cn/MyBatis/x-plugins/
     -->

    <resultMap id="BaseResultMap" type="cn.iocoder.yudao.module.system.dal.dataobject.positionmap.PositionMapDO">
        <!--@Table ware_position_map-->
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="floor" column="floor" jdbcType="INTEGER"/>
        <result property="area" column="area" jdbcType="VARCHAR"/>
        <result property="yamlJson" column="yaml_json" jdbcType="VARCHAR"/>
        <result property="pngUrl" column="png_url" jdbcType="VARCHAR"/>
        <result property="yamlUrl" column="yaml_url" jdbcType="VARCHAR"/>
        <result property="creator" column="creator" jdbcType="VARCHAR"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="updater" column="updater" jdbcType="VARCHAR"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
        <result property="deleted" column="deleted" jdbcType="INTEGER"/>
    </resultMap>

    <!--查询单个-->
    <sql id="base_sql" >
               id,
               floor,
               area,
               yaml_json,
               png_url,
               yaml_url,
               creator,
               create_time,
               updater,
               update_time,
               deleted,
               tenant_id
    </sql>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="BaseResultMap">
        select
        id, floor, area, yml_json, png_url,yaml_url, creator, create_time, updater, update_time, deleted, tenant_id
        from ware_position_map
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="floor != null">
                and floor = #{floor}
            </if>
            <if test="area != null and area != ''">
                and area = #{area}
            </if>
            <if test="ymlJson != null and ymlJson != ''">
                and yml_json = #{ymlJson}
            </if>
            <if test="pngUrl != null and pngUrl != ''">
                and png_url = #{pngUrl}
            </if>
            <if test="yamlUrl != null and yamlUrl != ''">
                and yaml_url = #{yamlUrl}
            </if>
            <if test="creator != null and creator != ''">
                and creator = #{creator}
            </if>
            <if test="createTime != null">
                and create_time = #{createTime}
            </if>
            <if test="updater != null and updater != ''">
                and updater = #{updater}
            </if>
            <if test="updateTime != null">
                and update_time = #{updateTime}
            </if>
            <if test="deleted != null">
                and deleted = #{deleted}
            </if>
            <if test="tenantId != null">
                and tenant_id = #{tenantId}
            </if>
        </where>
        limit #{pageable.offset}, #{pageable.pageSize}
    </select>

    <!--通过实体作为筛选条件查询-->
    <select id="queryAll" resultMap="BaseResultMap">
    select
    id, floor, area, yml_json, url, creator, create_time, updater, update_time, deleted, tenant_id
    from ware_position_map
    </select>
    <!--统计总行数-->
    <select id="count" resultType="java.lang.Long">
        select count(1)
        from ware_position_map
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="floor != null">
                and floor = #{floor}
            </if>
            <if test="area != null and area != ''">
                and area = #{area}
            </if>
            <if test="ymlJson != null and ymlJson != ''">
                and yml_json = #{ymlJson}
            </if>
            <if test="pngUrl != null and pngUrl != ''">
                and png_url = #{pngUrl}
            </if>
            <if test="yamlUrl != null and yamlUrl != ''">
                and yaml_url = #{yamlUrl}
            </if>
            <if test="creator != null and creator != ''">
                and creator = #{creator}
            </if>
            <if test="createTime != null">
                and create_time = #{createTime}
            </if>
            <if test="updater != null and updater != ''">
                and updater = #{updater}
            </if>
            <if test="updateTime != null">
                and update_time = #{updateTime}
            </if>
            <if test="deleted != null">
                and deleted = #{deleted}
            </if>
            <if test="tenantId != null">
                and tenant_id = #{tenantId}
            </if>
        </where>
    </select>

    <select id="selectByIds" resultMap="BaseResultMap">
        select
            <include refid="base_sql"></include>
        from
            ware_position_map
        where deleted = '0'
        and id in
        <foreach collection="ids" item="id" index="index" open="(" close=")"
                 separator=",">
            #{id}
        </foreach>
    </select>

    <!--新增所有列-->
    <insert id="insertEntity" keyProperty="id" useGeneratedKeys="true">
        insert into ware_position_map(floor, area, yml_json, png_url, yaml_url,creator, create_time, updater, update_time, deleted,
                                      tenant_id)
        values (#{floor}, #{area}, #{ymlJson}, #{pngUrl},#{yamlUrl}, #{creator}, #{createTime}, #{updater}, #{updateTime}, #{deleted},
                #{tenantId})
    </insert>

    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into ware_position_map(floor, area, yml_json, png_url,yaml_url, creator, create_time, updater, update_time, deleted,
        tenant_id)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.floor}, #{entity.area}, #{entity.ymlJson}, #{entity.pngUrl},#{entity.yamlUrl}, #{entity.creator}, #{entity.createTime},
            #{entity.updater}, #{entity.updateTime}, #{entity.deleted}, #{entity.tenantId})
        </foreach>
    </insert>

    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into ware_position_map(floor, area, yml_json, png_url,yaml_url, creator, create_time, updater, update_time, deleted,
        tenant_id)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.floor}, #{entity.area}, #{entity.ymlJson}, #{entity.pngUrl},  #{entity.yamlUrl},#{entity.creator}, #{entity.createTime},
            #{entity.updater}, #{entity.updateTime}, #{entity.deleted}, #{entity.tenantId})
        </foreach>
        on duplicate key update
        floor = values(floor),
        area = values(area),
        yml_json = values(yml_json),
        png_url = values(png_url),
        yaml_url = values(yaml_url),
        creator = values(creator),
        create_time = values(create_time),
        updater = values(updater),
        update_time = values(update_time),
        deleted = values(deleted),
        tenant_id = values(tenant_id)
    </insert>

    <!--通过主键修改数据-->
    <update id="updateBySelect">
        update ware_position_map
        <set>
            <if test="floor != null">
                floor = #{floor},
            </if>
            <if test="area != null and area != ''">
                area = #{area},
            </if>
            <if test="ymlJson != null and ymlJson != ''">
                yml_json = #{ymlJson},
            </if>
            <if test="pngUrl != null and pngUrl != ''">
                and png_url = #{pngUrl}
            </if>
            <if test="yamlUrl != null and yamlUrl != ''">
                and yaml_url = #{yamlUrl}
            </if>
            <if test="creator != null and creator != ''">
                creator = #{creator},
            </if>
            <if test="createTime != null">
                create_time = #{createTime},
            </if>
            <if test="updater != null and updater != ''">
                updater = #{updater},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime},
            </if>
            <if test="deleted != null">
                deleted = #{deleted},
            </if>
            <if test="tenantId != null">
                tenant_id = #{tenantId},
            </if>
        </set>
        where id = #{id}
    </update>

</mapper>