tmr_gear.go 738 B

123456789101112131415161718192021222324252627282930
  1. package sheep
  2. import (
  3. "context"
  4. operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
  5. "gitee.com/xuyiping_admin/pkg/xerr"
  6. "tmr-watch/module"
  7. )
  8. func UpdateOrCreateTmrGear(ctx context.Context, req *operationPb.UpdateOrCreateTmrGearRequest) error {
  9. if len(req.Params) <= 0 {
  10. return xerr.Customf("参数错误: params")
  11. }
  12. if len(req.TmrId) <= 0 {
  13. return xerr.Customf("参数错误: tmr_id")
  14. }
  15. revList := make(map[int32]struct{})
  16. for _, v := range req.Params {
  17. if _, ok := revList[v.Rev]; ok {
  18. return xerr.Customf("不能出现同样转速的数据")
  19. }
  20. revList[v.Rev] = struct{}{}
  21. }
  22. if err := module.CreateOrUpdateTmrGear(ctx, req); err != nil {
  23. return xerr.WithStack(err)
  24. }
  25. return nil
  26. }