job.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package db
  2. import (
  3. "context"
  4. "youngee_b_api/model/gorm_model"
  5. )
  6. // CreateJob 新建岗位
  7. func CreateJob(ctx context.Context, job gorm_model.YounggeeJob) error {
  8. db := GetWriteDB(ctx)
  9. err := db.Create(&job).Error
  10. if err != nil {
  11. return err
  12. }
  13. return nil
  14. }
  15. // UpdateJob 更新岗位
  16. func UpdateJob(ctx context.Context, job gorm_model.YounggeeJob) error {
  17. db := GetWriteDB(ctx)
  18. whereCondition := gorm_model.YounggeeJob{JobId: job.JobId}
  19. err := db.Model(&gorm_model.YounggeeJob{}).Where(whereCondition).Updates(job).Error
  20. if err != nil {
  21. return err
  22. }
  23. return nil
  24. }
  25. // DeleteJob 删除岗位
  26. func DeleteJob(ctx context.Context, job gorm_model.YounggeeJob) error {
  27. db := GetWriteDB(ctx)
  28. whereCondition := gorm_model.YounggeeJob{JobId: job.JobId}
  29. err := db.Where(whereCondition).Delete(&gorm_model.YounggeeJob{}).Error
  30. if err != nil {
  31. return err
  32. }
  33. return nil
  34. }
  35. // FindJobByEnterpriseId 按商家ID查找岗位信息
  36. func FindJobByEnterpriseId(ctx context.Context, enterpriseId string) ([]*gorm_model.YounggeeJob, int64, error) {
  37. db := GetReadDB(ctx)
  38. var Jobs []*gorm_model.YounggeeJob
  39. var total int64
  40. whereCondition := gorm_model.YounggeeJob{EnterpriseId: enterpriseId}
  41. err := db.Model(gorm_model.YounggeeJob{}).Where(whereCondition).Find(&Jobs).Count(&total).Error
  42. if err != nil {
  43. return nil, 0, err
  44. }
  45. // fmt.Println(Jobs)
  46. return Jobs, total, nil
  47. }
  48. // FindJobByJobId 按照岗位Id查找岗位信息
  49. func FindJobByJobId(ctx context.Context, jobId int) (*gorm_model.YounggeeJob, error) {
  50. db := GetReadDB(ctx)
  51. var Job *gorm_model.YounggeeJob
  52. whereCondition := gorm_model.YounggeeJob{JobId: jobId}
  53. err := db.Model(gorm_model.YounggeeJob{}).Where(whereCondition).Find(&Job).Error
  54. if err != nil {
  55. return nil, err
  56. }
  57. return Job, nil
  58. }
  59. /*
  60. func GetRewardStrategyBySelectionId(ctx context.Context, SelectionId string) ([]*gorm_model.RewardStrategy, error) {
  61. db := GetReadDB(ctx)
  62. var RewardStrategys []*gorm_model.RewardStrategy
  63. err := db.Model(gorm_model.RewardStrategy{}).Where("selection_id = ?", SelectionId).Find(&RewardStrategys).Error
  64. if err != nil {
  65. logrus.WithContext(ctx).Errorf("[GetRewardStrategyBySelectionId] error query, err:%+v", err)
  66. return nil, err
  67. }
  68. return RewardStrategys, nil
  69. }
  70. */