|
|
@@ -1413,3 +1413,794 @@ GROUP BY fpd.ptsid`
|
|
|
|
|
|
appG.Response(http.StatusOK, e.SUCCESS, data)
|
|
|
}
|
|
|
+
|
|
|
+func AddLpplandtl(c *gin.Context) {
|
|
|
+ appG := app.Gin{C: c}
|
|
|
+ dataByte, _ := ioutil.ReadAll(c.Request.Body)
|
|
|
+ fsion := gofasion.NewFasion(string(dataByte))
|
|
|
+ parammaps := fsion.Get("parammaps")
|
|
|
+
|
|
|
+ tx := restful.Engine.NewSession()
|
|
|
+ defer tx.Close()
|
|
|
+
|
|
|
+ exist := false
|
|
|
+ var err error
|
|
|
+
|
|
|
+ lpplandList := make([]*lpplandtl1, 0)
|
|
|
+ err = tx.Table("lpplandtl1").Select("id,pastureid,sort,barid,tmrid").Where("lppid = ? ", parammaps.Get("lppid").ValueStr()).And("pastureid = ?", parammaps.Get("pastureid").ValueStr()).
|
|
|
+ OrderBy("sort").Find(&lpplandList)
|
|
|
+ if err != nil {
|
|
|
+ log.Println("AddLpplandtl-error-1: ", err)
|
|
|
+ appG.Response(http.StatusOK, e.ERROR, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if parammaps.Get("id").ValueStr() != "" || parammaps.Get("id").ValueStr() != "0" {
|
|
|
+ for _, lppand := range lpplandList {
|
|
|
+ if lppand.Id == parammaps.Get("id").ValueInt64() {
|
|
|
+ if lppand.Tmrid == parammaps.Get("tmrid").ValueInt64() {
|
|
|
+ appG.Response(http.StatusOK, e.SUCCESS, true)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ exist = true
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ tmrid := parammaps.Get("tmrid").ValueInt64()
|
|
|
+ var sort int64 = -1
|
|
|
+ if !exist {
|
|
|
+ for _, lppand := range lpplandList {
|
|
|
+ if lppand.Barid == parammaps.Get("barid").ValueInt64() {
|
|
|
+ _, err := tx.SQL(" update lpplandtl1 set lweight =lweight + ? where id = ? and pastureid = ? ", parammaps.Get("lweight").ValueStr(), lppand.Id, parammaps.Get("pastureid").ValueStr()).Execute()
|
|
|
+ if err != nil {
|
|
|
+ log.Println("AddLpplandtl-error-2: ", err)
|
|
|
+ appG.Response(http.StatusOK, e.ERROR, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ appG.Response(http.StatusOK, e.SUCCESS, true)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for i, lppand := range lpplandList {
|
|
|
+ lppand.Sort = int64(i) + 1
|
|
|
+ }
|
|
|
+ updateLpplandList := make([]*lpplandtl1, 0)
|
|
|
+ for i, lppand := range lpplandList {
|
|
|
+ n := i + 1
|
|
|
+ if lppand.Tmrid == tmrid {
|
|
|
+ sort = int64(n)
|
|
|
+ lppand.Sort = int64(n) + 1
|
|
|
+ updateLpplandList = append(updateLpplandList, lppand)
|
|
|
+ } else if sort > 0 {
|
|
|
+ lppand.Sort = int64(n) + 1
|
|
|
+ updateLpplandList = append(updateLpplandList, lppand)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ tx.Begin()
|
|
|
+ for _, lppand := range updateLpplandList {
|
|
|
+ _, err := tx.SQL(" update lpplandtl1 set sort = ? where id = ? and pastureid = ? ", lppand.Sort, lppand.Id, lppand.Pastureid).Execute()
|
|
|
+ if err != nil {
|
|
|
+ tx.Rollback()
|
|
|
+ log.Println("AddLpplandtl-error-2: ", err)
|
|
|
+ appG.Response(http.StatusOK, e.ERROR, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if sort < 0 && len(lpplandList) > 0 {
|
|
|
+ sort = int64(len(lpplandList) + 1)
|
|
|
+ } else if len(lpplandList) == 0 {
|
|
|
+ sort = 1
|
|
|
+ }
|
|
|
+
|
|
|
+ _, err = tx.SQL(`INSERT INTO lpplandtl1(pastureid,lppid,barid,barname,fpdid,lweight,sort,tmrid,tmrname,fttype,background,cowcount,ccountradio)
|
|
|
+ VALUES (?,?,?,?,?,?,?,?,?,
|
|
|
+ ?,?,IF(?='',0,?),IF(?='',0,?))`,
|
|
|
+ parammaps.Get("pastureid").ValueStr(),
|
|
|
+ parammaps.Get("lppid").ValueStr(),
|
|
|
+ parammaps.Get("barid").ValueStr(),
|
|
|
+ parammaps.Get("barname").ValueStr(),
|
|
|
+ parammaps.Get("fpdid").ValueStr(),
|
|
|
+ parammaps.Get("lweight").ValueStr(),
|
|
|
+ sort,
|
|
|
+ parammaps.Get("tmrid").ValueStr(),
|
|
|
+ parammaps.Get("tmrname").ValueStr(),
|
|
|
+ parammaps.Get("fttype").ValueStr(),
|
|
|
+ parammaps.Get("background").ValueStr(),
|
|
|
+ parammaps.Get("cowcount").ValueStr(),
|
|
|
+ parammaps.Get("cowcount").ValueStr(),
|
|
|
+ parammaps.Get("ccountradio").ValueStr(),
|
|
|
+ parammaps.Get("ccountradio").ValueStr()).Execute()
|
|
|
+ if err != nil {
|
|
|
+ tx.Rollback()
|
|
|
+ log.Println("AddLpplandtl-error-3: ", err)
|
|
|
+ appG.Response(http.StatusOK, e.ERROR, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ err = tx.Commit()
|
|
|
+ if err != nil {
|
|
|
+ tx.Rollback()
|
|
|
+ log.Println("AddLpplandtl-error-6: ", err)
|
|
|
+ appG.Response(http.StatusOK, e.ERROR, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ lpplandid := parammaps.Get("id").ValueInt64()
|
|
|
+ updateLpplandList := make([]*lpplandtl1, 0)
|
|
|
+ var oldsort int64
|
|
|
+ for i, lppand := range lpplandList {
|
|
|
+ lppand.Sort = int64(i) + 1
|
|
|
+ }
|
|
|
+ for _, lppand := range lpplandList {
|
|
|
+ if lppand.Id == lpplandid {
|
|
|
+ oldsort = lppand.Sort
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, lppand := range lpplandList {
|
|
|
+
|
|
|
+ if lppand.Tmrid == tmrid && lppand.Id != lpplandid && sort < 0 {
|
|
|
+ sort = lppand.Sort
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if sort == -1 {
|
|
|
+ sort = 1
|
|
|
+ }
|
|
|
+
|
|
|
+ if oldsort < sort {
|
|
|
+ for _, lppand := range lpplandList {
|
|
|
+ if lppand.Id != lpplandid && lppand.Sort > oldsort && lppand.Sort < sort {
|
|
|
+ lppand.Sort--
|
|
|
+ updateLpplandList = append(updateLpplandList, lppand)
|
|
|
+ } else if lppand.Sort > sort && lppand.Id != lpplandid {
|
|
|
+ lppand.Sort++
|
|
|
+ updateLpplandList = append(updateLpplandList, lppand)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sort--
|
|
|
+ } else {
|
|
|
+ for _, lppand := range lpplandList {
|
|
|
+ if lppand.Sort < oldsort && lppand.Sort >= sort && lppand.Id != lpplandid {
|
|
|
+ lppand.Sort++
|
|
|
+ updateLpplandList = append(updateLpplandList, lppand)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var tmrlpplandList []*lpplandtl1
|
|
|
+ for _, lppand := range lpplandList {
|
|
|
+ exist := false
|
|
|
+ for _, lppand1 := range updateLpplandList {
|
|
|
+ if lppand.Id == lppand1.Id {
|
|
|
+ exist = true
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if !exist {
|
|
|
+ tmrlpplandList = append(tmrlpplandList, lppand)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ updateLpplandList = append(updateLpplandList, tmrlpplandList...)
|
|
|
+ if len(updateLpplandList) > 0 {
|
|
|
+ tx.Begin()
|
|
|
+ for _, lppand := range updateLpplandList {
|
|
|
+ _, err := tx.SQL(" update lpplandtl1 set sort = ? where id = ? and pastureid = ? ", lppand.Sort, lppand.Id, lppand.Pastureid).Execute()
|
|
|
+ if err != nil {
|
|
|
+ tx.Rollback()
|
|
|
+ log.Println("AddLpplandtl-error-2: ", err)
|
|
|
+ appG.Response(http.StatusOK, e.ERROR, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ _, err := tx.SQL(" update lpplandtl1 set tmrid = ? , tmrname = ?,sort = ? where id = ? and pastureid = ? ", parammaps.Get("tmrid").ValueStr(), parammaps.Get("tmrname").ValueStr(), sort, lpplandid, parammaps.Get("pastureid").ValueStr()).Execute()
|
|
|
+ if err != nil {
|
|
|
+ tx.Rollback()
|
|
|
+ log.Println("AddLpplandtl-error-2: ", err)
|
|
|
+ appG.Response(http.StatusOK, e.ERROR, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ tx.Commit()
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ appG.Response(http.StatusOK, e.SUCCESS, true)
|
|
|
+}
|
|
|
+
|
|
|
+func UpdateLpplandtlSort(c *gin.Context) {
|
|
|
+ appG := app.Gin{C: c}
|
|
|
+ dataByte, _ := ioutil.ReadAll(c.Request.Body)
|
|
|
+ fsion := gofasion.NewFasion(string(dataByte))
|
|
|
+ parammaps := fsion.Get("parammaps")
|
|
|
+
|
|
|
+ tx := restful.Engine.NewSession()
|
|
|
+ defer tx.Close()
|
|
|
+
|
|
|
+ var err error
|
|
|
+
|
|
|
+ lpplandList := make([]*lpplandtl1, 0)
|
|
|
+ err = tx.Table("lpplandtl1").Select("id,pastureid,sort,tmrid").Where("lppid = ? ", parammaps.Get("lppid").ValueStr()).And("pastureid = ?", parammaps.Get("pastureid").ValueStr()).
|
|
|
+ OrderBy("sort").Find(&lpplandList)
|
|
|
+ if err != nil {
|
|
|
+ log.Println("UpdateLpplandtlSort-error-1: ", err)
|
|
|
+ appG.Response(http.StatusOK, e.ERROR, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var oldsort int64
|
|
|
+ tmrid := parammaps.Get("tmrid").ValueInt64()
|
|
|
+ sort := parammaps.Get("sort").ValueInt64()
|
|
|
+
|
|
|
+ for i, lppland := range lpplandList {
|
|
|
+ lppland.Sort = int64(i) + 1
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, lppland := range lpplandList {
|
|
|
+ if tmrid == lppland.Tmrid {
|
|
|
+ oldsort = lppland.Sort
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, lppland := range lpplandList {
|
|
|
+ if lppland.Sort == sort {
|
|
|
+ for _, lppland1 := range lpplandList {
|
|
|
+ if lppland.Tmrid == lppland1.Tmrid {
|
|
|
+ sort = lppland1.Sort
|
|
|
+ if oldsort > sort {
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if oldsort == sort {
|
|
|
+ appG.Response(http.StatusOK, e.SUCCESS, true)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ tmrLpplandList := make([]*lpplandtl1, 0)
|
|
|
+ for _, lppland := range lpplandList {
|
|
|
+ if lppland.Tmrid == tmrid {
|
|
|
+ tmrLpplandList = append(tmrLpplandList, lppland)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for i, tmrLppland := range tmrLpplandList {
|
|
|
+ tmrLppland.Sort = sort + int64(i)
|
|
|
+ }
|
|
|
+
|
|
|
+ if oldsort > sort {
|
|
|
+ for _, lppland := range lpplandList {
|
|
|
+ if lppland.Sort == sort {
|
|
|
+ // uptmrid = lppland.Tmrid
|
|
|
+ sort = lppland.Sort
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ var uptmrid int64
|
|
|
+ for _, lppland := range lpplandList {
|
|
|
+ if lppland.Sort == sort {
|
|
|
+ uptmrid = lppland.Tmrid
|
|
|
+ sort = lppland.Sort
|
|
|
+ } else if uptmrid != 0 && uptmrid == lppland.Tmrid {
|
|
|
+ sort = lppland.Sort
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ upcount := int64(len(tmrLpplandList))
|
|
|
+ if oldsort > sort {
|
|
|
+ for _, lppland := range lpplandList {
|
|
|
+
|
|
|
+ if lppland.Sort >= sort && lppland.Tmrid != tmrid {
|
|
|
+ lppland.Sort += upcount
|
|
|
+ tmrLpplandList = append(tmrLpplandList, lppland)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ for _, lppland := range lpplandList {
|
|
|
+ if lppland.Sort <= sort && lppland.Sort >= oldsort && lppland.Tmrid != tmrid {
|
|
|
+ lppland.Sort -= upcount
|
|
|
+ tmrLpplandList = append(tmrLpplandList, lppland)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ updateLpplandList := make([]*lpplandtl1, 0)
|
|
|
+ for _, lppland := range lpplandList {
|
|
|
+ exist := false
|
|
|
+ for _, tmrLppland := range tmrLpplandList {
|
|
|
+ if lppland.Id == tmrLppland.Id {
|
|
|
+ exist = true
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if !exist {
|
|
|
+ updateLpplandList = append(updateLpplandList, lppland)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ tmrLpplandList = append(tmrLpplandList, updateLpplandList...)
|
|
|
+
|
|
|
+ tx.Begin()
|
|
|
+ // _, err = tx.Table("lpplandtl1").Update(&tmrLpplandList)
|
|
|
+
|
|
|
+ var wg sync.WaitGroup
|
|
|
+ for _, lppland := range tmrLpplandList {
|
|
|
+ wg.Add(1)
|
|
|
+ go func(lppland *lpplandtl1) {
|
|
|
+ defer wg.Done()
|
|
|
+ _, err = tx.SQL(`update lpplandtl1 set sort = ? where id = ? and pastureid = ? `, lppland.Sort, lppland.Id, lppland.Pastureid).Execute()
|
|
|
+ if err != nil {
|
|
|
+ log.Println("UpdateLpplandtlSort-error-2: ", err)
|
|
|
+ tx.Rollback()
|
|
|
+ appG.Response(http.StatusOK, e.ERROR, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ }(lppland)
|
|
|
+ }
|
|
|
+ wg.Wait()
|
|
|
+
|
|
|
+ err = tx.Commit()
|
|
|
+ if err != nil {
|
|
|
+ log.Println("UpdateLpplandtlSort-error-3: ", err)
|
|
|
+ tx.Rollback()
|
|
|
+ appG.Response(http.StatusOK, e.ERROR, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ appG.Response(http.StatusOK, e.SUCCESS, true)
|
|
|
+}
|
|
|
+
|
|
|
+func AddLpplandtlDate(c *gin.Context) {
|
|
|
+ appG := app.Gin{C: c}
|
|
|
+ dataByte, _ := ioutil.ReadAll(c.Request.Body)
|
|
|
+ fsion := gofasion.NewFasion(string(dataByte))
|
|
|
+ parammaps := fsion.Get("parammaps")
|
|
|
+
|
|
|
+ tx := restful.Engine.NewSession()
|
|
|
+ defer tx.Close()
|
|
|
+
|
|
|
+ exist := false
|
|
|
+ var err error
|
|
|
+
|
|
|
+ lpplandList := make([]*lpplandtl1, 0)
|
|
|
+ err = tx.Table("lpplandtl1date").Select("id,pastureid,sort,barid,tmrid").Where("lppid = ? ", parammaps.Get("lppid").ValueStr()).And("pastureid = ?", parammaps.Get("pastureid").ValueStr()).
|
|
|
+ And("date = ? ", parammaps.Get("date").ValueStr()).OrderBy("sort").Find(&lpplandList)
|
|
|
+ if err != nil {
|
|
|
+ log.Println("AddLpplandtl-error-1: ", err)
|
|
|
+ appG.Response(http.StatusOK, e.ERROR, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if parammaps.Get("id").ValueStr() != "" || parammaps.Get("id").ValueStr() != "0" {
|
|
|
+ for _, lppand := range lpplandList {
|
|
|
+ fmt.Println(parammaps.Get("id").ValueInt64())
|
|
|
+ if lppand.Id == parammaps.Get("id").ValueInt64() {
|
|
|
+ if lppand.Tmrid == parammaps.Get("tmrid").ValueInt64() {
|
|
|
+ appG.Response(http.StatusOK, e.SUCCESS, true)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ exist = true
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ tmrid := parammaps.Get("tmrid").ValueInt64()
|
|
|
+ var sort int64 = -1
|
|
|
+ if !exist {
|
|
|
+ for _, lppand := range lpplandList {
|
|
|
+ if lppand.Barid == parammaps.Get("barid").ValueInt64() {
|
|
|
+ _, err := tx.SQL(" update lpplandtl1date set lweight =lweight + ? where id = ? and pastureid = ? ", parammaps.Get("lweight").ValueStr(), lppand.Id, parammaps.Get("pastureid").ValueStr()).Execute()
|
|
|
+ if err != nil {
|
|
|
+ log.Println("AddLpplandtl-error-2: ", err)
|
|
|
+ appG.Response(http.StatusOK, e.ERROR, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ appG.Response(http.StatusOK, e.SUCCESS, true)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for i, lppand := range lpplandList {
|
|
|
+ lppand.Sort = int64(i) + 1
|
|
|
+ }
|
|
|
+ updateLpplandList := make([]*lpplandtl1, 0)
|
|
|
+ for i, lppand := range lpplandList {
|
|
|
+ n := i + 1
|
|
|
+ if lppand.Tmrid == tmrid {
|
|
|
+ sort = int64(n)
|
|
|
+ lppand.Sort = int64(n) + 1
|
|
|
+ updateLpplandList = append(updateLpplandList, lppand)
|
|
|
+ } else if sort > 0 {
|
|
|
+ lppand.Sort = int64(n) + 1
|
|
|
+ updateLpplandList = append(updateLpplandList, lppand)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ tx.Begin()
|
|
|
+ for _, lppand := range updateLpplandList {
|
|
|
+ _, err := tx.SQL(" update lpplandtl1date set sort = ? where id = ? and pastureid = ? and date = ? ", lppand.Sort, lppand.Id, lppand.Pastureid, parammaps.Get("date").ValueStr()).Execute()
|
|
|
+ if err != nil {
|
|
|
+ tx.Rollback()
|
|
|
+ log.Println("AddLpplandtl-error-2: ", err)
|
|
|
+ appG.Response(http.StatusOK, e.ERROR, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if sort < 0 && len(lpplandList) > 0 {
|
|
|
+ sort = int64(len(lpplandList) + 1)
|
|
|
+ } else if len(lpplandList) == 0 {
|
|
|
+ sort = 1
|
|
|
+ }
|
|
|
+
|
|
|
+ _, err = tx.SQL(`INSERT INTO lpplandtl1date(pastureid,lppid,barid,barname,fpdid,lweight,sort,tmrid,tmrname,fttype,background,cowcount,ccountradio,date)
|
|
|
+ VALUES (?,?,?,?,?,?,?,?,?,
|
|
|
+ ?,?,IF(?='',0,?),IF(?='',0,?),?)`,
|
|
|
+ parammaps.Get("pastureid").ValueStr(),
|
|
|
+ parammaps.Get("lppid").ValueStr(),
|
|
|
+ parammaps.Get("barid").ValueStr(),
|
|
|
+ parammaps.Get("barname").ValueStr(),
|
|
|
+ parammaps.Get("fpdid").ValueStr(),
|
|
|
+ parammaps.Get("lweight").ValueStr(),
|
|
|
+ sort,
|
|
|
+ parammaps.Get("tmrid").ValueStr(),
|
|
|
+ parammaps.Get("tmrname").ValueStr(),
|
|
|
+ parammaps.Get("fttype").ValueStr(),
|
|
|
+ parammaps.Get("background").ValueStr(),
|
|
|
+ parammaps.Get("cowcount").ValueStr(),
|
|
|
+ parammaps.Get("cowcount").ValueStr(),
|
|
|
+ parammaps.Get("ccountradio").ValueStr(),
|
|
|
+ parammaps.Get("ccountradio").ValueStr(),
|
|
|
+ parammaps.Get("date").ValueStr()).Execute()
|
|
|
+ if err != nil {
|
|
|
+ tx.Rollback()
|
|
|
+ log.Println("AddLpplandtl-error-3: ", err)
|
|
|
+ appG.Response(http.StatusOK, e.ERROR, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ err = tx.Commit()
|
|
|
+ if err != nil {
|
|
|
+ tx.Rollback()
|
|
|
+ log.Println("AddLpplandtl-error-6: ", err)
|
|
|
+ appG.Response(http.StatusOK, e.ERROR, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ lpplandid := parammaps.Get("id").ValueInt64()
|
|
|
+ updateLpplandList := make([]*lpplandtl1, 0)
|
|
|
+ var oldsort int64
|
|
|
+ for i, lppand := range lpplandList {
|
|
|
+ lppand.Sort = int64(i) + 1
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, lppand := range lpplandList {
|
|
|
+ if lppand.Id == lpplandid {
|
|
|
+ oldsort = lppand.Sort
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, lppand := range lpplandList {
|
|
|
+
|
|
|
+ if lppand.Tmrid == tmrid && lppand.Id != lpplandid && sort < 0 {
|
|
|
+ sort = lppand.Sort
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if sort == -1 {
|
|
|
+ sort = 1
|
|
|
+ }
|
|
|
+
|
|
|
+ if oldsort < sort {
|
|
|
+ for _, lppand := range lpplandList {
|
|
|
+ if lppand.Id != lpplandid && lppand.Sort > oldsort && lppand.Sort < sort {
|
|
|
+ lppand.Sort--
|
|
|
+ updateLpplandList = append(updateLpplandList, lppand)
|
|
|
+ } else if lppand.Sort > sort && lppand.Id != lpplandid {
|
|
|
+ lppand.Sort++
|
|
|
+ updateLpplandList = append(updateLpplandList, lppand)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sort--
|
|
|
+ } else {
|
|
|
+ for _, lppand := range lpplandList {
|
|
|
+ if lppand.Sort < oldsort && lppand.Sort >= sort && lppand.Id != lpplandid {
|
|
|
+ lppand.Sort++
|
|
|
+ updateLpplandList = append(updateLpplandList, lppand)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var tmrlpplandList []*lpplandtl1
|
|
|
+ for _, lppand := range lpplandList {
|
|
|
+ exist := false
|
|
|
+ for _, lppand1 := range updateLpplandList {
|
|
|
+ if lppand.Id == lppand1.Id {
|
|
|
+ exist = true
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if !exist {
|
|
|
+ tmrlpplandList = append(tmrlpplandList, lppand)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ updateLpplandList = append(updateLpplandList, tmrlpplandList...)
|
|
|
+ if len(updateLpplandList) > 0 {
|
|
|
+ tx.Begin()
|
|
|
+ for _, lppand := range updateLpplandList {
|
|
|
+ _, err := tx.SQL(" update lpplandtl1date set sort = ? where id = ? and pastureid = ? ", lppand.Sort, lppand.Id, lppand.Pastureid).Execute()
|
|
|
+ if err != nil {
|
|
|
+ tx.Rollback()
|
|
|
+ log.Println("AddLpplandtl-error-2: ", err)
|
|
|
+ appG.Response(http.StatusOK, e.ERROR, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ _, err := tx.SQL(" update lpplandtl1date set tmrid = ? , tmrname = ?,sort = ? where id = ? and pastureid = ? ", parammaps.Get("tmrid").ValueStr(), parammaps.Get("tmrname").ValueStr(), sort, lpplandid, parammaps.Get("pastureid").ValueStr()).Execute()
|
|
|
+ if err != nil {
|
|
|
+ tx.Rollback()
|
|
|
+ log.Println("AddLpplandtl-error-2: ", err)
|
|
|
+ appG.Response(http.StatusOK, e.ERROR, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ tx.Commit()
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ appG.Response(http.StatusOK, e.SUCCESS, true)
|
|
|
+}
|
|
|
+
|
|
|
+func UpdateLpplandtlDateSort(c *gin.Context) {
|
|
|
+ appG := app.Gin{C: c}
|
|
|
+ dataByte, _ := ioutil.ReadAll(c.Request.Body)
|
|
|
+ fsion := gofasion.NewFasion(string(dataByte))
|
|
|
+ parammaps := fsion.Get("parammaps")
|
|
|
+
|
|
|
+ tx := restful.Engine.NewSession()
|
|
|
+ defer tx.Close()
|
|
|
+
|
|
|
+ var err error
|
|
|
+
|
|
|
+ lpplandList := make([]*lpplandtl1, 0)
|
|
|
+ err = tx.Table("lpplandtl1date").Select("id,pastureid,sort,tmrid").Where("lppid = ? ", parammaps.Get("lppid").ValueStr()).And("pastureid = ?", parammaps.Get("pastureid").ValueStr()).
|
|
|
+ And("date = ? ", parammaps.Get("date").ValueStr()).OrderBy("sort").Find(&lpplandList)
|
|
|
+ if err != nil {
|
|
|
+ log.Println("UpdateLpplandtlSort-error-1: ", err)
|
|
|
+ appG.Response(http.StatusOK, e.ERROR, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var oldsort int64
|
|
|
+ tmrid := parammaps.Get("tmrid").ValueInt64()
|
|
|
+ sort := parammaps.Get("sort").ValueInt64()
|
|
|
+
|
|
|
+ for i, lppland := range lpplandList {
|
|
|
+ lppland.Sort = int64(i) + 1
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, lppland := range lpplandList {
|
|
|
+ if tmrid == lppland.Tmrid {
|
|
|
+ oldsort = lppland.Sort
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, lppland := range lpplandList {
|
|
|
+ if lppland.Sort == sort {
|
|
|
+ for _, lppland1 := range lpplandList {
|
|
|
+ if lppland.Tmrid == lppland1.Tmrid {
|
|
|
+ sort = lppland1.Sort
|
|
|
+ if oldsort > sort {
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if oldsort == sort {
|
|
|
+ appG.Response(http.StatusOK, e.SUCCESS, true)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ tmrLpplandList := make([]*lpplandtl1, 0)
|
|
|
+ for _, lppland := range lpplandList {
|
|
|
+ if lppland.Tmrid == tmrid {
|
|
|
+ tmrLpplandList = append(tmrLpplandList, lppland)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for i, tmrLppland := range tmrLpplandList {
|
|
|
+ tmrLppland.Sort = sort + int64(i)
|
|
|
+ }
|
|
|
+
|
|
|
+ if oldsort > sort {
|
|
|
+ for _, lppland := range lpplandList {
|
|
|
+ if lppland.Sort == sort {
|
|
|
+ // uptmrid = lppland.Tmrid
|
|
|
+ sort = lppland.Sort
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ var uptmrid int64
|
|
|
+ for _, lppland := range lpplandList {
|
|
|
+ if lppland.Sort == sort {
|
|
|
+ uptmrid = lppland.Tmrid
|
|
|
+ sort = lppland.Sort
|
|
|
+ } else if uptmrid != 0 && uptmrid == lppland.Tmrid {
|
|
|
+ sort = lppland.Sort
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ upcount := int64(len(tmrLpplandList))
|
|
|
+ if oldsort > sort {
|
|
|
+ for _, lppland := range lpplandList {
|
|
|
+
|
|
|
+ if lppland.Sort >= sort && lppland.Tmrid != tmrid {
|
|
|
+ lppland.Sort += upcount
|
|
|
+ tmrLpplandList = append(tmrLpplandList, lppland)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ for _, lppland := range lpplandList {
|
|
|
+ if lppland.Sort <= sort && lppland.Sort >= oldsort && lppland.Tmrid != tmrid {
|
|
|
+ lppland.Sort -= upcount
|
|
|
+ tmrLpplandList = append(tmrLpplandList, lppland)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ updateLpplandList := make([]*lpplandtl1, 0)
|
|
|
+ for _, lppland := range lpplandList {
|
|
|
+ exist := false
|
|
|
+ for _, tmrLppland := range tmrLpplandList {
|
|
|
+ if lppland.Id == tmrLppland.Id {
|
|
|
+ exist = true
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if !exist {
|
|
|
+ updateLpplandList = append(updateLpplandList, lppland)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ tmrLpplandList = append(tmrLpplandList, updateLpplandList...)
|
|
|
+
|
|
|
+ tx.Begin()
|
|
|
+ // _, err = tx.Table("lpplandtl1").Update(&tmrLpplandList)
|
|
|
+
|
|
|
+ var wg sync.WaitGroup
|
|
|
+ for _, lppland := range tmrLpplandList {
|
|
|
+ wg.Add(1)
|
|
|
+ go func(lppland *lpplandtl1) {
|
|
|
+ defer wg.Done()
|
|
|
+ _, err = tx.SQL(`update lpplandtl1date set sort = ? where id = ? and pastureid = ? `, lppland.Sort, lppland.Id, lppland.Pastureid).Execute()
|
|
|
+ if err != nil {
|
|
|
+ log.Println("UpdateLpplandtlSort-error-2: ", err)
|
|
|
+ tx.Rollback()
|
|
|
+ appG.Response(http.StatusOK, e.ERROR, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ }(lppland)
|
|
|
+ }
|
|
|
+ wg.Wait()
|
|
|
+
|
|
|
+ err = tx.Commit()
|
|
|
+ if err != nil {
|
|
|
+ log.Println("UpdateLpplandtlSort-error-3: ", err)
|
|
|
+ tx.Rollback()
|
|
|
+ appG.Response(http.StatusOK, e.ERROR, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ appG.Response(http.StatusOK, e.SUCCESS, true)
|
|
|
+}
|
|
|
+
|
|
|
+func GetFeedpUndistributed(c *gin.Context) {
|
|
|
+ appG := app.Gin{C: c}
|
|
|
+ tx := restful.Engine.NewSession()
|
|
|
+ defer tx.Close()
|
|
|
+ dataByte, _ := ioutil.ReadAll(c.Request.Body)
|
|
|
+ fsion := gofasion.NewFasion(string(dataByte))
|
|
|
+ timesMax := fsion.Get("times").ValueInt()
|
|
|
+ pastureid := fsion.Get("pastureid").ValueStr()
|
|
|
+
|
|
|
+ data := make(map[string]interface{})
|
|
|
+ for times := 1; times <= timesMax; times++ {
|
|
|
+ sqlStr := `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`
|
|
|
+
|
|
|
+ ftList, err := tx.SQL(sqlStr, times, pastureid, pastureid, times, pastureid, pastureid).Query().List()
|
|
|
+ if err != nil {
|
|
|
+ log.Println("GetFeedpUndistributed-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("GetFeedpUndistributed-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 {
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var key string
|
|
|
+ if times == 1 {
|
|
|
+ key = "one"
|
|
|
+ } else if times == 2 {
|
|
|
+ key = "two"
|
|
|
+ } else if times == 3 {
|
|
|
+ key = "three"
|
|
|
+ } else if times == 4 {
|
|
|
+ key = "four"
|
|
|
+ } else if times == 5 {
|
|
|
+ key = "five"
|
|
|
+ } else {
|
|
|
+ key = "six"
|
|
|
+ }
|
|
|
+
|
|
|
+ data[key] = ftList
|
|
|
+ }
|
|
|
+
|
|
|
+ appG.Response(http.StatusOK, e.SUCCESS, data)
|
|
|
+}
|