123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using XF.Domain.Exceptions;
- namespace XF.Domain.Extensions
- {
- public static class OrgExtensions
- {
- public static List<string> GetHigherOrgCodes(this string orgCode, bool withSelf = false)
- {
- if (string.IsNullOrEmpty(orgCode))
- return new();
- var length = orgCode.Length;
- if (length % 3 != 0)
- throw new UserFriendlyException($"非法OrgCode, code: {orgCode}");
- var rsp = new List<string>();
- if (withSelf)
- rsp.Add(orgCode);
- var code = orgCode.Substring(0, length - 3);
- while (code.Length > 0)
- {
- rsp.Add(code);
- code = code.Substring(0, code.Length - 3);
- }
- return rsp;
- }
- /// <summary>
- /// 部门等级转为中文(支持1~10,如有需要自行扩展)
- /// </summary>
- /// <param name="orgLevel"></param>
- /// <returns></returns>
- public static string ToChinese(this int orgLevel) =>
- orgLevel switch
- {
- 1 => "一",
- 2 => "二",
- 3 => "三",
- 4 => "四",
- 5 => "五",
- 6 => "六",
- 7 => "七",
- 8 => "八",
- 9 => "九",
- 10 => "十",
- _ => throw new ArgumentOutOfRangeException(nameof(orgLevel), orgLevel, "该部门等级暂不支持中文表示")
- };
- }
- }
|