/// <summary>
        /// 接受数据接口表信息生成
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="handleResult">当前状态类型(-1待处理, 0处理结果为错误)</param>
        /// <returns>接口表主键</returns>
        private void insertMsgInterface(SignMessageSendDto msg, int handleResult = -1)
        {
            try
            {
                SignMessageInterface face = new SignMessageInterface
                {
                    OID            = Guid.NewGuid().ToString(),
                    appname        = msg.appname,
                    sendtime       = msg.sendtime ?? DateTime.Now,
                    createtime     = DateTime.Now,
                    handleresult   = handleResult,
                    handleerrormsg = msg.handleerrormsg ?? "",
                    handlemsgoids  = msg.msgbody.boxOIDs ?? "",
                    msgbody        = msg.msgbody.SerializeModel()
                };

                var res = interfaceService.Insert(face);
                if (res)
                {
                    msg.interfaceOID = face.OID;
                }
                else
                {
                    msg.interfaceOID = "";
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("insertMsgInterface Exception: " + ex.Message);
                msg.interfaceOID = "";
            }
        }
        /// <summary>
        /// 检查用户角色--失效,过期等
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="roleEntity"></param>
        /// <returns></returns>
        private BizResult <List <SignMessageBox> > checkRoleInfo(SignMessageSendDto msg, SignMessageRole roleEntity)
        {
            if (roleEntity == null)
            {
                msg.handleerrormsg = "用户身份未找到";
                updateMsgInterfaceErrorHandle(msg);
                return(interfaceHandlerErrorReturn(msg.handleerrormsg));
            }


            if (msg.appname != roleEntity.appname)
            {
                msg.handleerrormsg = "请检查数据: 用户身份与appname不一致!";
                updateMsgInterfaceErrorHandle(msg);
                return(interfaceHandlerErrorReturn(msg.handleerrormsg));
            }

            if (roleEntity.rolestatus == 0)
            {
                msg.handleerrormsg = "请联系平台,用户身份已失效!";
                updateMsgInterfaceErrorHandle(msg);
                return(interfaceHandlerErrorReturn(msg.handleerrormsg));
            }

            return(new BizResult <List <SignMessageBox> >
            {
                Success = true
            });
        }
        private List <SignMessageBox> geneInsertSignMessageBox(SignMessageSendDto msg)
        {
            List <SignMessageBox> lstSignMessageBox = new List <SignMessageBox>();

            var ids   = msg.msgbody.toids.Split(",");
            var names = msg.msgbody.toids.Split(",");

            for (int i = 0; i < ids.Length; i++)
            {
                SignMessageBox saveEntity = new SignMessageBox
                {
                    OID             = Guid.NewGuid().ToString(),
                    appname         = msg.appname,
                    msgsourceid     = msg.msgbody.msgsourceid,
                    sendtime        = msg.sendtime,
                    fromempid       = msg.msgbody.fromid.ToUpper(),
                    fromempname     = msg.msgbody.fromname,
                    toempid         = ids[i].ToUpper(),
                    toempname       = names[i],
                    callbackurl     = msg.msgbody.callbackurl,
                    substance       = msg.msgbody.substance,
                    showmsg         = msg.msgbody.showmsg,
                    createtime      = DateTime.Now,
                    msgstatus       = (int)ReadStatusEnum.UnRead,
                    msghandlestatus = HandleStatusString.Undo,
                    emergencylevel  = msg.msgbody.emergencylevel ?? (int)EmergencyLevelEnum.Normal
                };

                lstSignMessageBox.Add(saveEntity);
            }

            return(lstSignMessageBox);
        }
        private BizResult <List <SignMessageBox> > checkPostAddData(SignMessageSendDto msg, string appOID)
        {
            var chkComm = this.checkCommonData(msg, appOID);


            if (msg.msgbody.handletype != (int)HandleTypeEnum.Add)
            {
                msg.handleerrormsg = "检查数据。消息处理类型错误";
                updateMsgInterfaceErrorHandle(msg);
                return(new BizResult <List <SignMessageBox> >
                {
                    Success = false,
                    Msg = msg.handleerrormsg
                });
            }

            return(chkComm);
        }
        //private string buildSperateIds(string ids)
        //{
        //    StringBuilder sb = new StringBuilder();
        //    string[] strids = ids.Split(",");

        //    foreach (var item in strids)
        //    {
        //        sb.Append("'");
        //        sb.Append(item);
        //        sb.Append("',");
        //    }

        //    return sb.ToString().Substring(0, sb.Length - 1);
        //}

        /// <summary>
        /// 检查更新通知类消息完整性
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="appOID"></param>
        /// <returns></returns>
        private BizResult <List <SignMessageBox> > checkPostUpdateNotifyData(SignMessageSendDto msg, string appOID)
        {
            var chkComm = this.checkCommonData(msg, appOID);

            if (!chkComm.Success)
            {
                return(chkComm);
            }

            List <string> lstId = new List <string>(msg.msgbody.toids.Split(","));

            List <SignMessageBox> existMsgBoxEntities = new List <SignMessageBox>();

            existMsgBoxEntities = messageboxService.db.Queryable <SignMessageBox>("t")
                                  .Where(t => t.appname == msg.appname && t.createtime <= msg.sendtime)
                                  .Where(t => t.msghandlestatus == HandleStatusString.Undo)
                                  .Where(t => lstId.Contains(t.toempid))
                                  //.Where("t.toempid in (@ids)", new { ids = buildSperateIds(msg.msgbody.toids) })
                                  .ToList();


            if (existMsgBoxEntities.Count == 0)
            {
                msg.handleerrormsg = "无需要更新消息";
                updateMsgInterfaceErrorHandle(msg);
                return(new BizResult <List <SignMessageBox> >
                {
                    Success = false,
                    Msg = msg.handleerrormsg
                });
            }
            else
            {
                msg.msgbody.boxOIDs = getMessageBoxIds(existMsgBoxEntities);
            }

            return(new BizResult <List <SignMessageBox> >
            {
                Success = true,
                Data = existMsgBoxEntities
            });
        }
        private void updateMsgInterfaceErrorHandle(SignMessageSendDto msg)
        {
            SignMessageInterface face = new SignMessageInterface
            {
                OID            = msg.interfaceOID,
                handleresult   = 0,//msg.handleresult,
                handleerrormsg = msg.handleerrormsg
                ,
                updatetime = DateTime.Now
            };

            try
            {
                interfaceService.UpdateOnlyColumn(face, t => new { t.handleresult, t.handleerrormsg, t.updatetime });
            }
            catch (Exception ex)
            {
                Console.WriteLine("updateMsgInterface Exception: " + ex.Message);
            }
        }
        /// <summary>
        /// 检查消息完整性,角色有效期,数据非空项,接口表数据新增
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="appOID"></param>
        /// <returns></returns>
        private BizResult <List <SignMessageBox> > checkCommonData(SignMessageSendDto msg, string appOID)
        {
            string appN       = "";
            var    roleEntity = roleService.sdb.GetSingle <SignMessageRole>(t => t.OID == appOID);

            if (roleEntity != null)
            {
                appN = roleEntity.appname;
            }

            if (string.IsNullOrEmpty(msg.appname))
            {
                msg.handleerrormsg = "请检查数据:发送appname不能为空!";
                msg.appname        = string.IsNullOrWhiteSpace(appN) ? appOID : appN;
                insertMsgInterface(msg, 0); //1. 插入接口表失败记录
                return(interfaceHandlerErrorReturn(msg.handleerrormsg));
            }

            insertMsgInterface(msg, -1); //1. 插入接口表中,待处理
            if (msg.interfaceOID == "")
            {
                msg.handleerrormsg = "请联系平台,错误信息: 接口表插入异常!";
                return(interfaceHandlerErrorReturn(msg.handleerrormsg));
            }

            //2. 检查角色是否有效,拦截
            var chkrole = this.checkRoleInfo(msg, roleEntity);

            if (!chkrole.Success)
            {
                return(chkrole);
            }

            //3. 检查本身内容完整性
            var chkMsgBody = this.checkMsgInfo(msg);

            return(chkMsgBody);
        }
Exemple #8
0
        /// <summary>
        /// 消息测试-更新
        /// </summary>
        /// <param name="OID"></param>
        /// <param name="type">类型,1新增, 2更新</param>
        /// <returns></returns>
        public BizResult <SignMessageBoxDto> testSend(string OID, int type)
        {
            try
            {
                SignMessageBoxDto dto = new SignMessageBoxDto();

                var signBox = Service.sdb.GetSingle <SignMessageBox>(t => t.OID == OID);
                if (signBox == null)
                {
                    return(new BizResult <SignMessageBoxDto>
                    {
                        Success = false,
                        Msg = "未找到,请重试"
                    });
                }

                string postUrl = "";
                if (type == 1)
                {
                    postUrl = "/SignMessage/UpdateSignMsg";
                }
                else
                {
                    postUrl = "/SignMessage/NewSignMsg";
                }
                //var getUrl = "/v1/Values";
                var postData = new SignMessageSendDto
                {
                    appname  = signBox.appname,
                    sendtime = DateTime.Now,
                    msgbody  =
                        type == 1 ? new SignMessageSendBodyDto //更新
                    {
                        //sourceid = signBox.OID,
                        callbackurl    = "http://www.baidu.com",
                        fromid         = signBox.fromempid,
                        toids          = signBox.toempid,
                        fromname       = signBox.fromempname,
                        tonames        = signBox.toempname,
                        handletype     = type,               //1,2,3 新增/更新/删除
                        emergencylevel = (int)EmergencyLevelEnum.Normal,
                        msgsourceid    = signBox.msgsourceid //必要条件
                    }
                    : new SignMessageSendBodyDto             //新增
                    {
                        //sourceid = signBox.OID,
                        callbackurl    = "http://www.baidu.com",
                        fromid         = signBox.fromempid,
                        toids          = signBox.toempid,
                        fromname       = signBox.fromempname,
                        tonames        = signBox.toempname,
                        handletype     = type,               //1,2,3 新增/更新/删除
                        emergencylevel = (int)EmergencyLevelEnum.Normal,
                        msgsourceid    = signBox.msgsourceid //必要条件
                    }
                };

                //var response = new CallAPI().PostCall(postUrl, postData.SerializeModel()).Content;
                var response = RestSharpHttp.PostJson(postUrl, postData.SerializeModel());

                //var response = HttpClinetHelper.Post(postUrl, postData.SerializeModel());
                //var response = HttpClinetHelper.HttpPost(postUrl, postData.SerializeModel());

                //.ConfigureAwait(false).GetAwaiter().GetResult();

                if (response == "")
                {
                    return(new BizResult <SignMessageBoxDto>
                    {
                        Success = false,
                        Msg = "网络请求内容为空"
                    });
                }
                else
                {
                    var returnD = response.DeserializeModel <BizResult <SignMessageBoxDto> >();
                    return(returnD);
                }

                //return new BizResult<SignMessageBoxDto>
                //{
                //    Success = true,
                //    Data = returnD
                //};
            }
            catch (Exception ex)
            {
                return(new BizResult <SignMessageBoxDto>
                {
                    Success = false,
                    Msg = ex.Message
                });
            }
        }
        private BizResult <List <SignMessageBox> > checkMsgInfo(SignMessageSendDto msg)
        {
            var msgbody = msg.msgbody;

            #region 为空检测
            StringBuilder errMsg = new StringBuilder();

            if (string.IsNullOrWhiteSpace(msgbody.msgsourceid))
            {
                errMsg.Append("msgsourceid 不能为空;");
            }
            if (string.IsNullOrWhiteSpace(msgbody.fromid))
            {
                errMsg.Append("fromid 不能为空;");
            }
            if (string.IsNullOrWhiteSpace(msgbody.fromname))
            {
                errMsg.Append("fromname 不能为空;");
            }
            if (string.IsNullOrWhiteSpace(msgbody.toids))
            {
                errMsg.Append("toids 不能为空;");
            }
            if (string.IsNullOrWhiteSpace(msgbody.tonames))
            {
                errMsg.Append("tonames 不能为空;");
            }

            if (!string.IsNullOrWhiteSpace(msgbody.toids) && !string.IsNullOrWhiteSpace(msgbody.tonames))
            {
                if (msgbody.toids.Split(",").Length != msgbody.tonames.Split(",").Length)
                {
                    errMsg.Append("toids 和 tonames 数量不符");
                }
            }

            //全部大写的工号
            msg.msgbody.fromid = msg.msgbody.fromid.ToUpper();
            msg.msgbody.toids  = msg.msgbody.toids.ToUpper();

            if (string.IsNullOrWhiteSpace(msgbody.handletype.ToString()))
            {
                errMsg.Append("handletype 不能为空;");
            }

            if (string.IsNullOrWhiteSpace(msgbody.callbackurl))
            {
                errMsg.Append("callbackurl 不能为空;");
            }

            string errMsgRes = errMsg.ToString();
            if (errMsgRes.Length > 3)
            {
                msg.handleerrormsg = errMsgRes;
                updateMsgInterfaceErrorHandle(msg);

                return(new BizResult <List <SignMessageBox> >
                {
                    Success = false,
                    Msg = errMsgRes
                });
            }
            #endregion


            msgbody.emergencylevel = msgbody.emergencylevel ?? 1;
            msgbody.substance      = msgbody.substance ?? msg.appname;

            return(new BizResult <List <SignMessageBox> >
            {
                Success = true
            });
        }
Exemple #10
0
        /// <summary>
        /// 检查更新类消息完整性
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="appOID"></param>
        /// <returns></returns>
        private BizResult <List <SignMessageBox> > checkPostUpdateData(SignMessageSendDto msg, string appOID)
        {
            var chkComm = this.checkCommonData(msg, appOID);

            if (!chkComm.Success)
            {
                return(chkComm);
            }

            List <SignMessageBox> existEntities = new List <SignMessageBox>();

            if (msg.msgbody.handletype == (int)HandleTypeEnum.CompletedWithOID)        //如果是TOID 部分更新类型
            {
                List <string> lstId = new List <string>(msg.msgbody.toids.Split(",")); //需要更新人员

                existEntities = messageboxService.db.Queryable <SignMessageBox>("t")
                                .Where(t => lstId.Contains(t.toempid))
                                .Where(t => t.msgsourceid == msg.msgbody.msgsourceid)
                                .ToList();
            }
            else
            {
                existEntities = messageboxService.db.Queryable <SignMessageBox>("t")
                                .Where(t => t.msgsourceid == msg.msgbody.msgsourceid)
                                .ToList();
                //.GetList<SignMessageBox>(t => t.msgsourceid == msg.msgbody.msgsourceid);
                //existEntities = messageboxService.sdb.GetList<SignMessageBox>(t => t.msgsourceid == msg.msgbody.msgsourceid);
            }

            if (existEntities.Count == 0)
            {
                if (msg.msgbody.handletype == (int)HandleTypeEnum.CompletedWithOID) //如果是TOID 部分更新类型
                {
                    msg.handleerrormsg = "提供msgsourceid,toids找不到对应消息,请检查";
                }
                else
                {
                    msg.handleerrormsg = "提供msgsourceid找不到对应消息,请检查";
                }

                updateMsgInterfaceErrorHandle(msg);
                return(new BizResult <List <SignMessageBox> >
                {
                    Success = false,
                    Msg = msg.handleerrormsg
                });
            }
            else
            {
                msg.msgbody.boxOIDs = getMessageBoxIds(existEntities);
            }

            var types = new int[]
            {
                (int)HandleTypeEnum.Completed, (int)HandleTypeEnum.Del, (int)HandleTypeEnum.CompletedWithOID
            };

            if (Array.IndexOf(types, msg.msgbody.handletype) == -1)
            {
                msg.handleerrormsg = "检查数据。消息处理类型错误";
                updateMsgInterfaceErrorHandle(msg);
                return(new BizResult <List <SignMessageBox> >
                {
                    Success = false,
                    Msg = msg.handleerrormsg
                });
            }


            return(new BizResult <List <SignMessageBox> >
            {
                Success = true,
                Data = existEntities
            });
        }
Exemple #11
0
        //更新
        public BizResult <List <SignMessageBox> > PostUpdateSignMsg(SignMessageSendDto msg, string appOID)
        {
            //NewOA.Employee emp = NewOA.Employee.GetEmployee("", "cocoge");


            try
            {
                if (msg == null)
                {
                    return(interfaceHandlerErrorReturn("接收类型为空,请检查"));
                }

                msg.sendtime = msg.sendtime ?? DateTime.Now;

                var res = this.checkPostUpdateData(msg, appOID);
                if (!res.Success)
                {
                    return(res);
                }


                try
                {
                    var needUpdateRows = res.Data;
                    foreach (var item in needUpdateRows)
                    {
                        item.updatetime      = DateTime.Now;
                        item.msghandlestatus = HandleStatusString.Done;
                        item.emergencylevel  = msg.msgbody.emergencylevel ?? 1;
                        item.callbackurl     = msg.msgbody.callbackurl;
                    }

                    messageboxService.db.BeginTran();
                    messageboxService.db.Updateable(new SignMessageInterface
                    {
                        OID           = msg.interfaceOID,
                        handleresult  = 1,
                        updatetime    = DateTime.Now,
                        handlemsgoids = msg.msgbody.boxOIDs //检查过存在
                    }).UpdateColumns(t => new { t.handleresult, t.handlemsgoids, t.updatetime }).ExecuteCommand();

                    messageboxService.db.Updateable(needUpdateRows)
                    .UpdateColumns(t => new { t.updatetime, t.msghandlestatus, t.emergencylevel, t.callbackurl })
                    .ExecuteCommand();

                    //messageboxService.db.Updateable(new SignMessageBox
                    //{
                    //    updatetime = DateTime.Now,
                    //    emergencylevel = msg.msgbody.emergencylevel ?? 1,
                    //    callbackurl = msg.msgbody.callbackurl,
                    //    msgsourceid = msg.msgbody.msgsourceid
                    //})
                    //.WhereColumns(t => new { t.msgsourceid})
                    //.ExecuteCommand();

                    //messageboxService.db.Updateable(new SignMessageBox
                    //{
                    //    updatetime = DateTime.Now,
                    //    emergencylevel = msg.msgbody.emergencylevel ?? 1,
                    //    callbackurl = msg.msgbody.callbackurl,
                    //    msghandlestatus = HandleStatusString.Done,
                    //}).Where(t => t.msgsourceid == msg.msgbody.msgsourceid)
                    //     .UpdateColumns(t => new
                    //     {
                    //         t.updatetime,
                    //         t.emergencylevel,
                    //         t.callbackurl,
                    //         t.msghandlestatus
                    //     }).ExecuteCommand();

                    messageboxService.db.CommitTran();
                    return(new BizResult <List <SignMessageBox> >
                    {
                        Success = true
                    });
                }
                catch (Exception ex)
                {
                    messageboxService.db.RollbackTran();
                    return(new BizResult <List <SignMessageBox> >
                    {
                        Success = false,
                        Msg = ex.Message
                    });
                }
            }
            catch (Exception ex)
            {
                return(interfaceHandlerErrorReturn(ex.Message));
            }
        }
Exemple #12
0
        //新增
        public BizResult <List <SignMessageBox> > PostNewSignMsg(SignMessageSendDto msg, string appOID)
        {
            try
            {
                if (msg == null)
                {
                    return(new BizResult <List <SignMessageBox> >
                    {
                        Success = false,
                        Msg = "接收类型为空,请检查"
                    });
                }

                msg.sendtime = msg.sendtime ?? DateTime.Now;

                var res = checkPostAddData(msg, appOID);
                if (!res.Success)
                {
                    return(res);
                }

                var saveEntities = this.geneInsertSignMessageBox(msg);

                try
                {
                    messageboxService.db.BeginTran();

                    foreach (var saveEntity in saveEntities)
                    {
                        messageboxService.InsertIgnoreNullColumn(saveEntity);
                    }

                    messageboxService.db.Updateable(new SignMessageInterface
                    {
                        OID           = msg.interfaceOID,
                        handleresult  = 1,
                        handlemsgoids = getMessageBoxIds(saveEntities),
                        updatetime    = DateTime.Now
                    })
                    .UpdateColumns(t => new { t.handleresult, t.updatetime, t.handlemsgoids }).ExecuteCommand();

                    messageboxService.db.CommitTran();
                    return(new BizResult <List <SignMessageBox> >
                    {
                        Success = true,
                        Data = saveEntities
                    });
                }
                catch (Exception ex)
                {
                    messageboxService.db.RollbackTran();
                    return(new BizResult <List <SignMessageBox> >
                    {
                        Success = false,
                        Msg = ex.Message
                    });
                }
            }
            catch (Exception ex)
            {
                return(new BizResult <List <SignMessageBox> >
                {
                    Success = false,
                    Msg = ex.Message
                });
            }
        }