CompanyEmailHistoryMapper.xml 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.simuwang.base.mapper.CompanyEmailSendHistoryMapper">
  4. <resultMap id="BaseResultMap" type="com.simuwang.base.pojo.dos.CompanyEmailSendHistoryDO">
  5. <id column="id" property="id"/>
  6. <result column="company_id" property="companyId"/>
  7. <result column="company_name" property="companyName"/>
  8. <result column="email" property="email"/>
  9. <result column="send_status" property="sendStatus"/>
  10. <result column="send_time" property="sendTime"/>
  11. <result column="send_remark" property="sendRemark"/>
  12. <result column="isvalid" property="isvalid"/>
  13. <result column="createtime" property="createTime"/>
  14. <result column="updatetime" property="updateTime"/>
  15. <result column="creatorid" property="creatorId"/>
  16. <result column="updaterid" property="updaterId"/>
  17. </resultMap>
  18. <insert id="saveCompanyEmailSendHistory"
  19. parameterType="com.simuwang.base.pojo.dos.CompanyEmailSendHistoryDO">
  20. insert into PPW_EMAIL.company_email_send_history(company_id,email,send_status,send_time,send_remark,isvalid,createtime,updatetime,creatorid,updaterid)
  21. values (#{companyId},#{email},#{sendStatus},#{sendTime},#{sendRemark},#{isvalid},#{createTime},#{updateTime},#{creatorId},#{updaterId})
  22. </insert>
  23. <update id="deleteEmailHistory">
  24. update PPW_EMAIL.company_email_send_history set isvalid =0,updatetime=sysdate() where email in
  25. <foreach item="email" collection="emailList" open="(" separator="," close=")">
  26. #{email}
  27. </foreach>
  28. </update>
  29. <update id="deleteEmailHistoryByIds">
  30. update PPW_EMAIL.company_email_send_history set isvalid =0,updatetime=sysdate(),updaterid=#{userId} where id in
  31. <foreach item="id" collection="ids" open="(" separator="," close=")">
  32. #{id}
  33. </foreach>
  34. </update>
  35. <select id="searchCompanyEmailList" resultMap="BaseResultMap">
  36. SELECT
  37. cec.id,
  38. cec.company_id,
  39. c.company_name,
  40. cec.email,
  41. maxce.send_time as send_time,
  42. maxce.send_remark,
  43. ifnull(maxce.send_status,-1) as send_status
  44. FROM
  45. PPW_EMAIL.company_email_config cec
  46. JOIN PPW_EMAIL.pvn_company_info c
  47. ON cec.company_id = c.company_id
  48. LEFT JOIN
  49. (SELECT
  50. me.email AS email,
  51. me.send_time AS send_time,
  52. me.company_id,
  53. me.send_remark,
  54. me.send_status
  55. FROM
  56. PPW_EMAIL.company_email_send_history me
  57. join (select mx.company_id,mx.email,max(mx.send_time) as max_send_time from PPW_EMAIL.company_email_send_history mx where mx.isvalid=1
  58. GROUP BY mx.email,
  59. mx.company_id) as mx on me.email=mx.email and me.company_id=mx.company_id and me.send_time=mx.max_send_time
  60. WHERE me.isvalid = 1) maxce
  61. ON cec.email = maxce.email and cec.company_id = maxce.company_id
  62. WHERE cec.isvalid = 1 and c.isvalid=1
  63. <if test="companyName != null and companyName !=''">
  64. and (c.company_name like concat('%',#{companyName},'%') or c.company_short_name like concat('%',#{companyName},'%') or c.register_number like concat('%',#{companyName},'%'))
  65. </if>
  66. <if test="email != null and email !=''">
  67. and cec.email like concat('%',#{email},'%')
  68. </if>
  69. <if test="sendStatus != null and sendStatus != -1">
  70. and maxce.send_status=#{sendStatus}
  71. </if>
  72. <if test="sendStatus == -1">
  73. and maxce.send_status is null
  74. </if>
  75. order by
  76. CASE
  77. WHEN send_time IS NULL THEN 1
  78. ELSE 0
  79. END,
  80. send_time desc
  81. limit #{offset},#{pageSize}
  82. </select>
  83. <select id="countCompanyEmailList" resultType="java.lang.Long"
  84. parameterType="com.simuwang.base.pojo.dto.query.CompanyEmailPageQuery">
  85. SELECT
  86. count(cec.company_id)
  87. from
  88. PPW_EMAIL.company_email_config cec
  89. JOIN PPW_EMAIL.pvn_company_info c
  90. ON cec.company_id = c.company_id
  91. LEFT JOIN
  92. (SELECT
  93. me.email AS email,
  94. me.send_time AS send_time,
  95. me.company_id,
  96. me.send_remark,
  97. me.send_status
  98. FROM
  99. PPW_EMAIL.company_email_send_history me
  100. join (select mx.company_id,mx.email,max(mx.send_time) as max_send_time from PPW_EMAIL.company_email_send_history mx where mx.isvalid=1
  101. GROUP BY mx.email,
  102. mx.company_id) as mx on me.email=mx.email and me.company_id=mx.company_id and me.send_time=mx.max_send_time
  103. WHERE me.isvalid = 1) maxce
  104. ON cec.email = maxce.email and cec.company_id = maxce.company_id
  105. WHERE cec.isvalid = 1 and c.isvalid=1
  106. <if test="companyName != null and companyName !=''">
  107. and (c.company_name like concat('%',#{companyName},'%') or c.company_short_name like concat('%',#{companyName},'%') or c.register_number like concat('%',#{companyName},'%'))
  108. </if>
  109. <if test="email != null and email !=''">
  110. and cec.email like concat('%',#{email},'%')
  111. </if>
  112. <if test="sendStatus != null and sendStatus != -1">
  113. and maxce.send_status=#{sendStatus}
  114. </if>
  115. <if test="sendStatus == -1">
  116. and maxce.send_status is null
  117. </if>
  118. </select>
  119. <select id="searchEmailHistory" resultMap="BaseResultMap">
  120. SELECT distinct
  121. cesh.id,
  122. cec.company_id,
  123. c.company_name,
  124. cesh.email,
  125. cesh.send_time,
  126. cesh.send_remark,
  127. cesh.send_status
  128. FROM
  129. PPW_EMAIL.company_email_send_history cesh
  130. JOIN PPW_EMAIL.company_email_config cec
  131. ON cec.email = cesh.email
  132. JOIN PPW_EMAIL.pvn_company_info c
  133. ON cec.company_id = c.company_id
  134. WHERE cec.isvalid = 1
  135. AND cesh.isvalid = 1 and c.isvalid =1
  136. <if test="companyId != null and companyId !=''">
  137. and c.company_id=#{companyId}
  138. </if>
  139. <if test="email != null and email !=''">
  140. and cesh.email=#{email}
  141. </if>
  142. order by cesh.send_time desc
  143. limit #{offset},#{pageSize}
  144. </select>
  145. <select id="countCompanyEmailhistory" resultType="java.lang.Long"
  146. parameterType="com.simuwang.base.pojo.dto.query.CompanyEmailHistoryPageQuery">
  147. SELECT
  148. count(distinct cesh.id)
  149. FROM
  150. PPW_EMAIL.company_email_send_history cesh
  151. JOIN PPW_EMAIL.company_email_config cec
  152. ON cec.email = cesh.email
  153. JOIN PPW_EMAIL.pvn_company_info c
  154. ON cec.company_id = c.company_id
  155. WHERE cec.isvalid = 1
  156. AND cesh.isvalid = 1 and c.isvalid =1
  157. <if test="companyId != null and companyId !=''">
  158. and c.company_id=#{companyId}
  159. </if>
  160. <if test="email != null and email !=''">
  161. and cesh.email=#{email}
  162. </if>
  163. </select>
  164. </mapper>