<?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.plant.mapper.TCanteenCardMapper">
    
    <resultMap type="TCanteenCard" id="TCanteenCardResult">
        <result property="cardId"    column="card_id"    />
        <result property="userId"    column="user_id"    />
        <result property="cardNo"    column="card_no"    />
        <result property="cardStatus"    column="card_status"    />
        <result property="status"    column="status"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createrCode"    column="creater_code"    />
        <result property="createdate"    column="createdate"    />
        <result property="updaterCode"    column="updater_code"    />
        <result property="updatedate"    column="updatedate"    />
        <result property="deptId"    column="dept_id"    />
        <result property="remarks"    column="remarks"    />
    </resultMap>

    <sql id="selectTCanteenCardVo">
        select card_id, user_id, card_no, card_status, status, del_flag, creater_code, createdate, updater_code, updatedate, dept_id, remarks from t_canteen_card
    </sql>

    <select id="selectTCanteenCardList" parameterType="TCanteenCard" resultMap="TCanteenCardResult">
        <include refid="selectTCanteenCardVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="cardNo != null  and cardNo != ''"> and card_no = #{cardNo}</if>
            <if test="cardStatus != null  and cardStatus != ''"> and card_status = #{cardStatus}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="createrCode != null "> and creater_code = #{createrCode}</if>
            <if test="createdate != null "> and createdate = #{createdate}</if>
            <if test="updaterCode != null "> and updater_code = #{updaterCode}</if>
            <if test="updatedate != null "> and updatedate = #{updatedate}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
        </where>
    </select>
    
    <select id="selectTCanteenCardByCardId" parameterType="Long" resultMap="TCanteenCardResult">
        <include refid="selectTCanteenCardVo"/>
        where card_id = #{cardId}
    </select>

    <insert id="insertTCanteenCard" parameterType="TCanteenCard" useGeneratedKeys="true" keyProperty="cardId">
        insert into t_canteen_card
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="cardNo != null">card_no,</if>
            <if test="cardStatus != null">card_status,</if>
            <if test="status != null">status,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createrCode != null">creater_code,</if>
            <if test="createdate != null">createdate,</if>
            <if test="updaterCode != null">updater_code,</if>
            <if test="updatedate != null">updatedate,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="remarks != null">remarks,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="cardNo != null">#{cardNo},</if>
            <if test="cardStatus != null">#{cardStatus},</if>
            <if test="status != null">#{status},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createrCode != null">#{createrCode},</if>
            <if test="createdate != null">#{createdate},</if>
            <if test="updaterCode != null">#{updaterCode},</if>
            <if test="updatedate != null">#{updatedate},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="remarks != null">#{remarks},</if>
         </trim>
    </insert>

    <update id="updateTCanteenCard" parameterType="TCanteenCard">
        update t_canteen_card
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="cardNo != null">card_no = #{cardNo},</if>
            <if test="cardStatus != null">card_status = #{cardStatus},</if>
            <if test="status != null">status = #{status},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createrCode != null">creater_code = #{createrCode},</if>
            <if test="createdate != null">createdate = #{createdate},</if>
            <if test="updaterCode != null">updater_code = #{updaterCode},</if>
            <if test="updatedate != null">updatedate = #{updatedate},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
        </trim>
        where card_id = #{cardId}
    </update>

    <delete id="deleteTCanteenCardByCardId" parameterType="Long">
        delete from t_canteen_card where card_id = #{cardId}
    </delete>

    <delete id="deleteTCanteenCardByCardIds" parameterType="String">
        delete from t_canteen_card where card_id in 
        <foreach item="cardId" collection="array" open="(" separator="," close=")">
            #{cardId}
        </foreach>
    </delete>
</mapper>