package business_trip import ( "fmt" "hongze/hongze_mobile_admin/models/tables/business_trip" "hongze/hongze_mobile_admin/utils" "time" ) // ResearcherReportList // @Title 出差日历表 // @Description 出差日历表接口 // @Param AdminId query int true "用户id" // @Success 200 {object} roadshow.BusinessTripResp // @router /calendar [get] func (this *BusinessTrip) BusinessTripCalendar() { //sysUser := this.AdminWx //sysUserId := sysUser.AdminId adminId, _ := this.GetInt("AdminId") groupList := make([]*business_trip.BusinessTripCalendarGroup, 0) researcherGroup := new(business_trip.BusinessTripCalendarGroup) researcherGroup.GroupId = 1 researcherGroup.GroupName = "研究员" researcherGroup.DepartmentId = "1" groupList = append(groupList, researcherGroup) sellerGroup := new(business_trip.BusinessTripCalendarGroup) sellerGroup.GroupId = 2 sellerGroup.GroupName = "销售" if utils.RunMode == "debug" { sellerGroup.DepartmentId = "2,5" } else { sellerGroup.DepartmentId = "2,4,5,9" } groupList = append(groupList, sellerGroup) otherGroup := new(business_trip.BusinessTripCalendarGroup) otherGroup.GroupId = 3 otherGroup.GroupName = "其他" if utils.RunMode == "debug" { otherGroup.DepartmentId = "3,7" } else { otherGroup.DepartmentId = "3,6,7,8" } groupList = append(groupList, otherGroup) groupLen := len(groupList) fmt.Println("groupLen:", groupLen) //获取当天周日期 nowWeekStart := utils.GetNowWeekMonday().AddDate(0, 0, -2) //nowWeekEnd := utils.GetNowWeekLastDay() //获取下周日期 nextWeekStart := utils.GetNextWeekMonday().AddDate(0, 0, -2) nextWeekEnd := utils.GetNextWeekLastDay().AddDate(0, 0, -2) //获取出差信息 businessTripList, err := business_trip.GetBusinessTripList(adminId, nowWeekStart.Format(utils.FormatDate), nextWeekEnd.Format(utils.FormatDate)) if err != nil { this.FailWithMessage("获取信息失败!", "获取路演信息失败!,GetBusinessTripList Err:"+err.Error()) return } btMap := make(map[int][]*business_trip.BusinessApplyView) for _, v := range businessTripList { if findVals, ok := btMap[v.ApplyAdminId]; ok { findVals = append(findVals, v) btMap[v.ApplyAdminId] = findVals } else { items := make([]*business_trip.BusinessApplyView, 0) items = append(items, v) btMap[v.ApplyAdminId] = items } } for i := 0; i < groupLen; i++ { group := groupList[i] fmt.Println("group:", group.DepartmentId) adminList, err := business_trip.GetBusinessTripCalendar(group.DepartmentId) if err != nil { this.FailWithMessage("获取信息失败!", "获取分组信息失败!,GetBusinessTripCalendar Err:"+err.Error()) return } setAdminList := make([]*business_trip.BusinessTripCalendarAdmin, 0) for _, v := range adminList { if findTripList, ok := btMap[v.AdminId]; ok { tripList := make([]*business_trip.BusinessTripCalendar, 0) for i := 0; i < 7; i++ { newDay, _ := time.ParseInLocation(utils.FormatDate, nowWeekStart.AddDate(0, 0, i).Format(utils.FormatDate), time.Local) weekDate := newDay.Format(utils.FormatDate) tripItem := new(business_trip.BusinessTripCalendar) for _, r := range findTripList { startDateT, _ := time.ParseInLocation(utils.FormatDate, r.ArriveDate, time.Local) endDateT, _ := time.ParseInLocation(utils.FormatDate, r.ReturnDate, time.Local) if r != nil && (newDay.Equal(startDateT) || (newDay.Equal(endDateT)) || (newDay.Before(endDateT) && newDay.After(startDateT))) { tripItem.City = r.City tripItem.BusinessApplyId = r.BusinessApplyId tripItem.Status = r.Status } } tripItem.WeekDate = weekDate tripItem.WeekType = "current" tripItem.Week = newDay.Weekday().String() tripList = append(tripList, tripItem) } for i := 0; i < 7; i++ { newDay := nextWeekStart.AddDate(0, 0, i) weekDate := newDay.Format(utils.FormatDate) tripItem := new(business_trip.BusinessTripCalendar) for _, r := range findTripList { startDateT, _ := time.ParseInLocation(utils.FormatDate, r.ArriveDate, time.Local) endDateT, _ := time.ParseInLocation(utils.FormatDate, r.ReturnDate, time.Local) if r != nil && (newDay.Equal(startDateT) || (newDay.Equal(endDateT)) || (newDay.Before(endDateT) && newDay.After(startDateT))) { tripItem.City = r.City tripItem.BusinessApplyId = r.BusinessApplyId tripItem.Status = r.Status } } tripItem.WeekDate = weekDate tripItem.WeekType = "next" tripItem.Week = newDay.Weekday().String() tripList = append(tripList, tripItem) } v.BusinessTripList = tripList setAdminList = append(setAdminList, v) } } groupList[i].AdminList = setAdminList } resp := new(business_trip.BusinessTripCalendarResp) resp.GroupList = groupList this.OkDetailed(resp, "获取成功") return }