<?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.lz.modules.equipment.dao.OneCodeMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.lz.modules.equipment.entity.OneCode">
        <id column="id" property="id"/>
        <result column="is_delete" property="isDelete"/>
        <result column="gmt_create" property="gmtCreate"/>
        <result column="gmt_modified" property="gmtModified"/>
        <result column="code" property="code"/>
        <result column="isPrint" property="isPrint"/>
    </resultMap>


    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id AS id, is_delete AS isDelete, gmt_create AS gmtCreate, gmt_modified AS gmtModified, code AS code, isPrint AS isPrint
    </sql>




    <select id="selectOneCodeById" resultType="OneCode" >
        select * from one_code  where id=#{id} and is_delete = 0 limit 1 
    </select>


    <insert id="insertOneCode" parameterType="OneCode" useGeneratedKeys="true" keyProperty="id" >
        insert into one_code(
            <if test="code != null">code, </if>
            <if test="isPrint != null">isPrint, </if>
            is_delete,
            gmt_create,
            gmt_modified
        )values(
            <if test="code != null">#{ code}, </if>
            <if test="isPrint != null">#{ isPrint}, </if>
            0,
            now(),
            now()
        )
    </insert>


    <update id="updateOneCodeById" parameterType="OneCode" >
        update
            one_code
        <trim prefix="set" suffixOverrides=",">
            <if test="isDelete != null">is_delete = #{isDelete},</if>
            <if test="gmtCreate != null">gmt_create = #{gmtCreate},</if>
            <if test="code != null">code = #{code},</if>
            <if test="isPrint != null">isPrint = #{isPrint}</if>                
        </trim>
        ,gmt_modified = now()
        where id = #{id}
    </update>


    <update id="updateCoverOneCodeById" parameterType="OneCode" >
        update
            one_code    
        set     
            is_delete = #{isDelete},
            gmt_create = #{gmtCreate},
            code = #{code},
            isPrint = #{isPrint}                
        ,gmt_modified = now()
        where id = #{id}
    </update>


    <update id="deleteOneCodeById" parameterType="java.lang.Long">
        update one_code set is_delete = 1 where id=#{id} limit 1  
    </update>

    <insert id="insertOneCodes" parameterType="java.util.List">
        insert into one_code(
        code,
        isPrint,
        is_delete,
        gmt_create,
        gmt_modified
        )values
        <foreach collection="list" index="index" item="item"
                 separator=",">
        (
        #{item},
        0,
        0,
        now(),
        now()
        )
        </foreach>
    </insert>

    <select id="selectNoPrints" resultType="java.lang.String">
        select code from one_code  where is_delete = 0 and isPrint = 0 limit 50
    </select>

    <select id="selectByCode" resultType="OneCode" >
        select * from one_code  where code=#{code} and is_delete = 0 limit 1
    </select>

    <insert id="updatePrintOneCodes" parameterType="java.util.List">
        update
        one_code
        set isPrint = 1 where code in
        (<foreach collection="list" index="index" item="item"
                 separator=",">

            #{item}

        </foreach>)
    </insert>

    <select id="selectByCondition" resultType="OneCode" >
        select * from one_code  where is_delete = 0
        <if test="req.isPrint != null">and isPrint = #{req.isPrint}</if>
        <if test="req.code != null and req.code != ''">and code like CONCAT('%', #{req.code}, '%') </if>
        order by id desc
    </select>

</mapper>

