package business_trip import ( "hongze/hongze_mobile_admin/models/tables/admin" "hongze/hongze_mobile_admin/models/tables/business_trip" "strconv" "strings" ) // ResearcherReportList // @Title 出差日历表 // @Description 出差日历表接口 // @Param AdminId query int true "用户id" // @Param TripDate query string true "日期" // @Success 200 {object} roadshow.BusinessTripResp // @router /calendar [get] func (this *BusinessTrip) BusinessTripCalendar() { sysUser := this.AdminWx sysUserId := sysUser.AdminId adminId, _ := this.GetInt("AdminId") tripDate := this.GetString("TripDate") var condition string var pars []interface{} if adminId > 0 { condition += ` AND apply_admin_id=? ` pars = append(pars, adminId) } if sysUserId == 66 { condition += ` AND status IN('待审批','已通过') ` } else { condition += ` AND status=? ` pars = append(pars, "已通过") } if tripDate != "" { condition += ` AND ? >= arrive_date ` pars = append(pars, tripDate) condition += ` AND ? <= return_date ` pars = append(pars, tripDate) } list, err := business_trip.GetBusinessTripApproveList(condition, pars) if err != nil { this.FailWithMessage("获取数据失败!", "获取数据失败,GetBusinessTripApproveList,Err:"+err.Error()) return } var peerIdArr []string for _, v := range list { if v.PeerPeopleId != "" { peerId := strings.Split(v.PeerPeopleId, ",") peerIdArr = append(peerIdArr, peerId...) } } adminMap := make(map[int]*admin.Admin) if len(peerIdArr) > 0 { peerIdStr := strings.Join(peerIdArr, ",") adminList, err := admin.GetAdminListByIds(peerIdStr) if err != nil { this.FailWithMessage("获取数据失败!", "获取数据失败,GetBusinessTripApproveList,Err:"+err.Error()) return } for _, av := range adminList { adminMap[av.AdminId] = av } } approveList := make([]*business_trip.BusinessTripApproveView, 0) listLen := len(list) for i := 0; i < listLen; i++ { item := list[i] approveList = append(approveList, item) dayCount := int(item.ReturnDate.Sub(item.ArriveDate).Hours()/24) + 1 list[i].DayTotal = dayCount var groupName string switch item.DepartmentId { case 1: groupName = "研究员" case 2, 4, 5, 9: groupName = "销售" case 3, 6, 7, 8: groupName = "其他" default: groupName = "其他" } list[i].GroupName = groupName //if item.Status == "已审批" && item.PeerPeopleId != "" { // peerIdArr := strings.Split(item.PeerPeopleId, ",") // peerNameArr := strings.Split(item.PeerPeopleName, ",") // for k, v := range peerIdArr { // peerId, err := strconv.Atoi(v) // if err != nil { // this.FailWithMessage("申请失败!", "同行人id失败,Err:"+err.Error()) // return // } // peerItem := new(business_trip.BusinessTripApproveView) // peerItem = item // peerItem.ApplyAdminId = peerId // peerItem.ApplyRealName = peerNameArr[k] // peerItem.DayTotal = dayCount // approveList = append(approveList, peerItem) // } //} if item.PeerPeopleId != "" { PeerItems := make([]*business_trip.PeerItem, 0) peerSplitIdArr := strings.Split(item.PeerPeopleId, ",") for _, v := range peerSplitIdArr { peerItem := new(business_trip.PeerItem) peerId, err := strconv.Atoi(v) if err != nil { this.FailWithMessage("申请失败!", "同行人id失败,Err:"+err.Error()) return } peerAdmin := adminMap[peerId] if peerAdmin != nil { peerItem.PeerPeopleId = peerAdmin.AdminId peerItem.PeerPeopleName = peerAdmin.RealName switch peerAdmin.DepartmentId { case 1: groupName = "研究员" case 2, 4, 5, 9: groupName = "销售" case 3, 6, 7, 8: groupName = "其他" default: groupName = "其他" } peerItem.PeerGroupName = groupName } PeerItems = append(PeerItems, peerItem) } list[i].PeerPeopleList = PeerItems } } this.OkDetailed(list, "获取成功") return }