| | |
| | | public class MesInvItemStocksManager : Repository<MesInvItemStocks> |
| | | { |
| | | /// <summary> |
| | | /// æ¥è¯¢å¯ä»¥éè´§çç©æ |
| | | /// æ¥è¯¢å¯ä»¥éè´§çç©æ(带å页åæç´¢) |
| | | /// </summary> |
| | | /// <param name="searchDto">æç´¢è¯·æ±åæ°</param> |
| | | /// <returns>åé¡µç»æ</returns> |
| | | public PagedResult<ReturnableStockDto> GetReturnableStocks(ReturnableStockSearchDto searchDto) |
| | | { |
| | | // åæ°æ ¡éª |
| | | if (searchDto.PageIndex < 1) |
| | | { |
| | | throw new Exception("页ç å¿
须大äº0"); |
| | | } |
| | | |
| | | if (!new[] { 10, 20, 50 }.Contains(searchDto.PageSize)) |
| | | { |
| | | throw new Exception("æ¯é¡µæ¡æ°å¿
须为10ã20æ50"); |
| | | } |
| | | |
| | | // 1. æ¥è¯¢XB_RACKING_TASK_SYXT_LOG䏿æçæ¡ç å¹¶å»é |
| | | var distinctBarcodes = Db.Queryable<XbRackingTaskSyxtLog>() |
| | | .Where(x => !string.IsNullOrEmpty(x.ItemBarcode)) |
| | | .Select(x => x.ItemBarcode) |
| | | .Distinct() |
| | | .ToList(); |
| | | |
| | | if (distinctBarcodes == null || !distinctBarcodes.Any()) |
| | | { |
| | | return new PagedResult<ReturnableStockDto> |
| | | { |
| | | TbBillList = new List<ReturnableStockDto>(), |
| | | Pagination = new PaginationInfo |
| | | { |
| | | CurrentPage = searchDto.PageIndex, |
| | | PageSize = searchDto.PageSize, |
| | | TotalRecords = 0, |
| | | TotalPages = 0 |
| | | } |
| | | }; |
| | | } |
| | | |
| | | // 2. æå»ºæ¥è¯¢æ¡ä»¶ |
| | | var query = Db.Queryable<MesInvItemStocks>() |
| | | .LeftJoin<MesItems>((stock, item) => stock.ItemId == item.Id) |
| | | .LeftJoin<MesDepots>((stock, item, depot) => stock.DepotsCode == depot.DepotCode) |
| | | .LeftJoin<Organize>((stock, item, depot, org) => item.UseOrg == org.Id.ToString()) |
| | | .LeftJoin<MesUnit>((stock, item, depot, org, unit) => item.ItemUnit == unit.Id.ToString()) |
| | | .Where((stock, item, depot, org, unit) => |
| | | distinctBarcodes.Contains(stock.ItemBarcode) && |
| | | stock.Quantity > 0); |
| | | |
| | | // 3. åºç¨æç´¢æ¡ä»¶ |
| | | var conditions = searchDto.Conditions; |
| | | if (conditions != null) |
| | | { |
| | | // 精确å¹é
æ¡ä»¶ |
| | | if (!string.IsNullOrEmpty(conditions.IqcStatus)) |
| | | { |
| | | query = query.Where((stock, item, depot, org, unit) => stock.IqcStatus == conditions.IqcStatus); |
| | | } |
| | | |
| | | if (conditions.Quantity.HasValue) |
| | | { |
| | | query = query.Where((stock, item, depot, org, unit) => stock.Quantity == conditions.Quantity.Value); |
| | | } |
| | | |
| | | // 模ç³å¹é
æ¡ä»¶ |
| | | if (!string.IsNullOrEmpty(conditions.StackCode)) |
| | | { |
| | | query = query.Where((stock, item, depot, org, unit) => |
| | | stock.StackCode != null && stock.StackCode.Contains(conditions.StackCode)); |
| | | } |
| | | |
| | | if (!string.IsNullOrEmpty(conditions.DepotName)) |
| | | { |
| | | query = query.Where((stock, item, depot, org, unit) => |
| | | depot.DepotName != null && depot.DepotName.Contains(conditions.DepotName)); |
| | | } |
| | | |
| | | if (!string.IsNullOrEmpty(conditions.DepotSectionsCode)) |
| | | { |
| | | query = query.Where((stock, item, depot, org, unit) => |
| | | stock.DepotSectionsCode != null && stock.DepotSectionsCode.Contains(conditions.DepotSectionsCode)); |
| | | } |
| | | |
| | | if (!string.IsNullOrEmpty(conditions.ItemNo)) |
| | | { |
| | | query = query.Where((stock, item, depot, org, unit) => |
| | | item.ItemNo != null && item.ItemNo.Contains(conditions.ItemNo)); |
| | | } |
| | | |
| | | if (!string.IsNullOrEmpty(conditions.ItemName)) |
| | | { |
| | | query = query.Where((stock, item, depot, org, unit) => |
| | | item.ItemName != null && item.ItemName.Contains(conditions.ItemName)); |
| | | } |
| | | |
| | | if (!string.IsNullOrEmpty(conditions.ItemModel)) |
| | | { |
| | | query = query.Where((stock, item, depot, org, unit) => |
| | | item.ItemModel != null && item.ItemModel.Contains(conditions.ItemModel)); |
| | | } |
| | | |
| | | if (!string.IsNullOrEmpty(conditions.ItemUnitName)) |
| | | { |
| | | query = query.Where((stock, item, depot, org, unit) => |
| | | unit.Fname != null && unit.Fname.Contains(conditions.ItemUnitName)); |
| | | } |
| | | |
| | | if (!string.IsNullOrEmpty(conditions.OrgCode)) |
| | | { |
| | | query = query.Where((stock, item, depot, org, unit) => |
| | | org.Fnumber != null && org.Fnumber.Contains(conditions.OrgCode)); |
| | | } |
| | | |
| | | if (!string.IsNullOrEmpty(conditions.OrgName)) |
| | | { |
| | | query = query.Where((stock, item, depot, org, unit) => |
| | | org.Fname != null && org.Fname.Contains(conditions.OrgName)); |
| | | } |
| | | |
| | | if (!string.IsNullOrEmpty(conditions.ItemBarcode)) |
| | | { |
| | | query = query.Where((stock, item, depot, org, unit) => |
| | | stock.ItemBarcode != null && stock.ItemBarcode.Contains(conditions.ItemBarcode)); |
| | | } |
| | | |
| | | // æ¥æèå´æ¡ä»¶ |
| | | if (!string.IsNullOrEmpty(conditions.IndepDateStart)) |
| | | { |
| | | if (DateTime.TryParse(conditions.IndepDateStart, out var startDate)) |
| | | { |
| | | query = query.Where((stock, item, depot, org, unit) => stock.IndepDate >= startDate); |
| | | } |
| | | } |
| | | |
| | | if (!string.IsNullOrEmpty(conditions.IndepDateEnd)) |
| | | { |
| | | if (DateTime.TryParse(conditions.IndepDateEnd, out var endDate)) |
| | | { |
| | | query = query.Where((stock, item, depot, org, unit) => stock.IndepDate <= endDate); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 4. æ¥è¯¢æ»è®°å½æ° |
| | | var totalRecords = query.Count(); |
| | | |
| | | // 5. 计ç®å页忰 |
| | | var totalPages = (int)Math.Ceiling((double)totalRecords / searchDto.PageSize); |
| | | var skip = (searchDto.PageIndex - 1) * searchDto.PageSize; |
| | | |
| | | // 6. æ¥è¯¢å½åé¡µæ°æ®(å
æ¥åºä¸é´æ°æ®) |
| | | var queryResult = query |
| | | .OrderByDescending((stock, item, depot, org, unit) => stock.IndepDate) |
| | | .Select((stock, item, depot, org, unit) => new |
| | | { |
| | | stock.IqcStatus, |
| | | stock.StackCode, |
| | | DepotCode = stock.DepotsCode, |
| | | depot.DepotName, |
| | | stock.DepotSectionsCode, |
| | | item.ItemNo, |
| | | item.ItemName, |
| | | item.ItemModel, |
| | | stock.Quantity, |
| | | item.ItemUnit, |
| | | ItemUnitName = unit.Fname, |
| | | stock.IndepDate, |
| | | OrgCode = org.Fnumber, |
| | | OrgName = org.Fname, |
| | | stock.ItemBarcode |
| | | }) |
| | | .Skip(skip) |
| | | .Take(searchDto.PageSize) |
| | | .ToList(); |
| | | |
| | | // 7. å¨å
åä¸è½¬æ¢ä¸ºDTO |
| | | var dataList = queryResult.Select(x => new ReturnableStockDto |
| | | { |
| | | IqcStatus = x.IqcStatus == "å·²æ£" ? "1" : "0", |
| | | ItemType = x.DepotName == "åææä»" ? "0" : "1", |
| | | StackCode = x.StackCode, |
| | | DepotCode = x.DepotCode, |
| | | DepotName = x.DepotName, |
| | | DepotSectionsCode = x.DepotSectionsCode, |
| | | ItemNo = x.ItemNo, |
| | | ItemName = x.ItemName, |
| | | ItemModel = x.ItemModel, |
| | | Quantity = x.Quantity, |
| | | ItemUnit = x.ItemUnit, |
| | | ItemUnitName = x.ItemUnitName, |
| | | IndepDate = x.IndepDate, |
| | | OrgCode = x.OrgCode, |
| | | OrgName = x.OrgName, |
| | | ItemBarcode = x.ItemBarcode |
| | | }).ToList(); |
| | | |
| | | // 8. åºç¨ItemTypeçé(å¨å
åä¸è¿æ»¤) |
| | | if (conditions?.ItemType != null) |
| | | { |
| | | dataList = dataList.Where(x => x.ItemType == conditions.ItemType).ToList(); |
| | | // éæ°è®¡ç®åé¡µä¿¡æ¯ |
| | | totalRecords = dataList.Count; |
| | | totalPages = (int)Math.Ceiling((double)totalRecords / searchDto.PageSize); |
| | | dataList = dataList.Skip(skip).Take(searchDto.PageSize).ToList(); |
| | | } |
| | | |
| | | // 9. è¿ååé¡µç»æ |
| | | return new PagedResult<ReturnableStockDto> |
| | | { |
| | | TbBillList = dataList, |
| | | Pagination = new PaginationInfo |
| | | { |
| | | CurrentPage = searchDto.PageIndex, |
| | | PageSize = searchDto.PageSize, |
| | | TotalRecords = totalRecords, |
| | | TotalPages = totalPages |
| | | } |
| | | }; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ¥è¯¢å¯ä»¥éè´§çç©æ(æ§çæ¬,ä¿çå
¼å®¹) |
| | | /// </summary> |
| | | /// <returns>å¯éè´§ç©æåºåå表</returns> |
| | | public List<ReturnableStockDto> GetReturnableStocks() |
| | |
| | | stock.Quantity > 0) |
| | | .Select((stock, item, depot, org, unit) => new |
| | | { |
| | | IqcStatus = stock.IqcStatus, |
| | | StackCode = stock.StackCode, |
| | | stock.IqcStatus, |
| | | stock.StackCode, |
| | | DepotCode = stock.DepotsCode, |
| | | DepotName = depot.DepotName, |
| | | DepotSectionsCode = stock.DepotSectionsCode, |
| | | ItemNo = item.ItemNo, |
| | | ItemName = item.ItemName, |
| | | ItemModel = item.ItemModel, |
| | | Quantity = stock.Quantity, |
| | | ItemUnit = item.ItemUnit, |
| | | depot.DepotName, |
| | | stock.DepotSectionsCode, |
| | | item.ItemNo, |
| | | item.ItemName, |
| | | item.ItemModel, |
| | | stock.Quantity, |
| | | item.ItemUnit, |
| | | ItemUnitName = unit.Fname, |
| | | IndepDate = stock.IndepDate, |
| | | stock.IndepDate, |
| | | OrgCode = org.Fnumber, |
| | | OrgName = org.Fname, |
| | | ItemBarcode = stock.ItemBarcode |
| | | stock.ItemBarcode |
| | | }) |
| | | .ToList(); |
| | | |