<?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.nantian.cloud.jljc.mapper.TStandardsRegulationsMapper">

    <!-- 可根据自己的需求，是否要使用 -->
    <resultMap type="com.nantian.cloud.jljc.entity.TStandardsRegulations" id="BaseResultMap">
        <id column="id" property="id"/>
        <result column="name" property="name"/>
        <result column="file_name" property="fileName"/>
        <result column="file_size" property="fileSize"/>
        <result column="type" property="type"/>
        <result column="tag" property="tag"/>
        <result column="file" property="file"/>
        <result column="state" property="state"/>
        <result column="publish_time" property="publishTime"/>
        <result column="execute_time" property="executeTime"/>
        <result column="remarks" property="remarks"/>
        <result column="userid" property="userid"/>
        <result column="update_time" property="updateTime"/>
        <result column="del_flag" property="delFlag"/>
        <result column="dept_id" property="deptId"/>
    </resultMap>

    <sql id="Base_Column_List">
        id, name, file_name, file_size, type, tag, file, state, publish_time, execute_time, remarks, userid, update_time, del_flag, dept_id
    </sql>

    <select id="selectall" resultType="com.nantian.cloud.jljc.entity.TStandardsRegulations">
        select <include refid="Base_Column_List"></include>
        from t_standards_regulations
        <trim prefix="where" prefixOverrides="and">
            <if test="param2.name!=null and param2.name !=''">
                and `name` like concat('%',#{param2.name},'%')
            </if>
            <if test="param2.type!=null and param2.type !=''">
                and type = #{param2.type}
            </if>
            <if test="param2.tag!=null and param2.tag !=''">
                and tag =#{param2.tag}
            </if>
            <if test="param2.state!=null and param2.state !=''">
                and state = #{param2.state}
            </if>
            and del_flag = '1'
        </trim>
    </select>

    <update id="deleteall" parameterType="com.nantian.cloud.jljc.entity.TStandardsRegulations">
        UPDATE t_standards_regulations a set a.del_flag ='4' where a.id =#{id}
    </update>

    <update id="updatefile" parameterType="com.nantian.cloud.jljc.entity.TStandardsRegulations">
        UPDATE t_standards_regulations a set
        a.update_time = #{updateTime},
        a.file_name = #{fileName},
        a.file = #{file}
         where a.id =  #{id}
    </update>

    <update id="updateall" parameterType="com.nantian.cloud.jljc.entity.TStandardsRegulations">
        UPDATE t_standards_regulations a set
        <if test="userId != null and userId != ''">
            a.userid = #{userId},
        </if>
        a.update_time = #{updateTime},
        a.type = #{type},
        a.tag = #{tag},
        a.state = #{state},
        a.remarks = #{remarks},
        a.name = #{name}
        where a.id = #{id}
    </update>

    <update id="updateByRegulations">
         update t_standards_regulations set
         name = #{name},
         file_name = #{fileName},
         file_size = #{fileSize},
         type = #{type},
         tag = #{tag},
         file = #{file},
         state = #{state},
         publish_time = #{publishTime},
         execute_time = #{executeTime},
         remarks = #{remarks},
         userid = #{userid},
         update_time = #{updateTime}
         where id = #{id}
    </update>

    <insert id="insertall" parameterType="com.nantian.cloud.jljc.entity.TStandardsRegulations">
        <selectKey resultType="java.lang.Long" order="AFTER" keyProperty="id">
            select LAST_INSERT_ID() as id
        </selectKey>
        insert INTO t_standards_regulations
        (name,remarks,state,tag,type,update_time,userid)
        VALUES (#{name},#{remarks},#{state},#{tag},#{type},#{updateTime},#{userId})
    </insert>

    <select id="selectFile" resultType="com.nantian.cloud.jljc.entity.TStandardsRegulations">
        select file_name, file from t_standards_regulations where id = #{id}
    </select>
</mapper>