<?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.ssm.manage.dao.BaseWorkTypeDao">

    <resultMap type="com.ssm.manage.entity.BaseWorkType" id="BaseWorkTypeMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="storeId" column="store_id" jdbcType="INTEGER"/>
        <result property="storeName" column="store_name" jdbcType="VARCHAR"/>
        <result property="storeNum" column="store_num" jdbcType="VARCHAR"/>
        <result property="state" column="state" jdbcType="INTEGER"/>
        <result property="wordTypeNum" column="word_type_num" jdbcType="VARCHAR"/>
        <result property="wordTypeName" column="word_type_name" jdbcType="VARCHAR"/>
    </resultMap>

    <!--查询单个-->
    <select id="queryById" resultMap="BaseWorkTypeMap">
        select
          id, store_id, store_name, store_num, state, word_type_num, word_type_name
        from base_work_type
        where id = #{id}
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="BaseWorkTypeMap">
        select
          id, store_id, store_name, store_num, state, word_type_num, word_type_name
        from base_work_type
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="storeId != null">
                and store_id = #{storeId}
            </if>
            <if test="storeName != null and storeName != ''">
                and store_name = #{storeName}
            </if>
            <if test="storeNum != null and storeNum != ''">
                and store_num = #{storeNum}
            </if>
            <if test="state != null">
                and state = #{state}
            </if>
            <if test="wordTypeNum != null and wordTypeNum != ''">
                and word_type_num = #{wordTypeNum}
            </if>
            <if test="wordTypeName != null and wordTypeName != ''">
                and word_type_name = #{wordTypeName}
            </if>
        </where>
        limit #{pageable.offset}, #{pageable.pageSize}
    </select>

    <!--统计总行数-->
    <select id="count" resultType="java.lang.Long">
        select count(1)
        from base_work_type
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="storeId != null">
                and store_id = #{storeId}
            </if>
            <if test="storeName != null and storeName != ''">
                and store_name = #{storeName}
            </if>
            <if test="storeNum != null and storeNum != ''">
                and store_num = #{storeNum}
            </if>
            <if test="state != null">
                and state = #{state}
            </if>
            <if test="wordTypeNum != null and wordTypeNum != ''">
                and word_type_num = #{wordTypeNum}
            </if>
            <if test="wordTypeName != null and wordTypeName != ''">
                and word_type_name = #{wordTypeName}
            </if>
        </where>
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into base_work_type(store_id, store_name, store_num, state, word_type_num, word_type_name)
        values (#{storeId}, #{storeName}, #{storeNum}, #{state}, #{wordTypeNum}, #{wordTypeName})
    </insert>

    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into base_work_type(store_id, store_name, store_num, state, word_type_num, word_type_name)
        values
        <foreach collection="entities" item="entity" separator=",">
        (#{entity.storeId}, #{entity.storeName}, #{entity.storeNum}, #{entity.state}, #{entity.wordTypeNum}, #{entity.wordTypeName})
        </foreach>
    </insert>

    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into base_work_type(store_id, store_name, store_num, state, word_type_num, word_type_name)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.storeId}, #{entity.storeName}, #{entity.storeNum}, #{entity.state}, #{entity.wordTypeNum}, #{entity.wordTypeName})
        </foreach>
        on duplicate key update
        store_id = values(store_id),
        store_name = values(store_name),
        store_num = values(store_num),
        state = values(state),
        word_type_num = values(word_type_num),
        word_type_name = values(word_type_name)
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update base_work_type
        <set>
            <if test="storeId != null">
                store_id = #{storeId},
            </if>
            <if test="storeName != null and storeName != ''">
                store_name = #{storeName},
            </if>
            <if test="storeNum != null and storeNum != ''">
                store_num = #{storeNum},
            </if>
            <if test="state != null">
                state = #{state},
            </if>
            <if test="wordTypeNum != null and wordTypeNum != ''">
                word_type_num = #{wordTypeNum},
            </if>
            <if test="wordTypeName != null and wordTypeName != ''">
                word_type_name = #{wordTypeName},
            </if>
        </set>
        where id = #{id}
    </update>

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

</mapper>

