|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 |
- using Learun.DataBase.Repository;
- using Learun.Util;
- using System;
- using System.Collections.Generic;
- using System.Net;
- using System.Text;
- using Nancy.Json;
- using Spire.Pdf.General.Render.Decode.Jpeg2000.Icc;
- using static Learun.Application.OA.NewsEntity;
- using Nancy.Helpers;
- using System.Configuration;
- using System.Threading.Tasks;
- using Newtonsoft.Json;
-
- namespace Learun.Application.OA
- {
- /// <summary>
- /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
- /// Copyright (c) 2013-2018 北京泉江科技有限公司
- /// 创建人:陈彬彬
- /// 日 期:2017.04.17
- /// 描 述:新闻管理
- /// </summary>
- public class NewsService : RepositoryFactory
- {
-
- #region 获取数据
- /// <summary>
- /// 新闻列表
- /// </summary>
- /// <param name="pagination">分页参数</param>
- /// <param name="categoryId">类型</param>
- /// <param name="keyword">关键词</param>
- /// <returns></returns>
- public IEnumerable<NewsEntity> GetPageList(Pagination pagination, string keyword)
- {
- try
- {
- var strSql = new StringBuilder();
- strSql.Append("SELECT * FROM LR_OA_News t WHERE t.F_TypeId = 1 ");
- if (!string.IsNullOrEmpty(keyword))
- {
- strSql.Append(" AND F_FullHead like @keyword");
- }
- return this.BaseRepository().FindList<NewsEntity>(strSql.ToString(), new { keyword = "%" + keyword + "%" }, pagination);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
- public IEnumerable<NewsEntity> GetAboutSchool()
- {
- try
- {
- return this.BaseRepository().FindList<NewsEntity>(a => a.F_Category == "关于学院");
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
- public IEnumerable<NewsEntity> GetNews()
- {
- try
- {
- return this.BaseRepository().FindList<NewsEntity>(a => a.F_Category == "新闻公告");
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
- /// <summary>
- /// 新闻公告实体
- /// </summary>
- /// <param name="keyValue">主键值</param>
- /// <returns></returns>
- public NewsEntity GetEntity(string keyValue)
- {
- try
- {
- return this.BaseRepository().FindEntity<NewsEntity>(keyValue);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
- #endregion
-
- #region 提交数据
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="keyValue">主键</param>
- public void DeleteEntity(string keyValue)
- {
- try
- {
- NewsEntity entity = new NewsEntity()
- {
- F_NewsId = keyValue,
- };
- this.BaseRepository().Delete(entity);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
- /// <summary>
- /// 保存(新增、修改)
- /// </summary>
- /// <param name="keyValue">主键值</param>
- /// <param name="newsEntity">新闻公告实体</param>
- /// <returns></returns>
- public void SaveEntity(string keyValue, NewsEntity newsEntity)
- {
- try
- {
- newsEntity.F_TypeId = 1;
- if (!string.IsNullOrEmpty(keyValue))
- {
- newsEntity.Modify(keyValue);
- this.BaseRepository().Update(newsEntity);
- }
- else
- {
- newsEntity.Create();
- this.BaseRepository().Insert(newsEntity);
- }
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
-
- }
- #endregion
-
- public void ChangeStatusByProcessId(string parameterProcessId, int status)
- {
- try
- {
- var newEntity = this.BaseRepository().FindEntity<NewsEntity>(a => a.F_ProgressId == parameterProcessId);
- if (null != newEntity)
- {
- if (status == 2)
- {
- newEntity.F_Status = "2";
- newEntity.F_EnabledMark = 1;
- }
- else
- {
- newEntity.F_Status = "0";
- }
- }
- this.BaseRepository().Update(newEntity);
-
- if (newEntity.IsSend == "1" && status == 2)
- {
- BaseRepository()
- .ExecuteBySql("insert INTO LR_Base_Log(F_LogId,F_CategoryId,F_SourceContentJson) VALUES (newid(),2222,'准备开始run task') ");
- Task.Run(async () => { sendNew(newEntity); });
- }
- }
- catch (Exception ex)
- {
- BaseRepository()
- .ExecuteBySql("insert INTO LR_Base_Log(F_LogId,F_CategoryId,F_SourceContentJson) VALUES (newid(),2222,'run task 报错"+ex.Message+"') ");
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- public void sendNew(NewsEntity newEntity)
- {
- try
- {
-
- if (newEntity.IsSend == "1") //判断是否下发
- {
- #region 获取配置文件
-
- string siteId = ConfigurationManager.AppSettings["SiteId"];
- string channelId = ConfigurationManager.AppSettings["ChannelId"];
- string ApiKey = ConfigurationManager.AppSettings["ApiKey"];
- string ports = ConfigurationManager.AppSettings["Ports"];
-
- #endregion
- BaseRepository()
- .ExecuteBySql("insert INTO LR_Base_Log(F_LogId,F_CategoryId,F_SourceContentJson) VALUES (newid(),2222,'准备开始组装实体') ");
- SemdNewList SendNew = new SemdNewList
- {
- Title = newEntity.F_FullHead,
- SubTitle = newEntity.F_BriefHead,
- Content = HttpUtility.HtmlDecode(newEntity.F_NewsContent),
- Author = newEntity.F_AuthorName,
- Source = newEntity.F_SourceName,
- AddDate = DateTime.Now,
- Tags = newEntity.F_TagWord,
- AddUserName = newEntity.F_CreateUserName,
- };
- WebHeaderCollection ApiId = new WebHeaderCollection
- {
- { "X-SS-API-KEY", ApiKey }
- };
- BaseRepository()
- .ExecuteBySql("insert INTO LR_Base_Log(F_LogId,F_CategoryId,F_SourceContentJson) VALUES (newid(),2222,'准备开始post cms') ");
-
- string responses = HttpMethods.HttpPosts("http://" + ports + "/api/v1/contents/" + siteId + "/" + channelId, SendNew.ToJson(), ApiId);
- BaseRepository()
- .ExecuteBySql("insert INTO LR_Base_Log(F_LogId,F_CategoryId,F_SourceContentJson) VALUES (newid(),2222,'"+HttpUtility.UrlEncode(responses)+"') ");
-
- //#region 修改审核状态
- //string Nid = JsonConvert.DeserializeObject<Root>(responses).value.id;
- //AuditList AList = new AuditList();
- //if (Nid != null)
- //{
- // AList.siteId = Convert.ToInt32(siteId);
- // List<contents> listCon = new List<contents>();
- // //这里应该循环,如果多个
- // contents con = new contents();
- // con.channelId = Convert.ToInt32(channelId);
- // con.id = Convert.ToInt32(Nid);
- // listCon.Add(con);
- // AList.contents = listCon;
- // //AList.reasons = "终审通过";
- // HttpMethods.HttpPosts("http://" + ports + "/api/v1/contents/check", AList.ToJson(), ApiId);
- //}
- //#endregion
- }
- }
- catch (Exception ex)
- {
- BaseRepository()
- .ExecuteBySql("insert INTO LR_Base_Log(F_LogId,F_CategoryId,F_SourceContentJson) VALUES (newid(),2222,'"+ex.Message + "') ");
- }
- }
-
- }
-
- //public class Root
- //{
- // public RootValue value { get; set; }
- //}
-
- //public class RootValue
- //{
- // public string id { get; set; }
- //}
- }
|