Açıklama Yok

IVRWelcomeController.cs 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. using CallCenter.Utility;
  2. using CallCenterApi.Common;
  3. using CallCenterApi.DB;
  4. using CallCenterApi.Interface.Controllers.Base;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data;
  8. using System.Linq;
  9. using System.Web;
  10. using System.Web.Mvc;
  11. namespace CallCenterApi.Interface.Controllers
  12. {
  13. public class IVRWelcomeController : BaseController
  14. {
  15. BLL.T_Sys_IVRWords dBLL = new BLL.T_Sys_IVRWords();
  16. //获取IVR欢迎词列表
  17. public ActionResult GetList()
  18. {
  19. string sql = " and F_IsDel = 0 ";
  20. upstate();//更新过期的为失效状态
  21. DataTable dt = new DataTable();
  22. #region 获取参数
  23. string key = HttpUtility.UrlDecode(RequestString.GetQueryString("key"));
  24. string itemid = HttpUtility.UrlDecode(RequestString.GetQueryString("itemid"));
  25. string strbtime = HttpUtility.UrlDecode(RequestString.GetQueryString("btime"));
  26. string stretime = HttpUtility.UrlDecode(RequestString.GetQueryString("etime"));
  27. string strybtime = HttpUtility.UrlDecode(RequestString.GetQueryString("bytime"));
  28. string stryetime = HttpUtility.UrlDecode(RequestString.GetQueryString("eytime"));
  29. string state = HttpUtility.UrlDecode(RequestString.GetQueryString("state"));
  30. string strpageindex = RequestString.GetQueryString("page");
  31. int pageindex = 1;
  32. string strpagesize = RequestString.GetQueryString("pagesize");
  33. int pagesize = 10;
  34. #endregion
  35. #region 条件筛选
  36. if (key.Trim() != "" && key != "undefined")
  37. {
  38. sql += " and (F_Item like '%" + key.Trim() + "%' or F_Content like '%" + key.Trim() + "%' )";
  39. }
  40. if (itemid.Trim() != "" && itemid != "undefined")
  41. {
  42. sql += " and F_ItemID=" + itemid;
  43. }
  44. if (strbtime.Trim() != "" && strbtime != "undefined")
  45. {
  46. sql += " and F_CreateTime >= '" + Convert.ToDateTime(strbtime.Trim()).ToString("yyyy-MM-dd 00:00:00") + "' ";
  47. }
  48. if (stretime.Trim() != "" && stretime != "undefined")
  49. {
  50. sql += " and F_CreateTime <= '" + Convert.ToDateTime(stretime.Trim()).ToString("yyyy-MM-dd 23:59:59") + "' ";
  51. }
  52. if (state.Trim() != "" && state != "undefined")
  53. {
  54. //0未启动,1生效中,2已失效
  55. sql += " and F_IsState=" + state;
  56. }
  57. #region 有效期添加
  58. var sqlwb = "";
  59. var sqlwe = "";
  60. if (strybtime.Trim() != "" && strybtime != "undefined")
  61. {
  62. sqlwb = " ('" + strybtime.Trim() + "' between F_StartDate and F_EndDate) ";
  63. }
  64. if (stryetime.Trim() != "" && stryetime != "undefined")
  65. {
  66. sqlwe = " ('" + stryetime.Trim() + "' between F_StartDate and F_EndDate) ";
  67. }
  68. if (sqlwb != "" && sqlwe != "")
  69. {
  70. sql += " and (" + sqlwb + " or " + sqlwe + ")";
  71. }
  72. else
  73. {
  74. if (sqlwb != "")
  75. {
  76. sql += " and (" + sqlwb + ")";
  77. }
  78. else if (sqlwe != "")
  79. {
  80. sql += " and (" + sqlwe + ")";
  81. }
  82. }
  83. #endregion
  84. #endregion
  85. if (strpageindex.Trim() != "")
  86. {
  87. pageindex = Convert.ToInt32(strpageindex);
  88. }
  89. if (strpagesize.Trim() != "")
  90. {
  91. pagesize = Convert.ToInt32(strpagesize);
  92. }
  93. int recordCount = 0;
  94. dt = BLL.PagerBLL.GetListPager(
  95. "T_Sys_IVRWords",
  96. "F_ID",
  97. "*",
  98. sql,
  99. "ORDER BY F_ID desc",
  100. pagesize,
  101. pageindex,
  102. true,
  103. out recordCount);
  104. var config = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='ftpvoice' ").FirstOrDefault();
  105. foreach (DataRow dr in dt.Rows)
  106. {
  107. string path = dr["F_WavFileName"] != null ? dr["F_WavFileName"].ToString() : "";
  108. if (path != "" && config != null && !string.IsNullOrEmpty(config.F_ParamValue))
  109. {
  110. dr["F_WavPath"] = config.F_ParamValue + dr["F_WavFileName"].ToString();
  111. }
  112. }
  113. var obj = new
  114. {
  115. state = "success",
  116. message = "成功",
  117. rows = dt,
  118. total = recordCount
  119. };
  120. return Content(obj.ToJson());
  121. }
  122. //获取IVR欢迎词
  123. public ActionResult GetIVRWords(string id)
  124. {
  125. if (id != null && id.Trim() != "")
  126. {
  127. Model.T_Sys_IVRWords dModel = dBLL.GetModel(int.Parse(id.Trim()));
  128. var config = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='ftpvoice' ").FirstOrDefault();
  129. if (dModel.F_WavFileName != "" && config != null && !string.IsNullOrEmpty(config.F_ParamValue))
  130. {
  131. dModel.F_WavPath = config.F_ParamValue + dModel.F_WavFileName;
  132. }
  133. if (dModel != null)
  134. {
  135. return Success("获取IVR欢迎词成功", dModel);
  136. }
  137. else
  138. {
  139. return Error("获取IVR欢迎词失败");
  140. }
  141. }
  142. else
  143. {
  144. return Error("获取参数失败");
  145. }
  146. }
  147. //添加IVR欢迎词
  148. public ActionResult AddIVRWords(string id,string itemid, string item,
  149. string sdate, string edate, string remark,
  150. string filename, string loadpath, string path, int type=2, int isstate=0)
  151. {
  152. bool res = false;
  153. int iss = returnisadd(id, itemid, sdate, edate);
  154. if (iss <= 0)
  155. {
  156. Model.T_Sys_IVRWords dModel = new Model.T_Sys_IVRWords();
  157. if (id != null && id.Trim() != "")
  158. {
  159. dModel = dBLL.GetModel(int.Parse(id.Trim()));
  160. if (dModel == null)
  161. {
  162. return Error("此对象获取失败,请刷新后再试!");
  163. }
  164. }
  165. dModel.F_Item = item.Trim();
  166. dModel.F_ItemID = Utils.StrToInt(itemid, 0);
  167. // dModel.F_Content = content.Trim();
  168. dModel.F_IsState = isstate;
  169. dModel.F_StartDate = Utils.StrToDateTime(sdate, DateTime.Now);
  170. dModel.F_EndDate = Utils.StrToDateTime(edate, DateTime.Now);
  171. dModel.F_Remark = remark.Trim();
  172. dModel.F_Type = 2;//1文本,2语音文件
  173. if (type == 2)
  174. {
  175. dModel.F_WavFileName = filename;
  176. dModel.F_WavLoadPath = loadpath;
  177. dModel.F_WavPath = path;
  178. }
  179. if (id != null && id.Trim() != "")
  180. {
  181. res = dBLL.Update(dModel);
  182. }
  183. else
  184. {
  185. dModel.F_IsDel = 0;
  186. dModel.F_CreateUser = CurrentUser.UserData.F_UserCode;
  187. dModel.F_CreateTime = DateTime.Now;
  188. int b = dBLL.Add(dModel);
  189. res = b > 0;
  190. }
  191. }
  192. if (res)
  193. {
  194. return Success("保存IVR欢迎词成功");
  195. }
  196. else
  197. {
  198. if (iss > 0)
  199. {
  200. return Error("存在已启动的IVR欢迎词在此有效期间,请查看记录后另外选择有效期!");
  201. }
  202. else
  203. {
  204. return Error("保存IVR欢迎词失败");
  205. }
  206. }
  207. }
  208. //删除IVR欢迎词
  209. public ActionResult DelIVRWords(string[] ids)
  210. {
  211. if (ids != null && ids.Length > 0)
  212. {
  213. string idd = " ";
  214. foreach (string str in ids)
  215. {
  216. idd += str + ",";
  217. }
  218. if (dBLL.DeleteList(idd.TrimEnd(','), CurrentUser.UserData.F_UserCode))
  219. {
  220. return Success("删除成功");
  221. }
  222. else
  223. return Error("删除失败");
  224. }
  225. else
  226. {
  227. return Error("请选择要删除的记录");
  228. }
  229. }
  230. //获取ivr欢迎词是否有添加权限
  231. private int returnisadd(string id,string itemid, string sdate, string edate)
  232. {
  233. DateTime ssdate = Utils.StrToDateTime(sdate, DateTime.Now);
  234. DateTime eedate = Utils.StrToDateTime(edate, DateTime.Now);
  235. string sql = " isnull(F_IsState,0)=1 and F_IsDel = 0 ";//生效中状态
  236. if (id != null && id != "")
  237. {
  238. sql += " and F_ID<>" + id;
  239. }
  240. if (itemid != null && itemid != "")
  241. {
  242. sql += " and F_ItemID<>" + itemid;
  243. }
  244. sql += " and( "
  245. + "('" + ssdate.ToString("yyyy-MM-dd HH:mm:ss") + "' between F_StartDate and F_EndDate) "
  246. + "or ('" + eedate.ToString("yyyy-MM-dd HH:mm:ss") + "' between F_StartDate and F_EndDate) "
  247. + ")";
  248. return dBLL.GetRecordCount(sql);
  249. }
  250. private void upstate()
  251. {
  252. string sql = " update T_Sys_IVRWords set F_IsState=2 ";
  253. sql += " where isnull(F_IsState,0)=1 and F_IsDel = 0 ";//启动状态
  254. sql += " and F_EndDate<getdate()";
  255. DbHelperSQL.ExecuteSql(sql);
  256. }
  257. //上传音频文件,并修改为系统需要的格式
  258. public ActionResult UploadWav()
  259. {
  260. HttpPostedFile _upFile = RequestString.GetFile("upFile");
  261. if (_upFile != null)
  262. {
  263. string datename = DateTime.Now.ToString("yyyyMMddHHMMss");
  264. string fullFileName = datename + "_" + _upFile.FileName;
  265. string ffmpegLocation = Server.MapPath("~/");
  266. #region 读取配置的上传路径-原文件和修改过格式的文件均上传至此
  267. string savedir = Configs.GetValue("saveloc");
  268. if (!System.IO.Directory.Exists(savedir))
  269. {
  270. System.IO.Directory.CreateDirectory(savedir);
  271. }
  272. #endregion
  273. #region 保存原文件到项目中
  274. string path = this.Request.ApplicationPath + "/uploadwav/" + fullFileName;
  275. if (!System.IO.Directory.Exists(Server.MapPath(this.Request.ApplicationPath + "/uploadwav/")))
  276. {
  277. System.IO.Directory.CreateDirectory(Server.MapPath(this.Request.ApplicationPath + "/uploadwav/"));
  278. }
  279. string physicalpath = Server.MapPath(path);
  280. _upFile.SaveAs(physicalpath);
  281. #endregion
  282. #region 保存文件到指定目录中和项目中
  283. if (!string.IsNullOrEmpty(physicalpath))
  284. {
  285. #region 上传
  286. uploadFile upfile = new uploadFile();
  287. //通过读取配置文件,获取数据库
  288. string _ftp = Configs.GetValue("ftp");
  289. string _acc = Configs.GetValue("account");
  290. string _pwd = Configs.GetValue("password");
  291. upfile.ftpPath = _ftp;
  292. upfile.ftpUserID = _acc;
  293. upfile.ftpPassword = _pwd;
  294. string uploadBeforres = upfile.UploadLocalToFtp(physicalpath);
  295. if (uploadBeforres == "上传成功!")
  296. {
  297. #region 写入日志
  298. Model.T_Sys_Accessories model_T_Sys_Accessories = new Model.T_Sys_Accessories();
  299. model_T_Sys_Accessories.F_AddTime = DateTime.Now;//上传时间
  300. model_T_Sys_Accessories.F_FileName = fullFileName;//附件名称
  301. model_T_Sys_Accessories.F_FileType = ".wav";//附件类型
  302. model_T_Sys_Accessories.F_FileUrl = savedir + fullFileName + ".wav";//附件地址
  303. //model_T_Sys_Accessories.F_Size = size;
  304. model_T_Sys_Accessories.F_UserCode = CurrentUser.UserData.F_UserCode;//上传人
  305. int fid = new BLL.T_Sys_Accessories().Add(model_T_Sys_Accessories);
  306. #endregion
  307. var obj = new
  308. {
  309. filename = fullFileName,
  310. loadpath = path + ".wav",
  311. wavpath = savedir + fullFileName + ".wav"
  312. };
  313. return Success("文件上传成功", obj);
  314. }
  315. else
  316. return Error("文件上传失败,请重新上传::::::::uploadBeforres::" + uploadBeforres);
  317. #endregion
  318. }
  319. else
  320. return Error("格式修改出错,请重新上传");
  321. #endregion
  322. }
  323. return Error("参数传入失败");
  324. }
  325. }
  326. }