Browse Source

撒料计划查询优化

bsj 3 years ago
parent
commit
e3c9ffd94b
2 changed files with 149 additions and 0 deletions
  1. 148 0
      routers/api/spillage.go
  2. 1 0
      routers/router.go

+ 148 - 0
routers/api/spillage.go

@@ -739,3 +739,151 @@ func autogeneration(typeIN int64, pastureid string, tx *xorm.Session) error {
 	}
 	return nil
 }
+
+func GetSpillage(c *gin.Context) {
+	appG := app.Gin{C: c}
+	dataByte, _ := ioutil.ReadAll(c.Request.Body)
+	fsion := gofasion.NewFasion(string(dataByte))
+	parammaps := fsion.Get("parammaps")
+	pastureid := parammaps.Get("pastureid").ValueInt64()
+	times := parammaps.Get("times").ValueInt64()
+
+	refresh := parammaps.Get("refresh").ValueInt64()
+	fmt.Println(pastureid, times)
+	tx := restful.Engine.NewSession()
+	defer tx.Close()
+
+	data := make(map[string]interface{})
+
+	if refresh == 0 || refresh == 2 {
+
+		ftList, err := tx.SQL(`SELECT trim(feedp.pastureid) pastureid,barname,trim(barid) barid,trim(ftid) arrid,1 as type,? as times,ft.tname ftname,ft.tcolor  background,0 isfill FROM feedp 
+		inner join  feedtemplet ft
+	on ft.id = feedp.ftid and  ft.pastureid=?
+	WHERE feedp.pastureid = ?
+	GROUP BY feedp.ftid
+	UNION
+	SELECT trim(feedp.pastureid) pastureid,barname,barid,trim(ptsfid) arrid,0 as type,? as times,ft.tname ptsfname ,ft.tcolor  background,1 isfill  FROM feedp
+	inner join  feedtemplet ft
+	on ft.id = feedp.ptsfid and  ft.pastureid=?
+	WHERE feedp.pastureid = ?  and  (SELECT inforvalue FROM sysopt WHERE sysopt.pastureid=feedp.pastureid AND sysopt.inforname= 'isEnableSupplyFeed') = 1
+	GROUP BY feedp.ptsfid`, times, pastureid, pastureid, times, pastureid, pastureid).Query().List()
+		if err != nil {
+			log.Println("GetSpillage-error-1: ", err)
+			appG.Response(http.StatusOK, e.ERROR, nil)
+			return
+		}
+
+		ftDetailList, err := tx.SQL(`SELECT TRIM(id) id,times,tratio,ROUND(ptsrate*weight,2)-ptsuse weight,TRIM(barid) barid,TRIM(pastureid) pastureid,TRIM(ptid) ptid,TRIM(ptsid ) ptsid ,
+	(select bname  from bar where pastureid =fpdetail.pastureid and id = fpdetail.barid ) barname,0 AS fttype,cowcount,ccountradio,1 isfill  FROM fpdetail
+	WHERE fpdetail.pastureid = ?  AND times=? AND  ptsuse< ROUND(ptsrate*weight,2) 
+	UNION
+	SELECT TRIM(id) id,times,tratio,ROUND((1-ptsrate)*weight,2)-ptuse weight,TRIM(barid) barid,TRIM(pastureid) pastureid,TRIM(ptid) ptid,TRIM(ptsid ) ptsid ,
+	(select bname  from bar where pastureid =fpdetail.pastureid and id = fpdetail.barid ) barname,1 AS fttype,cowcount,ccountradio,0 isfill  FROM fpdetail
+	WHERE fpdetail.pastureid = ?  AND times=? AND ptuse<ROUND((1-ptsrate)*weight,2)
+	ORDER BY  barid`, pastureid, times, pastureid, times).Query().List()
+		if err != nil {
+			log.Println("GetSpillage-error-2: ", err)
+			appG.Response(http.StatusOK, e.ERROR, nil)
+			return
+		}
+
+		for _, ft := range ftList {
+			arrList := make([]map[string]interface{}, 0)
+			arrid := ft["arrid"].(string)
+			for _, detail := range ftDetailList {
+				// var ptsid, ptid string
+				if _, ok := detail["ptid"]; ok {
+					if arrid == detail["ptid"].(string) && ft["isfill"].(int64) == detail["isfill"].(int64) {
+						detail["background"] = ft["background"]
+						arrList = append(arrList, detail)
+					}
+				} else if _, ok := detail["ptsid"]; ok {
+					if arrid == detail["ptsid"].(string) && ft["isfill"].(int64) == detail["isfill"].(int64) {
+						detail["background"] = ft["background"]
+						arrList = append(arrList, detail)
+					}
+				}
+
+			}
+			if len(arrList) > 0 {
+				ft["arrList"] = arrList
+			}
+		}
+
+		data["ftlist"] = ftList
+	}
+
+	if refresh == 0 || refresh == 1 {
+		lppList, err := tx.SQL(`SELECT
+	ifnull((select eqcode from tmr where pastureid =lpplan.pastureid and id = lpplan.tmrid ),lpplan.tmrname) tmrname,trim(tmrid) tmrid,sort,sel,
+	CASE times
+	WHEN 1 THEN
+	'第一班'
+WHEN 2 THEN
+'第二班'
+WHEN 3 THEN
+'第三班'
+WHEN 4 THEN
+'第四班'
+END timesstr,issplit,
+times,display,begintime,
+(select tname from feedtemplet where pastureid =lpplan.pastureid and id = lpplan.ftid ) ftname,sumcowcount,
+IFNULL(round((SELECT SUM(lpplandtl1.lweight) FROM lpplandtl1 WHERE lpplandtl1.lppid=lpplan.id),2),0) sumweight ,
+ifnull((select maxstirfeed from tmr where pastureid =lpplan.pastureid and id = lpplan.tmrid ),100000) maxweight,
+TRIM(ftid) ftid,
+TRIM(id) id,
+TRIM(id) lppid,
+TRIM(pastureid) pastureid
+
+FROM
+  lpplan
+WHERE pastureid = ?   and times <= (SELECT sysopt.inforvalue  FROM sysopt 
+ WHERE sysopt.pastureid= lpplan.pastureid  AND sysopt.inforname='times')
+ORDER BY  lpplan.sort`, pastureid).Query().List()
+		if err != nil {
+			log.Println("GetSpillage-error-3: ", err)
+			appG.Response(http.StatusOK, e.ERROR, nil)
+			return
+		}
+
+		arrList, _ := tx.SQL(`SELECT
+			trim(lpplandtl1.lppid) lppid,lweight,
+			lpplandtl1.lweight weight,lpplandtl1.sort,
+			(select bname  from bar where pastureid =lpplandtl1.pastureid and id = lpplandtl1.barid ) barname,
+			TRIM(lpplandtl1.fpdid) fpdid,
+			TRIM(lpplandtl1.barid) barid,
+			TRIM(lpplandtl1.id) id,
+			TRIM(lpplandtl1.pastureid) pastureid,
+			(SELECT tcolor FROM feedtemplet WHERE pastureid =lpplandtl1.pastureid AND id = IF(lpplandtl1.fttype=1,fpdetail.ptid,fpdetail.ptsid) ) background,
+			lpplandtl1.fttype,
+			trim(lpplandtl1.tmrid) tmrid,
+			ifnull((select eqcode  from tmr where pastureid =lpplandtl1.pastureid and id = lpplandtl1.tmrid ),lpplandtl1.tmrname) tmrname,
+			ifnull((select tcolor from tmr where pastureid =lpplandtl1.pastureid and id = lpplandtl1.tmrid ),'#ccc') tbackground,
+			fpdetail.ptid,
+			fpdetail.ptsid,
+			fpdetail.times,
+			fpdetail.cowcount,
+			fpdetail.ccountradio
+			FROM
+			  lpplandtl1
+			inner join  fpdetail
+			on  lpplandtl1.fpdid= fpdetail.id and lpplandtl1.pastureid = fpdetail.pastureid
+			WHERE lpplandtl1.pastureid = ?   and lpplandtl1.lweight>0
+			ORDER BY  lpplandtl1.sort`, pastureid).QueryString() //获取
+
+		for _, query := range lppList {
+			list := make([]map[string]string, 0)
+			for _, arr := range arrList {
+				if query["lppid"].(string) == arr["lppid"] {
+					list = append(list, arr)
+				}
+			}
+			query["arrList"] = list
+		}
+		data["list"] = lppList
+		data["total"] = len(lppList)
+	}
+
+	appG.Response(http.StatusOK, e.SUCCESS, data)
+}

+ 1 - 0
routers/router.go

@@ -109,6 +109,7 @@ func InitRouter() *gin.Engine {
 		apiV1.POST("/PostRJSBDatas", api.PostRJSBDatas)
 
 		apiV1.POST("/autogeneration", api.Autogeneration)
+		apiV1.POST("/spillage", api.GetSpillage)
 
 	}