1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- package db
- import (
- "context"
- "youngee_b_api/model/gorm_model"
- )
- // CreateJob 新建岗位
- func CreateJob(ctx context.Context, job gorm_model.YounggeeJob) error {
- db := GetWriteDB(ctx)
- err := db.Create(&job).Error
- if err != nil {
- return err
- }
- return nil
- }
- // UpdateJob 更新岗位
- func UpdateJob(ctx context.Context, job gorm_model.YounggeeJob) error {
- db := GetWriteDB(ctx)
- whereCondition := gorm_model.YounggeeJob{JobId: job.JobId}
- err := db.Model(&gorm_model.YounggeeJob{}).Where(whereCondition).Updates(job).Error
- if err != nil {
- return err
- }
- return nil
- }
- // DeleteJob 删除岗位
- func DeleteJob(ctx context.Context, job gorm_model.YounggeeJob) error {
- db := GetWriteDB(ctx)
- whereCondition := gorm_model.YounggeeJob{JobId: job.JobId}
- err := db.Where(whereCondition).Delete(&gorm_model.YounggeeJob{}).Error
- if err != nil {
- return err
- }
- return nil
- }
- // FindJobByEnterpriseId 按商家ID查找岗位信息
- func FindJobByEnterpriseId(ctx context.Context, enterpriseId string) ([]*gorm_model.YounggeeJob, int64, error) {
- db := GetReadDB(ctx)
- var Jobs []*gorm_model.YounggeeJob
- var total int64
- whereCondition := gorm_model.YounggeeJob{EnterpriseId: enterpriseId}
- err := db.Model(gorm_model.YounggeeJob{}).Where(whereCondition).Find(&Jobs).Count(&total).Error
- if err != nil {
- return nil, 0, err
- }
- // fmt.Println(Jobs)
- return Jobs, total, nil
- }
- // FindJobByJobId 按照岗位Id查找岗位信息
- func FindJobByJobId(ctx context.Context, jobId int) (*gorm_model.YounggeeJob, error) {
- db := GetReadDB(ctx)
- var Job *gorm_model.YounggeeJob
- whereCondition := gorm_model.YounggeeJob{JobId: jobId}
- err := db.Model(gorm_model.YounggeeJob{}).Where(whereCondition).Find(&Job).Error
- if err != nil {
- return nil, err
- }
- return Job, nil
- }
- /*
- func GetRewardStrategyBySelectionId(ctx context.Context, SelectionId string) ([]*gorm_model.RewardStrategy, error) {
- db := GetReadDB(ctx)
- var RewardStrategys []*gorm_model.RewardStrategy
- err := db.Model(gorm_model.RewardStrategy{}).Where("selection_id = ?", SelectionId).Find(&RewardStrategys).Error
- if err != nil {
- logrus.WithContext(ctx).Errorf("[GetRewardStrategyBySelectionId] error query, err:%+v", err)
- return nil, err
- }
- return RewardStrategys, nil
- }
- */
|