staff.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package archive
  2. import (
  3. "context"
  4. "go-common/app/interface/main/creative/model/archive"
  5. "go-common/library/database/sql"
  6. "go-common/library/log"
  7. )
  8. const (
  9. _staffCountSQL = "SELECT count(*) as count FROM archive_staff_apply WHERE apply_staff_mid=? AND deal_state = 1"
  10. _staffSQL = "SELECT id,aid,mid,staff_mid,staff_title FROM archive_staff WHERE aid=? AND state = 1"
  11. )
  12. // RawStaffData get staff data from db
  13. func (d *Dao) RawStaffData(c context.Context, aid int64) (res []*archive.Staff, err error) {
  14. rows, err := d.db.Query(c, _staffSQL, aid)
  15. if err != nil {
  16. log.Error("mysqlDB.Query error(%v)", err)
  17. return
  18. }
  19. defer rows.Close()
  20. res = make([]*archive.Staff, 0)
  21. res = append(res, &archive.Staff{AID: aid})
  22. var mid int64
  23. for rows.Next() {
  24. v := &archive.Staff{}
  25. if err = rows.Scan(&v.ID, &v.AID, &v.MID, &v.StaffMID, &v.StaffTitle); err != nil {
  26. log.Error("row.Scan error(%v)", err)
  27. res = res[0:0]
  28. return
  29. }
  30. res = append(res, v)
  31. mid = v.MID
  32. }
  33. if len(res) == 1 {
  34. return res[0:0], nil
  35. }
  36. for _, v := range res {
  37. if v.MID == 0 {
  38. v.MID = mid
  39. v.StaffMID = mid
  40. v.StaffTitle = "UP"
  41. break
  42. }
  43. }
  44. return
  45. }
  46. // CountByMID .
  47. func (d *Dao) CountByMID(c context.Context, mid int64) (count int, err error) {
  48. row := d.db.QueryRow(c, _staffCountSQL, mid)
  49. if err = row.Scan(&count); err != nil {
  50. if err == sql.ErrNoRows {
  51. err = nil
  52. } else {
  53. log.Error("row.Scan error(%v)", err)
  54. }
  55. }
  56. return
  57. }