|
@@ -1,6 +1,8 @@
|
|
|
package api
|
|
|
|
|
|
import (
|
|
|
+ "encoding/json"
|
|
|
+ "errors"
|
|
|
"fmt"
|
|
|
"io/ioutil"
|
|
|
"log"
|
|
@@ -47,6 +49,8 @@ type lpplanStruct struct {
|
|
|
Sumcowcount int64 `xorm:"sumcowcount"`
|
|
|
Pastureid string `xorm:"pastureid"`
|
|
|
Display string `xorm:"display"`
|
|
|
+ Issplit int64 `xorm:"issplit"`
|
|
|
+ BeginTime string `xorm:"begintime"`
|
|
|
}
|
|
|
|
|
|
type sysopt struct {
|
|
@@ -113,7 +117,7 @@ func Autogeneration(c *gin.Context) {
|
|
|
typeIN := fsion.Get("type").ValueInt64()
|
|
|
log.Println(time.Now())
|
|
|
tx := restful.Engine.NewSession()
|
|
|
- // defer tx.Close()
|
|
|
+ defer tx.Close()
|
|
|
var times int
|
|
|
var wg sync.WaitGroup
|
|
|
var tmrlist *[]*tmrStruct
|
|
@@ -189,12 +193,12 @@ func Autogeneration(c *gin.Context) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- 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, i, pastureid)
|
|
|
+ if err != nil {
|
|
|
+ appG.Response(http.StatusOK, e.ERROR, false)
|
|
|
+ return
|
|
|
+ }
|
|
|
for _, tem := range *feedtempletlist {
|
|
|
for _, fpd := range *fpdetailWeightList {
|
|
|
if tem.Id == fpd.Temid && i == int(fpd.Times) {
|
|
@@ -384,8 +388,8 @@ func addLpplan(lpplan *lpplanStruct, tx *xorm.Session) error {
|
|
|
}
|
|
|
|
|
|
//获取车次数量
|
|
|
-func getLpplanCount(tx *xorm.Session) (int64, error) {
|
|
|
- count, err := tx.Table("lpplan").Count()
|
|
|
+func getLpplanCount(tx *xorm.Session, times int, pastureid string) (int64, error) {
|
|
|
+ count, err := tx.Table("lpplan").Where("times = ?", times).And("pastureid = ?", pastureid).Count()
|
|
|
if err != nil {
|
|
|
log.Println("getLpplanCount-error", err)
|
|
|
return 0, err
|
|
@@ -757,7 +761,7 @@ func GetSpillage(c *gin.Context) {
|
|
|
parammaps := fsion.Get("parammaps")
|
|
|
pastureid := parammaps.Get("pastureid").ValueInt64()
|
|
|
times := parammaps.Get("times").ValueInt64()
|
|
|
-
|
|
|
+ ftid := parammaps.Get("ftid").ValueDefaultInt64(0)
|
|
|
// refresh 0 全部 , 1 车次信息, 2 班次
|
|
|
refresh := parammaps.Get("refresh").ValueInt64()
|
|
|
tx := restful.Engine.NewSession()
|
|
@@ -766,18 +770,25 @@ func GetSpillage(c *gin.Context) {
|
|
|
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
|
|
|
+ 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 = ?
|
|
|
+ WHERE feedp.pastureid = ? %s
|
|
|
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()
|
|
|
+ WHERE feedp.pastureid = ? %s and (SELECT inforvalue FROM sysopt WHERE sysopt.pastureid=feedp.pastureid AND sysopt.inforname= 'isEnableSupplyFeed') = 1
|
|
|
+ GROUP BY feedp.ptsfid`
|
|
|
+
|
|
|
+ if ftid != 0 {
|
|
|
+ sqlStr = fmt.Sprintf(sqlStr, fmt.Sprintf(" and ft.id = %d ", ftid), fmt.Sprintf(" and ft.id = %d ", ftid))
|
|
|
+ } else {
|
|
|
+ sqlStr = fmt.Sprintf(sqlStr, "", "")
|
|
|
+ }
|
|
|
+
|
|
|
+ ftList, err := tx.SQL(sqlStr, times, pastureid, pastureid, times, pastureid, pastureid).Query().List()
|
|
|
if err != nil {
|
|
|
log.Println("GetSpillage-error-1: ", err)
|
|
|
appG.Response(http.StatusOK, e.ERROR, nil)
|
|
@@ -848,8 +859,41 @@ func GetSpillage(c *gin.Context) {
|
|
|
lpplan
|
|
|
WHERE pastureid = ? and times <= (SELECT sysopt.inforvalue FROM sysopt
|
|
|
WHERE sysopt.pastureid= lpplan.pastureid AND sysopt.inforname='times')
|
|
|
- ORDER BY times,lpplan.sort`
|
|
|
- session := tx.SQL(sqlstr, pastureid)
|
|
|
+ `
|
|
|
+ arrsql := `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
|
|
|
+ `
|
|
|
+
|
|
|
+ var args []interface{}
|
|
|
+ args = append(args, pastureid)
|
|
|
+ if times != 0 {
|
|
|
+ sqlstr += " and times = ? "
|
|
|
+ arrsql += " and times = ? "
|
|
|
+ args = append(args, times)
|
|
|
+ }
|
|
|
+ sqlstr += "ORDER BY times,lpplan.sort"
|
|
|
+ session := tx.SQL(sqlstr, args...)
|
|
|
lppList, err := session.Query().List()
|
|
|
if err != nil {
|
|
|
log.Println("GetSpillage-error-3: ", err)
|
|
@@ -857,32 +901,10 @@ func GetSpillage(c *gin.Context) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- arrList, err := 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() //获取
|
|
|
+ arrsql += " ORDER BY lpplandtl1.sort"
|
|
|
+ arrList, err := tx.SQL(arrsql, args...).QueryString() //获取
|
|
|
if err != nil {
|
|
|
- log.Println("GetSpillage-error-2: ", err)
|
|
|
+ log.Println("GetSpillage-error-4: ", err)
|
|
|
appG.Response(http.StatusOK, e.ERROR, nil)
|
|
|
return
|
|
|
}
|
|
@@ -902,3 +924,174 @@ func GetSpillage(c *gin.Context) {
|
|
|
|
|
|
appG.Response(http.StatusOK, e.SUCCESS, data)
|
|
|
}
|
|
|
+
|
|
|
+type lpplanTrains struct {
|
|
|
+ Id string `xorm:"id"`
|
|
|
+ Sort int64 `xorm:"sort"`
|
|
|
+ Pastureid string `xorm:"pastureid"`
|
|
|
+}
|
|
|
+
|
|
|
+//修改车次顺序
|
|
|
+func UpdateTrains(c *gin.Context) {
|
|
|
+ appG := app.Gin{C: c}
|
|
|
+ lppList := make([]*lpplanTrains, 0)
|
|
|
+
|
|
|
+ err := c.Bind(&lppList)
|
|
|
+ if err != nil {
|
|
|
+ log.Println("UpdateTrains-error-1: ", err)
|
|
|
+ appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ tx := restful.Engine.NewSession()
|
|
|
+ defer tx.Close()
|
|
|
+ tx.Begin()
|
|
|
+ for _, item := range lppList {
|
|
|
+ _, err = tx.Table("lpplan").Where("id = ?", item.Id).And("pastureid = ? ", item.Pastureid).Update(item)
|
|
|
+ if err != nil {
|
|
|
+ log.Println("UpdateTrains-error-2: ", err)
|
|
|
+ appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
|
+ tx.Rollback()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ err = tx.Commit()
|
|
|
+ if err != nil {
|
|
|
+ log.Println("UpdateTrains-error-2: ", err)
|
|
|
+ appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
|
+ tx.Rollback()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ appG.Response(http.StatusOK, e.SUCCESS, true)
|
|
|
+}
|
|
|
+
|
|
|
+type ReqAddLpplan struct {
|
|
|
+ Id string `xorm:"id"`
|
|
|
+ Tmrid string `xorm:"tmrid"`
|
|
|
+ TmrName string `xorm:"tmrname"`
|
|
|
+ Sort int64 `xorm:"sort"`
|
|
|
+ Sel int64 `xorm:"sel"`
|
|
|
+ Times int64 `xorm:"times"`
|
|
|
+ Ftname string `xorm:"ftname"`
|
|
|
+ Ftid string `xorm:"ftid"`
|
|
|
+ Maxweight float64 `xorm:"maxweight"`
|
|
|
+ // Sumweight int64 `xorm:"sumweight"`
|
|
|
+ Sumcowcount int64 `xorm:"sumcowcount"`
|
|
|
+ Pastureid string `xorm:"pastureid"`
|
|
|
+ Display string `xorm:"display"`
|
|
|
+ Issplit int64 `xorm:"issplit"`
|
|
|
+ BeginTime string `xorm:"begintime"`
|
|
|
+}
|
|
|
+
|
|
|
+//添加车次并返回添加的车次信息
|
|
|
+func AddLpplan(c *gin.Context) {
|
|
|
+ appG := app.Gin{C: c}
|
|
|
+ dataByte, _ := ioutil.ReadAll(c.Request.Body)
|
|
|
+ fsion := gofasion.NewFasion(string(dataByte))
|
|
|
+ parammaps := fsion.Get("parammaps")
|
|
|
+ req := new(ReqAddLpplan)
|
|
|
+ err := json.Unmarshal([]byte(parammaps.Json()), req)
|
|
|
+ if err != nil {
|
|
|
+ log.Println("AddLpplan-error-1: ", err)
|
|
|
+ appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if req.Times == 0 {
|
|
|
+ log.Println("AddLpplan-error-1: ", err)
|
|
|
+ appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, errors.New(" 班次错误 times = 0 !!!"))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ tx := restful.Engine.NewSession()
|
|
|
+ defer tx.Close()
|
|
|
+
|
|
|
+ ids, err := setting.SnowIds.NextId()
|
|
|
+ if err != nil {
|
|
|
+ ids = time.Now().UnixNano()
|
|
|
+ logging.Info("AddLpplan-error-1: ", err)
|
|
|
+ }
|
|
|
+ req.Id = strconv.FormatInt(ids, 10)
|
|
|
+
|
|
|
+ count, err := tx.Table("lpplan").Where("pastureid = ?", req.Pastureid).And(" times = ?", req.Times).Count()
|
|
|
+ if err != nil {
|
|
|
+ log.Println("AddLpplan-error-2: ", err)
|
|
|
+ appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ req.Sort = count + 1
|
|
|
+ _, err = tx.Table("lpplan").Insert(req)
|
|
|
+ if err != nil {
|
|
|
+ log.Println("AddLpplan-error-3: ", err)
|
|
|
+ appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ appG.Response(http.StatusOK, e.SUCCESS, req)
|
|
|
+}
|
|
|
+
|
|
|
+//修改车次信息,如果修改tmrid信息则删除栏舍信息
|
|
|
+func UpdateLpplan(c *gin.Context) {
|
|
|
+ appG := app.Gin{C: c}
|
|
|
+ dataByte, _ := ioutil.ReadAll(c.Request.Body)
|
|
|
+ fsion := gofasion.NewFasion(string(dataByte))
|
|
|
+ parammaps := fsion.Get("parammaps")
|
|
|
+ lpplanid := parammaps.Get("id").ValueStr()
|
|
|
+ pastureid := parammaps.Get("pastureid").ValueStr()
|
|
|
+ tmrid := parammaps.Get("tmrid").ValueStr()
|
|
|
+ tmrname := parammaps.Get("tmrname").ValueStr()
|
|
|
+ begintime := parammaps.Get("begintime").ValueStr()
|
|
|
+
|
|
|
+ times := parammaps.Get("times").ValueInt64()
|
|
|
+ ftid := parammaps.Get("ftid").ValueStr()
|
|
|
+ ftname := parammaps.Get("ftname").ValueStr()
|
|
|
+ sel := parammaps.Get("sel").ValueInt64()
|
|
|
+ issplit := parammaps.Get("issplit").ValueInt64()
|
|
|
+ lpplan := new(ReqAddLpplan)
|
|
|
+ lpplan.Tmrid = tmrid
|
|
|
+ lpplan.TmrName = tmrname
|
|
|
+ lpplan.BeginTime = begintime
|
|
|
+ lpplan.Sel = sel
|
|
|
+ lpplan.Issplit = issplit
|
|
|
+ lpplan.Times = times
|
|
|
+ lpplan.Ftid = ftid
|
|
|
+ lpplan.Ftname = ftname
|
|
|
+ tx := restful.Engine.NewSession()
|
|
|
+ defer tx.Close()
|
|
|
+ tx.Begin()
|
|
|
+ lpplanData := new(lpplanStruct)
|
|
|
+ _, err := tx.Table("lpplan").Select("tmrid").Where(" id = ? ", lpplanid).And(" pastureid = ? ", pastureid).Get(lpplanData)
|
|
|
+ if err != nil {
|
|
|
+ log.Println("UpdateLpplan-error-1: ", err)
|
|
|
+ appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
|
+ tx.Rollback()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ _, err = tx.Table("lpplan").Where(" id = ? ", lpplanid).And(" pastureid = ? ", pastureid).
|
|
|
+ MustCols("tmrid,tmrname,begintime,sel,issplit,times,ftid,ftname").Update(lpplan)
|
|
|
+ if err != nil {
|
|
|
+ log.Println("UpdateLpplan-error-1: ", err)
|
|
|
+ appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
|
+ tx.Rollback()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // if tmrid != lpplan.Tmrid {
|
|
|
+ // _, err = tx.SQL(`delete from lpplandtl1 where lppid = ? and pastureid = ? `, lpplanid, pastureid).Execute()
|
|
|
+ // if err != nil {
|
|
|
+ // log.Println("UpdateLpplan-error-2: ", err)
|
|
|
+ // appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
|
+ // tx.Rollback()
|
|
|
+ // return
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ err = tx.Commit()
|
|
|
+ if err != nil {
|
|
|
+ log.Println("UpdateLpplan-error-3: ", err)
|
|
|
+ appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
|
+ tx.Rollback()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ appG.Response(http.StatusOK, e.SUCCESS, true)
|
|
|
+}
|