Bläddra i källkod

撒料计划自动生成添加车次排序方式修改

bsj 2 år sedan
förälder
incheckning
da35426dc5
1 ändrade filer med 40 tillägg och 31 borttagningar
  1. 40 31
      routers/api/spillage.go

+ 40 - 31
routers/api/spillage.go

@@ -46,6 +46,7 @@ type lpplanStruct struct {
 	Sumweight   float64 `xorm:"sumweight"`
 	Sumcowcount int64   `xorm:"sumcowcount"`
 	Pastureid   string  `xorm:"pastureid"`
+	Display     string  `xorm:"display"`
 }
 
 type sysopt struct {
@@ -188,13 +189,13 @@ func Autogeneration(c *gin.Context) {
 		}
 	}
 
-	for _, tem := range *feedtempletlist {
-		count, err := getLpplanCount(tx)
-		if err != nil {
-			appG.Response(http.StatusOK, e.ERROR, false)
-			return
-		}
-		for i := 1; i <= times; i++ {
+	count, err := getLpplanCount(tx)
+	if err != nil {
+		appG.Response(http.StatusOK, e.ERROR, false)
+		return
+	}
+	for i := 1; i <= times; i++ {
+		for _, tem := range *feedtempletlist {
 			for _, fpd := range *fpdetailWeightList {
 				if tem.Id == fpd.Temid && i == int(fpd.Times) {
 					var ftid int64
@@ -212,29 +213,37 @@ func Autogeneration(c *gin.Context) {
 									ids = time.Now().UnixNano()
 									logging.Info("create SnowIds err", err)
 								}
-								wg.Add(1)
-								go func(ids int64, tmr *tmrStruct, count, i, ftid int64, tem *feedtemplet) {
-									defer wg.Done()
-									lpplan := &lpplanStruct{
-										Id:          ids,
-										Tmrname:     tmr.Tname,
-										Tmrid:       tmr.Id,
-										Sort:        count,
-										Sel:         1,
-										Times:       int64(i),
-										Ftname:      tem.Cname,
-										Ftid:        ftid,
-										Maxweight:   tmr.Maxstirfeed,
-										Sumweight:   0,
-										Sumcowcount: 0,
-										Pastureid:   pastureid,
-									}
-									err = addLpplan(lpplan, tx)
-									if err != nil {
-										appG.Response(http.StatusOK, e.ERROR, false)
-										return
-									}
-								}(ids, tmr, count, int64(i), ftid, tem)
+								display := tem.Cname
+								if i == 1 {
+									display += "第一班"
+								} else if i == 2 {
+									display += "第二班"
+								} else if i == 3 {
+									display += "第三班"
+								} else if i == 4 {
+									display += "第四班"
+								}
+
+								lpplan := &lpplanStruct{
+									Id:          ids,
+									Tmrname:     tmr.Tname,
+									Tmrid:       tmr.Id,
+									Sort:        count,
+									Sel:         1,
+									Times:       int64(i),
+									Ftname:      tem.Cname,
+									Ftid:        ftid,
+									Maxweight:   tmr.Maxstirfeed,
+									Sumweight:   0,
+									Sumcowcount: 0,
+									Pastureid:   pastureid,
+									Display:     display,
+								}
+								err = addLpplan(lpplan, tx)
+								if err != nil {
+									appG.Response(http.StatusOK, e.ERROR, false)
+									return
+								}
 								fpd.Weight = fpd.Weight - tmr.Maxstirfeed
 							}
 							if fpd.Weight < 0 {
@@ -246,7 +255,7 @@ func Autogeneration(c *gin.Context) {
 			}
 		}
 	}
-	wg.Wait()
+	// wg.Wait()
 
 	err = autogeneration(typeIN, pastureid, tx)
 	if err != nil {