CompanyEmailHistoryMapper.xml 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 (select me.email as email,max(me.send_time) as send_time,me.company_id,me.send_remark,me.send_status from PPW_EMAIL.company_email_send_history me where isvalid =1 group by me.email,me.company_id) maxce
  49. ON cec.email = maxce.email and cec.company_id = maxce.company_id
  50. WHERE cec.isvalid = 1 and c.isvalid=1
  51. <if test="companyName != null and companyName !=''">
  52. and (c.company_name like concat('%',#{companyName},'%') or c.company_short_name like concat('%',#{companyName},'%') or c.register_number like concat('%',#{companyName},'%'))
  53. </if>
  54. <if test="email != null and email !=''">
  55. and cec.email like concat('%',#{email},'%')
  56. </if>
  57. <if test="sendStatus != null and sendStatus != -1">
  58. and maxce.send_status=#{sendStatus}
  59. </if>
  60. <if test="sendStatus == -1">
  61. and maxce.send_status is null
  62. </if>
  63. order by
  64. CASE
  65. WHEN send_time IS NULL THEN 1
  66. ELSE 0
  67. END,
  68. send_time desc
  69. limit #{offset},#{pageSize}
  70. </select>
  71. <select id="countCompanyEmailList" resultType="java.lang.Long"
  72. parameterType="com.simuwang.base.pojo.dto.query.CompanyEmailPageQuery">
  73. SELECT
  74. count(cec.company_id)
  75. from
  76. PPW_EMAIL.company_email_config cec
  77. JOIN PPW_EMAIL.pvn_company_info c
  78. ON cec.company_id = c.company_id
  79. LEFT JOIN (select me.email as email,max(me.send_time) as send_time,me.company_id,me.send_remark,me.send_status from PPW_EMAIL.company_email_send_history me where isvalid =1 group by me.email,me.company_id) maxce
  80. ON cec.email = maxce.email and cec.company_id = maxce.company_id
  81. WHERE cec.isvalid = 1 and c.isvalid=1
  82. <if test="companyName != null and companyName !=''">
  83. and (c.company_name like concat('%',#{companyName},'%') or c.company_short_name like concat('%',#{companyName},'%') or c.register_number like concat('%',#{companyName},'%'))
  84. </if>
  85. <if test="email != null and email !=''">
  86. and cec.email like concat('%',#{email},'%')
  87. </if>
  88. <if test="sendStatus != null and sendStatus != -1">
  89. and maxce.send_status=#{sendStatus}
  90. </if>
  91. <if test="sendStatus == -1">
  92. and maxce.send_status is null
  93. </if>
  94. </select>
  95. <select id="searchEmailHistory" resultMap="BaseResultMap">
  96. SELECT distinct
  97. cesh.id,
  98. cec.company_id,
  99. c.company_name,
  100. cesh.email,
  101. cesh.send_time,
  102. cesh.send_remark,
  103. cesh.send_status
  104. FROM
  105. PPW_EMAIL.company_email_send_history cesh
  106. JOIN PPW_EMAIL.company_email_config cec
  107. ON cec.email = cesh.email
  108. JOIN PPW_EMAIL.pvn_company_info c
  109. ON cec.company_id = c.company_id
  110. WHERE cec.isvalid = 1
  111. AND cesh.isvalid = 1 and c.isvalid =1
  112. <if test="companyId != null and companyId !=''">
  113. and c.company_id=#{companyId}
  114. </if>
  115. limit #{offset},#{pageSize}
  116. </select>
  117. <select id="countCompanyEmailhistory" resultType="java.lang.Long"
  118. parameterType="com.simuwang.base.pojo.dto.query.CompanyEmailHistoryPageQuery">
  119. SELECT
  120. count(distinct cesh.id)
  121. FROM
  122. PPW_EMAIL.company_email_send_history cesh
  123. JOIN PPW_EMAIL.company_email_config cec
  124. ON cec.email = cesh.email
  125. JOIN PPW_EMAIL.pvn_company_info c
  126. ON cec.company_id = c.company_id
  127. WHERE cec.isvalid = 1
  128. AND cesh.isvalid = 1 and c.isvalid =1
  129. <if test="companyId != null and companyId !=''">
  130. and c.company_id=#{companyId}
  131. </if>
  132. </select>
  133. </mapper>