using CRM.Core.Model.Entity; using System; using System.Collections.Generic; using System.Linq; using WX.CRM.Common; namespace CRM.Core.BLL.Voice { public class Voice_BL { //查询是否已经有了 record记录 public Voice_Aliyun_Return GetRecord(string file_md5) { using (var db = new zxdContext()) { var model = db.Voice_Aliyun_Return.FirstOrDefault(p => p.file_md5 == file_md5); return model; } } public List GetReceive(string file_md5) { using (var db = new zxdContext()) { return db.Voice_Receive.Where(m => m.file_md5 == file_md5).ToList(); } } //插入历史日志 public bool InsertLog(Voice_ReceiveHis model) { bool result = true; try { using (var db = new zxdContext()) { model.transtime = DateTime.Now; db.Voice_ReceiveHis.Add(model); db.SaveChanges(); } DeleteReceive(model.id); } catch (Exception e) { result = false; LogHelper.Error(e); } return result; } public bool DeleteReceive(int id) { bool result = true; try { using (var db = new zxdContext()) { var entry = db.Voice_Receive.FirstOrDefault(m => m.id == id); if (entry != null) { db.Voice_Receive.Remove(entry);//将数据转移到历史表 } db.SaveChanges(); } } catch (Exception e) { result = false; LogHelper.Error(e); } return result; } //插入历史日志 public bool InsertReceive(Voice_Receive model, ref ValidationErrors errors, ref int id) { bool result = true; try { using (var db = new zxdContext()) { model.ctime = DateTime.Now; db.Voice_Receive.Add(model); db.SaveChanges(); id = model.id; } } catch (Exception e) { result = false; LogHelper.Error(e); errors.Add(e.ToString()); } return result; } public bool RequestInsert(Voice_Aliyun_Request model, ref ValidationErrors errors) { bool result = true; try { using (var db = new zxdContext()) { model.ctime = DateTime.Now; db.Voice_Aliyun_Request.Add(model); db.SaveChanges(); } } catch (Exception e) { result = false; LogHelper.Error(e); errors.Add(e.ToString()); } return result; } /// /// 获取请求记录 /// /// /// public Voice_Aliyun_Request GetRequest(string taskid) { using (var db = new zxdContext()) { var model = db.Voice_Aliyun_Request.FirstOrDefault(p => p.TaskId == taskid); return model; } } public bool IsNeedAddNewRequest(string filemd5) { using (var db = new zxdContext()) { DateTime time = DateTime.Now.AddMinutes(-10);//超过了十分钟没有返回,就不管了 int acount = db.Voice_Aliyun_Request.Where(m => m.file_md5 == filemd5 && m.isReturnBack == 0 && m.ctime > time).Count(); return acount == 0 ? true : false; } } /// /// 获取请求记录 /// /// /// public bool ReturnRequest(Voice_Aliyun_Request info) { using (var db = new zxdContext()) { var model = db.Voice_Aliyun_Request.FirstOrDefault(p => p.id == info.id); if (model == null) return false; model.isReturnBack = 1; model.retruntime = DateTime.Now; db.SaveChanges(); return true; } } public bool RetrunSuccedInsert(Voice_Aliyun_Return model) { bool result = true; try { using (var db = new zxdContext()) { model.ctime = DateTime.Now; db.Voice_Aliyun_Return.Add(model); db.SaveChanges(); } } catch (Exception e) { result = false; LogHelper.Error(e); } return result; } public bool RetrunErroInsert(Voice_Aliyun_Return_Erro model) { bool result = true; try { using (var db = new zxdContext()) { model.ctime = DateTime.Now; db.Voice_Aliyun_Return_Erro.Add(model); db.SaveChanges(); } } catch (Exception e) { result = false; LogHelper.Error(e); } return result; } /// /// 语音服务配置 /// /// public List GetConfigList() { using (var db = new zxdContext()) { return db.Voice_Config.Where(m => m.status == 1).ToList(); } } } }