<?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.foreverwin.mesnac.common.mapper.MobileWorkStationMapper">
  <resultMap id="BaseResultMap" type="com.foreverwin.mesnac.common.model.MobileWorkStationData">
    <result column="WORKSTATION_BO"  property="workStationBo" />
    <result column="CAN_CHANGE_OPERATION"  property="canChangeOperation" />
    <result column="CAN_CHANGE_RESOURCE"  property="canChangeResource" />
    <result column="DEFAULT_OPERATION_BO"  property="defaultOperationBo" />
    <result column="DEFAULT_RESOURCE_BO"  property="defaultResourceBo" />
    <result column="MAIN_INPUT_PROMPT"  property="mainInputPrompt" />
    <result column="SEQUENCE"  property="sequence" />
    <result column="BUTTON_ID"  property="buttonId" />
    <result column="BUTTON_SIZE"  property="buttonSize" />
    <result column="LABEL" property="label" />
    <result column="IMAGE_ICON"  property="imageIcon" />
    <result column="ACTIVITY_BO"  property="activityBo" />
    <result column="ACTIVITY"  property="activity" />
    <result column="CLASS_OR_PROGRAM"  property="classOrProgram" />
  </resultMap>

  <resultMap id="ActivityOptionMap" type="com.foreverwin.mesnac.common.model.ActivityOption">
    <result column="ACTIVITY"  property="activity" />
    <result column="KEY"  property="key" />
    <result column="VALUE"  property="value" />
  </resultMap>

  <select id="selectActivityOptionList" resultMap="ActivityOptionMap">
    SELECT AC.ACTIVITY, AO.EXEC_UNIT_OPTION AS KEY, SETTING AS VALUE
    FROM ACTIVITY_OPTION AO
    INNER JOIN ACTIVITY AC ON AC.HANDLE = AO.ACTIVITY_BO
    WHERE AC.HANDLE IN
      <foreach collection="activityBoList" item="item" separator="," close=")" open="(">
        #{item}
      </foreach>
  </select>

  <select id="selectMobileWorkStationList" resultMap="BaseResultMap">
    SELECT PC.WORKSTATION_BO, PC.CAN_CHANGE_OPERATION, PC.CAN_CHANGE_RESOURCE, PC.DEFAULT_OPERATION_BO, PC.DEFAULT_RESOURCE_BO, PC.MAIN_INPUT_PROMPT,
           PB.SEQUENCE, PB.BUTTON_ID, PB.BUTTON_SIZE, PB.LABEL, PB.IMAGE_ICON, PA.ACTIVITY_BO, AC.ACTIVITY, AC.CLASS_OR_PROGRAM
    FROM WORKSTATION WC
    INNER JOIN POD_CONFIG PC ON WC.HANDLE = PC.WORKSTATION_BO
    INNER JOIN POD_BUTTON PB ON PB.POD_CONFIG_BO = PC.HANDLE
    INNER JOIN POD_ACTIVITY PA ON PA.POD_BUTTON_BO = PB.HANDLE
    INNER JOIN ACTIVITY AC ON AC.HANDLE = PA.ACTIVITY_BO AND AC.ENABLED = 'true'
    INNER JOIN(
        SELECT AP.ACTIVITY_OR_GROUP_GBO AS ACTIVITY_BO
        FROM USER_GROUP_MEMBER UGM
        INNER JOIN ACTIVITY_PERM AP ON UGM.USER_GROUP_BO = AP.USER_OR_GROUP_GBO
        WHERE UGM.USER_OR_GROUP_GBO = #{userBo}
        GROUP BY AP.ACTIVITY_OR_GROUP_GBO
    )AP ON AP.ACTIVITY_BO = PA.ACTIVITY_BO
    WHERE WC.SITE = #{site}
      AND WC.WORKSTATION = #{workStation}
      AND WC.WORKSTATION_TYPE = 'C'
  </select>
</mapper>