business_calendar.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. }
  18. // GetResearcherV2 获取研究员列表(冻结的也要)
  19. func GetBusinessTripCalendar(departmentId string) (list []*BusinessTripCalendarAdmin, err error) {
  20. o := orm.NewOrm()
  21. sql := ` SELECT a.admin_id,a.real_name
  22. FROM admin AS a
  23. WHERE a.enabled=1
  24. AND a.department_id IN(` + departmentId + `)
  25. ORDER BY a.admin_id ASC `
  26. _, err = o.Raw(sql).QueryRows(&list)
  27. return
  28. }
  29. type BusinessTripCalendarGroup struct {
  30. GroupId int `description:"分组id"`
  31. GroupName string `description:"分组名称"`
  32. DepartmentId string `json:"-" description:"部门id"`
  33. AdminList []*BusinessTripCalendarAdmin
  34. }
  35. type BusinessTripCalendarResp struct {
  36. GroupList []*BusinessTripCalendarGroup
  37. BaseDate string `description:"用于查询上下两周的开始日期"`
  38. }
  39. func GetBusinessTripList(adminId, startDate, endDate string) (list []*BusinessApplyView, err error) {
  40. o := orm.NewOrm()
  41. sql := `SELECT a.*
  42. FROM business_apply AS a
  43. left join business_apply_peer b on a.business_apply_id =b.business_apply_id
  44. WHERE a.status IN('待审批','已通过')
  45. AND ((a.arrive_date>=? AND a.arrive_date<=?) OR (a.return_date>=? AND a.return_date<=?)) `
  46. if adminId != "" {
  47. sql += ` AND (a.apply_admin_id IN (` + adminId + `) or b.peer_people_id IN (` + adminId + `) ) `
  48. sql += ` ORDER BY a.apply_admin_id ASC,a.arrive_date ASC `
  49. } else {
  50. sql += ` ORDER BY a.apply_admin_id ASC,a.arrive_date ASC `
  51. }
  52. sql = `SELECT * FROM ( ` + sql + ` ) d GROUP BY business_apply_id `
  53. _, err = o.Raw(sql, startDate, endDate, startDate, endDate).QueryRows(&list)
  54. return
  55. }