|
@@ -1,142 +1,94 @@
|
|
|
package business_trip
|
|
|
|
|
|
import (
|
|
|
- "fmt"
|
|
|
"hongze/hongze_mobile_admin/models/tables/business_trip"
|
|
|
- "hongze/hongze_mobile_admin/utils"
|
|
|
- "time"
|
|
|
+ "strconv"
|
|
|
+ "strings"
|
|
|
)
|
|
|
|
|
|
// ResearcherReportList
|
|
|
// @Title 出差日历表
|
|
|
// @Description 出差日历表接口
|
|
|
-// @Param AdminId query string true "用户id"
|
|
|
+// @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
|
|
|
+ sysUser := this.AdminWx
|
|
|
+ sysUserId := sysUser.AdminId
|
|
|
|
|
|
- adminId := this.GetString("AdminId")
|
|
|
+ adminId, _ := this.GetInt("AdminId")
|
|
|
+ tripDate := this.GetString("TripDate")
|
|
|
|
|
|
- groupList := make([]*business_trip.BusinessTripCalendarGroup, 0)
|
|
|
- researcherGroup := new(business_trip.BusinessTripCalendarGroup)
|
|
|
+ var condition string
|
|
|
+ var pars []interface{}
|
|
|
|
|
|
- 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"
|
|
|
+ if adminId > 0 {
|
|
|
+ condition += ` AND apply_admin_id=? `
|
|
|
+ pars = append(pars, adminId)
|
|
|
}
|
|
|
- groupList = append(groupList, sellerGroup)
|
|
|
|
|
|
- otherGroup := new(business_trip.BusinessTripCalendarGroup)
|
|
|
- otherGroup.GroupId = 3
|
|
|
- otherGroup.GroupName = "其他"
|
|
|
- if utils.RunMode == "debug" {
|
|
|
- otherGroup.DepartmentId = "3,7"
|
|
|
+ if sysUserId == 66 {
|
|
|
+ condition += ` AND status IN('待审批','已审批') `
|
|
|
} else {
|
|
|
- otherGroup.DepartmentId = "3,6,7,8"
|
|
|
+ condition += ` AND status=? `
|
|
|
+ pars = append(pars, "已审批")
|
|
|
}
|
|
|
- groupList = append(groupList, otherGroup)
|
|
|
|
|
|
- groupLen := len(groupList)
|
|
|
+ if tripDate != "" {
|
|
|
+ condition += ` AND arrive_date>=? `
|
|
|
+ pars = append(pars, tripDate)
|
|
|
|
|
|
- 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)
|
|
|
+ condition += ` AND return_date<=? `
|
|
|
+ pars = append(pars, tripDate)
|
|
|
+ }
|
|
|
|
|
|
- //获取出差信息
|
|
|
- businessTripList, err := business_trip.GetBusinessTripList(adminId, nowWeekStart.Format(utils.FormatDate), nextWeekEnd.Format(utils.FormatDate))
|
|
|
+ list, err := business_trip.GetBusinessTripApproveList(condition, pars)
|
|
|
if err != nil {
|
|
|
- this.FailWithMessage("获取信息失败!", "获取路演信息失败!,GetBusinessTripList Err:"+err.Error())
|
|
|
+ this.FailWithMessage("获取数据失败!", "获取数据失败,GetBusinessTripApproveList,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
|
|
|
+ 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.DepartmentTd {
|
|
|
+ case 1:
|
|
|
+ groupName = "研究员"
|
|
|
+ case 2, 4, 5, 9:
|
|
|
+ groupName = "销售"
|
|
|
+ case 3, 6, 7, 8:
|
|
|
+ groupName = "其他"
|
|
|
+ default:
|
|
|
+ groupName = "其他"
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- 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)
|
|
|
+ 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
|
|
|
}
|
|
|
-
|
|
|
- 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)
|
|
|
+ peerItem := new(business_trip.BusinessTripApproveView)
|
|
|
+ peerItem = item
|
|
|
+ peerItem.ApplyAdminId = peerId
|
|
|
+ peerItem.ApplyRealName = peerNameArr[k]
|
|
|
+ peerItem.DayTotal = dayCount
|
|
|
+ approveList = append(approveList, peerItem)
|
|
|
}
|
|
|
}
|
|
|
- groupList[i].AdminList = setAdminList
|
|
|
}
|
|
|
- resp := new(business_trip.BusinessTripCalendarResp)
|
|
|
- resp.GroupList = groupList
|
|
|
- this.OkDetailed(resp, "获取成功")
|
|
|
+
|
|
|
+ this.OkDetailed(list, "获取成功")
|
|
|
return
|
|
|
}
|