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); }
public Boolean CreateVendorGroup(UserBase data) { #region 該廠商底下所有技師 var con = new Conditions <DataBase.TVenderTechnician>(); con.And(x => x.Comp_Cd == data.CompCd && x.Vender_Cd == data.VenderCd); var query = _tvenderRepo.GetList(con); var accounts = new List <string>(); query?.ForEach(x => { accounts.Add(x.Account); }); #endregion var model = new TtechnicianGroup() { CompCd = data.CompCd, VendorCd = data.VenderCd, GroupName = data.VenderName, //IsAutoPush = false, //IsDefault = true }; return(this.CreateTechnicianGroup(model, accounts.ToArray())); }
public TechnicianGroupEditViewModel(TtechnicianGroup Data) { this.Seq = Data.Seq; //this.CompCd = Data.CompCd; //this.VendorCd = Data.VendorCd; this.GroupName = Data.GroupName; this.ResponsibleZo = Data.Responsible_Zo; this.ResponsibleDo = Data.Responsible_Do; }
/// <summary> /// 群組列表 /// </summary> public NotifyAssignedViewModel(TtechnicianGroup data) { this.seq = data.Seq; this.GroupName = data.GroupName; colData = new string[] { string.Empty, this.GroupName, this.seq.ToString() }; }
public TechnicianGPResultApiViewModel(TtechnicianGroup data) { this.CompCd = data.CompCd; this.GroupName = data.GroupName; this.VendorCd = data.VendorCd; this.Seq = data.Seq; var teClaim = data.TTechnicianGroupClaims; //取得已經通過總部審核跟已啟用的 this.Count = teClaim.Select(x => x.TVenderTechnician) .Count(g => g.Enable); }
public TechnicianGroupResultViewModel(TtechnicianGroup Data, PagedList <Tzocode> Zo) { this.CompCd = Data.CompCd; this.VendorCd = Data.VendorCd; this.GroupName = Data.GroupName; this.ResponsibleZo = Data.Responsible_Zo; string ShowZo = ""; var inputZo = Data.Responsible_Zo.Split(','); inputZo.ForEach(x => { ShowZo += "、" + Zo.Where(y => y.ZoCd == x && y.DoCd == "").Select(z => z.ZoName).FirstOrDefault(); }); ShowZo = ShowZo.Substring(1); string ShowDo = ""; var inputDo = Data.Responsible_Do.Split(','); inputDo.ForEach(x => { ShowDo += "、" + Zo.Where(y => y.DoCd == x).Select(z => z.DoName).FirstOrDefault(); }); ShowDo = ShowDo.Substring(1); this.ResponsibleZo = ShowZo; this.ResponsibleDo = ShowDo; this.Seq = Data.Seq; colData = new String[] { string.Empty, this.GroupName, this.ResponsibleZo, this.ResponsibleDo, this.CompCd, this.VendorCd, this.Seq.ToString(), this.IsDefault.ToString(), }; }
/// <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); }
public ActionResult Edit(TechnicianGroupEditViewModel model) { try { if (model == null) { throw new ArgumentNullException($"修改群組數據時,並未傳入任何信息"); } if (model.Zo == null) { throw new Exception($"並未傳入區域名稱"); } if (model.Accounts == null) { throw new Exception($"並未傳入技師名稱"); } #region 組合區域與課別 //組合區域 string ZO = ""; model.Zo.ForEach(x => { ZO += "," + x; }); if (ZO != "") { ZO = ZO.Substring(1); } //組合課別 string DO = ""; model.Do.ForEach(x => { DO += "," + x; }); if (DO != "") { DO = DO.Substring(1); } #endregion //修改群組信息 TtechnicianGroup techniciangroup = new TtechnicianGroup() { Seq = model.Seq, CompCd = model.CompCd, VendorCd = model.VendorCd, GroupName = model.GroupName, Responsible_Zo = ZO, Responsible_Do = DO, }; Boolean isSuccess = _vendorService.UpdateTechnicianGroup(techniciangroup, model.Accounts); return(Json(new JsonResult() { Data = new { IsSuccess = isSuccess, Message = String.Format("修改群組數據:{0}", 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 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()); } }