WFDelegateRuleService.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. using LeaRun.Application.Code;
  2. using LeaRun.Application.Entity.BaseManage;
  3. using LeaRun.Application.Entity.FlowManage;
  4. using LeaRun.Application.IService.AuthorizeManage;
  5. using LeaRun.Application.IService.FlowManage;
  6. using LeaRun.Application.Service.BaseManage;
  7. using LeaRun.Data;
  8. using LeaRun.Data.Repository;
  9. using LeaRun.Util;
  10. using LeaRun.Util.Extension;
  11. using LeaRun.Util.WebControl;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Data;
  15. using System.Data.Common;
  16. using System.Text;
  17. using System.Linq;
  18. namespace LeaRun.Application.Service.FlowManage
  19. {
  20. /// <summary>
  21. /// 版 本 6.1
  22. /// Copyright (c) 2013-2016 上海力软信息技术有限公司
  23. /// 创建人:陈彬彬
  24. /// 日 期:2016.01.14 11:02
  25. /// 描 述:工作流委托规则表操作类(支持:SqlServer)
  26. /// </summary>
  27. public class WFDelegateRuleService : RepositoryFactory, WFDelegateRuleIService
  28. {
  29. #region 获取数据
  30. /// <summary>
  31. /// 获取委托规则分页数据(不写委托人获取全部)
  32. /// </summary>
  33. /// <param name="pagination">分页参数</param>
  34. /// <param name="queryJson">查询条件</param>
  35. /// <param name="userId">委托人</param>
  36. /// <returns></returns>
  37. public DataTable GetPageList(Pagination pagination, string queryJson,string userId=null)
  38. {
  39. try
  40. {
  41. var strSql = new StringBuilder();
  42. strSql.Append(@"SELECT
  43. w1.Id,
  44. w1.ToUserId,
  45. w1.ToUserName,
  46. w1.BeginDate,
  47. w1.EndDate,
  48. w1.CreateUserId,
  49. w1.CreateUserName,
  50. w1.CreateDate,
  51. w1.Description,
  52. w1.EnabledMark,
  53. COUNT(w2.Id) as shcemeNum
  54. FROM
  55. WF_DelegateRule w1
  56. LEFT JOIN WF_DelegateRuleSchemeInfo w2 ON w2.DelegateRuleId = w1.Id
  57. Where 1=1
  58. ");
  59. var parameter = new List<DbParameter>();
  60. var queryParam = queryJson.ToJObject();
  61. if (!string.IsNullOrEmpty(userId))
  62. {
  63. strSql.Append(@" AND ( w1.CreateUserId = @CreateUserId )");
  64. parameter.Add(DbParameters.CreateDbParameter("@CreateUserId",userId));
  65. }
  66. if (!queryParam["Keyword"].IsEmpty())//关键字查询
  67. {
  68. string keyord = queryParam["Keyword"].ToString();
  69. strSql.Append(@" AND ( w1.ToUserName LIKE @keyword )");
  70. parameter.Add(DbParameters.CreateDbParameter("@keyword", '%' + keyord + '%'));
  71. }
  72. strSql.Append(@" GROUP BY
  73. w1.Id,
  74. w1.ToUserId,
  75. w1.ToUserName,
  76. w1.BeginDate,
  77. w1.EndDate,
  78. w1.CreateUserId,
  79. w1.CreateUserName,
  80. w1.CreateDate,
  81. w1.EnabledMark,
  82. w1.Description ");
  83. return this.BaseRepository().FindTable(strSql.ToString(), parameter.ToArray(), pagination);
  84. }
  85. catch (Exception)
  86. {
  87. throw;
  88. }
  89. }
  90. /// <summary>
  91. /// 获取流程模板信息列表数据
  92. /// </summary>
  93. /// <param name="ruleId">委托规则Id</param>
  94. /// <returns></returns>
  95. public DataTable GetSchemeInfoList(string ruleId)
  96. {
  97. try
  98. {
  99. var strSql = new StringBuilder();
  100. strSql.Append(@"SELECT
  101. w.Id,
  102. w.SchemeCode,
  103. w.SchemeName,
  104. w.SchemeType,
  105. w.SchemeVersion,
  106. w.FrmType,
  107. t2.ItemName AS SchemeTypeName,
  108. w.SortCode,
  109. w.DeleteMark,
  110. w.EnabledMark,
  111. w.Description,
  112. w.CreateDate,
  113. w.CreateUserId,
  114. w.CreateUserName,
  115. w.ModifyDate,
  116. w.ModifyUserId,
  117. w.ModifyUserName,
  118. CASE
  119. WHEN t3.Id IS NOT NULL THEN
  120. '1'
  121. ELSE
  122. '0'
  123. END AS ischecked
  124. FROM
  125. WF_SchemeInfo w
  126. LEFT JOIN Base_DataItemDetail t2 ON t2.ItemDetailId = w.SchemeType
  127. LEFT JOIN WF_DelegateRuleSchemeInfo t3 ON t3.SchemeInfoId = w.Id and t3.DelegateRuleId = @ruleId
  128. WHERE
  129. w.DeleteMark = 0
  130. AND w.EnabledMark = 1
  131. ORDER BY
  132. w.SchemeType,
  133. w.SchemeCode");
  134. var parameter = new List<DbParameter>();
  135. parameter.Add(DbParameters.CreateDbParameter("@ruleId", string.IsNullOrEmpty(ruleId) ? " " : ruleId));
  136. return this.BaseRepository().FindTable(strSql.ToString(), parameter.ToArray());
  137. }
  138. catch (Exception)
  139. {
  140. throw;
  141. }
  142. }
  143. /// <summary>
  144. /// 根据模板信息Id获取委托规则实体
  145. /// </summary>
  146. /// <param name="shcemeInfoId"></param>
  147. /// <returns></returns>
  148. public DataTable GetEntityBySchemeInfoId(string shcemeInfoId,string[] objectIdList)
  149. {
  150. try
  151. {
  152. IPermissionService service = new PermissionService();
  153. string userIdlist = "";
  154. foreach (string item in objectIdList)
  155. {
  156. List<UserRelationEntity> list = service.GetMemberList(item).ToList();
  157. foreach (var item1 in list)
  158. {
  159. if (userIdlist != "")
  160. {
  161. userIdlist += "','";
  162. }
  163. userIdlist += item1.UserId;
  164. }
  165. if (userIdlist != "")
  166. {
  167. userIdlist += "','";
  168. }
  169. userIdlist += item;
  170. }
  171. var strSql = new StringBuilder();
  172. strSql.Append(string.Format(@"SELECT
  173. w1.Id,
  174. w1.ToUserId,
  175. w1.ToUserName,
  176. w1.BeginDate,
  177. w1.EndDate,
  178. w1.CreateDate,
  179. w1.CreateUserId,
  180. w1.CreateUserName,
  181. w1.EnabledMark,
  182. w1.Description
  183. FROM
  184. WF_DelegateRule w1
  185. LEFT JOIN WF_DelegateRuleSchemeInfo w2 ON w2.DelegateRuleId = w1.Id
  186. WHERE
  187. w1.EnabledMark = 1 AND w1.BeginDate <='{0}' AND w1.EndDate >='{0}' AND w1.CreateUserId in ('{1}')
  188. AND w2.SchemeInfoId = @SchemeInfoId
  189. ", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), userIdlist));
  190. var parameter = new List<DbParameter>();
  191. parameter.Add(DbParameters.CreateDbParameter("@SchemeInfoId", shcemeInfoId));
  192. return this.BaseRepository().FindTable(strSql.ToString(), parameter.ToArray());
  193. }
  194. catch (Exception)
  195. {
  196. throw;
  197. }
  198. }
  199. /// <summary>
  200. /// 获取委托规则实体对象
  201. /// </summary>
  202. /// <param name="keyValue"></param>
  203. /// <returns></returns>
  204. public WFDelegateRuleEntity GetEntity(string keyValue)
  205. {
  206. try
  207. {
  208. return this.BaseRepository().FindEntity<WFDelegateRuleEntity>(keyValue);
  209. }
  210. catch
  211. {
  212. throw;
  213. }
  214. }
  215. #endregion
  216. #region 提交数据
  217. /// <summary>
  218. /// 保存委托规则
  219. /// </summary>
  220. /// <returns></returns>
  221. public int SaveDelegateRule(string keyValue,WFDelegateRuleEntity ruleEntity,string[] shcemeInfoIdlist)
  222. {
  223. IRepository db = this.BaseRepository().BeginTrans();
  224. try
  225. {
  226. if (string.IsNullOrEmpty(keyValue))
  227. {
  228. ruleEntity.Create();
  229. db.Insert(ruleEntity);
  230. }
  231. else
  232. {
  233. ruleEntity.Modify(keyValue);
  234. db.Update(ruleEntity);
  235. }
  236. db.Delete<WFDelegateRuleSchemeInfoEntity>(ruleEntity.Id, "DelegateRuleId");
  237. foreach (string item in shcemeInfoIdlist)
  238. {
  239. WFDelegateRuleSchemeInfoEntity entity = new WFDelegateRuleSchemeInfoEntity();
  240. entity.Create();
  241. entity.DelegateRuleId = ruleEntity.Id;
  242. entity.SchemeInfoId = item;
  243. db.Insert(entity);
  244. }
  245. db.Commit();
  246. return 1;
  247. }
  248. catch
  249. {
  250. db.Rollback();
  251. throw;
  252. }
  253. }
  254. /// <summary>
  255. /// 删除委托规则
  256. /// </summary>
  257. /// <param name="keyValue"></param>
  258. /// <returns></returns>
  259. public int DeleteRule(string keyValue)
  260. {
  261. IRepository db = this.BaseRepository().BeginTrans();
  262. try
  263. {
  264. db.Delete<WFDelegateRuleEntity>(keyValue);
  265. db.Delete<WFDelegateRuleSchemeInfoEntity>(keyValue, "DelegateRuleId");
  266. db.Commit();
  267. return 1;
  268. }
  269. catch
  270. {
  271. db.Rollback();
  272. throw;
  273. }
  274. }
  275. /// <summary>
  276. /// 使能委托规则
  277. /// </summary>
  278. /// <param name="keyValue"></param>
  279. /// <param name="enableMark"></param>
  280. /// <returns></returns>
  281. public int UpdateRuleEnable(string keyValue, int enableMark)
  282. {
  283. try
  284. {
  285. WFDelegateRuleEntity entity = new WFDelegateRuleEntity();
  286. entity.Modify(keyValue);
  287. entity.EnabledMark = enableMark;
  288. this.BaseRepository().Update(entity);
  289. return 1;
  290. }
  291. catch {
  292. throw;
  293. }
  294. }
  295. #endregion
  296. }
  297. }