msg_query.sql 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. select
  2. -- m.*
  3. m.id,
  4. m.created_at,
  5. m.updated_at,
  6. timestampdiff(minute,m.updated_at,now()) dif,
  7. mt.interval_time ,
  8. date_format(now(),'%H:%i') now_time,
  9. push_time
  10. from message m join message_type mt
  11. on m.sys_name=mt.sys_name and m.pasture_id=mt.pasture_id and m.service_id=mt.service_id
  12. where
  13. -- m.status=0
  14. m.id =1407
  15. and (
  16. mt.remind_type=1
  17. or
  18. (
  19. mt.remind_type=2 and
  20. timestampdiff(minute,m.created_at,now())>=mt.delay_time and
  21. (date_format(now(),'%H:%i')>=mt.push_time or mt.push_time='') and
  22. (
  23. cycle_type=1 or cycle_type=3 or
  24. (
  25. cycle_type=2 and timestampdiff(minute,m.updated_at,now()) >=mt.interval_time
  26. and m.push_count<mt.push_limit
  27. )
  28. )
  29. )
  30. or
  31. (
  32. mt.remind_type=3 and
  33. (
  34. mt.date_type=1
  35. or (mt.date_type=2 and weekday(now() ) +1 =mt.push_date)
  36. or (mt.date_type=3 and (day(now()) =mt.push_date or DAYOFMONTH(now())<mt.push_date))
  37. )
  38. and date_format(now(),'%H:%i')>=mt.push_time
  39. and
  40. (
  41. push_count=0
  42. or
  43. ( day(now())> day(mt.updated_at) and push_count>0)
  44. )
  45. )
  46. )