<?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.artfess.examine.dao.ExamPosSysDao">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.artfess.examine.model.ExamPosSys">
        <id column="id_" property="id" />
        <result column="sys_id_" property="sysId" />
        <result column="pos_id_" property="posId" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id_, sys_id_, pos_id_, job_id_
    </sql>
    <select id="getPositionInfo" resultType="com.artfess.examine.vo.PositionVo">
        SELECT
            sp.*,
            s.name_ AS majorName,
            sp.pos_id_ as positionId,
            op.code_ as positionCode,
            op.pos_name_ AS positionName
        FROM
            exam_pos_sys sp
            LEFT JOIN exam_equipment_sys s ON s.id_ = sp.sys_id_
            LEFT JOIN uc_org_post op ON op.id_ = sp.pos_id_
        WHERE
            sp.sys_id_ =#{id}


    </select>
    <select id="findByBindPos" resultType="com.artfess.examine.vo.PositionVo">
        SELECT 	op.pos_name_ AS positionName,  op.id_ AS positionId FROM uc_org_post op
        INNER JOIN (
        SELECT

        DISTINCT sp.pos_id_ AS positionId
        FROM
        exam_pos_sys sp
        where sp.sys_id_ in
        <foreach collection="idList" index="index" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>

        ) s on s.positionId = op.id_

    </select>
    <select id="getOrgId" resultType="java.lang.String">
        SELECT
            org_id_
        FROM
            uc_org_post
        WHERE
            id_ = #{positionId}
    </select>

    <select id="findByOrgName" resultType="java.lang.String">
          SELECT
            id_
        FROM
            uc_org
            where name_ = #{orgName}
    </select>
    <select id="getOrgCount" resultType="java.lang.Long">
        SELECT count(*) as orgCount FROM uc_org WHERE is_dele_='0'
    </select>
    <select id="getUserCount" resultType="java.lang.Long">
        SELECT count(*) as userCount FROM uc_user WHERE is_dele_='0'
    </select>
    <select id="getJlyCount" resultType="java.lang.Long">
        SELECT count(u.*) as roleCount FROM uc_user_role u
        LEFT JOIN uc_role r on u.role_id_ = r.id_
        WHERE r.code_='jly'
        and r.is_dele_='0'
    </select>
    <select id="getSysCount" resultType="java.lang.Long">
        SELECT count(*) as sysCount FROM exam_equipment_sys WHERE is_dele_='0'
    </select>
    <select id="getSubjectCount" resultType="java.lang.Long">
        SELECT count(*) as subjectCount FROM exam_subject_info WHERE is_dele_='0'
    </select>

</mapper>
