Repository.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. using SqlSugar;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Linq.Expressions;
  6. using System.Text;
  7. using wms.dto;
  8. using wms.dto.request.hj;
  9. using wms.dto.request.hj.dto;
  10. using wms.sqlsugar.model;
  11. using wms.sqlsugar.model.hj;
  12. using wms.util.Check;
  13. using static wms.dto.request.hj.dto.ReportResponse;
  14. namespace wms.sqlsugar
  15. {
  16. /// <summary>
  17. /// 创建仓储
  18. /// </summary>
  19. /// <typeparam name="T"></typeparam>
  20. public class Repository<T> : SimpleClient<T> where T : BaseModel, new()
  21. {
  22. public Repository()
  23. {
  24. //固定数据库用法
  25. base.Context = SqlSugarHelper.Db.GetConnectionScopeWithAttr<T>();
  26. //动态库用法一般用于维护数据库连接字符串根据用法
  27. //if (!SqlSugarHelper.Db.IsAnyConnection("用户读出来的数据库ConfigId"))
  28. //{
  29. // SqlSugarHelper.Db.AddConnection(new ConnectionConfig() { 数据库读出来信息 });
  30. //}
  31. //base.Context = SqlSugarHelper.Db.GetConnectionScope("用户读出来的数据库ConfigId");
  32. }
  33. public T InsertReturnEntity(T t)
  34. {
  35. t = CheckId.InitId<T>(t);
  36. return base.Context.Insertable(t).ExecuteReturnEntity();
  37. }
  38. /// <summary>
  39. /// 该方法默认不更新CreatedUserId,CreatedTime
  40. /// </summary>
  41. /// <param name="entity"></param>
  42. /// <returns></returns>
  43. public bool UpdateEntity(T entity)
  44. {
  45. return base.Context.Updateable(entity).IgnoreColumns(new string[] { "CreatedUserId", "CreatedTime", "CreatedUserName" }).ExecuteCommand() > 0;
  46. }
  47. public bool UpdateModelColumns(Expression<Func<T, T>> Columns, Expression<Func<T, bool>> WhereExpression)
  48. {
  49. return base.Update(Columns, WhereExpression);
  50. }
  51. /// <summary>
  52. /// 更新指定列数据,并返回受影响行数
  53. /// </summary>
  54. /// <param name="Columns"></param>
  55. /// <param name="WhereExpression"></param>
  56. /// <returns></returns>
  57. public int UpdateModelColumnsCommands(Expression<Func<T, T>> Columns, Expression<Func<T, bool>> WhereExpression)
  58. {
  59. return Context.Updateable<T>().SetColumns(Columns).Where(WhereExpression).ExecuteCommand();
  60. }
  61. public T GetModelByExpression(Expression<Func<T, bool>> WhereExpression)
  62. {
  63. return base.GetSingle(WhereExpression);
  64. }
  65. public bool UpdateStatus(long id, int status, long userId)
  66. {
  67. return base.Context.Updateable<T>().SetColumns(it => new T()
  68. {
  69. //Status = status, UpdatedTime = DateTime.Now
  70. }).Where(it => it.Id == id).ExecuteCommand() > 0;
  71. }
  72. public List<hjSysConfig> GetTunList(TunnelRequest request)
  73. {
  74. var list = base.Context.Queryable<hjSysConfig>()
  75. .WhereIF(!string.IsNullOrEmpty(request.WareHouse), p => p.Default2 == request.WareHouse)
  76. .WhereIF(!string.IsNullOrEmpty(request.Tunnel), p => p.Default1 == request.Tunnel)
  77. .WhereIF(!string.IsNullOrEmpty(request.type), p => p.Default2 == request.type)
  78. .ToList();
  79. return list;
  80. }
  81. public bool UpdateTunStatu(long id, string statu, long userId)
  82. {
  83. return base.Context.Updateable<hjSysConfig>().SetColumns(it => new hjSysConfig()
  84. {
  85. SContent = statu,
  86. EditTime = DateTime.Now
  87. }).Where(it => it.Id == id).ExecuteCommand() > 0;
  88. }
  89. public (List<hjBaseWarehouse>, int) GetPageWareHouseList(QuertRequest request)
  90. {
  91. int count = 0;
  92. var list = base.Context.Queryable<hjBaseWarehouse>()
  93. .WhereIF(!string.IsNullOrEmpty(request.Code), p => p.Code.Contains(request.Code))
  94. .WhereIF(!string.IsNullOrEmpty(request.Name), p => p.Name.Contains(request.Name))
  95. .WhereIF(!string.IsNullOrEmpty(request.WareState), p => p.WareState == request.WareState)
  96. .WhereIF(!string.IsNullOrEmpty(request.FactoryNo), p => p.FactoryNo == request.FactoryNo)
  97. .WhereIF(!string.IsNullOrEmpty(request.WareType), p => p.WareType == request.WareType)
  98. .ToPageList(request.PageIndex, request.PageSize, ref count);
  99. return (list.ToList(), count);
  100. }
  101. public (List<hjBaseWareZone>, int) GetPageWareZoneList(WareZoneRequest request)
  102. {
  103. int count = 0;
  104. var list = base.Context.Queryable<hjBaseWareZone>()
  105. .WhereIF(!string.IsNullOrEmpty(request.Code), p => p.Code.Contains(request.Code))
  106. .WhereIF(!string.IsNullOrEmpty(request.Name), p => p.Name.Contains(request.Name))
  107. .WhereIF(request.WareId > Const.Zero, p => p.WareId == request.WareId)
  108. .WhereIF(!string.IsNullOrEmpty(request.WZoneState), p => p.WZoneState == request.WZoneState)
  109. .ToPageList(request.PageIndex, request.PageSize, ref count);
  110. return (list.ToList(), count);
  111. }
  112. public (List<hjBaseWareLocation>, int) GetPageWareLocationList(WareLocationRequest request)
  113. {
  114. int count = 0;
  115. var list = base.Context.Queryable<hjBaseWareLocation>()
  116. .WhereIF(!string.IsNullOrEmpty(request.Code), p => p.Code.Contains(request.Code))
  117. .WhereIF(!string.IsNullOrEmpty(request.Name), p => p.Name.Contains(request.Name))
  118. .WhereIF(request.LocationType > Const.MinOne, p => p.LocationType == request.LocationType)
  119. .WhereIF(request.Tunnel > Const.Zero, p => p.Tunnel == request.Tunnel)
  120. .WhereIF(!string.IsNullOrEmpty(request.WareCode), p => p.WareCode.Contains(request.WareCode))
  121. .ToPageList(request.PageIndex, request.PageSize, ref count);
  122. return (list.ToList(), count);
  123. }
  124. public (List<hjBaseUnits>, int) GetPageUnitList(BaseUnitRequest request)
  125. {
  126. int count = 0;
  127. var list = base.Context.Queryable<hjBaseUnits>()
  128. .WhereIF(!string.IsNullOrEmpty(request.Code), p => p.Code.Contains(request.Code))
  129. .WhereIF(!string.IsNullOrEmpty(request.Name), p => p.Name.Contains(request.Name))
  130. .WhereIF(!string.IsNullOrEmpty(request.PrimaryUnit), p => p.PrimaryUnit.Contains(request.PrimaryUnit))
  131. .WhereIF(!string.IsNullOrEmpty(request.DeputyUnit), p => p.DeputyUnit.Contains(request.DeputyUnit))
  132. .ToPageList(request.PageIndex, request.PageSize, ref count);
  133. return (list.ToList(), count);
  134. }
  135. public (List<hjBaseMater>, int) GetPageMaterList(BaseMaterRequest request)
  136. {
  137. int count = 0;
  138. var list = base.Context.Queryable<hjBaseMater>()
  139. .WhereIF(!string.IsNullOrEmpty(request.Code), p => p.Code.Contains(request.Code))
  140. .WhereIF(!string.IsNullOrEmpty(request.Name), p => p.Name.Contains(request.Name))
  141. .WhereIF(request.HoldDuration > Const.Zero, p => p.HoldDuration == request.HoldDuration)
  142. .WhereIF(request.PlatingWeight > Const.Zero, p => p.PlatingWeight == request.PlatingWeight)
  143. .WhereIF(!string.IsNullOrEmpty(request.Strength), p => p.Strength.Contains(request.Strength))
  144. .WhereIF(!string.IsNullOrEmpty(request.Plating), p => p.Plating.Contains(request.Plating))
  145. .ToPageList(request.PageIndex, request.PageSize, ref count);
  146. return (list.ToList(), count);
  147. }
  148. public (List<hjBillBarcode>, int) GetPageBarCodeList(BaseBarCodeRequest request)
  149. {
  150. int count = 0;
  151. var list = base.Context.Queryable<hjBillBarcode>()
  152. .WhereIF(!string.IsNullOrEmpty(request.MatCode), p => p.MatCode.Contains(request.MatCode))
  153. .WhereIF(!string.IsNullOrEmpty(request.HWBarCode), p => p.HWBarCode.Contains(request.HWBarCode))
  154. .WhereIF(!string.IsNullOrEmpty(request.RFIDBarCode), p => p.RFIDBarCode.Contains(request.RFIDBarCode))
  155. .ToPageList(request.PageIndex, request.PageSize, ref count);
  156. return (list.ToList(), count);
  157. }
  158. public (List<MaterReportResponse>, int, decimal) GetPageMaterInAndOutReportList(ReportRequest request)
  159. {
  160. int count = 0;
  161. var list = base.Context.Queryable<hjBillContainer, hjBillTaskHistory, hjBaseWarehouse>((container, taskHistory, house) => new object[]
  162. {
  163. JoinType.Inner, container.ContGrpId == taskHistory.ContGrpId,
  164. JoinType.Inner, taskHistory.WareCode == house.Code
  165. })
  166. .WhereIF(!string.IsNullOrEmpty(request.RFID), (container, taskHistory, house) => taskHistory.ContGrpBarCode.Contains(request.RFID))
  167. .WhereIF(!string.IsNullOrEmpty(request.HWSpec), (container, taskHistory, house) => container.HWSpec == request.HWSpec)
  168. .WhereIF(!string.IsNullOrEmpty(request.Grade), (container, taskHistory, house) => container.Grade == request.Grade)
  169. .WhereIF(!string.IsNullOrEmpty(request.ExecDocsNo), (container, taskHistory, house) => container.ExecDocsNo.Contains(request.ExecDocsNo))
  170. .WhereIF(!string.IsNullOrEmpty(request.PutLocNo), (container, taskHistory, house) => container.PutLocNo.Contains(request.PutLocNo))
  171. .WhereIF(request.TaskCode > Const.Zero, (container, taskHistory, house) => taskHistory.TaskCode == request.TaskCode)
  172. .WhereIF(!string.IsNullOrEmpty(request.Tunnel), (container, taskHistory, house) => taskHistory.Tunnel == request.Tunnel)
  173. .WhereIF(!string.IsNullOrEmpty(request.StartPoint), (container, taskHistory, house) => taskHistory.StartPoint == request.StartPoint)
  174. .WhereIF(!string.IsNullOrEmpty(request.EndPoint), (container, taskHistory, house) => taskHistory.EndPoint == request.EndPoint)
  175. .Select((container, taskHistory, house) => new MaterReportResponse()
  176. {
  177. RFID = container.ContGrpBarCode,
  178. ContGrpBarCode = container.ContGrpBarCode,
  179. ExecState = container.ExecState.ToString(),
  180. ExecDocsNo = container.ExecDocsNo,
  181. ExecDocsRowNo = container.ExecDocsRowNo,
  182. CustNo = container.CustCode,
  183. CustName = container.CustName,
  184. PutRow = container.PutRow,
  185. PutCol = container.PutCol,
  186. PutLayer = container.PutLayer,
  187. PutLocNo = container.PutLocNo,
  188. InvBarCode = container.InvBarCode,
  189. InvState = container.InvState,
  190. InDocsNo = container.InDocsNo,
  191. InDocsRowNo = container.InDocsRowNo,
  192. SuppCode = container.SuppCode,
  193. SuppName = container.SuppName,
  194. WareHouseName = house.Name,
  195. ProductTime = container.ProductTime,
  196. RFIDBarCode = container.RFIDBarCode,
  197. HWSpec = container.HWSpec,
  198. IsSurplus = container.IsSurplus,
  199. IsRework = container.IsRework,
  200. IsFast = container.IsFast,
  201. IsFail = container.IsFail,
  202. FailReason = container.FailReason,
  203. Grade = container.Grade,
  204. IsBack = container.IsBack,
  205. BackReason = container.Reason,
  206. ProductWbNo = container.ProductWbNo,
  207. ProductLineNo = container.ProductLineNo
  208. })
  209. .ToPageList(request.PageIndex, request.PageSize, ref count);
  210. decimal pro = list.Sum(p => p.TotalWtQty); //临时计算总重量
  211. //list = list.Skip((request.PageIndex - 1) * request.PageSize).Take(request.PageSize).ToList();
  212. return (list.ToList(), count, pro);
  213. }
  214. public (List<RealTimeInventoryReportResponse>, int, decimal) GetPageRealTimeInventoryReportList(ReportRequest request)
  215. {
  216. int count = 0;
  217. var list = base.Context.Queryable<hjBillContainer, hjBaseWarehouse, hjBaseWareLocation, hjBaseMater>((container, house, location, mater) => new object[]
  218. {
  219. JoinType.Left, container.WarehouseId == house.Id,
  220. JoinType.Left, house.Code == location.WareCode,
  221. JoinType.Left, container.MatId == mater.Id
  222. })
  223. .WhereIF(!string.IsNullOrEmpty(request.ContGrpBarCode), (container, house, location, mater) => container.ContGrpBarCode.Contains(request.ContGrpBarCode))
  224. .WhereIF(!string.IsNullOrEmpty(request.InvBarCode), (container, house, location, mater) => container.InvBarCode.Contains(request.InvBarCode))
  225. .WhereIF(!string.IsNullOrEmpty(request.Location), (container, house, location, mater) => location.Code.Contains(request.Location))
  226. .WhereIF(!string.IsNullOrEmpty(request.MatCode), (container, house, location, mater) => mater.Code.Contains(request.MatCode))
  227. .OrderBy((container, house, location, mater) => container.OneInTime, OrderByType.Asc)
  228. .Select((container, house, location, mater) => new RealTimeInventoryReportResponse()
  229. {
  230. ContGrpBarCode = container.ContGrpBarCode,
  231. WareHouseName = house.Name,
  232. InvBarCode = container.InvBarCode,
  233. HWSpec = container.HWSpec,
  234. MatCode = mater.Code,
  235. Grade = container.Grade,
  236. SilkType = container.SilkType,
  237. TotalWtQty = container.TotalWtQty,
  238. NetWQty = container.NetWQty,
  239. TareWQty = container.TareWQty,
  240. LengthQty = container.LengthQty,
  241. InvState = container.InvState,
  242. IsSurplus = container.IsSurplus,
  243. IsRework = container.IsRework,
  244. IsFast = container.IsFast,
  245. IsBack = container.IsBack,
  246. BackReason = container.Reason,
  247. IsFail = container.IsFail,
  248. FailReason = container.FailReason,
  249. ProductTime = container.ProductTime,
  250. OneInTime = container.OneInTime,
  251. InDocsNo = container.InDocsNo,
  252. InDocsRowNo = container.InDocsRowNo,
  253. PutRow = container.PutRow,
  254. PutCol = container.PutCol,
  255. PutLayer = container.PutLayer,
  256. PutLocNo = container.PutLocNo,
  257. SuppCode = container.SuppCode,
  258. SuppName = container.SuppName,
  259. CustNo = container.CustCode,
  260. CustName = container.CustName,
  261. RFIDBarCode = container.RFIDBarCode,
  262. Tunnel = location.Tunnel.ToString(),
  263. Location = location.Code,
  264. })
  265. .ToPageList(request.PageIndex, request.PageSize, ref count);
  266. decimal pro = list.Sum(p => p.TotalWtQty); //临时计算总重量
  267. //list = list.Skip((request.PageIndex - 1) * request.PageSize).Take(request.PageSize).ToList();
  268. return (list.ToList(), count, pro);
  269. }
  270. public (List<InventoryAgingReportResponse>, int) GetPageInventoryAgingReportList(ReportRequest request)
  271. {
  272. int count = 0;
  273. var list = base.Context.Queryable<hjBillContainer, hjBaseWarehouse, hjBaseWareLocation, hjBaseMater>((container, house, location, mater) => new object[]
  274. {
  275. JoinType.Left, container.WarehouseId == house.Id,
  276. JoinType.Left, house.Code == location.WareCode,
  277. JoinType.Left, container.MatId == mater.Id
  278. })
  279. .WhereIF(!string.IsNullOrEmpty(request.RFID), (container, house, location, mater) => container.RFIDBarCode.Contains(request.RFID))
  280. .WhereIF(!string.IsNullOrEmpty(request.HWSpec), (container, house, location, mater) => container.HWSpec == request.HWSpec)
  281. .WhereIF(!string.IsNullOrEmpty(request.Tunnel), (container, house, location, mater) => location.Tunnel == int.Parse(request.Tunnel))
  282. .WhereIF(!string.IsNullOrEmpty(request.MatCode), (container, house, location, mater) => mater.Code.Contains(request.MatCode))
  283. .WhereIF(!string.IsNullOrEmpty(request.Grade), (container, house, location, mater) => container.Grade == request.Grade)
  284. .WhereIF(request.HoldDuration != null && request.HoldDuration > 0, (container, house, location, mater) => mater.HoldDuration == request.HoldDuration)
  285. .GroupBy((container, house, location, mater) => new
  286. {
  287. RFIDBarCode = container.RFIDBarCode,
  288. HWSpec = container.HWSpec,
  289. MatCode = mater.Code,
  290. MatName = mater.Name,
  291. Grade = container.Grade,
  292. ProductTime = container.ProductTime,
  293. HoldDuration = mater.HoldDuration,
  294. Tunnel = location.Tunnel.ToString()
  295. })
  296. .Select((container, house, location, mater) => new InventoryAgingReportResponse()
  297. {
  298. RFIDBarCode = container.RFIDBarCode,
  299. HWSpec = container.HWSpec,
  300. MatCode = mater.Code,
  301. MatName = mater.Name,
  302. Grade = container.Grade,
  303. ProductTime = container.ProductTime,
  304. HoldDuration = mater.HoldDuration,
  305. Tunnel = location.Tunnel.ToString()
  306. //Remaindays = (decimal)(container.ProductTime.AddDays((double)mater.HoldDuration) - DateTime.Now).TotalHours
  307. //Duedate = container.ProductTime.AddDays((double)mater.HoldDuration)
  308. })
  309. .ToPageList(request.PageIndex, request.PageSize, ref count);
  310. //list = list.Skip((request.PageIndex - 1) * request.PageSize).Take(request.PageSize).ToList();
  311. return (list.ToList(), count);
  312. }
  313. public (List<TaskRsponse>, int) GetPageTaskList(TaskRequest request)
  314. {
  315. int count = 0;
  316. var list = base.Context.Queryable<hjBillTask, hjBaseWarehouse>((task, house) => new object[]
  317. {
  318. JoinType.Inner, task.WareCode == house.Code
  319. })
  320. .WhereIF(request.TaskCode > Const.Zero, (task, house) => task.TaskCode == request.TaskCode)
  321. .WhereIF(request.TaskType > Const.Zero, (task, house) => task.TaskType == request.TaskType)
  322. .WhereIF(request.TaskState > Const.Zero, (task, house) => task.TaskState == request.TaskState)
  323. .WhereIF(request.Tunnel > Const.Zero, (task, house) => task.Tunnel == request.Tunnel)
  324. .WhereIF(!string.IsNullOrEmpty(request.BusType), (task, house) => task.BusType.Contains(request.BusType))
  325. .WhereIF(!string.IsNullOrEmpty(request.WareCode), (task, house) => task.WareCode.Contains(request.WareCode))
  326. .WhereIF(!string.IsNullOrEmpty(request.ContGrpBarCode), (task, house) => task.ContGrpBarCode.Contains(request.ContGrpBarCode))
  327. .WhereIF(!string.IsNullOrEmpty(request.EndPoint), (task, house) => task.EndPoint.Contains(request.EndPoint))
  328. .WhereIF(!string.IsNullOrEmpty(request.StartPoint), (task, house) => task.StartPoint.Contains(request.StartPoint))
  329. .WhereIF(!string.IsNullOrEmpty(request.DocCode), (task, house) => task.DocCode.Contains(request.DocCode))
  330. .Select((task, house) => new TaskRsponse()
  331. {
  332. Id = task.Id,
  333. TaskCode = task.TaskCode,
  334. TaskType = task.TaskType,
  335. TaskState = task.TaskState,
  336. Tunnel = task.Tunnel,
  337. ContGrpBarCode = task.ContGrpBarCode,
  338. EndPoint = task.EndPoint,
  339. StartPoint = task.StartPoint,
  340. BusType = task.BusType,
  341. WareCodeName = house.Name,
  342. Priority = task.Priority,
  343. EquNo = task.EquNo,
  344. Srm = task.SrmNo,
  345. CurPoint = task.CurPoint,
  346. NextPoint = task.NextPoint,
  347. Qty = task.Qty,
  348. DocCode = task.DocCode,
  349. IsManual = task.IsManual,
  350. IsEmpty = task.IsEmpty,
  351. AddWho = task.AddWho,
  352. EditWho = task.EditWho,
  353. AddTime = task.AddTime,
  354. EditTime = task.EditTime
  355. })
  356. .ToPageList(request.PageIndex, request.PageSize, ref count);
  357. //list = list.Skip((request.PageIndex - 1) * request.PageSize).Take(request.PageSize).ToList();
  358. return (list.ToList(), count);
  359. }
  360. public (List<TaskRsponse>, int) GetPageTaskHistoryList(TaskRequest request)
  361. {
  362. int count = 0;
  363. var list = base.Context.Queryable<hjBillTaskHistory, hjBaseWarehouse>((taskHistory, house) => new object[]
  364. {
  365. JoinType.Inner, taskHistory.WareCode == house.Code
  366. })
  367. .WhereIF(request.TaskCode > Const.Zero, (taskHistory, house) => taskHistory.TaskCode == request.TaskCode)
  368. .WhereIF(request.TaskType > Const.Zero, (taskHistory, house) => taskHistory.TaskType == request.TaskType)
  369. .WhereIF(request.TaskState > Const.Zero, (taskHistory, house) => taskHistory.TaskState == request.TaskState)
  370. .WhereIF(request.Tunnel > Const.Zero, (taskHistory, house) => taskHistory.Tunnel == request.Tunnel.ToString())
  371. .WhereIF(!string.IsNullOrEmpty(request.BusType), (taskHistory, house) => taskHistory.BusType.Contains(request.BusType))
  372. .WhereIF(!string.IsNullOrEmpty(request.WareCode), (taskHistory, house) => taskHistory.WareCode.Contains(request.WareCode))
  373. .WhereIF(!string.IsNullOrEmpty(request.ContGrpBarCode), (taskHistory, house) => taskHistory.ContGrpBarCode.Contains(request.ContGrpBarCode))
  374. .WhereIF(!string.IsNullOrEmpty(request.EndPoint), (taskHistory, house) => taskHistory.EndPoint.Contains(request.EndPoint))
  375. .WhereIF(!string.IsNullOrEmpty(request.StartPoint), (taskHistory, house) => taskHistory.StartPoint.Contains(request.StartPoint))
  376. .WhereIF(!string.IsNullOrEmpty(request.DocCode), (taskHistory, house) => taskHistory.DocCode.Contains(request.DocCode))
  377. .Select((taskHistory, house) => new TaskRsponse()
  378. {
  379. Id = taskHistory.Id,
  380. TaskCode = taskHistory.TaskCode,
  381. TaskType = taskHistory.TaskType,
  382. TaskState = taskHistory.TaskState,
  383. Tunnel = int.Parse(taskHistory.Tunnel),
  384. ContGrpBarCode = taskHistory.ContGrpBarCode,
  385. EndPoint = taskHistory.EndPoint,
  386. StartPoint = taskHistory.StartPoint,
  387. BusType = taskHistory.BusType,
  388. WareCodeName = house.Name,
  389. Priority = taskHistory.Priority,
  390. EquNo = taskHistory.EquNo,
  391. Srm = taskHistory.SrmNo,
  392. CurPoint = taskHistory.CurPoint,
  393. NextPoint = taskHistory.NextPoint,
  394. Qty = taskHistory.Qty,
  395. DocCode = taskHistory.DocCode,
  396. IsManual = int.Parse(taskHistory.IsManual),
  397. IsEmpty = int.Parse(taskHistory.IsEmpty),
  398. AddWho = taskHistory.AddWho,
  399. EditWho = taskHistory.EditWho,
  400. AddTime = taskHistory.AddTime,
  401. EditTime = taskHistory.EditTime
  402. })
  403. .ToPageList(request.PageIndex, request.PageSize, ref count);
  404. //list = list.Skip((request.PageIndex - 1) * request.PageSize).Take(request.PageSize).ToList();
  405. return (list.ToList(), count);
  406. }
  407. public (List<RealTimeInventoryReportResponse>, int, decimal) GetPageStockdetailList(StockRequest request)
  408. {
  409. int count = 0;
  410. var list = base.Context.Queryable<hjBillContainer, hjBaseWarehouse, hjBaseWareLocation, hjBaseMater>((stock, house, location, mater) => new object[]
  411. {
  412. JoinType.Left, stock.WarehouseId == house.Id,
  413. JoinType.Left, house.Id == location.WareId,
  414. JoinType.Left, stock.MatId == mater.Id
  415. })
  416. .Where((stock, house, location, mater) => house.WareState == Const.One.ToString()
  417. && location.LocationState == LocationState.LocationState_Full.GetHashCode() && location.LocationType == LocationType.LocationType_StorageLocation.GetHashCode()
  418. && stock.ExecState == InvState.InvEcecState_In.GetHashCode() && stock.ContGrpId == location.ContGrpID)
  419. .WhereIF(!string.IsNullOrEmpty(request.Grade), (stock, house, location, mater) => stock.Grade == request.Grade)
  420. .WhereIF(!string.IsNullOrEmpty(request.Location), (stock, house, location, mater) => location.Code.Contains(request.Location))
  421. .WhereIF(!string.IsNullOrEmpty(request.MatCode), (stock, house, location, mater) => mater.Code.Contains(request.MatCode))
  422. .WhereIF(!string.IsNullOrEmpty(request.ContGrpBarCode), (stock, house, location, mater) => stock.ContGrpBarCode.Contains(request.ContGrpBarCode))
  423. .WhereIF(!string.IsNullOrEmpty(request.HWSpec), (stock, house, location, mater) => stock.HWSpec == request.HWSpec)
  424. .WhereIF(request.HoldDuration > 0, (stock, house, location, mater) => mater.HoldDuration == request.HoldDuration)
  425. .Select((stock, house, location, mater) => new RealTimeInventoryReportResponse()
  426. {
  427. ContGrpBarCode = stock.ContGrpBarCode,
  428. ExecState = stock.ExecState.ToString(),
  429. ExecDocsNo = stock.ExecDocsNo,
  430. ExecDocsRowNo = stock.ExecDocsRowNo,
  431. ExecDocsTypeCode = stock.ExecDocsTypeCode,
  432. MatCode = mater.Code,
  433. MatName = mater.Name,
  434. Location = location.Code,
  435. Tunnel = location.Tunnel.ToString(),
  436. CustNo = stock.CustCode,
  437. CustName = stock.CustName,
  438. WareHouseName = house.Name,
  439. InvBarCode = stock.InvBarCode,
  440. InvState = stock.InvState,
  441. InDocsNo = stock.InDocsNo,
  442. InDocsRowNo = stock.InDocsRowNo,
  443. SuppCode = stock.SuppCode,
  444. SuppName = stock.SuppName,
  445. RowStop = location.RowStop,
  446. TotalWtQty = stock.TotalWtQty,
  447. NetWQty = stock.NetWQty,
  448. TareWQty = stock.TareWQty,
  449. LengthQty = stock.LengthQty,
  450. BatchNo = stock.Batch,
  451. ProductTime = stock.ProductTime,
  452. OneInTime = stock.OneInTime,
  453. RFIDBarCode = stock.RFIDBarCode,
  454. HWSpec = stock.HWSpec,
  455. IsSurplus = stock.IsSurplus,
  456. IsRework = stock.IsRework,
  457. IsFast = stock.IsFast,
  458. IsFail = stock.IsFail,
  459. FailReason = stock.FailReason,
  460. Grade = stock.Grade,
  461. IsBack = stock.IsBack,
  462. BackReason = stock.Reason,
  463. ProductWbNo = stock.ProductWbNo,
  464. ProductLineNo = stock.ProductLineNo,
  465. })
  466. .ToPageList(request.PageIndex, request.PageSize, ref count);
  467. decimal total = list.Sum(p => p.TotalWtQty);
  468. //list = list.Skip((request.PageIndex - 1) * request.PageSize).Take(request.PageSize).ToList();
  469. return (list.ToList(), count, total);
  470. }
  471. }
  472. }