RoadFlow2.1 临时演示

AppLibrary.cs 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Linq;
  5. namespace RoadFlow.Platform
  6. {
  7. public class AppLibrary
  8. {
  9. private string cacheKey = RoadFlow.Utility.Keys.CacheKeys.AppLibrary.ToString();
  10. private RoadFlow.Data.Interface.IAppLibrary dataAppLibrary;
  11. public AppLibrary()
  12. {
  13. this.dataAppLibrary = Data.Factory.Factory.GetAppLibrary();
  14. }
  15. /// <summary>
  16. /// 新增
  17. /// </summary>
  18. public int Add(RoadFlow.Data.Model.AppLibrary model)
  19. {
  20. return dataAppLibrary.Add(model);
  21. }
  22. /// <summary>
  23. /// 更新
  24. /// </summary>
  25. public int Update(RoadFlow.Data.Model.AppLibrary model)
  26. {
  27. return dataAppLibrary.Update(model);
  28. }
  29. /// <summary>
  30. /// 查询所有记录
  31. /// </summary>
  32. public List<RoadFlow.Data.Model.AppLibrary> GetAll(bool fromCache=false)
  33. {
  34. if (!fromCache)
  35. {
  36. return dataAppLibrary.GetAll();
  37. }
  38. else
  39. {
  40. object obj = RoadFlow.Cache.IO.Opation.Get(cacheKey);
  41. if (obj != null)
  42. {
  43. return obj as List<RoadFlow.Data.Model.AppLibrary>;
  44. }
  45. else
  46. {
  47. var list = dataAppLibrary.GetAll();
  48. RoadFlow.Cache.IO.Opation.Set(cacheKey, list);
  49. return list;
  50. }
  51. }
  52. }
  53. /// <summary>
  54. /// 查询单条记录
  55. /// </summary>
  56. public RoadFlow.Data.Model.AppLibrary Get(Guid id, bool fromCache=false)
  57. {
  58. if (!fromCache)
  59. {
  60. return dataAppLibrary.Get(id);
  61. }
  62. else
  63. {
  64. var all = GetAll(true);
  65. var app = all.Find(p => p.ID == id);
  66. return app == null ? dataAppLibrary.Get(id) : app;
  67. }
  68. }
  69. /// <summary>
  70. /// 清除缓存
  71. /// </summary>
  72. public void ClearCache()
  73. {
  74. RoadFlow.Cache.IO.Opation.Remove(cacheKey);
  75. }
  76. /// <summary>
  77. /// 删除
  78. /// </summary>
  79. public int Delete(Guid id)
  80. {
  81. return dataAppLibrary.Delete(id);
  82. }
  83. /// <summary>
  84. /// 查询记录条数
  85. /// </summary>
  86. public long GetCount()
  87. {
  88. return dataAppLibrary.GetCount();
  89. }
  90. /// <summary>
  91. /// 得到一页数据
  92. /// </summary>
  93. /// <param name="pager"></param>
  94. /// <param name="query"></param>
  95. /// <param name="order"></param>
  96. /// <param name="size"></param>
  97. /// <param name="numbe"></param>
  98. /// <param name="title"></param>
  99. /// <param name="type"></param>
  100. /// <param name="address"></param>
  101. /// <returns></returns>
  102. public List<RoadFlow.Data.Model.AppLibrary> GetPagerData(out string pager, string query = "", string title = "", string type = "", string address = "")
  103. {
  104. return dataAppLibrary.GetPagerData(out pager, query, "Type,Title", RoadFlow.Utility.Tools.GetPageSize(),
  105. RoadFlow.Utility.Tools.GetPageNumber(), title, type, address);
  106. }
  107. /// <summary>
  108. /// 查询一个类别下所有记录
  109. /// </summary>
  110. public List<RoadFlow.Data.Model.AppLibrary> GetAllByType(Guid type)
  111. {
  112. if (type.IsEmptyGuid())
  113. {
  114. return new List<RoadFlow.Data.Model.AppLibrary>();
  115. }
  116. return dataAppLibrary.GetAllByType(GetAllChildsIDString(type)).OrderBy(p=>p.Title).ToList();
  117. }
  118. /// <summary>
  119. /// 删除记录
  120. /// </summary>
  121. public int Delete(string[] idArray)
  122. {
  123. return dataAppLibrary.Delete(idArray);
  124. }
  125. /// <summary>
  126. /// 删除记录
  127. /// </summary>
  128. public int Delete(string idstring)
  129. {
  130. return idstring.IsNullOrEmpty() ? 0 : dataAppLibrary.Delete(idstring.Split(','));
  131. }
  132. /// <summary>
  133. /// 得到类型选择项
  134. /// </summary>
  135. /// <returns></returns>
  136. public string GetTypeOptions(string value="")
  137. {
  138. return new Dictionary().GetOptionsByCode("AppLibraryTypes", Dictionary.OptionValueField.ID, value);
  139. }
  140. /// <summary>
  141. /// 得到下级ID字符串
  142. /// </summary>
  143. /// <param name="id"></param>
  144. /// <returns></returns>
  145. public string GetAllChildsIDString(Guid id, bool isSelf = true)
  146. {
  147. return new Dictionary().GetAllChildsIDString(id, true);
  148. }
  149. /// <summary>
  150. /// 得到一个类型选择项
  151. /// </summary>
  152. /// <param name="type">程序类型</param>
  153. /// <param name="value"></param>
  154. /// <returns></returns>
  155. public string GetAppsOptions(Guid type, string value = "")
  156. {
  157. if (type.IsEmptyGuid()) return "";
  158. var apps = GetAllByType(type);
  159. StringBuilder options = new StringBuilder();
  160. foreach (var app in apps)
  161. {
  162. options.AppendFormat("<option value=\"{0}\" {1}>{2}</option>", app.ID,
  163. string.Compare(app.ID.ToString(), value, true) == 0 ? "selected=\"selected\"" : "",
  164. app.Title
  165. );
  166. }
  167. return options.ToString();
  168. }
  169. /// <summary>
  170. /// 根据ID得到类型
  171. /// </summary>
  172. /// <param name="id"></param>
  173. /// <returns></returns>
  174. public string GetTypeByID(Guid id)
  175. {
  176. var app = Get(id);
  177. return app == null ? "" : app.Type.ToString();
  178. }
  179. /// <summary>
  180. /// 根据代码查询一条记录
  181. /// </summary>
  182. public RoadFlow.Data.Model.AppLibrary GetByCode(string code)
  183. {
  184. return code.IsNullOrEmpty() ? null : dataAppLibrary.GetByCode(code.Trim());
  185. }
  186. /// <summary>
  187. /// 得到流程运行时地址
  188. /// </summary>
  189. /// <param name="app"></param>
  190. /// <returns></returns>
  191. public string GetFlowRunAddress(RoadFlow.Data.Model.AppLibrary app, string query="")
  192. {
  193. StringBuilder sb = new StringBuilder();
  194. if (app.Params.IsNullOrEmpty())
  195. {
  196. if (!app.Address.Contains("?"))
  197. {
  198. sb.Append(app.Address);
  199. sb.Append("?1=1");
  200. }
  201. }
  202. else
  203. {
  204. if (app.Address.Contains("?"))
  205. {
  206. sb.Append(app.Address);
  207. sb.Append("&");
  208. sb.Append(app.Params.TrimStart('?').TrimStart('&'));
  209. }
  210. else
  211. {
  212. sb.Append(app.Address);
  213. sb.Append("?");
  214. sb.Append(app.Params.TrimStart('?').TrimStart('&'));
  215. }
  216. }
  217. if (!query.IsNullOrEmpty())
  218. {
  219. sb.Append("&");
  220. sb.Append(query.TrimStart('?').TrimStart('&'));
  221. }
  222. return sb.ToString();
  223. }
  224. /// <summary>
  225. /// 更新应用程序库使用人员缓存
  226. /// </summary>
  227. /// <param name="appid"></param>
  228. /// <param name="userIdString"></param>
  229. public List<Guid> UpdateUseMemberCache(Guid appid)
  230. {
  231. string key = RoadFlow.Utility.Keys.CacheKeys.AppLibraryUseMember.ToString();
  232. var obj = RoadFlow.Cache.IO.Opation.Get(key);
  233. Dictionary<Guid, List<Guid>> dict;
  234. if (obj != null && obj is Dictionary<Guid, List<Guid>>)
  235. {
  236. dict = obj as Dictionary<Guid, List<Guid>>;
  237. }
  238. else
  239. {
  240. dict = new Dictionary<Guid, List<Guid>>();
  241. }
  242. var app = new AppLibrary().Get(appid);
  243. if (app == null)
  244. {
  245. return new List<Guid>();
  246. }
  247. if (dict.ContainsKey(appid))
  248. {
  249. if (app.UseMember.IsNullOrEmpty())
  250. {
  251. dict.Remove(appid);
  252. return new List<Guid>();
  253. }
  254. else
  255. {
  256. var userIDs = new Organize().GetAllUsersIdList(app.UseMember);
  257. dict[appid] = userIDs;
  258. return userIDs;
  259. }
  260. }
  261. else if(!app.UseMember.IsNullOrEmpty())
  262. {
  263. var userIDs = new Organize().GetAllUsersIdList(app.UseMember);
  264. dict.Add(appid, userIDs);
  265. return userIDs;
  266. }
  267. return new List<Guid>();
  268. }
  269. /// <summary>
  270. /// 得到一个应用程序库的使用人员
  271. /// </summary>
  272. /// <param name="appid"></param>
  273. /// <returns></returns>
  274. public List<Guid> GetUseMemberCache(Guid appid)
  275. {
  276. string key = RoadFlow.Utility.Keys.CacheKeys.AppLibraryUseMember.ToString();
  277. var obj = RoadFlow.Cache.IO.Opation.Get(key);
  278. if (obj != null && obj is Dictionary<Guid, List<Guid>>)
  279. {
  280. var dict = obj as Dictionary<Guid, List<Guid>>;
  281. if (dict.ContainsKey(appid))
  282. {
  283. return dict[appid];
  284. }
  285. }
  286. var app = new AppLibrary().Get(appid);
  287. if (app == null || app.UseMember.IsNullOrEmpty())
  288. {
  289. return new List<Guid>();
  290. }
  291. return UpdateUseMemberCache(appid);
  292. }
  293. /// <summary>
  294. /// 清除应用程序库的使用人员缓存
  295. /// </summary>
  296. public void ClearUseMemberCache()
  297. {
  298. string key = RoadFlow.Utility.Keys.CacheKeys.AppLibraryUseMember.ToString();
  299. Cache.IO.Opation.Remove(key);
  300. }
  301. }
  302. }