123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- package sheep
- import (
- "context"
- operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
- "gitee.com/xuyiping_admin/pkg/xerr"
- "net/http"
- "tmr-watch/module"
- )
- func UpdateOrCreateTmrGear(ctx context.Context, req *operationPb.UpdateOrCreateTmrGearRequest) error {
- if len(req.Params) <= 0 {
- return xerr.Customf("参数错误: params")
- }
- if len(req.TmrId) <= 0 {
- return xerr.Customf("参数错误: tmr_id")
- }
- revList := make(map[int32]struct{})
- for _, v := range req.Params {
- if _, ok := revList[v.Rev]; ok {
- return xerr.Customf("不能出现同样转速的数据")
- }
- revList[v.Rev] = struct{}{}
- }
- if err := module.CreateOrUpdateTmrGear(ctx, req); err != nil {
- return xerr.WithStack(err)
- }
- return nil
- }
- func UseGear(ctx context.Context, req *operationPb.UseGearRequest) (*operationPb.UseGearResponse, error) {
- list, err := module.UseTmrGear(ctx, req)
- if err != nil {
- return nil, xerr.WithStack(err)
- }
- tmrGearList, err := module.TmrGearListByTmrId(int64(req.TmrId))
- if err != nil {
- return nil, xerr.WithStack(err)
- }
- gear := "0"
- useGearDataList := make([]*operationPb.UseGearDataList, 0)
- for _, v := range list {
- if len(tmrGearList) > 0 {
- for i := 0; i < len(tmrGearList)-1; i++ {
- if v.GearRate > float64(tmrGearList[i].Rev) && v.GearRate <= float64(tmrGearList[i+1].Rev) {
- gear = tmrGearList[i+1].Gear
- }
- }
- if v.GearRate <= float64(tmrGearList[0].Rev) {
- gear = tmrGearList[0].Gear
- }
- if v.GearRate >= float64(tmrGearList[len(tmrGearList)-1].Rev) {
- gear = tmrGearList[len(tmrGearList)-1].Gear
- }
- }
- newData := &operationPb.UseGearDataList{
- Bcode: v.BCode,
- Fname: v.FName,
- Length: v.Length,
- Sort: v.Sort,
- Speed: float32(v.Speed),
- Useinbar: v.UseInBar,
- Weight: float32(v.Weight),
- Gear: gear,
- Ccount: v.CCount,
- GearRate: float32(v.GearRate),
- Pid: v.Pid,
- Fbarid: v.FBarid,
- }
- useGearDataList = append(useGearDataList, newData)
- }
- return &operationPb.UseGearResponse{
- Code: http.StatusOK,
- Msg: "ok",
- Data: &operationPb.UseGearData{List: useGearDataList},
- }, nil
- }
|