You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

302 lines
10 KiB

  1. using Learun.DataBase.Repository;
  2. using Learun.Util;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Net;
  6. using System.Text;
  7. using Nancy.Json;
  8. using Spire.Pdf.General.Render.Decode.Jpeg2000.Icc;
  9. using static Learun.Application.OA.NewsEntity;
  10. using Nancy.Helpers;
  11. using System.Configuration;
  12. using System.Threading.Tasks;
  13. using Newtonsoft.Json;
  14. namespace Learun.Application.OA
  15. {
  16. /// <summary>
  17. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  18. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  19. /// 创建人:陈彬彬
  20. /// 日 期:2017.04.17
  21. /// 描 述:新闻管理
  22. /// </summary>
  23. public class NewsService : RepositoryFactory
  24. {
  25. #region 获取数据
  26. /// <summary>
  27. /// 新闻列表
  28. /// </summary>
  29. /// <param name="pagination">分页参数</param>
  30. /// <param name="categoryId">类型</param>
  31. /// <param name="keyword">关键词</param>
  32. /// <returns></returns>
  33. public IEnumerable<NewsEntity> GetPageList(Pagination pagination, string keyword)
  34. {
  35. try
  36. {
  37. var strSql = new StringBuilder();
  38. strSql.Append("SELECT * FROM LR_OA_News t WHERE t.F_TypeId = 1 ");
  39. if (!string.IsNullOrEmpty(keyword))
  40. {
  41. strSql.Append(" AND F_FullHead like @keyword");
  42. }
  43. return this.BaseRepository().FindList<NewsEntity>(strSql.ToString(), new { keyword = "%" + keyword + "%" }, pagination);
  44. }
  45. catch (Exception ex)
  46. {
  47. if (ex is ExceptionEx)
  48. {
  49. throw;
  50. }
  51. else
  52. {
  53. throw ExceptionEx.ThrowServiceException(ex);
  54. }
  55. }
  56. }
  57. public IEnumerable<NewsEntity> GetAboutSchool()
  58. {
  59. try
  60. {
  61. return this.BaseRepository().FindList<NewsEntity>(a => a.F_Category == "关于学院");
  62. }
  63. catch (Exception ex)
  64. {
  65. if (ex is ExceptionEx)
  66. {
  67. throw;
  68. }
  69. else
  70. {
  71. throw ExceptionEx.ThrowServiceException(ex);
  72. }
  73. }
  74. }
  75. public IEnumerable<NewsEntity> GetNews()
  76. {
  77. try
  78. {
  79. return this.BaseRepository().FindList<NewsEntity>(a => a.F_Category == "新闻公告");
  80. }
  81. catch (Exception ex)
  82. {
  83. if (ex is ExceptionEx)
  84. {
  85. throw;
  86. }
  87. else
  88. {
  89. throw ExceptionEx.ThrowServiceException(ex);
  90. }
  91. }
  92. }
  93. /// <summary>
  94. /// 新闻公告实体
  95. /// </summary>
  96. /// <param name="keyValue">主键值</param>
  97. /// <returns></returns>
  98. public NewsEntity GetEntity(string keyValue)
  99. {
  100. try
  101. {
  102. return this.BaseRepository().FindEntity<NewsEntity>(keyValue);
  103. }
  104. catch (Exception ex)
  105. {
  106. if (ex is ExceptionEx)
  107. {
  108. throw;
  109. }
  110. else
  111. {
  112. throw ExceptionEx.ThrowServiceException(ex);
  113. }
  114. }
  115. }
  116. #endregion
  117. #region 提交数据
  118. /// <summary>
  119. /// 删除
  120. /// </summary>
  121. /// <param name="keyValue">主键</param>
  122. public void DeleteEntity(string keyValue)
  123. {
  124. try
  125. {
  126. NewsEntity entity = new NewsEntity()
  127. {
  128. F_NewsId = keyValue,
  129. };
  130. this.BaseRepository().Delete(entity);
  131. }
  132. catch (Exception ex)
  133. {
  134. if (ex is ExceptionEx)
  135. {
  136. throw;
  137. }
  138. else
  139. {
  140. throw ExceptionEx.ThrowServiceException(ex);
  141. }
  142. }
  143. }
  144. /// <summary>
  145. /// 保存(新增、修改)
  146. /// </summary>
  147. /// <param name="keyValue">主键值</param>
  148. /// <param name="newsEntity">新闻公告实体</param>
  149. /// <returns></returns>
  150. public void SaveEntity(string keyValue, NewsEntity newsEntity)
  151. {
  152. try
  153. {
  154. newsEntity.F_TypeId = 1;
  155. if (!string.IsNullOrEmpty(keyValue))
  156. {
  157. newsEntity.Modify(keyValue);
  158. this.BaseRepository().Update(newsEntity);
  159. }
  160. else
  161. {
  162. newsEntity.Create();
  163. this.BaseRepository().Insert(newsEntity);
  164. }
  165. }
  166. catch (Exception ex)
  167. {
  168. if (ex is ExceptionEx)
  169. {
  170. throw;
  171. }
  172. else
  173. {
  174. throw ExceptionEx.ThrowServiceException(ex);
  175. }
  176. }
  177. }
  178. #endregion
  179. public void ChangeStatusByProcessId(string parameterProcessId, int status)
  180. {
  181. try
  182. {
  183. var newEntity = this.BaseRepository().FindEntity<NewsEntity>(a => a.F_ProgressId == parameterProcessId);
  184. if (null != newEntity)
  185. {
  186. if (status == 2)
  187. {
  188. newEntity.F_Status = "2";
  189. newEntity.F_EnabledMark = 1;
  190. }
  191. else
  192. {
  193. newEntity.F_Status = "0";
  194. }
  195. }
  196. this.BaseRepository().Update(newEntity);
  197. if (newEntity.IsSend == "1" && status == 2)
  198. {
  199. BaseRepository()
  200. .ExecuteBySql("insert INTO LR_Base_Log(F_LogId,F_CategoryId,F_SourceContentJson) VALUES (newid(),2222,'准备开始run task') ");
  201. Task.Run(async () => { sendNew(newEntity); });
  202. }
  203. }
  204. catch (Exception ex)
  205. {
  206. BaseRepository()
  207. .ExecuteBySql("insert INTO LR_Base_Log(F_LogId,F_CategoryId,F_SourceContentJson) VALUES (newid(),2222,'run task 报错"+ex.Message+"') ");
  208. if (ex is ExceptionEx)
  209. {
  210. throw;
  211. }
  212. else
  213. {
  214. throw ExceptionEx.ThrowServiceException(ex);
  215. }
  216. }
  217. }
  218. public void sendNew(NewsEntity newEntity)
  219. {
  220. try
  221. {
  222. if (newEntity.IsSend == "1") //判断是否下发
  223. {
  224. #region 获取配置文件
  225. string siteId = ConfigurationManager.AppSettings["SiteId"];
  226. string channelId = ConfigurationManager.AppSettings["ChannelId"];
  227. string ApiKey = ConfigurationManager.AppSettings["ApiKey"];
  228. string ports = ConfigurationManager.AppSettings["Ports"];
  229. #endregion
  230. BaseRepository()
  231. .ExecuteBySql("insert INTO LR_Base_Log(F_LogId,F_CategoryId,F_SourceContentJson) VALUES (newid(),2222,'准备开始组装实体') ");
  232. SemdNewList SendNew = new SemdNewList
  233. {
  234. Title = newEntity.F_FullHead,
  235. SubTitle = newEntity.F_BriefHead,
  236. Content = HttpUtility.HtmlDecode(newEntity.F_NewsContent),
  237. Author = newEntity.F_AuthorName,
  238. Source = newEntity.F_SourceName,
  239. AddDate = DateTime.Now,
  240. Tags = newEntity.F_TagWord,
  241. AddUserName = newEntity.F_CreateUserName,
  242. };
  243. WebHeaderCollection ApiId = new WebHeaderCollection
  244. {
  245. { "X-SS-API-KEY", ApiKey }
  246. };
  247. BaseRepository()
  248. .ExecuteBySql("insert INTO LR_Base_Log(F_LogId,F_CategoryId,F_SourceContentJson) VALUES (newid(),2222,'准备开始post cms') ");
  249. string responses = HttpMethods.HttpPosts("http://" + ports + "/api/v1/contents/" + siteId + "/" + channelId, SendNew.ToJson(), ApiId);
  250. BaseRepository()
  251. .ExecuteBySql("insert INTO LR_Base_Log(F_LogId,F_CategoryId,F_SourceContentJson) VALUES (newid(),2222,'"+HttpUtility.UrlEncode(responses)+"') ");
  252. //#region 修改审核状态
  253. //string Nid = JsonConvert.DeserializeObject<Root>(responses).value.id;
  254. //AuditList AList = new AuditList();
  255. //if (Nid != null)
  256. //{
  257. // AList.siteId = Convert.ToInt32(siteId);
  258. // List<contents> listCon = new List<contents>();
  259. // //这里应该循环,如果多个
  260. // contents con = new contents();
  261. // con.channelId = Convert.ToInt32(channelId);
  262. // con.id = Convert.ToInt32(Nid);
  263. // listCon.Add(con);
  264. // AList.contents = listCon;
  265. // //AList.reasons = "终审通过";
  266. // HttpMethods.HttpPosts("http://" + ports + "/api/v1/contents/check", AList.ToJson(), ApiId);
  267. //}
  268. //#endregion
  269. }
  270. }
  271. catch (Exception ex)
  272. {
  273. BaseRepository()
  274. .ExecuteBySql("insert INTO LR_Base_Log(F_LogId,F_CategoryId,F_SourceContentJson) VALUES (newid(),2222,'"+ex.Message + "') ");
  275. }
  276. }
  277. }
  278. //public class Root
  279. //{
  280. // public RootValue value { get; set; }
  281. //}
  282. //public class RootValue
  283. //{
  284. // public string id { get; set; }
  285. //}
  286. }