<?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.bbd.bpm.dao.UserInfoMapper">

    <select id="getOrganization" resultType="com.bbd.bpm.vo.BpmCompanyVo">
        SELECT
            id,
            created_time createdTime,
            update_time updateTime,
            abbreviation_name  abbreviationName,
            `code`,
            organization_relation  organizationRelation,
            name name,
            parent_id pId,
            `status`
        FROM
            bpm_company
        WHERE
            STATUS = 0 and parent_id!=0
        <if test="id!=null">
            and parent_id=#{id}
        </if>
        <if test="name!=null">
            and name LIKE CONCAT('%',#{name},'%')
        </if>
    </select>

    <!--组织架构菜单-->
    <select id="getOrganizationList" resultType="map">
        SELECT
            id,
            parent_id pId,
            NAME name,
            true open
        FROM
            bpm_company
        WHERE
            STATUS = 0
    </select>

    <select id="getParentName" resultType="com.bbd.bpm.vo.BpmCompanyVo">
        SELECT
            name
        FROM
            bpm_company
        WHERE
            id=#{pId}
    </select>

    <select id="getOrganizationRelation" resultType="String">
        SELECT
            organization_relation
        FROM
            bpm_company
        WHERE
            id = #{id}
    </select>

    <select id="getOrganizationInfo" resultType="map">
        SELECT
            `name`,
            abbreviation_name abbreviationName
        FROM
            bpm_company
        WHERE
            id = #{id}
    </select>

    <update id="deleteDepartment">
        update bpm_company set status=2 where parent_id=#{id}
    </update>

    <update id="deleteDepartments">
        update bpm_company set status=2 where id=#{id}
    </update>

    <select id="getList" resultType="com.bbd.bpm.domain.ActReModelEntity">
        SELECT
            ID_ id,
            REV_ revision,
            NAME_ AS name,
            KEY_ ,
            CATEGORY_ category,
            CREATE_TIME_ createTime,
            LAST_UPDATE_TIME_  updateTime,
            VERSION_ version,
            META_INFO_ metaInfo,
            IFNULL( DEPLOYMENT_ID_,'未部署') deploymentId,
            EDITOR_SOURCE_EXTRA_VALUE_ID_ editorSourceExtraValueId,
            EDITOR_SOURCE_VALUE_ID_ editorSourceValueId,
            TENANT_ID_ tenantId
        FROM
            act_re_model
        where 1=1
        <if test="modelName!=null">
            and NAME_ LIKE CONCAT('%',#{modelName},'%')
        </if>
    </select>

    <select id="userList" resultType="com.bbd.bpm.domain.User">
        SELECT
            id,
            user_uuid userUuid,
            username,
            email,
            telephone,
            last_time lastTime,
            content,
            DATE_FORMAT(create_time,'%Y-%m-%d %H:%i:%s') createTime
        FROM
            `user`
        where 1=1
        <if test="userName!=null">
            and username LIKE CONCAT('%',#{userName},'%')
        </if>
    </select>


    <insert id="addUser" parameterType="com.bbd.bpm.domain.User">
        INSERT INTO `user` (
            user_Uuid,
            username,
            password,
            email,
            telephone,
            content,
            create_time
        )
        VALUES
            (#{userUuid},#{username},#{password},#{email},#{telephone},#{content},now())
    </insert>

    <delete id="deleteUser" parameterType="com.bbd.bpm.domain.User">
        DELETE  FROM user where id=#{id}
    </delete>

    <select id="getUserId" parameterType="com.bbd.bpm.domain.BpmEmployee" resultType="com.bbd.bpm.domain.BpmEmployee">
        SELECT
            user_code userCode
        FROM
            bpm_employee
        where position=#{position}
        <if test="department!=null">
            and department=#{department}
        </if>
        <if test="codeId!=null">
            and code_id=#{codeId}
        </if>
    </select>

</mapper>