|
@@ -1041,7 +1041,7 @@ func PostDataByName(c *gin.Context) {
|
|
|
var err error
|
|
|
queryData, err := module.PostDataByName(c, fsion)
|
|
|
if err != nil {
|
|
|
- appG.Response(http.StatusOK, e.ERROR, err)
|
|
|
+ appG.Response(http.StatusOK, e.ERROR, err.Error())
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -1063,6 +1063,7 @@ func PostDataByName(c *gin.Context) {
|
|
|
err = module.GroupCategoryDelete(keyWord, fsion)
|
|
|
case "updateFT":
|
|
|
FtdetailSurplus(fsion)
|
|
|
+
|
|
|
case "updateFeed":
|
|
|
FeedSurplus(fsion)
|
|
|
default:
|
|
@@ -3429,6 +3430,23 @@ func UpdateFTdetail(c *gin.Context) {
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
+ // ,,parammaps["ftid"])
|
|
|
+ // surplus, surplusId, id, pastureId string
|
|
|
+ // FtdetailSurplusFt(parammaps["ftid"].)
|
|
|
+ ftList1, err := tx.SQL(` SELECT
|
|
|
+ f.id,
|
|
|
+ f.surplus surplusId,
|
|
|
+ f.pastureid,
|
|
|
+ s.surplus
|
|
|
+FROM
|
|
|
+ feedtemplet f
|
|
|
+ JOIN surplus s ON s.id = f.surplus
|
|
|
+WHERE
|
|
|
+ f.id = ?`, parammaps["ftid"]).QueryString()
|
|
|
+
|
|
|
+ for _, ft := range ftList1 {
|
|
|
+ FtdetailSurplusFt(ft["surplus"], ft["surplusId"], ft["id"], ft["pastureid"])
|
|
|
+ }
|
|
|
|
|
|
appG.Response(http.StatusOK, e.SUCCESS, true)
|
|
|
}
|
|
@@ -8952,7 +8970,7 @@ func EditDownloadplandtl2Weight(c *gin.Context) {
|
|
|
appG.Response(http.StatusOK, e.SUCCESS, true)
|
|
|
}
|
|
|
|
|
|
-func FtdetailSurplus(fasion *gofasion.Fasion) {
|
|
|
+func FtdetailSurplus(fasion *gofasion.Fasion) error {
|
|
|
params := fasion.Get("parammaps")
|
|
|
surplus := params.Get("surplus").ValueStr()
|
|
|
surplusId := params.Get("surplusId").ValueStr()
|
|
@@ -8964,7 +8982,7 @@ func FtdetailSurplus(fasion *gofasion.Fasion) {
|
|
|
dataList, err := tx.Table("ftdetail").Where("ftid = ? ", params.Get("id").ValueStr()).QueryString()
|
|
|
if err != nil {
|
|
|
log.Println("PostDataByName-error-1: ", err)
|
|
|
- return
|
|
|
+ return errors.New("配方修改失败!")
|
|
|
}
|
|
|
|
|
|
type ftdetail struct {
|
|
@@ -8981,7 +8999,7 @@ func FtdetailSurplus(fasion *gofasion.Fasion) {
|
|
|
sort, err := strconv.ParseInt(data["sort"], 10, 64)
|
|
|
if err != nil {
|
|
|
log.Println("PostDataByName-error-2: ", err)
|
|
|
- return
|
|
|
+ return err
|
|
|
}
|
|
|
ft.Sort = sort
|
|
|
ftList = append(ftList, ft)
|
|
@@ -9003,6 +9021,7 @@ func FtdetailSurplus(fasion *gofasion.Fasion) {
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
if sort == 0 {
|
|
|
for _, ft := range ftList {
|
|
|
ft.Sort = ft.Sort + 1
|
|
@@ -9023,11 +9042,12 @@ func FtdetailSurplus(fasion *gofasion.Fasion) {
|
|
|
if err != nil {
|
|
|
log.Println("PostDataByName-error-1: ", err)
|
|
|
fmt.Println(err)
|
|
|
- return
|
|
|
+ return errors.New("配方修改失败!")
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
+ return nil
|
|
|
}
|
|
|
|
|
|
func FeedSurplus(fasion *gofasion.Fasion) {
|
|
@@ -9039,3 +9059,83 @@ func FeedSurplus(fasion *gofasion.Fasion) {
|
|
|
tx.Exec(` update surplus set surplus = (select fname from feed where id = ? ) where feedId = ? `, feedId, feedId)
|
|
|
tx.Exec(` update feed set fname = concat((select id from surplus where feedId = ? ) ,'_剩料') where backup3 = (select id from surplus where feedId = ? )`, feedId, feedId)
|
|
|
}
|
|
|
+
|
|
|
+func FtdetailSurplusFt(surplus, surplusId, id, pastureId string) error {
|
|
|
+ // params := fasion.Get("parammaps")
|
|
|
+ // surplus := params.Get("surplus").ValueStr()
|
|
|
+ // surplusId := params.Get("surplusId").ValueStr()
|
|
|
+
|
|
|
+ tx := restful.Engine.NewSession()
|
|
|
+ defer tx.Close()
|
|
|
+ tx.Exec(` delete from ftdetail where ftid = ? and is_surplus = 1 `, id)
|
|
|
+ if surplusId != "0" {
|
|
|
+ dataList, err := tx.Table("ftdetail").Where("ftid = ? ", id).QueryString()
|
|
|
+ if err != nil {
|
|
|
+ log.Println("PostDataByName-error-1: ", err)
|
|
|
+ return errors.New("配方修改失败!")
|
|
|
+ }
|
|
|
+
|
|
|
+ type ftdetail struct {
|
|
|
+ Id string
|
|
|
+ Fname string
|
|
|
+ Sort int64
|
|
|
+ }
|
|
|
+ ftList := make([]*ftdetail, 0)
|
|
|
+ for _, data := range dataList {
|
|
|
+ ft := new(ftdetail)
|
|
|
+ ft.Fname = data["fname"]
|
|
|
+ ft.Id = data["id"]
|
|
|
+
|
|
|
+ sort, err := strconv.ParseInt(data["sort"], 10, 64)
|
|
|
+ if err != nil {
|
|
|
+ log.Println("PostDataByName-error-2: ", err)
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ ft.Sort = sort
|
|
|
+ ftList = append(ftList, ft)
|
|
|
+ }
|
|
|
+
|
|
|
+ if surplus == "日粮" {
|
|
|
+ for _, ft := range ftList {
|
|
|
+ tx.Exec(` update ftdetail set sort = ? where id = ? `, ft.Sort+1, ft.Id)
|
|
|
+ }
|
|
|
+ _, err = tx.Exec(` insert into ftdetail(pastureid,ftid,fid,fname,sort,is_surplus,is_show,feedgroup,fweight)
|
|
|
+ values(?,?,(select id from feed where backup3 = ? ),(select fname from feed where backup3 = ? ),0,1,2,(select fname from feed where backup3 = ? ),0)`,
|
|
|
+ pastureId, id, surplusId, surplusId, surplusId)
|
|
|
+ fmt.Println(err)
|
|
|
+ } else {
|
|
|
+ var sort int64
|
|
|
+ for _, ft := range ftList {
|
|
|
+ if ft.Fname == surplus {
|
|
|
+ sort = ft.Sort
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if sort == 0 {
|
|
|
+ for _, ft := range ftList {
|
|
|
+ ft.Sort = ft.Sort + 1
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ for _, ft := range ftList {
|
|
|
+ if ft.Sort >= sort {
|
|
|
+ ft.Sort = ft.Sort + 1
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for _, ft := range ftList {
|
|
|
+ tx.Exec(` update ftdetail set sort = ? where id = ? `, ft.Sort, ft.Id)
|
|
|
+ }
|
|
|
+ _, err = tx.Exec(` insert into ftdetail(ftid,fid,fname,sort,is_surplus,is_show,feedgroup,fweight,pastureid)
|
|
|
+ values(?,(select id from feed where backup3 = ? ),(select fname from feed where backup3 = ? ),?,1,2,(select fname from feed where backup3 = ? ),0,?)`,
|
|
|
+ id, surplusId, surplusId, sort, surplusId, pastureId)
|
|
|
+ if err != nil {
|
|
|
+ log.Println("PostDataByName-error-1: ", err)
|
|
|
+ fmt.Println(err)
|
|
|
+ return errors.New("配方修改失败!")
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|