public Boolean AddTechnicianGroup(TtechnicianGroup Data, string account) { var con = new Conditions <DataBase.TTechnicianGroupClaims>(); con.And(x => x.Seq == Data.Seq && x.CompCd == Data.CompCd && x.VendorCd == Data.VendorCd && x.Account == account); if (_technicianGroupClaimsRepo.IsExist(con)) { throw new Exception("[ERROR]=>預設群組已有該技師!!"); } TtechnicianGroupClaims technicianGroupClaims = new TtechnicianGroupClaims() { Seq = Data.Seq, CompCd = Data.CompCd, VendorCd = Data.VendorCd, Account = account }; if (!_technicianGroupClaimsRepo.Add(con, technicianGroupClaims)) { throw new Exception("[ERROR]=>修改技師至群組時,新增失敗"); } 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); }
/// <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); }
/// <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); }