|
@@ -12,11 +12,8 @@ import (
|
|
"time"
|
|
"time"
|
|
"tmr-watch/conf/setting"
|
|
"tmr-watch/conf/setting"
|
|
"tmr-watch/http/handle/restful"
|
|
"tmr-watch/http/handle/restful"
|
|
- "tmr-watch/pkg/app"
|
|
|
|
- "tmr-watch/pkg/e"
|
|
|
|
"tmr-watch/pkg/logging"
|
|
"tmr-watch/pkg/logging"
|
|
|
|
|
|
- "github.com/Anderson-Lu/gofasion/gofasion"
|
|
|
|
"github.com/astaxie/beego/logs"
|
|
"github.com/astaxie/beego/logs"
|
|
"github.com/robfig/cron"
|
|
"github.com/robfig/cron"
|
|
"github.com/xormplus/xorm"
|
|
"github.com/xormplus/xorm"
|
|
@@ -585,30 +582,32 @@ func syncBar(token, pastureid string) {
|
|
for _, item := range dataList {
|
|
for _, item := range dataList {
|
|
arg := item.(map[string]interface{})
|
|
arg := item.(map[string]interface{})
|
|
fmt.Println(arg)
|
|
fmt.Println(arg)
|
|
|
|
+ // arg["sheepCount"] = 150
|
|
_, err := tx.Exec(` insert into bar(pen,bname,bcode,pastureid)values(?,?,?,?) ON DUPLICATE KEY UPDATE pen = ? `, arg["districtName"],
|
|
_, err := tx.Exec(` insert into bar(pen,bname,bcode,pastureid)values(?,?,?,?) ON DUPLICATE KEY UPDATE pen = ? `, arg["districtName"],
|
|
fmt.Sprintf("%v-%v", arg["houseName"], arg["compartmentName"]), fmt.Sprintf("%v-%v", arg["houseName"], arg["compartmentName"]), pastureid, arg["houseName"])
|
|
fmt.Sprintf("%v-%v", arg["houseName"], arg["compartmentName"]), fmt.Sprintf("%v-%v", arg["houseName"], arg["compartmentName"]), pastureid, arg["houseName"])
|
|
fmt.Println(err)
|
|
fmt.Println(err)
|
|
|
|
|
|
insertSql := `insert into feedp(pastureid,barname,barid,ccount)VALUES(?,?,(select id from bar where bname = ?),?)
|
|
insertSql := `insert into feedp(pastureid,barname,barid,ccount)VALUES(?,?,(select id from bar where bname = ?),?)
|
|
ON DUPLICATE KEY UPDATE ccount = ? ,barname = ? `
|
|
ON DUPLICATE KEY UPDATE ccount = ? ,barname = ? `
|
|
- tx.SQL(insertSql, pastureid, fmt.Sprintf("%v-%v", arg["houseName"], arg["compartmentName"]),
|
|
|
|
|
|
+ _, err = tx.SQL(insertSql, pastureid, fmt.Sprintf("%v-%v", arg["houseName"], arg["compartmentName"]),
|
|
fmt.Sprintf("%v-%v", arg["houseName"], arg["compartmentName"]), arg["sheepCount"], arg["sheepCount"],
|
|
fmt.Sprintf("%v-%v", arg["houseName"], arg["compartmentName"]), arg["sheepCount"], arg["sheepCount"],
|
|
fmt.Sprintf("%v-%v", arg["houseName"], arg["compartmentName"])).Execute()
|
|
fmt.Sprintf("%v-%v", arg["houseName"], arg["compartmentName"])).Execute()
|
|
-
|
|
|
|
- tx.SQL(` select from feedp where barname = ? `)
|
|
|
|
|
|
+ fmt.Println(err)
|
|
|
|
+ // tx.SQL(` select from feedp where barname = ? `)
|
|
|
|
|
|
// barList := make([]*bar,0)
|
|
// barList := make([]*bar,0)
|
|
b := new(bar)
|
|
b := new(bar)
|
|
// b.BarName = fmt.Sprintf("%v-%v", arg["houseName"], arg["compartmentName"])
|
|
// b.BarName = fmt.Sprintf("%v-%v", arg["houseName"], arg["compartmentName"])
|
|
// b.Ccount = arg["sheepCount"]
|
|
// b.Ccount = arg["sheepCount"]
|
|
- err = tx.SQL(`select fp.barname,fp.ccount,ratio,ft.tname ftname,(select tratio from fpdetail where barid = fp.barid and times = 1 ) times1,
|
|
|
|
-(select tratio from fpdetail where barid = fp.barid and times = 2 ) times2 ,
|
|
|
|
-(select tratio from fpdetail where barid = fp.barid and times = 3 ) times3 ,
|
|
|
|
-(select tratio from fpdetail where barid = fp.barid and times = 4 ) times4 ,
|
|
|
|
-(select tratio from fpdetail where barid = fp.barid and times =5 ) times5 ,
|
|
|
|
-(select tratio from fpdetail where barid = fp.barid and times =6 ) times6
|
|
|
|
- from feedp fp join feedtemplet ft on ft.id = fp.ftid where ratio > 0 and fp.barname = ? `, fmt.Sprintf("%v-%v", arg["houseName"], arg["compartmentName"])).GetFirst(&b).Error
|
|
|
|
-
|
|
|
|
|
|
+ err = tx.SQL(` select fp.barname,fp.ccount,ratio,ft.tname ftname,ifnull((select tratio from fpdetail where barid = fp.barid and times = 1 ),0) times1,
|
|
|
|
+ ifnull((select tratio from fpdetail where barid = fp.barid and times = 2 ),0) times2 ,
|
|
|
|
+ ifnull((select tratio from fpdetail where barid = fp.barid and times = 3 ),0) times3 ,
|
|
|
|
+ ifnull((select tratio from fpdetail where barid = fp.barid and times = 4 ),0) times4 ,
|
|
|
|
+ ifnull((select tratio from fpdetail where barid = fp.barid and times =5 ),0) times5 ,
|
|
|
|
+ ifnull((select tratio from fpdetail where barid = fp.barid and times =6 ),0) times6
|
|
|
|
+ from feedp fp join feedtemplet ft on ft.id = fp.ftid where ratio > 0 and fp.barname = ? `, fmt.Sprintf("%v-%v", arg["houseName"], arg["compartmentName"])).GetFirst(b).Error
|
|
|
|
+ fmt.Println(err)
|
|
|
|
+ fpdBatchEdit(pastureid, b)
|
|
// {"pastureId":"1653271339","barList":[{"barname":"14","ccount":155,"ratio":"100.00","ftname":"高产2配方",
|
|
// {"pastureId":"1653271339","barList":[{"barname":"14","ccount":155,"ratio":"100.00","ftname":"高产2配方",
|
|
// "times1":"41","times2":"25","times3":"25","times4":0,"times5":0,"times6":0}]}
|
|
// "times1":"41","times2":"25","times3":"25","times4":0,"times5":0,"times6":0}]}
|
|
|
|
|
|
@@ -616,19 +615,19 @@ func syncBar(token, pastureid string) {
|
|
}
|
|
}
|
|
|
|
|
|
type bar struct {
|
|
type bar struct {
|
|
- BarName string `xorm:"barname" json:"barname"`
|
|
|
|
- Ccount string `xorm:"ccount" json:"ccount"`
|
|
|
|
- Ratio string `xorm:"ratio" json:"ratio"`
|
|
|
|
- Ftname string `xorm:"ftname" json:"ftname"`
|
|
|
|
- Times1 int64 `xorm:"times1" json:"times1"`
|
|
|
|
- Times2 int64 `xorm:"times2" json:"times2"`
|
|
|
|
- Times3 int64 `xorm:"times3" json:"times3"`
|
|
|
|
- Times4 int64 `xorm:"times4" json:"times4"`
|
|
|
|
- Times5 int64 `xorm:"times5" json:"times5"`
|
|
|
|
- Times6 int64 `xorm:"times6" json:"times6"`
|
|
|
|
|
|
+ BarName string `xorm:"barname"`
|
|
|
|
+ Ccount string `xorm:"ccount"`
|
|
|
|
+ Ratio string `xorm:"ratio"`
|
|
|
|
+ Ftname string `xorm:"ftname"`
|
|
|
|
+ Times1 float64 `xorm:"times1"`
|
|
|
|
+ Times2 float64 `xorm:"times2"`
|
|
|
|
+ Times3 float64 `xorm:"times3"`
|
|
|
|
+ Times4 float64 `xorm:"times4"`
|
|
|
|
+ Times5 float64 `xorm:"times5"`
|
|
|
|
+ Times6 float64 `xorm:"times6"`
|
|
}
|
|
}
|
|
|
|
|
|
-func fpdBatchEdit(pastureid string ,b *bar) {
|
|
|
|
|
|
+func fpdBatchEdit(pastureid string, b *bar) {
|
|
|
|
|
|
// appG := app.Gin{C: c}
|
|
// appG := app.Gin{C: c}
|
|
// dataByte, _ := ioutil.ReadAll(c.Request.Body)
|
|
// dataByte, _ := ioutil.ReadAll(c.Request.Body)
|
|
@@ -648,285 +647,258 @@ func fpdBatchEdit(pastureid string ,b *bar) {
|
|
|
|
|
|
// for _, barFsions := range barList {
|
|
// for _, barFsions := range barList {
|
|
|
|
|
|
- dataexcel := make(map[string]interface{}, 0)
|
|
|
|
- dataexcel["barname"] =b.BarName
|
|
|
|
- dataexcel["ccount"] = b.Ccount
|
|
|
|
- dataexcel["ratio"] = b.Ratio
|
|
|
|
- dataexcel["ftname"] = b.Ftname
|
|
|
|
- // dataexcel["ptsfname"] = barFsions.Get("ptsfname").ValueStr()
|
|
|
|
- if dataexcel["ftname"] == "" || dataexcel["ccount"] == "0" || dataexcel["ratio"] == "0" {
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
|
|
+ dataexcel := make(map[string]interface{}, 0)
|
|
|
|
+ dataexcel["barname"] = b.BarName
|
|
|
|
+ dataexcel["ccount"] = b.Ccount
|
|
|
|
+ dataexcel["ratio"] = b.Ratio
|
|
|
|
+ dataexcel["ftname"] = b.Ftname
|
|
|
|
+ // dataexcel["ptsfname"] = barFsions.Get("ptsfname").ValueStr()
|
|
|
|
+ if dataexcel["ftname"] == "" || dataexcel["ccount"] == "0" || dataexcel["ratio"] == "0" {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
|
|
- dataexcel["1"] = b.Times1
|
|
|
|
- dataexcel["2"] = b.Times2
|
|
|
|
- dataexcel["3"] = b.Times3
|
|
|
|
- dataexcel["4"] = b.Times4
|
|
|
|
- dataexcel["5"] = b.Times5
|
|
|
|
- dataexcel["6"] = b.Times6
|
|
|
|
|
|
+ dataexcel["1"] = b.Times1
|
|
|
|
+ dataexcel["2"] = b.Times2
|
|
|
|
+ dataexcel["3"] = b.Times3
|
|
|
|
+ dataexcel["4"] = b.Times4
|
|
|
|
+ dataexcel["5"] = b.Times5
|
|
|
|
+ dataexcel["6"] = b.Times6
|
|
|
|
|
|
- ftexist, err := tx.SQL(` select id from feedp where barname = ? and pastureid = ? and ftname = ? `, dataexcel["barname"], pastureid, dataexcel["ftname"]).Exist()
|
|
|
|
|
|
+ ftexist, err := tx.SQL(` select id from feedp where barname = ? and pastureid = ? and ftname = ? `, dataexcel["barname"], pastureid, dataexcel["ftname"]).Exist()
|
|
|
|
+ if err != nil {
|
|
|
|
+ logs.Error(err)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if !ftexist {
|
|
|
|
+ fmt.Println(dataexcel["barname"], pastureid, dataexcel["ftname"])
|
|
|
|
+ tx.SQL(` delete from lpplandtl1 where barname = ? and pastureid = ? `, dataexcel["barname"], pastureid).Exist()
|
|
if err != nil {
|
|
if err != nil {
|
|
logs.Error(err)
|
|
logs.Error(err)
|
|
-
|
|
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- if !ftexist {
|
|
|
|
- fmt.Println(dataexcel["barname"], pastureid, dataexcel["ftname"])
|
|
|
|
- tx.SQL(` delete from lpplandtl1 where barname = ? and pastureid = ? `, dataexcel["barname"], pastureid).Exist()
|
|
|
|
- if err != nil {
|
|
|
|
- logs.Error(err)
|
|
|
|
- appG.Response(http.StatusInternalServerError, e.ERROR, false)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- tx.SQL(` update fpdetail set ptuse = 0 where barname = ? and pastureid = ? `, dataexcel["barname"], pastureid).Exist()
|
|
|
|
- if err != nil {
|
|
|
|
- logs.Error(err)
|
|
|
|
- appG.Response(http.StatusInternalServerError, e.ERROR, false)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
|
|
+ tx.SQL(` update fpdetail set ptuse = 0 where barname = ? and pastureid = ? `, dataexcel["barname"], pastureid).Exist()
|
|
|
|
+ if err != nil {
|
|
|
|
+ logs.Error(err)
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
|
|
- exist, err := tx.SQL(` select id from feedp where barname = ? and pastureid = ? `, dataexcel["barname"], pastureid).Exist()
|
|
|
|
|
|
+ exist, err := tx.SQL(` select id from feedp where barname = ? and pastureid = ? `, dataexcel["barname"], pastureid).Exist()
|
|
|
|
+ if err != nil {
|
|
|
|
+ logs.Error(err)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if !exist {
|
|
|
|
+ _, err := tx.SQL(` insert into feedp(pastureid,barid,barname,ccount)values(?,(select id from bar where bname = ? and pastureid = ? ),?,?) `,
|
|
|
|
+ pastureid, dataexcel["barname"], pastureid, dataexcel["barname"], 0).Execute()
|
|
if err != nil {
|
|
if err != nil {
|
|
logs.Error(err)
|
|
logs.Error(err)
|
|
- appG.Response(http.StatusInternalServerError, e.ERROR, false)
|
|
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- if !exist {
|
|
|
|
- _, err := tx.SQL(` insert into feedp(pastureid,barid,barname,ccount)values(?,(select id from bar where bname = ? and pastureid = ? ),?,?) `,
|
|
|
|
- pastureid, dataexcel["barname"], pastureid, dataexcel["barname"], 0).Execute()
|
|
|
|
- if err != nil {
|
|
|
|
- logs.Error(err)
|
|
|
|
- appG.Response(http.StatusInternalServerError, e.ERROR, false)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- var feedpargs []interface{}
|
|
|
|
- upFeedpSql := `update feedp set ccount = ? ,ratio = ? ,ccountratio = ?*(?*0.01) `
|
|
|
|
- feedpargs = append(feedpargs, dataexcel["ccount"], dataexcel["ratio"], dataexcel["ccount"], dataexcel["ratio"])
|
|
|
|
- if _, ok := dataexcel["ftname"]; ok {
|
|
|
|
- feedpargs = append(feedpargs, dataexcel["ftname"], pastureid, dataexcel["ftname"])
|
|
|
|
- upFeedpSql += ` , ftid = (select id from feedtemplet where tname = ? and pastureid = ? ),ftname = ? `
|
|
|
|
|
|
+ var feedpargs []interface{}
|
|
|
|
+ upFeedpSql := `update feedp set ccount = ? ,ratio = ? ,ccountratio = ?*(?*0.01) `
|
|
|
|
+ feedpargs = append(feedpargs, dataexcel["ccount"], dataexcel["ratio"], dataexcel["ccount"], dataexcel["ratio"])
|
|
|
|
+ if _, ok := dataexcel["ftname"]; ok {
|
|
|
|
+ feedpargs = append(feedpargs, dataexcel["ftname"], pastureid, dataexcel["ftname"])
|
|
|
|
+ upFeedpSql += ` , ftid = (select id from feedtemplet where tname = ? and pastureid = ? ),ftname = ? `
|
|
|
|
|
|
- upFeedpSql += `,ftweight = (select sum(fweight) fweight from ftdetail
|
|
|
|
|
|
+ upFeedpSql += `,ftweight = (select sum(fweight) fweight from ftdetail
|
|
where ftid = (select id from feedtemplet where tname = ? and pastureid = ? )) * (?*(?*0.01)) `
|
|
where ftid = (select id from feedtemplet where tname = ? and pastureid = ? )) * (?*(?*0.01)) `
|
|
- feedpargs = append(feedpargs, dataexcel["ftname"], pastureid, dataexcel["ccount"], dataexcel["ratio"])
|
|
|
|
- } else {
|
|
|
|
- upFeedpSql += ` , ftid = -1,ftname = '' ,ftweight = 0 `
|
|
|
|
- }
|
|
|
|
|
|
+ feedpargs = append(feedpargs, dataexcel["ftname"], pastureid, dataexcel["ccount"], dataexcel["ratio"])
|
|
|
|
+ } else {
|
|
|
|
+ upFeedpSql += ` , ftid = -1,ftname = '' ,ftweight = 0 `
|
|
|
|
+ }
|
|
|
|
|
|
- if _, ok := dataexcel["ptsfname"]; ok {
|
|
|
|
- feedpargs = append(feedpargs, dataexcel["ptsfname"], pastureid, dataexcel["ptsfname"])
|
|
|
|
- upFeedpSql += ` , ptsfid = (select id from feedtemplet where tname = ? and pastureid = ? ),ptsfname = ? `
|
|
|
|
|
|
+ if _, ok := dataexcel["ptsfname"]; ok {
|
|
|
|
+ feedpargs = append(feedpargs, dataexcel["ptsfname"], pastureid, dataexcel["ptsfname"])
|
|
|
|
+ upFeedpSql += ` , ptsfid = (select id from feedtemplet where tname = ? and pastureid = ? ),ptsfname = ? `
|
|
|
|
|
|
- upFeedpSql += `,supplyweight = (select sum(fweight) fweight from ftdetail
|
|
|
|
|
|
+ upFeedpSql += `,supplyweight = (select sum(fweight) fweight from ftdetail
|
|
where ftid = (select id from feedtemplet where tname = ? and pastureid = ? )) * (?*(?*0.01))`
|
|
where ftid = (select id from feedtemplet where tname = ? and pastureid = ? )) * (?*(?*0.01))`
|
|
- feedpargs = append(feedpargs, dataexcel["ptsfname"], pastureid, dataexcel["ccount"], dataexcel["ratio"])
|
|
|
|
- } else {
|
|
|
|
- upFeedpSql += ` , ptsfid = -1,ptsfname = '',supplyweight = 0 `
|
|
|
|
- }
|
|
|
|
- upFeedpSql += " where barname = ? and pastureid = ? "
|
|
|
|
- feedpargs = append(feedpargs, dataexcel["barname"], pastureid)
|
|
|
|
- _, err = tx.SQL(upFeedpSql, feedpargs...).Execute()
|
|
|
|
- if err != nil {
|
|
|
|
- logs.Error(err)
|
|
|
|
- appG.Response(http.StatusInternalServerError, e.ERROR, false)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
|
|
+ feedpargs = append(feedpargs, dataexcel["ptsfname"], pastureid, dataexcel["ccount"], dataexcel["ratio"])
|
|
|
|
+ } else {
|
|
|
|
+ upFeedpSql += ` , ptsfid = -1,ptsfname = '',supplyweight = 0 `
|
|
|
|
+ }
|
|
|
|
+ upFeedpSql += " where barname = ? and pastureid = ? "
|
|
|
|
+ feedpargs = append(feedpargs, dataexcel["barname"], pastureid)
|
|
|
|
+ _, err = tx.SQL(upFeedpSql, feedpargs...).Execute()
|
|
|
|
+ if err != nil {
|
|
|
|
+ logs.Error(err)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
|
|
- exist1, err := tx.SQL(` select id from fpdetail where barname = ? and pastureid = ? and times = 1 `, dataexcel["barname"], pastureid).Exist()
|
|
|
|
|
|
+ exist1, err := tx.SQL(` select id from fpdetail where barname = ? and pastureid = ? and times = 1 `, dataexcel["barname"], pastureid).Exist()
|
|
|
|
+ if err != nil {
|
|
|
|
+ logs.Error(err)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if !exist1 {
|
|
|
|
+ _, err := tx.SQL(` insert into fpdetail(pastureid,barid,barname,times,ptuse,ptsuse,ptsrate,ptsid,ptid)values(?,(select id from bar where bname = ? and pastureid = ? ),?,1,0,0,0,-1,-1) `,
|
|
|
|
+ pastureid, dataexcel["barname"], pastureid, dataexcel["barname"]).Execute()
|
|
if err != nil {
|
|
if err != nil {
|
|
logs.Error(err)
|
|
logs.Error(err)
|
|
- appG.Response(http.StatusInternalServerError, e.ERROR, false)
|
|
|
|
return
|
|
return
|
|
}
|
|
}
|
|
-
|
|
|
|
- if !exist1 {
|
|
|
|
- _, err := tx.SQL(` insert into fpdetail(pastureid,barid,barname,times,ptuse,ptsuse,ptsrate,ptsid,ptid)values(?,(select id from bar where bname = ? and pastureid = ? ),?,1,0,0,0,-1,-1) `,
|
|
|
|
- pastureid, dataexcel["barname"], pastureid, dataexcel["barname"]).Execute()
|
|
|
|
- if err != nil {
|
|
|
|
- logs.Error(err)
|
|
|
|
- appG.Response(http.StatusInternalServerError, e.ERROR, false)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- exist2, err := tx.SQL(` select id from fpdetail where barname = ? and pastureid = ? and times = 2 `, dataexcel["barname"], pastureid).Exist()
|
|
|
|
|
|
+ }
|
|
|
|
+ exist2, err := tx.SQL(` select id from fpdetail where barname = ? and pastureid = ? and times = 2 `, dataexcel["barname"], pastureid).Exist()
|
|
|
|
+ if err != nil {
|
|
|
|
+ logs.Error(err)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if !exist2 {
|
|
|
|
+ _, err = tx.SQL(` insert into fpdetail(pastureid,barid,barname,times,ptuse,ptsuse,ptsrate,ptsid,ptid)values(?,(select id from bar where bname = ? and pastureid = ? ),?,2,0,0,0,-1,-1) `,
|
|
|
|
+ pastureid, dataexcel["barname"], pastureid, dataexcel["barname"]).Execute()
|
|
if err != nil {
|
|
if err != nil {
|
|
logs.Error(err)
|
|
logs.Error(err)
|
|
- appG.Response(http.StatusInternalServerError, e.ERROR, false)
|
|
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- if !exist2 {
|
|
|
|
- _, err = tx.SQL(` insert into fpdetail(pastureid,barid,barname,times,ptuse,ptsuse,ptsrate,ptsid,ptid)values(?,(select id from bar where bname = ? and pastureid = ? ),?,2,0,0,0,-1,-1) `,
|
|
|
|
- pastureid, dataexcel["barname"], pastureid, dataexcel["barname"]).Execute()
|
|
|
|
- if err != nil {
|
|
|
|
- logs.Error(err)
|
|
|
|
- appG.Response(http.StatusInternalServerError, e.ERROR, false)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- exist3, err := tx.SQL(` select id from fpdetail where barname = ? and pastureid = ? and times =3 `, dataexcel["barname"], pastureid).Exist()
|
|
|
|
|
|
+ exist3, err := tx.SQL(` select id from fpdetail where barname = ? and pastureid = ? and times =3 `, dataexcel["barname"], pastureid).Exist()
|
|
|
|
+ if err != nil {
|
|
|
|
+ logs.Error(err)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if !exist3 {
|
|
|
|
+ _, err = tx.SQL(` insert into fpdetail(pastureid,barid,barname,times,ptuse,ptsuse,ptsrate,ptsid,ptid)values(?,(select id from bar where bname = ? and pastureid = ? ),?,3,0,0,0,-1,-1) `,
|
|
|
|
+ pastureid, dataexcel["barname"], pastureid, dataexcel["barname"]).Execute()
|
|
if err != nil {
|
|
if err != nil {
|
|
logs.Error(err)
|
|
logs.Error(err)
|
|
- appG.Response(http.StatusInternalServerError, e.ERROR, false)
|
|
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- if !exist3 {
|
|
|
|
- _, err = tx.SQL(` insert into fpdetail(pastureid,barid,barname,times,ptuse,ptsuse,ptsrate,ptsid,ptid)values(?,(select id from bar where bname = ? and pastureid = ? ),?,3,0,0,0,-1,-1) `,
|
|
|
|
- pastureid, dataexcel["barname"], pastureid, dataexcel["barname"]).Execute()
|
|
|
|
- if err != nil {
|
|
|
|
- logs.Error(err)
|
|
|
|
- appG.Response(http.StatusInternalServerError, e.ERROR, false)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- exist4, err := tx.SQL(` select id from fpdetail where barname = ? and pastureid = ? and times = 4 `, dataexcel["barname"], pastureid).Exist()
|
|
|
|
|
|
+ }
|
|
|
|
+ exist4, err := tx.SQL(` select id from fpdetail where barname = ? and pastureid = ? and times = 4 `, dataexcel["barname"], pastureid).Exist()
|
|
|
|
+ if err != nil {
|
|
|
|
+ logs.Error(err)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if !exist4 {
|
|
|
|
+ _, err = tx.SQL(` insert into fpdetail(pastureid,barid,barname,times,ptuse,ptsuse,ptsrate,ptsid,ptid)values(?,(select id from bar where bname = ? and pastureid = ? ),?,4,0,0,0,-1,-1) `,
|
|
|
|
+ pastureid, dataexcel["barname"], pastureid, dataexcel["barname"]).Execute()
|
|
if err != nil {
|
|
if err != nil {
|
|
logs.Error(err)
|
|
logs.Error(err)
|
|
- appG.Response(http.StatusInternalServerError, e.ERROR, false)
|
|
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- if !exist4 {
|
|
|
|
- _, err = tx.SQL(` insert into fpdetail(pastureid,barid,barname,times,ptuse,ptsuse,ptsrate,ptsid,ptid)values(?,(select id from bar where bname = ? and pastureid = ? ),?,4,0,0,0,-1,-1) `,
|
|
|
|
- pastureid, dataexcel["barname"], pastureid, dataexcel["barname"]).Execute()
|
|
|
|
- if err != nil {
|
|
|
|
- logs.Error(err)
|
|
|
|
- appG.Response(http.StatusInternalServerError, e.ERROR, false)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- exist5, err := tx.SQL(` select id from fpdetail where barname = ? and pastureid = ? and times = 5 `, dataexcel["barname"], pastureid).Exist()
|
|
|
|
|
|
+ }
|
|
|
|
+ exist5, err := tx.SQL(` select id from fpdetail where barname = ? and pastureid = ? and times = 5 `, dataexcel["barname"], pastureid).Exist()
|
|
|
|
+ if err != nil {
|
|
|
|
+ logs.Error(err)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if !exist5 {
|
|
|
|
+ _, err = tx.SQL(` insert into fpdetail(pastureid,barid,barname,times,ptuse,ptsuse,ptsrate,ptsid,ptid)values(?,(select id from bar where bname = ? and pastureid = ? ),?,5,0,0,0,-1,-1) `,
|
|
|
|
+ pastureid, dataexcel["barname"], pastureid, dataexcel["barname"]).Execute()
|
|
if err != nil {
|
|
if err != nil {
|
|
logs.Error(err)
|
|
logs.Error(err)
|
|
- appG.Response(http.StatusInternalServerError, e.ERROR, false)
|
|
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- if !exist5 {
|
|
|
|
- _, err = tx.SQL(` insert into fpdetail(pastureid,barid,barname,times,ptuse,ptsuse,ptsrate,ptsid,ptid)values(?,(select id from bar where bname = ? and pastureid = ? ),?,5,0,0,0,-1,-1) `,
|
|
|
|
- pastureid, dataexcel["barname"], pastureid, dataexcel["barname"]).Execute()
|
|
|
|
- if err != nil {
|
|
|
|
- logs.Error(err)
|
|
|
|
- appG.Response(http.StatusInternalServerError, e.ERROR, false)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- exist6, err := tx.SQL(` select id from fpdetail where barname = ? and pastureid = ? and times = 6 `, dataexcel["barname"], pastureid).Exist()
|
|
|
|
|
|
+ }
|
|
|
|
+ exist6, err := tx.SQL(` select id from fpdetail where barname = ? and pastureid = ? and times = 6 `, dataexcel["barname"], pastureid).Exist()
|
|
|
|
+ if err != nil {
|
|
|
|
+ logs.Error(err)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if !exist6 {
|
|
|
|
+ _, err = tx.SQL(` insert into fpdetail(pastureid,barid,barname,times,ptuse,ptsuse,ptsrate,ptsid,ptid)values(?,(select id from bar where bname = ? and pastureid = ? ),?,6,0,0,0,-1,-1) `,
|
|
|
|
+ pastureid, dataexcel["barname"], pastureid, dataexcel["barname"]).Execute()
|
|
if err != nil {
|
|
if err != nil {
|
|
logs.Error(err)
|
|
logs.Error(err)
|
|
- appG.Response(http.StatusInternalServerError, e.ERROR, false)
|
|
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- if !exist6 {
|
|
|
|
- _, err = tx.SQL(` insert into fpdetail(pastureid,barid,barname,times,ptuse,ptsuse,ptsrate,ptsid,ptid)values(?,(select id from bar where bname = ? and pastureid = ? ),?,6,0,0,0,-1,-1) `,
|
|
|
|
- pastureid, dataexcel["barname"], pastureid, dataexcel["barname"]).Execute()
|
|
|
|
- if err != nil {
|
|
|
|
- logs.Error(err)
|
|
|
|
- appG.Response(http.StatusInternalServerError, e.ERROR, false)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- upFpdSql := ` update fpdetail set tratio = ? ,weight = (? *0.01) * ((select sum(fweight) fweight from ftdetail
|
|
|
|
|
|
+ upFpdSql := ` update fpdetail set tratio = ? ,weight = (? *0.01) * ((select sum(fweight) fweight from ftdetail
|
|
where ftid = (select id from feedtemplet where tname = ? and pastureid = ? )) * (?*(?*0.01))) ,cowcount = ? ,
|
|
where ftid = (select id from feedtemplet where tname = ? and pastureid = ? )) * (?*(?*0.01))) ,cowcount = ? ,
|
|
ccountradio= ?,ptid= (select id from feedtemplet where tname = ? and pastureid = ? ) where barname = ?
|
|
ccountradio= ?,ptid= (select id from feedtemplet where tname = ? and pastureid = ? ) where barname = ?
|
|
and pastureid = ? and times = ?`
|
|
and pastureid = ? and times = ?`
|
|
- var fpdargs1 []interface{}
|
|
|
|
- fpdargs1 = append(fpdargs1, dataexcel["1"], dataexcel["1"], dataexcel["ftname"], pastureid,
|
|
|
|
- dataexcel["ccount"], dataexcel["ratio"], dataexcel["ccount"], dataexcel["ratio"],
|
|
|
|
- dataexcel["ftname"], pastureid, dataexcel["barname"], pastureid, 1)
|
|
|
|
- _, err = tx.SQL(upFpdSql, fpdargs1...).Execute()
|
|
|
|
- if err != nil {
|
|
|
|
- appG.Response(http.StatusInternalServerError, e.ERROR, false)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
|
|
+ var fpdargs1 []interface{}
|
|
|
|
+ fpdargs1 = append(fpdargs1, dataexcel["1"], dataexcel["1"], dataexcel["ftname"], pastureid,
|
|
|
|
+ dataexcel["ccount"], dataexcel["ratio"], dataexcel["ccount"], dataexcel["ratio"],
|
|
|
|
+ dataexcel["ftname"], pastureid, dataexcel["barname"], pastureid, 1)
|
|
|
|
+ _, err = tx.SQL(upFpdSql, fpdargs1...).Execute()
|
|
|
|
+ if err != nil {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
|
|
- var fpdargs2 []interface{}
|
|
|
|
- fpdargs2 = append(fpdargs2, dataexcel["2"], dataexcel["2"], dataexcel["ftname"], pastureid,
|
|
|
|
- dataexcel["ccount"], dataexcel["ratio"], dataexcel["ccount"], dataexcel["ratio"],
|
|
|
|
- dataexcel["ftname"], pastureid, dataexcel["barname"], pastureid, 2)
|
|
|
|
- _, err = tx.SQL(upFpdSql, fpdargs2...).Execute()
|
|
|
|
- if err != nil {
|
|
|
|
- appG.Response(http.StatusInternalServerError, e.ERROR, false)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- var fpdargs3 []interface{}
|
|
|
|
- fpdargs3 = append(fpdargs3, dataexcel["3"], dataexcel["3"], dataexcel["ftname"], pastureid,
|
|
|
|
- dataexcel["ccount"], dataexcel["ratio"], dataexcel["ccount"], dataexcel["ratio"],
|
|
|
|
- dataexcel["ftname"], pastureid, dataexcel["barname"], pastureid, 3)
|
|
|
|
- _, err = tx.SQL(upFpdSql, fpdargs3...).Execute()
|
|
|
|
- if err != nil {
|
|
|
|
- appG.Response(http.StatusInternalServerError, e.ERROR, false)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- var fpdargs4 []interface{}
|
|
|
|
- fpdargs4 = append(fpdargs4, dataexcel["4"], dataexcel["4"], dataexcel["ftname"], pastureid,
|
|
|
|
- dataexcel["ccount"], dataexcel["ratio"], dataexcel["ccount"], dataexcel["ratio"],
|
|
|
|
- dataexcel["ftname"], pastureid, dataexcel["barname"], pastureid, 4)
|
|
|
|
- _, err = tx.SQL(upFpdSql, fpdargs4...).Execute()
|
|
|
|
- if err != nil {
|
|
|
|
- appG.Response(http.StatusInternalServerError, e.ERROR, false)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
|
|
+ var fpdargs2 []interface{}
|
|
|
|
+ fpdargs2 = append(fpdargs2, dataexcel["2"], dataexcel["2"], dataexcel["ftname"], pastureid,
|
|
|
|
+ dataexcel["ccount"], dataexcel["ratio"], dataexcel["ccount"], dataexcel["ratio"],
|
|
|
|
+ dataexcel["ftname"], pastureid, dataexcel["barname"], pastureid, 2)
|
|
|
|
+ _, err = tx.SQL(upFpdSql, fpdargs2...).Execute()
|
|
|
|
+ if err != nil {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ var fpdargs3 []interface{}
|
|
|
|
+ fpdargs3 = append(fpdargs3, dataexcel["3"], dataexcel["3"], dataexcel["ftname"], pastureid,
|
|
|
|
+ dataexcel["ccount"], dataexcel["ratio"], dataexcel["ccount"], dataexcel["ratio"],
|
|
|
|
+ dataexcel["ftname"], pastureid, dataexcel["barname"], pastureid, 3)
|
|
|
|
+ _, err = tx.SQL(upFpdSql, fpdargs3...).Execute()
|
|
|
|
+ if err != nil {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ var fpdargs4 []interface{}
|
|
|
|
+ fpdargs4 = append(fpdargs4, dataexcel["4"], dataexcel["4"], dataexcel["ftname"], pastureid,
|
|
|
|
+ dataexcel["ccount"], dataexcel["ratio"], dataexcel["ccount"], dataexcel["ratio"],
|
|
|
|
+ dataexcel["ftname"], pastureid, dataexcel["barname"], pastureid, 4)
|
|
|
|
+ _, err = tx.SQL(upFpdSql, fpdargs4...).Execute()
|
|
|
|
+ if err != nil {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
|
|
- var fpdargs5 []interface{}
|
|
|
|
- fpdargs5 = append(fpdargs5, dataexcel["5"], dataexcel["5"], dataexcel["ftname"], pastureid,
|
|
|
|
- dataexcel["ccount"], dataexcel["ratio"], dataexcel["ccount"], dataexcel["ratio"],
|
|
|
|
- dataexcel["ftname"], pastureid, dataexcel["barname"], pastureid, 5)
|
|
|
|
- _, err = tx.SQL(upFpdSql, fpdargs5...).Execute()
|
|
|
|
- if err != nil {
|
|
|
|
- appG.Response(http.StatusInternalServerError, e.ERROR, false)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
|
|
+ var fpdargs5 []interface{}
|
|
|
|
+ fpdargs5 = append(fpdargs5, dataexcel["5"], dataexcel["5"], dataexcel["ftname"], pastureid,
|
|
|
|
+ dataexcel["ccount"], dataexcel["ratio"], dataexcel["ccount"], dataexcel["ratio"],
|
|
|
|
+ dataexcel["ftname"], pastureid, dataexcel["barname"], pastureid, 5)
|
|
|
|
+ _, err = tx.SQL(upFpdSql, fpdargs5...).Execute()
|
|
|
|
+ if err != nil {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
|
|
- var fpdargs6 []interface{}
|
|
|
|
- fpdargs6 = append(fpdargs6, dataexcel["6"], dataexcel["6"], dataexcel["ftname"], pastureid,
|
|
|
|
- dataexcel["ccount"], dataexcel["ratio"], dataexcel["ccount"], dataexcel["ratio"],
|
|
|
|
- dataexcel["ftname"], pastureid, dataexcel["barname"], pastureid, 6)
|
|
|
|
- _, err = tx.SQL(upFpdSql, fpdargs6...).Execute()
|
|
|
|
- if err != nil {
|
|
|
|
- appG.Response(http.StatusInternalServerError, e.ERROR, false)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- // _, err = tx.SQL(`call updateLPPbyFPChange(?,( select id from feedp where barname = ? and pastureid = ?))`, pastureid, dataexcel["barname"], pastureid).Execute()
|
|
|
|
|
|
+ var fpdargs6 []interface{}
|
|
|
|
+ fpdargs6 = append(fpdargs6, dataexcel["6"], dataexcel["6"], dataexcel["ftname"], pastureid,
|
|
|
|
+ dataexcel["ccount"], dataexcel["ratio"], dataexcel["ccount"], dataexcel["ratio"],
|
|
|
|
+ dataexcel["ftname"], pastureid, dataexcel["barname"], pastureid, 6)
|
|
|
|
+ _, err = tx.SQL(upFpdSql, fpdargs6...).Execute()
|
|
|
|
+ if err != nil {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ // _, err = tx.SQL(`call updateLPPbyFPChange(?,( select id from feedp where barname = ? and pastureid = ?))`, pastureid, dataexcel["barname"], pastureid).Execute()
|
|
|
|
|
|
- newList, err := tx.SQL(` select ifnull(ROUND((1-ptsrate)*weight,2)-ptuse,"") fweight,id,ptid,weight,times from fpdetail where barname = ? and pastureid = ? `, dataexcel["barname"], pastureid).Query().List()
|
|
|
|
- if err != nil {
|
|
|
|
- appG.Response(http.StatusInternalServerError, e.ERROR, false)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- // oldFpdList, err := tx.SQL(` select fpd.id,fpd.barname,fpd.weight,fpd.times,fp.ftweight,fp.supplyweight from fpdetail fpd
|
|
|
|
- // join feedp fp on fp.barid = fpd.barid and fpd.pastureid = fp.pastureid where fpd.pastureid = ?`, pastureid).Query().List()
|
|
|
|
- upFpdetailList := make([]*upFpdetail, 0)
|
|
|
|
- for _, newfpd := range newList {
|
|
|
|
- for _, oldfpd := range oldFpdList {
|
|
|
|
- if oldfpd["id"].(int64) == newfpd["id"].(int64) {
|
|
|
|
- var oldweight, newweight float64
|
|
|
|
- if oldfpd["weight"] != nil {
|
|
|
|
- oldweight, _ = strconv.ParseFloat(oldfpd["weight"].(string), 64)
|
|
|
|
- }
|
|
|
|
- if newfpd["weight"] != nil {
|
|
|
|
- newweight, _ = strconv.ParseFloat(newfpd["weight"].(string), 64)
|
|
|
|
- }
|
|
|
|
- fweight, _ := strconv.ParseFloat(newfpd["fweight"].(string), 64)
|
|
|
|
- upFpdetailList = append(upFpdetailList, &upFpdetail{
|
|
|
|
- Old: oldweight,
|
|
|
|
- New: newweight,
|
|
|
|
- Times: newfpd["times"].(int64),
|
|
|
|
- Ptid: newfpd["ptid"].(int64),
|
|
|
|
- Fweight: fweight,
|
|
|
|
- Id: oldfpd["id"].(int64),
|
|
|
|
- })
|
|
|
|
- break
|
|
|
|
|
|
+ newList, err := tx.SQL(` select ifnull(ROUND((1-ptsrate)*weight,2)-ptuse,"") fweight,id,ptid,weight,times from fpdetail where barname = ? and pastureid = ? `, dataexcel["barname"], pastureid).Query().List()
|
|
|
|
+ if err != nil {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ // oldFpdList, err := tx.SQL(` select fpd.id,fpd.barname,fpd.weight,fpd.times,fp.ftweight,fp.supplyweight from fpdetail fpd
|
|
|
|
+ // join feedp fp on fp.barid = fpd.barid and fpd.pastureid = fp.pastureid where fpd.pastureid = ?`, pastureid).Query().List()
|
|
|
|
+ upFpdetailList := make([]*upFpdetail, 0)
|
|
|
|
+ for _, newfpd := range newList {
|
|
|
|
+ for _, oldfpd := range oldFpdList {
|
|
|
|
+ if oldfpd["id"].(int64) == newfpd["id"].(int64) {
|
|
|
|
+ var oldweight, newweight float64
|
|
|
|
+ if oldfpd["weight"] != nil {
|
|
|
|
+ oldweight, _ = strconv.ParseFloat(oldfpd["weight"].(string), 64)
|
|
}
|
|
}
|
|
|
|
+ if newfpd["weight"] != nil {
|
|
|
|
+ newweight, _ = strconv.ParseFloat(newfpd["weight"].(string), 64)
|
|
|
|
+ }
|
|
|
|
+ fweight, _ := strconv.ParseFloat(newfpd["fweight"].(string), 64)
|
|
|
|
+ upFpdetailList = append(upFpdetailList, &upFpdetail{
|
|
|
|
+ Old: oldweight,
|
|
|
|
+ New: newweight,
|
|
|
|
+ Times: newfpd["times"].(int64),
|
|
|
|
+ Ptid: newfpd["ptid"].(int64),
|
|
|
|
+ Fweight: fweight,
|
|
|
|
+ Id: oldfpd["id"].(int64),
|
|
|
|
+ })
|
|
|
|
+ break
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
|
|
- updateFpdetailByBar(pastureid, dataexcel["barname"].(string), upFpdetailList)
|
|
|
|
- // }
|
|
|
|
- appG.Response(http.StatusOK, e.SUCCESS, "ok")
|
|
|
|
|
|
+ updateFpdetailByBar(pastureid, dataexcel["barname"].(string), upFpdetailList)
|
|
}
|
|
}
|
|
|
|
|
|
type lpplandtlInfo struct {
|
|
type lpplandtlInfo struct {
|