/// <summary> /// /// </summary> /// <param name="list"></param> /// <param name="write_enum"></param> private void WriteInDB(List<SMSModel_QueryReceive> list,ref PMS.Model.Enum.WriteInDb_Enum write_enum) { IS_SMSRecord_CurrentBLL smsRecord_CurrentBLL = new PMS.BLL.S_SMSRecord_CurrentBLL(); //思路 /*尽量减少反复连接数据库的操作 先从list中提取msgid不同的对象 */ //1 查出不同的msgid集合(IEnmuerable) var list_distinct_msgid = from s in list.Distinct(new PMS.Model.EqualCompare.SMSModel_QueryReceive_Compare()) select s.msgId; write_enum = PMS.Model.Enum.WriteInDb_Enum.ok; //2 遍历 foreach (var item in list_distinct_msgid) { //2.1 取出对应msgid对应的集合 var list_temp = (from s in list where s.msgId == item select s).ToList(); //2.2批量写入 try { smsRecord_CurrentBLL.SaveReceieveMsg(list_temp,item); Console.WriteLine("写入成功{0}个人其对应msgid为{1}",list_temp.Count(),item); } catch (Exception ex) { write_enum =PMS.Model.Enum.WriteInDb_Enum.error; } } }
/// <summary> /// 根据msgid执行查询接收短信状态 /// </summary> /// <param name="msgid"></param> public void ToQuery(PMS.Model.QueryModel.Redis_SMSContent model) { if (model.msgid == string.Empty) { //ToShow("读取msgid错误"); return; } if (model.PhoneNums == string.Empty) { //ToShow("发送联系人列表为空"); return; } string account = "dh74381"; //账号"dh74381"; string passWord = "******";//密码 = "uAvb3Qey"; //6 查询发送状态(是否加入等待时间?) PMS.Model.SMSModel.SMSModel_Query queryMsg = new PMS.Model.SMSModel.SMSModel_Query() { account = account, password = passWord, smsId = model.msgid, //phoneNums=model.PhoneNums }; List<PMS.Model.SMSModel.SMSModel_QueryReceive> list_QueryReceive; ISMS.ISMSQuery smsQuery = new SMSFactory.SMSQuery(); bool isGetReturnMsg = smsQuery.QueryMsg(queryMsg, out list_QueryReceive); if (!isGetReturnMsg) { return; // return Content("服务器错误"); } //7 获取改次发送的SMSContent的ID IS_SMSContentBLL smsContentBLL = new PMS.BLL.S_SMSContentBLL(); var list = smsContentBLL.GetListBy(p => p.msgId.Equals(model.msgid)); if (list.Count() < 1) { return; } else { int scid = list.FirstOrDefault().ID; if (list_QueryReceive.Count() == 0) { //ToShow("当前取出的对象中接收内容有误"); return; } IS_SMSRecord_CurrentBLL smsRecord_CurrentBLL = new PMS.BLL.S_SMSRecord_CurrentBLL(); bool isSaveCurrnetMsgOk = smsRecord_CurrentBLL.SaveReceieveMsg(list_QueryReceive, scid); } }
/// <summary> /// 根据msgid执行查询接收短信状态 /// </summary> /// <param name="msgid"></param> public static void ToQuery(string msgid,out List<SMSModel_QueryReceive> list_queryReceive,out int state) { //IS_SMSRecord_CurrentBLL smsRecord_CurrentBLL = new PMS.BLL.S_SMSRecord_CurrentBLL(); //以后通过spring .net 实现 ISMSQuery smsQuery = new SMSFactory.SMSQuery(); IS_SMSContentBLL smsContentBLL = new PMS.BLL.S_SMSContentBLL(); IS_SMSRecord_CurrentBLL smsRecord_CurrentBLL = new PMS.BLL.S_SMSRecord_CurrentBLL(); string account = "dh74381"; //账号"dh74381"; string passWord = "******";//密码 = "uAvb3Qey"; //6 查询发送状态(是否加入等待时间?) SMSModel_Query queryMsg = new SMSModel_Query() { account = account, password = passWord, smsId = msgid, //phoneNums=model.PhoneNums }; List<SMSModel_QueryReceive> list_QueryReceive; //根据传入的信息进行查询,并有一个状态信息集合 bool isGetReturnMsg = smsQuery.QueryMsg(queryMsg, out list_QueryReceive); //根据传入的状态集合进行判断当前的状态 var index_state = 0;//smsQuery.GetQueryState(list_QueryReceive);此处已修改 //为变量赋值 list_queryReceive = list_QueryReceive; state = index_state; if (!isGetReturnMsg) { //查询结果有问题,跳出本次查询 state = 2; return; // return Content("服务器错误"); } //当查询返回的集合数量为1,且唯一的对象的desc为成功,则直接跳出,不进行下面的操作,并对state赋值为1 if (list_QueryReceive.Count() == 1 && list_queryReceive.FirstOrDefault().desc == "成功"&&list_queryReceive.FirstOrDefault().phoneNumber==null) { //返回的desc=成功 state = 1; //return; } //7 获取该次发送的SMSContent的ID var list = smsContentBLL.GetListBy(p => p.msgId.Equals(msgid)); int scid = list.FirstOrDefault().ID; //向数据库中写入本集合中的对象 bool isSaveCurrnetMsgOk = smsRecord_CurrentBLL.SaveReceieveMsg(list_QueryReceive, scid); if (list_QueryReceive.Count() == 0) { state = 99; //ToShow("当前取出的对象中接收内容有误"); //return; } }