offline_task.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package task
  4. import (
  5. "adm-task/errors"
  6. "context"
  7. "git.getensh.com/common/gopkgsv2/database"
  8. pb_v1 "adm-task/pb/v1"
  9. )
  10. func UpdateOfflineTask(ctx context.Context, req *pb_v1.UpdateOfflineTaskRequest) (reply *pb_v1.UpdateOfflineTaskReply, err error) {
  11. if req.TaskId == 0 {
  12. return nil, errors.ServiceError
  13. }
  14. reply = &pb_v1.UpdateOfflineTaskReply{}
  15. if req.Total != 0 {
  16. err = database.DB().Exec("update t_adm_offline_task set total=? where id=?", req.Total, req.TaskId).Error
  17. return reply, err
  18. }
  19. if req.FinishCount != 0 {
  20. err = database.DB().Exec("update t_adm_offline_task set finish_count=finish_count+? where id=?", req.FinishCount, req.TaskId).Error
  21. return reply, err
  22. }
  23. if req.IsFinish != 0 {
  24. err = database.DB().Exec("update t_adm_offline_task set is_finish=? where id=?", req.IsFinish, req.TaskId).Error
  25. if req.IsFinish == 1 {
  26. database.DB().Exec("update t_adm_offline_task set finish_count=total where id=?", req.TaskId)
  27. }
  28. return reply, err
  29. }
  30. return reply, nil
  31. }