diff --git a/app/bigData/hdl/hdl_making_data.go b/app/bigData/hdl/hdl_making_data.go index add3ece..8e496bf 100644 --- a/app/bigData/hdl/hdl_making_data.go +++ b/app/bigData/hdl/hdl_making_data.go @@ -39,6 +39,24 @@ func NewSortingCate(c *gin.Context) { e.OutSuc(c, result, nil) return } +func NewSortingGoodsCate(c *gin.Context) { + + result := svc.NewSortingGoodsCate() + + e.OutSuc(c, result, nil) + return +} +func NewSortingGoodsData(c *gin.Context) { + var arg map[string]string + if err := c.ShouldBindJSON(&arg); err != nil { + e.OutErr(c, e.ERR_INVALID_ARGS, err) + return + } + result := svc.NewSortingGoodsData(arg) + + e.OutSuc(c, result, nil) + return +} func NewSortingData(c *gin.Context) { result := svc.NewSortingData(c) diff --git a/app/bigData/svc/svc_data.go b/app/bigData/svc/svc_data.go index 4d7c331..8147fef 100644 --- a/app/bigData/svc/svc_data.go +++ b/app/bigData/svc/svc_data.go @@ -513,3 +513,116 @@ func NewSortingData(c *gin.Context) []map[string]string { } return res } +func NewSortingGoodsCate() []map[string]string { + res := make([]map[string]string, 0) + + engine := db.Db + //1、查找不等于4 5 + today := utils.GetTimeRange("today") + if time.Now().Hour() < 2 { + today = utils.GetTimeRange("yesterday") + } + var orders []model.Order + err := engine.Where(" state != 4 and state != 5 and create_at>=? ", time.Unix(today["start"], 0).Format("2006-01-02 15:04:05")).Find(&orders) + if err != nil { + return res + } + var oIds []string + for _, v := range orders { + v1 := order.JudgePackageOrdOrdState(&v) + if v1.State == 4 || v1.State == 5 { + continue + } + oIds = append(oIds, utils.Int64ToStr(v.Oid)) + } + sql := `SELECT SUM(num) as num,SUM(success_num) as success_num,goods_title,sku,goods_id,sku_id FROM order_goods WHERE oid in (%s) GROUP BY goods_id,sku_id` + sql = fmt.Sprintf(sql, strings.Join(oIds, ",")) + nativeString, err := db.QueryNativeString(engine, sql) + for _, v := range nativeString { + skuData := make([]md2.Sku, 0) + json.Unmarshal([]byte(v["sku"]), &skuData) + skuStr := "" + for _, v1 := range skuData { + if skuStr != "" { + skuStr += ";" + } + skuStr += v1.Value + } + tmp := map[string]string{ + "goods_id": v["goods_id"], + "sku_id": v["sku_id"], + "goods_name": v["goods_title"], + "sku": skuStr, + "num": v["num"], + "success_num": v["success_num"], + "state": "1", + "state_str": "待分拣", + } + if utils.StrToInt(v["num"]) <= utils.StrToInt(v["success_num"]) { + tmp["state"] = "4" + tmp["stare_str"] = "分拣完成" + } + res = append(res, tmp) + } + return res +} +func NewSortingGoodsData(arg map[string]string) []map[string]string { + + engine := db.Db + res := make([]map[string]string, 0) + var enterprise []model.Enterprise + err := engine.Where("1=1").Find(&enterprise) + if err != nil { + return res + } + var enterpriseMap = map[int]model.Enterprise{} + for _, v := range enterprise { + enterpriseMap[v.Id] = v + } + //1、查找不等于4 5 + today := utils.GetTimeRange("today") + if time.Now().Hour() < 2 { + today = utils.GetTimeRange("yesterday") + } + var orders []model.Order + err = engine.Where(" state != 4 and state != 5 and create_at>=? ", time.Unix(today["start"], 0).Format("2006-01-02 15:04:05")).Find(&orders) + if err != nil { + return res + } + var oIds []string + for _, v := range orders { + v1 := order.JudgePackageOrdOrdState(&v) + if v1.State == 4 || v1.State == 5 { + continue + } + oIds = append(oIds, utils.Int64ToStr(v.Oid)) + } + sql := `SELECT SUM(num) as num,SUM(success_num) as success_num,goods_title,sku,goods_id,sku_id,enterprise_id FROM order_goods WHERE oid in (%s) and goods_id=%s and sku_id=%s GROUP BY enterprise_id` + sql = fmt.Sprintf(sql, strings.Join(oIds, ","), arg["goods_id"], arg["sku_id"]) + nativeString, err := db.QueryNativeString(engine, sql) + for _, v := range nativeString { + skuData := make([]md2.Sku, 0) + json.Unmarshal([]byte(v["sku"]), &skuData) + skuStr := "" + for _, v1 := range skuData { + if skuStr != "" { + skuStr += ";" + } + skuStr += v1.Value + } + tmp := map[string]string{ + "enterprise_name": enterpriseMap[utils.StrToInt(v["enterprise_id"])].Name, + "num": v["num"], + "success_num": v["success_num"], + "state": "1", + "state_str": "待分拣", + } + if utils.StrToInt(v["num"]) <= utils.StrToInt(v["success_num"]) { + tmp["state"] = "4" + tmp["stare_str"] = "分拣完成" + } + res = append(res, tmp) + } + return res + +} diff --git a/app/e/msg.go b/app/e/msg.go index ed226ae..77ca0cc 100644 --- a/app/e/msg.go +++ b/app/e/msg.go @@ -3,9 +3,8 @@ package e import ( "applet/app/utils" "encoding/json" - "net/http" - "github.com/gin-gonic/gin" + "net/http" "applet/app/utils/logx" ) diff --git a/app/router/big_data_router.go b/app/router/big_data_router.go index ea10555..a72ba54 100644 --- a/app/router/big_data_router.go +++ b/app/router/big_data_router.go @@ -28,4 +28,7 @@ func rData(r *gin.RouterGroup) { r.GET("/new_sorting_cate", hdl.NewSortingCate) //分拣区学校分类 r.POST("/new_sorting_data", hdl.NewSortingData) //分拣区数据 + r.GET("/new_sorting_goods_cate", hdl.NewSortingGoodsCate) //分拣区 按商品 + r.POST("/new_sorting_goods_data", hdl.NewSortingGoodsData) //分拣区 按商品 数据 + }