Esempio n. 1
0
func GetPurchases(queryParams t.Params, limitParams t.LimitParams, orderBy t.Params) (string, int64, []map[string]interface{}) {
	beego.Debug("purchase.GetPurchases:", queryParams, limitParams, orderBy)
	surface := s.Purchase
	sqlBuilder := wbo.NewSqlBuilder()
	for k, v := range queryParams {
		sqlBuilder.Filter(surface+"."+k, v)
	}
	count := GetPurchaseTotal(sqlBuilder)
	if count == -1 {
		return stat.Failed, 0, make([]map[string]interface{}, 0)
	}
	if limit, ok := limitParams[s.Limit]; ok {
		sqlBuilder.Limit(limit)
	}
	if offset, ok := limitParams[s.Offset]; ok {
		sqlBuilder.Offset(offset)
	}
	for k, v := range orderBy {
		sqlBuilder.OrderBy(surface+"."+k, v)
	}
	if code, retMaps := GetPurchaseList(sqlBuilder); strings.EqualFold(code, stat.Success) {
		return stat.Success, count, retMaps
	} else {
		return code, 0, make([]map[string]interface{}, 0)
	}
}
Esempio n. 2
0
func calcTimely(queryParams t.Params) (noDelay int64, total int64, rat string) {
	sqlBuilder := wbo.NewSqlBuilder()
	for k, v := range queryParams {
		sqlBuilder.Filter(k, v)
	}
	where := sqlBuilder.GetConditonSql()
	noDelaySql := "SELECT count(id) as count FROM purchase WHERE godowndate != '' AND godowndate < requireddate " + "AND " + where
	noDelay = wbo.QueryRawCount(noDelaySql, sqlBuilder.GetValues())
	totalSql := "SELECT count(id) as count FROM purchase WHERE " + where + " AND (godowndate != '' OR requireddate < '?')"
	total = wbo.QueryRawCount(totalSql, append(sqlBuilder.GetValues(), u.GetToday()))
	if total == 0 || noDelay == 0 {
		rat = "0%"
		return
	}
	rat = fmt.Sprintf("%.2f", float64(noDelay)*100/float64(total)) + "%"
	return
}
Esempio n. 3
0
func Query(entity string, queryParams t.Params, limitParams map[string]int64, orderBy t.Params) (string, []map[string]interface{}) {
	sqlBuilder := wbo.NewSqlBuilder()
	sqlBuilder.QueryTable(entity)
	for k, v := range queryParams {
		sqlBuilder.Filter(k, v)
	}
	if limit, ok := limitParams[s.Limit]; ok {
		sqlBuilder.Limit(limit)
	}
	if offset, ok := limitParams[s.Offset]; ok {
		sqlBuilder.Offset(offset)
	}
	for k, v := range orderBy {
		sqlBuilder.OrderBy(k, v)
	}
	query := sqlBuilder.GetSql()

	values := sqlBuilder.GetValues()
	//fmt.Println("buildsql: ", query)
	o := orm.NewOrm()
	var resultMaps []orm.Params
	retList := make([]map[string]interface{}, 0)
	_, err := o.Raw(query, values...).Values(&resultMaps)
	if err == nil {
		//		fmt.Println("res", res, resultMaps)
		retList = make([]map[string]interface{}, len(resultMaps))
		//		fmt.Println("old", resultMaps)
		for idx, oldMap := range resultMaps {
			var retMap = make(map[string]interface{}, len(oldMap))
			for key, value := range oldMap {
				retMap[strings.ToLower(key)] = value
			}
			retList[idx] = retMap
		}
		return stat.Success, retList
	} else {
		beego.Error(fmt.Sprintf("Query error:%s for sql:%s", err.Error(), query))
	}
	return stat.Failed, retList
}
Esempio n. 4
0
func Count(entity string, params t.Params) int64 {
	sqlBuilder := wbo.NewSqlBuilder()
	sqlBuilder.QueryTable(entity)
	for k, v := range params {
		sqlBuilder.Filter(k, v)
	}
	query := sqlBuilder.GetCountSql()
	values := sqlBuilder.GetValues()
	//	fmt.Println("buildsqlcount: ", query)
	o := orm.NewOrm()
	var maps []orm.Params
	if _, err := o.Raw(query, values...).Values(&maps); err == nil {
		//		fmt.Println("res", res, maps)
		if total, ok := maps[0]["COUNT(id)"]; ok {
			total64, err := strconv.ParseInt(total.(string), 10, 64)
			if err != nil {
				panic(err)
			}
			return total64
		}
	}
	return -1
}