<?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.baseinfo.mapper.BaseShiftmasterInfoMapper">

    <resultMap type="BaseShiftmasterInfo" id="BaseShiftmasterInfoResult">
        <result property="shiftNo"    column="shift_no"    />
        <result property="deviceId"    column="device_id"    />
        <result property="shiftId"    column="shift_id"    />
        <result property="groupId"    column="group_id"    />
        <result property="startTime"    column="start_time"    />
        <result property="overTime"    column="over_time"    />
        <result property="status"    column="status"    />
        <result property="remark"    column="remark"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="deviceName"    column="device_name"    />
        <result property="shiftname"    column="shiftname"    />
        <result property="groupname"    column="groupname"    />
    </resultMap>

    <sql id="selectBaseShiftmasterInfoVo">
        select shift_no, device_id, shift_id, group_id, start_time, over_time, status, remark, create_by, create_time, update_by, update_time, del_flag from base_shiftmaster_info
    </sql>

    <select id="selectBaseShiftmasterInfoList" parameterType="BaseShiftmasterInfo" resultMap="BaseShiftmasterInfoResult">
        select t1.shift_no, t1.device_id,t2.device_name, t1.shift_id,t3.shiftname, t1.group_id,t4.groupname, t1.start_time, t1.over_time, t1.status, t1.remark, t1.create_by, t1.create_time, t1.update_by, t1.update_time, t1.del_flag from base_shiftmaster_info t1
        left join base_device_info t2 on t1.device_id = t2.device_id
        left join base_shift_info t3 on t1.shift_id = t3.shiftid
        left join base_group_info t4 on t1.group_id = t4.groupid
        <where>
            <if test="deviceId != null  and deviceId != ''"> and t1.device_id = #{deviceId}</if>
            <if test="shiftId != null  and shiftId != ''"> and t1.shift_id = #{shiftId}</if>
            <if test="groupId != null  and groupId != ''"> and t1.group_id = #{groupId}</if>
            <if test="startTime != null "> and t1.start_time = #{startTime}</if>
            <if test="overTime != null "> and t1.over_time = #{overTime}</if>
            <if test="status != null  and status != ''"> and t1.status = #{status}</if>
        </where>
    </select>

    <select id="selectBaseShiftmasterInfoById" parameterType="String" resultMap="BaseShiftmasterInfoResult">
        <include refid="selectBaseShiftmasterInfoVo"/>
        where shift_no = #{shiftNo}
    </select>

    <insert id="insertBaseShiftmasterInfo" parameterType="BaseShiftmasterInfo">
        insert into base_shiftmaster_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="shiftNo != null">shift_no,</if>
            <if test="deviceId != null">device_id,</if>
            <if test="shiftId != null">shift_id,</if>
            <if test="groupId != null">group_id,</if>
            <if test="startTime != null">start_time,</if>
            <if test="overTime != null">over_time,</if>
            <if test="status != null">status,</if>
            <if test="remark != null">remark,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="delFlag != null">del_flag,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="shiftNo != null">#{shiftNo},</if>
            <if test="deviceId != null">#{deviceId},</if>
            <if test="shiftId != null">#{shiftId},</if>
            <if test="groupId != null">#{groupId},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="overTime != null">#{overTime},</if>
            <if test="status != null">#{status},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="delFlag != null">#{delFlag},</if>
         </trim>
    </insert>

    <update id="updateBaseShiftmasterInfo" parameterType="BaseShiftmasterInfo">
        update base_shiftmaster_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="shiftId != null">shift_id = #{shiftId},</if>
            <if test="groupId != null">group_id = #{groupId},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="overTime != null">over_time = #{overTime},</if>
            <if test="status != null">status = #{status},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
        </trim>
        where shift_no = #{shiftNo}
    </update>

    <delete id="deleteBaseShiftmasterInfoById" parameterType="String">
        delete from base_shiftmaster_info where shift_no = #{shiftNo}
    </delete>

    <delete id="deleteBaseShiftmasterInfoByIds" parameterType="String">
        delete from base_shiftmaster_info where shift_no in
        <foreach item="shiftNo" collection="array" open="(" separator="," close=")">
            #{shiftNo}
        </foreach>
    </delete>

</mapper>
