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.

FunctionSerivce.cs 10 KiB

4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. using Learun.DataBase.Repository;
  2. using Learun.Util;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Text;
  6. using Learun.Application.AppMagager.Function;
  7. namespace Learun.Application.AppMagager
  8. {
  9. /// <summary>
  10. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  11. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  12. /// 创建人:陈彬彬
  13. /// 日 期:2018.03.16
  14. /// 描 述:移动端功能管理
  15. /// </summary>
  16. public class FunctionSerivce: RepositoryFactory
  17. {
  18. #region 属性 构造函数
  19. private string sql;
  20. public FunctionSerivce()
  21. {
  22. sql = @"
  23. t.F_Id,
  24. t.F_Type,
  25. t.F_FormId,
  26. t.F_CodeId,
  27. t.F_CreateDate,
  28. t.F_CreateUserId,
  29. t.F_CreateUserName,
  30. t.F_ModifyDate,
  31. t.F_ModifyUserId,
  32. t.F_ModifyUserName,
  33. t.F_Icon,
  34. t.F_Name,
  35. t.F_SchemeId,
  36. t.F_EnabledMark,
  37. t.F_SortCode,
  38. t.F_Url,
  39. t.F_IsSystem
  40. ";
  41. }
  42. #endregion
  43. #region 获取数据
  44. /// <summary>
  45. ///
  46. /// </summary>
  47. /// <param name="type">1 target 2 list 3 chart</param>
  48. /// <returns></returns>
  49. public IEnumerable<DesktopEntity> GetDesktopList(string type)
  50. {
  51. try
  52. {
  53. var strSql = new StringBuilder();
  54. strSql.Append("SELECT t.* ");
  55. switch (type)
  56. {
  57. case "1":
  58. strSql.Append(" FROM LR_DT_Target t ");
  59. break;
  60. case "2":
  61. strSql.Append(" FROM LR_DT_List t ");
  62. break;
  63. case "3":
  64. strSql.Append(" ,t.F_Type FROM LR_DT_Chart t ");
  65. break;
  66. }
  67. return this.BaseRepository().FindList<DesktopEntity>(strSql.ToString());
  68. }
  69. catch (Exception ex)
  70. {
  71. if (ex is ExceptionEx)
  72. {
  73. throw;
  74. }
  75. else
  76. {
  77. throw ExceptionEx.ThrowServiceException(ex);
  78. }
  79. }
  80. }
  81. /// <summary>
  82. /// 获取分页列表
  83. /// </summary>
  84. /// <param name="pagination">分页参数</param>
  85. /// <param name="keyword">关键字</param>
  86. /// <param name="type">分类</param>
  87. /// <returns></returns>
  88. public IEnumerable<FunctionEntity> GetPageList(Pagination pagination, string keyword, string type)
  89. {
  90. try
  91. {
  92. var strSql = new StringBuilder();
  93. strSql.Append("SELECT ");
  94. strSql.Append(sql);
  95. strSql.Append(" FROM LR_App_Function t where 1=1 ");
  96. if (!string.IsNullOrEmpty(keyword))
  97. {
  98. strSql.Append(" AND ( t.F_Name like @keyword ) ");
  99. keyword = "%" + keyword + "%";
  100. }
  101. if (!string.IsNullOrEmpty(type))
  102. {
  103. strSql.Append(" AND t.F_Type = @type ");
  104. }
  105. return this.BaseRepository().FindList<FunctionEntity>(strSql.ToString(), new { keyword, type }, pagination);
  106. }
  107. catch (Exception ex)
  108. {
  109. if (ex is ExceptionEx)
  110. {
  111. throw;
  112. }
  113. else
  114. {
  115. throw ExceptionEx.ThrowServiceException(ex);
  116. }
  117. }
  118. }
  119. /// <summary>
  120. /// 获取列表数据
  121. /// </summary>
  122. /// <returns></returns>
  123. public IEnumerable<FunctionEntity> GetList()
  124. {
  125. try
  126. {
  127. var strSql = new StringBuilder();
  128. strSql.Append("SELECT ");
  129. strSql.Append(sql);
  130. strSql.Append(" ,s.F_Scheme FROM LR_App_Function t LEFT JOIN LR_App_FnScheme s on t.F_SchemeId = s.F_Id where t.F_EnabledMark = 1 ORDER BY F_SortCode ");
  131. return this.BaseRepository().FindList<FunctionEntity>(strSql.ToString());
  132. }
  133. catch (Exception ex)
  134. {
  135. if (ex is ExceptionEx)
  136. {
  137. throw;
  138. }
  139. else
  140. {
  141. throw ExceptionEx.ThrowServiceException(ex);
  142. }
  143. }
  144. }
  145. /// <summary>
  146. /// 获取移动功能模板
  147. /// </summary>
  148. /// <param name="keyValue">主键</param>
  149. /// <returns></returns>
  150. public FunctionSchemeEntity GetScheme(string keyValue)
  151. {
  152. try
  153. {
  154. return this.BaseRepository().FindEntity<FunctionSchemeEntity>(keyValue);
  155. }
  156. catch (Exception ex)
  157. {
  158. if (ex is ExceptionEx)
  159. {
  160. throw;
  161. }
  162. else
  163. {
  164. throw ExceptionEx.ThrowServiceException(ex);
  165. }
  166. }
  167. }
  168. /// <summary>
  169. /// 获取实体对象
  170. /// </summary>
  171. /// <param name="keyValue">主键</param>
  172. /// <returns></returns>
  173. public FunctionEntity GetEntity(string keyValue) {
  174. try
  175. {
  176. return this.BaseRepository().FindEntity<FunctionEntity>(keyValue);
  177. }
  178. catch (Exception ex)
  179. {
  180. if (ex is ExceptionEx)
  181. {
  182. throw;
  183. }
  184. else
  185. {
  186. throw ExceptionEx.ThrowServiceException(ex);
  187. }
  188. }
  189. }
  190. #endregion
  191. #region 提交数据
  192. /// <summary>
  193. /// 删除
  194. /// </summary>
  195. /// <param name="keyValue">主键</param>
  196. public void Delete(string keyValue)
  197. {
  198. var db = this.BaseRepository().BeginTrans();
  199. try
  200. {
  201. FunctionEntity entity = db.FindEntity<FunctionEntity>(keyValue);
  202. string schemeId = entity.F_SchemeId;
  203. if (!string.IsNullOrEmpty(schemeId)) {
  204. db.Delete<FunctionSchemeEntity>(t => t.F_Id == schemeId);
  205. }
  206. db.Delete<FunctionEntity>(t => t.F_Id == keyValue);
  207. db.Commit();
  208. }
  209. catch (Exception ex)
  210. {
  211. db.Rollback();
  212. if (ex is ExceptionEx)
  213. {
  214. throw;
  215. }
  216. else
  217. {
  218. throw ExceptionEx.ThrowServiceException(ex);
  219. }
  220. }
  221. }
  222. /// <summary>
  223. /// 保存
  224. /// </summary>
  225. /// <param name="keyValue">主键</param>
  226. /// <param name="functionEntity">功能信息</param>
  227. /// <param name="functionSchemeEntity">功能模板信息</param>
  228. public void SaveEntity(string keyValue, FunctionEntity functionEntity, FunctionSchemeEntity functionSchemeEntity)
  229. {
  230. IRepository db = new RepositoryFactory().BaseRepository().BeginTrans();
  231. try
  232. {
  233. // 如果是代码开发功能
  234. if (functionEntity.F_IsSystem == 1)
  235. {
  236. if (!string.IsNullOrEmpty(functionEntity.F_SchemeId))
  237. {
  238. db.Delete<FunctionSchemeEntity>(t => t.F_Id == functionEntity.F_SchemeId);
  239. }
  240. }
  241. else
  242. {
  243. #region 模板信息
  244. if (string.IsNullOrEmpty(functionEntity.F_SchemeId))
  245. {
  246. functionSchemeEntity.Create();
  247. db.Insert(functionSchemeEntity);
  248. functionEntity.F_SchemeId = functionSchemeEntity.F_Id;
  249. }
  250. else
  251. {
  252. functionSchemeEntity.Modify(functionEntity.F_SchemeId);
  253. db.Update(functionSchemeEntity);
  254. }
  255. #endregion
  256. }
  257. if (string.IsNullOrEmpty(keyValue))
  258. {
  259. functionEntity.Create();
  260. db.Insert(functionEntity);
  261. }
  262. else
  263. {
  264. functionEntity.Modify(keyValue);
  265. db.Update(functionEntity);
  266. }
  267. db.Commit();
  268. }
  269. catch (Exception ex)
  270. {
  271. db.Rollback();
  272. if (ex is ExceptionEx)
  273. {
  274. throw;
  275. }
  276. else
  277. {
  278. throw ExceptionEx.ThrowServiceException(ex);
  279. }
  280. }
  281. }
  282. /// <summary>
  283. /// 更新状态
  284. /// </summary>
  285. /// <param name="keyValue">模板信息主键</param>
  286. /// <param name="state">状态1启用0禁用</param>
  287. public void UpdateState(string keyValue, int state)
  288. {
  289. try
  290. {
  291. FunctionEntity entity = new FunctionEntity
  292. {
  293. F_Id = keyValue,
  294. F_EnabledMark = state
  295. };
  296. this.BaseRepository().Update(entity);
  297. }
  298. catch (Exception ex)
  299. {
  300. if (ex is ExceptionEx)
  301. {
  302. throw;
  303. }
  304. else
  305. {
  306. throw ExceptionEx.ThrowServiceException(ex);
  307. }
  308. }
  309. }
  310. #endregion
  311. }
  312. }