/// <summary> /// 取得資料範圍 /// </summary> /// <param name="Data"></param> public override void GetDataAuth(ref UserBase Data) { if (!IsMatch(Data)) { throw new Exception($"此角色無法使用該功能!"); } UserBase temp = Data; var conVnd = new Conditions <DataBase.TVENDER>(); //關聯所屬公司 //con.Include(x => x.TCMPDAT); //廠商別 conVnd.And(x => x.Vender_Cd == temp.UserId); //公司別 conVnd.And(x => x.Comp_Cd == temp.CompCd); ////廠商到期日 //con.And(x => x.Close_Date >= DateTime.Now); Tvender range = _vendorRepo.Get(conVnd); Data.VenderName = range?.VenderName; if (range == null) { throw new Exception("廠商主檔 查無資料"); } var conComp = new Conditions <DataBase.TCMPDAT>(); conComp.And(x => x.Comp_Cd == range.CompCd); Tcmpdat Comp = _cmpdatRepo.Get(conComp); Data.CompShort = Comp?.CompShort; var datarange = new DataRange(); var vendorcd = new List <string>() { range?.VenderCd }; datarange.VendorCd = vendorcd; Data.DataRange = datarange; }
/// <summary> /// 取得廠商資訊 /// </summary> /// <param name="compCd"></param> /// <param name="venderCd"></param> /// <returns></returns> public virtual Tvender GetTvender(string compCd, string venderCd) { if (String.IsNullOrEmpty(compCd) || String.IsNullOrEmpty(venderCd)) { throw new ArgumentNullException($"[ERROR]=>取得廠商資訊時,並沒有給入相關資訊"); } var con = new Conditions <DataBase.TVENDER>(); con.And(x => x.Comp_Cd == compCd && x.Vender_Cd == venderCd); Tvender data = _venderRepo.Get(con); if (data == null) { throw new NullReferenceException($"[ERROR]=>找不到對應的廠商資訊,公司編號:{compCd},廠商代號:{venderCd}"); } return(data); }
/// <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); }