25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

372 lines
11 KiB

  1. using Learun.Cache.Base;
  2. using Learun.Cache.Factory;
  3. using Learun.Util;
  4. using System;
  5. using System.Collections.Generic;
  6. namespace Learun.Application.Organization
  7. {
  8. /// <summary>
  9. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  10. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  11. /// 创建人:陈彬彬
  12. /// 日 期:2017.04.17
  13. /// 描 述:公司管理
  14. /// </summary>
  15. public class CompanyBLL : CompanyIBLL
  16. {
  17. #region 属性
  18. private CompanyService companyService = new CompanyService();
  19. #endregion
  20. #region 缓存定义
  21. private ICache cache = CacheFactory.CaChe();
  22. private string cacheKey = "Learun_adms_company";
  23. #endregion
  24. #region 获取数据
  25. /// <summary>
  26. /// 获取公司列表数据
  27. /// </summary>
  28. /// <returns></returns>
  29. public List<CompanyEntity> GetList()
  30. {
  31. try
  32. {
  33. List<CompanyEntity> list = cache.Read<List<CompanyEntity>>(cacheKey, CacheId.company);
  34. if (list == null)
  35. {
  36. list = (List<CompanyEntity>)companyService.GetList();
  37. cache.Write<List<CompanyEntity>>(cacheKey, list, CacheId.company);
  38. }
  39. return list;
  40. }
  41. catch (Exception ex)
  42. {
  43. if (ex is ExceptionEx)
  44. {
  45. throw;
  46. }
  47. else
  48. {
  49. throw ExceptionEx.ThrowBusinessException(ex);
  50. }
  51. }
  52. }
  53. /// <summary>
  54. /// 获取公司列表信息(微信用)
  55. /// </summary>
  56. /// <param name="keyWord">查询关键字</param>
  57. /// <returns></returns>
  58. public List<CompanyEntity> GetWeChatList(string keyWord)
  59. {
  60. try
  61. {
  62. return (List<CompanyEntity>)companyService.GetWeChatList(keyWord);
  63. }
  64. catch (Exception ex)
  65. {
  66. if (ex is ExceptionEx)
  67. {
  68. throw;
  69. }
  70. else
  71. {
  72. throw ExceptionEx.ThrowBusinessException(ex);
  73. }
  74. }
  75. }
  76. /// <summary>
  77. /// 获取微信人员树形数据
  78. /// </summary>
  79. /// <param name="parentId">父级id</param>
  80. /// <returns></returns>
  81. public List<TreeModel> GetWeChatTree(string parentId)
  82. {
  83. try
  84. {
  85. List<CompanyEntity> list = GetWeChatList("");
  86. List<TreeModel> treeList = new List<TreeModel>();
  87. foreach (var item in list)
  88. {
  89. TreeModel node = new TreeModel
  90. {
  91. id = item.F_CompanyId,
  92. text = item.F_FullName,
  93. value = item.F_CompanyId,
  94. showcheck = false,
  95. checkstate = 0,
  96. isexpand = true,
  97. parentId = item.F_ParentId
  98. };
  99. treeList.Add(node);
  100. }
  101. return treeList.ToTree(parentId);
  102. }
  103. catch (Exception ex)
  104. {
  105. if (ex is ExceptionEx)
  106. {
  107. throw;
  108. }
  109. else
  110. {
  111. throw ExceptionEx.ThrowBusinessException(ex);
  112. }
  113. }
  114. }
  115. /// <summary>
  116. /// 获取公司映射数据
  117. /// </summary>
  118. /// <returns></returns>
  119. public Dictionary<string,CompanyModel> GetModelMap() {
  120. try
  121. {
  122. Dictionary<string, CompanyModel> dic = cache.Read<Dictionary<string, CompanyModel>>(cacheKey + "dic", CacheId.company);
  123. if (dic == null) {
  124. dic = new Dictionary<string, CompanyModel>();
  125. List<CompanyEntity> list = GetList();
  126. foreach (var item in list)
  127. {
  128. CompanyModel model = new CompanyModel
  129. {
  130. parentId = item.F_ParentId,
  131. name = item.F_FullName
  132. };
  133. dic.Add(item.F_CompanyId, model);
  134. cache.Write(cacheKey + "dic", dic, CacheId.company);
  135. }
  136. }
  137. return dic;
  138. }
  139. catch (Exception ex)
  140. {
  141. if (ex is ExceptionEx)
  142. {
  143. throw;
  144. }
  145. else
  146. {
  147. throw ExceptionEx.ThrowBusinessException(ex);
  148. }
  149. }
  150. }
  151. /// <summary>
  152. /// 获取公司列表数据
  153. /// </summary>
  154. /// <param name="keyWord">查询关键字</param>
  155. /// <returns></returns>
  156. public List<CompanyEntity> GetList(string keyWord)
  157. {
  158. try
  159. {
  160. List<CompanyEntity> list = GetList();
  161. if (!string.IsNullOrEmpty(keyWord)) {
  162. list = list.FindAll(t => t.F_FullName.Contains(keyWord) || t.F_EnCode.Contains(keyWord) || t.F_ShortName.Contains(keyWord));
  163. }
  164. return list;
  165. }
  166. catch (Exception ex)
  167. {
  168. if (ex is ExceptionEx)
  169. {
  170. throw;
  171. }
  172. else
  173. {
  174. throw ExceptionEx.ThrowBusinessException(ex);
  175. }
  176. }
  177. }
  178. /// <summary>
  179. /// 获取公司信息实体
  180. /// </summary>
  181. /// <param name="keyValue">主键</param>
  182. /// <returns></returns>
  183. public CompanyEntity GetEntity(string keyValue)
  184. {
  185. try
  186. {
  187. List<CompanyEntity> list = GetList();
  188. CompanyEntity entity = list.Find(t => t.F_CompanyId.Equals(keyValue));
  189. return entity;
  190. }
  191. catch (Exception ex)
  192. {
  193. if (ex is ExceptionEx)
  194. {
  195. throw;
  196. }
  197. else
  198. {
  199. throw ExceptionEx.ThrowBusinessException(ex);
  200. }
  201. }
  202. }
  203. /// <summary>
  204. /// 获取公司信息实体
  205. /// </summary>
  206. /// <param name="keyValue">主键</param>
  207. /// <returns></returns>
  208. public bool GetAny()
  209. {
  210. try
  211. {
  212. return companyService.GetAny();
  213. }
  214. catch (Exception ex)
  215. {
  216. if (ex is ExceptionEx)
  217. {
  218. throw;
  219. }
  220. else
  221. {
  222. throw ExceptionEx.ThrowBusinessException(ex);
  223. }
  224. }
  225. }
  226. /// <summary>
  227. /// 获取树形数据
  228. /// </summary>
  229. /// <param name="parentId">父级id</param>
  230. /// <returns></returns>
  231. public List<TreeModel> GetTree(string parentId) {
  232. try
  233. {
  234. List<CompanyEntity> list = GetList();
  235. List<TreeModel> treeList = new List<TreeModel>();
  236. foreach (var item in list) {
  237. TreeModel node = new TreeModel
  238. {
  239. id = item.F_CompanyId,
  240. text = item.F_FullName,
  241. value = item.F_CompanyId,
  242. showcheck = false,
  243. checkstate = 0,
  244. isexpand = true,
  245. parentId = item.F_ParentId
  246. };
  247. treeList.Add(node);
  248. }
  249. return treeList.ToTree(parentId);
  250. }
  251. catch (Exception ex)
  252. {
  253. if (ex is ExceptionEx)
  254. {
  255. throw;
  256. }
  257. else
  258. {
  259. throw ExceptionEx.ThrowBusinessException(ex);
  260. }
  261. }
  262. }
  263. /// <summary>
  264. /// 获取公司本身和子公司的id
  265. /// </summary>
  266. /// <param name="parentId">父级ID</param>
  267. /// <returns></returns>
  268. public List<string> GetSubNodes(string parentId)
  269. {
  270. try
  271. {
  272. if (string.IsNullOrEmpty(parentId)) {
  273. return new List<string>();
  274. }
  275. List<string> res = new List<string>();
  276. res.Add(parentId);
  277. List<TreeModel> list = GetTree(parentId);
  278. GetSubNodes(list, res);
  279. return res;
  280. }
  281. catch (Exception ex)
  282. {
  283. if (ex is ExceptionEx)
  284. {
  285. throw;
  286. }
  287. else
  288. {
  289. throw ExceptionEx.ThrowBusinessException(ex);
  290. }
  291. }
  292. }
  293. /// <summary>
  294. /// 遍历树形数据获取全部子节点ID
  295. /// </summary>
  296. /// <param name="list">树形数据列表</param>
  297. /// <param name="ourList">输出数据列表</param>
  298. private void GetSubNodes(List<TreeModel> list, List<string> ourList) {
  299. foreach (var item in list) {
  300. ourList.Add(item.id);
  301. if (item.hasChildren) {
  302. GetSubNodes(item.ChildNodes, ourList);
  303. }
  304. }
  305. }
  306. #endregion
  307. #region 提交数据
  308. /// <summary>
  309. /// 虚拟删除公司信息
  310. /// </summary>
  311. /// <param name="keyValue">主键</param>
  312. public void VirtualDelete(string keyValue)
  313. {
  314. try
  315. {
  316. cache.Remove(cacheKey, CacheId.company);
  317. cache.Remove(cacheKey + "dic", CacheId.company);
  318. companyService.VirtualDelete(keyValue);
  319. }
  320. catch (Exception ex)
  321. {
  322. if (ex is ExceptionEx)
  323. {
  324. throw;
  325. }
  326. else
  327. {
  328. throw ExceptionEx.ThrowBusinessException(ex);
  329. }
  330. }
  331. }
  332. /// <summary>
  333. /// 保存公司信息(新增、修改)
  334. /// </summary>
  335. /// <param name="keyValue">主键值</param>
  336. /// <param name="companyEntity">公司实体</param>
  337. /// <returns></returns>
  338. public void SaveEntity(string keyValue, CompanyEntity companyEntity)
  339. {
  340. try
  341. {
  342. cache.Remove(cacheKey, CacheId.company);
  343. cache.Remove(cacheKey + "dic", CacheId.company);
  344. companyService.SaveEntity(keyValue, companyEntity);
  345. }
  346. catch (Exception ex)
  347. {
  348. if (ex is ExceptionEx)
  349. {
  350. throw;
  351. }
  352. else
  353. {
  354. throw ExceptionEx.ThrowBusinessException(ex);
  355. }
  356. }
  357. }
  358. #endregion
  359. }
  360. }