calendar_check.go 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package roadshow
  2. import "hongze/hz_crm_api/models/roadshow"
  3. func CheckMatters(startDateTime, endDateTime string, researcherId, rsMattersId int) (matterCount int, err error) {
  4. var matterCondition string
  5. var matterPars []interface{}
  6. if rsMattersId > 0 {
  7. matterCondition += " AND rs_matters_id <> ? "
  8. matterPars = append(matterPars, rsMattersId)
  9. }
  10. matterCondition += " AND sys_user_id = ? "
  11. matterPars = append(matterPars, researcherId)
  12. matterCondition += ` AND (((? >=DATE_FORMAT(CONCAT(start_date," ",start_time),'%Y-%m-%d %H:%i:%S') AND ? <= DATE_FORMAT(CONCAT(end_date," ",end_time),'%Y-%m-%d %H:%i:%S')) OR (? >= DATE_FORMAT(CONCAT(start_date," ",start_time),'%Y-%m-%d %H:%i:%S') AND ? <= DATE_FORMAT(CONCAT(end_date," ",end_time),'%Y-%m-%d %H:%i:%S') )))`
  13. matterPars = append(matterPars, startDateTime)
  14. matterPars = append(matterPars, startDateTime)
  15. matterPars = append(matterPars, endDateTime)
  16. matterPars = append(matterPars, endDateTime)
  17. matterCount, err = roadshow.CheckMattersCount(matterCondition, matterPars)
  18. if matterCount <= 0 {
  19. var matterCondition string
  20. var matterPars []interface{}
  21. if rsMattersId > 0 {
  22. matterCondition += " AND rs_matters_id <> ? "
  23. matterPars = append(matterPars, rsMattersId)
  24. }
  25. matterCondition += " AND sys_user_id = ? "
  26. matterPars = append(matterPars, researcherId)
  27. matterCondition += ` AND ? <=DATE_FORMAT(CONCAT(start_date," ",start_time),'%Y-%m-%d %H:%i:%S')
  28. AND ? >= DATE_FORMAT(CONCAT(end_date," ",end_time),'%Y-%m-%d %H:%i:%S') `
  29. matterPars = append(matterPars, startDateTime)
  30. matterPars = append(matterPars, endDateTime)
  31. matterCount, err = roadshow.CheckMattersCount(matterCondition, matterPars)
  32. }
  33. return
  34. }
  35. func CheckCalendar(startDateTime, endDateTime, status string, researcherId, rsCalendarResearcherId int) (calendarCount int, err error) {
  36. var researcherCondition string
  37. var researcherMatterPars []interface{}
  38. if rsCalendarResearcherId > 0 {
  39. researcherCondition += " AND rs_calendar_researcher_id <> ? "
  40. researcherMatterPars = append(researcherMatterPars, rsCalendarResearcherId)
  41. }
  42. researcherCondition += " AND researcher_id = ? "
  43. researcherMatterPars = append(researcherMatterPars, researcherId)
  44. researcherCondition += " AND status IN (" + status + ") "
  45. researcherCondition += ` AND (((? >=DATE_FORMAT(CONCAT(start_date," ",start_time),'%Y-%m-%d %H:%i:%S') AND ? <= DATE_FORMAT(CONCAT(end_date," ",end_time),'%Y-%m-%d %H:%i:%S')) OR (? >= DATE_FORMAT(CONCAT(start_date," ",start_time),'%Y-%m-%d %H:%i:%S') AND ? <= DATE_FORMAT(CONCAT(end_date," ",end_time),'%Y-%m-%d %H:%i:%S') )))`
  46. researcherMatterPars = append(researcherMatterPars, startDateTime)
  47. researcherMatterPars = append(researcherMatterPars, startDateTime)
  48. researcherMatterPars = append(researcherMatterPars, endDateTime)
  49. researcherMatterPars = append(researcherMatterPars, endDateTime)
  50. calendarCount, err = roadshow.CheckCalendarResearcherCount(researcherCondition, researcherMatterPars)
  51. if calendarCount <= 0 {
  52. var researcherCondition string
  53. var researcherMatterPars []interface{}
  54. if rsCalendarResearcherId > 0 {
  55. researcherCondition += " AND rs_calendar_researcher_id <> ? "
  56. researcherMatterPars = append(researcherMatterPars, rsCalendarResearcherId)
  57. }
  58. researcherCondition += " AND researcher_id = ? "
  59. researcherMatterPars = append(researcherMatterPars, researcherId)
  60. researcherCondition += " AND status IN (" + status + ") "
  61. researcherCondition += ` AND ? <=DATE_FORMAT(CONCAT(start_date," ",start_time),'%Y-%m-%d %H:%i:%S')
  62. AND ? >= DATE_FORMAT(CONCAT(end_date," ",end_time),'%Y-%m-%d %H:%i:%S') `
  63. researcherMatterPars = append(researcherMatterPars, startDateTime)
  64. researcherMatterPars = append(researcherMatterPars, endDateTime)
  65. calendarCount, err = roadshow.CheckCalendarResearcherCount(researcherCondition, researcherMatterPars)
  66. }
  67. return
  68. }