Açıklama Yok

HotspotGlossaryController.cs 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. using CallCenter.Utility;
  2. using CallCenterApi.Interface.Controllers.Base;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Web;
  8. using System.Web.Mvc;
  9. namespace CallCenterApi.Interface.Controllers.Wiki
  10. {
  11. [Authority]
  12. public class HotspotGlossaryController : BaseController
  13. {
  14. // GET: HotspotGlossary
  15. /// <summary>
  16. /// 上传附件
  17. /// </summary>
  18. /// <returns></returns>
  19. public ActionResult UploadFile()
  20. {
  21. HttpFileCollection files = RequestString.GetFiles();
  22. if (files.Count > 0)
  23. {
  24. List<Model.T_Sys_Accessories> acs = new List<Model.T_Sys_Accessories>();
  25. string path = "/Upload/Wiki/" + DateTime.Now.ToString("yyyy") + "/" + DateTime.Now.ToString("MM") + "/" + DateTime.Now.ToString("dd") + "/";
  26. for (int i = 0; i < files.Count; i++)
  27. {
  28. HttpPostedFile file = files[i];
  29. FileUp fu = new FileUp();
  30. string name = fu.Upload(file, path);
  31. Model.T_Sys_Accessories model_T_Sys_Accessories = new Model.T_Sys_Accessories();
  32. model_T_Sys_Accessories.F_AddTime = DateTime.Now;//上传时间
  33. model_T_Sys_Accessories.F_FileName = name;//附件名称
  34. model_T_Sys_Accessories.F_FileType = System.IO.Path.GetExtension(file.FileName);//附件类型
  35. model_T_Sys_Accessories.F_FileUrl = path + name;//附件地址
  36. model_T_Sys_Accessories.F_Size = file.ContentLength;
  37. model_T_Sys_Accessories.F_UserCode = User.F_UserCode;//上传人
  38. int id = new BLL.T_Sys_Accessories().Add(model_T_Sys_Accessories);
  39. model_T_Sys_Accessories.F_FileId = id;
  40. acs.Add(model_T_Sys_Accessories);
  41. }
  42. return Success("成功", acs);
  43. }
  44. else
  45. {
  46. return Error("请选择要上传的文件");
  47. }
  48. }
  49. /// <summary>
  50. /// 列表
  51. /// </summary>
  52. /// <param name="page"></param>
  53. /// <param name="pagesize"></param>
  54. /// <param name="isdc"></param>
  55. /// <returns></returns>
  56. public ActionResult GetList(string keyvalue, string stime, string etime, int key = 0, int page = 1, int pagesize = 10, int isdc = 0)
  57. {
  58. DataTable dt = new DataTable();
  59. string sql = " and F_IsDelete=0 ";
  60. string sqldt = "";
  61. if (stime.Trim() != "" && stime != "undefined")
  62. {
  63. sql += " and F_FaBuShiJian >= '" + stime + " 00:00:00" + "' ";
  64. }
  65. if (etime.Trim() != "" && etime != "undefined")
  66. {
  67. sql += " and F_FaBuShiJian <= '" + etime + " 23:59:59" + "' ";
  68. }
  69. if (key > 0)
  70. {
  71. //sql += " and F_Key = " + key;
  72. sqldt = " INNER JOIN [GetValueId]('" + key + "') Value on a.F_Key = Value.F_ValueId";
  73. }
  74. if (!string.IsNullOrEmpty(keyvalue))
  75. {
  76. sql += " and (F_ZhengCeMingCi like '%" + keyvalue + "%' or F_QiTaShuoMing like '%" + keyvalue + "%' or F_BanLiLiuCheng like '%" + keyvalue + "%' or F_BeiZhu like '%" + keyvalue + "%')";
  77. }
  78. if (isdc > 0)
  79. {
  80. string cols = "(case when a.F_Id <100 then RIGHT ('00'+CONVERT (varchar(10),a.F_Id),3) else CONVERT(varchar(10), a.F_Id) end) as 序号,F_HangYe as 所属行业 ,F_ReDianWenTi as 热点问题,F_WenTiJieDa as 内容解答,F_ZhengCeMingCi as 政策名称,F_JieDaDanWei as 解答单位,F_FaWenWenHao as 发文文号,F_FaWenDanWei as 发文单位,F_ShengXiaoShiJian as 生效时间,F_ShiXiaoShiJian as 失效时间,dbo.GetKeyNames(F_Key) as 四级关键词,F_FaBuShiJian as 发布时间,F_FaBuRen as 发布人,F_FaBuDanWei as 发布单位,F_BiaoShiBianMa as 标识编码,(select stuff((select ',' + F_FileName from T_Sys_Accessories where F_FileId in (a.F_File) for xml path('')),1,1,'')) as 附件,地区 as F_DiQu";
  81. var dtdc = DB.DbHelperSQL.Query(" select " + cols + " from T_Wiki_HotspotGlossary a with(nolock) " + sqldt + " where 1=1 " + sql).Tables[0];
  82. var msg = new NPOIHelper().ExportToExcel("热点问题", dtdc);
  83. if (msg == "")
  84. {
  85. return Success("导出成功");
  86. }
  87. else
  88. {
  89. return Error("导出失败");
  90. }
  91. }
  92. int recordCount = 0;
  93. dt = BLL.PagerBLL.GetListPager(
  94. "T_Wiki_HotspotGlossary a with(nolock) " + sqldt,
  95. "F_Id",
  96. "a.*,dbo.GetDictionaryName(F_Key) as KeyName",
  97. sql,
  98. "ORDER BY F_DianJiLiang,F_CreateTime DESC",
  99. pagesize,
  100. page,
  101. true,
  102. out recordCount);
  103. var obj = new
  104. {
  105. state = "success",
  106. message = "成功",
  107. rows = dt,
  108. total = recordCount
  109. };
  110. return Content(obj.ToJson());
  111. }
  112. /// <summary>
  113. /// 获取
  114. /// </summary>
  115. /// <param name="id"></param>
  116. /// <returns></returns>
  117. public ActionResult GetModel(int id = 0)
  118. {
  119. if (id != 0)
  120. {
  121. var model = new BLL.T_Wiki_HotspotGlossary().GetModel(id);
  122. if (model != null)
  123. {
  124. DB.DbHelperSQL.ExecuteSql(" update T_Wiki_HotspotGlossary set F_DianJiLiang=F_DianJiLiang+1 where F_Id=" + id);
  125. DataTable dtkey = new DataTable();
  126. if (model.F_Key > 0)
  127. {
  128. dtkey = DB.DbHelperSQL.Query(" select * from View_KeysSplit where id=" + model.F_Key).Tables[0];
  129. }
  130. DataTable dtfile = new DataTable();
  131. var configfj = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='FileUrlPath' ").FirstOrDefault();
  132. if (!string.IsNullOrEmpty(model.F_File) && configfj != null)
  133. {
  134. dtfile = DB.DbHelperSQL.Query("select * from T_Sys_Accessories WITH(NOLOCK) where F_FileId in (" + model.F_File + ")").Tables[0];
  135. foreach (DataRow dr in dtfile.Rows)
  136. {
  137. dr["F_FileUrl"] = configfj.F_ParamValue + dr["F_FileUrl"].ToString();
  138. }
  139. }
  140. var obj = new { model, dtkey, dtfile };
  141. return Success("成功", obj);
  142. }
  143. return Error("参数错误");
  144. }
  145. else
  146. {
  147. return Error("参数错误");
  148. }
  149. }
  150. /// <summary>
  151. /// 添加
  152. /// </summary>
  153. /// <param name="input"></param>
  154. /// <returns></returns>
  155. [HttpPost]
  156. public ActionResult AddModel(int id = 0, int key = 0)
  157. {
  158. string fabudanwei = RequestString.GetFormString("fabudanwei");
  159. string faburen = RequestString.GetFormString("faburen");
  160. string hangye = RequestString.GetFormString("hangye");
  161. string diqu = RequestString.GetFormString("diqu");
  162. string shengxiaoshijian = RequestString.GetFormString("shengxiaoshijian");
  163. string shixiaoshijian = RequestString.GetFormString("shixiaoshijian");
  164. string fabushijian = RequestString.GetFormString("fabushijian");
  165. string fawenwenhao = RequestString.GetFormString("fawenwenhao");
  166. string fawendanwei = RequestString.GetFormString("fawendanwei");
  167. string biaoshibianma = RequestString.GetFormString("biaoshibianma");
  168. string jiedadanwei = RequestString.GetFormString("jiedadanwei");
  169. string zhengcemingci = RequestString.GetFormString("zhengcemingci");
  170. string file = RequestString.GetFormString("file");
  171. string redianwenti = RequestString.GetFormString("redianwenti");
  172. string wentijieda = RequestString.GetFormString("wentijieda");
  173. Model.T_Wiki_HotspotGlossary dModel = new Model.T_Wiki_HotspotGlossary();
  174. if (id == 0)
  175. {
  176. dModel.F_FaBuRen = User .F_UserName ;
  177. dModel.F_FaBuDanWei = fabudanwei;
  178. dModel.F_HangYe = hangye;
  179. dModel.F_DiQu = diqu;
  180. try
  181. {
  182. dModel.F_ShengXiaoShiJian = DateTime.Parse(shengxiaoshijian);
  183. }
  184. catch { };
  185. try
  186. {
  187. dModel.F_ShiXiaoShiJian = DateTime.Parse(shixiaoshijian);
  188. }
  189. catch { };
  190. dModel.F_FaBuShiJian = DateTime.Now;
  191. dModel.F_Key = key;
  192. dModel.F_FaWenWenHao = DateTime .Now .ToString ("yyyyMMddHHmmssff");
  193. dModel.F_FaWenDanWei = fawendanwei;
  194. dModel.F_JieDaDanWei = jiedadanwei;
  195. dModel.F_ZhengCeMingCi = zhengcemingci;
  196. dModel.F_File = file;
  197. dModel.F_ReDianWenTi = redianwenti;
  198. dModel.F_WenTiJieDa = wentijieda;
  199. dModel.F_DianJiLiang = 0;
  200. dModel.F_IsDelete = 0;
  201. dModel.F_CreateUser = User.F_UserCode;
  202. dModel.F_CreateTime = DateTime.Now;
  203. int n = new BLL.T_Wiki_HotspotGlossary().Add(dModel);
  204. if (n > 0)
  205. {
  206. DB.DbHelperSQL.ExecuteSql("update T_Wiki_HotspotGlossary set F_BiaoShiBianMa =right('00000'+'" + User.F_DeptId + "' ,5)+right('0000000'+'" + n + "' ,8) where F_Id=" + n);
  207. return Success("添加成功", n);
  208. }
  209. else
  210. return Error("添加失败");
  211. //}
  212. }
  213. else
  214. {
  215. dModel = new BLL.T_Wiki_HotspotGlossary().GetModel(id);
  216. if (dModel != null)
  217. {
  218. dModel.F_FaBuRen = faburen;
  219. dModel.F_FaBuDanWei = fabudanwei;
  220. dModel.F_HangYe = hangye;
  221. dModel.F_DiQu = diqu;
  222. try
  223. {
  224. dModel.F_ShengXiaoShiJian = DateTime.Parse(shengxiaoshijian);
  225. }
  226. catch { };
  227. try
  228. {
  229. dModel.F_ShiXiaoShiJian = DateTime.Parse(shixiaoshijian);
  230. }
  231. catch { };
  232. try
  233. {
  234. dModel.F_FaBuShiJian = DateTime.Parse(fabushijian);
  235. }
  236. catch { };
  237. dModel.F_Key = key;
  238. dModel.F_FaWenWenHao = fawenwenhao;
  239. dModel.F_FaWenDanWei = fawendanwei;
  240. dModel.F_BiaoShiBianMa = biaoshibianma;
  241. dModel.F_JieDaDanWei = jiedadanwei;
  242. dModel.F_ZhengCeMingCi = zhengcemingci;
  243. dModel.F_File = file;
  244. dModel.F_ReDianWenTi = redianwenti;
  245. dModel.F_WenTiJieDa = wentijieda;
  246. if (new BLL.T_Wiki_HotspotGlossary().Update(dModel))
  247. return Success("修改成功");
  248. else
  249. return Error("修改失败");
  250. //}
  251. }
  252. else
  253. {
  254. return Error("修改失败");
  255. }
  256. }
  257. }
  258. /// <summary>
  259. /// 删除
  260. /// </summary>
  261. /// <param name="ids"></param>
  262. /// <returns></returns>
  263. public ActionResult DelModel(string[] ids)
  264. {
  265. if (ids == null || ids.Length <= 0)
  266. {
  267. return Error("请选择要删除的选项");
  268. }
  269. var idStr = string.Join(",", ids);
  270. if (string.IsNullOrEmpty(idStr.Trim()))
  271. {
  272. return Error("请选择要删除的选项");
  273. }
  274. int n = DB.DbHelperSQL.ExecuteSql(" update T_Wiki_HotspotGlossary set F_IsDelete=1,F_DeleteUser='" + User.F_UserCode + "',F_DeleteTime=getdate() where F_Id in (" + idStr + ")");
  275. if (n > 0)
  276. {
  277. return Success("删除成功");
  278. }
  279. return Error("删除失败");
  280. }
  281. /// <summary>
  282. /// 导出word
  283. /// </summary>
  284. /// <returns></returns>
  285. public ActionResult ExportWord(int id)
  286. {
  287. var aw = new AsposeWord();
  288. aw.OpenWithTemplate(Server.MapPath("/Upload/Word/热点问答模板.doc"));
  289. var dt = DB.DbHelperSQL.Query("select a.*,(select stuff((select ',' + F_FileName from T_Sys_Accessories where F_FileId in (a.F_File) for xml path('')),1,1,'')) as fileurl from T_Wiki_HotspotGlossary a with(nolock) where a.F_Id=" + id).Tables[0];
  290. string F_key = dt.Rows[0]["F_key"].ToString();
  291. var dt2 = DB.DbHelperSQL.Query("SELECT * FROM View_KeysSplit WHERE id=" + F_key).Tables[0];
  292. aw.Builder();
  293. aw.CreateHotSpotWord(dt, dt2);
  294. var bt = aw.ExportAs();
  295. Response.AppendHeader("Access-Control-Expose-Headers", "Content-Disposition");
  296. return File(bt, "application/msword", DateTime.Now.Ticks.ToString() + ".doc");
  297. }
  298. }
  299. }