<?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.cf.imes.module.system.dal.mysql.process.ProcessMapper">
    <select id="selectProcessPage" resultType="com.cf.imes.module.system.dal.dataobject.process.ProcessDO">
        select
        p.id,
        p.organ_id,
        p.name,
        p.piece_rate,
        p.piece_type,
        p.type,
        p.is_custom,
        p.is_dealer,
        p.hour_capacity,
        p.sort,
        p.unit,
        p.is_enabled,
        p.prepare_time,
        p.description,
        p.creator,
        p.create_time,
        p.updater,
        p.update_time,
        p.deleted
        from process p
        <where>
            p.deleted = 0 and p.organ_id = #{vo.organId}
            <if test="vo.userId != null and vo.userId != '' ">
                and p.id in (select process_id from process_user where user_id = #{vo.userId})
            </if>
            <if test="vo.name != null and vo.name != '' ">
                and p.name like concat('%', #{vo.name}, '%')
            </if>
            <if test="vo.isEnabled != null">
                and p.is_enabled = #{vo.isEnabled}
            </if>
            <if test="vo.type != null">
                and p.type = #{vo.type}
            </if>
            <if test="vo.pieceType != null">
                and p.piece_type = #{vo.pieceType}
            </if>
        </where>
        order by sort,id desc
    </select>

    <select id="selectOneById" resultType="com.cf.imes.module.system.dal.dataobject.process.ProcessDO">
        select
            p.id,
            p.organ_id,
            p.name,
            p.piece_rate,
            p.piece_type,
            p.type,
            p.is_custom,
            p.is_dealer,
            p.hour_capacity,
            p.sort,
            p.unit,
            p.is_enabled,
            p.prepare_time,
            p.description,
            p.creator,
            p.create_time,
            p.updater,
            p.update_time,
            p.deleted
        from process p
        where p.id = #{id} and p.organ_id = #{organId} and p.deleted = 0
    </select>


    <delete id="deleteById" parameterType="java.lang.Long">
        DELETE FROM process
        WHERE id = #{id};
    </delete>


    <select id="selectUserProcess"
            resultType="com.cf.imes.module.system.controller.admin.process.vo.processUser.ProcessAndUserRespVO">


        select distinct p.name as processName,pu.user_id as userId
        from process p
                 join process_user pu on p.id = pu.process_id
        where p.organ_id = #{organId} and p.deleted = false


    </select>




</mapper>