/// <summary> /// 连接 /// </summary> /// <param name="loggingSession"></param> /// <param name="condition"></param> /// <returns></returns> protected string GenInsertUnitTemporaryTableSQL(cPos.Model.LoggingSessionInfo loggingSession, cPos.Model.Unit.UnitQueryCondition condition) { StringBuilder sb = new StringBuilder(); sb.AppendLine("declare @tmp_unit table(unit_id varchar(32));"); sb.AppendLine("insert into @tmp_unit"); //表 //sb.AppendLine("select a2.unit_id from t_unit_level a1, t_unit_level a2 "); //视图 sb.AppendLine("select a2.unit_id from vw_unit_level a1, vw_unit_level a2 "); if (condition.SuperUnitIDs.Count == 0) { sb.Append(",(select distinct unit_id from t_user_role where "); sb.Append(string.Format(" user_id='{0}' ", loggingSession.CurrentUser.User_Id)); sb.AppendLine(string.Format(" and role_id='{0}') a3 ", this.GetBasicRoleId(loggingSession.CurrentUserRole.RoleId))); sb.AppendLine("where a3.unit_id=a1.unit_id "); } else { sb.Append(string.Format("where (a1.unit_id='{0}' ", condition.SuperUnitIDs[0])); for (int i = 1; i < condition.SuperUnitIDs.Count; i++) { sb.Append(string.Format("or a1.unit_id='{0}' ", condition.SuperUnitIDs[i])); } sb.AppendLine(")"); } //表 //sb.AppendLine(" and a2.path_unit_no like a1.path_unit_no + '%' "); //视图 sb.AppendLine(" and a2.path_unit_id like a1.path_unit_id + '%' "); sb.AppendLine("group by a2.unit_id; "); return(sb.ToString()); }
/// <summary> /// 根据单位的查询条件,将符合条件的单位的ID插入到临时表中 /// </summary> /// <param name="sqlMap">数据库连接</param> /// <param name="loggingSession">当前登录的信息</param> /// <param name="condition">单位的查询条件</param> /// <returns></returns> protected void InsertUnitTemporaryTable(ISqlMapper sqlMap, cPos.Model.LoggingSessionInfo loggingSession, cPos.Model.Unit.UnitQueryCondition condition) { sqlMap.QueryForObject("Pos.Operate.InsertUnitTemporaryTable", this.GenInsertUnitTemporaryTableSQL(loggingSession, condition)); }