jobs.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package job
  2. import (
  3. "context"
  4. "go-common/app/interface/main/web-show/model/job"
  5. "go-common/library/log"
  6. )
  7. const (
  8. _selCateSQL = "SELECT id,name,type FROM job_category"
  9. _selJobsSQL = "SELECT id,name,cate_id,addr_id,duty,demand FROM jobs WHERE status=1"
  10. )
  11. // Categories Dao
  12. func (dao *Dao) Categories(c context.Context) (cs []*job.Category, err error) {
  13. rows, err := dao.db.Query(c, _selCateSQL)
  14. if err != nil {
  15. log.Error("Job.GetAllCate error(%v)", err)
  16. return
  17. }
  18. defer rows.Close()
  19. for rows.Next() {
  20. c := &job.Category{}
  21. if err = rows.Scan(&c.ID, &c.Name, &c.Type); err != nil {
  22. PromError("Categories", "rows.scan err(%v)", err)
  23. return
  24. }
  25. cs = append(cs, c)
  26. }
  27. return
  28. }
  29. // Jobs Dao
  30. func (dao *Dao) Jobs(c context.Context) (js []*job.Job, err error) {
  31. rows, err := dao.db.Query(c, _selJobsSQL)
  32. if err != nil {
  33. log.Error("Job.Jobs error (%v)", err)
  34. return
  35. }
  36. defer rows.Close()
  37. for rows.Next() {
  38. j := &job.Job{}
  39. if err = rows.Scan(&j.ID, &j.Name, &j.CateID, &j.AddrID, &j.Duty, &j.Demand); err != nil {
  40. PromError("Jobs", "rows.scan err(%v)", err)
  41. return
  42. }
  43. js = append(js, j)
  44. }
  45. return
  46. }