business_calendar.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package business_trip
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. )
  5. type BusinessTripCalendarAdmin struct {
  6. AdminId int `description:"研究员id"`
  7. RealName string `description:"研究员名称"`
  8. BusinessTripList []*BusinessTripCalendar
  9. }
  10. type BusinessTripCalendar struct {
  11. BusinessApplyId int `description:"出差申请id"`
  12. Status string `description:"状态:'待审批','已审批','已驳回','已撤回','已过期'"`
  13. WeekDate string `description:"开始日期"`
  14. City string `description:"城市"`
  15. Week string `description:"周"`
  16. WeekType string `description:"当前周:current,下一周:next"`
  17. Reason string `description:"出差事由"`
  18. }
  19. // GetResearcherV2 获取研究员列表(冻结的也要)
  20. func GetBusinessTripCalendar(departmentId string) (list []*BusinessTripCalendarAdmin, err error) {
  21. o := orm.NewOrm()
  22. sql := ` SELECT a.admin_id,a.real_name
  23. FROM admin AS a
  24. WHERE a.enabled=1
  25. AND a.department_id IN(` + departmentId + `)
  26. ORDER BY a.admin_id ASC `
  27. _, err = o.Raw(sql).QueryRows(&list)
  28. return
  29. }
  30. type BusinessTripCalendarGroup struct {
  31. GroupId int `description:"分组id"`
  32. GroupName string `description:"分组名称"`
  33. DepartmentId string `json:"-" description:"部门id"`
  34. AdminList []*BusinessTripCalendarAdmin
  35. }
  36. type BusinessTripCalendarResp struct {
  37. GroupList []*BusinessTripCalendarGroup
  38. BaseDate string `description:"用于查询上下两周的开始日期"`
  39. }
  40. func GetBusinessTripList(adminId, startDate, endDate string) (list []*BusinessApplyView, err error) {
  41. o := orm.NewOrm()
  42. sql := `SELECT a.*
  43. FROM business_apply AS a
  44. left join business_apply_peer b on a.business_apply_id =b.business_apply_id
  45. WHERE a.status IN('待审批','已通过')
  46. AND ((a.arrive_date>=? AND a.arrive_date<=?) OR (a.return_date>=? AND a.return_date<=?)) `
  47. if adminId != "" {
  48. sql += ` AND (a.apply_admin_id IN (` + adminId + `) or b.peer_people_id IN (` + adminId + `) ) `
  49. sql += ` ORDER BY a.apply_admin_id ASC,a.arrive_date ASC `
  50. } else {
  51. sql += ` ORDER BY a.apply_admin_id ASC,a.arrive_date ASC `
  52. }
  53. sql = `SELECT * FROM ( ` + sql + ` ) d GROUP BY business_apply_id `
  54. _, err = o.Raw(sql, startDate, endDate, startDate, endDate).QueryRows(&list)
  55. return
  56. }