Subversion Repositories SmartDukaan

Rev

Rev 7636 | 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.TicketMapper">
  <resultMap type="ticket" id="ticketResult">
    <id property="id" column="id"/>
  </resultMap>

  <insert id="insertTicket" parameterType="ticket" useGeneratedKeys="true" keyProperty="id">
    INSERT INTO ticket
      (customerId, openDate, closeDate, creatorId, description, assigneeId, status,
       priority, category, productName, airwayBillNo, orderId, customerEmailId,
       customerMobileNumber, customerName)
    VALUES
      (#{customerId}, NOW(),  #{closeDate},  #{creatorId}, #{description}, #{assigneeId}, #{status},
       #{priority}, #{category}, #{productName}, #{airwayBillNo}, #{orderId}, #{customerEmailId},
       #{customerMobileNumber}, #{customerName})
  </insert>
        
  <update id="unassignAgentTickets" parameterType="int">
        UPDATE ticket
        SET assigneeId = NULL
        WHERE   assigneeId = #{assigneeId} 
                AND status != 2
                        
  </update>
  
  <update id="updateTicket" parameterType="ticket">
    UPDATE ticket
    SET
    <if test="assigneeId != null">
      assigneeId = #{assigneeId},
    </if>
    <if test="status != null">
      status = #{status},
    </if>
    <if test="priority != null">
      priority = #{priority},
    </if>
    <if test="category != null">
      category = #{category},
    </if>
    <if test="description != null">
      description = #{description},
    </if>
    <if test="customerEmailId != null">
      customerEmailId = #{customerEmailId},
    </if>
    <if test="customerName != null">
      customerName = #{customerName},
    </if>
    <if test="customerMobileNumber != null">
      customerMobileNumber = #{customerMobileNumber},
    </if>
    closeDate = #{closeDate}
    WHERE id = #{id}
  </update>

  <select id="getUnassignedTickets" resultType="ticket">
    SELECT * FROM ticket
    WHERE assigneeId IS NULL
    ORDER BY openDate DESC
  </select>

  <select id="getOpenTicketCountForAgent" parameterType="long" resultType="int">
        SELECT count(*) FROM ticket
        WHERE assigneeId = #{agentId}
                AND status != 2
  </select>
  <select id="getTickets" parameterType="searchFilter" resultType="ticket">
    SELECT *
    FROM ticket
    <where>
    <if test="ticketId != null">
        AND id = #{ticketId}
    </if>
    <if test="ticketAssigneeIds != null">
        AND assigneeId IN 
        <foreach collection="ticketAssigneeIds" item="ticketAssigneeId"
                 index="index" open="(" close=")" separator=",">
            #{ticketAssigneeId}
        </foreach>
    </if>
    <if test="customerId != null">
        AND customerId = #{customerId}
    </if>
    <if test="startTimestamp != null">
        AND openDate &gt; #{startTimestamp}
    </if>
    <if test="endTimestamp != null">
        AND openDate &lt; #{endTimestamp}
    </if>
    <if test="customerEmailId != null">
        AND customerEmailId = #{customerEmailId}
    </if>
    <if test="customerMobileNumber != null">
        AND customerMobileNumber = #{customerMobileNumber}
    </if>
    <if test="ticketStatuses != null">
        AND status IN 
        <foreach collection="ticketStatuses" item="ticketStatus"
                 index="index" open="(" close=")" separator=",">
            #{ticketStatus}
        </foreach>
    </if>
    <if test="ticketPriority != null">
        AND priority = #{ticketPriority}
    </if>
    <if test="ticketCategory != null">
        AND category = #{ticketCategory}
    </if>
    <if test="ticketCategoryList != null">
        AND category IN 
        <foreach collection="ticketCategoryList" item="tkCategory" 
                         index="index" open="(" close=")" separator=",">
                #{tkCategory}
        </foreach>
    </if>
    </where>
    ORDER BY openDate
  </select>
  
  <select id="getOpenTicketsMap" resultType="map">
        SELECT category, count(*) as count 
        FROM ticket 
        <where>
                status IN ('OPEN','REOPEN')
                AND category IS NOT NULL
        </where>
        group by category
  </select >
</mapper>