Exemplo n.º 1
0
func (o StepService) Run(sysUser map[string]interface{}) {
	sysUserManster := sysUser["A"].(map[string]interface{})
	sysUnitId := CommonUtil{}.GetIntFromMap(sysUserManster, "createUnit")
	// 加锁
	lockService := LockService{}
	unitLock := lockService.GetUnitLock(fmt.Sprint(sysUnitId))
	(*unitLock).Lock()
	defer (*unitLock).Unlock()

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

	txnId := global.GetTxnId(sessionId)
	_, db := global.GetConnection(sessionId)
	txnManager := TxnManager{db}
	stepLi := []map[string]interface{}{}
	err := db.C("SysStep").Find(map[string]interface{}{
		"A.sysUnitId": sysUnitId,
	}).Sort("A.type").All(&stepLi)
	if err != nil {
		panic(err)
	}

	for _, item := range stepLi {
		master := item["A"].(map[string]interface{})
		item["A"] = master

		status := fmt.Sprint(master["status"])
		if status == "1" { // 未开始
			stepType := fmt.Sprint(master["type"])
			if stepType == "3" { //初始化供应商类别
				o.InitProviderType(sessionId, sysUser)
			} else if stepType == "5" { //初始化币别
				o.InitCurrencyType(sessionId, sysUser)
			} else if stepType == "6" { //初始化银行资料
				o.InitBank(sessionId, sysUser)
			} else if stepType == "7" { //初始化计量单位
				o.InitMeasureUnit(sessionId, sysUser)
			} else if stepType == "9" { //初始化客户类别
				o.InitCustomerType(sessionId, sysUser)
			} else if stepType == "12" { //初始化税率类别
				o.InitTaxType(sessionId, sysUser)
			} else if stepType == "14" { //初始化收入费用类别
				o.InitIncomeType(sessionId, sysUser)
			} else if stepType == "15" { //初始化收入费用项目
				o.InitIncomeItem(sessionId, sysUser)
			} else if stepType == "16" { //初始化会计期
				o.InitAccountingPeriod(sessionId, sysUser)
			} else if stepType == "18" { //初始化收款单类型参数
				o.InitBillReceiveTypeParameter(sessionId, sysUser)
			} else if stepType == "19" { //初始化付款单类型参数
				o.InitBillPaymentTypeParameter(sessionId, sysUser)
			} else if stepType == "20" { //初始化系统参数
				o.InitSystemParameter(sessionId, sysUser)
			}
		}
		master["status"] = 2
		_, updateResult := txnManager.Update(txnId, "SysStep", item)
		if !updateResult {
			panic(BusinessError{Message: "更新SysStep" + fmt.Sprint(master["name"]) + "失败"})
		}
	}

	global.CommitTxn(sessionId)
}
Exemplo n.º 2
0
/**
http://uhz001889.chinaw3.com/?myEnt=approval&code=BiWbZfjYoCIp4oRzo7rgRpUv243721&state=
*/
func (c App) Index() revel.Result {
	if c.Params.Query.Get("code") != "" {
		url := c.Request.URL.Path + "?" + c.Request.URL.RawQuery
		sessionId := global.GetSessionId()
		defer global.CloseSession(sessionId)
		defer global.RollbackTxn(sessionId)

		resStruct, userId, isStep := LoginService{}.DealLogin(sessionId, url)
		global.CommitTxn(sessionId)
		c.Session["userId"] = fmt.Sprint(userId)

		loginService := LoginService{}
		if isStep {
			qb := QuerySupport{}
			session, db := global.GetConnection(sessionId)
			user := qb.FindByMapWithSessionExact(session, "SysUser", map[string]interface{}{
				"id": userId,
			})
			userMain := user["A"].(map[string]interface{})
			appKey := fmt.Sprint(resStruct["app_key"])
			stepTypeLi := loginService.GetStepTypeLi(appKey)
			stepLi := []interface{}{}
			err := db.C("SysStep").Find(map[string]interface{}{
				"A.sysUnitId": userMain["createUnit"],
				"A.type": map[string]interface{}{
					"$in": stepTypeLi,
				},
			}).Sort("A.type").All(&stepLi)
			if err != nil {
				panic(err)
			}
			c.RenderArgs["result"] = map[string]interface{}{
				"stepLi": stepLi,
			}
			//c.Response.ContentType = "text/html; charset=utf-8"
			return c.RenderTemplate("Step/Step.html")
		} else {
			return c.Redirect("/")
		}
	}

	if c.Session["userId"] == "" {
		if strings.Index(c.Request.Header.Get("HTTP_REFERER"), "taobao") > -1 {
			taobaoPath := revel.Config.StringDefault("TAOBAO_PATH", "")
			return c.Redirect(taobaoPath)
		} else {
			c.Response.ContentType = "text/plain; charset=utf-8"
			return c.RenderText("会话过期,请您从淘宝重新登录应用!")
		}
	}
	// 取得菜单等数据,
	userId, err := strconv.Atoi(c.Session["userId"])
	if err != nil {
		panic(err)
	}
	sessionId := global.GetSessionId()
	defer global.CloseSession(sessionId)
	qb := QuerySupport{}
	session, _ := global.GetConnection(sessionId)
	user := qb.FindByMapWithSessionExact(session, "SysUser", map[string]interface{}{
		"id": userId,
	})

	// 获取数据,
	result := map[string]interface{}{
		"user":            user,
		"unit":            c.getSysUnit(sessionId, user),
		"menuLi":          c.getMenuLi(sessionId),
		"gatheringBillLi": c.getGatheringBillLi(sessionId, user),
		"payBillLi":       c.getPayBillLi(sessionId, user),
	}
	return c.Render(result)
}