<?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.ruoyi.platform.mapper.ComputingResourceDao">

    <resultMap type="com.ruoyi.platform.domain.ComputingResource" id="ComputingResourceMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="computingResource" column="computing_resource" jdbcType="VARCHAR"/>
        <result property="standard" column="standard" jdbcType="VARCHAR"/>
        <result property="description" column="description" jdbcType="VARCHAR"/>
        <result property="createBy" column="create_by" jdbcType="VARCHAR"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="updateBy" column="update_by" jdbcType="VARCHAR"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
        <result property="state" column="state" jdbcType="INTEGER"/>
    </resultMap>

    <!--查询单个-->
    <select id="queryById" resultMap="ComputingResourceMap">
        select
        id,computing_resource,standard,description,create_by,create_time,update_by,update_time,state
        from computing_resource
        where id = #{id} and state = 1
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="ComputingResourceMap">
        select
        id,computing_resource,standard,description,create_by,create_time,update_by,update_time,state
        from computing_resource
        <where>
            state = 1
            <if test="computingResource.id != null">
                and id = #{computingResource.id}
            </if>
            <if test="computingResource.computingResource != null and computingResource.computingResource != ''">
                and computing_resource = #{computingResource.computingResource}
            </if>
            <if test="computingResource.standard != null and computingResource.standard != ''">
                and standard = #{computingResource.standard}
            </if>
            <if test="computingResource.description != null and computingResource.description != ''">
                and description = #{computingResource.description}
            </if>
            <if test="computingResource.createBy != null and computingResource.createBy != ''">
                and create_by = #{computingResource.createBy}
            </if>
            <if test="computingResource.createTime != null">
                and create_time = #{computingResource.createTime}
            </if>
            <if test="computingResource.updateBy != null and computingResource.updateBy != ''">
                and update_by = #{computingResource.updateBy}
            </if>
            <if test="computingResource.updateTime != null">
                and update_time = #{computingResource.updateTime}
            </if>
            <if test="computingResource.state != null">
                and state = #{computingResource.state}
            </if>
        </where>
        limit #{pageable.offset}, #{pageable.pageSize}
    </select>

    <!--统计总行数-->
    <select id="count" resultType="java.lang.Long">
        select count(1)
        from computing_resource
        <where>
            state = 1
            <if test="computingResource.id != null">
                and id = #{computingResource.id}
            </if>
            <if test="computingResource.computingResource != null and computingResource.computingResource != ''">
                and computing_resource = #{computingResource.computingResource}
            </if>
            <if test="computingResource.standard != null and computingResource.standard != ''">
                and standard = #{computingResource.computingResource}
            </if>
            <if test="computingResource.description != null and computingResource.description != ''">
                and description = #{computingResource.description}
            </if>
            <if test="computingResource.createBy != null and computingResource.createBy != ''">
                and create_by = #{computingResource.createBy}
            </if>
            <if test="computingResource.createTime != null">
                and create_time = #{computingResource.createTime}
            </if>
            <if test="computingResource.updateBy != null and computingResource.updateBy != ''">
                and update_by = #{computingResource.updateBy}
            </if>
            <if test="computingResource.updateTime != null">
                and update_time = #{computingResource.updateTime}
            </if>
            <if test="computingResource.state != null">
                and state = #{computingResource.state}
            </if>
        </where>
    </select>

    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into computing_resource (computing_resource, standard, description, create_by, create_time, update_by, update_time, state)
        values (#{computingResource.computingResource}, #{computingResource.standard}, #{computingResource.description}, #{computingResource.createBy}, #{computingResource.createTime}, #{computingResource.updateBy}, #{computingResource.updateTime}, #{computingResource.state})
    </insert>


    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into computing_resource(computing_resource,standard,description,create_by,create_time,update_by,update_time,state)
        values
        <foreach collection="entities" item="entity" separator=",">
        (#{entity.computingResource},#{entity.standard},#{entity.description},#{entity.createBy},#{entity.createTime},#{entity.updateBy},#{entity.updateTime},#{entity.state})
        </foreach>
    </insert>

    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into computing_resource(computing_resourcestandarddescriptioncreate_bycreate_timeupdate_byupdate_timestate)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.computingResource}#{entity.standard}#{entity.description}#{entity.createBy}#{entity.createTime}#{entity.updateBy}#{entity.updateTime}#{entity.state})
        </foreach>
        on duplicate key update
computing_resource = values(computing_resource)standard = values(standard)description = values(description)create_by = values(create_by)create_time = values(create_time)update_by = values(update_by)update_time = values(update_time)state = values(state)
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update computing_resource
        <set>
            <if test="computingResource.id != null">
                and id = #{computingResource.id}
            </if>
            <if test="computingResource.computingResource != null and computingResource.computingResource != ''">
                and computing_resource = #{computingResource.computingResource}
            </if>
            <if test="computingResource.standard != null and computingResource.standard != ''">
                and standard = #{computingResource.standard}
            </if>
            <if test="computingResource.description != null and computingResource.description != ''">
                and description = #{computingResource.description}
            </if>
            <if test="computingResource.createBy != null and computingResource.createBy != ''">
                and create_by = #{computingResource.createBy}
            </if>
            <if test="computingResource.createTime != null">
                and create_time = #{computingResource.createTime}
            </if>
            <if test="computingResource.updateBy != null and computingResource.updateBy != ''">
                and update_by = #{computingResource.updateBy}
            </if>
            <if test="computingResource.updateTime != null">
                and update_time = #{computingResource.updateTime}
            </if>
            <if test="computingResource.state != null">
                and state = #{computingResource.state}
            </if>
        </set>

        where id = #{computingResource.id}
    </update>

    <update id="updateUsedStateByNode">
        update computing_resource set used_state  = #{usedState} where node = #{node}
    </update>

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

</mapper>

