| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352 |
- using CallCenter.Utility;
- using CallCenterApi.Common;
- using CallCenterApi.DB;
- using CallCenterApi.Interface.Controllers.Base;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- namespace CallCenterApi.Interface.Controllers
- {
- public class IVRWelcomeController : BaseController
- {
- BLL.T_Sys_IVRWords dBLL = new BLL.T_Sys_IVRWords();
- //获取IVR欢迎词列表
- public ActionResult GetList()
- {
- string sql = " and F_IsDel = 0 ";
- upstate();//更新过期的为失效状态
- DataTable dt = new DataTable();
- #region 获取参数
- string key = HttpUtility.UrlDecode(RequestString.GetQueryString("key"));
- string itemid = HttpUtility.UrlDecode(RequestString.GetQueryString("itemid"));
- string strbtime = HttpUtility.UrlDecode(RequestString.GetQueryString("btime"));
- string stretime = HttpUtility.UrlDecode(RequestString.GetQueryString("etime"));
- string strybtime = HttpUtility.UrlDecode(RequestString.GetQueryString("bytime"));
- string stryetime = HttpUtility.UrlDecode(RequestString.GetQueryString("eytime"));
- string state = HttpUtility.UrlDecode(RequestString.GetQueryString("state"));
- string strpageindex = RequestString.GetQueryString("page");
- int pageindex = 1;
- string strpagesize = RequestString.GetQueryString("pagesize");
- int pagesize = 10;
- #endregion
- #region 条件筛选
- if (key.Trim() != "" && key != "undefined")
- {
- sql += " and (F_Item like '%" + key.Trim() + "%' or F_Content like '%" + key.Trim() + "%' )";
- }
- if (itemid.Trim() != "" && itemid != "undefined")
- {
- sql += " and F_ItemID=" + itemid;
- }
- if (strbtime.Trim() != "" && strbtime != "undefined")
- {
- sql += " and F_CreateTime >= '" + Convert.ToDateTime(strbtime.Trim()).ToString("yyyy-MM-dd 00:00:00") + "' ";
- }
- if (stretime.Trim() != "" && stretime != "undefined")
- {
- sql += " and F_CreateTime <= '" + Convert.ToDateTime(stretime.Trim()).ToString("yyyy-MM-dd 23:59:59") + "' ";
- }
- if (state.Trim() != "" && state != "undefined")
- {
- //0未启动,1生效中,2已失效
- sql += " and F_IsState=" + state;
- }
- #region 有效期添加
- var sqlwb = "";
- var sqlwe = "";
- if (strybtime.Trim() != "" && strybtime != "undefined")
- {
- sqlwb = " ('" + strybtime.Trim() + "' between F_StartDate and F_EndDate) ";
- }
- if (stryetime.Trim() != "" && stryetime != "undefined")
- {
- sqlwe = " ('" + stryetime.Trim() + "' between F_StartDate and F_EndDate) ";
- }
- if (sqlwb != "" && sqlwe != "")
- {
- sql += " and (" + sqlwb + " or " + sqlwe + ")";
- }
- else
- {
- if (sqlwb != "")
- {
- sql += " and (" + sqlwb + ")";
- }
- else if (sqlwe != "")
- {
- sql += " and (" + sqlwe + ")";
- }
- }
- #endregion
- #endregion
- if (strpageindex.Trim() != "")
- {
- pageindex = Convert.ToInt32(strpageindex);
- }
- if (strpagesize.Trim() != "")
- {
- pagesize = Convert.ToInt32(strpagesize);
- }
- int recordCount = 0;
- dt = BLL.PagerBLL.GetListPager(
- "T_Sys_IVRWords",
- "F_ID",
- "*",
- sql,
- "ORDER BY F_ID desc",
- pagesize,
- pageindex,
- true,
- out recordCount);
- var config = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='ftpvoice' ").FirstOrDefault();
- foreach (DataRow dr in dt.Rows)
- {
- string path = dr["F_WavFileName"] != null ? dr["F_WavFileName"].ToString() : "";
- if (path != "" && config != null && !string.IsNullOrEmpty(config.F_ParamValue))
- {
- dr["F_WavPath"] = config.F_ParamValue + dr["F_WavFileName"].ToString();
- }
- }
- var obj = new
- {
- state = "success",
- message = "成功",
- rows = dt,
- total = recordCount
- };
- return Content(obj.ToJson());
- }
- //获取IVR欢迎词
- public ActionResult GetIVRWords(string id)
- {
- if (id != null && id.Trim() != "")
- {
- Model.T_Sys_IVRWords dModel = dBLL.GetModel(int.Parse(id.Trim()));
- var config = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='ftpvoice' ").FirstOrDefault();
- if (dModel.F_WavFileName != "" && config != null && !string.IsNullOrEmpty(config.F_ParamValue))
- {
- dModel.F_WavPath = config.F_ParamValue + dModel.F_WavFileName;
- }
- if (dModel != null)
- {
- return Success("获取IVR欢迎词成功", dModel);
- }
- else
- {
- return Error("获取IVR欢迎词失败");
- }
- }
- else
- {
- return Error("获取参数失败");
- }
- }
- //添加IVR欢迎词
- public ActionResult AddIVRWords(string id,string itemid, string item,
- string sdate, string edate, string remark,
- string filename, string loadpath, string path, int type=2, int isstate=0)
- {
- bool res = false;
- int iss = returnisadd(id, itemid, sdate, edate);
- if (iss <= 0)
- {
- Model.T_Sys_IVRWords dModel = new Model.T_Sys_IVRWords();
- if (id != null && id.Trim() != "")
- {
- dModel = dBLL.GetModel(int.Parse(id.Trim()));
- if (dModel == null)
- {
- return Error("此对象获取失败,请刷新后再试!");
- }
- }
- dModel.F_Item = item.Trim();
- dModel.F_ItemID = Utils.StrToInt(itemid, 0);
- // dModel.F_Content = content.Trim();
- dModel.F_IsState = isstate;
- dModel.F_StartDate = Utils.StrToDateTime(sdate, DateTime.Now);
- dModel.F_EndDate = Utils.StrToDateTime(edate, DateTime.Now);
- dModel.F_Remark = remark.Trim();
- dModel.F_Type = 2;//1文本,2语音文件
- if (type == 2)
- {
- dModel.F_WavFileName = filename;
- dModel.F_WavLoadPath = loadpath;
- dModel.F_WavPath = path;
- }
- if (id != null && id.Trim() != "")
- {
- res = dBLL.Update(dModel);
- }
- else
- {
- dModel.F_IsDel = 0;
- dModel.F_CreateUser = CurrentUser.UserData.F_UserCode;
- dModel.F_CreateTime = DateTime.Now;
- int b = dBLL.Add(dModel);
- res = b > 0;
- }
- }
- if (res)
- {
- return Success("保存IVR欢迎词成功");
- }
- else
- {
- if (iss > 0)
- {
- return Error("存在已启动的IVR欢迎词在此有效期间,请查看记录后另外选择有效期!");
- }
- else
- {
- return Error("保存IVR欢迎词失败");
- }
- }
- }
- //删除IVR欢迎词
- public ActionResult DelIVRWords(string[] ids)
- {
- if (ids != null && ids.Length > 0)
- {
- string idd = " ";
- foreach (string str in ids)
- {
- idd += str + ",";
- }
- if (dBLL.DeleteList(idd.TrimEnd(','), CurrentUser.UserData.F_UserCode))
- {
- return Success("删除成功");
- }
- else
- return Error("删除失败");
- }
- else
- {
- return Error("请选择要删除的记录");
- }
- }
- //获取ivr欢迎词是否有添加权限
- private int returnisadd(string id,string itemid, string sdate, string edate)
- {
- DateTime ssdate = Utils.StrToDateTime(sdate, DateTime.Now);
- DateTime eedate = Utils.StrToDateTime(edate, DateTime.Now);
- string sql = " isnull(F_IsState,0)=1 and F_IsDel = 0 ";//生效中状态
- if (id != null && id != "")
- {
- sql += " and F_ID<>" + id;
- }
- if (itemid != null && itemid != "")
- {
- sql += " and F_ItemID<>" + itemid;
- }
- sql += " and( "
- + "('" + ssdate.ToString("yyyy-MM-dd HH:mm:ss") + "' between F_StartDate and F_EndDate) "
- + "or ('" + eedate.ToString("yyyy-MM-dd HH:mm:ss") + "' between F_StartDate and F_EndDate) "
- + ")";
- return dBLL.GetRecordCount(sql);
- }
- private void upstate()
- {
- string sql = " update T_Sys_IVRWords set F_IsState=2 ";
- sql += " where isnull(F_IsState,0)=1 and F_IsDel = 0 ";//启动状态
- sql += " and F_EndDate<getdate()";
- DbHelperSQL.ExecuteSql(sql);
- }
- //上传音频文件,并修改为系统需要的格式
- public ActionResult UploadWav()
- {
- HttpPostedFile _upFile = RequestString.GetFile("upFile");
- if (_upFile != null)
- {
- string datename = DateTime.Now.ToString("yyyyMMddHHMMss");
- string fullFileName = datename + "_" + _upFile.FileName;
- string ffmpegLocation = Server.MapPath("~/");
- #region 读取配置的上传路径-原文件和修改过格式的文件均上传至此
- string savedir = Configs.GetValue("saveloc");
- if (!System.IO.Directory.Exists(savedir))
- {
- System.IO.Directory.CreateDirectory(savedir);
- }
- #endregion
- #region 保存原文件到项目中
- string path = this.Request.ApplicationPath + "/uploadwav/" + fullFileName;
- if (!System.IO.Directory.Exists(Server.MapPath(this.Request.ApplicationPath + "/uploadwav/")))
- {
- System.IO.Directory.CreateDirectory(Server.MapPath(this.Request.ApplicationPath + "/uploadwav/"));
- }
- string physicalpath = Server.MapPath(path);
- _upFile.SaveAs(physicalpath);
- #endregion
- #region 保存文件到指定目录中和项目中
- if (!string.IsNullOrEmpty(physicalpath))
- {
- #region 上传
- uploadFile upfile = new uploadFile();
- //通过读取配置文件,获取数据库
- string _ftp = Configs.GetValue("ftp");
- string _acc = Configs.GetValue("account");
- string _pwd = Configs.GetValue("password");
- upfile.ftpPath = _ftp;
- upfile.ftpUserID = _acc;
- upfile.ftpPassword = _pwd;
- string uploadBeforres = upfile.UploadLocalToFtp(physicalpath);
- if (uploadBeforres == "上传成功!")
- {
- #region 写入日志
- Model.T_Sys_Accessories model_T_Sys_Accessories = new Model.T_Sys_Accessories();
- model_T_Sys_Accessories.F_AddTime = DateTime.Now;//上传时间
- model_T_Sys_Accessories.F_FileName = fullFileName;//附件名称
- model_T_Sys_Accessories.F_FileType = ".wav";//附件类型
- model_T_Sys_Accessories.F_FileUrl = savedir + fullFileName + ".wav";//附件地址
- //model_T_Sys_Accessories.F_Size = size;
- model_T_Sys_Accessories.F_UserCode = CurrentUser.UserData.F_UserCode;//上传人
- int fid = new BLL.T_Sys_Accessories().Add(model_T_Sys_Accessories);
- #endregion
- var obj = new
- {
- filename = fullFileName,
- loadpath = path + ".wav",
- wavpath = savedir + fullFileName + ".wav"
- };
- return Success("文件上传成功", obj);
- }
- else
- return Error("文件上传失败,请重新上传::::::::uploadBeforres::" + uploadBeforres);
- #endregion
- }
- else
- return Error("格式修改出错,请重新上传");
- #endregion
- }
- return Error("参数传入失败");
- }
- }
- }
|