/// <summary> /// [client]技師登入 /// </summary> /// <param name="Account"></param> /// <param name="Password"></param> /// <returns></returns> public TvenderTechnician VendorLogin(string Account, string Password, string UUID) { _logger.Info($"APP登入-帳號:{Account},密碼:{Password},UUID:{UUID}"); #region 取得技師資訊 var con = new Conditions <DataBase.TVenderTechnician>(); con.And(x => x.Account == Account); con.And(x => x.Password == Password); con.Include(x => x.TVENDER); con.And(x => x.TVENDER.Comp_Cd == "711"); TvenderTechnician result = _technicianRepo.Get(con); #endregion 檢核技師相關欄位 #region 相關驗證 if (result == null) { _logger.Info("帳號或密碼不存在"); throw new NullReferenceException($"登入失敗"); } if (!result.Enable) { _logger.Info("帳號尚未啟用"); throw new InvalidProgramException($"帳號尚未啟用"); } var ConTusrven = new Conditions <DataBase.TUSRVENRELATION>(); ConTusrven.And(x => x.Comp_Cd == result.CompCd); ConTusrven.And(x => x.Vender_Cd == result.VenderCd); var Tusrven = _tusrvenrelationRepo.Get(ConTusrven); if (Tusrven == null) { _logger.Info("廠商未服務711"); throw new InvalidProgramException($"廠商未服務711"); } //2018/06/19因為廠商輸入密碼錯誤6次會造成帳號被關閉且技師無法登入APP,經與玉萍討論,在決定檢核廠商的規則前,暫時不進行檢核 by 天生 //if (_venderFactory.CheckVender(result.CompCd, Tusrven.User_Id) == false) //{ // _logger.Info("廠商已被關閉"); // throw new InvalidProgramException($"廠商已被關閉"); //} if (!string.IsNullOrEmpty(result.DeviceID) && result.DeviceID != UUID) { _logger.Info("UUID重複"); throw new ArgumentOutOfRangeException($"已經有其他設備登入過,是否強制登入?"); } #endregion #region 寫入相關資訊 _logger.Info($"APP登入-準備更新資訊"); con.Allow(x => x.LastLoginTime); con.Allow(x => x.DeviceID); if (!_technicianRepo.Update(con, new TvenderTechnician() { Account = Account, Password = Password, DeviceID = UUID, LastLoginTime = DateTime.Now })) { throw new Exception("登入失敗"); } #endregion return(result); }
public void SelectMultiple_Generic_EqualsExpected() { var sqlFilter = SqlFilter.Construct(new { Ids = new[] { 1, 2 }, Value1 = "foo", Auto = (int?)null, Key = Guid.Empty, DbGeneratedKey = 2 }); var sqlBuilder = SqlBuilder <Class1, Class2> .Select() .CustomSql("/* SELECT */") .From((table1, table2) => table1) .CustomSql("/* FROM */") .InnerJoin((table1, table2) => table2, (table1, table2) => table2[m => m.Key].EqualsOne(table1[m => m.Id])) .CustomSql("/* JOIN */") .Where((table1, table2) => Conditions.And( Conditions.Or(sqlFilter[f => f.Ids].IsNull(), table1[m => m.Id].EqualsAny(sqlFilter[f => f.Ids])), Conditions.Or(sqlFilter[f => f.Value1].IsNull(), table1[m => m.Value1].EqualsOne(sqlFilter[f => f.Value1])), Conditions.Or(sqlFilter[f => f.Key].IsNull(), table2[m => m.Key].EqualsOne(sqlFilter[f => f.Key])), sqlFilter[f => f.DbGeneratedKey] .IsNull() .Or(table2[m => m.DbGeneratedKey].EqualsOne(sqlFilter[f => f.DbGeneratedKey])), table2[m => m.Key].ILike(sqlFilter[f => f.Key]), table2[m => m.Key].Like(sqlFilter[f => f.Key]), table2[m => m.Key].Lower().Like(sqlFilter[f => f.Key].Lower()))) .CustomSql("/* WHERE */") .OrderBy((table1, table2) => table1[m => m.Id], OrderDirection.Asc) .CustomSql("/* ORDER */") .Offset(5) .CustomSql("/* OFFSET */") .LimitBy(10) .CustomSql("/* LIMIT */") .CustomSql("/* START */", SqlSelectPosition.Start); var sqlOptions = new SqlOptions { Dialect = SqlDialect.Postgres95 }; var actual = sqlBuilder.BuildSql(sqlOptions); var expected = @" /* START */ SELECT class1.id AS Id, class1.auto AS Auto, class1.value1 AS Value1, class1.value2 AS Value2, class1.do_not_change AS DoNotChange, class2.key AS Key, class2.db_generated_key AS DbGeneratedKey, class2.db_generated AS DbGenerated, class2.value1 AS Value1, class2.value2 AS Value2, class2.code_generated AS CodeGenerated, class2.do_not_change AS DoNotChange /* SELECT */ FROM foo.class1 /* FROM */ INNER JOIN foo.class2 ON class2.key = class1.id /* JOIN */ WHERE (@Ids IS NULL OR class1.id = ANY(@Ids)) AND (@Value1 IS NULL OR class1.value1 = @Value1) AND (@Key IS NULL OR class2.key = @Key) AND (@DbGeneratedKey IS NULL OR class2.db_generated_key = @DbGeneratedKey) AND class2.key ILIKE @Key AND class2.key LIKE @Key AND LOWER(class2.key) LIKE LOWER(@Key) /* WHERE */ ORDER BY class1.id ASC /* ORDER */ OFFSET 5 /* OFFSET */ LIMIT 10 /* LIMIT */ "; Check(expected, actual); Assert.AreEqual("Id,Key", sqlBuilder.SplitOn); }
/// <summary> /// [server 更新使用者資訊] /// </summary> /// <param name="user"></param> /// <param name="role"></param> /// <returns></returns> public bool Update(UserBase User, RoleAuth Role) { #region 找到對應的使用者 var uCon = new Conditions <DataBase.TUSRMST>(); uCon.And(x => x.Comp_Cd == User.CompCd && x.User_Id == User.UserId); //uCon.Include(x => x.TSYSROL); Tusrmst user = _userRepo.Get(uCon); if (user == null) { throw new NullReferenceException($"[ERROR]=>找不到對應的使用者資訊,公司代號:{User.CompCd},使用者ID:{User.UserId}"); } #endregion #region 找到對應權限 var rCon = new Conditions <DataBase.TSYSROL>(); rCon.And(x => x.Comp_Cd == Role.CompCd && x.Role_Id == Role.RoleId); RoleAuth role = _aspRoleRepo.Get(rCon); if (role == null) { throw new NullReferenceException($"[ERROR]=>找不到對應的權限資訊,公司代號:{User.CompCd},權限ID:{User.RoleId}"); } #endregion #region 組合物件 List <AuthItem> pageAuth = CulcPageAuth(role.PageAuth, User.PageAuth); user.RoleId = role.RoleId; user.PageAuth = pageAuth != null?JsonConvert.SerializeObject(pageAuth) : string.Empty; #endregion #region 更新資料 uCon.Allow(x => x.Role_Id, x => x.PageAuth); if (!_userRepo.Update(uCon, user)) { throw new Exception("[ERROR]=>更新使用者資訊失敗"); } #endregion return(true); }
public ActionResult TechnicianNotifyForAppoint(string[] Technician, string Sn) { try { if (Technician == null) { throw new Exception("未選擇推播技師"); } if (Sn == string.Empty) { throw new Exception("未選擇案件"); } string[] CallogSn = Sn.Split(','); var _user = ((PtcIdentity)this.User.Identity).currentUser; if (_user.CompCd == "") { _user.CompCd = "711"; } List <string> NotifySn = new List <string>(); //Sn //Dictionary<string, string> Account = new Dictionary<string, string>(); //key:技師帳號、value:技師RegId List <string> Account = new List <string>(); #region 驗證技師資料 Conditions <DataBase.TVenderTechnician> conTechnician = new Conditions <DataBase.TVenderTechnician>(); foreach (string itemTechnician in Technician) { _logger.Info($"廠商:{_user.VenderCd},開始驗證技師資料,被驗證的技師有{itemTechnician}"); conTechnician.And(x => x.Comp_Cd == _user.CompCd); //公司別 conTechnician.And(x => x.Vender_Cd == _user.VenderCd); //廠商 conTechnician.And(x => x.Enable == true); //啟用 conTechnician.And(x => x.Account == itemTechnician); //廠商帳號 TvenderTechnician data = _TvenderTechnicianRepo.Get(conTechnician); if (data == null) { _logger.Info($"查無技師資料:{itemTechnician}"); } else { _logger.Info($"加入推播,帳號:{itemTechnician}"); Account.Add(itemTechnician); Account.Add(data.RegistrationID); Account.Add(data.Name); } conTechnician = new Conditions <DataBase.TVenderTechnician>(); } #endregion #region 檢查叫修編號狀態 Conditions <DataBase.TCALLOG> conCallog = new Conditions <DataBase.TCALLOG>(); foreach (string itemSn in CallogSn) { _logger.Info($"廠商:{_user.VenderCd},開始驗證案件資料,被驗證的案件有{itemSn}"); conCallog.And(x => x.Comp_Cd == _user.CompCd); conCallog.And(x => x.Sn == itemSn); conCallog.And(x => x.TAcceptedLog.Sn == null); Tcallog data = _tcallogRepo.Get(conCallog); if (data == null) { _logger.Info($"查無案件資料:{itemSn}(可能已經被認養)"); } else if (data.CloseSts > (byte)CloseSts.process) { _logger.Info($"案件:{itemSn},已經銷案。"); } else { _logger.Info($"加入推播,案件:{itemSn}"); NotifySn.Add(itemSn); } conCallog = new Conditions <DataBase.TCALLOG>(); } #endregion if (Account.Count == 0) { throw new Exception("勾選的技師驗證後無資料"); } if (NotifySn.Count == 0) { throw new Exception("勾選的案件驗證後無資料,請重新整理"); } #region 更新待受理案件+推播 var isSuccess = _callogService.NotificationForAppoint(_user, NotifySn, Account); #endregion return(Json(new JsonResult() { Data = new { IsSuccess = isSuccess, Message = $"指派案件:{(isSuccess ? "成功" : "失敗")}" } })); } catch (Exception ex) { _logger.Error(ex.Message); if (ex.InnerException != null) { _logger.Error(ex.InnerException.Message); if (ex.InnerException.InnerException != null) { _logger.Error(ex.InnerException.InnerException.Message); } } return(Json(new JsonResult() { Data = new { IsSuccess = false, Message = $"指派案件失敗,原因:{ex.Message}" } })); } }
/// <summary> /// 新增群組信息 /// </summary> /// <param name="Data"></param> /// <param name="Accounts"></param> /// <returns></returns> public Boolean CreateTechnicianGroup(TtechnicianGroup Data, String[] Accounts) { //_logger.Info($"新增群組-群組名稱:{Data.GroupName}"); #region 檢核群組信息是否重复 var con = new Conditions <DataBase.TTechnicianGroup>(); con.And(x => x.CompCd == Data.CompCd && x.VendorCd == Data.VendorCd && x.GroupName == Data.GroupName); //if (_technicianGroupRepo.IsExist(con)) // throw new IndexOutOfRangeException("[ERROR]=>新增群組,檢核已有該群組存在"); #endregion using (TransactionScope scope = new TransactionScope()) { _logger.Info($"新增群組-準備更新資料"); #region 新增群組 if (_technicianGroupRepo.IsExist(con)) { throw new Exception("群組名稱相同"); } _technicianGroupRepo.Add(con, Data); var seq = _technicianGroupRepo.Get(con).Seq; #endregion #region 新增技師至群組 if (Accounts != null) { foreach (String account in Accounts) { TtechnicianGroupClaims technicianGroupClaims = new TtechnicianGroupClaims() { Seq = seq, CompCd = Data.CompCd, VendorCd = Data.VendorCd, Account = account }; var cond = new Conditions <DataBase.TTechnicianGroupClaims>(); cond.And(x => x.Seq == seq && x.CompCd == Data.CompCd && x.VendorCd == Data.VendorCd && x.Account == account); if (!_technicianGroupClaimsRepo.Add(cond, technicianGroupClaims)) { throw new Exception("[ERROR]=>新增技師至群組時,新增失敗"); } } } #endregion scope.Complete(); } return(true); }
public override void OnAuthorization(HttpActionContext actionContext) { var token = HttpUtility.ParseQueryString(actionContext.Request.RequestUri.Query).Get("token"); if (token == null) { actionContext.Response = new System.Net.Http.HttpResponseMessage(System.Net.HttpStatusCode.Forbidden); } else { var tokenHandler = new JwtSecurityTokenHandler(); var securityKey = GetBytes("anyoldrandomtext"); var validationParameters = new TokenValidationParameters() { ValidAudience = "https://www.mywebsite.com", ValidateLifetime = true, IssuerSigningKeys = new List <SecurityKey> { new SymmetricSecurityKey(securityKey) }, ValidAudiences = new List <string> { "https://www.mywebsite.com" }, ValidIssuer = "self" }; try { SecurityToken securityToken; var principal = tokenHandler.ValidateToken(token, validationParameters, out securityToken); var userData = principal.Claims.FirstOrDefault(); if (userData != null) { //解析token var input = JsonConvert.DeserializeObject <TvenderTechnician>(userData.Value); var con = new Conditions <DataBase.TVenderTechnician>(); var password = Identity.ClearPassword.GetMd5Hash(input.Password).ToUpper(); con.And(x => x.Account == input.Account && x.Password == password); TvenderTechnician user = _userRepo.Get(con); //查无使用者 if (user == null) { throw new Exception("no find user info"); } //使用者已關閉 if (user.Enable == false) { throw new Exception("user info is not Enable"); } var tusrvenlation = new Conditions <DataBase.TUSRVENRELATION>(); tusrvenlation.And(x => x.Comp_Cd == user.CompCd); tusrvenlation.And(x => x.Vender_Cd == user.VenderCd); var resault = _TUSRVENRELATIONRepo.Get(tusrvenlation); if (resault == null) { throw new Exception("Vender is not find"); } //廠商已關閉 var conUser = new Conditions <DataBase.TUSRMST>(); conUser.And(x => x.Comp_Cd == user.CompCd || x.Comp_Cd == ""); conUser.And(x => x.User_Id == resault.User_Id); conUser.And(x => x.Role_Id == "VENDER" || x.Role_Id == "CafeVender" || x.Role_Id == "APPVENDER"); conUser.And(x => x.Id_Sts == "Y"); if (_usermstRepo.Count(conUser) == 0) { throw new Exception("user vender is close"); } // 裝置不同 if (user.DeviceID != input.DeviceID) { throw new Exception("different device"); } var identity = new AspnetMvc.Models.PtcIdentity( System.Threading.Thread.CurrentPrincipal.Identity, new UserBase() { VenderCd = user.VenderCd, CompCd = user.CompCd, UserName = user.Name, UserId = user.Account, Password = input.Password }, "phone", null); SetPrincipal(new GenericPrincipal(identity, null)); } else { HandleUnauthorizedRequest(actionContext); } } catch (Exception) { HandleUnauthorizedRequest(actionContext); } } //base.OnAuthorization(actionContext); }
/// <summary> /// 廠商銷案案件 /// </summary> /// <param name="input"></param> /// <returns></returns> public Boolean VendorConfirm(Tcallog input) { _logger.Info($"案件銷案-公司別:{input.CompCd},案件編號:{input.Sn}"); string SapAssetKind = _ImgRepo.GetSpcAssetKind(input.CompCd, input.AssetCd); var con = new Conditions <DataBase.TCALLOG>(); con.And(g => g.Sn == input.Sn); con.And(g => g.Comp_Cd == input.CompCd); con.Allow(g => g.Arrive_Date); con.Allow(g => g.Fc_Date); con.Allow(g => g.TimePoint); con.Allow(g => g.Work_Id); con.Allow(g => g.Finish_Id); con.Allow(g => g.Damage_Proc_No); if (SapAssetKind == "1") { con.Allow(g => g.Coffee_Cup); } con.Allow(g => g.Close_Sts); con.Allow(g => g.Work_Desc); con.Allow(g => g.VndEng_Id); con.Allow(g => g.AppClose_Date); con.Allow(g => g.Update_User); con.Allow(g => g.Update_Date); List <TCallLogDateRecord> AddCDR = new List <TCallLogDateRecord>(); if (input.TcallLogDateRecords != null) { AddCDR = input.TcallLogDateRecords.Where(x => x.Seq == 0).ToList(); } //檢查是否已有既有紀錄,若有則進行更新就好 TCALINV sqlCALINV = GetTCALINV(input.CompCd, input.Sn); var conINV = new Conditions <DataBase.TCALINV>(); conINV.And(g => g.Comp_Cd == input.CompCd); conINV.And(g => g.Sn == input.Sn); if (sqlCALINV != null) { conINV.Allow(g => g.Work_Id); conINV.Allow(g => g.Pre_Amt); conINV.Allow(g => g.Update_User); conINV.Allow(g => g.Update_Date); } using (TransactionScope scope = new TransactionScope()) { _logger.Info($"案件銷案-準備更新資料"); #region 儲存資料 _callogRepo.Update(con, input); if (input.TCALINV != null) { if (sqlCALINV == null) { _CALINVRepo.Add(conINV, input.TCALINV); } else { _CALINVRepo.Update(conINV, input.TCALINV); } } if (AddCDR != null) { _callogFactory.AddDateRecords(AddCDR); } #endregion _logger.Info($"案件銷案-準備儲存照片"); #region 儲存照片 _ImgRepo.AddImg(input); #endregion scope.Complete(); } return(true); }
public ActionResult GetList(DataTablesReqModel <List <TechnicianViewModel> > data) { List <TechnicianViewModel> models = data.criteria; DataTablesRespModel result = new DataTablesRespModel(data.draw); try { if (data.criteria == null) { throw new Exception("沒有條件,無法查詢"); } Conditions <DataBase.TVenderTechnician> con = new Conditions <DataBase.TVenderTechnician>(data.length, (data.start / data.length)); models?.ForEach(model => { var component = new List <Expression <Func <DataBase.TVenderTechnician, Boolean> > >(); model.GetProperties()? .Select(x => x.Avatar <AvatarAttribute>(model)) .Where(x => x.Key != null) .ForEach(g => { component.Add(con.CombinationExpression( g.Key.SubstituteName, g.Key.ExpressionType, g.Value)); }); con.ConvertToMultiFilter(component); }); data.order?.ForEach(x => { con.Order(x.dir, data.columns[x.column].name); }); #region DataRange var _user = (this.User.Identity as PtcIdentity).currentUser; con.And(x => x.Comp_Cd == _user.CompCd); if (_user.DataRange?.VendorCd != null) { con.And(x => _user.DataRange.VendorCd.Contains(x.Vender_Cd)); } #endregion var list = _technicianRepo.GetList(con); int PageIndex = (data.start / data.length); PagedList <TvenderTechnician> meta = new PagedList <TvenderTechnician>(list, PageIndex, data.length); result.data = meta.Select(x => new TechnicianResultViewModel(x).colData) .ToArray(); result.TotalCount(con.TotalCount); } catch (Exception ex) { _logger.Error(ex); if (ex.InnerException != null) { _logger.Error(ex.InnerException.Message); if (ex.InnerException.InnerException != null) { _logger.Error(ex.InnerException.InnerException.Message); } } result.error = ex.Message; } return(Json(result)); }
public ActionResult Edit(TechnicianEditViewModel data) { try { if (!this.LoginUserInfo.CurrentGroupAction.AuthType.Value.HasFlag(AuthNodeType.Edit)) { throw new Exception("沒有修改權限"); } if (!ModelState.IsValid) { throw new ArgumentNullException($"修改技師資料時有欄位未輸入"); } //組合對象 TvenderTechnician technician = new TvenderTechnician() { Account = data.Account, CompCd = data.CompCd, VenderCd = data.VenderCd, Name = data.Name, Enable = data.Enable, Password = !string.IsNullOrEmpty(data.NewPassword) ? //if(新密码不为空) 新密码加密 Identity.ClearPassword.GetMd5Hash(data.NewPassword).ToUpper() : // else data.Password, // 旧密码 IsVendor = data.IsVendor //是否為技師主管 }; var con = new Conditions <DataBase.TVenderTechnician>(); con.And(x => x.Comp_Cd == data.CompCd && //查詢條件 x.Vender_Cd == data.VenderCd && // x.Account == data.Account); // //執行修改 Boolean isSuccess = _technicianService.UpdateTechnician(technician); return(Json(new JsonResult() { Data = new { IsSuccess = isSuccess, Message = $"修改技師:{(isSuccess ? "成功" : "失敗")}" } })); } catch (Exception ex) { _logger.Error(ex.Message); if (ex.InnerException != null) { _logger.Error(ex.InnerException.Message); if (ex.InnerException.InnerException != null) { _logger.Error(ex.InnerException.InnerException.Message); } } return(Json(new JsonResult() { Data = new { IsSuccess = false, Message = $"修改技師失敗,原因:{ex.Message}" } })); } }
public ActionResult SearchMasterAuth(DataTablesReqModel <List <AuthSetViewModel> > data) { List <AuthSetViewModel> models = data.criteria; DataTablesRespModel result = new DataTablesRespModel(data.draw); try { Conditions <DataBase.TSYSROL> con = new Conditions <DataBase.TSYSROL>(data.length, (data.start / data.length)); models?.ForEach(model => { var component = new List <Expression <Func <DataBase.TSYSROL, Boolean> > >(); model.GetProperties()? .Select(x => x.Avatar <AvatarAttribute>(model)) .Where(x => x.Key != null) .ForEach(g => { component.Add(con.CombinationExpression( g.Key.SubstituteName, g.Key.ExpressionType, g.Value)); }); con.ConvertToMultiFilter(component); }); data.order?.ForEach(x => { con.Order(x.dir, data.columns[x.column].name); }); //con.Include(x => x.TUSRMST); #region DataRange var _user = (this.User.Identity as AspnetMvc.Models.PtcIdentity).currentUser; con.And(x => x.Comp_Cd == _user.CompCd); #endregion var list = _tsysrolRepo.GetList(con); PagedList <RoleAuth> meta = new PagedList <RoleAuth>(list); result.data = list.Select(x => new RoleAuthViewModel(x, new List <AuthData>())) .Select(g => new string[] { g.Compcd, g.RoleName, g.RoleId, }).ToArray(); result.TotalCount(con.TotalCount); } catch (Exception ex) { _logger.Error(ex); result.error = ex.Message; } return(Json(result)); }
public ActionResult ModifyMasterAuth(RoleAuthViewModel model) { Boolean isSuccess = false; try { var con = new Conditions <DataBase.TSYSROL>(); var compcd = model?.Compcd ?? string.Empty; con.And(x => x.Comp_Cd == compcd && x.Role_Id == model.RoleId); RoleAuth roleAuth = _tsysrolRepo.Get(con); if (roleAuth == null) { throw new NullReferenceException($"no find data"); } List <AuthItem> pageAuth = model.PageAuth == null ? new List <AuthItem>() : model.PageAuth.Select(x => new AuthItem() { GroupName = x.id, AuthType = x.AuthType }).ToList(); Tsysrol updaterole = new Tsysrol() { RoleId = model.RoleId, RoleName = model.RoleName, CompCd = model.Compcd, PageAuth = pageAuth != null?JsonConvert.SerializeObject(pageAuth) : string.Empty, UpdateDate = DateTime.Now, UpdateUser = User.Identity.Name, }; con.Allow(y => y.Role_Name, y => y.PageAuth, y => y.Update_Date, y => y.Update_User); isSuccess = _uptsysrolRepo.Update(con, updaterole); MvcSiteMapProvider.SiteMaps.ReleaseSiteMap(); return(Json(new JsonResult() { Data = new { IsSuccess = isSuccess, Message = $"修改權限:{(isSuccess ? "成功" : "失敗")}" } })); } catch (Exception ex) { return(Json(new JsonResult() { Data = new { IsSuccess = isSuccess, Message = $"修改權限:{(isSuccess ? "成功" : "失敗")}" } })); } }
protected override void Initialize(SonarAnalysisContext context) { // Special case - Assembly.Load InvocationTracker.Track(context, InvocationTracker.MatchMethod( new MemberDescriptor(KnownType.System_Reflection_Assembly, "Load"), new MemberDescriptor(KnownType.System_Reflection_Assembly, "LoadFile"), new MemberDescriptor(KnownType.System_Reflection_Assembly, "LoadFrom"), new MemberDescriptor(KnownType.System_Reflection_Assembly, "LoadWithPartialName")), InvocationTracker.MethodIsStatic()); // Special case - Type.GetType() without paramters is ok, but // and Type.GetType(...) with parameters is not ok InvocationTracker.Track(context, InvocationTracker.MatchMethod( new MemberDescriptor(KnownType.System_Type, "GetType")), InvocationTracker.MethodIsStatic(), InvocationTracker.MethodHasParameters(), Conditions.ExceptWhen( Conditions.And( InvocationTracker.ArgumentAtIndexIs(0, KnownType.System_String), InvocationTracker.ArgumentAtIndexIsConstant(0)))); // Special case - Activator.CreateXXX InvocationTracker.Track(context, InvocationTracker.MatchMethod( new MemberDescriptor(KnownType.System_Activator, "CreateComInstanceFrom"), new MemberDescriptor(KnownType.System_Activator, "CreateInstance"), new MemberDescriptor(KnownType.System_Activator, "CreateInstanceFrom")), InvocationTracker.MethodIsStatic(), InvocationTracker.MethodHasParameters(), Conditions.ExceptWhen( InvocationTracker.ArgumentAtIndexIs(0, KnownType.System_Type))); // All other method invocations InvocationTracker.Track(context, Conditions.ExceptWhen( InvocationTracker.IsTypeOfExpression()), InvocationTracker.MatchMethod( // Methods on assembly that are safe to call with constants new MemberDescriptor(KnownType.System_Reflection_Assembly, "GetType"), new MemberDescriptor(KnownType.System_Reflection_Assembly, "GetTypes"), new MemberDescriptor(KnownType.System_Reflection_Assembly, "GetModule"), new MemberDescriptor(KnownType.System_Reflection_Assembly, "GetLoadedModules"), new MemberDescriptor(KnownType.System_Reflection_Assembly, "GetModules"), new MemberDescriptor(KnownType.System_Reflection_Assembly, "CreateInstance"), new MemberDescriptor(KnownType.System_Reflection_Assembly, "GetExportedTypes"), new MemberDescriptor(KnownType.System_Type, "GetInterface"), new MemberDescriptor(KnownType.System_Type, "GetNestedType"), new MemberDescriptor(KnownType.System_Type, "GetNestedTypes"), new MemberDescriptor(KnownType.System_Type, "GetInterfaces"), new MemberDescriptor(KnownType.System_Type, "GetMethod"), new MemberDescriptor(KnownType.System_Type, "GetField"), new MemberDescriptor(KnownType.System_Type, "GetProperty"), new MemberDescriptor(KnownType.System_Type, "GetMember"), new MemberDescriptor(KnownType.System_Type, "GetMethods"), new MemberDescriptor(KnownType.System_Type, "GetFields"), new MemberDescriptor(KnownType.System_Type, "GetProperties"), new MemberDescriptor(KnownType.System_Type, "GetMembers"), new MemberDescriptor(KnownType.System_Type, "GetDefaultMembers"), new MemberDescriptor(KnownType.System_Type, "InvokeMember")), Conditions.ExceptWhen( Conditions.And( InvocationTracker.ArgumentAtIndexIs(0, KnownType.System_String), InvocationTracker.ArgumentAtIndexIsConstant(0)))); }
public ActionResult ReadView(TechnicianGroupEditViewModel model) { try { if (MethodHelper.IsNullOrEmpty(model.CompCd, model.VendorCd)) { throw new ArgumentNullException($"移至瀏覽群組畫面,没有傳入對應信息"); } TtechnicianGroup group = _vendorFactory.GetGroup(model.CompCd, model.VendorCd, model.Seq); List <TvenderTechnician> technicians = _vendorFactory.GetTechnicians(model.CompCd, model.VendorCd); var mask = group?.TTechnicianGroupClaims? .Select(x => x.TVenderTechnician.Account) .ToList(); #region 處理區域與課別 //取得所有區課 var conZo = new Conditions <DataBase.TZOCODE>(); conZo.And(x => x.Comp_Cd == model.CompCd); PagedList <Tzocode> Zo = _TzocodeRepo.GetList(conZo); //取得保修商負責區域 List <string> tvndzo = _vendorFactory.GetVenderZo(model.CompCd, model.VendorCd).Select(x => x.Key).ToList(); var ZoMask = group?.TTechnicianGroupClaims? .Select(x => x.TTechnicianGroup.Responsible_Zo) .ToList(); var ZoMaskFinal = new List <string>(); ZoMask.ForEach(x => { bool hasMultiple = x.Contains(','); if (hasMultiple) { string[] ary = x.Split(','); ary.ForEach(y => ZoMaskFinal.Add(y)); } else { ZoMaskFinal.Add(x); } }); var DoMask = group?.TTechnicianGroupClaims? .Select(x => x.TTechnicianGroup.Responsible_Do) .ToList(); var DoMaskFinal = new List <string>(); DoMask.ForEach(x => { bool hasMultiple = x.Contains(','); if (hasMultiple) { string[] ary = x.Split(','); ary.ForEach(y => DoMaskFinal.Add(y)); } else { DoMaskFinal.Add(x); } }); #endregion return(View("Edit", new TechnicianGroupEditViewModel() { Seq = model.Seq, CompCd = model.CompCd, VendorCd = model.VendorCd, GroupName = group.GroupName, ActionType = AuthNodeType.Read, AccountDualBoxList = technicians?.Select(x => { return new SelectListItem() { Value = x.Account, Text = x.Name, Selected = (mask.Contains(x.Account)) }; }), VenderZoDualBoxList = Zo?.Where(y => y.DoCd == "" && y.CloseDate == "9999/12/31" && tvndzo.Contains(y.ZoCd)).Select(x => { return new SelectListItem() { Text = x.ZoName, Value = x.ZoCd, Selected = (ZoMaskFinal.Contains(x.ZoCd)) }; }), DoDualBoxList = Zo?.Where(y => y.DoCd != "" && y.CloseDate == "9999/12/31" && y.UpkeepSts == "Y" && ZoMaskFinal.Contains(y.ZoCd)).Select(x => { return new SelectListItem() { Text = x.DoName, Value = x.DoCd, Selected = (DoMaskFinal.Contains(x.DoCd)) }; }) })); } catch (Exception ex) { _logger.Error(ex.Message); if (ex.InnerException != null) { _logger.Error(ex.InnerException.Message); if (ex.InnerException.InnerException != null) { _logger.Error(ex.InnerException.InnerException.Message); } } return(View()); } }
/// <summary> /// 合并所选择的技師 /// </summary> /// <param name="technicians"></param> /// <param name="groups"></param> /// <returns></returns> public List <TvenderTechnician> MergeTechnician(IEnumerable <TvenderTechnician> technicians, IEnumerable <TtechnicianGroup> groups) { _logger.Info($"APP_合併技師/群組,產生推播對象"); HashSet <TvenderTechnician> result = new HashSet <TvenderTechnician>(); #region 瀏覽群組 groups?.ForEach(group => { _logger.Info($"APP_合併技師/群組,產生推播對象-瀏覽群組:{group.Seq}"); var con = new Conditions <DataBase.TTechnicianGroup>(); con.And(x => x.CompCd == group.CompCd && x.VendorCd == group.VendorCd && x.Seq == group.Seq); con.Include(x => x.TTechnicianGroupClaims.Select(y => y.TVenderTechnician)); var currGroup = _technicianGroupRepo.Get(con); if (currGroup == null) { throw new NullReferenceException($"合并技師數據時,找不到群組信息"); } //找到群組下的技師,放入hashSet currGroup.TTechnicianGroupClaims.ForEach(claims => { //群組下的技師,要找到已經通過總部審核並啟用的 if (claims.TVenderTechnician.Enable) { if (!result.Any(x => x.Account == claims.Account)) { result.Add(claims.TVenderTechnician); } } }); }); #endregion #region 瀏覽技師 technicians?.ForEach(technician => { _logger.Info($"APP_合併技師/群組,產生推播對象-瀏覽技師:{technician.Account}"); var con = new Conditions <DataBase.TVenderTechnician>(); con.And(x => x.Comp_Cd == technician.CompCd && x.Vender_Cd == technician.VenderCd && x.Account == technician.Account); var currTechnician = _technicianRepo.Get(con); if (currTechnician == null) { throw new NullReferenceException($"合并技師數據時,找不到技師信息"); } //技師要已經通過總部審核並啟用的 if (currTechnician.Enable) { if (!result.Any(x => x.Account == currTechnician.Account)) { result.Add(currTechnician); } } }); #endregion return(result.ToList()); }
public ActionResult TechnicianNotifyForChange(string Technician, string Sn) { try { if (Technician == null) { throw new Exception("未選擇推播技師"); } if (Sn == string.Empty) { throw new Exception("未選擇案件"); } string[] CallogSn = Sn.Split(','); var _user = ((PtcIdentity)this.User.Identity).currentUser; List <string> NotifySn = new List <string>(); //Sn //Dictionary<string, string> Account = new Dictionary<string, string>(); //key:技師帳號、value:技師RegId Dictionary <string, string> OldAccount = new Dictionary <string, string>(); //key:技師帳號、value:技師RegId TvenderTechnician Techniciandata = new TvenderTechnician(); #region 驗證技師資料 Conditions <DataBase.TVenderTechnician> conTechnician = new Conditions <DataBase.TVenderTechnician>(); _logger.Info($"廠商:{_user.VenderCd},開始驗證技師資料,被驗證的技師有{Technician}"); conTechnician.And(x => x.Comp_Cd == _user.CompCd); //公司別 conTechnician.And(x => x.Vender_Cd == _user.VenderCd); //廠商 conTechnician.And(x => x.Enable == true); //啟用 conTechnician.And(x => x.Account == Technician); //廠商帳號 TvenderTechnician TvenderTechniciandata = _TvenderTechnicianRepo.Get(conTechnician); if (TvenderTechniciandata == null) { _logger.Info($"查無技師資料:{Technician}"); throw new Exception("勾選的技師驗證後無資料"); } else { _logger.Info($"加入推播,帳號:{Technician}"); //Account.Add(itemTechnician, data.RegistrationID); Techniciandata = TvenderTechniciandata; } #endregion #region 檢查叫修編號狀態 Conditions <DataBase.TCALLOG> conCallog = new Conditions <DataBase.TCALLOG>(); Conditions <DataBase.TVenderTechnician> conTechniciang = new Conditions <DataBase.TVenderTechnician>(); foreach (string itemSn in CallogSn) { _logger.Info($"廠商:{_user.VenderCd},開始驗證案件資料,被驗證的案件有{itemSn}"); conCallog.And(x => x.Comp_Cd == _user.CompCd); conCallog.And(x => x.Sn == itemSn); conCallog.And(x => x.TAcceptedLog.Sn != null); conCallog.Include(x => x.TAcceptedLog); Tcallog data = _tcallogRepo.Get(conCallog); if (data == null) { _logger.Info($"查無案件資料:{itemSn}"); } else if (data.CloseSts > (byte)CloseSts.process) { _logger.Info($"案件:{itemSn},已經銷案。"); } else { conTechniciang.And(x => x.Account == data.TacceptedLog.Account); conTechniciang.And(x => x.Comp_Cd == data.CompCd); conTechniciang.And(x => x.Vender_Cd == data.VenderCd); var Techniciang = _TvenderTechnicianRepo.Get(conTechniciang); _logger.Info($"加入推播,案件:{itemSn}"); //判斷若該案件的舊技師為新技師就不寫入NotifySn if (TvenderTechniciandata.Account != data.TacceptedLog.Account) { NotifySn.Add(itemSn); if (!OldAccount.Keys.Contains(data.TacceptedLog.Account)) { OldAccount.Add(data.TacceptedLog.Account, Techniciang.RegistrationID); } } } conCallog = new Conditions <DataBase.TCALLOG>(); conTechniciang = new Conditions <DataBase.TVenderTechnician>(); } #endregion if (NotifySn.Count == 0) { throw new Exception("勾選的案件驗證後無資料,請重新整理"); } #region 更新案件技師資訊+推播 var isSuccess = _callogService.ChangeNotificationForWeb(_user, NotifySn, Techniciandata, OldAccount); #endregion return(Json(new JsonResult() { Data = new { IsSuccess = isSuccess, Message = $"改派案件:{(isSuccess ? "成功" : "失敗")}" } })); } catch (Exception ex) { _logger.Error(ex.Message); if (ex.InnerException != null) { _logger.Error(ex.InnerException.Message); if (ex.InnerException.InnerException != null) { _logger.Error(ex.InnerException.InnerException.Message); } } return(Json(new JsonResult() { Data = new { IsSuccess = false, Message = $"改派案件失敗,原因:{ex.Message}" } })); } }
public ActionResult ModifyMemberAuth(MemberSetViewModel model) { Boolean isSuccess = false; try { var compcd = model?.Compcd ?? model.Compcd; var user = new UserBase() { CompCd = compcd, UserId = model.UserID, RoleAuth = new RoleAuth() { RoleName = model.RoleName }, PageAuth = (model?.PageAuth == null ? new List <AuthItem>() : model.PageAuth.Select(x => new AuthItem() { GroupName = x.id, AuthType = x.AuthType }) .ToList()), }; var con = new Conditions <DataBase.TSYSROL>(); con.And(x => x.Comp_Cd == compcd && x.Role_Id == model.RoleName); var roleAuth = _tsysrolRepo.Get(con); if (roleAuth == null) { throw new Exception("[ERROR]=>該腳色未設定權限"); } var role = new RoleAuth() { CompCd = compcd, RoleId = model.RoleName, UpdateTime = DateTime.Now, PageAuth = roleAuth.PageAuth }; isSuccess = _aspUserService.Update(user, role); return(Json(new JsonResult() { Data = new { IsSuccess = true, Message = $"修改帳號資料:{(isSuccess ? "成功" : "失敗")}" } })); } catch (Exception ex) { _logger.Error(ex.Message); return(Json(new JsonResult() { Data = new { IsSuccess = false, Message = $"修改帳號資料失敗,原因:{ex.Message}" } })); } }
public ActionResult Getcallog(DataTablesReqModel <List <ChangeAssignedViewModel> > data) { var _user = ((PtcIdentity)this.User.Identity).currentUser; if (_user.CompCd == "") { _user.CompCd = "711"; } DataTablesRespModel result = new DataTablesRespModel(data.draw); try { #region 取得所有區域 Conditions <DataBase.TZOCODE> conZo = new Conditions <DataBase.TZOCODE>(); conZo.And(x => x.Comp_Cd == _user.CompCd); //公司別 var Zo = _TzocodeRepo.GetList(conZo).ToList(); #endregion #region 取得未完修案件 Conditions <DataBase.VW_MobileCallogNoFinish> conCallog = new Conditions <DataBase.VW_MobileCallogNoFinish>(); conCallog.And(x => x.Comp_Cd == _user.CompCd); //公司別 conCallog.And(x => x.Vender_Cd == _user.VenderCd); //廠商 conCallog.And(x => x.Close_Sts == (byte)CloseSts.process); //剛立案 conCallog.And(x => x.TimePoint >= (byte)TimePoint.Accepted); //timepoint>=2 conCallog.And(x => x.TimePoint < (byte)TimePoint.Finish); //timepoint<4 data.order?.ForEach(x => { if (data.columns[x.column].name == "Zo_Name") { conCallog.Order(x.dir, "Z_O"); } else if (data.columns[x.column].name == "Do_Name") { conCallog.Order(x.dir, "D_O"); } else { conCallog.Order(x.dir, data.columns[x.column].name); } }); var Data = _VWMobileCallogNoFinishRepo.GetList(conCallog); #endregion int PageIndex = (data.start / data.length); PagedList <MobileCallogSearch> meta = new PagedList <MobileCallogSearch>(Data, PageIndex, data.length); result.data = meta.Select(x => new ChangeAssignedViewModel(x, Zo.Where(y => y.ZoCd == x.Zo && y.DoCd == "").Select(z => z.ZoName).FirstOrDefault(), Zo.Where(y => y.ZoCd == x.Zo && y.DoCd == x.Do).Select(z => z.DoName).FirstOrDefault()).colData).ToArray(); result.TotalCount(conCallog.TotalCount); } catch (Exception ex) { _logger.Error(ex); if (ex.InnerException != null) { _logger.Error(ex.InnerException.Message); if (ex.InnerException.InnerException != null) { _logger.Error(ex.InnerException.InnerException.Message); } } result.error = ex.Message; } return(Json(result)); }
public ActionResult GetList(DataTablesReqModel <List <TassetsViewModel> > data) { List <TassetsViewModel> models = data.criteria; DataTablesRespModel result = new DataTablesRespModel(data.draw); try { Conditions <DataBase.TASSETS> con = new Conditions <DataBase.TASSETS> (data.length, (data.start / data.length)); models?.ForEach(model => { var component = new List <Expression <Func <DataBase.TASSETS, Boolean> > >(); model.GetProperties()? .Select(x => x.Avatar <AvatarAttribute>(model)) .Where(x => x.Key != null) .ForEach(g => { component.Add(con.CombinationExpression( g.Key.SubstituteName, g.Key.ExpressionType, g.Value)); }); con.ConvertToMultiFilter(component); }); data.order?.ForEach(x => { con.Order(x.dir, data.columns[x.column].name); }); #region DataRange var _user = (this.User.Identity as AspnetMvc.Models.PtcIdentity).currentUser; con.And(x => x.Comp_Cd == _user.CompCd); #endregion PagedList <Tassets> meta = new PagedList <Tassets>(_baseRepo.GetList(con), (data.start / data.length), data.length); result.data = meta.Select(x => new TassetsResultViewModel(x).colData) .ToArray(); result.TotalCount(meta.TotalCount); } catch (AutoMapper.AutoMapperMappingException ex) { _logger.Error(ex); result.error = ex.InnerException.Message; } catch (Exception ex) { _logger.Error(ex); result.error = ex.Message; } return(Json(result)); }
public override void OnAuthorization(HttpActionContext actionContext) { // var token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvY2xhaW1zL3VzZXJkYXRhIjoie1xyXG4gIFwiJGlkXCI6IFwiMVwiLFxyXG4gIFwiQ29tcENkXCI6IG51bGwsXHJcbiAgXCJDb21wU2hvcnRcIjogbnVsbCxcclxuICBcIlVzZXJJZFwiOiBcIkFtb25cIixcclxuICBcIlVzZXJOYW1lXCI6IG51bGwsXHJcbiAgXCJOaWNrbmFtZVwiOiBudWxsLFxyXG4gIFwiUm9sZUlkXCI6IG51bGwsXHJcbiAgXCJab0NkXCI6IG51bGwsXHJcbiAgXCJWZW5kZXJDZFwiOiBudWxsLFxyXG4gIFwiVmVuZGVyTmFtZVwiOiBudWxsLFxyXG4gIFwiU3RvcmVDZFwiOiBudWxsLFxyXG4gIFwiU3RvcmVOYW1lXCI6IG51bGwsXHJcbiAgXCJFbWFpbFwiOiBudWxsLFxyXG4gIFwiUGFzc3dvcmRcIjogXCIxMjg3NjI2NlwiLFxyXG4gIFwiVGVsTm9cIjogbnVsbCxcclxuICBcIkZheE5vXCI6IG51bGwsXHJcbiAgXCJNb2JpbGVUZWxcIjogbnVsbCxcclxuICBcIklkU3RzXCI6IGZhbHNlLFxyXG4gIFwiQ3JlYXRlX1VzZXJcIjogbnVsbCxcclxuICBcIkNyZWF0ZV9EYXRlXCI6IFwiMDAwMS0wMS0wMVQwMDowMDowMFwiLFxyXG4gIFwiVXBkYXRlX1VzZXJcIjogbnVsbCxcclxuICBcIlVwZGF0ZV9EYXRlXCI6IG51bGwsXHJcbiAgXCJUb2tlblwiOiBudWxsLFxyXG4gIFwiRGV2aWNlSURcIjogXCJub25lXCIsXHJcbiAgXCJSZWdpc3RyYXRpb25JRFwiOiBudWxsLFxyXG4gIFwiUGFnZUF1dGhcIjogbnVsbCxcclxuICBcIlJvbGVBdXRoXCI6IG51bGwsXHJcbiAgXCJVc2VyUGFnZUF1dGhcIjoge30sXHJcbiAgXCJEYXRhUmFuZ2VcIjogbnVsbFxyXG59IiwibmJmIjoxNDk2MjQzNTI5LCJleHAiOjE1Mjc3Nzk1MjksImlhdCI6MTQ5NjI0MzUyOSwiaXNzIjoic2VsZiIsImF1ZCI6Imh0dHBzOi8vd3d3Lm15d2Vic2l0ZS5jb20ifQ.1ykpD48w49nVa2zcZnMh-edk-eYHckL1m33miY0Sp24"; var token = HttpUtility.ParseQueryString(actionContext.Request.RequestUri.Query).Get("token"); if (token == null) { actionContext.Response = new System.Net.Http.HttpResponseMessage(System.Net.HttpStatusCode.Forbidden); } else { var tokenHandler = new JwtSecurityTokenHandler(); var securityKey = GetBytes("anyoldrandomtext"); var validationParameters = new TokenValidationParameters() { ValidAudience = "https://www.mywebsite.com", ValidateLifetime = true, IssuerSigningKeys = new List <SecurityKey> { new SymmetricSecurityKey(securityKey) }, ValidAudiences = new List <string> { "https://www.mywebsite.com" }, ValidIssuer = "self" }; try { SecurityToken securityToken; var principal = tokenHandler.ValidateToken(token, validationParameters, out securityToken); var userData = principal.Claims.FirstOrDefault(); if (userData != null) { //解析token var input = JsonConvert.DeserializeObject <UserBase>(userData.Value); var con = new Conditions <DataBase.TUSRMST>(); var password = Identity.ClearPassword.GetMd5Hash(input.Password.ToUpper()).ToUpper(); con.And(x => x.User_Id == input.UserId && x.TUSRDTL.Pass_Wd == password); con.Include(x => x.TUSRDTL); Tusrmst user = _usermstRepo.Get(con); //查无使用者 if (user == null) { throw new Exception($"no find user info"); } //使用者未審核通過 if (!user.IdSts) { throw new Exception($"user info is not IdSts"); } // 裝置不同 if (user.DeviceID != input.DeviceID) { throw new Exception($"different device"); } // 密碼修改 if (user.TUSRDTL.PassWd != password) { throw new Exception($"Password is changed"); } var identity = new AspnetMvc.Models.PtcIdentity( System.Threading.Thread.CurrentPrincipal.Identity, new UserBase() { CompCd = user.CompCd, //公司代號 RoleId = user.RoleId, //角色 UserName = user.UserName, //使用者姓名 UserId = user.UserId, //使用者帳號 Password = input.Password, //使用者密碼 }, "phone", null); SetPrincipal(new GenericPrincipal(identity, null)); } else { HandleUnauthorizedRequest(actionContext); } } catch (Exception) { HandleUnauthorizedRequest(actionContext); } } //base.OnAuthorization(actionContext); }
/// <summary> /// 更新群組信息 /// </summary> /// <param name="Data"></param> /// <param name="Accounts"></param> /// <returns></returns> public Boolean UpdateTechnicianGroup(TtechnicianGroup Data, String[] Accounts) { //_logger.Info($"更新群組-群組名稱:{Data.GroupName}"); #region 檢核群組信息是否存在 var con = new Conditions <DataBase.TTechnicianGroup>(); con.And(x => x.Seq == Data.Seq && x.CompCd == Data.CompCd && x.VendorCd == Data.VendorCd); con.Allow(x => x.GroupName); con.Allow(x => x.Responsible_Do); con.Allow(x => x.Responsible_Zo); var group = _technicianGroupRepo.Get(con); if (group == null) { throw new IndexOutOfRangeException("[ERROR]=>修改群組數據時,檢核没有該群組數據存在"); } var groupname = group.GroupName; #endregion #region 檢核群組信息是否重复 var query = new Conditions <DataBase.TTechnicianGroup>(); query.And(x => x.CompCd == Data.CompCd && x.VendorCd == Data.VendorCd && x.GroupName == Data.GroupName); var count = _technicianGroupRepo.GetList(query).Count(); if (count > 1) { throw new IndexOutOfRangeException("[ERROR]=>修改群組數據時,檢核已經有該群組存在"); } else { var gp = _technicianGroupRepo.Get(query); var groupseq = 0; if (gp != null) { groupseq = gp.Seq; } if (count == 1 && groupseq != Data.Seq) { throw new IndexOutOfRangeException("[ERROR]=>修改群組數據時,檢核已經有該群組存在"); } } #endregion using (TransactionScope scope = new TransactionScope()) { _logger.Info($"更新群組-準備更新資料"); #region 修改群組 _technicianGroupRepo.Update(con, Data); #endregion #region 修改技師至群組 var cond = new Conditions <DataBase.TTechnicianGroupClaims>(); cond.And(x => x.Seq == Data.Seq && x.CompCd == Data.CompCd && x.VendorCd == Data.VendorCd); if (_technicianGroupClaimsRepo.GetList(cond).Any()) { _technicianGroupClaimsRepo.Remove(cond); } if (Accounts != null) { foreach (String account in Accounts) { TtechnicianGroupClaims technicianGroupClaims = new TtechnicianGroupClaims() { Seq = Data.Seq, CompCd = Data.CompCd, VendorCd = Data.VendorCd, Account = account }; var condition = new Conditions <DataBase.TTechnicianGroupClaims>(); condition.And(x => x.Seq == Data.Seq && x.CompCd == Data.CompCd && x.VendorCd == Data.VendorCd && x.Account == account); if (!_technicianGroupClaimsRepo.Add(condition, technicianGroupClaims)) { throw new Exception("[ERROR]=>修改技師至群組時,新增失敗"); } } } #endregion scope.Complete(); } return(true); }
/// <summary> /// 自動通知技師: /// 通常在立案當下呼叫的 /// </summary> /// <param name="Comp_Cd"></param> /// <param name="Sn"></param> /// <returns></returns> public Boolean AutoNotification(string Comp_Cd, string Sn) { _logger.Info($"立案自動通知-公司別:{Comp_Cd},案件編號:{Sn}"); #region 驗證與取得資訊 //取得案件 Tcallog callog = base.GetCallog(Comp_Cd, Sn); //取得廠商及底下的技師群組 var venderCon = new Conditions <DataBase.TVENDER>(); venderCon.And(x => x.Comp_Cd == callog.CompCd && x.Vender_Cd == callog.VenderCd); _logger.Info($"立案自動通知-公司別:{callog.CompCd}"); _logger.Info($"立案自動通知-廠商別:{callog.VenderCd}"); venderCon.Include(x => x.TTechnicianGroup .Select(g => g.TTechnicianGroupClaims .Select(y => y.TVenderTechnician))); Tvender vender = _venderRepo.Get(venderCon); if (vender == null) { _logger.Error($"查無廠商-廠商別:{callog.VenderCd}"); throw new Exception($"查無廠商"); } #endregion //找到可以被自動推播的群組 IEnumerable <TtechnicianGroup> groups = vender.TTechnicianGroup; List <TtechnicianGroup> techGroup = new List <TtechnicianGroup>(); techGroup.AddRange(groups.Where(x => x.Responsible_Do.Contains(callog.Do)).ToList()); if (groups.Where(x => x.Responsible_Do.Contains(callog.Do)).Count() == 0) { //沒有對應的課群組才撈區群組 techGroup.AddRange(groups.Where(x => x.Responsible_Zo.Contains(callog.Zo)).ToList()); } techGroup = techGroup.Distinct().ToList(); //取出群組內技師並過濾 Dictionary <string, string> accounts = new Dictionary <string, string>(); //確認廠商是否有建立技師 var venderTech = new Conditions <DataBase.TVenderTechnician>(); venderTech.And(x => x.Comp_Cd == callog.CompCd && x.Vender_Cd == callog.VenderCd); var technicians = _technicianRepo.GetList(venderTech); //有建立技師,沒有建立群組則自動建立進行推播 if (technicians.Count != 0 && groups.ToList().Count == 0) { _logger.Error($"查無群組自動建立-廠商別:{callog.VenderCd}"); //取得廠商所負責的區域 var venderZO = new Conditions <DataBase.TVNDZO>(); venderZO.And(x => x.Comp_Cd == callog.CompCd && x.Vender_Cd == callog.VenderCd); var vndzos = _vndzoRepo.GetList(venderZO); string ZO = ""; string DO = ""; vndzos?.ForEach(vndzo => { ZO += "," + vndzo.Zo; //取得各區對應的課別 var ZOCODE = new Conditions <DataBase.TZOCODE>(); ZOCODE.And(x => x.Comp_Cd == vndzo.CompCd && x.Z_O == vndzo.Zo && x.Upkeep_Sts == "Y"); var zocodes = _zocodeRepo.GetList(ZOCODE); zocodes?.ForEach(zocode => { DO += "," + zocode.DoCd; }); }); //新增群組 var con = new Conditions <DataBase.TTechnicianGroup>(); con.And(x => x.CompCd == callog.CompCd); con.And(x => x.VendorCd == callog.VenderCd); TtechnicianGroup TGroup = new TtechnicianGroup(); TGroup.CompCd = callog.CompCd; TGroup.VendorCd = callog.VenderCd; TGroup.GroupName = "系統產生"; TGroup.Responsible_Zo = ZO.Substring(1); TGroup.Responsible_Do = DO.Substring(1); if (!_technicianGroupRepo.Add(con, TGroup)) { throw new Exception("[ERROR]=>自動新增群組時,新增失敗"); } else { //重新取得群組 vender = _venderRepo.Get(venderCon); TtechnicianGroup group = vender.TTechnicianGroup.SingleOrDefault(); _logger.Info($"自動新增技師群組對應主檔開始"); var Claimscon = new Conditions <DataBase.TTechnicianGroupClaims>(); TtechnicianGroupClaims TClaims = new TtechnicianGroupClaims(); TClaims.Seq = group.Seq; TClaims.CompCd = callog.CompCd; TClaims.VendorCd = callog.VenderCd; //新增技師群組對應主檔 technicians?.ForEach(technician => { Claimscon.And(x => x.Seq == group.Seq); Claimscon.And(x => x.CompCd == group.CompCd); Claimscon.And(x => x.VendorCd == group.VendorCd); Claimscon.And(x => x.Account == technician.Account); TClaims.Account = technician.Account; try { _technicianGroupClaimsRepo.Add(Claimscon, TClaims); } catch (Exception) { _logger.Error($"自動新增技師群組對應主檔時新增失敗-公司別:{callog.CompCd},廠商別:{callog.VenderCd},技師帳號:{technician.Account}"); } Claimscon = new Conditions <DataBase.TTechnicianGroupClaims>(); }); _logger.Info($"自動新增技師群組對應主檔結束"); technicians?.ForEach(claim => { var current = claim; _logger.Info($"立案自動通知-組合物件-尋覽技師名稱:{current.Account}"); //啟用 if (current.Enable) { try { if (!accounts.Keys.Contains(current.Account)) { accounts.Add(current.Account, current.RegistrationID); } } catch (Exception ex) { _logger.Error($"立案自動通知-技師帳號:{current.Account},放入推播清單錯誤,原因:{ex.Message}"); } } }); } } else { techGroup?.ForEach(group => { _logger.Info($"立案自動通知-組合物件-尋覽群組代號:{group.Seq}"); group.TTechnicianGroupClaims?.ForEach(claim => { var current = claim.TVenderTechnician; _logger.Info($"立案自動通知-組合物件-尋覽技師名稱:{current.Account}"); //啟用 if (current.Enable) { try { if (!accounts.Keys.Contains(current.Account)) { accounts.Add(current.Account, current.RegistrationID); } } catch (Exception ex) { _logger.Error($"立案自動通知-技師帳號:{current.Account},放入推播清單錯誤,原因:{ex.Message}"); } } }); }); } //更新TCALLOG.TimePoint //var callogcon = new Conditions<DataBase.TCALLOG>(); //callogcon.And(x => x.Comp_Cd == callog.CompCd); //callogcon.And(x => x.Sn == callog.Sn); //callogcon.Allow(x => x.TimePoint); //if (!_callogRepo.Update(callogcon, new Tcallog() //{ // TimePoint = 1 //})) // throw new Exception("更新TCALLOG.TimePoint失敗"); if (callog.TacceptedLog == null) { //準備通知-寫入待認養 accounts.ForEach(account => { try { _logger.Info($"準備通知-寫入待認養 帳號:{account.Key}"); #region 更新資料 _technicianProvider.AddAwaitAcceptLog(callog.CompCd, callog.Sn, account.Key); #endregion } catch (Exception ex) { _logger.Error($"準備通知-寫入待認養 帳號:{account},通知發生錯誤,原因:{ex.Message}"); if (ex.InnerException != null) { _logger.Error(ex.InnerException.Message); if (ex.InnerException.InnerException != null) { _logger.Error(ex.InnerException.InnerException.Message); } } _logger.Error(ex.StackTrace); } }); //準備推播 accounts.ForEach(account => { try { _logger.Info($"準備推播 帳號:{account.Key}"); string storeName = getStoreName(callog.CompCd, callog.StoreCd); string CallLevel = callog.CallLevel == "1" ? "普通" : "緊急"; #region 推播訊息 _notifyFactory.Exucte(new JPushRequest( callog.CompCd, callog.VenderCd) { Sn = callog.Sn, Content = $"您有一筆新案件待認養,案件編號:{callog.Sn} 店名:{storeName} 叫修等級:{CallLevel}", Title = "認養案件", Extras = new Dictionary <string, string>() { { "FeatureName", "VenderAccept" } } }, account.Key, account.Value); #endregion } catch (Exception ex) { _logger.Error($"準備推播 帳號:{account},通知發生錯誤,原因:{ex.Message}"); if (ex.InnerException != null) { _logger.Error(ex.InnerException.Message); if (ex.InnerException.InnerException != null) { _logger.Error(ex.InnerException.InnerException.Message); } } _logger.Error(ex.StackTrace); } }); } return(true); }
public ActionResult GroupNotify(string Groupseq, string Sn) { try { if (Groupseq == string.Empty) { throw new Exception("未選擇群組"); } if (Sn == string.Empty) { throw new Exception("未選擇案件"); } string[] CallogSn = Sn.Split(','); var _user = ((PtcIdentity)this.User.Identity).currentUser; if (_user.CompCd == "") { _user.CompCd = "711"; } List <string> NotifySn = new List <string>(); //Sn Dictionary <string, string> Account = new Dictionary <string, string>(); //key:技師帳號、value:技師RegId #region 檢查叫修編號狀態 Conditions <DataBase.TCALLOG> conCallog = new Conditions <DataBase.TCALLOG>(); foreach (string itemSn in CallogSn) { _logger.Info($"廠商:{_user.VenderCd},開始驗證案件資料,被驗證的案件有{itemSn}"); conCallog.And(x => x.Comp_Cd == _user.CompCd); conCallog.And(x => x.Sn == itemSn); conCallog.And(x => x.TAcceptedLog.Sn == null); Tcallog data = _tcallogRepo.Get(conCallog); if (data == null) { _logger.Info($"查無案件資料:{itemSn}(可能已經被認養)"); } else if (data.CloseSts > (byte)CloseSts.process) { _logger.Info($"案件:{itemSn},已經銷案。"); } else { _logger.Info($"加入推播,案件:{itemSn}"); NotifySn.Add(itemSn); } conCallog = new Conditions <DataBase.TCALLOG>(); } #endregion #region 群組取出技師資料 _logger.Info($"廠商:{_user.VenderCd},開始群組取出技師資料,群組ID:{Groupseq}"); int seq = Convert.ToInt32(Groupseq); Conditions <DataBase.TTechnicianGroupClaims> conGroupClaims = new Conditions <DataBase.TTechnicianGroupClaims>(); conGroupClaims.And(x => x.CompCd == _user.CompCd); conGroupClaims.And(x => x.VendorCd == _user.VenderCd); conGroupClaims.And(x => x.Seq == seq); conGroupClaims.Include(x => x.TVenderTechnician); var TechnicianList = _TtechnicianGroupClaimsRepo.GetList(conGroupClaims); TechnicianList.ForEach(account => { _logger.Info($"加入推播,帳號:{account.Account}"); Account.Add(account.Account, account.TVenderTechnician.RegistrationID); }); #endregion if (Account.Count == 0) { throw new Exception("群組裡無技師"); } if (NotifySn.Count == 0) { throw new Exception("勾選的案件驗證後無資料,請重新整理"); } #region 更新待受理案件+推播 var isSuccess = _callogService.NotificationForWeb(_user, NotifySn, Account); #endregion return(Json(new JsonResult() { Data = new { IsSuccess = isSuccess, Message = $"推播通知:{(isSuccess ? "成功" : "失敗")}" } })); } catch (Exception ex) { _logger.Error(ex.Message); if (ex.InnerException != null) { _logger.Error(ex.InnerException.Message); if (ex.InnerException.InnerException != null) { _logger.Error(ex.InnerException.InnerException.Message); } } return(Json(new JsonResult() { Data = new { IsSuccess = false, Message = $"推播通知失敗,原因:{ex.Message}" } })); } }