<?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.bonus.canteen.core.account.mapper.AccOperationHistoryMapper">
    <select id="queryPageAccOperationRecord" resultType="com.bonus.canteen.core.account.domain.bo.AccOperationHistory">
        SELECT aop.id,
               aop.user_id,
               su.nick_name as userName,
               su.phonenumber as phone,
               sd.dept_name,
               aop.type,
               aop.create_by,
               aop.create_time
        FROM acc_operation_history aop
        LEFT JOIN sys_user su ON aop.user_id = su.user_id
        LEFT JOIN sys_dept sd on sd.dept_id = su.dept_id
        <where>
            <if test="param.startDateTime != null">
                and aop.create_time  <![CDATA[ >= ]]> #{param.startDateTime}
            </if>
            <if test="param.endDateTime != null">
                and aop.create_time  <![CDATA[ <= ]]> #{param.endDateTime}
            </if>
            <if test="param.type != null">
                and aop.type = #{param.type}
            </if>
            <if test="param.deptIds != null and param.deptIds.size() > 0">
                and su.dept_id IN
                <foreach collection="param.deptIds" item="deptId" separator="," open="(" close=")">
                    #{deptId}
                </foreach>
            </if>
            <if test="param.createBy != null and param.createBy != ''">
                and aop.create_by like #{param.createBy}
            </if>
            <if test="param.searchValue != null and param.searchValue != '' ">
                and (su.nick_name = #{param.searchValue}
                or su.phonenumber = #{encryptedSearchValue}
                )
            </if>
        </where>
        ORDER BY `id` DESC
    </select>
</mapper>
