<?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.yifu.cloud.plus.v1.yifu.process.mapper.TProcessMapper">
    <resultMap id="tProcessMap" type="com.yifu.cloud.plus.v1.yifu.process.entity.TProcess">
        <id property="id" column="ID"/>
        <result property="name" column="NAME"/>
        <result property="logoTitle" column="LOGO_TITLE"/>
        <result property="createUser" column="CREATE_USER"/>
        <result property="createDate" column="CREATE_DATE"/>
        <result property="updateUser" column="UPDATE_USER"/>
        <result property="updateDate" column="UPDATE_DATE"/>
        <result property="description" column="DESCRIPTION"/>
        <result property="deleteFlag" column="DELETE_FLAG"/>
        <result property="commonUse" column="common_use"/>
        <result property="processIsUse" column="process_is_use"/>
    </resultMap>
    <sql id="Base_Column_List">
             a.ID,
                  a.NAME,
                  a.LOGO_TITLE,
                  a.CREATE_USER,
                  a.CREATE_DATE,
                  a.UPDATE_USER,
                  a.UPDATE_DATE,
                  a.DESCRIPTION,
                  a.delete_flag,
                  a.common_use,
                  a.process_is_use
         </sql>
    <sql id="tProcess_where">
        <if test="tProcess != null">
            <if test="tProcess.id != null and tProcess.id.trim() != ''">
                AND a.ID = #{tProcess.id}
            </if>
            <if test="tProcess.name != null and tProcess.name.trim() != ''">
                AND a.NAME like CONCAT('%' , #{tProcess.name},'%')
            </if>
            <if test="tProcess.logoTitle != null and tProcess.logoTitle.trim() != ''">
                AND a.LOGO_TITLE like CONCAT('%' , #{tProcess.logoTitle},'%')
            </if>
            <if test="tProcess.createUser != null and tProcess.createUser.trim() != ''">
                AND a.CREATE_USER like CONCAT('%' , #{tProcess.createUser},'%')
            </if>
            <if test="tProcess.createDate != null">
                AND a.CREATE_DATE = #{tProcess.createDate}
            </if>
            <if test="tProcess.updateUser != null and tProcess.updateUser.trim() != ''">
                AND a.UPDATE_USER = #{tProcess.updateUser}
            </if>
            <if test="tProcess.updateDate != null">
                AND a.UPDATE_DATE = #{tProcess.updateDate}
            </if>
            <if test="tProcess.description != null and tProcess.description.trim() != ''">
                AND a.DESCRIPTION = #{tProcess.description}
            </if>
            <if test="tProcess.commonUse != null and tProcess.commonUse.trim() != ''">
                AND a.common_use = #{tProcess.commonUse}
            </if>
            <if test="tProcess.processIsUse != null and tProcess.processIsUse.trim() != ''">
                AND a.process_is_use = #{tProcess.processIsUse}
            </if>
        </if>
    </sql>
    <!--tProcess简单分页查询-->
    <select id="getTProcessPage" resultType="com.yifu.cloud.plus.v1.yifu.process.vo.TProcessViewVo">
        SELECT
        <include refid="Base_Column_List"/>
        FROM t_process a
        <where>
             delete_flag='0'
            <include refid="tProcess_where"/>
            <if test="type != null and type.trim() != ''">
                <if test="type == 0">
                  and   exists(select 1 from t_process_approval_conf where process_id=a.id  and  delete_flag='0'  )
                </if>
                <if test="type == 1">
                    and exists(select 1 from t_process_approval_conf where process_id=a.id  and  delete_flag='1'  )
                </if>
            </if>
            <if test="tProcess.processIds != null and tProcess.processIds.size() > 0">
                and a.ID IN
                <foreach collection="tProcess.processIds" item="item" index="index" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
            order by a.CREATE_DATE desc
        </where>
    </select>
</mapper>
