job.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. // FindJobBySupplierId 按服务商ID查找岗位信息
  36. func FindJobBySupplierId(ctx context.Context, supplierId int) ([]*gorm_model.YounggeeJob, int64, error) {
  37. db := GetReadDB(ctx)
  38. var Jobs []*gorm_model.YounggeeJob
  39. whereCondition := gorm_model.YounggeeJob{SupplierId: supplierId}
  40. var total int64
  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. return Jobs, total, nil
  46. }
  47. // FindJobByJobId 按照岗位Id查找岗位信息
  48. func FindJobByJobId(ctx context.Context, jobId int) (*gorm_model.YounggeeJob, error) {
  49. db := GetReadDB(ctx)
  50. var Job *gorm_model.YounggeeJob
  51. whereCondition := gorm_model.YounggeeJob{JobId: jobId}
  52. err := db.Model(gorm_model.YounggeeJob{}).Where(whereCondition).Find(&Job).Error
  53. if err != nil {
  54. return nil, err
  55. }
  56. return Job, nil
  57. }
  58. /*
  59. func GetRewardStrategyBySelectionId(ctx context.Context, SelectionId string) ([]*gorm_model.RewardStrategy, error) {
  60. db := GetReadDB(ctx)
  61. var RewardStrategys []*gorm_model.RewardStrategy
  62. err := db.Model(gorm_model.RewardStrategy{}).Where("selection_id = ?", SelectionId).Find(&RewardStrategys).Error
  63. if err != nil {
  64. logrus.WithContext(ctx).Errorf("[GetRewardStrategyBySelectionId] error query, err:%+v", err)
  65. return nil, err
  66. }
  67. return RewardStrategys, nil
  68. }
  69. */