NoticeController.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. using PMS.BusinessModels.Account;
  2. using PMS.BusinessModels.Problem;
  3. using PMS.EntityModels.NoticeManager;
  4. using PMS.Interface;
  5. using PMS.Interface.MessageManage;
  6. using QWPlatform.SystemLibrary.Utils;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Web;
  12. using System.Web.Mvc;
  13. namespace PMS.WebUI.Controllers
  14. {
  15. public class NoticeController : BaseController
  16. {
  17. #region 接口实例
  18. IMessageManage notice = InterfaceFactory.CreateBusinessInstance<IMessageManage>();
  19. #endregion
  20. #region 查询
  21. //通知类型
  22. public ActionResult NoticeType()
  23. {
  24. return Content(notice.NoticeType(), "application/json");
  25. }
  26. //通知优先级
  27. public ActionResult NoticeOrder()
  28. {
  29. return Content(notice.NoticeOrder(), "application/json");
  30. }
  31. //通知对象
  32. public ActionResult NoticePerson()
  33. {
  34. int PersonProperty = GetCurrentUser().PersonProperty;
  35. return Content(notice.NoticePerson(PersonProperty), "application/json");
  36. }
  37. //根据ID获取通知信息
  38. public ActionResult GetNoticeByID(string id)
  39. {
  40. return Content(notice.GetNoticeByID(id), "application/json");
  41. }
  42. //根据公告ID获取通知对象
  43. public ActionResult GetNatureByID(string id)
  44. {
  45. return Content(notice.GetNatureByID(id), "application/json");
  46. }
  47. //获取渠道
  48. public ActionResult GetChannelByNature()
  49. {
  50. var user = GetCurrentUser();
  51. return Content(notice.GetChannelByNature(user), "application/json");
  52. }
  53. //获取进入首页的通知公告
  54. public ActionResult ShowNotice()
  55. {
  56. var user = GetCurrentUser();
  57. return Content(notice.ShowNotice(user), "application/json");
  58. }
  59. //获取登陆人ID
  60. public string GetFeedbackID()
  61. {
  62. var user = GetCurrentUser();
  63. return user.PersonID;
  64. }
  65. #endregion
  66. #region 通知首页
  67. //公告首页
  68. public ActionResult Index()
  69. {
  70. return View();
  71. }
  72. //公告信息绑定
  73. public ActionResult DataBind(int page, int rows, string query)
  74. {
  75. var user = GetCurrentUser();
  76. return Content(notice.DataBind(page, rows, query, user), "application/json");
  77. }
  78. //获取首页公告信息
  79. public ActionResult GetHome()
  80. {
  81. var userInfo = GetCurrentUser();
  82. var json = notice.GetHome(userInfo);
  83. return Content(json, "application/json");
  84. }
  85. //公告列表首页
  86. public ActionResult HomeGetList(int page, int rows)
  87. {
  88. var user = GetCurrentUser();
  89. return Content(notice.HomeGetList(page, rows, user), "application/json");
  90. }
  91. //通知列表首页
  92. public ActionResult HomeGetNotice(int page, int rows)
  93. {
  94. var user = GetCurrentUser();
  95. return Content(notice.HomeGetNotice(page, rows, user), "application/json");
  96. }
  97. #endregion
  98. #region 首页通知公告显示
  99. //判断是否显示通知
  100. public bool PanDuanIsShow()
  101. {
  102. var user = GetCurrentUser();
  103. var Count = notice.GetCount(user);
  104. return Count > 0;
  105. }
  106. public ActionResult Notice_Window()
  107. {
  108. return View();
  109. }
  110. //显示总部和渠道的最新公告通知
  111. public ActionResult GetMessageOnIndex()
  112. {
  113. var user = GetCurrentUser();
  114. return Content(notice.GetMessageOnIndex(user), "application/json");
  115. }
  116. /// <summary>
  117. ///
  118. /// </summary>
  119. /// <returns></returns>
  120. public ActionResult SaveNoticeConfig(string NoticeId, bool IsOpen)
  121. {
  122. var user = GetCurrentUser();
  123. var r = notice.SaveNoticeConfig(user.PersonID, NoticeId, IsOpen);
  124. return Content(r ? "1" : "0", "application/json");
  125. }
  126. #endregion
  127. #region 添加
  128. //添加公告弹窗
  129. public ActionResult Add_Window()
  130. {
  131. return View();
  132. }
  133. //添加操作
  134. [HttpPost]
  135. public int Add_Notice(string text)
  136. {
  137. //反编码并转换为一个Model对象
  138. MessageManageModel model = Strings.JsonToModel<MessageManageModel>(HttpUtility.UrlDecode(text));
  139. model.PersonName = GetCurrentUser().Name;
  140. model.PersonId = GetCurrentUser().PersonID;
  141. var user = GetCurrentUser();
  142. string ID = Guid.NewGuid().ToString();
  143. if (TempData["PID"] != null)
  144. {
  145. model.FJID = TempData["PID"].ToString();
  146. }
  147. var r = notice.AddMessage(model, user,ID);
  148. //推送
  149. if (r && model.IsShow == 1)
  150. {
  151. App_Start.ClientManager.Add_NoticeToNotice();
  152. }
  153. return r ? 1 : 0;
  154. }
  155. #endregion
  156. #region 修改
  157. //添加公告弹窗
  158. public ActionResult Edit_Window(string id)
  159. {
  160. ViewBag.id = id;
  161. TempData["NID"] = id;
  162. return View();
  163. }
  164. //修改操作
  165. [HttpPost]
  166. public int Edit_Notice(string text)
  167. {
  168. //反编码并转换为一个Model对象
  169. MessageManageModel model = Strings.JsonToModel<MessageManageModel>(HttpUtility.UrlDecode(text));
  170. if (model.FJID == null)
  171. {
  172. var tempdata = TempData["PID"];
  173. if (tempdata != null)
  174. {
  175. model.FJID = tempdata.ToString();
  176. }
  177. }
  178. return notice.Edit_Notice(model) ? 1 : 0;
  179. }
  180. [HttpPost]
  181. public int DeleteFJ(string id)
  182. {
  183. return notice.DeleteFJ(id);
  184. }
  185. #endregion
  186. #region 删除
  187. public int Del_Notice(string id)
  188. {
  189. MessageManageModel model = new MessageManageModel();
  190. model.ID = id;
  191. return notice.DeleteMessage(model) ? 1 : 0;
  192. }
  193. #endregion
  194. #region 是否启用
  195. public int NoticeStatus(string id)
  196. {
  197. return notice.NoticeStatus(id);
  198. }
  199. #endregion
  200. #region APP首页推送
  201. public ActionResult APPIndex()
  202. {
  203. return View();
  204. }
  205. //APP公告获取
  206. public ActionResult APPDataBind(int page, int rows)
  207. {
  208. return Content(notice.APPDataBind(page, rows), "application/json");
  209. }
  210. //添加公告弹窗
  211. public ActionResult App_Window()
  212. {
  213. return View();
  214. }
  215. //添加操作
  216. [HttpPost]
  217. public string Add_AppPush(string text)
  218. {
  219. //反编码并转换为一个Model对象
  220. AppPush_Model model = Strings.JsonToModel<AppPush_Model>(HttpUtility.UrlDecode(text));
  221. model.TJRID = GetCurrentUser().PersonID;
  222. var user = GetCurrentUser();
  223. var id = notice.Add_AppPush(model);
  224. TempData["imgID"] = id;
  225. return id;
  226. }
  227. //图片上传
  228. [HttpPost]
  229. public int FileUpload(int type)
  230. {
  231. AppPush_Model model = new AppPush_Model();
  232. var files = this.Request.Files;
  233. if (this.Request.Files.Count > 0)
  234. {
  235. using (BinaryReader br = new BinaryReader(files[0].InputStream))
  236. {
  237. byte[] byteData = br.ReadBytes((int)files[0].InputStream.Length);
  238. var uploadFile = files[0];
  239. var fileName = uploadFile.FileName;
  240. var fileLen = uploadFile.ContentLength;
  241. var fileType = uploadFile.ContentType;
  242. string _tp = System.IO.Path.GetExtension(fileName);
  243. var r = UploadFile(byteData, fileName, fileType);
  244. if (r.code == 100)
  245. {
  246. if (type == 1)
  247. {
  248. model.TPID = r.data;
  249. model.ID = TempData["imgID"].ToString();
  250. model.TJRID = GetCurrentUser().PersonID;
  251. return notice.Edit_AppNotice(model);
  252. }
  253. if(type==2)
  254. {
  255. return notice.Edit_NoticeFJ(r.data, TempData["NID"].ToString());
  256. }
  257. if(type==3)
  258. {
  259. TempData["PID"]= r.data;
  260. return 1;
  261. }
  262. }
  263. }
  264. }
  265. return 0;
  266. }
  267. //清空Tempdata
  268. [HttpPost]
  269. public void ClearTempData()
  270. {
  271. TempData["PID"] = null;
  272. }
  273. //app公告是否启用
  274. public int AppNoticeStatus(string id)
  275. {
  276. return notice.AppNoticeStatus(id);
  277. }
  278. //app公告删除
  279. public int Del_AppNotice(string id)
  280. {
  281. return notice.Del_AppNotice(id);
  282. }
  283. //获取启用的app公告
  284. [HttpPost]
  285. public ActionResult GetWorkNotice()
  286. {
  287. return Content(notice.GetWorkNotice(),"application/json");
  288. }
  289. #endregion
  290. }
  291. }