<?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.sckw.mine.mapper.MineralAggregateMapper">

    <sql id="Base_Column_List">
        id,
                tenant_id,
                `code`,
                `name`,
                type,
                unit,
                size,
                weight,
                `status`,
                `value`,
                create_by,
                update_by,
                create_time,
                update_time,
                del_flag
    </sql>

    <update id="aggreDelete">
        update kw_business_mineral_aggregate set del_flag = 1 where id = #{id}
    </update>

    <select id="mineAggregatePageList"
            resultType="com.sckw.mine.entity.res.MineralAggregateListRes">
        select <include refid="Base_Column_List" /> from kw_business_mineral_aggregate
        <where>
            del_flag = 0
            <if test="param.name != '' and param.name != null">
                and `name` like concat('%',#{param.name},'%')
            </if>
            <if test="param.code != '' and param.code != null">
                and `code` like concat('%',#{param.code},'%')
            </if>
            <if test="param.tenantId != '' and param.tenantId != null">
                and tenant_id = #{param.tenantId}
            </if>
            <if test="param.status != null">
                and `status` = #{param.status}
            </if>
            <if test="param.startTime != '' and param.startTime != null">
                and o.create_time  >=  #{param.startTime}
            </if>
            <if test="param.endTime != '' and param.endTime != null">
                and o.create_time  &lt; #{param.endTime}
            </if>
        </where>
        order by create_time desc
    </select>
    <select id="load" resultType="com.sckw.mine.entity.res.KwBusinessMineralAggregateDetailRes">
        select <include refid="Base_Column_List" /> from kw_business_mineral_aggregate where id = #{id}
    </select>


    <update id="aggreUpdate" parameterType="com.sckw.mine.entity.req.MineralAggregateUpdateParam">
        UPDATE kw_business_mineral_aggregate
        <set>
            <trim suffixOverrides=",">
                <if test="null != param.name and '' != param.name">`name` = #{param.name},</if>
                <if test="null != param.type">type = #{param.type},</if>
                <if test="null != param.unit">unit = #{param.unit},</if>
                <if test="null != param.size and '' != param.size">size = #{param.size},</if>
                <if test="null != param.weight">weight = #{param.weight},</if>
                <if test="null != param.status">`status` = #{param.status}</if>
                <if test="null != param.value and '' != param.value">`value` = #{param.value}</if>
            </trim>
        </set>
        WHERE id = #{param.id}
    </update>

</mapper>