コード例 #1
0
ファイル: func.go プロジェクト: tomlovzki/ebs
func GetUsrPaperRecord(uid int64, p2bIds string) ([]map[string]interface{}, error) {
	rs := []map[string]interface{}{}
	if _, err := common.IdsValid(p2bIds, ",", -1); err != nil {
		return rs, err
	}
	sql_ := fmt.Sprintf(`select a.tid,a.begin,a.end,a.duration,a.score,a.uid,a.uname,a.status,a.p2b_id,a.bank_id,p.tid,p.name,qCnt.cnt,p2b.ext from ebs_answer a join ebs_p2b p2b on p2b.tid=a.p2b_id join
	ebs_paper p on p.tid=a.paper_id left join (select paper_id,count(*) cnt from ebs_p2q group by paper_id) qCnt on qCnt.paper_id=p.tid where a.p2b_id in (%s) and a.uid=?`, p2bIds)
	conn := dbMgr.DbConn()
	if rows, err := conn.Query(sql_, uid); err != nil {
		return rs, err
	} else {
		for rows.Next() {
			var v1, v2, v3, v4, v6, v9, v10, v11, v13 sql.NullInt64
			var v5 sql.NullFloat64
			var v7, v8, v12, v14 sql.NullString
			rows.Scan(&v1, &v2, &v3, &v4, &v5, &v6, &v7, &v8, &v9, &v10, &v11, &v12, &v13, &v14)
			o := map[string]interface{}{
				"aid":      v1.Int64,
				"begin":    v2.Int64,
				"end":      v3.Int64,
				"duration": v4.Int64,
				"score":    v5.Float64,
				"uid":      v6.Int64,
				"uname":    v7.String,
				"status":   v8.String,
				"p2bId":    v9.Int64,
				"bankId":   v10.Int64,
				"pId":      v11.Int64,
				"pName":    v12.String,
				"qCnt":     v13.Int64,
				"ext":      v14.String,
				"process":  0,
			}
			rs = append(rs, o)
		}
	}
	return rs, nil
}
コード例 #2
0
ファイル: func.go プロジェクト: tomlovzki/ebs
func GetBankCountInfo(bankIds string, uid int64) ([]map[string]interface{}, error) {
	rs_ := []map[string]interface{}{}
	_, err := common.IdsValid(bankIds, ",", -1)
	if err != nil {
		return rs_, err
	}
	rs := make(map[int64]interface{})
	sql1 := fmt.Sprintf(`select a.count_,b.tid,b.name,qCount from (select count(*) count_,'qCount',bank_id from ebs_q2b where bank_id in (%s) group by bank_id union select count(*),'pCount',bank_id from ebs_p2b where bank_id in (%s) group by bank_id)
	a join ebs_bank b on b.tid=a.bank_id`, bankIds, bankIds)
	sql2 := fmt.Sprintf(`select p2q.cnt,p.tid,p.name,p.description,p2b.bank_id,p2b.ext,p.q_grp,group_concat(a.score),group_concat(a.status),group_concat(a.tid),p2b.tid from ebs_paper p
	left join (select count(*) cnt,p2q.paper_id from ebs_p2q p2q join ebs_p2b p2b on p2q.paper_id=p2b.paper_id and p2b.bank_id in (%s)  group by paper_id) p2q on p2q.paper_id=p.tid
	join ebs_p2b p2b on p2b.paper_id=p.tid
	left join ebs_answer a on a.p2b_id=p2b.tid and a.uid=? where p2b.bank_id in (%s) group by p.tid`, bankIds, bankIds)
	//	log.D("sql1:%s\nsql2:%s",sql1,sql2)
	conn := dbMgr.DbConn()
	if rows, err := conn.Query(sql1); err != nil {
		return rs_, err
	} else {
		for rows.Next() {
			var v1, v2 sql.NullInt64
			var v3, v4 sql.NullString
			rows.Scan(&v1, &v2, &v3, &v4)
			if v, ok := rs[v2.Int64]; ok {
				v.(map[string]interface{})[v4.String] = v1.Int64
			} else {
				o := make(map[string]interface{})
				o["paperInfo"] = []map[string]interface{}{}
				o["name"] = v3.String
				o["bankId"] = v2.Int64

				o[v4.String] = v1.Int64
				rs[v2.Int64] = o
			}
		}

	}
	if rows, err := conn.Query(sql2, uid); err != nil {
		return rs_, err
	} else {
		for rows.Next() {

			var v1, v2, v5, v11 sql.NullInt64
			var v3, v4, v6, v7 sql.NullString
			var v8, v9, v10 sql.NullString
			rows.Scan(&v1, &v2, &v3, &v4, &v5, &v6, &v7, &v8, &v9, &v10, &v11)
			o := map[string]interface{}{
				"pId": v2.Int64, "qCount": v1.Int64, "name": v3.String, "desc": v4.String, "p2bId": v11.Int64,
				"score": v8.String, "status": v9.String, "aid": v10.String, "ext": func() EXT {
					ext := EXT{}
					json.Unmarshal([]byte(v6.String), &ext)
					if ext.Begin == 0 {
						ext.P = "1"
					} else {
						if ext.Duration != 0 {
							diff := time.Now().Unix() - ext.Begin/1000
							fmt.Println(diff, time.Now().Unix(), ext.Begin/1000)
							if diff < ext.Duration {
								ext.P = "1"
							} else {
								ext.P = "0"
							}
						}
					}
					return ext
				}(), "part": func() int {
					qGrp := []Q_GRP{}
					json.Unmarshal([]byte(v7.String), &qGrp)
					return len(qGrp)
				}(),
			}

			if v, ok := rs[v5.Int64]; ok {
				if _, ok2 := v.(map[string]interface{})["paperInfo"]; ok2 {
					v.(map[string]interface{})["paperInfo"] = append(v.(map[string]interface{})["paperInfo"].([]map[string]interface{}), o)
				}
			}
		}
	}
	for _, v := range rs {
		rs_ = append(rs_, v.(map[string]interface{}))
	}
	return rs_, nil
}