Пример #1
0
        /// <summary>
        /// 认可技師
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public Boolean ConfirmTechnician(TvenderTechnician data)
        {
            _logger.Info($"認可技師-技師帳號:{data.Account}");

            //using (TransactionScope scope = new TransactionScope())
            //{

            //    _logger.Info($"認可技師-準備更新資料");

            //    var con = new Conditions<DataBase.TVenderTechnician>();

            //    con.And(g => g.Account == data.Account);
            //    con.And(g => g.Comp_Cd == data.CompCd);
            //    con.And(g => g.Vender_Cd == data.VenderCd);


            //    con.Allow(g => g.IsHQCheck,
            //              g => g.IsHQCheckRemark,
            //              g => g.HQCheckTime);

            //    _technicianRepo.Update(con, data);


            //    scope.Complete();
            //}

            return(true);
        }
        public ActionResult Added(TechnicianEditViewModel data)
        {
            try
            {
                if (!this.LoginUserInfo.CurrentGroupAction.AuthType.Value.HasFlag(AuthNodeType.Create))
                {
                    throw new Exception("沒有新增權限");
                }

                if (!ModelState.IsValid)
                {
                    throw new ArgumentNullException($"新增技師資料時有欄位未輸入");
                }

                //組合對象
                TvenderTechnician technician = new TvenderTechnician()
                {
                    CompCd   = data.CompCd,                                                  //公司代號
                    VenderCd = data.VenderCd,                                                //廠商代號
                    Account  = data.Account,                                                 //帳號
                    Name     = data.Name,                                                    //技師姓名
                    Password = Identity.ClearPassword.GetMd5Hash(data.Password).ToUpper(),   //密碼
                    Enable   = data.Enable,                                                  //帳號是否啟用
                    IsVendor = data.IsVendor                                                 //是否為技師主管
                };

                Boolean isSuccess = _technicianService.CreateTechnician(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 TechnicianListDetailViewModel(TvenderTechnician data) : this()
 {
     this.CompCd   = data.CompCd;
     this.VenderCd = data.VenderCd;
     //this.CompName = data.TVENDER?.TCMPDAT?.CompName;
     this.VenderName = data.TVENDER?.VenderName;
     this.Name       = data.Name;
     this.Password   = data.Password;
     this.Account    = data.Account;
 }
 public TechnicianEditViewModel(TvenderTechnician data) : this()
 {
     this.CompCd   = data.CompCd;
     this.VenderCd = data.VenderCd;
     this.Account  = data.Account;
     this.Name     = data.Name;
     this.Enable   = data.Enable;
     this.Password = data.Password;
     this.IsVendor = data.IsVendor;
 }
Пример #5
0
 /// <summary>
 /// 技師列表
 /// </summary>
 public ChangeAssignedViewModel(TvenderTechnician data)
 {
     this.Name    = data.Name;
     this.Account = data.Account;
     colData      = new string[]
     {
         string.Empty,
         this.Name,
         this.Account
     };
 }
        public TechnicianListResultViewModel(TvenderTechnician data)
        {
            this.VenderCd   = data.VenderCd;
            this.CompCd     = data.CompCd;
            this.VenderName = data.TVENDER?.VenderName;
            //this.CompName = data.TVENDER?.TCMPDAT?.CompName;
            this.Name    = data.Name;
            this.Account = data.Account;

            colData = new String[] {
                string.Empty,
                this.VenderName,
                this.Account,
                this.Name,
                $"{this.Account},{this.CompCd},{this.VenderCd}",
                this.CompCd,
                this.VenderCd,
            };
        }
Пример #7
0
        /// <summary>
        /// 更新技師
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public Boolean UpdateTechnician(TvenderTechnician data)
        {
            _logger.Info($"更新技師-技師帳號:{data.Account}");

            #region 找到技師相關訊息
            var con = new Conditions <DataBase.TVenderTechnician>();

            con.And(x => x.Comp_Cd == data.CompCd);
            con.And(x => x.Vender_Cd == data.VenderCd);
            con.And(x => x.Account == data.Account);

            TvenderTechnician meta = _technicianRepo.Get(con);

            if (meta == null)
            {
                throw new NullReferenceException($"[ERROR]=> 更新技師訊息時,找不到技師相關訊息");
            }

            #endregion

            using (TransactionScope scope = new TransactionScope())
            {
                _logger.Info($"更新技師-準備更新資料");

                #region 更新技師訊息


                con.Allow(x => x.Enable,     //帳號啟用
                          x => x.Name,       //名字
                          x => x.IsVendor,   //角色
                          x => x.Password);  //密碼

                _technicianRepo.Update(con, data);


                #endregion

                scope.Complete();
            }

            return(true);
        }
Пример #8
0
        public HttpResponseMessage VendorLogin(string Account, string Password, string UUID)
        {
            try
            {
                if (MethodHelper.IsNullOrEmpty(Account, Password, UUID))
                {
                    throw new ArgumentNullException($"未輸入帳號密碼");
                }

                //取得MD5資訊
                var md5Password = Identity.ClearPassword.GetMd5Hash(Password).ToUpper();

                TvenderTechnician result = _userService.VendorLogin(Account, md5Password, UUID);


                return(Request.CreateResponse(
                           HttpStatusCode.OK,
                           new JsonResult <TechnicianResultApiViewModel>(new TechnicianResultApiViewModel(result)
                {
                    Password = Password,
                    Token = TokenUtil <TvenderTechnician> .Create(new TvenderTechnician()
                    {
                        Account = result.Account,
                        Password = Password,
                        DeviceID = UUID,
                    })
                }, "登入成功", 1, true)));
            }
            catch (ArgumentOutOfRangeException ex)
            {
                return(Request.CreateResponse(
                           HttpStatusCode.OK,
                           new JsonResult <object>(new { clearUUID = true }, ex.ParamName, 1, true)));
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message);
                return(Request.CreateResponse(
                           HttpStatusCode.OK,
                           new JsonResult <TechnicianResultApiViewModel>(null, ex.Message, 1, false)));
            }
        }
Пример #9
0
        /// <summary>
        /// 取得技師資訊
        /// </summary>Class1.cs
        /// <param name="CompCd"></param>
        /// <param name="Account"></param>
        /// <returns></returns>
        public virtual TvenderTechnician GetTechnician(string compCd, string account)
        {
            if (String.IsNullOrEmpty(compCd) || String.IsNullOrEmpty(account))
            {
                throw new ArgumentNullException($"[ERROR]=>取得技師資訊時,並沒有給入相關資訊");
            }

            var con = new Conditions <DataBase.TVenderTechnician>();

            con.And(x => x.Comp_Cd == compCd &&
                    x.Account == account);

            TvenderTechnician data = _technicianRepo.Get(con);

            if (data == null)
            {
                throw new NullReferenceException($"[ERROR]=>找不到對應的技師資訊,公司編號:{compCd},技師帳號:{account}");
            }

            return(data);
        }
Пример #10
0
        /// <summary>
        /// [client]技師登出
        /// </summary>
        /// <param name="Account"></param>
        /// <param name="Password"></param>
        /// <returns></returns>
        public Boolean VendorLogout(string Account, string Password)
        {
            _logger.Info($"APP登出-帳號:{Account},密碼:{Password}");

            #region 取得技師資訊

            var con = new Conditions <DataBase.TVenderTechnician>();

            con.And(x => x.Account == Account);
            con.And(x => x.Password == Password);

            //con.Include(x => x.TVENDER.TCMPDAT);

            TvenderTechnician result = _technicianRepo.Get(con);

            if (result == null)
            {
                throw new NullReferenceException($"[ERROR]=> 廠商登入時,帳號或密碼不存在");
            }

            #endregion 檢核技師相關欄位

            #region 清空相關欄位

            _logger.Info($"APP登出-準備更新資訊");

            result.DeviceID       = "";
            result.RegistrationID = "";

            con.Allow(x => x.DeviceID);
            con.Allow(x => x.RegistrationID);

            _technicianRepo.Update(con, result);

            #endregion

            return(true);
        }
        public ActionResult Detail(string Account, string CompCd, string VenderCd, AuthNodeType mode)
        {
            try
            {
                if (MethodHelper.IsNullOrEmpty(Account, CompCd, VenderCd))
                {
                    throw new ArgumentException($"取得技師信息時,并没有给入对应的参数");
                }


                var con = new Conditions <DataBase.TVenderTechnician>();

                con.And(x => x.Comp_Cd == CompCd);
                con.And(x => x.Vender_Cd == VenderCd);
                con.And(x => x.Account == Account);

                //con.Include(x => x.TVENDER.TCMPDAT);

                TvenderTechnician technician = _technicianRepo.Get(con);

                if (technician == null)
                {
                    throw new NullReferenceException($"取得不到技師信息,公司编号:{CompCd} , 厂商编号:{VenderCd} ,账号为:{Account}");
                }

                return(View("Edit", new TechnicianListDetailViewModel(technician)
                {
                    ActionType = mode
                }));
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message);
                return(View());
            }
        }
Пример #12
0
        /// <summary>
        /// 新增技師
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public Boolean CreateTechnician(TvenderTechnician data)

        {
            _logger.Info($"新增技師-技師帳號:{data.Account}");

            #region 檢核技師是否重覆

            var con = new Conditions <DataBase.TVenderTechnician>();

            con.And(x => x.Account == data.Account);

            if (_technicianRepo.GetList(con).Any())
            {
                throw new IndexOutOfRangeException("[ERROR]=>該帳號已被使用,請重新填寫");
            }

            #endregion

            using (TransactionScope scope = new TransactionScope())
            {
                _logger.Info($"新增技師-準備新增資料");

                #region 新增技師信息
                con.And(x => x.Account == data.Account);
                if (!_technicianRepo.Add(con, data))
                {
                    throw new Exception("[ERROR]=>新增失敗");
                }

                #endregion

                scope.Complete();
            }

            return(true);
        }
Пример #13
0
        /// <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);
        }
Пример #14
0
        /// <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);
        }
Пример #15
0
        /// <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);
        }
        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);
        }
Пример #17
0
        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}"
                    }
                }));
            }
        }
Пример #18
0
        /// <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 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}"
                    }
                }));
            }
        }
Пример #20
0
        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}"
                    }
                }));
            }
        }