<?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.xinelu.manage.mapper.operationInfo.OperationInfoMapper">

    <resultMap type="OperationInfo" id="OperationInfoResult">
        <result property="id" column="id"/>
        <result property="departmentId" column="department_id"/>
        <result property="departmentName" column="department_name"/>
        <result property="operationName" column="operation_name"/>
        <result property="operationCode" column="operation_code"/>
        <result property="operationInfo" column="operation_info"/>
        <result property="operationRemark" column="operation_remark"/>
        <result property="sort" column="sort"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectOperationInfoVo">
        select id,
               department_id,
               department_name,
               operation_name,
               operation_code,
               operation_info,
               operation_remark,
               sort,
               create_by,
               create_time,
               update_by,
               update_time
        from operation_info
    </sql>

    <select id="selectOperationInfoList" parameterType="OperationInfo" resultMap="OperationInfoResult">
        <include refid="selectOperationInfoVo"/>
        <where>
            <if test="departmentId != null ">
                and department_id =
                #{departmentId}
            </if>
            <if test="departmentName != null  and departmentName != ''">
                and department_name like concat('%',
                #{departmentName},
                '%'
                )
            </if>
            <if test="operationName != null  and operationName != ''">
                and operation_name like concat('%',
                #{operationName},
                '%'
                )
            </if>
            <if test="operationCode != null  and operationCode != ''">
                and operation_code =
                #{operationCode}
            </if>
            <if test="operationInfo != null  and operationInfo != ''">
                and operation_info =
                #{operationInfo}
            </if>
            <if test="operationRemark != null  and operationRemark != ''">
                and operation_remark =
                #{operationRemark}
            </if>
            <if test="sort != null ">
                and sort =
                #{sort}
            </if>
        </where>
        order by create_time DESC
    </select>

    <select id="selectOperationInfoById" parameterType="Long"
            resultMap="OperationInfoResult">
        <include refid="selectOperationInfoVo"/>
        where id = #{id}
    </select>

    <select id="countByDepartmentIdAndOperationName" resultType="java.lang.Integer">
        select count(*)
        from operation_info
        where department_id = #{departmentId}
          and operation_name = #{operationName}
    </select>

    <select id="countByOperationNameExcludingId" resultType="java.lang.Integer">
        select count(1)
        from operation_info
        where department_id = #{departmentId}
          and operation_name = #{operationName}
          and id != #{id}
    </select>

    <insert id="insertOperationInfo" parameterType="OperationInfo" useGeneratedKeys="true"
            keyProperty="id">
        insert into operation_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="departmentId != null">department_id,
            </if>
            <if test="departmentName != null">department_name,
            </if>
            <if test="operationName != null">operation_name,
            </if>
            <if test="operationCode != null">operation_code,
            </if>
            <if test="operationInfo != null">operation_info,
            </if>
            <if test="operationRemark != null">operation_remark,
            </if>
            <if test="sort != null">sort,
            </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>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="departmentId != null">#{departmentId},
            </if>
            <if test="departmentName != null">#{departmentName},
            </if>
            <if test="operationName != null">#{operationName},
            </if>
            <if test="operationCode != null">#{operationCode},
            </if>
            <if test="operationInfo != null">#{operationInfo},
            </if>
            <if test="operationRemark != null">#{operationRemark},
            </if>
            <if test="sort != null">#{sort},
            </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>
        </trim>
    </insert>

    <update id="updateOperationInfo" parameterType="OperationInfo">
        update operation_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="departmentId != null">department_id =
            #{departmentId},
            </if>
            <if test="departmentName != null">department_name =
            #{departmentName},
            </if>
            <if test="operationName != null">operation_name =
            #{operationName},
            </if>
            <if test="operationCode != null">operation_code =
            #{operationCode},
            </if>
            <if test="operationInfo != null">operation_info =
            #{operationInfo},
            </if>
            <if test="operationRemark != null">operation_remark =
            #{operationRemark},
            </if>
            <if test="sort != null">sort =
            #{sort},
            </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>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteOperationInfoById" parameterType="Long">
        delete
        from operation_info
        where id = #{id}
    </delete>

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