Example #1
0
func (o FinanceService) validateMasterDataDuplicate(sessionId int, dataSource DataSource, bo map[string]interface{}) string {
	userId, err := strconv.Atoi(fmt.Sprint(global.GetGlobalAttr(sessionId, "userId")))
	if err != nil {
		panic(err)
	}
	session, _ := global.GetConnection(sessionId)

	message := ""
	modelTemplateFactory := ModelTemplateFactory{}
	strId := modelTemplateFactory.GetStrId(bo)
	andQueryLi := []map[string]interface{}{}
	qb := QuerySupport{}
	andQueryLi = append(andQueryLi, map[string]interface{}{
		"deleteFlag": map[string]interface{}{
			"$ne": 9,
		},
		"A.createUnit": qb.GetCreateUnitByUserId(session, userId),
	})
	andFieldNameLi := []string{}
	modelIterator := ModelIterator{}
	var result interface{} = ""
	modelIterator.IterateAllFieldBo(dataSource, &bo, &result, func(fieldGroup FieldGroup, data *map[string]interface{}, rowIndex int, result *interface{}) {
		if fieldGroup.IsMasterField() {
			if fieldGroup.AllowDuplicate == "false" && fieldGroup.Id != "id" {
				andQueryLi = append(andQueryLi, map[string]interface{}{
					"A." + fieldGroup.Id: (*data)[fieldGroup.Id],
				})
				andFieldNameLi = append(andFieldNameLi, fieldGroup.DisplayName)
			}
		}
	})
	if len(andFieldNameLi) > 0 {
		if !(strId == "" || strId == "0") {
			andQueryLi = append(andQueryLi, map[string]interface{}{
				"_id": map[string]interface{}{
					"$ne": bo["id"],
				},
			})
		}
		duplicateQuery := map[string]interface{}{
			"$and": andQueryLi,
		}
		collectionName := modelTemplateFactory.GetCollectionName(dataSource)
		_, db := global.GetConnection(sessionId)
		duplicateQueryByte, err := json.MarshalIndent(duplicateQuery, "", "\t")
		if err != nil {
			panic(err)
		}
		log.Println("validateMasterDataDuplicate,collectionName:" + collectionName + ", query:" + string(duplicateQueryByte))
		count, err := db.C(collectionName).Find(duplicateQuery).Limit(1).Count()
		if err != nil {
			panic(err)
		}
		if count > 0 {
			message = strings.Join(andFieldNameLi, "+") + "不允许重复"
		}
	}

	return message
}
Example #2
0
func (c BbsPostSupport) addOrUpdateBbsPostRead(sessionId int, bbsPostId int) {
	session, db := global.GetConnection(sessionId)
	txnManager := TxnManager{db}
	txnId := global.GetTxnId(sessionId)
	bbsPost := BbsPost{}
	modelTemplateFactory := ModelTemplateFactory{}
	bbsPostReadDS := modelTemplateFactory.GetDataSource("BbsPostRead")

	userId, err := strconv.Atoi(fmt.Sprint(global.GetGlobalAttr(sessionId, "userId")))
	if err != nil {
		panic(err)
	}
	dateUtil := DateUtil{}
	qb := QuerySupport{}

	bbsPostRead, found := qb.FindByMapWithSession(session, "BbsPostRead", map[string]interface{}{
		"A.bbsPostId": bbsPostId,
		"A.readBy":    userId,
	})
	if found {
		bbsPost.RSetModifyFixFieldValue(sessionId, bbsPostReadDS, &bbsPostRead)
		bbsPostReadA := bbsPostRead["A"].(map[string]interface{})
		bbsPostRead["A"] = bbsPostReadA

		bbsPostReadA["lastReadTime"] = dateUtil.GetCurrentYyyyMMddHHmmss()
		_, updateResult := txnManager.Update(txnId, "BbsPostRead", bbsPostRead)
		if !updateResult {
			panic(BusinessError{Message: "更新意见反馈阅读记录失败"})
		}
	} else {
		c.addBbsPostRead(sessionId, bbsPostId)
	}
}
func (o AccountInOutDisplaySupport) RAfterNewData(sessionId int, dataSource DataSource, formTemplate FormTemplate, bo *map[string]interface{}) {
	masterData := (*bo)["A"].(map[string]interface{})
	(*bo)["A"] = masterData

	session, _ := global.GetConnection(sessionId)
	qb := QuerySupport{}
	query := map[string]interface{}{
		"A.code": "RMB",
	}
	permissionSupport := PermissionSupport{}
	permissionQueryDict := permissionSupport.GetPermissionQueryDict(sessionId, formTemplate.Security)
	for k, v := range permissionQueryDict {
		query[k] = v
	}

	collectionName := "CurrencyType"
	{
		queryByte, err := json.MarshalIndent(&query, "", "\t")
		if err != nil {
			panic(err)
		}
		log.Println("RAfterNewData,collectionName:" + collectionName + ", query:" + string(queryByte))
	}
	result, found := qb.FindByMapWithSession(session, collectionName, query)
	if found {
		masterData["currencyTypeId"] = result["id"]
	}
}
/**
 * 添加现金账户会计期汇总(月档)记录
 * @param sessionId
 * @param accountInOutParam 参数对象
 */
func (o AccountInOutService) addFinAccountInOutForCash(sessionId int, accountInOutParam AccountInOutParam) map[string]interface{} {
	accountInOut := map[string]interface{}{
		"accountType":           accountInOutParam.AccountType,
		"accountId":             accountInOutParam.AccountId,
		"currencyTypeId":        accountInOutParam.CurrencyTypeId,
		"exchangeRateShow":      accountInOutParam.ExchangeRateShow,
		"exchangeRate":          accountInOutParam.ExchangeRate,
		"accountingPeriodYear":  accountInOutParam.AccountingPeriodYear,
		"accountingPeriodMonth": accountInOutParam.AccountingPeriodMonth,
		"amtIncrease":           "0",
		"amtReduce":             "0",
		"createBy":              accountInOutParam.CreateBy,
		"createTime":            accountInOutParam.CreateTime,
		"createUnit":            accountInOutParam.CreateUnit,
	}
	_, db := global.GetConnection(sessionId)
	dataSourceModelId := "AccountInOut"
	modelTemplateFactory := ModelTemplateFactory{}
	dataSource := modelTemplateFactory.GetDataSource(dataSourceModelId)
	masterSeqName := GetMasterSequenceName(dataSource)
	masterSeqId := GetSequenceNo(db, masterSeqName)
	accountInOut["id"] = masterSeqId
	bo := map[string]interface{}{
		"_id": masterSeqId,
		"id":  masterSeqId,
		"A":   accountInOut,
	}
	modelTemplateFactory.ConvertDataType(dataSource, &bo)
	txnManager := TxnManager{db}
	txnId := global.GetTxnId(sessionId)
	collectionName := modelTemplateFactory.GetCollectionName(dataSource)
	return txnManager.Insert(txnId, collectionName, bo)
}
/**
 * 删除日记帐明细
 * @param sessionId
 * @param accountInOutItemParam 日记帐明细业务参数
 */
func (o AccountInOutService) deleteCashBankDailyInOut(sessionId int, accountInOutItemParam AccountInOutItemParam) {
	_, db := global.GetConnection(sessionId)
	query := map[string]interface{}{
		"A.accountId":      accountInOutItemParam.AccountId,
		"A.currencyTypeId": accountInOutItemParam.CurrencyTypeId,
		"A.accountType":    accountInOutItemParam.AccountType,
		"A.billId":         accountInOutItemParam.BillId,
		"A.billTypeId":     accountInOutItemParam.BillTypeId,
	}
	if accountInOutItemParam.BillDetailId != 0 {
		query["A.billDetailId"] = accountInOutItemParam.BillDetailId
		query["A.billDetailName"] = accountInOutItemParam.BillDetailName
	} else {
		query["A.billDetailId"] = 0 // 主数据集记录
	}
	dataSourceModelId := "AccountInOutItem"
	modelTemplateFactory := ModelTemplateFactory{}
	dataSource := modelTemplateFactory.GetDataSource(dataSourceModelId)
	txnManager := TxnManager{db}
	txnId := global.GetTxnId(sessionId)
	collectionName := modelTemplateFactory.GetCollectionName(dataSource)
	_, result := txnManager.RemoveAll(txnId, collectionName, query)
	if !result {
		queryByte, err := json.MarshalIndent(&query, "", "\t")
		if err != nil {
			panic(err)
		}
		panic("删除日记账明细失败,查询语句为:" + string(queryByte))
	}
}
func (o AccountInOutService) GetFirstAccountingPeriodStartEndDate(sessionId int, year int) (int, int) {
	session, _ := global.GetConnection(sessionId)
	dataSourceModelId := "AccountingPeriod"
	modelTemplateFactory := ModelTemplateFactory{}
	dataSource := modelTemplateFactory.GetDataSource(dataSourceModelId)
	collectionName := modelTemplateFactory.GetCollectionName(dataSource)
	qb := QuerySupport{}
	userId, err := strconv.Atoi(fmt.Sprint(global.GetGlobalAttr(sessionId, "userId")))
	if err != nil {
		panic(err)
	}
	queryMap := map[string]interface{}{
		"A.accountingYear": year,
		"A.createUnit":     qb.GetCreateUnitByUserId(session, userId),
	}
	accountingPeriod, found := qb.FindByMapWithSession(session, collectionName, queryMap)
	if !found {
		panic(BusinessError{Message: "会计年度:" + fmt.Sprint(year) + "未找到对应会计期"})
		//		log.Println("会计年度:" + fmt.Sprint(year) + "未找到对应会计期")
		//		return 0, 0
	}
	var startDate int
	var endDate int
	bDataSetLi := accountingPeriod["B"].([]interface{})
	commonUtil := CommonUtil{}
	for _, item := range bDataSetLi {
		line := item.(map[string]interface{})
		startDate = commonUtil.GetIntFromMap(line, "startDate")
		endDate = commonUtil.GetIntFromMap(line, "endDate")
		break
	}
	return startDate, endDate
}
Example #7
0
func (c App) MenuList() revel.Result {
	sessionId := global.GetSessionId()
	defer global.CloseSession(sessionId)

	_, db := global.GetConnection(sessionId)
	menuResultLi := []map[string]interface{}{}
	err := db.C("Menu").Find(nil).Sort("level").All(&menuResultLi)
	if err != nil {
		panic(err)
	}

	menuLi := []map[string]interface{}{}
	for _, item := range menuResultLi {
		level := fmt.Sprint(item["level"])
		if len(level) == 3 {
			menuLi = append(menuLi, item)

			subMenuLi := []map[string]interface{}{}
			for _, subItem := range menuResultLi {
				subLevel := fmt.Sprint(subItem["level"])
				if len(subLevel) == 6 && subLevel[0:3] == level {
					subMenuLi = append(subMenuLi, subItem)
				}
			}
			item["subMenuLi"] = subMenuLi
		}
	}

	result := map[string]interface{}{
		"menuLi": menuLi,
	}
	return c.Render(result)
}
Example #8
0
func (c BbsPostSupport) addBbsPostRead(sessionId int, bbsPostId int) {
	_, db := global.GetConnection(sessionId)
	txnManager := TxnManager{db}
	txnId := global.GetTxnId(sessionId)
	bbsPost := BbsPost{}
	modelTemplateFactory := ModelTemplateFactory{}
	bbsPostReadDS := modelTemplateFactory.GetDataSource("BbsPostRead")

	userId, err := strconv.Atoi(fmt.Sprint(global.GetGlobalAttr(sessionId, "userId")))
	if err != nil {
		panic(err)
	}
	dateUtil := DateUtil{}
	sequenceNo := mongo.GetSequenceNo(db, "bbsPostReadId")
	bbsPostRead := map[string]interface{}{
		"_id": sequenceNo,
		"id":  sequenceNo,
		"A": map[string]interface{}{
			"id":           sequenceNo,
			"bbsPostId":    bbsPostId,
			"readBy":       userId,
			"lastReadTime": dateUtil.GetCurrentYyyyMMddHHmmss(),
		},
	}
	bbsPost.RSetCreateFixFieldValue(sessionId, bbsPostReadDS, &bbsPostRead)
	txnManager.Insert(txnId, "BbsPostRead", bbsPostRead)
}
Example #9
0
func (c Hjq) Login() revel.Result {
	if strings.ToLower(c.Request.Method) == "get" {
		//c.Response.ContentType = "text/html; charset=utf-8"
		return c.Render()
	}
	username := c.Params.Get("username")
	password := c.Params.Get("password")

	hash := sha1.New()
	_, err := io.WriteString(hash, password)
	if err != nil {
		panic(err)
	}
	encryPassword := fmt.Sprintf("%x", hash.Sum(nil))

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

	session, _ := global.GetConnection(sessionId)
	qb := QuerySupport{}
	user, found := qb.FindByMapWithSession(session, "SysUser", map[string]interface{}{
		"A.type":     1,
		"A.name":     username,
		"A.password": encryPassword,
	})
	if !found {
		c.Response.ContentType = "text/plain; charset=utf-8"
		return c.RenderText("用户名密码错误")
	}
	c.Session["adminUserId"] = fmt.Sprint(user["id"])
	c.Session["userId"] = fmt.Sprint(user["id"])

	return c.Redirect("/console/listschema?@name=LastSessionData&cookie=false")
}
func (o AccountInOutItemInterceptor) GetAccountingPeriodStartEndDate(sessionId int, year int, sequenceNo int) (int, int) {
	session, _ := global.GetConnection(sessionId)
	userId, err := strconv.Atoi(fmt.Sprint(global.GetGlobalAttr(sessionId, "userId")))
	if err != nil {
		panic(err)
	}
	collectionName := "AccountingPeriod"
	queryMap := map[string]interface{}{
		"A.accountingYear": year,
		"B.sequenceNo":     sequenceNo,
		"A.createUnit":     InterceptorCommon{}.GetCreateUnitByUserId(session, userId),
	}
	accountingPeriod, found := InterceptorCommon{}.FindByMapWithSession(session, collectionName, queryMap)
	if !found {
		//		panic(BusinessError{Message: "会计年度:" + fmt.Sprint(year) + ",会计期序号:" + fmt.Sprint(sequenceNo) + "未找到对应会计期"})
		log.Println("会计年度:" + fmt.Sprint(year) + ",会计期序号:" + fmt.Sprint(sequenceNo) + "未找到对应会计期")
		return 0, 0
	}
	var startDate int
	var endDate int
	bDataSetLi := accountingPeriod["B"].([]interface{})
	commonUtil := CommonUtil{}
	for _, item := range bDataSetLi {
		line := item.(map[string]interface{})
		if fmt.Sprint(line["sequenceNo"]) == fmt.Sprint(sequenceNo) {
			startDate = commonUtil.GetIntFromMap(line, "startDate")
			endDate = commonUtil.GetIntFromMap(line, "endDate")
			break
		}
	}
	return startDate, endDate
}
Example #11
0
// TODO
func (o TemplateManager) GetLayerForListTemplate(sId int, listTemplate ListTemplate) map[string]interface{} {
	_, db := global.GetConnection(sId)

	result := map[string]interface{}{}
	resultLi := map[string]interface{}{}
	layerManager := layer.GetInstance()

	listTemplateIterator := ListTemplateIterator{}
	var iterateResult interface{} = ""
	listTemplateIterator.IterateTemplateColumn(listTemplate, &iterateResult, func(column Column, iterateResult *interface{}) {
		if column.Dictionary != "" {
			layerMap := layerManager.GetLayerBySession(sId, db, column.Dictionary)
			if layerMap != nil {
				items := layerMap["items"]
				if items != nil {
					dictMap := map[string]interface{}{}
					for _, item := range items.([]map[string]interface{}) {
						dictMap[fmt.Sprint(item["code"])] = item
					}
					result[column.Dictionary] = dictMap
					resultLi[column.Dictionary] = items
				} else {
					result[column.Dictionary] = map[string]interface{}{}
					resultLi[column.Dictionary] = []interface{}{}
				}
			}
		}
	})

	return map[string]interface{}{
		"layerBo":   result,
		"layerBoLi": resultLi,
	}
}
Example #12
0
func (o TemplateManager) GetLayerForFormTemplate(sId int, formTemplate FormTemplate) map[string]interface{} {
	_, db := global.GetConnection(sId)

	result := map[string]interface{}{}
	resultLi := map[string]interface{}{}
	layerManager := layer.GetInstance()
	for _, item := range formTemplate.FormElemLi {
		if item.XMLName.Local == "column-model" {
			for _, column := range item.ColumnModel.ColumnLi {
				if column.Dictionary != "" {
					layerMap := layerManager.GetLayerBySession(sId, db, column.Dictionary)
					if layerMap != nil {
						items := layerMap["items"]
						if items != nil {
							dictMap := map[string]interface{}{}
							for _, item := range items.([]map[string]interface{}) {
								dictMap[fmt.Sprint(item["code"])] = item
							}
							result[column.Dictionary] = dictMap
							resultLi[column.Dictionary] = items
						} else {
							result[column.Dictionary] = map[string]interface{}{}
							resultLi[column.Dictionary] = []interface{}{}
						}
					}
				}
			}
		}
	}

	return map[string]interface{}{
		"layerBo":   result,
		"layerBoLi": resultLi,
	}
}
Example #13
0
func (o UsedCheck) Insert(sessionId int, fieldGroupLi []FieldGroup, bo *map[string]interface{}, data *map[string]interface{}) {
	_, db := global.GetConnection(sessionId)
	txnManager := TxnManager{db}
	txnId := global.GetTxnId(sessionId)
	createTime := DateUtil{}.GetCurrentYyyyMMddHHmmss()
	for _, fieldGroup := range fieldGroupLi {
		if fieldGroup.IsRelationField() {
			modelTemplateFactory := ModelTemplateFactory{}
			relationItem, found := modelTemplateFactory.ParseRelationExpr(fieldGroup, *bo, *data)
			if !found {
				panic("数据源:" + fieldGroup.GetDataSource().Id + ",数据集:" + fieldGroup.GetDataSetId() + ",字段:" + fieldGroup.Id + ",配置的关联模型列表,不存在返回true的记录")
			}
			referenceData := map[string]interface{}{
				"A": map[string]interface{}{
					"createBy":   (*data)["createBy"],
					"createTime": createTime,
					"createUnit": (*data)["createUnit"],
				},
				"reference":   o.GetSourceReferenceLi(db, fieldGroup, bo, data),
				"beReference": o.GetBeReferenceLi(db, fieldGroup, relationItem, data),
			}
			txnManager.Insert(txnId, "PubReferenceLog", referenceData)
		}
	}
}
Example #14
0
func (c BankAccountSupport) RAfterNewData(sessionId int, dataSource DataSource, formTemplate FormTemplate, bo *map[string]interface{}) {
	modelTemplateFactory := ModelTemplateFactory{}
	dataSetId := "B"
	data := modelTemplateFactory.GetDataSetNewData(dataSource, dataSetId, *bo)

	// 设置默认的币别
	qb := QuerySupport{}
	session, _ := global.GetConnection(sessionId)
	collection := "CurrencyType"
	query := map[string]interface{}{
		"A.code": "RMB",
	}
	permissionSupport := PermissionSupport{}
	permissionQueryDict := permissionSupport.GetPermissionQueryDict(sessionId, formTemplate.Security)
	for k, v := range permissionQueryDict {
		query[k] = v
	}

	currencyType, found := qb.FindByMapWithSession(session, collection, query)
	if !found {
		panic(BusinessError{Message: "没有找到币别人民币,请先配置默认币别"})
	}
	data["currencyTypeId"] = currencyType["id"]

	(*bo)["B"] = []interface{}{
		data,
	}
}
Example #15
0
func (o UsedCheck) deleteReference(sessionId int, referenceQueryLi []interface{}) {
	_, db := global.GetConnection(sessionId)
	txnManager := TxnManager{db}
	txnId := global.GetTxnId(sessionId)
	//	deleteQuery := map[string]interface{}{
	//		"reference": referenceQueryLi,
	//	}
	deleteQuery := map[string]interface{}{
	//"$and": referenceQueryLi,
	}
	andQuery := []interface{}{}
	for _, item := range referenceQueryLi {
		andQuery = append(andQuery, map[string]interface{}{
			"reference": item,
		})
	}
	deleteQuery["$and"] = andQuery
	deleteByte, err := json.MarshalIndent(&deleteQuery, "", "\t")
	if err != nil {
		panic(err)
	}
	log.Println("deleteReference,collection:PubReferenceLog,query is:" + string(deleteByte))
	count, err := db.C("PubReferenceLog").Find(deleteQuery).Limit(1).Count()
	if err != nil {
		panic(err)
	}
	if count > 0 {
		_, result := txnManager.RemoveAll(txnId, "PubReferenceLog", deleteQuery)
		if !result {
			panic("删除失败")
		}
	}
}
Example #16
0
func (o BbsPostInterceptor) AfterQueryData(sessionId int, dataSetId string, items []interface{}) []interface{} {
	session, _ := global.GetConnection(sessionId)
	userId, err := strconv.Atoi(fmt.Sprint(global.GetGlobalAttr(sessionId, "userId")))
	if err != nil {
		panic(err)
	}
	collectionName := "BbsPostRead"
	interceptorCommon := InterceptorCommon{}
	commonUtil := CommonUtil{}
	for i, item := range items {
		data := item.(map[string]interface{})
		dataA := data["A"].(map[string]interface{})
		data["A"] = dataA
		items[i] = data

		bbsPostReadQuery := map[string]interface{}{
			"A.bbsPostId": data["id"],
			"A.readBy":    userId,
		}
		bbsPostRead, found := interceptorCommon.FindByMapWithSession(session, collectionName, bbsPostReadQuery)
		if !found {
			data["bbsPostReadType"] = 1 // 未读
		} else {
			bbsPostReadA := bbsPostRead["A"].(map[string]interface{})
			lastReadTime := commonUtil.GetFloat64FromMap(bbsPostReadA, "lastReadTime")
			lastReplyTime := commonUtil.GetFloat64FromMap(dataA, "lastReplyTime")
			if lastReadTime < lastReplyTime {
				dataA["bbsPostReadType"] = 1 // 未读
			} else {
				dataA["bbsPostReadType"] = 2 // 已读
			}
		}
	}
	return items
}
Example #17
0
func (c BaseDataAction) RSetCreateFixFieldValue(sessionId int, dataSource DataSource, bo *map[string]interface{}) {
	var result interface{} = ""
	userId, err := strconv.Atoi(fmt.Sprint(global.GetGlobalAttr(sessionId, "userId")))
	if err != nil {
		panic(err)
	}
	createTime, err := strconv.ParseInt(time.Now().Format("20060102150405"), 10, 64)
	if err != nil {
		panic(err)
	}
	_, db := global.GetConnection(sessionId)
	sysUser := map[string]interface{}{}
	query := map[string]interface{}{
		"_id": userId,
	}
	err = db.C("SysUser").Find(query).One(&sysUser)
	if err != nil {
		panic(err)
	}
	sysUserMaster := sysUser["A"].(map[string]interface{})
	modelIterator := ModelIterator{}
	modelIterator.IterateDataBo(dataSource, bo, &result, func(fieldGroupLi []FieldGroup, data *map[string]interface{}, rowIndex int, result *interface{}) {
		(*data)["createBy"] = userId
		(*data)["createTime"] = createTime
		(*data)["createUnit"] = sysUserMaster["createUnit"]
	})
}
Example #18
0
/**
* 为避免并发问题,重设amtOriginalCurrencyBalance为数据库中值
 */
func (o CashAccountSupport) RBeforeSaveData(sessionId int, dataSource DataSource, formTemplate FormTemplate, bo *map[string]interface{}) {
	session, _ := global.GetConnection(sessionId)
	modelTemplateFactory := ModelTemplateFactory{}
	strId := modelTemplateFactory.GetStrId(*bo)
	if strId != "" && strId != "0" {
		id, err := strconv.Atoi(strId)
		if err != nil {
			panic(err)
		}
		qb := QuerySupport{}
		queryMap := map[string]interface{}{
			"_id": id,
		}
		permissionSupport := PermissionSupport{}
		permissionQueryDict := permissionSupport.GetPermissionQueryDict(sessionId, formTemplate.Security)
		for k, v := range permissionQueryDict {
			queryMap[k] = v
		}

		collectionName := "CashAccount"
		boInDb, found := qb.FindByMapWithSession(session, collectionName, queryMap)
		if !found {
			panic(BusinessError{Message: "现金账户保存前,现金账户未找到"})
		}

		masterData := (*bo)["A"].(map[string]interface{})
		(*bo)["A"] = masterData

		masterDataInDb := boInDb["A"].(map[string]interface{})
		boInDb["A"] = masterDataInDb

		masterData["amtOriginalCurrencyBalance"] = masterDataInDb["amtOriginalCurrencyBalance"]
	}
}
Example #19
0
func (o PermissionSupport) GetPermissionQueryDict(sessionId int, security Security) map[string]interface{} {
	if security.ByUnit == "true" {
		userIdI := global.GetGlobalAttr(sessionId, "userId")
		userId, err := strconv.Atoi(fmt.Sprint(userIdI))
		if err != nil {
			panic(err)
		}
		querySupport := QuerySupport{}
		session, _ := global.GetConnection(sessionId)
		collectionName := "SysUser"
		sysUser, found := querySupport.FindByMapWithSession(session, collectionName, map[string]interface{}{
			"_id": userId,
		})
		if found {
			sysUserMaster := sysUser["A"].(map[string]interface{})
			return map[string]interface{}{
				"A.createUnit": sysUserMaster["createUnit"],
			}
		}
		return map[string]interface{}{
			"_id": -1,
		}
	}
	if security.ByAdmin == "true" {
		adminUserId := global.GetGlobalAttr(sessionId, "adminUserId")
		if adminUserId != nil && fmt.Sprint(adminUserId) != "" {
			return map[string]interface{}{}
		}
		return map[string]interface{}{
			"_id": -1,
		}
	}
	return map[string]interface{}{}
}
Example #20
0
/**
删除前判断被用,会计期内有单据则视为被用
*/
func (o AccountingPeriodSupport) RBeforeDeleteData(sessionId int, dataSource DataSource, formTemplate FormTemplate, bo *map[string]interface{}) {
	bDataSetLi := (*bo)["B"].([]interface{})
	firstLineData := bDataSetLi[0].(map[string]interface{})
	lastLineData := bDataSetLi[len(bDataSetLi)-1].(map[string]interface{})

	commonUtil := CommonUtil{}
	firstStartDate := commonUtil.GetIntFromMap(firstLineData, "startDate")
	lastEndDate := commonUtil.GetIntFromMap(lastLineData, "endDate")

	qb := QuerySupport{}
	session, _ := global.GetConnection(sessionId)
	queryMap := map[string]interface{}{
		"A.billDate": map[string]interface{}{
			"$gte": firstStartDate,
			"$lt":  lastEndDate,
		},
	}
	permissionSupport := PermissionSupport{}
	permissionQueryDict := permissionSupport.GetPermissionQueryDict(sessionId, formTemplate.Security)
	for k, v := range permissionQueryDict {
		queryMap[k] = v
	}

	modelTemplateFactory := ModelTemplateFactory{}
	dataSourceIdLi := []string{"GatheringBill", "PayBill"}
	for _, dataSourceId := range dataSourceIdLi {
		tmpDataSource := modelTemplateFactory.GetDataSource(dataSourceId)
		collectionName := modelTemplateFactory.GetCollectionName(tmpDataSource)
		_, found := qb.FindByMapWithSession(session, collectionName, queryMap)
		if found {
			panic(BusinessError{Message: "会计期范围内存在单据,不能删除"})
		}
	}
}
Example #21
0
/**
初始化系统参数
*/
func (o StepService) InitSystemParameter(sessionId int, sysUser map[string]interface{}) {
	sysUserMaster := sysUser["A"].(map[string]interface{})
	txnId := global.GetTxnId(sessionId)
	session, db := global.GetConnection(sessionId)
	txnManager := TxnManager{db}
	qb := QuerySupport{}
	initDataLi := []map[string]interface{}{
		map[string]interface{}{
			"percentDecimals":    3,
			"percentRoundingWay": 2,
			"thousandDecimals":   2,
			//			"currencyTypeId": xxxx,
			"costDecimals": 3,
			//			"taxTypeId": xxxx,
		},
	}
	for _, initData := range initDataLi {
		_, found := qb.FindByMapWithSession(session, "SystemParameter", map[string]interface{}{
			"A.createUnit": sysUserMaster["createUnit"],
		})
		if !found {
			id := mongo.GetSequenceNo(db, "systemParameterId")
			aData := map[string]interface{}{
				"id":          id,
				"createBy":    sysUserMaster["id"],
				"createTime":  DateUtil{}.GetCurrentYyyyMMddHHmmss(),
				"createUnit":  sysUserMaster["createUnit"],
				"modifyBy":    0,
				"modifyTime":  0,
				"modifyUnit":  0,
				"billStatus":  0,
				"attachCount": 0,
				"remark":      "",
			}
			for k, v := range initData {
				aData[k] = v
			}
			// 币别
			currencyType, found := qb.FindByMapWithSession(session, "CurrencyType", map[string]interface{}{
				"A.createUnit": sysUserMaster["createUnit"],
			})
			if found {
				aData["currencyTypeId"] = currencyType["id"]
			}
			taxType, found := qb.FindByMapWithSession(session, "TaxType", map[string]interface{}{
				"A.createUnit": sysUserMaster["createUnit"],
			})
			if found {
				aData["taxTypeId"] = taxType["id"]
			}
			data := map[string]interface{}{
				"_id": id,
				"id":  id,
				"A":   aData,
			}
			txnManager.Insert(txnId, "SystemParameter", data)
		}
	}
}
Example #22
0
/**
取得max(会计期结束日期<date)的会计期年月
@param date yyyyMMdd
*/
func (c AccountInOutDisplay) getLastAccountingYearSequenceNoByYearMonth(sessionId int, formTemplate FormTemplate, accountingYear int, sequenceNo int) (int, int) {
	session, _ := global.GetConnection(sessionId)
	querySupport := QuerySupport{}
	queryMap := map[string]interface{}{
		"$or": []interface{}{
			map[string]interface{}{
				"A.accountingYear": accountingYear,
				"B.sequenceNo": map[string]interface{}{
					"$lt": sequenceNo,
				},
			},
			map[string]interface{}{
				"A.accountingYear": map[string]interface{}{
					"$lt": accountingYear,
				},
			},
		},
	}
	permissionSupport := PermissionSupport{}
	permissionQueryDict := permissionSupport.GetPermissionQueryDict(sessionId, formTemplate.Security)
	for k, v := range permissionQueryDict {
		queryMap[k] = v
	}

	collectionName := "AccountingPeriod"
	pageNo := 1
	pageSize := 1
	orderBy := "-A.accountingYear"
	queryResult := querySupport.IndexWithSession(session, collectionName, queryMap, pageNo, pageSize, orderBy)
	items := queryResult["items"].([]interface{})
	if len(items) > 0 {
		commonUtil := CommonUtil{}
		accountingPeriod := items[0].(map[string]interface{})
		master := accountingPeriod["A"].(map[string]interface{})
		accountingYearToReturn := commonUtil.GetIntFromMap(master, "accountingYear")
		sequenceNoToReturn := 0
		detailB := accountingPeriod["B"].([]interface{})
		detailLength := len(detailB)
		i := detailLength - 1
		for i >= 0 {
			line := detailB[i].(map[string]interface{})
			sequenceNoInDB := commonUtil.GetIntFromMap(line, "sequenceNo")

			if accountingYearToReturn < accountingYear {
				sequenceNoToReturn = sequenceNoInDB
				break
			}

			if sequenceNoInDB < sequenceNo {
				sequenceNoToReturn = sequenceNoInDB
				break
			}
			i -= 1
		}
		return accountingYearToReturn, sequenceNoToReturn
	} else {
		return 0, 0
	}
}
Example #23
0
func (c Console) getCurrencyType(sessionId int, currencyTypeId int) map[string]interface{} {
	session, _ := global.GetConnection(sessionId)
	querySupport := QuerySupport{}
	currencyType := querySupport.FindByMapWithSessionExact(session, "CurrencyType", map[string]interface{}{
		"_id": currencyTypeId,
	})
	return currencyType
}
Example #24
0
func (c BaseDataAction) CommitTxn(sessionId int) {
	txnId := global.GetGlobalAttr(sessionId, "txnId")
	if txnId != nil {
		_, db := global.GetConnection(sessionId)
		txnManager := TxnManager{db}
		txnManager.Commit(txnId.(int))
	}
}
Example #25
0
func (c App) getSysUnit(sessionId int, user map[string]interface{}) map[string]interface{} {
	userMain := user["A"].(map[string]interface{})
	session, _ := global.GetConnection(sessionId)
	qb := QuerySupport{}
	return qb.FindByMapWithSessionExact(session, "SysUnit", map[string]interface{}{
		"id": userMain["createUnit"],
	})
}
Example #26
0
func (c Console) RSetModifyFixFieldValue(sessionId int, dataSource DataSource, bo *map[string]interface{}) {
	var result interface{} = ""
	userId, err := strconv.Atoi(fmt.Sprint(global.GetGlobalAttr(sessionId, "userId")))
	if err != nil {
		panic(err)
	}
	modifyTime, err := strconv.ParseInt(time.Now().Format("20060102150405"), 10, 64)
	if err != nil {
		panic(err)
	}
	_, db := global.GetConnection(sessionId)
	sysUser := map[string]interface{}{}
	query := map[string]interface{}{
		"_id": userId,
	}
	err = db.C("SysUser").Find(query).One(&sysUser)
	if err != nil {
		panic(err)
	}
	sysUserMaster := sysUser["A"].(map[string]interface{})

	srcBo := map[string]interface{}{}
	srcQuery := map[string]interface{}{
		"_id":          (*bo)["id"],
		"A.createUnit": sysUserMaster["createUnit"],
	}
	// log
	modelTemplateFactory := ModelTemplateFactory{}
	collectionName := modelTemplateFactory.GetCollectionName(dataSource)
	srcQueryByte, err := json.Marshal(&srcQuery)
	if err != nil {
		panic(err)
	}
	log.Println("RSetModifyFixFieldValue,collectionName:" + collectionName + ", query:" + string(srcQueryByte))
	db.C(collectionName).Find(srcQuery).One(&srcBo)
	modelIterator := ModelIterator{}
	modelIterator.IterateDiffBo(dataSource, bo, srcBo, &result, func(fieldGroupLi []FieldGroup, destData *map[string]interface{}, srcData map[string]interface{}, result *interface{}) {
		if destData != nil && srcData == nil {
			(*destData)["createBy"] = userId
			(*destData)["createTime"] = modifyTime
			(*destData)["createUnit"] = sysUserMaster["createUnit"]
		} else if destData == nil && srcData != nil {
			// 删除,不处理
		} else if destData != nil && srcData != nil {
			isMasterData := fieldGroupLi[0].IsMasterField()
			isDetailDataDiff := (!fieldGroupLi[0].IsMasterField()) && modelTemplateFactory.IsDataDifferent(fieldGroupLi, *destData, srcData)
			if isMasterData || isDetailDataDiff {
				(*destData)["createBy"] = srcData["createBy"]
				(*destData)["createTime"] = srcData["createTime"]
				(*destData)["createUnit"] = srcData["createUnit"]

				(*destData)["modifyBy"] = userId
				(*destData)["modifyTime"] = modifyTime
				(*destData)["modifyUnit"] = sysUserMaster["createUnit"]
			}
		}
	})
}
Example #27
0
func (o UsedCheck) GetListUsedCheck(sessionId int, dataSource DataSource, items []interface{}, dataSetId string) map[string]interface{} {
	result := map[string]interface{}{}
	_, db := global.GetConnection(sessionId)
	for _, item := range items {
		itemMap := item.(map[string]interface{})
		dataSetData := itemMap
		referenceQuery := []interface{}{
			dataSource.Id,
			dataSetId,
			"id",
			dataSetData["id"],
		}
		queryMap := map[string]interface{}{
			"beReference": referenceQuery,
		}
		queryByte, err := json.MarshalIndent(&queryMap, "", "\t")
		if err != nil {
			panic(err)
		}
		log.Println("GetListUsedCheck,collection:PubReferenceLog,query is:" + string(queryByte))
		count, err := db.C("PubReferenceLog").Find(queryMap).Limit(1).Count()
		if err != nil {
			panic(err)
		}
		isUsed := count > 0
		if result[dataSetId] == nil {
			result[dataSetId] = map[string]interface{}{}
		}
		dataSetUsedMap := result[dataSetId].(map[string]interface{})
		dataSetUsedMap[fmt.Sprint(dataSetData["id"])] = isUsed
		result[dataSetId] = dataSetUsedMap
		/*
			if itemMap[dataSetId] != nil {
				dataSetData := itemMap[dataSetId].(map[string]interface{})
				referenceQuery := []interface{}{
					dataSource.Id,
					dataSetId,
					"id",
					dataSetData["id"],
				}
				count, err := db.C("PubReferenceLog").Find(map[string]interface{}{
					"reference": referenceQuery,
				}).Limit(1).Count()
				if err != nil {
					panic(err)
				}
				isUsed := count > 0
				if result[dataSetId] == nil {
					result[dataSetId] = map[string]interface{}{}
				}
				dataSetUsedMap := result[dataSetId].(map[string]interface{})
				dataSetUsedMap[fmt.Sprint(dataSetData["id"])] = isUsed
				result[dataSetId] = dataSetUsedMap
			}
		*/
	}
	return result
}
Example #28
0
func (o AccountInOutService) GetAccountingPeriodYearSequenceNo(sessionId int, ymd int) (int, int) {
	session, _ := global.GetConnection(sessionId)
	dataSourceModelId := "AccountingPeriod"
	modelTemplateFactory := ModelTemplateFactory{}
	dataSource := modelTemplateFactory.GetDataSource(dataSourceModelId)
	collectionName := modelTemplateFactory.GetCollectionName(dataSource)
	qb := QuerySupport{}
	userId, err := strconv.Atoi(fmt.Sprint(global.GetGlobalAttr(sessionId, "userId")))
	if err != nil {
		panic(err)
	}
	queryMap := map[string]interface{}{
		"B.startDate": map[string]interface{}{
			"$lte": ymd,
		},
		"B.endDate": map[string]interface{}{
			"$gte": ymd,
		},
		"A.createUnit": qb.GetCreateUnitByUserId(session, userId),
	}
	accountingPeriod, found := qb.FindByMapWithSession(session, collectionName, queryMap)
	if !found {
		billDate, err := time.Parse("20060102", fmt.Sprint(ymd))
		if err != nil {
			panic(err)
		}
		//		log.Println("单据日期" + billDate.Format("2006-01-02") + "未找到对应会计期")
		//		return 0,0
		panic(BusinessError{Message: "单据日期" + billDate.Format("2006-01-02") + "未找到对应会计期"})
	}
	masterData := accountingPeriod["A"].(map[string]interface{})
	year, err := strconv.Atoi(fmt.Sprint(masterData["accountingYear"]))
	if err != nil {
		panic(err)
	}
	var sequenceNo int
	bDataSetLi := accountingPeriod["B"].([]interface{})
	for _, item := range bDataSetLi {
		line := item.(map[string]interface{})
		if fmt.Sprint(line["startDate"]) <= fmt.Sprint(ymd) && fmt.Sprint(ymd) <= fmt.Sprint(line["endDate"]) {
			sequenceNo, err = strconv.Atoi(fmt.Sprint(line["sequenceNo"]))
			if err != nil {
				panic(err)
			}
			break
		}
	}
	//	if sequenceNo == 0 {
	//		billDate, err := time.Parse("20060102", fmt.Sprint(ymd))
	//		if err != nil {
	//			panic(err)
	//		}
	//		panic(BusinessError{Message: "单据日期" + billDate.Format("2006-01-02") + "找到年度" + fmt.Sprint(year) + ",未找到会计期"})
	//	}

	return year, sequenceNo
}
Example #29
0
func (c App) getPayBillLi(sessionId int, user map[string]interface{}) []map[string]interface{} {
	userMain := user["A"].(map[string]interface{})
	_, db := global.GetConnection(sessionId)
	li := []map[string]interface{}{}
	err := db.C("PayBill").Find(map[string]interface{}{
		"A.createUnit": userMain["createUnit"],
	}).Limit(6).Sort("-A.billDate").All(&li)
	if err != nil {
		panic(err)
	}
	result := []map[string]interface{}{}
	cashAccountIdLi := []int{}
	bankAccountIdLi := []int{}

	customerChamberlainId := []int{}
	providerChamberlainId := []int{}
	sysUserChamberlainId := []int{}

	commonUtil := CommonUtil{}
	dateUtil := DateUtil{}
	for _, item := range li {
		master := item["A"].(map[string]interface{})
		if fmt.Sprint(master["property"]) == "1" { // 银行
			bankAccountIdLi = append(bankAccountIdLi, commonUtil.GetIntFromMap(master, "accountId"))
		} else if fmt.Sprint(master["property"]) == "2" { // 现金
			cashAccountIdLi = append(cashAccountIdLi, commonUtil.GetIntFromMap(master, "accountId"))
		}
		if fmt.Sprint(master["payerType"]) == "1" { // customer
			customerChamberlainId = append(customerChamberlainId, commonUtil.GetIntFromMap(master, "payerId"))
		} else if fmt.Sprint(master["payerType"]) == "2" { // provider
			providerChamberlainId = append(providerChamberlainId, commonUtil.GetIntFromMap(master, "payerId"))
		} else if fmt.Sprint(master["payerType"]) == "3" { // sysUser
			sysUserChamberlainId = append(sysUserChamberlainId, commonUtil.GetIntFromMap(master, "payerId"))
		}
		resultItem := map[string]interface{}{
			"id":        master["id"],
			"billDate":  dateUtil.ConvertDate2String(fmt.Sprint(master["billDate"]), "20060102", "2006-01-02"),
			"billNo":    master["billNo"],
			"property":  master["property"],
			"accountId": master["accountId"],
			"account":   "",
			"payerType": master["payerType"],
			"payerId":   master["payerId"],
			"payer":     "",
			"amtPay":    commonUtil.TrimZero(master["amtPay"].(string)),
		}
		result = append(result, resultItem)
	}
	c.mergeCashAccount(sessionId, cashAccountIdLi, &result)
	c.mergeBankAccount(sessionId, bankAccountIdLi, &result)

	c.mergePayCustomer(sessionId, customerChamberlainId, &result)
	c.mergePayProvider(sessionId, providerChamberlainId, &result)
	c.mergePaySysUser(sessionId, sysUserChamberlainId, &result)

	return result
}
Example #30
0
func (o TemplateManager) GetRelationBo(sId int, relationLi []map[string]interface{}) map[string]interface{} {
	_, db := global.GetConnection(sId)
	result := map[string]interface{}{}
	for _, item := range relationLi {
		relationId, err := strconv.Atoi(fmt.Sprint(item["relationId"]))
		if err != nil {
			panic(err)
		}
		if relationId == 0 {
			continue
		}
		selectorId := fmt.Sprint(item["selectorId"])
		listTemplate := o.GetSelectorTemplate(selectorId)
		collection := listTemplate.DataProvider.Collection
		element := map[string]interface{}{}
		queryMap := map[string]interface{}{
			"_id": relationId,
		}
		queryByte, err := json.MarshalIndent(queryMap, "", "\t")
		if err != nil {
			panic(err)
		}
		log.Println("GetRelationBo,collection:" + collection + ",query is:" + string(queryByte))
		err = db.C(collection).Find(queryMap).One(&element)
		if err != nil {
			if err == mgo.ErrNotFound {
				continue
			}
			panic(err)
		}
		items := []interface{}{element}
		interceptorManager := InterceptorManager{}
		items = interceptorManager.ParseAfterQueryData(sId, listTemplate.AfterQueryData, listTemplate.ColumnModel.DataSetId, items)
		if len(items) > 0 {
			itemsDict := o.GetColumnModelDataForListTemplate(sId, listTemplate, items)
			items = itemsDict["items"].([]interface{})
			element = items[0].(map[string]interface{})
		} else {
			continue
		}
		if result[selectorId] == nil {
			result[selectorId] = map[string]interface{}{}
		}
		selectorDict := result[selectorId].(map[string]interface{})
		selectorDict[fmt.Sprint(relationId)] = element
		if selectorDict["url"] == nil {
			selectorDict["url"] = o.GetViewUrl(listTemplate)
		}
		if selectorDict["Description"] == nil {
			selectorDict["Description"] = listTemplate.Description
		}
		result[selectorId] = selectorDict
	}
	return result
}