コード例 #1
0
ファイル: Interceptor.go プロジェクト: hongjinqiu/finance
func (o InterceptorCommon) IndexWithSession(session *mgo.Session, collection string, query map[string]interface{}, pageNo int, pageSize int, orderBy string) (result map[string]interface{}) {
	mongoDBFactory := mongo.GetInstance()
	db := mongoDBFactory.GetDatabase(session)

	c := db.C(collection)

	items := []map[string]interface{}{}
	var err error
	if orderBy != "" {
		fieldLi := strings.Split(orderBy, ",")
		err = c.Find(query).Sort(fieldLi...).Limit(pageSize).Skip((pageNo - 1) * pageSize).All(&items)
	} else {
		err = c.Find(query).Limit(pageSize).Skip((pageNo - 1) * pageSize).All(&items)
	}
	if err != nil {
		panic(err)
	}

	totalResults, err := c.Find(query).Count()
	if err != nil {
		panic(err)
	}

	mapItems := []interface{}{}
	for _, item := range items {
		mapItems = append(mapItems, item)
	}
	return map[string]interface{}{
		"totalResults": totalResults,
		"items":        mapItems,
	}
}
コード例 #2
0
ファイル: tree.go プロジェクト: hongjinqiu/finance
func (o Tree) SysUserTest() revel.Result {
	mongoDBFactory := mongo.GetInstance()
	session, db := mongoDBFactory.GetConnection()
	defer session.Close()

	collection := "SysUser"
	c := db.C(collection)

	queryMap := map[string]interface{}{}

	sysUserResult := []map[string]interface{}{}
	err := c.Find(queryMap).Limit(10).All(&sysUserResult)
	if err != nil {
		panic(err)
	}

	items := []map[string]interface{}{}
	for _, item := range sysUserResult {
		items = append(items, map[string]interface{}{
			"code": item["_id"],
			"name": item["nick"],
		})
	}

	o.Response.ContentType = "application/json; charset=utf-8"
	return o.RenderJson(&items)
}
コード例 #3
0
ファイル: Dictionary.go プロジェクト: hongjinqiu/finance
func (o DictionaryManager) GetDictionary(code string) map[string]interface{} {
	mongoDBFactory := mongo.GetInstance()
	session, db := mongoDBFactory.GetConnection()
	defer session.Close()

	return o.GetDictionaryBySession(db, code)
}
コード例 #4
0
ファイル: Query.go プロジェクト: hongjinqiu/finance
func (qb QuerySupport) Index(collection string, query map[string]interface{}, pageNo int, pageSize int, orderBy string) (result map[string]interface{}) {
	mongoDBFactory := mongo.GetInstance()
	session, _ := mongoDBFactory.GetConnection()
	defer session.Close()

	return qb.IndexWithSession(session, collection, query, pageNo, pageSize, orderBy)
}
コード例 #5
0
ファイル: Query.go プロジェクト: hongjinqiu/finance
func (qb QuerySupport) FindByMap(collection string, query map[string]interface{}) (result map[string]interface{}, found bool) {
	mongoDBFactory := mongo.GetInstance()
	session := mongoDBFactory.GetSession()
	defer session.Close()

	return qb.FindByMapWithSession(session, collection, query)
}
コード例 #6
0
ファイル: Layer.go プロジェクト: hongjinqiu/finance
func (o LayerManager) GetLayer(code string) map[string]interface{} {
	connectionFactory := mongo.GetInstance()
	session, db := connectionFactory.GetConnection()
	defer session.Close()

	sessionId := global.GetSessionId()
	defer global.CloseSession(sessionId)

	return o.GetLayerBySession(sessionId, db, code)
}
コード例 #7
0
func (o ProgramDictionaryManager) GetProgramDictionary(code string) map[string]interface{} {
	mongoDBFactory := mongo.GetInstance()
	session, db := mongoDBFactory.GetConnection()
	defer session.Close()
	
	sessionId := global.GetSessionId()
	defer global.CloseSession(sessionId)
	
	return o.GetProgramDictionaryBySession(sessionId, db, code)
}
コード例 #8
0
ファイル: resumetest.go プロジェクト: hongjinqiu/finance
func (c ResumeTest) SeqTest() revel.Result {
	//	db *mgo.Database, sequenceName string
	connectionFactory := mongo.GetInstance()
	session, db := connectionFactory.GetConnection()
	defer session.Close()
	sequenceName := "sysUserId"
	seq := mongo.GetSequenceNo(db, sequenceName)

	c.Response.ContentType = "text/plain; charset=utf-8"
	return c.RenderText(strconv.Itoa(seq))
}
コード例 #9
0
ファイル: Interceptor.go プロジェクト: hongjinqiu/finance
func (o InterceptorCommon) FindByMapWithSession(session *mgo.Session, collection string, query map[string]interface{}) (result map[string]interface{}, found bool) {
	mongoDBFactory := mongo.GetInstance()
	db := mongoDBFactory.GetDatabase(session)
	c := db.C(collection)

	result = make(map[string]interface{})
	err := c.Find(query).One(&result)
	if err != nil {
		return result, false
	}

	return result, true
}
コード例 #10
0
ファイル: Query.go プロジェクト: hongjinqiu/finance
func (qb QuerySupport) MapReduce(collection string, query map[string]interface{}, mapReduce mgo.MapReduce, pageNo int, pageSize int) (result []map[string]interface{}) {
	mongoDBFactory := mongo.GetInstance()
	session, db := mongoDBFactory.GetConnection()
	defer session.Close()

	result = []map[string]interface{}{}
	_, err := db.C(collection).Find(query).Limit(pageSize).Skip((pageNo-1)*pageSize).MapReduce(&mapReduce, &result)
	if err != nil {
		panic(err)
	}

	return result
}
コード例 #11
0
ファイル: GlobalManager.go プロジェクト: hongjinqiu/finance
func setConnection(sId int) (*mgo.Session, *mgo.Database) {
	connectionFactory := mongo.GetInstance()
	session, db := connectionFactory.GetConnection()

	globalMapRwlock.Lock()
	defer globalMapRwlock.Unlock()

	if globalMap[sId] == nil {
		globalMap[sId] = map[string]interface{}{}
	}
	objMap := globalMap[sId].(map[string]interface{})
	objMap["session"] = session
	objMap["db"] = db
	globalMap[sId] = objMap
	return session, db
}
コード例 #12
0
ファイル: test.go プロジェクト: hongjinqiu/finance
func (c Test) AddRemoveTestData() revel.Result {
	userIdLi := []int{10, 20}
	modelTemplateFactory := ModelTemplateFactory{}
	dataSourceInfoLi := modelTemplateFactory.GetDataSourceInfoLi()
	//	 GetCollectionName
	// 初始化数据只有 billType,BillTypeParameter,CurrencyType,
	connectionFactory := mongo.GetInstance()
	_, db := connectionFactory.GetConnection()
	modelIterator := ModelIterator{}
	for _, item := range dataSourceInfoLi {
		collectionName := modelTemplateFactory.GetCollectionName(item.DataSource)
		_, err := db.C(collectionName).RemoveAll(map[string]interface{}{})
		if err != nil {
			panic(err)
		}
		if collectionName == "BillType" || collectionName == "BillTypeParameter" || collectionName == "CurrencyType" {

		} else {
			for _, userId := range userIdLi {
				for i := 0; i < 25; i += 1 {
					masterData := map[string]interface{}{}
					bo := map[string]interface{}{
						"A": masterData,
					}
					var result interface{} = ""
					modelIterator.IterateAllField(&item.DataSource, &result, func(fieldGroup *FieldGroup, result *interface{}) {
						if fieldGroup.IsMasterField() {
							c.initData(userId, *fieldGroup, &masterData)
						} else {
							dataSetId := fieldGroup.GetDataSetId()
							if bo[dataSetId] == nil {
								bo[dataSetId] = []interface{}{}
							}
							dataSetDataLi := bo[dataSetId].([]interface{})
							bo[dataSetId] = dataSetDataLi

							if len(dataSetDataLi) == 0 {
								dataSetDataLi = append(dataSetDataLi, map[string]interface{}{})
							}
							dataSetData0 := dataSetDataLi[0].(map[string]interface{})
							dataSetDataLi[0] = dataSetData0

							c.initData(userId, *fieldGroup, &dataSetData0)
						}
					})
					collectionSequenceName := mongo.GetCollectionSequenceName(collectionName)
					id := mongo.GetSequenceNo(db, collectionSequenceName)
					bo["_id"] = id
					bo["id"] = id
					masterData["id"] = id
					masterData["createBy"] = userId
					masterData["createUnit"] = userId
					masterData["createTime"] = DateUtil{}.GetCurrentYyyyMMddHHmmss()
					masterData["modifyBy"] = userId
					masterData["modifyUnit"] = userId
					masterData["modifyTime"] = DateUtil{}.GetCurrentYyyyMMddHHmmss()
					modelIterator.IterateDataBo(item.DataSource, &bo, &result, func(fieldGroupLi []FieldGroup, data *map[string]interface{}, rowIndex int, result *interface{}) {
						if !fieldGroupLi[0].IsMasterField() {
							id := mongo.GetSequenceNo(db, collectionSequenceName)
							(*data)["id"] = id
							(*data)["createBy"] = userId
							(*data)["createUnit"] = userId
							(*data)["createTime"] = DateUtil{}.GetCurrentYyyyMMddHHmmss()
							(*data)["modifyBy"] = userId
							(*data)["modifyUnit"] = userId
							(*data)["modifyTime"] = DateUtil{}.GetCurrentYyyyMMddHHmmss()
						}
					})
					modelTemplateFactory.ConvertDataType(item.DataSource, &bo)
					db.C(collectionName).Insert(bo)
				}
			}
		}
	}
	return c.RenderText("success")
}