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.
 
 
 
 
 
 

405 lines
12 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. {
  121. try
  122. {
  123. Dictionary<string, CompanyModel> dic = cache.Read<Dictionary<string, CompanyModel>>(cacheKey + "dic", CacheId.company);
  124. if (dic == null)
  125. {
  126. dic = new Dictionary<string, CompanyModel>();
  127. List<CompanyEntity> list = GetList();
  128. foreach (var item in list)
  129. {
  130. CompanyModel model = new CompanyModel
  131. {
  132. parentId = item.F_ParentId,
  133. name = item.F_FullName
  134. };
  135. dic.Add(item.F_CompanyId, model);
  136. cache.Write(cacheKey + "dic", dic, CacheId.company);
  137. }
  138. }
  139. return dic;
  140. }
  141. catch (Exception ex)
  142. {
  143. if (ex is ExceptionEx)
  144. {
  145. throw;
  146. }
  147. else
  148. {
  149. throw ExceptionEx.ThrowBusinessException(ex);
  150. }
  151. }
  152. }
  153. /// <summary>
  154. /// 获取公司列表数据
  155. /// </summary>
  156. /// <param name="keyWord">查询关键字</param>
  157. /// <returns></returns>
  158. public List<CompanyEntity> GetList(string keyWord)
  159. {
  160. try
  161. {
  162. List<CompanyEntity> list = GetList();
  163. if (!string.IsNullOrEmpty(keyWord))
  164. {
  165. list = list.FindAll(t => t.F_FullName.Contains(keyWord) || t.F_EnCode.Contains(keyWord) || t.F_ShortName.Contains(keyWord));
  166. }
  167. return list;
  168. }
  169. catch (Exception ex)
  170. {
  171. if (ex is ExceptionEx)
  172. {
  173. throw;
  174. }
  175. else
  176. {
  177. throw ExceptionEx.ThrowBusinessException(ex);
  178. }
  179. }
  180. }
  181. /// <summary>
  182. /// 获取公司信息实体
  183. /// </summary>
  184. /// <param name="keyValue">主键</param>
  185. /// <returns></returns>
  186. public CompanyEntity GetEntity(string keyValue)
  187. {
  188. try
  189. {
  190. List<CompanyEntity> list = GetList();
  191. CompanyEntity entity = list.Find(t => t.F_CompanyId.Equals(keyValue));
  192. return entity;
  193. }
  194. catch (Exception ex)
  195. {
  196. if (ex is ExceptionEx)
  197. {
  198. throw;
  199. }
  200. else
  201. {
  202. throw ExceptionEx.ThrowBusinessException(ex);
  203. }
  204. }
  205. }
  206. /// <summary>
  207. /// 获取公司信息
  208. /// </summary>
  209. /// <returns></returns>
  210. public CompanyEntity GetDetail()
  211. {
  212. try
  213. {
  214. List<CompanyEntity> list = GetList();
  215. CompanyEntity entity = list.Find(x => x.F_DeleteMark == 0 && x.F_EnabledMark == 1);
  216. return entity;
  217. }
  218. catch (Exception ex)
  219. {
  220. if (ex is ExceptionEx)
  221. {
  222. throw;
  223. }
  224. else
  225. {
  226. throw ExceptionEx.ThrowBusinessException(ex);
  227. }
  228. }
  229. }
  230. /// <summary>
  231. /// 获取公司信息实体
  232. /// </summary>
  233. /// <param name="keyValue">主键</param>
  234. /// <returns></returns>
  235. public bool GetAny()
  236. {
  237. try
  238. {
  239. return companyService.GetAny();
  240. }
  241. catch (Exception ex)
  242. {
  243. if (ex is ExceptionEx)
  244. {
  245. throw;
  246. }
  247. else
  248. {
  249. throw ExceptionEx.ThrowBusinessException(ex);
  250. }
  251. }
  252. }
  253. /// <summary>
  254. /// 获取树形数据
  255. /// </summary>
  256. /// <param name="parentId">父级id</param>
  257. /// <returns></returns>
  258. public List<TreeModel> GetTree(string parentId)
  259. {
  260. try
  261. {
  262. List<CompanyEntity> list = GetList();
  263. List<TreeModel> treeList = new List<TreeModel>();
  264. foreach (var item in list)
  265. {
  266. TreeModel node = new TreeModel
  267. {
  268. id = item.F_CompanyId,
  269. text = item.F_FullName,
  270. value = item.F_CompanyId,
  271. showcheck = false,
  272. checkstate = 0,
  273. isexpand = true,
  274. parentId = item.F_ParentId
  275. };
  276. treeList.Add(node);
  277. }
  278. return treeList.ToTree(parentId);
  279. }
  280. catch (Exception ex)
  281. {
  282. if (ex is ExceptionEx)
  283. {
  284. throw;
  285. }
  286. else
  287. {
  288. throw ExceptionEx.ThrowBusinessException(ex);
  289. }
  290. }
  291. }
  292. /// <summary>
  293. /// 获取公司本身和子公司的id
  294. /// </summary>
  295. /// <param name="parentId">父级ID</param>
  296. /// <returns></returns>
  297. public List<string> GetSubNodes(string parentId)
  298. {
  299. try
  300. {
  301. if (string.IsNullOrEmpty(parentId))
  302. {
  303. return new List<string>();
  304. }
  305. List<string> res = new List<string>();
  306. res.Add(parentId);
  307. List<TreeModel> list = GetTree(parentId);
  308. GetSubNodes(list, res);
  309. return res;
  310. }
  311. catch (Exception ex)
  312. {
  313. if (ex is ExceptionEx)
  314. {
  315. throw;
  316. }
  317. else
  318. {
  319. throw ExceptionEx.ThrowBusinessException(ex);
  320. }
  321. }
  322. }
  323. /// <summary>
  324. /// 遍历树形数据获取全部子节点ID
  325. /// </summary>
  326. /// <param name="list">树形数据列表</param>
  327. /// <param name="ourList">输出数据列表</param>
  328. private void GetSubNodes(List<TreeModel> list, List<string> ourList)
  329. {
  330. foreach (var item in list)
  331. {
  332. ourList.Add(item.id);
  333. if (item.hasChildren)
  334. {
  335. GetSubNodes(item.ChildNodes, ourList);
  336. }
  337. }
  338. }
  339. #endregion
  340. #region 提交数据
  341. /// <summary>
  342. /// 虚拟删除公司信息
  343. /// </summary>
  344. /// <param name="keyValue">主键</param>
  345. public void VirtualDelete(string keyValue)
  346. {
  347. try
  348. {
  349. cache.Remove(cacheKey, CacheId.company);
  350. cache.Remove(cacheKey + "dic", CacheId.company);
  351. companyService.VirtualDelete(keyValue);
  352. }
  353. catch (Exception ex)
  354. {
  355. if (ex is ExceptionEx)
  356. {
  357. throw;
  358. }
  359. else
  360. {
  361. throw ExceptionEx.ThrowBusinessException(ex);
  362. }
  363. }
  364. }
  365. /// <summary>
  366. /// 保存公司信息(新增、修改)
  367. /// </summary>
  368. /// <param name="keyValue">主键值</param>
  369. /// <param name="companyEntity">公司实体</param>
  370. /// <returns></returns>
  371. public void SaveEntity(string keyValue, CompanyEntity companyEntity)
  372. {
  373. try
  374. {
  375. cache.Remove(cacheKey, CacheId.company);
  376. cache.Remove(cacheKey + "dic", CacheId.company);
  377. companyService.SaveEntity(keyValue, companyEntity);
  378. }
  379. catch (Exception ex)
  380. {
  381. if (ex is ExceptionEx)
  382. {
  383. throw;
  384. }
  385. else
  386. {
  387. throw ExceptionEx.ThrowBusinessException(ex);
  388. }
  389. }
  390. }
  391. #endregion
  392. }
  393. }