RptTempService.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. using LeaRun.Application.Entity.ReportManage;
  2. using LeaRun.Application.IService.ReportManage;
  3. using LeaRun.Data;
  4. using LeaRun.Data.Repository;
  5. using LeaRun.Util.Extension;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Data;
  9. using System.Data.Common;
  10. using System.Linq;
  11. using System.Text;
  12. using LeaRun.Util;
  13. using LeaRun.Application.Entity.AuthorizeManage;
  14. namespace LeaRun.Application.Service.ReportManage
  15. {
  16. /// <summary>
  17. /// 版 本 6.1
  18. /// Copyright (c) 2013-2016 上海力软信息技术有限公司
  19. /// 创建人:佘赐雄
  20. /// 日 期:2016.1.14 14:27
  21. /// 描 述:报表模板管理
  22. /// </summary>
  23. public class RptTempService : RepositoryFactory<RptTempEntity>, IRptTempService
  24. {
  25. #region 获取数据
  26. /// <summary>
  27. /// 报表模板列表
  28. /// </summary>
  29. /// <param name="queryJson">查询参数</param>
  30. /// <returns></returns>
  31. public IEnumerable<RptTempEntity> GetList(string queryJson)
  32. {
  33. var strSql = new StringBuilder();
  34. strSql.Append(@"SELECT r.TempId,
  35. r.EnCode ,
  36. r.FullName ,
  37. CASE r.TempType
  38. WHEN 'line' THEN '折线图'
  39. WHEN 'bar' THEN '柱形图'
  40. WHEN 'map' THEN '地图'
  41. WHEN 'pie' THEN '饼图'
  42. END AS TempType ,
  43. r.TempCategory ,
  44. r.Description ,
  45. r.CreateDate
  46. FROM Rpt_Temp r
  47. WHERE 1 = 1 ");
  48. var parameter = new List<DbParameter>();
  49. var queryParam = queryJson.ToJObject();
  50. //查询条件
  51. if (!queryParam["condition"].IsEmpty() && !queryParam["keyword"].IsEmpty())
  52. {
  53. string condition = queryParam["condition"].ToString();
  54. string keyword = queryParam["keyword"].ToString();
  55. switch (condition)
  56. {
  57. case "EnCode": //角色编号
  58. strSql.Append(" AND r.EnCode LIKE @keyword ");
  59. parameter.Add(DbParameters.CreateDbParameter("@keyword", '%' + keyword + '%'));
  60. break;
  61. case "FullName": //角色名称
  62. strSql.Append(" AND r.FullName LIKE @keyword ");
  63. parameter.Add(DbParameters.CreateDbParameter("@keyword", '%' + keyword + '%'));
  64. break;
  65. default:
  66. break;
  67. }
  68. }
  69. if (!queryParam["reportCode"].IsEmpty())
  70. {
  71. strSql.Append(" AND r.TempCategory = @TempCategory ");
  72. parameter.Add(DbParameters.CreateDbParameter("@TempCategory", queryParam["reportCode"].ToString()));
  73. }
  74. return this.BaseRepository().FindList(strSql.ToString(), parameter.ToArray());
  75. }
  76. /// <summary>
  77. /// 报表模板实体
  78. /// </summary>
  79. /// <param name="keyValue">主键值</param>
  80. /// <returns></returns>
  81. public RptTempEntity GetEntity(string keyValue)
  82. {
  83. return this.BaseRepository().FindEntity(keyValue);
  84. }
  85. /// <summary>
  86. /// 获得报表数据
  87. /// </summary>
  88. /// <param name="reportId">主键值</param>
  89. /// <returns></returns>
  90. public string GetReportData(string reportId)
  91. {
  92. RptTempEntity rpttempentity = this.BaseRepository().FindEntity(reportId);
  93. if (rpttempentity.ParamJson != null)
  94. {
  95. dynamic paramJson = rpttempentity.ParamJson.ToJson();
  96. string strSql = paramJson.sqlString;
  97. string strListSql = paramJson.listSqlString;
  98. string picTitle = paramJson.title;
  99. string title = rpttempentity.FullName;
  100. string tempType = rpttempentity.TempType;
  101. List<FieldList> listField = new List<FieldList>();
  102. DataTable picData = new DataTable();
  103. if (!string.IsNullOrEmpty(strSql))
  104. {
  105. picData = this.BaseRepository().FindTable(strSql);
  106. }
  107. DataTable listData = new DataTable();
  108. if (!string.IsNullOrEmpty(strListSql))
  109. {
  110. listData = this.BaseRepository().FindTable(strListSql);
  111. if (listData.Columns.Count > 0)
  112. {
  113. for (int i = 0; i < listData.Columns.Count; i++)
  114. {
  115. listField.Add(new FieldList() { Field = listData.Columns[i].ColumnName });
  116. }
  117. }
  118. }
  119. var jsonData = new
  120. {
  121. title = title,
  122. tempType = tempType,
  123. listField = listField,
  124. picTitle = picTitle,
  125. picData = picData,
  126. listData = listData
  127. };
  128. return jsonData.ToJson();
  129. }
  130. return null;
  131. }
  132. #endregion
  133. #region 提交数据
  134. /// <summary>
  135. /// 删除报表模板
  136. /// </summary>
  137. /// <param name="keyValue">主键</param>
  138. public void RemoveForm(string keyValue)
  139. {
  140. this.BaseRepository().Delete(keyValue);
  141. }
  142. /// <summary>
  143. /// 保存报表模板表单(新增、修改)
  144. /// </summary>
  145. /// <param name="keyValue">主键值</param>
  146. /// <param name="rptTempEntity">报表实体</param>
  147. /// <param name="moduleEntity">模块实体</param>
  148. /// <returns></returns>
  149. public void SaveForm(string keyValue, RptTempEntity rptTempEntity, ModuleEntity moduleEntity)
  150. {
  151. IRepository db = new RepositoryFactory().BaseRepository().BeginTrans();
  152. try
  153. {
  154. if (!string.IsNullOrEmpty(keyValue))
  155. {
  156. rptTempEntity.Modify(keyValue);
  157. db.Update(rptTempEntity);
  158. }
  159. else
  160. {
  161. rptTempEntity.Create();
  162. db.Insert(rptTempEntity);
  163. moduleEntity.UrlAddress = " /ReportManage/Report/ReportPreview?keyValue=" + rptTempEntity.TempId;
  164. db.Insert(moduleEntity);
  165. }
  166. db.Commit();
  167. }
  168. catch (Exception)
  169. {
  170. db.Rollback();
  171. throw;
  172. }
  173. }
  174. #endregion
  175. }
  176. class FieldList
  177. {
  178. public string Field { get; set; }
  179. }
  180. }