BaseWarehouse.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. using SqlSugar;
  2. using System;
  3. using System.Collections.Generic;
  4. using WMS.Info;
  5. using WMS.Util;
  6. namespace WMS.Core
  7. {
  8. public class BaseWarehouse
  9. {
  10. public const string WarehouseHead = "37731699696042abb0d46c7699e29c60";
  11. /// <summary>
  12. /// 获取列表数据
  13. /// <summary>
  14. /// <returns></returns>
  15. public IEnumerable<BASE_WAREHOUSE> GetList(string keyword)
  16. {
  17. try
  18. {
  19. return SysDbCore.GetDbCtx().Queryable<BASE_WAREHOUSE>().Where(it => it.F_ISDELETE == 0).WhereIF(!keyword.IsEmpty(), it => it.F_NO.Contains(keyword) || it.F_NAME.Contains(keyword)).ToList();
  20. }
  21. catch (Exception ex)
  22. {
  23. throw ex;
  24. }
  25. }
  26. /// <summary>
  27. /// 获取启用列表数据
  28. /// <summary>
  29. /// <returns></returns>
  30. public IEnumerable<BASE_WAREHOUSE> GetEnableList()
  31. {
  32. try
  33. {
  34. return SysDbCore.GetDbCtx().Queryable<BASE_WAREHOUSE>().Where(it => it.F_ISDELETE == 0 && it.F_ISSTOP == 0).ToList();
  35. }
  36. catch (Exception ex)
  37. {
  38. throw ex;
  39. }
  40. }
  41. /// <summary>
  42. /// 获取树型
  43. /// </summary>
  44. /// <returns></returns>
  45. public List<TreeModel> GetCheckTree()
  46. {
  47. List<BASE_WAREHOUSE> list = SysDbCore.GetDbCtx().Queryable<BASE_WAREHOUSE>().Where(it => it.F_ISDELETE == 0 && it.F_ISSTOP == 0).ToList();
  48. List<TreeModel> treeList = new List<TreeModel>();
  49. {
  50. TreeModel node = new TreeModel();
  51. node.id = ACLAuthorize.ALLAuthorize;
  52. node.text = " 仓库";
  53. node.value = "";
  54. node.showcheck = true;
  55. node.checkstate = 0;
  56. node.isexpand = true;
  57. node.icon = ACLAuthorize.IcoAuthorize;
  58. node.parentId = "";
  59. treeList.Add(node);
  60. }
  61. foreach (var item in list)
  62. {
  63. TreeModel node = new TreeModel();
  64. node.id = item.F_NO;
  65. node.text = item.F_NAME;
  66. node.value = item.F_NO;
  67. node.showcheck = true;
  68. node.checkstate = 0;
  69. node.isexpand = true;
  70. node.icon = ACLAuthorize.IcoAuthorize;
  71. node.parentId = ACLAuthorize.ALLAuthorize;
  72. treeList.Add(node);
  73. }
  74. return treeList.ToTree();
  75. }
  76. /// <summary>
  77. /// 获取树型
  78. /// </summary>
  79. /// <returns></returns>
  80. public List<TreeModel> GetCheckWWTree()
  81. {
  82. List<TreeModel> treeList = new List<TreeModel>();
  83. List<BASE_WAREHOUSE> list = SysDbCore.GetDbCtx().Queryable<BASE_WAREHOUSE>().Where(it => it.F_ISDELETE == 0 && it.F_ISSTOP == 0).ToList();
  84. foreach (var item in list)
  85. {
  86. TreeModel node = new TreeModel();
  87. node.id = item.F_NO;
  88. node.text = item.F_NAME;
  89. node.value = item.F_NO;
  90. node.showcheck = true;
  91. node.checkstate = 0;
  92. node.isexpand = true;
  93. node.icon = ACLAuthorize.IcoAuthorize;
  94. node.parentId = "";
  95. treeList.Add(node);
  96. }
  97. List<BASE_WAREA> warealist = SysDbCore.GetDbCtx().Queryable<BASE_WAREA>().Where(it => it.F_ISDELETE == 0 && it.F_ISSTOP == 0).ToList();
  98. foreach (var item in warealist)
  99. {
  100. TreeModel node = new TreeModel();
  101. node.id = item.F_NO;
  102. node.text = item.F_NAME;
  103. node.value = item.F_NO;
  104. node.showcheck = true;
  105. node.checkstate = 0;
  106. node.isexpand = true;
  107. node.icon = ACLAuthorize.IcoAuthorize;
  108. node.parentId = item.F_WAREHOUSENO;
  109. treeList.Add(node);
  110. }
  111. return treeList.ToTree();
  112. }
  113. public List<TreeModel> GetCheckWWTreeByLocation()
  114. {
  115. List<TreeModel> treeList = new List<TreeModel>();
  116. List<BASE_WAREHOUSE> list = SysDbCore.GetDbCtx().Queryable<BASE_WAREHOUSE>().Where(it => it.F_ISDELETE == 0 && it.F_ISSTOP == 0 && it.F_TYPENUM == 1).ToList();
  117. foreach (var item in list)
  118. {
  119. TreeModel node = new TreeModel();
  120. node.id = item.F_NO;
  121. node.text = item.F_NAME;
  122. node.value = item.F_NO;
  123. node.showcheck = true;
  124. node.checkstate = 0;
  125. node.isexpand = true;
  126. node.icon = ACLAuthorize.IcoAuthorize;
  127. node.parentId = "";
  128. treeList.Add(node);
  129. }
  130. return treeList.ToTree();
  131. }
  132. /// <summary>
  133. /// 获取树型
  134. /// </summary>
  135. /// <returns></returns>
  136. public List<TreeModel> GetCheckWWACLTree()
  137. {
  138. List<TreeModel> treeList = new List<TreeModel>();
  139. List<BASE_WAREHOUSE> list = SysDbCore.GetDbCtx().Queryable<BASE_WAREHOUSE>().Where(it => it.F_ISDELETE == 0 && it.F_ISSTOP == 0).ToList();
  140. {
  141. TreeModel node = new TreeModel();
  142. node.id = ACLAuthorize.ALLAuthorize;
  143. node.text = " 仓库";
  144. node.value = "";
  145. node.showcheck = true;
  146. node.checkstate = 0;
  147. node.isexpand = true;
  148. node.icon = ACLAuthorize.IcoAuthorize;
  149. node.parentId = "";
  150. treeList.Add(node);
  151. }
  152. foreach (var item in list)
  153. {
  154. TreeModel node = new TreeModel();
  155. node.id = WarehouseHead + "_" + item.F_NO;
  156. node.text = item.F_NAME;
  157. node.value = WarehouseHead + "_" + item.F_NO;
  158. node.showcheck = true;
  159. node.checkstate = 0;
  160. node.isexpand = true;
  161. node.icon = ACLAuthorize.IcoAuthorize;
  162. node.parentId = ACLAuthorize.ALLAuthorize;
  163. treeList.Add(node);
  164. }
  165. //List<BASE_WAREA> warealist = SysDbCore.GetDbCtx().Queryable<BASE_WAREA>().Where(it => it.F_ISDELETE == 0 && it.F_ISSTOP == 0).ToList();
  166. //foreach (var item in warealist)
  167. //{
  168. // TreeModel node = new TreeModel();
  169. // node.id = item.F_NO;
  170. // node.text = item.F_NAME;
  171. // node.value = item.F_NO;
  172. // node.showcheck = true;
  173. // node.checkstate = 0;
  174. // node.isexpand = true;
  175. // node.icon = ACLAuthorize.IcoAuthorize;
  176. // node.parentId = WarehouseHead + "_" + item.F_WAREHOUSENO;
  177. // treeList.Add(node);
  178. //}
  179. return treeList.ToTree();
  180. }
  181. /// <summary>
  182. /// 获取分页数据
  183. /// <summary>
  184. /// <returns></returns>
  185. public IEnumerable<BASE_WAREHOUSE> GetPageList(string keyword, Pagination pagination)
  186. {
  187. try
  188. {
  189. int count = 0;
  190. var db = SysDbCore.GetDbCtx().Queryable<BASE_WAREHOUSE>().Where(it => it.F_ISDELETE == 0).WhereIF(!keyword.IsEmpty(), it => it.F_NO.Contains(keyword) || it.F_NAME.Contains(keyword));
  191. List<BASE_WAREHOUSE> list = new List<BASE_WAREHOUSE>();
  192. if (pagination.sord.ToUpper() == "ASC")
  193. {
  194. list = db.OrderBy(pagination.sidx).ToPageList(pagination.page, pagination.rows, ref count);
  195. }
  196. else
  197. {
  198. string orderstr = pagination.sidx + " desc";
  199. list = db.OrderBy(orderstr).ToPageList(pagination.page, pagination.rows, ref count);
  200. }
  201. pagination.records = count;
  202. return list;
  203. }
  204. catch (Exception ex)
  205. {
  206. throw ex;
  207. }
  208. }
  209. /// <summary>
  210. /// 获取实体数据
  211. /// <param name="keyValue">主键</param>
  212. /// <summary>
  213. /// <returns></returns>
  214. public BASE_WAREHOUSE GetEntity(string keyValue)
  215. {
  216. try
  217. {
  218. return SysDbCore.GetDbCtx().Queryable<BASE_WAREHOUSE>().Where(it => it.F_ISDELETE == 0 && it.F_NO == keyValue).First();
  219. }
  220. catch (Exception ex)
  221. {
  222. throw ex;
  223. }
  224. }
  225. /// <summary>
  226. /// 删除实体数据
  227. /// <param name="keyValue">主键</param>
  228. /// <summary>
  229. /// <returns></returns>
  230. public void DeleteEntity(string keyValue)
  231. {
  232. try
  233. {
  234. //SysDbCore.GetDbCtx().Deleteable<BASE_WAREHOUSE>().Where(it => it.F_NO == keyValue).ExecuteCommand();
  235. SysDbCore.GetDbCtx().Updateable<BASE_WAREHOUSE>().UpdateColumns(it => new BASE_WAREHOUSE { F_ISDELETE = 1 }).Where(it => it.F_NO == keyValue).ExecuteCommand();
  236. }
  237. catch (Exception ex)
  238. {
  239. throw ex;
  240. }
  241. }
  242. /// <summary>
  243. /// 保存实体数据(新增、修改)
  244. /// <param name="keyValue">主键</param>
  245. /// <summary>
  246. /// <returns></returns>
  247. public void SaveEntity(LoginUserInfo loginUserInfo, string keyValue, BASE_WAREHOUSE entity)
  248. {
  249. try
  250. {
  251. if (entity == null)
  252. {
  253. throw SysExCore.ThrowFailException("输入数据为空。");
  254. }
  255. if (string.IsNullOrWhiteSpace(entity.F_NO))
  256. {
  257. throw SysExCore.ThrowFailException("编码为空。");
  258. }
  259. if (string.IsNullOrWhiteSpace(entity.F_NAME))
  260. {
  261. throw SysExCore.ThrowFailException("名称为空。");
  262. }
  263. entity.F_EDITTIME = DateTime.Now;
  264. entity.F_EDITUSERNO = loginUserInfo.UserNo;
  265. if (string.IsNullOrEmpty(keyValue))
  266. {
  267. var item = SysDbCore.GetDbCtx().Queryable<BASE_WAREHOUSE>().First(v => v.F_NO == entity.F_NO);
  268. if (item != null)
  269. {
  270. throw SysExCore.ThrowFailException("添加仓库时,仓库编号不能重复。");
  271. }
  272. entity.F_ADDTIME = DateTime.Now;
  273. entity.F_ADDUSERNO = loginUserInfo.UserNo;
  274. entity.F_ISDELETE = 0;
  275. //entity.F_ISSTOP = 0;
  276. SysDbCore.GetDbCtx().Insertable(entity).ExecuteCommand();
  277. }
  278. else
  279. {
  280. SysDbCore.GetDbCtx().Updateable(entity).IgnoreColumns(it => new { it.F_ADDTIME, it.F_ADDUSERNO }).Where(it => it.F_NO == keyValue).ExecuteCommand();
  281. }
  282. }
  283. catch (Exception ex)
  284. {
  285. throw ex;
  286. }
  287. }
  288. /// <summary>
  289. /// 获取仓库和区域列表数据
  290. /// </summary>
  291. /// <param name="parentId">父节点主键(0表示顶层)</param>
  292. /// <param name="keyword">关键字查询(名称/编号)</param>
  293. /// <returns></returns>
  294. //public List<V_WMS_WAREHOUSEWAREA> GetList(string parentId, string keyword)
  295. //{
  296. // try
  297. // {
  298. // //if (string.IsNullOrWhiteSpace(parentId))
  299. // //{
  300. // // parentId = "0";
  301. // //}
  302. // //var db = SysDbCore.GetDbCtx().Queryable<V_WMS_WAREHOUSEWAREA>().Where(v => v.F_PARENTID == parentId);
  303. // //var list = db.Where(t => t.F_NAME.Contains(keyword)).ToList();
  304. // return null;
  305. // }
  306. // catch (Exception ex)
  307. // {
  308. // throw ex;
  309. // }
  310. //}
  311. public Dictionary<string, BASE_WAREHOUSE> GetMap()
  312. {
  313. try
  314. {
  315. Dictionary<string, BASE_WAREHOUSE> dics = new Dictionary<string, BASE_WAREHOUSE>();
  316. SysDbCore.GetDbCtx().Queryable<BASE_WAREHOUSE>().ToList().ForEach(it => dics.Add(it.F_NO, it));
  317. return dics;
  318. }
  319. catch (Exception ex)
  320. {
  321. throw ex;
  322. }
  323. }
  324. }
  325. }