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.
 
 
 
 
 
 

516 lines
18 KiB

  1. using Dapper;
  2. using Learun.DataBase.Repository;
  3. using Learun.Util;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Text;
  8. namespace Learun.Application.WorkFlow
  9. {
  10. /// <summary>
  11. /// 版 本 Learun-ADMS V7.0.3 力软敏捷开发框架
  12. /// Copyright (c) 2013-2018 上海力软信息技术有限公司
  13. /// 创建人:力软-框架开发组
  14. /// 日 期:2018.12.06
  15. /// 描 述:工作流模板(新)
  16. /// </summary>
  17. public class NWFSchemeService : RepositoryFactory
  18. {
  19. #region 获取数据
  20. /// <summary>
  21. /// 获取流程分页列表
  22. /// </summary>
  23. /// <param name="pagination">分页参数</param>
  24. /// <param name="queryJson">查询条件</param>
  25. /// <returns></returns>
  26. public IEnumerable<NWFSchemeInfoEntity> GetInfoPageList(Pagination pagination, string queryJson)
  27. {
  28. try
  29. {
  30. var strSql = new StringBuilder();
  31. strSql.Append("SELECT t.* ");
  32. strSql.Append(",t1.F_Type,t1.F_CreateDate,t1.F_CreateUserId,t1.F_CreateUserName ");
  33. strSql.Append(" FROM LR_NWF_SchemeInfo t LEFT JOIN LR_NWF_Scheme t1 ON t.F_SchemeId = t1.F_Id WHERE 1=1 ");
  34. var dp = new DynamicParameters();
  35. if (!string.IsNullOrEmpty(queryJson))
  36. {
  37. var queryParam = queryJson.ToJObject();
  38. if (!queryParam["keyword"].IsEmpty())
  39. {
  40. strSql.Append(" AND ( t.F_Name like @keyword OR t.F_Code like @keyword ) ");
  41. dp.Add("keyword", "%" + queryParam["keyword"].ToString() + "%", DbType.String);
  42. }
  43. if (!queryParam["category"].IsEmpty())
  44. {
  45. strSql.Append(" AND t.F_Category = @category ");
  46. dp.Add("category", queryParam["category"].ToString(), DbType.String);
  47. }
  48. }
  49. return this.BaseRepository().FindList<NWFSchemeInfoEntity>(strSql.ToString(), dp, pagination);
  50. }
  51. catch (Exception ex)
  52. {
  53. if (ex is ExceptionEx)
  54. {
  55. throw;
  56. }
  57. else
  58. {
  59. throw ExceptionEx.ThrowServiceException(ex);
  60. }
  61. }
  62. }
  63. /// <summary>
  64. /// 获取自定义流程列表
  65. /// </summary>
  66. /// <param name="userInfo">用户信息</param>
  67. /// <returns></returns>
  68. public IEnumerable<NWFSchemeInfoEntity> GetInfoList(UserInfo userInfo)
  69. {
  70. try
  71. {
  72. string userId = userInfo.userId;
  73. string postIds = userInfo.postIds;
  74. string roleIds = userInfo.roleIds;
  75. List<NWFSchemeAuthEntity> list = (List<NWFSchemeAuthEntity>)this.BaseRepository().FindList<NWFSchemeAuthEntity>(t => t.F_ObjId == null
  76. || userId.Contains(t.F_ObjId)
  77. || postIds.Contains(t.F_ObjId)
  78. || roleIds.Contains(t.F_ObjId)
  79. );
  80. string schemeinfoIds = "";
  81. foreach (var item in list)
  82. {
  83. schemeinfoIds += "'" + item.F_SchemeInfoId + "',";
  84. }
  85. schemeinfoIds = "(" + schemeinfoIds.Remove(schemeinfoIds.Length - 1, 1) + ")";
  86. var strSql = new StringBuilder();
  87. strSql.Append("SELECT * ");
  88. strSql.Append(" FROM LR_NWF_SchemeInfo t WHERE (t.F_EnabledMark = 1 AND t.F_Mark = 1 AND t.F_Kind = 1 AND t.F_Id in " + schemeinfoIds + ")");
  89. strSql.Append(" or t.F_Id in('3a9e9db8-a928-435b-a9d2-4a4660b4cdeb','307b2c75-174f-424d-84d8-e0f8374ec6d1')");
  90. return this.BaseRepository().FindList<NWFSchemeInfoEntity>(strSql.ToString());
  91. }
  92. catch (Exception ex)
  93. {
  94. if (ex is ExceptionEx)
  95. {
  96. throw;
  97. }
  98. else
  99. {
  100. throw ExceptionEx.ThrowServiceException(ex);
  101. }
  102. }
  103. }
  104. /// <summary>
  105. /// 获取流程列表
  106. /// </summary>
  107. /// <returns></returns>
  108. public IEnumerable<NWFSchemeInfoEntity> GetInfoList()
  109. {
  110. try
  111. {
  112. var strSql = new StringBuilder();
  113. strSql.Append("SELECT * ");
  114. strSql.Append(" FROM LR_NWF_SchemeInfo t WHERE t.F_EnabledMark = 1 ");
  115. return this.BaseRepository().FindList<NWFSchemeInfoEntity>(strSql.ToString());
  116. }
  117. catch (Exception ex)
  118. {
  119. if (ex is ExceptionEx)
  120. {
  121. throw;
  122. }
  123. else
  124. {
  125. throw ExceptionEx.ThrowServiceException(ex);
  126. }
  127. }
  128. }
  129. /// <summary>
  130. /// 获取流程模板分页列表
  131. /// </summary>
  132. /// <param name="pagination">分页参数</param>
  133. /// <param name="userInfo">登录者信息</param>
  134. /// <param name="queryJson">查询参数</param>
  135. /// <returns></returns>
  136. public IEnumerable<NWFSchemeInfoEntity> GetAppInfoPageList(Pagination pagination, UserInfo userInfo, string queryJson)
  137. {
  138. try
  139. {
  140. string userId = userInfo.userId;
  141. string postIds = userInfo.postIds;
  142. string roleIds = userInfo.roleIds;
  143. List<NWFSchemeAuthEntity> list = (List<NWFSchemeAuthEntity>)this.BaseRepository().FindList<NWFSchemeAuthEntity>(t => t.F_ObjId == null
  144. || userId.Contains(t.F_ObjId)
  145. || postIds.Contains(t.F_ObjId)
  146. || roleIds.Contains(t.F_ObjId)
  147. );
  148. string schemeinfoIds = "";
  149. foreach (var item in list)
  150. {
  151. schemeinfoIds += "'" + item.F_SchemeInfoId + "',";
  152. }
  153. schemeinfoIds = "(" + schemeinfoIds.Remove(schemeinfoIds.Length - 1, 1) + ")";
  154. var strSql = new StringBuilder();
  155. strSql.Append("SELECT * ");
  156. strSql.Append(" FROM LR_NWF_SchemeInfo t WHERE t.F_EnabledMark = 1 AND t.F_Mark = 1 AND F_IsInApp = 1 AND t.F_Kind = 1 AND t.F_Id in " + schemeinfoIds);
  157. var queryParam = queryJson.ToJObject();
  158. string keyword = "";
  159. if (!queryParam["keyword"].IsEmpty())
  160. {
  161. strSql.Append(" AND ( t.F_Name like @keyword OR t.F_Code like @keyword ) ");
  162. keyword = "%" + queryParam["keyword"].ToString() + "%";
  163. }
  164. return this.BaseRepository().FindList<NWFSchemeInfoEntity>(strSql.ToString(), new { keyword }, pagination);
  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. /// <summary>
  179. /// 获取模板基础信息的实体
  180. /// </summary>
  181. /// <param name="keyValue">主键</param>
  182. /// <returns></returns>
  183. public NWFSchemeInfoEntity GetInfoEntity(string keyValue)
  184. {
  185. try
  186. {
  187. return this.BaseRepository().FindEntity<NWFSchemeInfoEntity>(keyValue);
  188. }
  189. catch (Exception ex)
  190. {
  191. if (ex is ExceptionEx)
  192. {
  193. throw;
  194. }
  195. else
  196. {
  197. throw ExceptionEx.ThrowServiceException(ex);
  198. }
  199. }
  200. }
  201. /// <summary>
  202. /// 获取模板基础信息的实体
  203. /// </summary>
  204. /// <param name="code">流程编号</param>
  205. /// <returns></returns>
  206. public NWFSchemeInfoEntity GetInfoEntityByCode(string code)
  207. {
  208. try
  209. {
  210. return this.BaseRepository().FindEntity<NWFSchemeInfoEntity>(t => t.F_Code == code);
  211. }
  212. catch (Exception ex)
  213. {
  214. if (ex is ExceptionEx)
  215. {
  216. throw;
  217. }
  218. else
  219. {
  220. throw ExceptionEx.ThrowServiceException(ex);
  221. }
  222. }
  223. }
  224. /// <summary>
  225. /// 获取流程模板权限列表
  226. /// </summary>
  227. /// <param name="schemeInfoId">模板信息主键</param>
  228. /// <returns></returns>
  229. public IEnumerable<NWFSchemeAuthEntity> GetAuthList(string schemeInfoId)
  230. {
  231. try
  232. {
  233. return this.BaseRepository().FindList<NWFSchemeAuthEntity>(t => t.F_SchemeInfoId == schemeInfoId);
  234. }
  235. catch (Exception ex)
  236. {
  237. if (ex is ExceptionEx)
  238. {
  239. throw;
  240. }
  241. else
  242. {
  243. throw ExceptionEx.ThrowServiceException(ex);
  244. }
  245. }
  246. }
  247. /// <summary>
  248. /// 获取模板列表
  249. /// </summary>
  250. /// <param name="pagination">分页参数</param>
  251. /// <param name="schemeInfoId">流程信息主键</param>
  252. /// <returns></returns>
  253. public IEnumerable<NWFSchemeEntity> GetSchemePageList(Pagination pagination, string schemeInfoId)
  254. {
  255. try
  256. {
  257. var strSql = new StringBuilder();
  258. strSql.Append("SELECT t.F_Id,t.F_SchemeInfoId,t.F_Type,t.F_CreateDate,t.F_CreateUserId,t.F_CreateUserName");
  259. strSql.Append(" FROM LR_NWF_Scheme t ");
  260. strSql.Append(" WHERE t.F_SchemeInfoId = @schemeInfoId ");
  261. return this.BaseRepository().FindList<NWFSchemeEntity>(strSql.ToString(), new { schemeInfoId }, pagination);
  262. }
  263. catch (Exception ex)
  264. {
  265. if (ex is ExceptionEx)
  266. {
  267. throw;
  268. }
  269. else
  270. {
  271. throw ExceptionEx.ThrowServiceException(ex);
  272. }
  273. }
  274. }
  275. /// <summary>
  276. /// 获取模板的实体
  277. /// </summary>
  278. /// <param name="keyValue">主键</param>
  279. /// <returns></returns>
  280. public NWFSchemeEntity GetSchemeEntity(string keyValue)
  281. {
  282. try
  283. {
  284. return this.BaseRepository().FindEntity<NWFSchemeEntity>(keyValue);
  285. }
  286. catch (Exception ex)
  287. {
  288. if (ex is ExceptionEx)
  289. {
  290. throw;
  291. }
  292. else
  293. {
  294. throw ExceptionEx.ThrowServiceException(ex);
  295. }
  296. }
  297. }
  298. #endregion
  299. #region 提交数据
  300. /// <summary>
  301. /// 虚拟删除模板信息
  302. /// </summary>
  303. /// <param name="keyValue">主键</param>
  304. public void DeleteEntity(string keyValue)
  305. {
  306. var db = this.BaseRepository().BeginTrans();
  307. try
  308. {
  309. db.Delete<NWFSchemeInfoEntity>(t => t.F_Id.Equals(keyValue));
  310. db.Delete<NWFSchemeAuthEntity>(t => t.F_SchemeInfoId.Equals(keyValue));
  311. db.Delete<NWFSchemeEntity>(t => t.F_SchemeInfoId.Equals(keyValue));
  312. db.Commit();
  313. }
  314. catch (Exception ex)
  315. {
  316. db.Rollback();
  317. if (ex is ExceptionEx)
  318. {
  319. throw;
  320. }
  321. else
  322. {
  323. throw ExceptionEx.ThrowServiceException(ex);
  324. }
  325. }
  326. }
  327. /// <summary>
  328. /// 保存模板信息
  329. /// </summary>
  330. /// <param name="keyValue">主键</param>
  331. /// <param name="infoEntity">模板基础信息</param>
  332. /// <param name="schemeEntity">模板信息</param>
  333. /// <param name="authList">模板权限信息</param>
  334. public void SaveEntity(string keyValue, NWFSchemeInfoEntity infoEntity, NWFSchemeEntity schemeEntity, List<NWFSchemeAuthEntity> authList)
  335. {
  336. IRepository db = new RepositoryFactory().BaseRepository().BeginTrans();
  337. try
  338. {
  339. if (string.IsNullOrEmpty(keyValue))
  340. {
  341. infoEntity.Create();
  342. }
  343. else
  344. {
  345. infoEntity.Modify(keyValue);
  346. }
  347. #region 模板信息
  348. if (schemeEntity != null)
  349. {
  350. schemeEntity.F_SchemeInfoId = infoEntity.F_Id;
  351. schemeEntity.Create();
  352. db.Insert(schemeEntity);
  353. infoEntity.F_SchemeId = schemeEntity.F_Id;
  354. }
  355. #endregion
  356. #region 模板基础信息
  357. if (!string.IsNullOrEmpty(keyValue))
  358. {
  359. db.Update(infoEntity);
  360. }
  361. else
  362. {
  363. db.Insert(infoEntity);
  364. }
  365. #endregion
  366. #region 流程模板权限信息
  367. string schemeInfoId = infoEntity.F_Id;
  368. db.Delete<NWFSchemeAuthEntity>(t => t.F_SchemeInfoId == schemeInfoId);
  369. foreach (var item in authList)
  370. {
  371. item.Create();
  372. item.F_SchemeInfoId = schemeInfoId;
  373. db.Insert(item);
  374. }
  375. #endregion
  376. db.Commit();
  377. }
  378. catch (Exception ex)
  379. {
  380. db.Rollback();
  381. if (ex is ExceptionEx)
  382. {
  383. throw;
  384. }
  385. else
  386. {
  387. throw ExceptionEx.ThrowServiceException(ex);
  388. }
  389. }
  390. }
  391. /// <summary>
  392. /// 更新流程模板
  393. /// </summary>
  394. /// <param name="schemeInfoId">模板信息主键</param>
  395. /// <param name="schemeId">模板主键</param>
  396. public void UpdateScheme(string schemeInfoId, string schemeId)
  397. {
  398. try
  399. {
  400. NWFSchemeEntity nWFSchemeEntity = GetSchemeEntity(schemeId);
  401. NWFSchemeInfoEntity entity = new NWFSchemeInfoEntity
  402. {
  403. F_Id = schemeInfoId,
  404. F_SchemeId = schemeId
  405. };
  406. if (nWFSchemeEntity.F_Type != 1)
  407. {
  408. entity.F_EnabledMark = 0;
  409. }
  410. this.BaseRepository().Update(entity);
  411. }
  412. catch (Exception ex)
  413. {
  414. if (ex is ExceptionEx)
  415. {
  416. throw;
  417. }
  418. else
  419. {
  420. throw ExceptionEx.ThrowServiceException(ex);
  421. }
  422. }
  423. }
  424. /// <summary>
  425. /// 更新自定义表单模板状态
  426. /// </summary>
  427. /// <param name="schemeInfoId">模板信息主键</param>
  428. /// <param name="state">状态1启用0禁用</param>
  429. public void UpdateState(string schemeInfoId, int state)
  430. {
  431. try
  432. {
  433. NWFSchemeInfoEntity entity = new NWFSchemeInfoEntity
  434. {
  435. F_Id = schemeInfoId,
  436. F_EnabledMark = state
  437. };
  438. this.BaseRepository().Update(entity);
  439. }
  440. catch (Exception ex)
  441. {
  442. if (ex is ExceptionEx)
  443. {
  444. throw;
  445. }
  446. else
  447. {
  448. throw ExceptionEx.ThrowServiceException(ex);
  449. }
  450. }
  451. }
  452. #endregion
  453. #region 扩展数据
  454. /// <summary>
  455. /// 获取流程模板使用次数列表
  456. /// </summary>
  457. /// <param name="queryJson">查询参数</param>
  458. /// <returns></returns>
  459. public IEnumerable<NWFSchemeInfoEntity> GetNWFSchemeUseList(string queryJson)
  460. {
  461. try
  462. {
  463. var dp = new object();
  464. var queryParam = queryJson.ToJObject();
  465. var strSql = new StringBuilder();
  466. strSql.Append("select si.*,p.F_Id as F_ProcessId,p.F_CreateDate from LR_NWF_SchemeInfo si");
  467. strSql.Append(" left join LR_NWF_Scheme s on si.F_Id=s.F_SchemeInfoId and s.F_Type=1 ");
  468. strSql.Append(" left join LR_NWF_Process p on s.F_Id=p.F_SchemeId ");
  469. if (!queryParam["year"].IsEmpty())
  470. {
  471. dp = new { year = queryParam["year"].ToInt() };
  472. strSql.Append(" and DATEPART(yyyy,p.F_CreateDate) = @year ");
  473. }
  474. strSql.Append(" where si.F_EnabledMark=1 ");
  475. return this.BaseRepository().FindList<NWFSchemeInfoEntity>(strSql.ToString(), dp);
  476. }
  477. catch (Exception ex)
  478. {
  479. if (ex is ExceptionEx)
  480. {
  481. throw;
  482. }
  483. else
  484. {
  485. throw ExceptionEx.ThrowServiceException(ex);
  486. }
  487. }
  488. }
  489. #endregion
  490. }
  491. }