<?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.robot.RobotInformationMapper">

    <!--
        一般情况下，尽可能使用 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.robot.RobotInformationDO">
        <!--@Table robot_information-->
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="robotModelId" column="robot_model_id" jdbcType="INTEGER"/>
        <result property="robotModelNumber" column="robot_model_number" jdbcType="VARCHAR"/>
        <result property="robotNo" column="robot_no" jdbcType="VARCHAR"/>
        <result property="robotTaskModel" column="robot_task_model" jdbcType="INTEGER"/>
        <result property="macAddress" column="mac_address" jdbcType="VARCHAR"/>
        <result property="url" column="url" jdbcType="VARCHAR"/>
        <result property="robotStatus" column="robot_status" jdbcType="INTEGER"/>
<!--        <result property="floorAreaJson" column="floor_area_json" 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"/>
        <result property="taskDetailId" column="task_detail_id" jdbcType="INTEGER"/>
    </resultMap>

    <!--查询单个-->
    <sql id="base_sql" >
           id,
           robot_model_id,
           robot_model_number,
           robot_no,
           robot_task_model,
           mac_address,
           url,
           robot_status,
           creator,
           floor_area_json,
           create_time,
           updater,
           update_time,
           deleted,
           tenant_id,
           task_detail_id
    </sql>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="BaseResultMap">
        select
        <include refid="base_sql"></include>
        from robot_information
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="robotModelId != null">
                and robot_model_id = #{robotModelId}
            </if>
            <if test="robotModelNumber != null and robotModelNumber != ''">
                and robot_model_number = #{robotModelNumber}
            </if>
            <if test="robotNo != null and robotNo != ''">
                and robot_no = #{robotNo}
            </if>
            <if test="robotTaskModel != null">
                and robot_task_model = #{robotTaskModel}
            </if>
            <if test="macAddress != null and macAddress != ''">
                and mac_address = #{macAddress}
            </if>
            <if test="url != null and url != ''">
                and url = #{url}
            </if>
            <if test="robotStatus != null">
                and robot_status = #{robotStatus}
            </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="taskDetailId != null">
                and task_detail_id = #{taskDetailId}
            </if>
            <if test="1==1">
                and deleted = '0'
            </if>
        </where>
    </select>

    <!--通过实体作为筛选条件查询-->
    <select id="queryAll" resultMap="BaseResultMap">
    select
    id, robot_model_id, robot_model_number, robot_no, robot_task_model, mac_address, url, robot_status, creator,
    create_time, updater, update_time, deleted, tenant_id,task_detail_id
    from zn_wcs.robot_information
    </select>
    <!--统计总行数-->
    <select id="count" resultType="java.lang.Long">
        select count(1)
        from robot_information
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="robotModelId != null">
                and robot_model_id = #{robotModelId}
            </if>
            <if test="robotModelNumber != null and robotModelNumber != ''">
                and robot_model_number = #{robotModelNumber}
            </if>
            <if test="robotNo != null and robotNo != ''">
                and robot_no = #{robotNo}
            </if>
            <if test="robotTaskModel != null">
                and robot_task_model = #{robotTaskModel}
            </if>
            <if test="macAddress != null and macAddress != ''">
                and mac_address = #{macAddress}
            </if>
            <if test="url != null and url != ''">
                and url = #{url}
            </if>
            <if test="robotStatus != null">
                and robot_status = #{robotStatus}
            </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>

    <!--通过主键修改数据-->
    <update id="doUpdateById">
        update robot_information
        <set>
            <if test="robotModelId != null">
                robot_model_id = #{robotModelId},
            </if>
            <if test="robotModelNumber != null and robotModelNumber != ''">
                robot_model_number = #{robotModelNumber},
            </if>
            <if test="robotNo != null and robotNo != ''">
                robot_no = #{robotNo},
            </if>
            <if test="robotTaskModel != null">
                robot_task_model = #{robotTaskModel},
            </if>
            <if test="macAddress != null and macAddress != ''">
                mac_address = #{macAddress},
            </if>
            <if test="url != null and url != ''">
                url = #{url},
            </if>
            <if test="robotStatus != null">
                robot_status = #{robotStatus},
            </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>

    <update id="updateRobotStatus">
        update
            robot_information
        set
            robot_status = #{robotStatus}
        where
            robot_no = #{robotNo}
    </update>

    <update id="updateRobotTaskModel">
        update
            robot_information
        set
            robot_task_model = #{robotTaskModel}
        where
            robot_no = = #{robotNo}
    </update>


    <update id="updateRobotListStatus">
        update
            robot_information
        set
            robot_status = #{robotStatus},
            task_detail_id = #{taskDetailId}
        where
            robot_no = #{robotNo}
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        delete
        from robot_information
        where id = #{id}
    </delete>

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

    <select id="selectRobotDimensions"
            resultType="cn.iocoder.yudao.module.mqtt.api.path.dto.RobotDimensionsDTO">
        SELECT
            t1.robot_no AS robotNo,
            t2.robot_wide AS robotWide,
            t2.robot_center_headstock AS robotCenterHeadstock,
            t2.robot_center_tail AS robotCenterTail,
            t1.mac_address as macAddress
        FROM
            robot_information t1
                LEFT JOIN robot_model t2 ON t1.robot_model_id = t2.id
    </select>
    <select id="getListByMapId"
            resultType="cn.iocoder.yudao.module.system.dal.dataobject.robot.RobotInformationDO">
        select
        a.*
        from robot_information as a
        left join robot_information_map_association as b on a.id = b.robot_information_id
        <where>
            a.deleted = 0
            and b.deleted = 0
            <if test="mapId != null">
                and b.position_map_id = #{mapId}
            </if>
        </where>
    </select>
</mapper>
