Subversion Repositories SmartDukaan

Rev

Rev 5286 | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?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="in.shop2020.crm.persistence.AgentMapper">
  <resultMap type="agent" id="agentResult">
    <id property="id" column="id"/>
  </resultMap>

        <insert id="insertAgent" parameterType="agent" useGeneratedKeys="true" keyProperty="id">
    INSERT INTO agent
      ( name, emailId, password, managerId, is_active, is_pmCrmUser, is_allAssignable)
    VALUES
      (#{name}, #{emailId},  #{password}, #{managerId}, #{is_active}, #{is_pmCrmUser}, #{is_allAssignable})
  </insert>

        <insert id="insertAgentRole" parameterType="map">
        INSERT INTO user_roles
                (agentId, role_name)
        VALUES 
                (#{id}, #{agentRole})
        </insert>

  <select id="getAgents" parameterType="searchFilter" resultType="agent">
    SELECT *
    FROM agent a
    WHERE is_active = 1
        <if test="agentId != null">
            AND a.id = #{agentId}
        </if>
        <if test="agentEmailId != null">
            AND a.emailId = #{agentEmailId}
        </if>
  </select>
  
  <select id="getInactiveAgents" parameterType="searchFilter" resultType="agent">
    SELECT *
    FROM agent a
    WHERE is_active = 0
        <if test="agentId != null">
            AND a.id = #{agentId}
        </if>
        <if test="agentEmailId != null">
            AND a.emailId = #{agentEmailId}
        </if>
  </select>  

  <select id="getRoleNamesForAgent" parameterType="String" resultType="String">
    SELECT role_name 
    FROM user_roles a
    JOIN agent b
        ON (b.id = a.agentId)
    WHERE b.emailId = #{emailId}
  </select>

  <select id="getPermissionsForRoleName" parameterType="String" resultType="String">
    SELECT permission
    FROM roles_permissions
    WHERE role_name = #{role_name}
  </select>
  
  <update id="updatePasswordForAgent" parameterType="map">
    UPDATE agent
    SET password = #{password}
    WHERE emailId = #{emailId}
  </update>

  <select id="getLastEmailProcessedTimestamp" resultType="java.util.Date">
    SELECT lastUpdatedTimestamp from emailStatus
  </select>

  <update id="updateLastEmailProcessedTimestamp" parameterType="java.util.Date">
    UPDATE emailStatus
    SET lastUpdatedTimestamp = #{timestamp} 
  </update>
  
  <update id="changeAgentStatus" parameterType="map">
        UPDATE agent
        SET is_active = #{status}
        WHERE emailId = #{emailId}
  </update>
        
  <update id="removeAgentRoles" parameterType="long">
        DELETE FROM user_roles
        WHERE agentId = #{id}
  </update>  
  
  
</mapper>