فهرست منبع

更改库存管理通用方法

shawei_zz 2 سال پیش
والد
کامیت
4f7b8113b8
2فایلهای تغییر یافته به همراه131 افزوده شده و 93 حذف شده
  1. 11 12
      routers/api/db.go
  2. 120 81
      routers/api/report.go

+ 11 - 12
routers/api/db.go

@@ -650,6 +650,7 @@ func GetReportform(c *gin.Context) {
 
 	fsion := gofasion.NewFasion(string(dataByte))
 	sqlnamestr := fsion.Get("name").ValueStr()
+	checked := fsion.Get("checked").ValueStr()
 	parammaps := fsion.Get("parammaps")
 	logging.Info("GetReportform ", c.Keys, sqlnamestr, parammaps)
 	tx := restful.Engine.NewSession()
@@ -670,7 +671,7 @@ func GetReportform(c *gin.Context) {
 		}
 	}()
 
-	queryData, err := praseReportform(sqlnamestr, parammaps, tx)
+	queryData, err := praseReportform(sqlnamestr, parammaps, tx, checked)
 	if err != nil {
 		appG.Response(http.StatusOK, e.ERROR, err.Error())
 	} else {
@@ -965,6 +966,7 @@ func GetAccount(c *gin.Context) {
 		appG.Response(http.StatusOK, e.SUCCESS, nil)
 	}
 }
+
 // @Summary   根据APISQL表中SQL执行得到数据集
 // @Tags PostDataByName
 // @Accept json
@@ -1212,7 +1214,6 @@ func PostRJSBData(c *gin.Context) {
 	}
 	s_params = make([]interface{}, 0)
 
-
 	paramslist = strings.Split(p3, ",")
 	if len(paramslist) > 0 && p3 != "" {
 		for _, value := range paramslist {
@@ -1643,8 +1644,6 @@ func ExitsChildrenParam(fasion map[string]interface{}, tempValParam interface{},
 	return nil
 }
 
-
-
 // @Summary   删除图片
 // @Tags RemovePicByName
 // @Accept json
@@ -1854,7 +1853,7 @@ func PostDataByNames(c *gin.Context) {
 		fsion2 := gofasion.NewFasion(v.Json())
 		ss := fsion2.Get("name")
 		aa := fsion2.Get("params")
-		fmt.Println(ss,aa)
+		fmt.Println(ss, aa)
 		logging.Info("PostDataByNames ", c.Keys, fsion2.Get("name").ValueStr())
 		sql, p := restful.GetSqlByNameDB(fsion2.Get("name").ValueStr())
 		if sql == "" {
@@ -2448,10 +2447,10 @@ func ExecSQL(c *gin.Context) {
 		} else if value.(map[string]interface{})["calculFunc"].(string) == "custbiaozhun" {
 			tem := "STDDEV" + "(" + value.(map[string]interface{})["Column"].(string) + ") as " + value.(map[string]interface{})["Column"].(string)
 			sqlstr = sqlstr + tem + ","
-		}else if value.(map[string]interface{})["calculFunc"].(string) == "custbianyi" {
-			tem := "STDDEV" + "(" + value.(map[string]interface{})["Column"].(string) + ")/ AVG(" +value.(map[string]interface{})["Column"].(string)+")as " + value.(map[string]interface{})["Column"].(string)
+		} else if value.(map[string]interface{})["calculFunc"].(string) == "custbianyi" {
+			tem := "STDDEV" + "(" + value.(map[string]interface{})["Column"].(string) + ")/ AVG(" + value.(map[string]interface{})["Column"].(string) + ")as " + value.(map[string]interface{})["Column"].(string)
 			sqlstr = sqlstr + tem + ","
-		}else {
+		} else {
 			tem := value.(map[string]interface{})["calculFunc"].(string) + "(" + value.(map[string]interface{})["Column"].(string) + ") as " + value.(map[string]interface{})["Column"].(string)
 			sqlstr = sqlstr + tem + ","
 		}
@@ -2461,13 +2460,13 @@ func ExecSQL(c *gin.Context) {
 			if value.(map[string]interface{})["calculFunc"].(string) == "none" {
 				sqlstr = sqlstr + value.(map[string]interface{})["Column"].(string) + ","
 				groupstr = groupstr + value.(map[string]interface{})["Column"].(string) + ","
-			}else if value.(map[string]interface{})["calculFunc"].(string) == "custbiaozhun" {
+			} else if value.(map[string]interface{})["calculFunc"].(string) == "custbiaozhun" {
 				tem := "STDDEV" + "(" + value.(map[string]interface{})["Column"].(string) + ") as " + value.(map[string]interface{})["Column"].(string)
 				sqlstr = sqlstr + tem + ","
-			}else if value.(map[string]interface{})["calculFunc"].(string) == "custbianyi" {
-				tem := "STDDEV" + "(" + value.(map[string]interface{})["Column"].(string) + ")/ AVG(" +value.(map[string]interface{})["Column"].(string)+")as " + value.(map[string]interface{})["Column"].(string)
+			} else if value.(map[string]interface{})["calculFunc"].(string) == "custbianyi" {
+				tem := "STDDEV" + "(" + value.(map[string]interface{})["Column"].(string) + ")/ AVG(" + value.(map[string]interface{})["Column"].(string) + ")as " + value.(map[string]interface{})["Column"].(string)
 				sqlstr = sqlstr + tem + ","
-			}else {
+			} else {
 				tem := value.(map[string]interface{})["calculFunc"].(string) + "(" + value.(map[string]interface{})["Column"].(string) + ") as " + value.(map[string]interface{})["Column"].(string)
 				sqlstr = sqlstr + tem + ","
 			}

+ 120 - 81
routers/api/report.go

@@ -11,8 +11,9 @@ import (
 	"strings"
 	"time"
 )
+
 //包含报表模块前端需要的各种数据格式转换
-func praseReportform(sqlnamestr string, parammaps *gofasion.Fasion, tx *xorm.Session) (queryData map[string]interface{}, err error) {
+func praseReportform(sqlnamestr string, parammaps *gofasion.Fasion, tx *xorm.Session, checked string) (queryData map[string]interface{}, err error) {
 
 	sql, p := restful.GetSqlByNameDBT(sqlnamestr, tx)
 	s_params := make([]interface{}, 0)
@@ -25,12 +26,11 @@ func praseReportform(sqlnamestr string, parammaps *gofasion.Fasion, tx *xorm.Ses
 		}
 	}
 	queryList, err := tx.SQL(sql, s_params...).Query().List()
-
-	if err != nil{
-		return  nil,err
+	if err != nil {
+		return nil, err
 	}
-	if len(queryList) == 0{
-		return  nil,nil
+	if len(queryList) == 0 {
+		return nil, nil
 	}
 	temstr := ""
 	//除特殊接口外,去接口名称的前10位做同一类型的转换
@@ -48,21 +48,32 @@ func praseReportform(sqlnamestr string, parammaps *gofasion.Fasion, tx *xorm.Ses
 		//queryData, err = getAccuracyV3v1(queryList)
 		queryData, err = getAccuracyV3(queryList)
 		// 统计分析 过程分析
-		if sqlnamestr == "getprocessAnalysisTB"{
-			quertDataList :=queryData["list"]
-			query :=quertDataList.(map[string]interface{})
-			querys,_:=GetprocessAnalysisTB(parammaps, tx ,quertDataList ,queryList)
-			query["data1"]=querys["WTime"]
-			query["data2"]=querys["data2"]
-			query["data3"]=querys["realWandT"]
-			query["data5"]=querys["data5"]
+		if sqlnamestr == "getprocessAnalysisTB" {
+			quertDataList := queryData["list"]
+			query := quertDataList.(map[string]interface{})
+			querys, _ := GetprocessAnalysisTB(parammaps, tx, quertDataList, queryList)
+			query["data1"] = querys["WTime"]
+			query["data2"] = querys["data2"]
+			query["data3"] = querys["realWandT"]
+			query["data5"] = querys["data5"]
 		}
 	case "getHomepro":
 		queryData, err = getAccuracyV3(queryList)
 	case "getAccuracyAllHL", "getAccuracyAllQX", "getAccuracyAllJH", "getFeedEffMR", "getFeedEffHL", "getHomepageCB", "getAccuraa":
 		queryData, err = getAccuracyV2(queryList) //固定维度 日期
 	case "getMateria":
-		queryData, err = getAccuracyV4(queryList)
+		sql1, p1 := restful.GetSqlByNameDBT(sqlnamestr+("sum"), tx)
+		s_params1 := make([]interface{}, 0)
+		if sql1 != "" {
+			paramslist1 := strings.Split(p1, ",")
+			if len(paramslist1) > 0 && p != "" {
+				for _, value := range paramslist1 {
+					s_params1 = append(s_params1, parammaps.Get(strings.Trim(value, " ")).ValueStr())
+				}
+			}
+		}
+		queryListSum, _ := tx.SQL(sql1, s_params1...).Query().List()
+		queryData, err = getAccuracyV4(queryList, queryListSum, checked)
 	case "getPriceAn":
 		queryData, err = getAccuracyV5(queryList)
 	case "getJT1Accu":
@@ -72,7 +83,7 @@ func praseReportform(sqlnamestr string, parammaps *gofasion.Fasion, tx *xorm.Ses
 	case "judgenurFTReportDetail":
 		queryData, err = getAccuracyV8(queryList)
 	case "downloadPl":
-		queryData, err = getAccuracyV9(queryList)  //投料简打、累加
+		queryData, err = getAccuracyV9(queryList) //投料简打、累加
 	default:
 		queryData, err = nil, nil
 	}
@@ -86,7 +97,6 @@ func getAccuracyV9(queryList []map[string]interface{}) (map[string]interface{},
 	data2 := []interface{}{}
 	data1 := []interface{}{}
 
-
 	mapc3["label"] = "车次"
 	mapc3["prop"] = "projname"
 	data1 = append(data1, mapc3)
@@ -127,15 +137,14 @@ func getAccuracyV9(queryList []map[string]interface{}) (map[string]interface{},
 	data1 = append(data1, mapc3)
 	mapc3 = make(map[string]interface{})
 
-
 	mtem := make(map[interface{}]interface{})
 	var stem []string
 	for i := 0; i < len(queryList); i++ { // 获取所有饲料种类
-		if _,ok :=mtem[queryList[i]["fname"]];ok {
+		if _, ok := mtem[queryList[i]["fname"]]; ok {
 			continue
 		}
-		stem = append(stem,queryList[i]["fname"].(string))
-		mtem[queryList[i]["fname"]] = struct {}{}
+		stem = append(stem, queryList[i]["fname"].(string))
+		mtem[queryList[i]["fname"]] = struct{}{}
 
 	}
 	sort.Strings(stem)
@@ -145,7 +154,7 @@ func getAccuracyV9(queryList []map[string]interface{}) (map[string]interface{},
 		data1 = append(data1, mapc3)
 		mapc3 = make(map[string]interface{})
 	}
-	if queryList[0]["sumlweight"] != nil{
+	if queryList[0]["sumlweight"] != nil {
 		mapc3["label"] = "合计"
 		mapc3["prop"] = "sumlweight"
 	}
@@ -155,20 +164,20 @@ func getAccuracyV9(queryList []map[string]interface{}) (map[string]interface{},
 	mapc2 := make(map[string]interface{})
 	for i := 0; i < len(queryList); i++ { // 获取所有饲料种类
 
-		if i == 0{
+		if i == 0 {
 			tem = queryList[i]["projname"]
-			mapc2  = queryList[i]
+			mapc2 = queryList[i]
 			//for key:= range mtem {
 			//	mapc2[xorm.String(key)] = ""
 			//}
 			mapc2[xorm.String(queryList[i]["fname"])] = queryList[i]["lweight"]
 		}
-		if tem == queryList[i]["projname"]{
+		if tem == queryList[i]["projname"] {
 			mapc2[xorm.String(queryList[i]["fname"])] = queryList[i]["lweight"]
-		}else{
+		} else {
 			data2 = append(data2, mapc2)
 			tem = queryList[i]["projname"]
-			mapc2  = queryList[i]
+			mapc2 = queryList[i]
 			//for key := range mtem {
 			//	mapc2[xorm.String(key)] = ""
 			//}
@@ -388,9 +397,9 @@ func getAccuracyV8(queryList []map[string]interface{}) (map[string]interface{},
 	queryData["data"] = queryList
 	return queryData, nil
 }
-func TransFloat(flo float64)(float64){
-	hf,_ :=strconv.ParseFloat(fmt.Sprintf("%.3f", float64(flo)), 64)
-	return  hf
+func TransFloat(flo float64) float64 {
+	hf, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(flo)), 64)
+	return hf
 }
 func getAccuracyV7(queryList []map[string]interface{}) (map[string]interface{}, error) {
 	queryData := make(map[string]interface{})
@@ -613,7 +622,7 @@ func getAccuracyV5(queryList []map[string]interface{}) (map[string]interface{},
 	queryData["data"] = queryList
 	return queryData, nil
 }
-func getAccuracyV4(queryList []map[string]interface{}) (map[string]interface{}, error) {
+func getAccuracyV4(queryList []map[string]interface{}, queryListSum []map[string]interface{}, checked string) (map[string]interface{}, error) {
 	queryData := make(map[string]interface{})
 	chartData := make(map[string]interface{})
 	datamap1 := make(map[string]interface{})
@@ -627,7 +636,7 @@ func getAccuracyV4(queryList []map[string]interface{}) (map[string]interface{},
 	data2 := []interface{}{}
 	data1 := []interface{}{}
 	a := 0
-
+	//ss := 0
 	var dtem interface{}
 
 	count2 := 0
@@ -641,10 +650,14 @@ func getAccuracyV4(queryList []map[string]interface{}) (map[string]interface{},
 			temstr = queryList[i]["fname"]
 			typestr = queryList[i]["typestr"]
 		}
+
 		if temstr == queryList[i]["fname"] {
 			temsmap[queryList[i]["feedname"]] = 1
 		}
-
+		//if i == len(queryList)-1{
+		//	temstr = "合计"
+		//	typestr = queryList[i]["typestr"]
+		//}
 		if _, ok := mapc2[queryList[i]["feedname"]]; !ok {
 			mapc2[queryList[i]["feedname"]] = count2 // 编号
 			mapc2[count2] = queryList[i]["feedname"]
@@ -715,6 +728,7 @@ func getAccuracyV4(queryList []map[string]interface{}) (map[string]interface{},
 
 		if queryList[i]["fname"] == temstr {
 			datamap2["label"] = queryList[i]["feedname"]
+
 			datamap2child["label"] = "理论"
 			datamap2child["prop"] = "a" + strconv.Itoa(a)
 			data3 = append(data3, datamap2child)
@@ -725,29 +739,55 @@ func getAccuracyV4(queryList []map[string]interface{}) (map[string]interface{},
 			data3 = append(data3, datamap2child)
 			datamap2child = make(map[string]interface{})
 
-			datamap2child["label"] = "误差值"
-			datamap2child["prop"] = "a" + strconv.Itoa(a+2)
-			data3 = append(data3, datamap2child)
-			datamap2child = make(map[string]interface{})
+			if checked == "1" {
+				datamap2child["label"] = "误差值"
+				datamap2child["prop"] = "a" + strconv.Itoa(a+2)
+				data3 = append(data3, datamap2child)
+				datamap2child = make(map[string]interface{})
 
-			datamap2child["label"] = "误差率"
-			datamap2child["prop"] = "a" + strconv.Itoa(a+3)
-			data3 = append(data3, datamap2child)
+				datamap2child["label"] = "误差率"
+				datamap2child["prop"] = "a" + strconv.Itoa(a+3)
+				data3 = append(data3, datamap2child)
+				datamap2child = make(map[string]interface{})
+			}
+			datamap2 = make(map[string]interface{})
 			datamap2["children"] = data3
 			data2 = append(data2, datamap2)
 			data3 = []interface{}{}
-			datamap2 = make(map[string]interface{})
-			datamap2child = make(map[string]interface{})
-
 		}
 
 		datamap1["A"] = queryList[i]["fname"]
 		datamap1["a"+strconv.Itoa(a)] = queryList[i]["lweight"]
 		datamap1["a"+strconv.Itoa(a+1)] = queryList[i]["actualweightminus"]
-		datamap1["a"+strconv.Itoa(a+2)] = queryList[i]["diff"]
-		datamap1["a"+strconv.Itoa(a+3)] = queryList[i]["diffrate"]
+		if checked == "1" {
+			datamap1["a"+strconv.Itoa(a+2)] = queryList[i]["diff"]
+			datamap1["a"+strconv.Itoa(a+3)] = queryList[i]["diffrate"]
+		}
 		datamap2["label"] = queryList[i]["饲料名称"]
+		for z := 0; z < len(queryListSum); z++ {
+			if queryListSum[z]["fname"] == queryList[i]["fname"] {
+				datamap1["B"] = queryListSum[z]["lweight"]
+				datamap1["C"] = queryListSum[z]["actualweightminus"]
+			}
+		}
+
+		if i == len(queryList)-1 {
+			datamap2["label"] = "合计"
+			datamap2child = make(map[string]interface{})
+			datamap2child["label"] = "理论"
+			datamap2child["prop"] = "B"
+			data3 = append(data3, datamap2child)
+
+			datamap2child = make(map[string]interface{})
+			datamap2child["label"] = "实际"
+			datamap2child["prop"] = "C"
+			data3 = append(data3, datamap2child)
 
+			//	###########################
+
+			datamap2["children"] = data3
+			data3 = []interface{}{}
+		}
 	}
 
 	data1 = append(data1, datamap1)
@@ -806,7 +846,7 @@ func getAccuracyV3(queryList []map[string]interface{}) (map[string]interface{},
 func getAccuracyV2(queryList []map[string]interface{}) (map[string]interface{}, error) {
 	queryData := make(map[string]interface{})
 	chartData := make(map[string]interface{})
-	data  := []interface{}{}
+	data := []interface{}{}
 	data1 := []interface{}{}
 	data2 := []interface{}{}
 	data3 := []interface{}{}
@@ -881,9 +921,9 @@ func getAccuracy(queryList []map[string]interface{}) (map[string]interface{}, er
 		case string:
 			dates, _ := time.Parse("2006-01-02", queryList[i]["日期"].(string))
 			dates1 := ""
-			if a < len(e2) -1{
+			if a < len(e2)-1 {
 				dates1 = e2[a]
-			}else {
+			} else {
 				dates1 = e2[len(e2)-1]
 			}
 			if a < len(e2)-1 {
@@ -924,9 +964,8 @@ func getAccuracy(queryList []map[string]interface{}) (map[string]interface{}, er
 	return queryData, nil
 }
 
-
- //统计分析过程分析data值拆分
-func GetprocessAnalysisTB(parammaps *gofasion.Fasion, tx *xorm.Session,quertDataList interface{},queryList []map[string]interface{})(query map[string]interface{},err error){
+//统计分析过程分析data值拆分
+func GetprocessAnalysisTB(parammaps *gofasion.Fasion, tx *xorm.Session, quertDataList interface{}, queryList []map[string]interface{}) (query map[string]interface{}, err error) {
 	sql1, p1 := restful.GetSqlByNameDBT("getweightjson", tx)
 	s_params1 := make([]interface{}, 0)
 	if sql1 != "" {
@@ -938,46 +977,46 @@ func GetprocessAnalysisTB(parammaps *gofasion.Fasion, tx *xorm.Session,quertData
 		}
 	}
 	queryList2, err := tx.SQL(sql1, s_params1...).Query().List()
-	if err !=nil{
+	if err != nil {
 		fmt.Println("查询配料出错")
-		return nil,err
+		return nil, err
 	}
 	//fmt.Printf("%T\n",queryList2[0]["weightjson"])
 	b, _ := json.Marshal(&quertDataList)
 	var m map[string]interface{}
 	_ = json.Unmarshal(b, &m)
-	msg :=queryList2[0]["weightjson"].(string)
-	weightjson := make([]map[string]string,0)
-	json.Unmarshal([]byte(msg),&weightjson)
+	msg := queryList2[0]["weightjson"].(string)
+	weightjson := make([]map[string]string, 0)
+	json.Unmarshal([]byte(msg), &weightjson)
 	//fmt.Println(len(weightjson))
-	realWandT :=make([]interface{},0)
-	for i:=0;i<len(weightjson);i++{
-		oneSlice := make([]interface{},0)
-		oneSlice =append(oneSlice,weightjson[i]["mt"])
-		oneSlice =append(oneSlice,weightjson[i]["w"])
+	realWandT := make([]interface{}, 0)
+	for i := 0; i < len(weightjson); i++ {
+		oneSlice := make([]interface{}, 0)
+		oneSlice = append(oneSlice, weightjson[i]["mt"])
+		oneSlice = append(oneSlice, weightjson[i]["w"])
 		realWandT = append(realWandT, oneSlice)
 	}
-	WTime:=make([]interface{},0)
-	for z :=0;z<len(weightjson);z++{
-		WTime = append(WTime,weightjson[z]["mt"])
+	WTime := make([]interface{}, 0)
+	for z := 0; z < len(weightjson); z++ {
+		WTime = append(WTime, weightjson[z]["mt"])
 	}
 
-	data2 := make([]interface{},0)
-	for i:=0;i<len(queryList);i++{
-		querySlice:=make([]interface{},0)
-		querySlice = append(querySlice,queryList[i]["timedate"],queryList[i]["lweight"])
-		data2 = append(data2,querySlice)
+	data2 := make([]interface{}, 0)
+	for i := 0; i < len(queryList); i++ {
+		querySlice := make([]interface{}, 0)
+		querySlice = append(querySlice, queryList[i]["timedate"], queryList[i]["lweight"])
+		data2 = append(data2, querySlice)
 	}
-	data5 := make([]interface{},0)
-	for i:=0;i<len(queryList);i++{
-		querySlice:=make([]interface{},0)
-		querySlice = append(querySlice,queryList[i]["intime"], queryList[i]["actualweight"],queryList[i]["allname"],queryList[i]["fname"])
-		data5 = append(data5,querySlice)
+	data5 := make([]interface{}, 0)
+	for i := 0; i < len(queryList); i++ {
+		querySlice := make([]interface{}, 0)
+		querySlice = append(querySlice, queryList[i]["intime"], queryList[i]["actualweight"], queryList[i]["allname"], queryList[i]["fname"])
+		data5 = append(data5, querySlice)
 	}
-	query1 :=make(map[string]interface{},0)
-	query1 ["WTime"] = WTime
-	query1 ["data2"] = data2
-	query1 ["data5"] = data5
-	query1 ["realWandT"] = realWandT
-	return query1,nil
-}
+	query1 := make(map[string]interface{}, 0)
+	query1["WTime"] = WTime
+	query1["data2"] = data2
+	query1["data5"] = data5
+	query1["realWandT"] = realWandT
+	return query1, nil
+}