<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zioinfo.mall.cs.mapper.CsMapper">
  <select id="findByOwner" resultType="com.zioinfo.mall.cs.MallCsTicket">
    SELECT * FROM mall_cs_ticket WHERE owner = #{owner} ORDER BY id DESC
  </select>
  <select id="findAll" resultType="com.zioinfo.mall.cs.MallCsTicket">
    SELECT * FROM mall_cs_ticket
    <where><if test="status != null and status != ''">status = #{status}</if></where>
    ORDER BY id DESC
  </select>
  <select id="findById" resultType="com.zioinfo.mall.cs.MallCsTicket">SELECT * FROM mall_cs_ticket WHERE id = #{id}</select>
  <insert id="insert" parameterType="com.zioinfo.mall.cs.MallCsTicket" useGeneratedKeys="true" keyProperty="id">
    INSERT INTO mall_cs_ticket (owner, order_no, category, subject, content, status)
    VALUES (#{owner}, #{orderNo}, #{category}, #{subject}, #{content}, COALESCE(#{status},'OPEN'))
  </insert>
  <update id="setSr">UPDATE mall_cs_ticket SET itsm_sr_id = #{srId} WHERE id = #{id}</update>
  <update id="setAiReply">UPDATE mall_cs_ticket SET ai_reply = #{aiReply}, status = 'ANSWERED' WHERE id = #{id}</update>
  <update id="updateStatus">UPDATE mall_cs_ticket SET status = #{status} WHERE id = #{id}</update>
</mapper>
