business_calendar.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. package business_trip
  2. import (
  3. "fmt"
  4. "hongze/hongze_mobile_admin/models/tables/business_trip"
  5. "hongze/hongze_mobile_admin/utils"
  6. "time"
  7. )
  8. // ResearcherReportList
  9. // @Title 出差日历表
  10. // @Description 出差日历表接口
  11. // @Param AdminId query int true "用户id"
  12. // @Success 200 {object} roadshow.BusinessTripResp
  13. // @router /calendar [get]
  14. func (this *BusinessTrip) BusinessTripCalendar() {
  15. //sysUser := this.AdminWx
  16. //sysUserId := sysUser.AdminId
  17. adminId, _ := this.GetInt("AdminId")
  18. groupList := make([]*business_trip.BusinessTripCalendarGroup, 0)
  19. researcherGroup := new(business_trip.BusinessTripCalendarGroup)
  20. researcherGroup.GroupId = 1
  21. researcherGroup.GroupName = "研究员"
  22. researcherGroup.DepartmentId = "1"
  23. groupList = append(groupList, researcherGroup)
  24. sellerGroup := new(business_trip.BusinessTripCalendarGroup)
  25. sellerGroup.GroupId = 2
  26. sellerGroup.GroupName = "销售"
  27. if utils.RunMode == "debug" {
  28. sellerGroup.DepartmentId = "2,5"
  29. } else {
  30. sellerGroup.DepartmentId = "2,4,5,9"
  31. }
  32. groupList = append(groupList, sellerGroup)
  33. otherGroup := new(business_trip.BusinessTripCalendarGroup)
  34. otherGroup.GroupId = 3
  35. otherGroup.GroupName = "其他"
  36. if utils.RunMode == "debug" {
  37. otherGroup.DepartmentId = "3,7"
  38. } else {
  39. otherGroup.DepartmentId = "3,6,7,8"
  40. }
  41. groupList = append(groupList, otherGroup)
  42. groupLen := len(groupList)
  43. fmt.Println("groupLen:", groupLen)
  44. //获取当天周日期
  45. nowWeekStart := utils.GetNowWeekMonday().AddDate(0, 0, -2)
  46. //nowWeekEnd := utils.GetNowWeekLastDay()
  47. //获取下周日期
  48. nextWeekStart := utils.GetNextWeekMonday().AddDate(0, 0, -2)
  49. nextWeekEnd := utils.GetNextWeekLastDay().AddDate(0, 0, -2)
  50. //获取出差信息
  51. businessTripList, err := business_trip.GetBusinessTripList(adminId, nowWeekStart.Format(utils.FormatDate), nextWeekEnd.Format(utils.FormatDate))
  52. if err != nil {
  53. this.FailWithMessage("获取信息失败!", "获取路演信息失败!,GetBusinessTripList Err:"+err.Error())
  54. return
  55. }
  56. btMap := make(map[int][]*business_trip.BusinessApplyView)
  57. for _, v := range businessTripList {
  58. if findVals, ok := btMap[v.ApplyAdminId]; ok {
  59. findVals = append(findVals, v)
  60. btMap[v.ApplyAdminId] = findVals
  61. } else {
  62. items := make([]*business_trip.BusinessApplyView, 0)
  63. items = append(items, v)
  64. btMap[v.ApplyAdminId] = items
  65. }
  66. }
  67. for i := 0; i < groupLen; i++ {
  68. group := groupList[i]
  69. fmt.Println("group:", group.DepartmentId)
  70. adminList, err := business_trip.GetBusinessTripCalendar(group.DepartmentId)
  71. if err != nil {
  72. this.FailWithMessage("获取信息失败!", "获取分组信息失败!,GetBusinessTripCalendar Err:"+err.Error())
  73. return
  74. }
  75. setAdminList := make([]*business_trip.BusinessTripCalendarAdmin, 0)
  76. for _, v := range adminList {
  77. if findTripList, ok := btMap[v.AdminId]; ok {
  78. tripList := make([]*business_trip.BusinessTripCalendar, 0)
  79. for i := 0; i < 7; i++ {
  80. newDay, _ := time.ParseInLocation(utils.FormatDate, nowWeekStart.AddDate(0, 0, i).Format(utils.FormatDate), time.Local)
  81. weekDate := newDay.Format(utils.FormatDate)
  82. tripItem := new(business_trip.BusinessTripCalendar)
  83. for _, r := range findTripList {
  84. startDateT, _ := time.ParseInLocation(utils.FormatDate, r.ArriveDate, time.Local)
  85. endDateT, _ := time.ParseInLocation(utils.FormatDate, r.ReturnDate, time.Local)
  86. if r != nil && (newDay.Equal(startDateT) || (newDay.Equal(endDateT)) || (newDay.Before(endDateT) && newDay.After(startDateT))) {
  87. tripItem.City = r.City
  88. tripItem.BusinessApplyId = r.BusinessApplyId
  89. tripItem.Status = r.Status
  90. }
  91. }
  92. tripItem.WeekDate = weekDate
  93. tripItem.WeekType = "current"
  94. tripItem.Week = newDay.Weekday().String()
  95. tripList = append(tripList, tripItem)
  96. }
  97. for i := 0; i < 7; i++ {
  98. newDay := nextWeekStart.AddDate(0, 0, i)
  99. weekDate := newDay.Format(utils.FormatDate)
  100. tripItem := new(business_trip.BusinessTripCalendar)
  101. for _, r := range findTripList {
  102. startDateT, _ := time.ParseInLocation(utils.FormatDate, r.ArriveDate, time.Local)
  103. endDateT, _ := time.ParseInLocation(utils.FormatDate, r.ReturnDate, time.Local)
  104. if r != nil && (newDay.Equal(startDateT) || (newDay.Equal(endDateT)) || (newDay.Before(endDateT) && newDay.After(startDateT))) {
  105. tripItem.City = r.City
  106. tripItem.BusinessApplyId = r.BusinessApplyId
  107. tripItem.Status = r.Status
  108. }
  109. }
  110. tripItem.WeekDate = weekDate
  111. tripItem.WeekType = "next"
  112. tripItem.Week = newDay.Weekday().String()
  113. tripList = append(tripList, tripItem)
  114. }
  115. v.BusinessTripList = tripList
  116. setAdminList = append(setAdminList, v)
  117. }
  118. }
  119. groupList[i].AdminList = setAdminList
  120. }
  121. resp := new(business_trip.BusinessTripCalendarResp)
  122. resp.GroupList = groupList
  123. this.OkDetailed(resp, "获取成功")
  124. return
  125. }