12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304 |
-
- using Microsoft.AspNetCore.SignalR;
- using Microsoft.International.Converters.PinYinConverter;
- using NPOI.HSSF.Util;
- using OASystem.API.OAMethodLib.Hub.HubClients;
- using OASystem.API.OAMethodLib.Hub.Hubs;
- using OASystem.API.OAMethodLib.JuHeAPI;
- using OASystem.API.OAMethodLib.SignalR.Hubs;
- using OASystem.Domain.Entities.Customer;
- using OASystem.Domain.Entities.District;
- using OASystem.Domain.Entities.Financial;
- using OASystem.Domain.Entities.Groups;
- using OASystem.Domain.ViewModels.Financial;
- using OASystem.Domain.ViewModels.Groups;
- using OASystem.Domain.ViewModels.JuHeExchangeRate;
- using OASystem.Infrastructure.Repositories.CRM;
- using OASystem.Infrastructure.Repositories.Groups;
- using System.IdentityModel.Tokens.Jwt;
- using System.IO.Compression;
- using System.Security.Claims;
- using System.Web;
- namespace OASystem.API.OAMethodLib
- {
- public static class GeneralMethod
- {
- //团组信息
- private readonly static DelegationInfoRepository _dirRep = AutofacIocManager.Instance.GetService<DelegationInfoRepository>();
- private readonly static TeamRateRepository _teamRateRep = AutofacIocManager.Instance.GetService<TeamRateRepository>();
- private readonly static IJuHeApiService _juHeApi = AutofacIocManager.Instance.GetService<IJuHeApiService>();
- private readonly static SetDataRepository _setDataRep = AutofacIocManager.Instance.GetService<SetDataRepository>();
- private readonly static TableOperationRecordRepository _tableOperationRecordRep = AutofacIocManager.Instance.GetService<TableOperationRecordRepository>();
- private readonly static MessageRepository _messageRep = AutofacIocManager.Instance.GetService<MessageRepository>();
- private readonly static IHubContext<ChatHub, IChatClient> _hubContext = AutofacIocManager.Instance.GetService<IHubContext<ChatHub, IChatClient>>();
- #region 员工注册默认添加基础页面
- /// <summary>
- /// 默认职位权限 View
- /// </summary>
- public static bool DefaultPostAuth(int depId,int postId, int userId,int createUserId)
- {
- if (depId < 1) return false;
- if (postId < 1) return false;
- if (userId < 1) return false;
- if (userId < 1) return false;
- List<DefaultPostPageAuthView> _defaultData = AppSettingsHelper.Get<DefaultPostPageAuthView>("DefaultPostPageData");
- if (_defaultData.Count < 1) return false;
- List<int> pageData = new List<int>();
- //添加公司公共页面
- pageData.AddRange(_defaultData.Find(it => it.DepId == -1)?.PostPageAuths[0].PageIds ?? new List<int>());
- //添加部门页面
- var depPublicPageData = _defaultData.Find(it => it.DepId == depId);
- if (depPublicPageData != null) //特殊部门
- {
- //公共页面
- pageData.AddRange(depPublicPageData.PostPageAuths.Find(it => it.PostId == -1)?.PageIds ?? new List<int>());
- //岗位页面
- pageData.AddRange(depPublicPageData.PostPageAuths.Find(it => it.PostId == postId)?.PageIds ?? new List<int>());
- }
- else //通用部门
- {
- pageData.AddRange(_defaultData.Find(it => it.DepId == 0)?.PostPageAuths[0].PageIds ?? new List<int>());
- }
- if (pageData.Count > 0)
- {
- //页面操作权限数据(添加修改等...)
- var pageFunctionData = _dirRep._sqlSugar.Queryable<Sys_SystemMenuAndFunction>().Where(it => pageData.Contains(it.SmId) && it.IsDel == 0 ).ToList();
- var defaultPageData = pageFunctionData.Select(it => new Sys_UserAuthority() {
- UId = userId,
- SmId = it.SmId,
- FId = it.FId,
- CreateUserId = createUserId, //管理员
- CreateTime = DateTime.Now,
- IsDel = 0,
- IsTemp = 1
- }).ToList();
- if (defaultPageData.Count > 0)
- {
- //添加页面操作权限
- var s = _dirRep._sqlSugar.Fastest<Sys_UserAuthority>().PageSize(100000).BulkCopy(defaultPageData);
- if (s > 0)
- {
- return true;
- }
- }
- }
- return false;
- }
- #endregion
- #region 消息
- /// <summary>
- /// 消息 发布And 通知
- /// </summary>
- /// <param name="msgTypeEnum">
- /// 消息类型
- /// 1 公告通知
- /// 2 团组流程管控通知
- /// 3 团组业务操作通知
- /// 4 团组费用审核消息
- /// 5 团组签证进度通知
- /// 6 团组任务进度通知
- /// </param>
- /// <param name="title">消息标题</param>
- /// <param name="content">消息内容</param>
- /// <param name="userIds"></param>
- /// <param name="diId">团组id</param>
- /// <param name="param">团组id</param>
- /// <returns></returns>
- public static async Task<bool> MessageIssueAndNotification(MessageTypeEnum msgTypeEnum, string title, string content, List<int> userIds, int diId = 0, string param = "")
- {
- MessageDto messageDto = new()
- {
- Type = msgTypeEnum,
- IssuerId = 4,//管理员
- DiId = diId,
- Title = title,
- Content = content,
- ReleaseTime = DateTime.Now,
- UIdList = userIds,
- Param = param
- };
- var status = await _messageRep.AddMsg(messageDto);//添加消息
- if (status)
- {
- //给在线在用户发送消息
- List<string> connIds = UserStore.OnlineUser.Where(it => userIds.Contains(it.UserId)).Select(it => it.ConnectionId).ToList();
- string notificationTypeStr1 = GetMsgNotificationType(msgTypeEnum);
- string notificationTypeStr = JsonConvert.SerializeObject(
- new
- {
- UserIds = userIds,
- Msg = $"您有一条{notificationTypeStr1}相关的消息!"
- }
- );
- await _hubContext.Clients.Clients(connIds).ReceiveMessage($"您有一条{notificationTypeStr1}相关的消息!");
- return true;
- }
- return false;
- }
- /// <summary>
- /// 根据消息类型 获取 消息通知类型
- /// </summary>
- /// <returns></returns>
- public static string GetMsgNotificationType(MessageTypeEnum msgTypeEnum)
- {
- int notificationType = 0;
- string notificationStr = "";
- List<NotificationTypeView> notificationTypeViews = AppSettingsHelper.Get<NotificationTypeView>("MessageNotificationType");
- notificationType = notificationTypeViews.Where(it => it.MsgTypeIds.Contains((int)msgTypeEnum)).Select(it => it.TypeId).FirstOrDefault();
- if (notificationType == 1021) notificationStr = "操作";
- else if (notificationType == 1020) notificationStr = "任务";
- return notificationStr;
- }
- #endregion
- #region md5 加密
- /// <summary>
- /// MD5加密,和动网上的16/32位MD5加密结果相同,
- /// 使用的UTF8编码
- /// </summary>
- /// <param name="source">待加密字串</param>
- /// <param name="length">16或32值之一,其它则采用.net默认MD5加密算法</param>
- /// <returns>加密后的字串</returns>
- public static string Encrypt(string source, int length = 32)
- {
- if (string.IsNullOrWhiteSpace(source))
- return string.Empty;
- HashAlgorithm hashAlgorithm = CryptoConfig.CreateFromName("MD5") as HashAlgorithm;
- byte[] bytes = Encoding.UTF8.GetBytes(source);
- byte[] hashValue = hashAlgorithm.ComputeHash(bytes);
- StringBuilder sb = new StringBuilder();
- switch (length)
- {
- case 16://16位密文是32位密文的9到24位字符
- for (int i = 4; i < 12; i++)
- {
- sb.Append(hashValue[i].ToString("x2"));
- }
- break;
- case 32:
- for (int i = 0; i < 16; i++)
- {
- sb.Append(hashValue[i].ToString("x2"));
- }
- break;
- default:
- for (int i = 0; i < hashValue.Length; i++)
- {
- sb.Append(hashValue[i].ToString("x2"));
- }
- break;
- }
- return sb.ToString();
- }
- #endregion
- #region jwt
- /// <summary>
- /// 获取token
- /// </summary>
- /// <param name="_config"></param>
- /// <param name="Number"></param>
- /// <param name="exp"></param>
- /// <returns></returns>
- public static async Task<string> GetToken(IConfiguration _config, string Number, int uId, string uName, DateTime exp)
- {
- string userId = Guid.NewGuid().ToString().Replace("-", "");
- var claims = new[] {
- new Claim(ClaimTypes.NameIdentifier, uName),
- new Claim(ClaimTypes.NameIdentifier, uId.ToString()),
- new Claim(ClaimTypes.NameIdentifier, userId),
- new Claim("Number",Number)
- };
- var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["JwtSecurityKey"]));
- var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
- var token = new JwtSecurityToken(
- issuer: "OASystem.com",
- audience: "OASystem.com",
- claims: claims,
- expires: exp,
- signingCredentials: creds);
- var indentity = new ClaimsIdentity(claims, "formlogin");
- var principal = new ClaimsPrincipal(indentity);
- // await _httpContext.SignInAsync (CookieAuthenticationDefaults.AuthenticationScheme, principal);
- return new JwtSecurityTokenHandler().WriteToken(token);
- }
- #endregion
- #region 数据类型转换
- /// <summary>
- /// object 转 Int
- /// </summary>
- /// <param name="obj"></param>
- /// <returns></returns>
- public static int GetInt(this object obj)
- {
- if (obj == null)
- return 0;
- int _number = 0;
- bool reslut = Int32.TryParse(obj.ToString(), out _number);
- return _number;
- }
- private static DateTime dateStart = new DateTime(1970, 1, 1, 8, 0, 0);
- private static long longTime = 621355968000000000;
- private static int samllTime = 10000000;
- /// <summary>
- /// 时间戳 转 datetime
- /// </summary>
- /// <param name="timeStamp"></param>
- /// <returns></returns>
- public static DateTime GetTimeSpmpToDate(this object timeStamp)
- {
- if (timeStamp == null) return dateStart;
- DateTime dateTime = new DateTime(longTime + Convert.ToInt64(timeStamp) * samllTime, DateTimeKind.Utc).ToLocalTime();
- return dateTime;
- }
- #endregion
- #region 用户页面操作功能 权限
- /// <summary>
- /// 用户页面操作功能(可使用)
- /// </summary>
- /// <param name="userId">用户Id</param>
- /// <param name="PageId">页面Id</param>
- /// <returns></returns>
- public static async Task<PageFunAuthViewBase> PostUserPageFuncDatas(int userId, int PageId)
- {
- PageFunAuthViewBase pageFunAuth = new PageFunAuthViewBase();
- List<UserPageFuncView> userPageFuncDatas = new List<UserPageFuncView>();
- string sql = string.Format(@"Select ua.UId As UserId, u.CnName As UserName, pa.ModuleId,pa.ModuleName,pa.PageId,pa.PageName,pa.PageIsEnable,
- pa.PagePhoneIsEnable,pa.FuncId,pa.FuncName,pa.FuncIsEnable
- From Sys_UserAuthority ua
- Left Join Sys_Users u On ua.UId = u.Id
- Left Join (
- Select sd.Id As ModuleId,sd.Name As ModuleName, smp.Id As PageId,smp.Name As PageName,smp.IsEnable As PageIsEnable,
- smp.phoneIsEnable As PagePhoneIsEnable,pfp.Id As FuncId,pfp.FunctionName As FuncName,pfp.IsEnable As FuncIsEnable
- From Sys_SystemMenuAndFunction smaf
- Left Join Sys_SystemMenuPermission smp On smaf.SmId = smp.Id
- Left Join Sys_SetData sd On sd.STid = 5 And smp.Mid = sd.Id
- Left Join Sys_PageFunctionPermission pfp On smaf.FId = pfp.Id
- Where smaf.IsDel = 0 And smp.IsDel = 0 And pfp.IsDel = 0 And sd.IsDel = 0 And smp.IsEnable = 1
- ) As pa On ua.SmId = pa.PageId And ua.FId = pa.FuncId
- Where ua.IsDel = 0 And ua.UId = {0} And pa.PageId = {1}
- Order By ModuleId,PageId,FuncId Asc", userId, PageId);
- userPageFuncDatas = await _dirRep._sqlSugar.SqlQueryable<UserPageFuncView>(sql).ToListAsync();
- if (userPageFuncDatas.Count <= 0)
- {
- return pageFunAuth;
- }
- UserPageFuncView userPageFunc = new UserPageFuncView();
- //查询 1
- userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 1).FirstOrDefault();
- if (userPageFunc != null) pageFunAuth.CheckAuth = 1;
- //删除 2
- userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 2).FirstOrDefault();
- if (userPageFunc != null) pageFunAuth.DeleteAuth = 1;
- //编辑 3
- userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 3).FirstOrDefault();
- if (userPageFunc != null) pageFunAuth.EditAuth = 1;
- //下载 4
- userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 4).FirstOrDefault();
- if (userPageFunc != null) pageFunAuth.FilesDownloadAuth = 1;
- //上传 5
- userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 5).FirstOrDefault();
- if (userPageFunc != null) pageFunAuth.FilesUploadAuth = 1;
- //添加 11
- userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 11).FirstOrDefault();
- if (userPageFunc != null) pageFunAuth.AddAuth = 1;
- //审核 12
- userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 12).FirstOrDefault();
- if (userPageFunc != null) pageFunAuth.AuditAuth = 1;
- return pageFunAuth;
- }
- #endregion
- #region 业务模块 团组权限
- /// <summary>
- /// 业务模块 团组操作权限
- /// 验证 并返回可操作的团
- /// </summary>
- /// <param name="diId">团组Id</param>
- /// <param name="userId">用户Id</param>
- /// <param name="CTable">业务模块Id</param>
- /// <returns></returns>
- public static async Task<Result> PostGroupOperationAuth(int diId, int userId, int CTable)
- {
- Result _result = new Result { Code = -1, Msg = "No Operation Authorty!" };
- if (CTable < 1)
- {
- _result.Msg = "请填写正确的用户Id!";
- return _result;
- }
- var data = _dirRep._sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(it => it.DIId == diId && it.UId == userId && it.CTId == CTable && it.IsDel == 0).First();
- if (data == null)
- {
- _result.Msg = "你没有本团下的该业务模块操作,请联系主管分配操作权限!";
- }
- else
- {
- _result.Code = 0;
- }
- return _result;
- }
- /// <summary>
- /// 业务模块 团组操作权限
- /// 返回可操作的团
- /// </summary>
- /// <param name="diId">团组Id</param>
- /// <param name="userId">用户Id</param>
- /// <param name="CTable">业务模块Id</param>
- /// <returns></returns>
- public static async Task<List<Web_ShareGroupInfoView>> PostOperationAuthReturnGroupInfosAsync(int userId, int CTable)
- {
- List<Web_ShareGroupInfoView> _ShareGroupInfoViews = new List<Web_ShareGroupInfoView>();
- var taskDatas = _dirRep._sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(it => it.UId == userId && it.CTId == CTable && it.IsDel == 0).ToList();
- if (taskDatas.Count < 1) return _ShareGroupInfoViews;
- string diIds = string.Join(",", taskDatas.Select(it => it.DIId).ToList());
- string sql = string.Format(@"Select Id,TeamName,TourCode,ClientName,VisitCountry,VisitStartDate,VisitEndDate,VisitDays,VisitPNumber
- From Grp_DelegationInfo Where Id In({0}) And IsDel = 0 Order By Id Desc", diIds);
- _ShareGroupInfoViews = await _dirRep._sqlSugar.SqlQueryable<Web_ShareGroupInfoView>(sql).ToListAsync();
-
- return _ShareGroupInfoViews;
- }
- #endregion
- #region 团组相关
- #region 建团按国家默认添加汇率 / 默认权限分配
- /// <summary>
- /// 团组汇率
- /// 建团时 添加基础汇率 CNY
- /// 按国家 添加 默认币种
- /// </summary>
- /// <param name="userId"></param>
- /// <param name="diId"></param>
- /// <returns></returns>
- public static async Task<Result> PostGroupRateAddInit(int userId, int diId)
- {
- Result result = new() { Code = -2 };
- if (userId < 1)
- {
- result.Msg = string.Format(@"请传入正确的userId");
- return result;
- }
- if (diId < 1)
- {
- result.Msg = string.Format(@"请传入正确的DiId");
- return result;
- }
- //美元(USD):1.0000|欧元(EUR):1.0000|墨西哥比索(MXN):1.0000
- string rateInit = string.Format(@"人名币(CNY):1.0000");
- //var gropInfo = _dirRep._sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && it.Id == diId).First();
- //if (gropInfo == null)
- //{
- // result.Msg = $@"未查询到团组信息!";
- // return result;
- //}
- var juheRateData = await _juHeApi.GetExchangeRateAsync();
- if (juheRateData.Error_code != 0)
- {
- result.Msg = juheRateData.Reason;
- return result;
- }
- List<ExchangeRateModel> exchangeRateModels = (List<ExchangeRateModel>)juheRateData.Result;
- if (exchangeRateModels.Count <= 0)
- {
- result.Msg = $@"未查询到聚合接口汇率信息!";
- return result;
- }
- if (exchangeRateModels.Count > 0)
- {
- var codes = _dirRep._sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 66).ToList();
- for (int i = 0; i < exchangeRateModels.Count; i++)
- {
- string currencyName = exchangeRateModels[i].Name;
- string code = "";
- var currencyData = codes.Where(it => it.Remark == currencyName).FirstOrDefault();
- if (currencyData != null)
- {
- code = currencyData.Name;
- decimal currRate = 0.00M;
- string MSellPri = exchangeRateModels[i].MSellPri;
- if (!string.IsNullOrEmpty(MSellPri))
- {
- currRate = Convert.ToDecimal(MSellPri) / 100M;
- }
-
- rateInit += $@"|{currencyName}({code}):{currRate.ToString("#0.0000")}";
- }
- }
- }
- var cTableIds = _dirRep._sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 16).ToList();
- if (cTableIds.Count < 1)
- {
- result.Msg = $@"未查询到操作模块信息!";
- return result;
- }
- List<Grp_TeamRate> grp_TeamRates = new List<Grp_TeamRate>();
- foreach (var item in cTableIds)
- {
- grp_TeamRates.Add(
- new Grp_TeamRate() { DiId = diId, CTable = item.Id, Remark = rateInit, CreateUserId = userId }
- );
- }
- if (grp_TeamRates.Count > 0)
- {
- var addId = _teamRateRep._sqlSugar.Insertable(grp_TeamRates).ExecuteCommand();
- if (addId < 1)
- {
- result.Msg = string.Format(@"添加失败!");
- return result;
- }
- }
- result.Code = 0;
- result.Msg = string.Format(@"操作成功!");
- return result;
- }
- /// <summary>
- /// 团组汇率
- /// 建团时 默认按照岗位分配权限
- /// </summary>
- /// <param name="userId"></param>
- /// <param name="diId"></param>
- /// <param name="companyId"></param>
- /// <returns></returns>
- public static async Task<Result> PostGroupAuthAddInit(int userId, int diId, int companyId = 2)
- {
- Result result = new() { Code = -2 };
- if (userId < 0)
- {
- result.Msg = string.Format(@"请传入正确的userId");
- return result;
- }
- if (companyId < 0)
- {
- result.Msg = string.Format(@"请传入正确的companyId");
- return result;
- }
- if (diId < 0)
- {
- result.Msg = string.Format(@"请传入正确的DiId");
- return result;
- }
- var userDatas = await _teamRateRep._sqlSugar
- .Queryable<Sys_Users>()
- .LeftJoin<Sys_Department>((su,sd) => su.DepId == sd.Id && sd.IsDel == 0)
- .LeftJoin<Sys_JobPost>((su,sd,sjp) => su.JobPostId == sjp.Id && sjp.IsDel == 0)
- .Where(su => su.IsDel == 0)
- .Select((su,sd,sjp) => new {
- su.DepId,
- sd.DepName,
- su.JobPostId,
- sjp.JobName,
- su.Id,
- su.CnName
- })
- .ToListAsync();
- /*
- * 76 酒店预订 --> 国交部门 酒店 岗位
- * 77 行程 --> 国交部门 经理,主管 岗位
- * 79 车/导游地接 --> 国交部门 OP 岗位
- * 80 签证 --> 国交部门 签证 岗位
- * 81 邀请/公务活动 --> 国交部门 商邀 岗位
- * 82 团组客户保险 --> 国交部 经理,主管 岗位
- * 85 机票预订 --> 国交部门 机票 岗位
- * 98 其他款项 --> 总经办部门 总经理 岗位/国交部门(ALL) 岗位/财务部门(ALL) 岗位/策划部门(ALL) 岗位/人事部门 采购 岗位
- * 1015 超支费用 --> 财务部门(ALL)岗位
- */
- List<Grp_GroupsTaskAssignment> _GroupsTaskAssignments = new List<Grp_GroupsTaskAssignment>();
- // 76 酒店预订 --> 国交部门(7) 酒店(25) 岗位
- _GroupsTaskAssignments.AddRange(
- userDatas
- .Where(it => it.DepId == 7 && it.JobPostId == 25)
- .Select(it => new Grp_GroupsTaskAssignment()
- {
- DIId = diId,
- CTId = 76,
- UId = it.Id,
- CreateUserId = userId
- }).ToList()
- );
- // 77 行程 --> 国交部门(7) 经理(32),主管(22) 岗位
- _GroupsTaskAssignments.AddRange(
- userDatas
- .Where(it => it.DepId == 7 && (it.JobPostId == 22 || it.JobPostId == 32))
- .Select(it => new Grp_GroupsTaskAssignment()
- {
- DIId = diId,
- CTId = 77,
- UId = it.Id,
- CreateUserId = userId
- }).ToList()
- );
- //79 车/导游地接 --> 国交部门(7) OP(28) 岗位
- _GroupsTaskAssignments.AddRange(
- userDatas.Where(it => it.DepId == 7 && it.JobPostId == 28)
- .Select(it => new Grp_GroupsTaskAssignment()
- {
- DIId = diId,
- CTId = 79,
- UId = it.Id,
- CreateUserId = userId
- }).ToList()
- );
- //81 邀请/公务活动 --> 国交部门(7) 商邀(27) 岗位
- _GroupsTaskAssignments.AddRange(
- userDatas
- .Where(it => it.DepId == 7 && it.JobPostId == 27)
- .Select(it => new Grp_GroupsTaskAssignment()
- {
- DIId = diId,
- CTId = 81,
- UId = it.Id,
- CreateUserId = userId
- }).ToList()
- );
-
- //80 签证 --> 国交部门(7) 签证(26) 岗位
- _GroupsTaskAssignments.AddRange(
- userDatas
- .Where(it => it.DepId == 7 && it.JobPostId == 26)
- .Select(it => new Grp_GroupsTaskAssignment()
- {
- DIId = diId,
- CTId = 80,
- UId = it.Id,
- CreateUserId = userId
- }).ToList()
- );
- //82 团组客户保险 --> 国交部(7) 经理(32),主管(22) 岗位
- _GroupsTaskAssignments.AddRange(
- userDatas
- .Where(it => it.DepId == 7 && (it.JobPostId == 22 || it.JobPostId == 32))
- .Select(it => new Grp_GroupsTaskAssignment()
- {
- DIId = diId,
- CTId = 82,
- UId = it.Id,
- CreateUserId = userId
- }).ToList()
- );
- //85 机票预订 --> 国交部门(7) 机票(24) 岗位
- _GroupsTaskAssignments.AddRange(
- userDatas
- .Where(it => it.DepId == 7 && it.JobPostId == 24)
- .Select(it => new Grp_GroupsTaskAssignment()
- {
- DIId = diId,
- CTId = 85,
- UId = it.Id,
- CreateUserId = userId
- }).ToList()
- );
- //98 其他款项 --> 总经办部门(1) 总经理(1) 岗位/国交部门(7)(ALL) 岗位/财务部门(3)(ALL) 岗位/策划部门(5)(ALL) 岗位/人事部门(4) 采购(74) 岗位
- List<int> depIds = new List<int>() { 7,3,5 };
- List<int> jobIds = new List<int>() { 1,74};
- _GroupsTaskAssignments.AddRange(
- userDatas
- .Where(it => depIds.Contains(it.DepId) || jobIds.Contains(it.JobPostId))
- .Select(it => new Grp_GroupsTaskAssignment()
- {
- DIId = diId,
- CTId = 98,
- UId = it.Id,
- CreateUserId = userId
- }).ToList()
- );
- //1015 超支费用 --> 财务部门(3)(ALL)岗位
- _GroupsTaskAssignments.AddRange(
- userDatas
- .Where(it => it.DepId == 3)
- .Select(it => new Grp_GroupsTaskAssignment()
- {
- DIId = diId,
- CTId = 1015,
- UId = it.Id,
- CreateUserId = userId
- }).ToList()
- );
- if (_GroupsTaskAssignments.Count > 0)
- {
- var addId =_teamRateRep._sqlSugar.Insertable(_GroupsTaskAssignments).ExecuteCommand();
- }
- result.Code = 0;
- result.Msg = string.Format(@"操作成功!");
- return result;
- }
- #endregion
- #endregion
- #region 团组汇率
- /// <summary>
- /// 团组汇率
- /// 获取板块 币种 及 汇率
- /// 76 酒店预订 77 行程 79 车/导游地接
- /// 80 签证 82 团组客户保险 85 机票预订
- /// 98 其他款项 285 收款退还
- /// </summary>
- /// <param name="teamRateModels"></param>
- /// <param name="cTable"></param>
- /// <param name="currencyCode"></param>
- /// <returns>
- /// string
- /// eg: CNY 1.0000
- /// </returns>
- public static async Task<string> PostGroupRateByCTableAndCurrency(List<TeamRateModelView> teamRateModels, int cTable, List<string> currencyCodes)
- {
- string str = "";
- List<string> currencyRates = new List<string>();
- TeamRateModelView hotelRateData = teamRateModels.Where(it => it.CTableId == cTable).FirstOrDefault();
- if (hotelRateData != null)
- {
- var hotelRates = hotelRateData.TeamRates;
- foreach (var item in currencyCodes)
- {
- if (!string.IsNullOrEmpty(item))
- {
- var hotelRateInfo = hotelRates.Where(it => it.CurrencyCode.Equals(item)).FirstOrDefault();
- if (hotelRateInfo != null)
- {
- string str1 = string.Format("{0} {1}\r\n", hotelRateInfo.CurrencyCode, hotelRateInfo.Rate.ToString("#0.0000"));
- currencyRates.Add(str1);
- }
- }
- }
- if (currencyRates != null || currencyRates.Count > 0)
- {
- currencyRates = currencyRates.Distinct().ToList();
- foreach (var item in currencyRates)
- {
- str += item;
- }
- }
- }
- return str;
- }
- /// <summary>
- /// 团组汇率 币种 Item (来源:团组汇率)
- /// 根据 团组Id And 业务类型(CTable)Id
- /// api处理CTable = 285,默认返回CNY
- /// </summary>
- /// <param name="portType"></param>
- /// <param name="diId"></param>
- /// <param name="cTable"></param>
- /// <returns></returns>
- public static async Task<TeamRateModelGeneralView> PostGroupTeamRateByDiIdAndCTableId(int portType, int diId, int cTable)
- {
- TeamRateModelGeneralView _view = new TeamRateModelGeneralView();
- _view = await _teamRateRep.PostGroupTeamRateByDiIdAndCTableId(portType, diId, cTable);
- return _view;
- }
- /// <summary>
- /// 汇率备注拆分
- /// (美元(USD):7.2370|日元(JPY):0.0499|欧元(EUR):8.3000|英镑(GBP):9.1996|港币(HKD):0.9291)
- /// </summary>
- /// <param name="rateRemark"></param>
- /// <returns></returns>
- public static async Task<List<TeamRateDescAddCurrencyIdView>> SplitExchangeRate(this string rateRemark)
- {
- List<TeamRateDescAddCurrencyIdView> _view = new List<TeamRateDescAddCurrencyIdView>();
- List<SetDataInfoView> currencyDatas = new List<SetDataInfoView>();
- #region 获取所有币种
- string sql = string.Format(@"select * from Sys_SetData where STid = {0} and isdel = 0", 66);
- var DBdata = _setDataRep.GetListBySqlWithNolock(sql);
- if (DBdata == null || DBdata.Count == 0)
- {
- return _view;
- }
- currencyDatas = DBdata.Select(x => new SetDataInfoView
- {
- Name = x.Name,
- Id = x.Id,
- Remark = x.Remark,
- }).ToList();
- #endregion
- #region 拆分remark里的汇率
- if (string.IsNullOrEmpty(rateRemark))
- {
- return _view;
- }
- if (rateRemark.Contains("|"))
- {
- string[] currencyArr = rateRemark.Split("|");
- foreach (string currency in currencyArr)
- {
- string[] currency1 = currency.Split(":");
- string[] currency2 = currency1[0].Split("(");
- string currencyCode = currency2[1].Replace(")", "").TrimEnd();
- TeamRateDescAddCurrencyIdView rateDescView = new TeamRateDescAddCurrencyIdView()
- {
- CurrencyId = currencyDatas.Find(it => it.Name == currencyCode).Id,
- CurrencyCode = currencyCode,
- CurrencyName = currency2[0],
- Rate = decimal.Parse(currency1[1]),
- };
- _view.Add(rateDescView);
- }
- }
- else
- {
- try
- {
- string[] currency1 = rateRemark.Split(":");
- string[] currency2 = currency1[0].Split("(");
- string currencyCode = currency2[1].Replace(")", "").TrimEnd();
- TeamRateDescAddCurrencyIdView rateDescView = new TeamRateDescAddCurrencyIdView()
- {
- CurrencyId = currencyDatas.Find(it => it.Name == currencyCode).Id,
- CurrencyCode = currencyCode,
- CurrencyName = currency2[0],
- Rate = decimal.Parse(currency1[1]),
- };
- _view.Add(rateDescView);
- }
- catch (Exception)
- {
- return _view;
- }
- }
- #endregion
- return _view;
- }
- #endregion
- #region 汉字转换拼音
- private static Dictionary<int, List<string>> GetTotalPingYinDictionary(string text)
- {
- var chs = text.ToCharArray();
- //记录每个汉字的全拼
- Dictionary<int, List<string>> totalPingYinList = new Dictionary<int, List<string>>();
- for (int i = 0; i < chs.Length; i++)
- {
- var pinyinList = new List<string>();
- //是否是有效的汉字
- if (ChineseChar.IsValidChar(chs[i]))
- {
- ChineseChar cc = new ChineseChar(chs[i]);
- pinyinList = cc.Pinyins.Where(p => !string.IsNullOrWhiteSpace(p)).ToList();
- }
- else
- {
- pinyinList.Add(chs[i].ToString());
- }
- //去除声调,转小写
- pinyinList = pinyinList.ConvertAll(p => Regex.Replace(p, @"\d", "").ToLower());
- //去重
- pinyinList = pinyinList.Where(p => !string.IsNullOrWhiteSpace(p)).Distinct().ToList();
- if (pinyinList.Any())
- {
- totalPingYinList[i] = pinyinList;
- }
- }
- return totalPingYinList;
- }
- /// <summary>
- /// 获取汉语拼音全拼
- /// </summary>
- /// <param name="text">The string.</param>
- /// <returns></returns>
- public static List<string> GetTotalPingYin(this string text)
- {
- var result = new List<string>();
- foreach (var pys in GetTotalPingYinDictionary(text))
- {
- var items = pys.Value;
- if (result.Count <= 0)
- {
- result = items;
- }
- else
- {
- //全拼循环匹配
- var newTotalPingYinList = new List<string>();
- foreach (var totalPingYin in result)
- {
- newTotalPingYinList.AddRange(items.Select(item => totalPingYin + item));
- }
- newTotalPingYinList = newTotalPingYinList.Distinct().ToList();
- result = newTotalPingYinList;
- }
- }
- return result;
- }
- /// <summary>
- /// 获取汉语拼音首字母
- /// </summary>
- /// <param name="text"></param>
- /// <returns></returns>
- public static List<string> GetFirstPingYin(this string text)
- {
- var result = new List<string>();
- foreach (var pys in GetTotalPingYinDictionary(text))
- {
- var items = pys.Value;
- if (result.Count <= 0)
- {
- result = items.ConvertAll(p => p.Substring(0, 1)).Distinct().ToList();
- }
- else
- {
- //首字母循环匹配
- var newFirstPingYinList = new List<string>();
- foreach (var firstPingYin in result)
- {
- newFirstPingYinList.AddRange(items.Select(item => firstPingYin + item.Substring(0, 1)));
- }
- newFirstPingYinList = newFirstPingYinList.Distinct().ToList();
- result = newFirstPingYinList;
- }
- }
- return result;
- }
- #endregion
- #region 新客户资料表 操作记录
- /// <summary>
- /// 新客户资料表
- /// 操作记录添加
- /// </summary>
- /// <param name="portType"></param>
- /// <param name="operationEnum"></param>
- /// <param name="userId"></param>
- /// <param name="dataId"></param>
- /// <param name="remark"></param>
- /// <returns></returns>
- public static async Task<bool> NewClientOperationRecord(int portType, OperationEnum operationEnum, int userId, int dataId, string remark)
- {
- Crm_TableOperationRecord _TableOperationRecord = new Crm_TableOperationRecord()
- {
- TableName = "Crm_NewClientData",
- PortType = portType,
- OperationItem = operationEnum,
- DataId = dataId,
- CreateUserId = userId,
- CreateTime = DateTime.Now,
- Remark = remark
- };
- bool add = await _tableOperationRecordRep._Add(_TableOperationRecord);
- if (add) return false;
- return false;
- }
- #endregion
- #region 金额转大写
- /// <summary>
- /// 金额转换为大写数字
- /// <para>1、支持的最大数字:999999999999.99(玖仟玖佰玖拾玖亿玖仟玖佰玖拾玖万玖仟玖佰玖拾玖元玖角玖分)</para>
- /// <para>2、小数点后最多支持两位</para>
- /// </summary>
- /// <param name="num">数值</param>
- /// <returns></returns>
- public static string ConvertCNYUpper(this decimal num)
- {
- if (num == 0)
- {
- return "零元";
- }
- // 解决327000000转换后缺少单位万的问题
- return ConvertToChinese(num);
- }
- #region 实例
- /// <summary>
- /// 要转换的数字
- /// </summary>
- private static decimal j;
- /// <summary>
- ///
- /// </summary>
- private static string[] NumChineseCharacter = new string[] { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
- /// <summary>
- /// 判断输入的数字是否大于double类型
- /// </summary>
- private static bool IsNumber
- {
- get
- {
- if (j > decimal.MaxValue || j <= 0)
- return false;
- else
- return true;
- }
- }
- /// <summary>
- /// 数字转换成大写汉字主函数
- /// </summary>
- /// <returns>返回转换后的大写汉字</returns>
- public static string ConvertToChinese(decimal m)
- {
- j = m;
- string bb = "";
- if (IsNumber)
- {
- string str = j.ToString();
- string[] Num = str.Split('.');
- if (Num.Length == 1)
- {
- bb = NumberString(Num[0]) + "元整";
- bb = bb.Replace("零零", "零");
- }
- else
- {
- bb = NumberString(Num[0]) + "元";
- bb += FloatString(Num[1]);
- bb = bb.Replace("零零", "零");
- }
- }
- else
- {
- throw new FormatException("你输入的数字格式不正确或不是数字!");
- }
- return bb;
- }
- /// <summary>
- /// 小数位转换只支持两位的小数
- /// </summary>
- /// <param name="Num">转换的小数</param>
- /// <returns>小数转换成汉字</returns>
- private static string FloatString(string Num)
- {
- string cc = "";
- if (Num.Length > 2)
- {
- throw new FormatException("小数位数过多.");
- }
- else
- {
- string bb = ConvertString(Num);
- int len = bb.IndexOf("零");
- if (len != 0)
- {
- bb = bb.Replace("零", "");
- if (bb.Length == 1)
- {
- cc = bb.Substring(0, 1) + "角";
- }
- else
- {
- cc = bb.Substring(0, 1) + "角";
- cc += bb.Substring(1, 1) + "分";
- }
- }
- else
- cc = bb + "分";
- }
- return cc;
- }
- /// <summary>
- /// 判断数字位数以进行拆分转换
- /// </summary>
- /// <param name="Num">要进行拆分的数字</param>
- /// <returns>转换成的汉字</returns>
- private static string NumberString(string Num)
- {
- string bb = "";
- if (Num.Length <= 4)
- {
- bb = Convert4(Num);
- }
- else if (Num.Length > 4 && Num.Length <= 8)
- {
- bb = Convert4(Num.Substring(0, Num.Length - 4)) + "万";
- bb += Convert4(Num.Substring(Num.Length - 4, 4));
- }
- else if (Num.Length > 8 && Num.Length <= 12)
- {
- bb = Convert4(Num.Substring(0, Num.Length - 8)) + "亿";
- if (Convert4(Num.Substring(Num.Length - 8, 4)) == "")
- if (Convert4(Num.Substring(Num.Length - 4, 4)) != "")
- bb += "零";
- else
- bb += "";
- else
- bb += Convert4(Num.Substring(Num.Length - 8, 4)) + "万";
- bb += Convert4(Num.Substring(Num.Length - 4, 4));
- }
- else
- {
- throw new Exception("整数部分最多支持12位");
- }
- return bb;
- }
- /// <summary>
- /// 四位数字的转换
- /// </summary>
- /// <param name="Num">准备转换的四位数字</param>
- /// <returns>转换以后的汉字</returns>
- private static string Convert4(string Num)
- {
- string bb = "";
- if (Num.Length == 1)
- {
- bb = ConvertString(Num);
- }
- else if (Num.Length == 2)
- {
- bb = ConvertString(Num);
- bb = Convert2(bb);
- }
- else if (Num.Length == 3)
- {
- bb = ConvertString(Num);
- bb = Convert3(bb);
- }
- else
- {
- bb = ConvertString(Num);
- string cc = "";
- string len = bb.Substring(0, 4);
- if (len != "零零零零")
- {
- len = bb.Substring(0, 3);
- if (len != "零零零")
- {
- bb = bb.Replace("零零零", "");
- if (bb.Length == 1)
- {
- bb = bb.Substring(0, 1) + "仟";
- }
- else
- {
- if (bb.Substring(0, 1) != "零" && bb.Substring(0, 2) != "零")
- cc = bb.Substring(0, 1) + "仟";
- else
- cc = bb.Substring(0, 1);
- bb = cc + Convert3(bb.Substring(1, 3));
- }
- }
- else
- {
- bb = bb.Replace("零零零", "零");
- }
- }
- else
- {
- bb = bb.Replace("零零零零", "");
- }
- }
- return bb;
- }
- /// <summary>
- /// 将数字转换成汉字
- /// </summary>
- /// <param name="Num">需要转换的数字</param>
- /// <returns>转换后的汉字</returns>
- private static string ConvertString(string Num)
- {
- string bb = "";
- for (int i = 0; i < Num.Length; i++)
- {
- bb += NumChineseCharacter[int.Parse(Num.Substring(i, 1))];
- }
- return bb;
- }
- /// <summary>
- /// 两位数字的转换
- /// </summary>
- /// <param name="Num">两位数字</param>
- /// <returns>转换后的汉字</returns>
- private static string Convert2(string Num)
- {
- string bb = ""; string cc = "";
- string len = Num.Substring(0, 1);
- if (len != "零")
- {
- bb = Num.Replace("零", "");
- if (bb.Length == 1)
- {
- cc = bb.Substring(0, 1) + "拾";
- }
- else
- {
- cc = bb.Substring(0, 1) + "拾";
- cc += bb.Substring(1, 1);
- }
- }
- else
- cc = Num;
- return cc;
- }
- /// <summary>
- /// 三位数字的转换
- /// </summary>
- /// <param name="Num">三位数字</param>
- /// <returns>转换后的汉字</returns>
- private static string Convert3(string Num)
- {
- string bb = ""; string cc = "";
- string len = Num.Substring(0, 2);
- if (len != "零零")
- {
- bb = Num.Replace("零零", "");
- if (bb.Length == 1)
- {
- bb = bb.Substring(0, 1) + "佰";
- }
- else
- {
- if (bb.Substring(0, 1) != "零")
- cc = bb.Substring(0, 1) + "佰";
- else
- cc = bb.Substring(0, 1);
- bb = cc + Convert2(bb.Substring(1, 2));
- }
- }
- else
- {
- bb = Num.Replace("零零", "零");
- }
- return bb;
- }
- #endregion
- #endregion
- #region 数字验证
- /// <summary>
- /// 验证数字字符串
- /// </summary>
- /// <param name="num"></param>
- /// <returns></returns>
- public static bool IsNumeric(this string numStr)
- {
- bool isNumeric = Regex.IsMatch(numStr, @"^\d+$");
- if (isNumeric)
- {
- return true;
- }
- return false;
- }
- #endregion
- }
- }
|