Bez popisu

FunctionsController.cs 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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 FunctionsController : BaseController
  13. {
  14. // GET: Policy
  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_FaWenWenHao like '%" + keyvalue + "%' or F_FaWenDanWei like '%" + keyvalue + "%' orF_BiaoShiBianMa like '%" + keyvalue + "%' or F_ZhiNengBuMen like '%" + keyvalue + "%' or F_WenJianMingCheng like '%" + keyvalue + "%' or F_WenJianNeiRong 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_ZhiNengBuMen as 职能部门,F_WenJianNeiRong as 文件内容,F_WenJianMingCheng as 文件名称,F_FaWenWenHao as 发文文号,F_FaWenDanWei 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_Functions 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_Functions 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_Functions().GetModel(id);
  122. if (model != null)
  123. {
  124. DB.DbHelperSQL.ExecuteSql(" update T_Wiki_Functions 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 zhinengbumen = RequestString.GetFormString("zhinengbumen");
  169. string file = RequestString.GetFormString("file");
  170. string wenjianmingcheng = RequestString.GetFormString("wenjianmingcheng");
  171. string wenjianneirong = RequestString.GetFormString("wenjianneirong");
  172. Model.T_Wiki_Functions dModel = new Model.T_Wiki_Functions();
  173. if (id == 0)
  174. {
  175. //var list = new BLL.T_Wiki_Functions().GetList(" F_FaBuDanWei='" + fabudanwei + "' and F_IsDelete=0 ").Tables[0];
  176. //if (list.Rows.Count > 0)
  177. //{
  178. // return Error("已经存在");
  179. //}
  180. //else
  181. //{
  182. dModel.F_FaBuRen = User.F_UserName;
  183. dModel.F_FaBuDanWei = fabudanwei;
  184. dModel.F_HangYe = hangye;
  185. dModel.F_DiQu = diqu;
  186. try
  187. {
  188. dModel.F_ShengXiaoShiJian = DateTime.Parse(shengxiaoshijian);
  189. }
  190. catch { };
  191. try
  192. {
  193. dModel.F_ShiXiaoShiJian = DateTime.Parse(shixiaoshijian);
  194. }
  195. catch { };
  196. dModel.F_FaBuShiJian = DateTime.Now;
  197. dModel.F_Key = key;
  198. dModel.F_FaWenWenHao = DateTime.Now.ToString("yyyyMMddHHmmssff");
  199. dModel.F_FaWenDanWei = fawendanwei;
  200. // dModel.F_BiaoShiBianMa = biaoshibianma;
  201. dModel.F_ZhiNengBuMen = zhinengbumen;
  202. dModel.F_File = file;
  203. dModel.F_WenJianMingCheng = wenjianmingcheng;
  204. dModel.F_WenJianNeiRong = wenjianneirong;
  205. dModel.F_DianJiLiang = 0;
  206. dModel.F_IsDelete = 0;
  207. dModel.F_CreateUser = User.F_UserCode;
  208. dModel.F_CreateTime = DateTime.Now;
  209. int n = new BLL.T_Wiki_Functions().Add(dModel);
  210. if (n > 0)
  211. {
  212. DB.DbHelperSQL.ExecuteSql("update T_Wiki_Functions set F_BiaoShiBianMa =right('00000'+'" + User.F_DeptId + "' ,5)+right('0000000'+'" + n + "' ,8) where F_Id=" + n);
  213. return Success("添加成功", n);
  214. }
  215. else
  216. return Error("添加失败");
  217. //}
  218. }
  219. else
  220. {
  221. dModel = new BLL.T_Wiki_Functions().GetModel(id);
  222. if (dModel != null)
  223. {
  224. //var list = new BLL.T_Wiki_Functions().GetList(" F_FaBuDanWei='" + fabudanwei + "' and F_IsDelete=0 and F_Id!='" + id + "' ").Tables[0];
  225. //if (list.Rows.Count > 0)
  226. //{
  227. // return Error("已经存在");
  228. //}
  229. //else
  230. //{
  231. dModel.F_FaBuRen = faburen;
  232. dModel.F_FaBuDanWei = fabudanwei;
  233. dModel.F_HangYe = hangye;
  234. dModel.F_DiQu = diqu;
  235. try
  236. {
  237. dModel.F_ShengXiaoShiJian = DateTime.Parse(shengxiaoshijian);
  238. }
  239. catch { };
  240. try
  241. {
  242. dModel.F_ShiXiaoShiJian = DateTime.Parse(shixiaoshijian);
  243. }
  244. catch { };
  245. try
  246. {
  247. dModel.F_FaBuShiJian = DateTime.Parse(fabushijian);
  248. }
  249. catch { };
  250. dModel.F_Key = key;
  251. dModel.F_FaWenWenHao = fawenwenhao;
  252. dModel.F_FaWenDanWei = fawendanwei;
  253. dModel.F_BiaoShiBianMa = biaoshibianma;
  254. dModel.F_ZhiNengBuMen = zhinengbumen;
  255. dModel.F_File = file;
  256. dModel.F_WenJianMingCheng = wenjianmingcheng;
  257. dModel.F_WenJianNeiRong = wenjianneirong;
  258. if (new BLL.T_Wiki_Functions().Update(dModel))
  259. return Success("修改成功");
  260. else
  261. return Error("修改失败");
  262. //}
  263. }
  264. else
  265. {
  266. return Error("修改失败");
  267. }
  268. }
  269. }
  270. /// <summary>
  271. /// 删除
  272. /// </summary>
  273. /// <param name="ids"></param>
  274. /// <returns></returns>
  275. public ActionResult DelModel(string[] ids)
  276. {
  277. if (ids == null || ids.Length <= 0)
  278. {
  279. return Error("请选择要删除的选项");
  280. }
  281. var idStr = string.Join(",", ids);
  282. if (string.IsNullOrEmpty(idStr.Trim()))
  283. {
  284. return Error("请选择要删除的选项");
  285. }
  286. int n = DB.DbHelperSQL.ExecuteSql(" update T_Wiki_Functions set F_IsDelete=1,F_DeleteUser='" + User.F_UserCode + "',F_DeleteTime=getdate() where F_Id in (" + idStr + ")");
  287. if (n > 0)
  288. {
  289. return Success("删除成功");
  290. }
  291. return Error("删除失败");
  292. }
  293. /// <summary>
  294. /// 导出word
  295. /// </summary>
  296. /// <returns></returns>
  297. public ActionResult ExportWord(int id)
  298. {
  299. var aw = new AsposeWord();
  300. aw.OpenWithTemplate(Server.MapPath("/Upload/Word/政策法规模板.doc"));
  301. 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_Policy a with(nolock) where a.F_Id=" + id).Tables[0];
  302. string F_key = dt.Rows[0]["F_key"].ToString();
  303. var dt2 = DB.DbHelperSQL.Query("SELECT * FROM View_KeysSplit WHERE id=" + F_key).Tables[0];
  304. aw.Builder();
  305. aw.CreateDepartmentFunctionsWord(dt, dt2);
  306. var bt = aw.ExportAs();
  307. Response.AppendHeader("Access-Control-Expose-Headers", "Content-Disposition");
  308. return File(bt, "application/msword", DateTime.Now.Ticks.ToString() + ".doc");
  309. }
  310. }
  311. }