|
@@ -3,20 +3,20 @@ package module
|
|
|
import (
|
|
|
"context"
|
|
|
"errors"
|
|
|
+ "fmt"
|
|
|
+ operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
|
|
|
"gitee.com/xuyiping_admin/pkg/xerr"
|
|
|
"github.com/xormplus/xorm"
|
|
|
"strconv"
|
|
|
- "time"
|
|
|
"tmr-watch/http/handle/restful"
|
|
|
"tmr-watch/models"
|
|
|
-
|
|
|
- operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
|
|
|
)
|
|
|
|
|
|
// SearchTrmGearByTmrId 查询撒料电机档位数据
|
|
|
func SearchTrmGearByTmrId(ctx context.Context, tmrId int64) ([]*models.TmrGear, error) {
|
|
|
res := make([]*models.TmrGear, 0)
|
|
|
- if err := restful.Engine.NewSession().Table(new(models.TmrGear).TableName()).Where("is_delete = ?", operationPb.IsShow_OK).
|
|
|
+ if err := restful.Engine.NewSession().Table(new(models.TmrGear).TableName()).
|
|
|
+ Where("is_delete = ?", operationPb.IsShow_OK).
|
|
|
Where("tmr_id = ?", tmrId).Find(&res); err != nil {
|
|
|
if !errors.Is(err, xorm.ErrNotExist) {
|
|
|
return nil, err
|
|
@@ -40,10 +40,7 @@ func CreateOrUpdateTmrGear(ctx context.Context, req *operationPb.UpdateOrCreateT
|
|
|
}
|
|
|
|
|
|
if len(tmrGearList) >= 1 {
|
|
|
- if _, err = tx.Table(new(models.TmrGear).TableName()).Where("tmr_id = ?", req.TmrId).Update(map[string]interface{}{
|
|
|
- "is_delete": operationPb.IsShow_NO,
|
|
|
- "updated_at": time.Now().Unix(),
|
|
|
- }); err != nil {
|
|
|
+ if _, err = tx.Table(new(models.TmrGear).TableName()).Where("tmr_id = ?", req.TmrId).Delete(new(models.TmrGear)); err != nil {
|
|
|
tx.Rollback()
|
|
|
return xerr.WithStack(err)
|
|
|
}
|
|
@@ -56,3 +53,70 @@ func CreateOrUpdateTmrGear(ctx context.Context, req *operationPb.UpdateOrCreateT
|
|
|
}
|
|
|
return tx.Commit()
|
|
|
}
|
|
|
+
|
|
|
+func UseTmrGear(ctx context.Context, req *operationPb.UseGearRequest) ([]*models.TmrGearDetail, error) {
|
|
|
+ sqlName := fmt.Sprintf(
|
|
|
+ `SELECT sort,fname,weight,LENGTH,bcode,ccount,speed,gear_rate,useinbar FROM
|
|
|
+ (SELECT a.sort,a.fname,a.lweight weight,a.fpid, IF(a.useinbartype=0,'转投剩料', IF(a.useinbartype=1,'撒','继续饲喂') ) useinbar,
|
|
|
+ CONCAT(a.fbarid) fbarid,
|
|
|
+ CONCAT(a.pid) pid,
|
|
|
+ b.bcode,
|
|
|
+ b.length,
|
|
|
+ c.ccount,
|
|
|
+ d.speed,
|
|
|
+ (((a.lweight / b.length) * f.volume) / d.volume_rate) / (60 * 60 / 1000 / d.speed) AS gear_rate
|
|
|
+ FROM downloadplandtl2 a
|
|
|
+ JOIN bar b ON a.fbarid = b.id
|
|
|
+ JOIN feedp c ON c.barid = a.fbarid
|
|
|
+ JOIN downloadedplan g ON a.pid = g.id
|
|
|
+ JOIN tmr d ON d.id = g.tmrid
|
|
|
+ JOIN feedtemplet f ON c.ftid = f.id
|
|
|
+ WHERE a.pastureid = %s
|
|
|
+ AND a.pid= %s
|
|
|
+ AND d.id = %d
|
|
|
+ ORDER BY a.sort) AS B`, req.PastureId, req.Id, req.TmrId)
|
|
|
+
|
|
|
+ tx := restful.Engine.NewSession()
|
|
|
+ defer tx.Close()
|
|
|
+
|
|
|
+ resultList, err := tx.QueryString(sqlName)
|
|
|
+ if err != nil {
|
|
|
+ return nil, xerr.WithStack(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ tmrGearDetailList := make([]*models.TmrGearDetail, 0)
|
|
|
+ for _, v := range resultList {
|
|
|
+ sort, _ := strconv.ParseInt(v["sort"], 10, 64)
|
|
|
+ fname := v["fname"]
|
|
|
+ bcode := v["bcode"]
|
|
|
+ weight, _ := strconv.ParseFloat(v["weight"], 64)
|
|
|
+ length, _ := strconv.ParseInt(v["length"], 10, 64)
|
|
|
+ ccount, _ := strconv.ParseInt(v["ccount"], 10, 64)
|
|
|
+ speed, _ := strconv.ParseFloat(v["speed"], 64)
|
|
|
+ gearRate, _ := strconv.ParseFloat(v["gear_rate"], 64)
|
|
|
+
|
|
|
+ tmrGearDetailList = append(tmrGearDetailList, &models.TmrGearDetail{
|
|
|
+ Sort: int32(sort),
|
|
|
+ FName: fname,
|
|
|
+ Weight: weight,
|
|
|
+ Length: int32(length),
|
|
|
+ BCode: bcode,
|
|
|
+ CCount: int32(ccount),
|
|
|
+ Speed: speed,
|
|
|
+ GearRate: gearRate,
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ return tmrGearDetailList, nil
|
|
|
+}
|
|
|
+
|
|
|
+func TmrGearListByTmrId(tmrId int64) ([]*models.TmrGear, error) {
|
|
|
+ tmrGearList := make([]*models.TmrGear, 0)
|
|
|
+ tx := restful.Engine.NewSession()
|
|
|
+ defer tx.Close()
|
|
|
+ err := tx.Table(new(models.TmrGear).TableName()).Where("tmr_id = ?", tmrId).Select("*").Find(&tmrGearList)
|
|
|
+ if err != nil {
|
|
|
+ return nil, xerr.WithStack(err)
|
|
|
+ }
|
|
|
+ return tmrGearList, nil
|
|
|
+}
|