예제 #1
0
        /// <summary>
        /// 新增进度
        /// </summary>
        /// <param name="tbsms"></param>
        /// <returns></returns>
        public int Add(TbSMSAlert tbsms)
        {
            var count = Db.Context.Insert <TbSMSAlert>(tbsms);

            if (count > 0)
            {
                return(1);
            }
            return(0);
        }
예제 #2
0
        /// <summary>
        /// 已接收(还未领料)订单中的某种材料汇总重量≥当前库存重量的80%
        /// (即这些订单领料后,此种材料库存量会小于等于现有库存量的80%),系统发送预警信息给加工厂材料负责人,并以短信通知。
        /// </summary>
        public bool SendMsgForMaterialStockByOrderNew(int orderId)
        {
            try
            {
                List <TbFormEarlyWarningNodeInfo> myMsgList = new List <TbFormEarlyWarningNodeInfo>(); //Pc端推送
                List <TbSMSAlert> myDxList = new List <TbSMSAlert>();                                  //App端
                //查找订单信息
                var order = Repository <TbWorkOrder> .First(p => p.ID == orderId);

                if (order != null)
                {
                    //查找订单明细信息
                    var materialCodeList = Repository <TbWorkOrderDetail> .Query(p => p.OrderCode == order.OrderCode).Select(p => p.MaterialCode).ToList();

                    string         MaterialCodes = string.Join("','", materialCodeList);
                    SqlParameter[] par           = new SqlParameter[]
                    {
                        new SqlParameter("@MaterialCodeS", MaterialCodes),
                        new SqlParameter("@ProcessFactoryCode", order.ProcessFactoryCode),
                    };
                    var list = Db.Context.FromProc("MaterialTotalStockReport_Proc").AddParameter(par).ToList <MaterialTotalStockReportModel>();
                    if (list.Count > 0)
                    {
                        //筛选大于80%的数据,发送预警信息给加工厂材料负责人,并以短信通知
                        var dataList = list.Where(p => p.Point >= 80).ToList();
                        if (dataList.Count > 0)
                        {
                            //预警设置
                            var ewSstUp = Repository <TbEarlyWarningSetUp> .First(p => p.MenuCode == "RawMaterialStock" && p.IsStart == 1);

                            if (ewSstUp != null)
                            {
                                //查找短信模板信息
                                var smsTemp =
                                    Repository <TbShortMessageTemplate> .First(p => p.TemplateCode == "MB0010");

                                dataList.ForEach(x =>
                                {
                                    //短信内容
                                    string content   = smsTemp.TemplateContent;
                                    var ShortContent = content.Replace("变量:材料名称,规格", x.MaterialName + "," + x.SpecificationModel);
                                    //获取要发送短信通知消息的用户
                                    DataTable dt = ct.GetParentCompany(order.SiteCode);
                                    if (dt.Rows.Count > 0)
                                    {
                                        string ManagerDepartmentCode = "";
                                        string BranchCode            = "";
                                        string BranchName            = "";
                                        string WorkAreaCode          = "";
                                        string WorkAreaName          = "";
                                        string SiteName = "";
                                        for (int i = 0; i < dt.Rows.Count; i++)
                                        {
                                            if (dt.Rows[i]["OrgType"].ToString() == "2")
                                            {
                                                ManagerDepartmentCode = dt.Rows[i]["CompanyCode"].ToString();
                                            }
                                            else if (dt.Rows[i]["OrgType"].ToString() == "3")
                                            {
                                                BranchCode = dt.Rows[i]["CompanyCode"].ToString();
                                                BranchName = dt.Rows[i]["CompanyFullName"].ToString();
                                            }
                                            else if (dt.Rows[i]["OrgType"].ToString() == "4")
                                            {
                                                WorkAreaCode = dt.Rows[i]["CompanyCode"].ToString();
                                                WorkAreaName = dt.Rows[i]["CompanyFullName"].ToString();
                                            }
                                            else if (dt.Rows[i]["OrgType"].ToString() == "5")
                                            {
                                                SiteName = dt.Rows[i]["CompanyFullName"].ToString();
                                            }
                                        }
                                        List <CensusdemoTask.NotiecUser> listUser = ct.GetSendUser("WorkOrder", ewSstUp.EarlyWarningNewsCode, orderId);
                                        if (listUser.Any())
                                        {
                                            for (int i = 0; i < listUser.Count; i++)
                                            {
                                                if (ewSstUp.App == 1)
                                                {
                                                    //调用BIM获取人员电话或者身份证号码的的接口
                                                    string userInfo = ct.up(listUser[i].PersonnelCode);
                                                    var jObject     = Newtonsoft.Json.Linq.JObject.Parse(userInfo);
                                                    string tel      = jObject["data"][0]["MobilePhone"].ToString();
                                                    if (!string.IsNullOrWhiteSpace(tel))
                                                    {
                                                        var myDxMsg = new TbSMSAlert()
                                                        {
                                                            InsertTime        = DateTime.Now,
                                                            ManagerDepartment = ManagerDepartmentCode,
                                                            Branch            = BranchCode,
                                                            WorkArea          = WorkAreaCode,
                                                            Site         = "",
                                                            UserCode     = listUser[i].PersonnelCode,
                                                            UserTel      = tel,
                                                            DXType       = "",
                                                            BusinessCode = smsTemp.TemplateCode,
                                                            DataCode     = order.OrderCode,
                                                            ShortContent = ShortContent,
                                                            FromCode     = "WorkOrder",
                                                            MsgType      = "2"
                                                        };
                                                        myDxList.Add(myDxMsg);
                                                    }
                                                }
                                                if (ewSstUp.Pc == 1)
                                                {
                                                    var myMsg = new TbFormEarlyWarningNodeInfo()
                                                    {
                                                        MenuCode         = "WorkOrder",
                                                        EarlyWarningCode = ewSstUp.EarlyWarningNewsCode,
                                                        EWNodeCode       = ewSstUp.ID,
                                                        EWContent        = ShortContent,
                                                        EWUserCode       = listUser[i].PersonnelCode,
                                                        EWFormDataCode   = orderId,
                                                        EWStart          = 0,
                                                        WorkArea         = WorkAreaCode,
                                                        CompanyCode      = BranchCode,
                                                        SiteCode         = order.SiteCode,
                                                        EWTime           = DateTime.Now,
                                                        ProjectId        = order.ProjectId,
                                                        MsgType          = "2"
                                                    };
                                                    myMsgList.Add(myMsg);
                                                }
                                            }
                                        }
                                    }
                                });
                                for (int i = 0; i < myDxList.Count; i++)
                                {
                                    //调用短信发送接口
                                    //string dx = ct.ShortMessagePC(myDxList[i].UserTel, myDxList[i].ShortContent);
                                    string dx       = ct.ShortMessagePC("15756321745", myDxList[i].ShortContent);
                                    var    jObject1 = Newtonsoft.Json.Linq.JObject.Parse(dx);
                                    var    logmsg   = jObject1["data"][0]["code"].ToString();
                                    myDxList[i].DXType = logmsg;
                                }
                            }
                        }
                    }
                }
                using (DbTrans trans = Db.Context.BeginTransaction())
                {
                    if (myMsgList.Any())
                    {
                        Repository <TbFormEarlyWarningNodeInfo> .Insert(trans, myMsgList, true);
                    }
                    if (myDxList.Any())
                    {
                        Repository <TbSMSAlert> .Insert(trans, myDxList, true);
                    }
                    trans.Commit();
                    return(true);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }