<?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.zcloud.modules.RyCheck.mapper.UserMapper">
    <insert id="addDept">
        insert into oa_department (DEPARTMENT_ID,
                                   NAME,
                                   PARENT_ID,
                                   CORPINFO_ID,
                                   LEVEL,
                                   DEP_ORDER,
                                   ISSUPERVISE)
        values (#{DEPARTMENT_ID},
                #{NAME},
                #{PARENT_ID},
                #{CORPINFO_ID},
                #{LEVEL},
                #{DEP_ORDER},
                #{ISSUPERVISE})
    </insert>
    <sql id="Field">
        USER_ID,
        USERNAME,
        PASSWORD,
        NAME,
        ROLE_ID,
        LAST_LOGIN,
        IP,
        STATUS,
        BZ,
        SKIN,
        EMAIL,
        NUMBER,
        PHONE,
        ROLE_IDS,
        DEPARTMENT_ID,
        POST_ID,
        ISMAIN,
        <!-- 		CORPINFO_ID, -->
        <!-- 		BASICINFO_ID, -->
        FUN_IDS,
        SORT,
        PERSON_TYPE,
        IS_HAZARDCONFIRMER,
        IS_ONLINELEARNING,
        LEARNERCATEGORY,
        USERAVATARPREFIX,
        USERAVATARURL,
        SHIFTDUTYONE,
        SHIFTDUTYTWO,
        DURATION,
        WORKSTATUS,
        WORKPERIOD,
        JCR,
        CORPINFO_ID,
        CARDNO,
        ISDELETE
    </sql>
    <sql id="FieldValue">
        #{USER_ID},
        #{USERNAME},
        #{PASSWORD},
        #{NAME},
        #{ROLE_ID},
        #{LAST_LOGIN},
        #{IP},
        #{STATUS},
        #{BZ},
        #{SKIN},
        #{EMAIL},
        #{NUMBER},
        #{PHONE},
        #{ROLE_IDS},
        #{DEPARTMENT_ID},
        #{POST_ID},
        #{ISMAIN},
        #{FUN_IDS},
        #{SORT},
        #{PERSON_TYPE},
        #{IS_HAZARDCONFIRMER},
        #{IS_ONLINELEARNING},
        #{LEARNERCATEGORY},
        #{USERAVATARPREFIX},
        #{USERAVATARURL},
        #{SHIFTDUTYONE},
        #{SHIFTDUTYTWO},
        #{DURATION},
        #{WORKSTATUS},
        #{WORKPERIOD},
        #{JCR},
        #{CORPINFO_ID},
        #{CARDNO},
        #{ISDELETE}
    </sql>

    <insert id="saveUser">
        insert into sys_user (
        <include refid="Field"></include>
        ) values (
        <include refid="FieldValue"></include>
        )
    </insert>

    <select id="getAllUserList" resultType="pd">
        SELECT u.USERNAME,
               u.USER_ID,
               u.`NAME`,
               d.DEPARTMENT_ID,
               d.`NAME` deptname
        FROM `sys_user` u
                 LEFT JOIN oa_department d on u.DEPARTMENT_ID = d.DEPARTMENT_ID
        WHERE u.ISDELETE = 0
          and u.CORPINFO_ID = '8854edee3aa94be496cee676b6d4845a'
        ORDER BY d.name desc
    </select>

    <select id="getAllUsers" resultType="pd">
        SELECT u.*
        FROM `sys_user` u
        WHERE u.CORPINFO_ID = '8854edee3aa94be496cee676b6d4845a'
    </select>

    <select id="getAllDepts" resultType="pd">
        SELECT d.*
        FROM oa_department d
        WHERE d.CORPINFO_ID = '8854edee3aa94be496cee676b6d4845a'
    </select>

    <select id="getAllDeptList" resultType="pd">
        SELECT d.DEPARTMENT_ID,
               d.`NAME` deptname
        FROM oa_department d
        WHERE d.CORPINFO_ID = '8854edee3aa94be496cee676b6d4845a'
        ORDER BY d.name desc
    </select>
</mapper>
