Exemple #1
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{}{}
}
Exemple #2
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"]
	})
}
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
}
Exemple #4
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
}
Exemple #5
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)
}
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
}
Exemple #7
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 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
}
Exemple #9
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))
	}
}
Exemple #10
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"]
			}
		}
	})
}
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
}
/**
 * 银行帐户赤字检查
 * @param sessionId
 * @param accountId
 * @param currencyTypeId
 * @return {code: int, message: string}
 * code AccountLimitControlStatus.SUCCESS:检查通过
 * code AccountLimitControlStatus.FORBID:赤字字段为禁止,保存时金额 < 0,需要调用方抛出异常通知客户端
 * code AccountLimitControlStatus.WARN:赤字字段为警告,保存时金额 < 0,需要调用方提供警告信息通知客户端
 */
func (o AccountInOutService) CheckBankAccountLimitControl(sessionId int, accountId int, currencyTypeId int) map[string]interface{} {
	session, _ := global.GetConnection(sessionId)
	userId, err := strconv.Atoi(fmt.Sprint(global.GetGlobalAttr(sessionId, "userId")))
	if err != nil {
		panic(err)
	}
	qb := QuerySupport{}
	queryMap := map[string]interface{}{
		"_id":          accountId,
		"A.createUnit": qb.GetCreateUnitByUserId(session, userId),
	}
	collectionName := "BankAccount"
	bankAccountBo, found := qb.FindByMapWithSession(session, collectionName, queryMap)
	if !found {
		queryMapByte, err := json.Marshal(&queryMap)
		if err != nil {
			panic(err)
		}
		panic(BusinessError{Message: "银行账户没找到,查询条件为:" + string(queryMapByte)})
	}
	bankAccountMaster := bankAccountBo["A"].(map[string]interface{})
	bDetailDataLi := bankAccountBo["B"].([]interface{})
	commonUtil := CommonUtil{}
	for _, item := range bDetailDataLi {
		bankAccountCurrencyType := item.(map[string]interface{})
		if fmt.Sprint(bankAccountCurrencyType["currencyTypeId"]) == fmt.Sprint(currencyTypeId) {
			limitsControl := fmt.Sprint(bankAccountCurrencyType["limitsControl"])
			amtOriginalCurrencyBalanceStr := fmt.Sprint(bankAccountCurrencyType["amtOriginalCurrencyBalance"])
			amtOriginalCurrencyBalance := commonUtil.GetFloat64FromString(amtOriginalCurrencyBalanceStr)

			if limitsControl == "1" { // 禁止
				if amtOriginalCurrencyBalance < 0 {
					result := map[string]interface{}{
						"code":    LIMIT_CONTROL_FORBID,
						"message": "帐户:" + fmt.Sprint(bankAccountMaster["name"]) + "出现赤字!",
					}
					return result
				}
			} else if limitsControl == "2" { // 警告
				if amtOriginalCurrencyBalance < 0 {
					result := map[string]interface{}{
						"code":    LIMIT_CONTROL_WARN,
						"message": "帐户:" + fmt.Sprint(bankAccountMaster["name"]) + "出现赤字!",
					}
					return result
				}
			}
			break
		}
	}
	return map[string]interface{}{
		"code": LIMIT_CONTROL_SUCCESS,
	}
}
Exemple #13
0
func (c BaseDataAction) RRollbackTxn(sessionId int) {
	txnId := global.GetGlobalAttr(sessionId, "txnId")
	if txnId != nil {
		if x := recover(); x != nil {
			_, db := global.GetConnection(sessionId)
			txnManager := TxnManager{db}
			txnManager.Rollback(txnId.(int))
			panic(x)
		}
	}
}
func (o ProgramDictionaryManager) GetAccountingPeriodStartProgramDictionary(sessionId int, db *mgo.Database, code string) map[string]interface{} {
	userId, err := strconv.Atoi(fmt.Sprint(global.GetGlobalAttr(sessionId, "userId")))
	if err != nil {
		panic(err)
	}

	collection := "AccountingPeriod"
	c := db.C(collection)
	
	session, _ := global.GetConnection(sessionId)
	queryMap := map[string]interface{}{
		"A.createUnit": o.GetCreateUnitByUserId(session, userId),
	}
	
	itemResult := []map[string]interface{}{}
	err = c.Find(queryMap).All(&itemResult)
	if err != nil {
		panic(err)
	}
	
	result := map[string]interface{}{}
	result["code"] = code
	items := []interface{}{}
	for _, item := range itemResult {
		detailLi := item["B"].([]interface{})
		for _, detail := range detailLi {
			detailMap := detail.(map[string]interface{})
			isIn := false
			for _, dictItem := range items {
				dictItemMap := dictItem.(map[string]interface{})
				if fmt.Sprint(dictItemMap["code"]) == fmt.Sprint(detailMap["sequenceNo"]) {
					isIn = true
					break
				}
			}
			if !isIn {
				items = append(items, map[string]interface{}{
					"code": detailMap["sequenceNo"],
					"name": detailMap["sequenceNo"],
					"order": detailMap["sequenceNo"],
				})
			}
		}
	}
	result["items"] = items
	
	// 排序
	o.sortProgramDictionary(&result)
	return result
}
/**
 * 现金帐户过帐,
 * @param depositLogParam 过帐参数对象
 */
func (o AccountInOutService) LogCashAccountInOut(sessionId int, accountInOutParam AccountInOutParam) {
	session, db := global.GetConnection(sessionId)
	userId, err := strconv.Atoi(fmt.Sprint(global.GetGlobalAttr(sessionId, "userId")))
	if err != nil {
		panic(err)
	}
	collectionName := "CashAccount"
	querySupport := QuerySupport{}
	queryMap := map[string]interface{}{
		"_id":          accountInOutParam.AccountId,
		"A.createUnit": querySupport.GetCreateUnitByUserId(session, userId),
	}
	cashAccountBo, found := querySupport.FindByMapWithSession(session, collectionName, queryMap)
	if !found {
		queryMapByte, err := json.Marshal(&queryMap)
		if err != nil {
			panic(err)
		}
		panic(BusinessError{Message: "现金账户没找到,查询条件为:" + string(queryMapByte)})
	}

	mathUtil := MathUtil{}
	cashAccount := cashAccountBo["A"].(map[string]interface{})
	if fmt.Sprint(cashAccount["currencyTypeId"]) != fmt.Sprint(accountInOutParam.CurrencyTypeId) {
		panic(BusinessError{Message: "过账现金账户:" + fmt.Sprint(cashAccount["name"]) + "未找到对应币别"})
	}

	amtOriginalCurrencyBalance := fmt.Sprint(cashAccount["amtOriginalCurrencyBalance"])

	amtIncrease := accountInOutParam.AmtIncrease
	amtReduce := accountInOutParam.AmtReduce

	if accountInOutParam.DiffDataType == ADD || accountInOutParam.DiffDataType == AFTER_UPDATE { // 正过账
		amtOriginalCurrencyBalance = mathUtil.Add(amtOriginalCurrencyBalance, amtIncrease)
		amtOriginalCurrencyBalance = mathUtil.Sub(amtOriginalCurrencyBalance, amtReduce)
	} else if accountInOutParam.DiffDataType == BEFORE_UPDATE || accountInOutParam.DiffDataType == DELETE { // 反过账
		amtOriginalCurrencyBalance = mathUtil.Sub(amtOriginalCurrencyBalance, amtIncrease)
		amtOriginalCurrencyBalance = mathUtil.Add(amtOriginalCurrencyBalance, amtReduce)
	}
	commonUtil := CommonUtil{}
	cashAccount["amtOriginalCurrencyBalance"] = commonUtil.GetFloatFormat(amtOriginalCurrencyBalance)
	cashAccountBo["A"] = cashAccount
	txnManager := TxnManager{db}
	txnId := global.GetTxnId(sessionId)
	_, found = txnManager.Update(txnId, collectionName, cashAccountBo)
	if !found {
		panic(BusinessError{Message: "现金账户更新失败"})
	}
}
Exemple #16
0
func (c BbsPostSupport) RAfterDeleteData(sessionId int, dataSource DataSource, formTemplate FormTemplate, bo *map[string]interface{}) {
	// 反过账
	_, db := global.GetConnection(sessionId)
	txnManager := TxnManager{db}
	txnId := global.GetTxnId(sessionId)
	userId, err := strconv.Atoi(fmt.Sprint(global.GetGlobalAttr(sessionId, "userId")))
	if err != nil {
		panic(err)
	}

	query := map[string]interface{}{
		"A.bbsPostId": (*bo)["id"],
		"A.readBy":    userId,
	}
	txnManager.RemoveAll(txnId, "BbsPostRead", query)
}
Exemple #17
0
func (o GatheringBillSupport) setBillNo(sessionId int, bo *map[string]interface{}) {
	master := (*bo)["A"].(map[string]interface{})
	(*bo)["A"] = master
	session, _ := global.GetConnection(sessionId)

	userId, err := strconv.Atoi(fmt.Sprint(global.GetGlobalAttr(sessionId, "userId")))
	if err != nil {
		panic(err)
	}
	// 单据编号
	qb := QuerySupport{}
	gatheringBillCollectionName := "GatheringBill"
	billNoQuery := map[string]interface{}{
		"A.createUnit": qb.GetCreateUnitByUserId(session, userId),
	}
	pageNo := 1
	pageSize := 1
	orderBy := "-A.billNo"
	result := qb.IndexWithSession(session, gatheringBillCollectionName, billNoQuery, pageNo, pageSize, orderBy)
	items := result["items"].([]interface{})
	dateUtil := DateUtil{}
	if len(items) > 0 {
		maxItem := items[0].(map[string]interface{})
		maxItemA := maxItem["A"].(map[string]interface{})
		maxBillNo := fmt.Sprint(maxItemA["billNo"])

		regx := regexp.MustCompile(`^.*?(\d+)$`)
		matchResult := regx.FindStringSubmatch(maxBillNo)
		if len(matchResult) >= 2 {
			matchNum := matchResult[1]
			matchInt, err := strconv.Atoi(matchNum)
			if err != nil {
				master["billNo"] = fmt.Sprint(dateUtil.GetCurrentYyyyMMdd()) + "_001"
			} else {
				matchStr := fmt.Sprint(matchInt + 1)
				if len(matchStr) < 3 {
					matchStr = "000"[:(3-len(matchStr))] + matchStr
				}
				master["billNo"] = fmt.Sprint(dateUtil.GetCurrentYyyyMMdd()) + "_" + matchStr
			}
		} else {
			master["billNo"] = fmt.Sprint(dateUtil.GetCurrentYyyyMMdd()) + "_001"
		}
	} else {
		master["billNo"] = fmt.Sprint(dateUtil.GetCurrentYyyyMMdd()) + "_001"
	}
}
/**
 * 检查现金帐户赤字,供过帐完毕后调用
 * @param session
 * @param accountId
 * @return {code: int, message: string}
 * code LIMIT_CONTROL_SUCCESS:检查通过
 * code LIMIT_CONTROL_FORBID:赤字字段为禁止,保存时金额 < 0,需要调用方抛出异常通知客户端
 * code LIMIT_CONTROL_WARN:赤字字段为警告,保存时金额 < 0,需要调用方提供警告信息通知客户端
 */
func (o AccountInOutService) CheckCashAccountLimitControl(sessionId int, accountId int) map[string]interface{} {
	qb := QuerySupport{}
	userId, err := strconv.Atoi(fmt.Sprint(global.GetGlobalAttr(sessionId, "userId")))
	if err != nil {
		panic(err)
	}
	session, _ := global.GetConnection(sessionId)
	queryMap := map[string]interface{}{
		"_id":          accountId,
		"A.createUnit": qb.GetCreateUnitByUserId(session, userId),
	}
	collectionName := "CashAccount"
	cashAccountBo, found := qb.FindByMapWithSession(session, collectionName, queryMap)
	if !found {
		queryMapByte, err := json.Marshal(&queryMap)
		if err != nil {
			panic(err)
		}
		panic(BusinessError{Message: "现金账户没找到,查询条件为:" + string(queryMapByte)})
	}
	cashAccount := cashAccountBo["A"].(map[string]interface{})
	limitsControl := fmt.Sprint(cashAccount["limitsControl"])
	commonUtil := CommonUtil{}
	amtOriginalCurrencyBalance := commonUtil.GetFloat64FromString(fmt.Sprint(cashAccount["amtOriginalCurrencyBalance"]))
	if limitsControl == "1" { // 禁止
		if amtOriginalCurrencyBalance < 0 {
			result := map[string]interface{}{
				"code":    LIMIT_CONTROL_FORBID,
				"message": "帐户:" + fmt.Sprint(cashAccount["name"]) + "出现赤字!",
			}
			return result
		}
	} else if limitsControl == "2" { // 警告
		if amtOriginalCurrencyBalance < 0 {
			result := map[string]interface{}{
				"code":    LIMIT_CONTROL_WARN,
				"message": "帐户:" + fmt.Sprint(cashAccount["name"]) + "出现赤字!",
			}
			return result
		}
	}
	return map[string]interface{}{
		"code": LIMIT_CONTROL_SUCCESS,
	}
}
Exemple #19
0
func (c GatheringBillSupport) RAfterNewData(sessionId int, dataSource DataSource, formTemplate FormTemplate, bo *map[string]interface{}) {
	master := (*bo)["A"].(map[string]interface{})
	(*bo)["A"] = master
	modelTemplateFactory := ModelTemplateFactory{}
	billTypeParameterDataSource := modelTemplateFactory.GetDataSource("BillReceiveTypeParameter")
	collectionName := modelTemplateFactory.GetCollectionName(billTypeParameterDataSource)
	session, _ := global.GetConnection(sessionId)
	qb := QuerySupport{}
	userId, err := strconv.Atoi(fmt.Sprint(global.GetGlobalAttr(sessionId, "userId")))
	if err != nil {
		panic(err)
	}
	queryMap := map[string]interface{}{
		"A.billTypeId": 1,
		"A.createUnit": qb.GetCreateUnitByUserId(session, userId),
	}

	billTypeParameter, found := qb.FindByMapWithSession(session, collectionName, queryMap)
	if !found {
		panic(BusinessError{
			Message: "未找到收款单类型参数",
		})
	}
	billTypeParameterMaster := billTypeParameter["A"].(map[string]interface{})
	master["property"] = billTypeParameterMaster["property"]

	// 币别默认值
	currencyTypeQuery := map[string]interface{}{
		"A.code":       "RMB",
		"A.createUnit": qb.GetCreateUnitByUserId(session, userId),
	}

	currencyTypeCollectionName := "CurrencyType"
	result, found := qb.FindByMapWithSession(session, currencyTypeCollectionName, currencyTypeQuery)
	if found {
		master["currencyTypeId"] = result["id"]
	}

	// 单据编号
	c.setBillNo(sessionId, bo)
}
func (o AccountInOutItemInterceptor) GetAccountingPeriod(sessionId int, year int) (map[string]interface{}, bool) {
	session, _ := global.GetConnection(sessionId)
	collectionName := "AccountingPeriod"

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

	queryMap := map[string]interface{}{
		"A.accountingYear": year,
		"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) + "未找到对应会计期")
		return nil, false
	}
	return accountingPeriod, true
}
func (o AccountInOutItemInterceptor) GetMinAccountingPeriod(sessionId int) (map[string]interface{}, bool) {
	userId, err := strconv.Atoi(fmt.Sprint(global.GetGlobalAttr(sessionId, "userId")))
	if err != nil {
		panic(err)
	}

	session, _ := global.GetConnection(sessionId)
	collectionName := "AccountingPeriod"
	interceptorCommon := InterceptorCommon{}
	queryMap := map[string]interface{}{
		"A.createUnit": interceptorCommon.GetCreateUnitByUserId(session, userId),
	}
	pageNo := 1
	pageSize := 1
	orderBy := "A.accountingYear"
	queryResult := interceptorCommon.IndexWithSession(session, collectionName, queryMap, pageNo, pageSize, orderBy)
	items := queryResult["items"].([]interface{})
	if len(items) > 0 {
		return items[0].(map[string]interface{}), true
	}
	return nil, false
}
Exemple #22
0
func (c BbsPostSupport) bbsPostReplyAfterSaveData(sessionId int, dataSource DataSource, bo *map[string]interface{}, diffDateRowLi *[]DiffDataRow) {
	session, db := global.GetConnection(sessionId)
	txnManager := TxnManager{db}
	txnId := global.GetTxnId(sessionId)

	userId, err := strconv.Atoi(fmt.Sprint(global.GetGlobalAttr(sessionId, "userId")))
	if err != nil {
		panic(err)
	}
	// 更新bbsPostId对应的主题帖的 lastReplyBy = self,lastReplyTime = currentTime,
	commonUtil := CommonUtil{}
	dateUtil := DateUtil{}
	master := (*bo)["A"].(map[string]interface{})
	qb := QuerySupport{}
	mainBbsPostQuery := map[string]interface{}{
		"_id": commonUtil.GetIntFromMap(master, "bbsPostId"),
	}
	bbsPostCollectionName := "BbsPost"
	mainBbsPost, found := qb.FindByMapWithSession(session, bbsPostCollectionName, mainBbsPostQuery)
	if !found {
		panic(BusinessError{Message: "主题帖未找到"})
	}
	mainBbsPostMaster := mainBbsPost["A"].(map[string]interface{})
	mainBbsPost["A"] = mainBbsPostMaster
	mainBbsPostMaster["lastReplyBy"] = userId
	mainBbsPostMaster["lastReplyTime"] = dateUtil.GetCurrentYyyyMMddHHmmss()
	if _, updateResult := txnManager.Update(txnId, bbsPostCollectionName, mainBbsPost); !updateResult {
		panic(BusinessError{Message: "主题帖更新失败"})
	}

	for _, item := range *diffDateRowLi {
		isNewOrUpdate := (item.SrcData != nil && item.DestData != nil) || (item.SrcData == nil && item.DestData != nil)
		if isNewOrUpdate {
			// 旧数据反过账,新数据正过账,修改后,更新 bbsPostId,readBy,bbsPostId
			bbsPostId := commonUtil.GetIntFromMap(*item.DestData, "bbsPostId")
			c.addOrUpdateBbsPostRead(sessionId, bbsPostId)
		}
	}
}
func (o ProgramDictionaryManager) GetSysUserProgramDictionary(sessionId int, db *mgo.Database, code string) map[string]interface{} {
	userId, err := strconv.Atoi(fmt.Sprint(global.GetGlobalAttr(sessionId, "userId")))
	if err != nil {
		panic(err)
	}

	collection := "SysUser"
	c := db.C(collection)
	
	session, _ := global.GetConnection(sessionId)
	queryMap := map[string]interface{}{
		"A.createUnit": o.GetCreateUnitByUserId(session, userId),
	}
	
	sysUserResult := []map[string]interface{}{}
	err = c.Find(queryMap).Limit(10).All(&sysUserResult)
	if err != nil {
		panic(err)
	}
	
	result := map[string]interface{}{}
	result["code"] = code
	//items := []map[string]interface{}{}
	items := []interface{}{}
	for idx, item := range sysUserResult {
		items = append(items, map[string]interface{}{
			"code": item["_id"],
			"name": item["nick"],
			"order": idx,
		})
	}
	result["items"] = items
	
	// 排序
	o.sortProgramDictionary(&result)
	return result
}
func (o ProgramDictionaryManager) GetAccountingYearStartProgramDictionary(sessionId int, db *mgo.Database, code string) map[string]interface{} {
	userId, err := strconv.Atoi(fmt.Sprint(global.GetGlobalAttr(sessionId, "userId")))
	if err != nil {
		panic(err)
	}

	collection := "AccountingPeriod"
	c := db.C(collection)
	
	session, _ := global.GetConnection(sessionId)
	queryMap := map[string]interface{}{
		"A.createUnit": o.GetCreateUnitByUserId(session, userId),
	}
	
	itemResult := []map[string]interface{}{}
	err = c.Find(queryMap).All(&itemResult)
	if err != nil {
		panic(err)
	}
	
	result := map[string]interface{}{}
	result["code"] = code
	items := []interface{}{}
	for _, item := range itemResult {
		master := item["A"].(map[string]interface{})
		items = append(items, map[string]interface{}{
			"code": master["accountingYear"],
			"name": master["accountingYear"],
			"order": master["accountingYear"],
		})
	}
	result["items"] = items
	
	// 排序
	o.sortProgramDictionary(&result)
	return result
}
/**
 * 现金月档过帐,
 * 1.月档记录不存在,则给其新增一条
 * 2.正反过帐
 * @param accountInOutParam	参数对象
 */
func (o AccountInOutService) logMonthInOut(sessionId int, accountInOutParam AccountInOutParam) {
	session, db := global.GetConnection(sessionId)
	// 参数中加入 currencyTypeId
	commonUtil := CommonUtil{}
	mathUtil := MathUtil{}
	amtIncrease := accountInOutParam.AmtIncrease
	amtReduce := accountInOutParam.AmtReduce

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

	qb := QuerySupport{}
	query := map[string]interface{}{
		"A.accountId":             accountInOutParam.AccountId,
		"A.currencyTypeId":        accountInOutParam.CurrencyTypeId,
		"A.accountType":           accountInOutParam.AccountType,
		"A.accountingPeriodYear":  accountInOutParam.AccountingPeriodYear,
		"A.accountingPeriodMonth": accountInOutParam.AccountingPeriodMonth,
		"A.createUnit":            qb.GetCreateUnitByUserId(session, userId),
	}

	dataSourceModelId := "AccountInOut"
	modelTemplateFactory := ModelTemplateFactory{}
	dataSource := modelTemplateFactory.GetDataSource(dataSourceModelId)
	collectionName := modelTemplateFactory.GetCollectionName(dataSource)

	accountInOut, found := qb.FindByMapWithSession(session, collectionName, query)
	if !found {
		accountInOut = o.addFinAccountInOutForCash(sessionId, accountInOutParam)
	} else { // 设置modifyBy等字段
		masterData := accountInOut["A"].(map[string]interface{})
		masterData["modifyBy"] = accountInOutParam.ModifyBy
		masterData["modifyUnit"] = accountInOutParam.ModifyUnit
		masterData["modifyTime"] = accountInOutParam.ModifyTime
		accountInOut["A"] = masterData
	}

	masterData := accountInOut["A"].(map[string]interface{})
	accountInOut["A"] = masterData
	amtIncreaseInDb := fmt.Sprint(masterData["amtIncrease"])
	amtReduceInDb := fmt.Sprint(masterData["amtReduce"])

	increaseCountInDb := commonUtil.GetIntFromString(fmt.Sprint(masterData["increaseCount"]))
	reduceCountInDb := commonUtil.GetIntFromString(fmt.Sprint(masterData["reduceCount"]))

	if accountInOutParam.DiffDataType == ADD || accountInOutParam.DiffDataType == AFTER_UPDATE {
		amtIncreaseInDb = mathUtil.Add(amtIncreaseInDb, amtIncrease)
		amtReduceInDb = mathUtil.Add(amtReduceInDb, amtReduce)

		if commonUtil.GetFloat64FromString(amtIncrease) > 0 {
			increaseCountInDb += 1
		}
		if commonUtil.GetFloat64FromString(amtReduce) > 0 {
			reduceCountInDb += 1
		}
	} else {
		amtIncreaseInDb = mathUtil.Sub(amtIncreaseInDb, amtIncrease)
		amtReduceInDb = mathUtil.Sub(amtReduceInDb, amtReduce)

		if commonUtil.GetFloat64FromString(amtIncrease) > 0 {
			increaseCountInDb -= 1
		}
		if commonUtil.GetFloat64FromString(amtReduce) > 0 {
			reduceCountInDb -= 1
		}
	}
	masterData["amtIncrease"] = commonUtil.GetFloatFormat(amtIncreaseInDb)
	masterData["amtReduce"] = commonUtil.GetFloatFormat(amtReduceInDb)
	masterData["increaseCount"] = increaseCountInDb
	masterData["reduceCount"] = reduceCountInDb

	txnManager := TxnManager{db}
	txnId := global.GetTxnId(sessionId)
	_, found = txnManager.Update(txnId, collectionName, accountInOut)
	if !found {
		panic(BusinessError{Message: "月档更新失败"})
	}
}
/**
 * 银行帐户过帐,
 * @param sessionId
 * @param accountInOutParam 过帐参数对象
 */
func (o AccountInOutService) LogBankAccountInOut(sessionId int, accountInOutParam AccountInOutParam) {
	// 从银行账户初始化那里面拷贝一份出来,
	session, db := global.GetConnection(sessionId)

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

	collectionName := "BankAccount"
	querySupport := QuerySupport{}
	queryMap := map[string]interface{}{
		"_id":          accountInOutParam.AccountId,
		"A.createUnit": querySupport.GetCreateUnitByUserId(session, userId),
	}
	bankAccountBo, found := querySupport.FindByMapWithSession(session, collectionName, queryMap)
	if !found {
		queryMapByte, err := json.Marshal(&queryMap)
		if err != nil {
			panic(err)
		}
		panic(BusinessError{Message: "银行账户没找到,查询条件为:" + string(queryMapByte)})
	}
	currencyTypeId := accountInOutParam.CurrencyTypeId
	bDetailDataLi := bankAccountBo["B"].([]interface{})
	mathUtil := MathUtil{}
	commonUtil := CommonUtil{}
	isFound := false
	for i, item := range bDetailDataLi {
		bankAccountCurrencyType := item.(map[string]interface{})
		if fmt.Sprint(bankAccountCurrencyType["currencyTypeId"]) == fmt.Sprint(currencyTypeId) {
			amtOriginalCurrencyBalance := fmt.Sprint(bankAccountCurrencyType["amtOriginalCurrencyBalance"])
			amtIncrease := accountInOutParam.AmtIncrease
			amtReduce := accountInOutParam.AmtReduce

			if accountInOutParam.DiffDataType == ADD || accountInOutParam.DiffDataType == AFTER_UPDATE { // 正过账
				amtOriginalCurrencyBalance = mathUtil.Add(amtOriginalCurrencyBalance, amtIncrease)
				amtOriginalCurrencyBalance = mathUtil.Sub(amtOriginalCurrencyBalance, amtReduce)
			} else if accountInOutParam.DiffDataType == BEFORE_UPDATE || accountInOutParam.DiffDataType == DELETE { // 反过账
				amtOriginalCurrencyBalance = mathUtil.Sub(amtOriginalCurrencyBalance, amtIncrease)
				amtOriginalCurrencyBalance = mathUtil.Add(amtOriginalCurrencyBalance, amtReduce)
			}
			bankAccountCurrencyType["amtOriginalCurrencyBalance"] = commonUtil.GetFloatFormat(amtOriginalCurrencyBalance)
			bDetailDataLi[i] = bankAccountCurrencyType
			isFound = true
			break
		}
	}
	if !isFound {
		bankAccountMaster := bankAccountBo["A"].(map[string]interface{})
		panic(BusinessError{Message: "过账银行账户:" + fmt.Sprint(bankAccountMaster["name"]) + "未找到对应币别"})
	}

	bankAccountBo["B"] = bDetailDataLi
	txnManager := TxnManager{db}
	txnId := global.GetTxnId(sessionId)
	_, found = txnManager.Update(txnId, collectionName, bankAccountBo)
	if !found {
		panic(BusinessError{Message: "银行账户更新失败"})
	}
}