/// <summary> /// 取得案件資訊 /// </summary> /// <param name="Sn"></param> /// <returns></returns> public virtual Tcallog GetCallog(string Comp_Cd, string Sn) { if (String.IsNullOrEmpty(Comp_Cd)) { throw new ArgumentNullException($"[ERROR]=>取得案件資訊時,並沒有給入公司代號"); } if (String.IsNullOrEmpty(Sn)) { throw new ArgumentNullException($"[ERROR]=>取得案件資訊時,並沒有給入案件資代號"); } var con = new Conditions <DataBase.TCALLOG>(); con.Include(x => x.TAcceptedLog); con.And(x => x.Comp_Cd == Comp_Cd); con.And(x => x.Sn == Sn); Tcallog data = _callogRepo.Get(con); if (data == null) { throw new NullReferenceException($"[ERROR]=>找不到對應的案件資資訊,案件編號:{Sn}"); } return(data); }
/// <summary> /// 取得案件的待受理技師 /// </summary> public Dictionary <string, string> GetAwaitAdoptTechnician(Tcallog data) { Dictionary <string, string> resault = new Dictionary <string, string>(); DataBase.SETENG_Entities db = new DataBase.SETENG_Entities(); var table = db.TTechnicianGroup.Where(x => x.CompCd == data.CompCd && x.VendorCd == data.VenderCd).ToList(); if (table.Count == 0) { return(new Dictionary <string, string>()); } else { table.ForEach(x => { var GroupClaims = db.TTechnicianGroupClaims.Where(y => y.Seq == x.Seq).Select(z => z.Account).ToList(); GroupClaims.ForEach(g => { var Technician = db.TVenderTechnician.Where(q => q.Comp_Cd == data.CompCd && q.Vender_Cd == data.VenderCd && q.Account == g).FirstOrDefault(); if (!resault.Keys.Contains(g)) { resault.Add(g, Technician.RegistrationID); } }); }); return(resault); } }
/// <summary> /// 催修通知 /// </summary> /// <param name="data"></param> /// <returns></returns> public Boolean PushUrg(Tcallog data) { var StoreName = _ImgRepo.GetStoreName(data.CompCd, data.StoreCd); if (data.TimePoint == 1) { Dictionary <string, string> Technician = _ImgRepo.GetAwaitAdoptTechnician(data); Technician.ForEach(x => { _notifyFactory.Exucte(new JPushRequest( data.CompCd, data.VenderCd) { Sn = data.Sn, Content = $"{StoreName}門市,案件:{data.Sn} 已催修,請儘速處理。", Title = "催修案件", Extras = new Dictionary <string, string>() { { "FeatureName", "VenderAccept" } } }, x.Key, x.Value); }); } else if (data.TimePoint >= 2 && data.TimePoint < 4) { Dictionary <string, string> Technician = _ImgRepo.GetAcceptTechnician(data.CompCd, data.Sn); #region 推播訊息 Technician.ForEach(x => { _notifyFactory.Exucte(new JPushRequest( data.CompCd, data.VenderCd) { Sn = data.Sn, Content = $"{StoreName}門市,案件:{data.Sn} 已催修,請儘速處理。", Title = "催修案件", Extras = new Dictionary <string, string>() { { "FeatureName", "VenderConfirm" } } }, x.Key, x.Value); }); #endregion } else { throw new Exception($"案件:{data.Sn},狀態(TimePoint):{data.TimePoint},不符,因此不推播"); } return(true); }
/// <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); }
/// <summary> /// 廠商改派案件 /// </summary> /// <param name="log">畫面上選擇的案件</param> /// <param name="account">廠商選擇的技師帳號</param> /// <returns></returns> public Boolean VendorChangeLog(Tcallog log, string account, string username) { _logger.Info($"案件改派-公司別:{log.CompCd},案件編號:{log.Sn}"); #region 驗證與取得資訊 //取得案件 Tcallog callog = base.GetCallog(log.CompCd, log.Sn); //取得原來的受理技師帳號,並記錄 if (callog.TacceptedLog == null) { throw new NullReferenceException($"此案件未被認養,因此無法改派"); } //如果已經銷案不允許再指通知了 if (callog.CloseSts > (byte)CloseSts.process) { throw new IndexOutOfRangeException($"此案件已銷案"); } string oldAccount = callog.TacceptedLog.Account; //取得公司 Tcmpdat comp = base.GetComp(log.CompCd); //取得技師 TvenderTechnician technician = base.GetTechnician(log.CompCd, account); _logger.Info($"案件改派-公司別:{callog.CompCd}"); _logger.Info($"案件改派-廠商別:{callog.VenderCd}"); _logger.Info($"案件改派-要被改派的技師代號:{technician.Account}"); _logger.Info($"案件改派-既有的技師代號:{oldAccount}"); #endregion #region 組合物件 DateTime now = DateTime.Now; TacceptedLog tacceptedLog = new TacceptedLog() { Account = technician.Account, Sn = callog.Sn, RcvDatetime = DateTime.Now, RcvRemark = "no defind", Name = technician.Name, }; callog.TacceptedLog = tacceptedLog; #endregion #region 廠商改派 _logger.Info($"案件改派-準備更新資料"); if (!_callogFactory.TechnicianAccept(callog)) { throw new Exception("[ERROR]=>廠商改派案件,改派失敗"); } #endregion #region 推播訊息 _logger.Info($"案件改派-準備通知給帳號:{account}"); string storeName = getStoreName(callog.CompCd, callog.StoreCd); string CallLevel = callog.CallLevel == "1" ? "普通" : "緊急"; _notifyFactory.Exucte(new JPushRequest( callog.CompCd, callog.VenderCd, account) { Sn = callog.Sn, Content = $"您有一筆新案件待銷案,案件編號:{callog.Sn} 店名:{storeName} 叫修等級:{CallLevel}", Title = "廠商改派", Extras = new Dictionary <string, string>() { { "FeatureName", "VenderConfirm" } } }); _logger.Info($"案件改派-準備通知給帳號:{oldAccount}"); _notifyFactory.Exucte(new JPushRequest( callog.CompCd, callog.VenderCd, oldAccount) { Sn = callog.Sn, Content = $"您的案件已經指派給:{ technician.Name},案件編號:{callog.Sn} 店名:{storeName} 叫修等級:{CallLevel}", Title = "廠商改派", Extras = new Dictionary <string, string>() { { "FeatureName", "" } } }); var Con = new Conditions <DataBase.TCallogCourse>(); TCallogCourse course = new TCallogCourse() { CompCd = log.CompCd, Sn = log.Sn, Assignor = username, Admissibility = technician.Name, Datetime = now }; //新增案件歷程 _CallogCourseRepo.Insert(Con, course); #endregion return(true); }
/// <summary> /// 技師認養案件/廠商指派案件 /// </summary> /// <param name="log">畫面上選擇的案件</param> /// <param name="account">登入的技師/廠商選取的技師</param> /// <returns></returns> public Boolean TechnicianAccept(Tcallog log, string account, Boolean isVndAssign, string username) { _logger.Info($"案件認養/指派-公司別:{log.CompCd},案件編號:{log.Sn}"); #region 驗證與取得資訊 //取得案件 Tcallog callog = base.GetCallog(log.CompCd, log.Sn); if (callog.TacceptedLog != null) { throw new IndexOutOfRangeException($"案件已由{callog.TacceptedLog.Name}認養"); } //如果已經銷案不允許再指通知了 if (callog.CloseSts > (byte)CloseSts.process) { throw new IndexOutOfRangeException($"此案件已銷案"); } //取得技師 TvenderTechnician technician = base.GetTechnician(log.CompCd, account); _logger.Info($"案件認養/指派-公司別:{callog.CompCd}"); _logger.Info($"案件認養/指派-廠商別:{callog.VenderCd}"); _logger.Info($"案件認養/指派-技師代號:{technician.Account}"); #endregion #region 組合物件 DateTime now = DateTime.Now; TacceptedLog tacceptedLog = new TacceptedLog() { Account = technician.Account, Sn = callog.Sn, RcvDatetime = now, RcvRemark = "no defind", Name = technician.Name, }; callog.TacceptedLog = tacceptedLog; callog.TimePoint = (int)TimePoint.Accepted; #endregion using (TransactionScope scope = new TransactionScope()) { _logger.Info($"案件認養/指派-準備更新資料"); #region 技師認養 if (!_callogFactory.TechnicianAccept(callog)) { throw new Exception("[ERROR]=>技師認養案件時,認養失敗"); } #endregion _logger.Info($"案件認養/指派-移除案件與技師關聯"); #region 移除案件與技師關聯 //bool bo = _technicianProvider.RemoveAwaitAcceptLog(log.CompCd, log.Sn); //if (bo == false) //{ // string Mail = ServerProfile.GetInstance().Mail; // string[] MailList = Mail.Split(';'); // _MailFactory.Excute(new MailRequest( // MailList, // "移除案件與技師關聯失敗", // $"認養或指派時,刪除技師與案件關聯失敗,案件編號:{log.Sn}" // )); // throw new Exception("[ERROR]=>技師認養案件時,認養失敗"); //} int DataCount; using (TransactionScope tss = new TransactionScope(TransactionScopeOption.RequiresNew)) { DataCount = _technicianProvider.GetCallLogClaimsCount(log.CompCd, log.Sn); _logger.Info($"移除案件與技師關聯[前],CallLogClaims關聯資料筆數 :{DataCount}, 查詢條件-公司別:{log.CompCd}、案件編號:{log.Sn}"); _logger.Info($"案件認養/指派-準備移除案件與技師關聯,公司別:{log.CompCd}、案件編號:{log.Sn}"); _technicianProvider.RemoveAwaitAcceptLog(log.CompCd, log.Sn); tss.Complete(); } using (TransactionScope tss = new TransactionScope(TransactionScopeOption.Suppress)) { DataCount = _technicianProvider.GetCallLogClaimsCount(log.CompCd, log.Sn); _logger.Info($"移除案件與技師關聯[後],CallLogClaims關聯資料筆數 :{DataCount}, 查詢條件-公司別:{log.CompCd}、案件編號:{log.Sn}"); } if (DataCount != 0) { string Mail = ServerProfile.GetInstance().Mail; string[] MailList = Mail.Split(';'); _MailFactory.Excute(new MailRequest( MailList, "移除案件與技師關聯失敗", $"認養或指派時,刪除技師與案件關聯失敗,案件編號:{log.Sn}" )); throw new Exception($"[ERROR]=>案件編號:{log.Sn},技師認養案件時,認養失敗"); } #endregion scope.Complete(); } #region 推播訊息 string Assignor = ""; if (isVndAssign) //由廠商指派的才需要推播 { _logger.Info($"案件認養/指派-準備通知給帳號:{account}"); string storeName = getStoreName(callog.CompCd, callog.StoreCd); string CallLevel = callog.CallLevel == "1" ? "普通" : "緊急"; _notifyFactory.Exucte(new JPushRequest( callog.CompCd, callog.VenderCd, account) { Sn = callog.Sn, Content = $"您有一筆新案件待銷案,案件編號:{callog.Sn} 店名:{storeName} 叫修等級:{CallLevel}", Title = "認養案件", Extras = new Dictionary <string, string>() { { "FeatureName", "VenderConfirm" } } }); Assignor = username; } else { Assignor = technician.Name; } var Con = new Conditions <DataBase.TCallogCourse>(); TCallogCourse course = new TCallogCourse() { CompCd = log.CompCd, Sn = log.Sn, Assignor = Assignor, Admissibility = technician.Name, Datetime = now }; //新增案件歷程 _CallogCourseRepo.Insert(Con, course); #endregion return(true); }
/// <summary> /// 廠商通知技師認養案件 /// </summary> /// <param name="log"></param> /// <param name="accounts"></param> /// <returns></returns> public Boolean VenderNotification(Tcallog log, List <string> accounts) { _logger.Info($"案件通知-公司別:{log.CompCd},案件編號:{log.Sn}"); #region 驗證與取得資訊 //取得案件 Tcallog callog = base.GetCallog(log.CompCd, log.Sn); //如果已經銷案不允許再指通知了 if (callog.CloseSts > (byte)CloseSts.process) { throw new IndexOutOfRangeException($"此案件已銷案"); } if (callog.TacceptedLog != null) { throw new IndexOutOfRangeException($"案件已由{callog.TacceptedLog.Name}認養"); } //取得公司 Tcmpdat comp = base.GetComp(log.CompCd); _logger.Info($"案件通知-公司別:{callog.CompCd}"); _logger.Info($"案件通知-廠商別:{callog.VenderCd}"); #endregion using (TransactionScope scope = new TransactionScope()) { accounts.ForEach(account => { _logger.Info($"準備通知給帳號:{account}"); #region 更新資料 _technicianProvider.AddAwaitAcceptLog(log.CompCd, callog.Sn, account); #endregion #region 推播訊息 string storeName = getStoreName(callog.CompCd, callog.StoreCd); string CallLevel = callog.CallLevel == "1" ? "普通" : "緊急"; _notifyFactory.Exucte(new JPushRequest( callog.CompCd, callog.VenderCd, account) { Sn = callog.Sn, Content = $"您有一筆新案件待認養,案件編號:{callog.Sn} 店名:{storeName} 叫修等級:{CallLevel}", Title = "認養案件", Extras = new Dictionary <string, string>() { { "FeatureName", "VenderAccept" } } }); #endregion }); scope.Complete(); } return(true); }
/// <summary> /// 多案件、單一技師改派 /// </summary> /// <param name="user"></param> /// <param name="Sn"></param> /// <param name="Account"></param> /// <returns>從Web進行改派</returns> public Boolean ChangeNotificationForWeb(UserBase user, List <string> Sn, TvenderTechnician Techniciandata, Dictionary <string, string> OldAccount) { _logger.Info("更新技師已受理案件(網頁改派案件)"); using (TransactionScope scope = new TransactionScope()) { //更新案件已受理技師 Sn.ForEach(sn => { #region 更新資料 //取得案件 Tcallog callog = base.GetCallog(user.CompCd, sn); TacceptedLog tacceptedLog = new TacceptedLog() { Account = Techniciandata.Account, Sn = callog.Sn, RcvDatetime = DateTime.Now, RcvRemark = "no defind", Name = Techniciandata.Name, }; callog.TacceptedLog = tacceptedLog; if (!_callogFactory.TechnicianAccept(callog)) { throw new Exception($"[ERROR]=>廠商改派案件失敗,案件編號:{sn}"); } #endregion #region 新增案件歷程 Conditions <DataBase.TCallogCourse> Con = new Conditions <DataBase.TCallogCourse>(); TCallogCourse course = new TCallogCourse() { CompCd = user.CompCd, Sn = sn, Assignor = user.UserName, Admissibility = Techniciandata.Name, Datetime = DateTime.Now }; //新增案件歷程 _CallogCourseRepo.Insert(Con, course); #endregion }); scope.Complete(); } #region 推播給新技師 Dictionary <string, string> Account = new Dictionary <string, string>(); Account.Add(Techniciandata.Account, Techniciandata.RegistrationID); _notifyFactory.Exucte( new JPushRequest(user.CompCd, user.VenderCd) { Content = "您有新案件待銷案", Title = "廠商改派", Extras = new Dictionary <string, string>() { { "FeatureName", "VenderConfirm" } } } , Sn , Account); #endregion #region 推播給舊技師 _notifyFactory.Exucte( new JPushRequest(user.CompCd, user.VenderCd) { Content = "您的案件已經被指派給其他技師", Title = "廠商改派", Extras = new Dictionary <string, string>() { { "FeatureName", "" } } } , Sn , OldAccount); #endregion return(true); }
/// <summary> /// 多案件、單一技師指派 /// </summary> /// <param name="user"></param> /// <param name="Sn"></param> /// <param name="Account"></param> /// <returns>從Web進行指派</returns> public Boolean NotificationForAppoint(UserBase user, List <string> Sn, List <string> Account) { _logger.Info("更新技師待受理案件(網頁指派案件)"); DateTime now = DateTime.Now; using (TransactionScope scope = new TransactionScope()) { _logger.Info($"案件認養/指派-準備更新資料"); Sn.ForEach(sn => { int DataCount; #region 移除案件與技師關聯 using (TransactionScope tss = new TransactionScope(TransactionScopeOption.RequiresNew)) { DataCount = _technicianProvider.GetCallLogClaimsCount(user.CompCd, sn); _logger.Info($"移除案件與技師關聯[前],CallLogClaims關聯資料筆數 :{DataCount}, 查詢條件-公司別:{user.CompCd}、案件編號:{sn}"); _logger.Info($"案件認養/指派-準備移除案件與技師關聯,公司別:{user.CompCd}、案件編號:{sn}"); _technicianProvider.RemoveAwaitAcceptLog(user.CompCd, sn); tss.Complete(); } #endregion using (TransactionScope tss = new TransactionScope(TransactionScopeOption.Suppress)) { DataCount = _technicianProvider.GetCallLogClaimsCount(user.CompCd, sn); _logger.Info($"移除案件與技師關聯[後],CallLogClaims關聯資料筆數 :{DataCount}, 查詢條件-公司別:{user.CompCd}、案件編號:{sn}"); } if (DataCount != 0) { string Mail = ServerProfile.GetInstance().Mail; string[] MailList = Mail.Split(';'); _MailFactory.Excute(new MailRequest( MailList, "移除案件與技師關聯失敗", $"認養或指派時,刪除技師與案件關聯失敗,案件編號:{sn}" )); throw new Exception($"[ERROR]=>案件編號:{sn},技師認養案件時,認養失敗"); } else { #region 更新資料 //取得案件 Tcallog callog = base.GetCallog(user.CompCd, sn); TacceptedLog tacceptedLog = new TacceptedLog() { Account = Account[0].ToString(), Sn = sn, RcvDatetime = now, RcvRemark = "no defind", Name = Account[2].ToString(), }; callog.TacceptedLog = tacceptedLog; callog.TimePoint = (int)TimePoint.Accepted; if (!_callogFactory.TechnicianAccept(callog)) { throw new Exception("[ERROR]=>技師認養案件時,認養失敗"); } #endregion } #region 新增案件歷程 Conditions <DataBase.TCallogCourse> Con = new Conditions <DataBase.TCallogCourse>(); TCallogCourse course = new TCallogCourse() { CompCd = user.CompCd, Sn = sn, Assignor = user.UserName, Admissibility = Account[2].ToString(), Datetime = now }; //新增案件歷程 _CallogCourseRepo.Insert(Con, course); #endregion }); scope.Complete(); } #region 推播 var bo = _notifyFactory.Exucte( new JPushRequest(user.CompCd, user.VenderCd) { Content = "您有新案件待銷案", Title = "認養案件", Extras = new Dictionary <string, string>() { { "FeatureName", "VenderConfirm" } } } , Sn , Account); #endregion 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}" } })); } }
public StoreCallogResultApiViewModel(Tcallog data) { }
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}" } })); } }
/// <summary> /// 新增照片 /// </summary> public void AddImg(Tcallog input) { DataBase.SETENG_Entities db = new DataBase.SETENG_Entities(); var resault = db.TCALIMG.Where(x => x.Comp_Cd == input.CompCd && x.Sn == input.Sn); if (resault.ToList().Count > 0) { foreach (var seq in resault.Select(x => x.File_Seq).ToList()) { var query = db.TUpFile.Where(x => x.File_Seq == seq); foreach (var item in query) { bool success = _getCallLogFile.DelFile(input.Sn, input.CompCd, item.File_Name); if (!success) { _logger.Error("圖片刪除錯誤-檔名: " + item.File_Name); } } db.TUpFile.RemoveRange(query); } db.TCALIMG.RemoveRange(resault); db.SaveChanges(); } foreach (var img in input.ImgBeforeFix) { int index = 0; var table = db.TCALIMG.Where(x => x.Comp_Cd == input.CompCd && x.Sn == input.Sn); if (table.ToList().Count == 0) { index = 1; } else { index = table.Max(x => x.Seq); index = index + 1; } DataBase.TUpFile item = new DataBase.TUpFile(); item.Create_Date = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); item.Create_User = input.AcceptedName; item.Doc_Type = "jpg"; item.File_Name = String.Format("{0}-{1}-{2}.jpg", input.CompCd, input.Sn, index); item.Pgm_Id = "手機上傳"; item.File_Size = 0; db.TUpFile.Add(item); db.SaveChanges(); DataBase.TUpFile Upfile = db.TUpFile.Where(x => x.File_Name == item.File_Name).FirstOrDefault(); DataBase.TCALIMG itemImg = new DataBase.TCALIMG(); itemImg.Comp_Cd = input.CompCd; itemImg.File_Seq = Upfile.File_Seq; itemImg.Img_Type = ((int)ImgType.BeforeFix).ToString(); itemImg.Seq = (byte)index; itemImg.Sn = input.Sn; db.TCALIMG.Add(itemImg); db.SaveChanges(); uploadImage(img, input.Sn, input.CompCd, item.File_Name); } foreach (var img in input.ImgAfterFix) { int index = 0; var table = db.TCALIMG.Where(x => x.Comp_Cd == input.CompCd && x.Sn == input.Sn); if (table.ToList().Count == 0) { index = 1; } else { index = table.Max(x => x.Seq); index = index + 1; } DataBase.TUpFile item = new DataBase.TUpFile(); item.Create_Date = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); item.Create_User = input.AcceptedName; item.Doc_Type = "jpg"; item.File_Name = String.Format("{0}-{1}-{2}.jpg", input.CompCd, input.Sn, index); item.Pgm_Id = "手機上傳"; item.File_Size = 0; db.TUpFile.Add(item); db.SaveChanges(); DataBase.TUpFile Upfile = db.TUpFile.Where(x => x.File_Name == item.File_Name).FirstOrDefault(); DataBase.TCALIMG itemImg = new DataBase.TCALIMG(); itemImg.Comp_Cd = input.CompCd; itemImg.File_Seq = Upfile.File_Seq; itemImg.Img_Type = ((int)ImgType.AfterFix).ToString(); itemImg.Seq = (byte)index; itemImg.Sn = input.Sn; db.TCALIMG.Add(itemImg); db.SaveChanges(); uploadImage(img, input.Sn, input.CompCd, item.File_Name); } foreach (var img in input.Img) { int index = 0; var table = db.TCALIMG.Where(x => x.Comp_Cd == input.CompCd && x.Sn == input.Sn); if (table.ToList().Count == 0) { index = 1; } else { index = table.Max(x => x.Seq); index = index + 1; } DataBase.TUpFile item = new DataBase.TUpFile(); item.Create_Date = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); item.Create_User = input.AcceptedName; item.Doc_Type = "jpg"; item.File_Name = String.Format("{0}-{1}-{2}.jpg", input.CompCd, input.Sn, index); item.Pgm_Id = "手機上傳"; item.File_Size = 0; db.TUpFile.Add(item); db.SaveChanges(); DataBase.TUpFile Upfile = db.TUpFile.Where(x => x.File_Name == item.File_Name).FirstOrDefault(); DataBase.TCALIMG itemImg = new DataBase.TCALIMG(); itemImg.Comp_Cd = input.CompCd; itemImg.File_Seq = Upfile.File_Seq; itemImg.Img_Type = ((int)ImgType.Workorder).ToString(); itemImg.Seq = (byte)index; itemImg.Sn = input.Sn; db.TCALIMG.Add(itemImg); db.SaveChanges(); uploadImage(img, input.Sn, input.CompCd, item.File_Name); } foreach (var img in input.ImgSignature) { int index = 0; var table = db.TCALIMG.Where(x => x.Comp_Cd == input.CompCd && x.Sn == input.Sn); if (table.Count() == 0) { index = 1; } else { index = table.Max(x => x.Seq); index = index + 1; } DataBase.TUpFile item = new DataBase.TUpFile(); item.Create_Date = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); item.Create_User = input.AcceptedName; item.Doc_Type = "jpg"; item.File_Name = String.Format("{0}-{1}-{2}.jpg", input.CompCd, input.Sn, index); item.Pgm_Id = "手機上傳"; item.File_Size = 0; db.TUpFile.Add(item); db.SaveChanges(); DataBase.TUpFile Upfile = db.TUpFile.Where(x => x.File_Name == item.File_Name).FirstOrDefault(); DataBase.TCALIMG itemImg = new DataBase.TCALIMG(); itemImg.Comp_Cd = input.CompCd; itemImg.File_Seq = Upfile.File_Seq; itemImg.Img_Type = ((int)ImgType.Signature).ToString(); itemImg.Seq = (byte)index; itemImg.Sn = input.Sn; db.TCALIMG.Add(itemImg); db.SaveChanges(); uploadImage(img, input.Sn, input.CompCd, item.File_Name); } }
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="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 StoreCallogResultApiViewModel(Tcallog data, IEnumerable <TvenderTechnician> listTechnician, IEnumerable <Tusrmst> listUser) { }
public CallogDetailViewModel(Tcallog data, FeatureType type) { }