business_calendar.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. package business_trip
  2. import (
  3. "hongze/hongze_mobile_admin/models/tables/admin"
  4. "hongze/hongze_mobile_admin/models/tables/business_trip"
  5. "strconv"
  6. "strings"
  7. )
  8. // ResearcherReportList
  9. // @Title 出差日历表
  10. // @Description 出差日历表接口
  11. // @Param AdminId query int true "用户id"
  12. // @Param TripDate query string true "日期"
  13. // @Success 200 {object} roadshow.BusinessTripResp
  14. // @router /calendar [get]
  15. func (this *BusinessTrip) BusinessTripCalendar() {
  16. sysUser := this.AdminWx
  17. sysUserId := sysUser.AdminId
  18. adminId, _ := this.GetInt("AdminId")
  19. tripDate := this.GetString("TripDate")
  20. var condition string
  21. var pars []interface{}
  22. if adminId > 0 {
  23. condition += ` AND apply_admin_id=? `
  24. pars = append(pars, adminId)
  25. }
  26. if sysUserId == 66 {
  27. condition += ` AND status IN('待审批','已通过') `
  28. } else {
  29. condition += ` AND status=? `
  30. pars = append(pars, "已通过")
  31. }
  32. if tripDate != "" {
  33. condition += ` AND ? >= arrive_date `
  34. pars = append(pars, tripDate)
  35. condition += ` AND ? <= return_date `
  36. pars = append(pars, tripDate)
  37. }
  38. list, err := business_trip.GetBusinessTripApproveList(condition, pars)
  39. if err != nil {
  40. this.FailWithMessage("获取数据失败!", "获取数据失败,GetBusinessTripApproveList,Err:"+err.Error())
  41. return
  42. }
  43. var peerIdArr []string
  44. for _, v := range list {
  45. if v.PeerPeopleId != "" {
  46. peerId := strings.Split(v.PeerPeopleId, ",")
  47. peerIdArr = append(peerIdArr, peerId...)
  48. }
  49. }
  50. adminMap := make(map[int]*admin.Admin)
  51. if len(peerIdArr) > 0 {
  52. peerIdStr := strings.Join(peerIdArr, ",")
  53. adminList, err := admin.GetAdminListByIds(peerIdStr)
  54. if err != nil {
  55. this.FailWithMessage("获取数据失败!", "获取数据失败,GetBusinessTripApproveList,Err:"+err.Error())
  56. return
  57. }
  58. for _, av := range adminList {
  59. adminMap[av.AdminId] = av
  60. }
  61. }
  62. approveList := make([]*business_trip.BusinessTripApproveView, 0)
  63. listLen := len(list)
  64. for i := 0; i < listLen; i++ {
  65. item := list[i]
  66. approveList = append(approveList, item)
  67. dayCount := int(item.ReturnDate.Sub(item.ArriveDate).Hours()/24) + 1
  68. list[i].DayTotal = dayCount
  69. var groupName string
  70. switch item.DepartmentId {
  71. case 1:
  72. groupName = "研究员"
  73. case 2, 4, 5, 9:
  74. groupName = "销售"
  75. case 3, 6, 7, 8:
  76. groupName = "其他"
  77. default:
  78. groupName = "其他"
  79. }
  80. list[i].GroupName = groupName
  81. //if item.Status == "已审批" && item.PeerPeopleId != "" {
  82. // peerIdArr := strings.Split(item.PeerPeopleId, ",")
  83. // peerNameArr := strings.Split(item.PeerPeopleName, ",")
  84. // for k, v := range peerIdArr {
  85. // peerId, err := strconv.Atoi(v)
  86. // if err != nil {
  87. // this.FailWithMessage("申请失败!", "同行人id失败,Err:"+err.Error())
  88. // return
  89. // }
  90. // peerItem := new(business_trip.BusinessTripApproveView)
  91. // peerItem = item
  92. // peerItem.ApplyAdminId = peerId
  93. // peerItem.ApplyRealName = peerNameArr[k]
  94. // peerItem.DayTotal = dayCount
  95. // approveList = append(approveList, peerItem)
  96. // }
  97. //}
  98. if item.PeerPeopleId != "" {
  99. PeerItems := make([]*business_trip.PeerItem, 0)
  100. peerSplitIdArr := strings.Split(item.PeerPeopleId, ",")
  101. for _, v := range peerSplitIdArr {
  102. peerItem := new(business_trip.PeerItem)
  103. peerId, err := strconv.Atoi(v)
  104. if err != nil {
  105. this.FailWithMessage("申请失败!", "同行人id失败,Err:"+err.Error())
  106. return
  107. }
  108. peerAdmin := adminMap[peerId]
  109. if peerAdmin != nil {
  110. peerItem.PeerPeopleId = peerAdmin.AdminId
  111. peerItem.PeerPeopleName = peerAdmin.RealName
  112. switch peerAdmin.DepartmentId {
  113. case 1:
  114. groupName = "研究员"
  115. case 2, 4, 5, 9:
  116. groupName = "销售"
  117. case 3, 6, 7, 8:
  118. groupName = "其他"
  119. default:
  120. groupName = "其他"
  121. }
  122. peerItem.PeerGroupName = groupName
  123. }
  124. PeerItems = append(PeerItems, peerItem)
  125. }
  126. list[i].PeerPeopleList = PeerItems
  127. }
  128. }
  129. this.OkDetailed(list, "获取成功")
  130. return
  131. }