| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328 |
- using System;
- using System.Collections.Generic;
- using System.Data.Entity;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- using Abp.Application.Services;
- using Abp.Application.Services.Dto;
- using Abp.Authorization;
- using Abp.Configuration;
- using Abp.Domain.Repositories;
- using Abp.Extensions;
- using IwbZero.AppServiceBase;
- using IwbZero.Auditing;
- using IwbZero.Setting;
- using ShwasherSys.Authorization.Permissions;
- using ShwasherSys.Common;
- using ShwasherSys.Common.Dto;
- using ShwasherSys.Lambda;
- using ShwasherSys.ProductStoreInfo;
- using ShwasherSys.SemiProductStoreInfo;
- using ShwasherSys.StoreQuery.Dto;
- namespace ShwasherSys.StoreQuery
- {
- [AbpAuthorize]
- public class StoreStatisticsApplicationService: ShwasherAsyncCrudAppService<ViewEnterOutProductStore, ViewEnterOutProductStoreDto, string, PagedRequestDto, ViewEnterOutProductStoreDto, ViewEnterOutProductStoreDto>, IStoreStatisticsApplicationService
- {
- public IRepository<ViewCurrentStoreTotal,string> ViewCurrentStoreTotalRepository { get; }
- public IRepository<ViewEnterOutLogCus, string> ViewEnterOutLogCusRepository { get; }
- public IRepository<ViewEnterOutSemiProductStore, string> ViewEnterOutSemiProductStoreRepository { get; }
- public IRepository<ViewCurrentSemiStoreTotal, string> ViewCurrentSemiStoreTotalRepository { get; }
- public StoreStatisticsApplicationService(IRepository<ViewEnterOutProductStore, string> repository,IRepository<ViewCurrentStoreTotal, string> viewCurrentStoreTotalRepository,IIwbSettingManager settingManager, IRepository<ViewEnterOutLogCus, string> viewEnterOutLogCusRepository, IRepository<ViewEnterOutSemiProductStore, string> viewEnterOutSemiProductStoreRepository, IRepository<ViewCurrentSemiStoreTotal, string> viewCurrentSemiStoreTotalRepository):base(repository)
- {
- ViewCurrentStoreTotalRepository = viewCurrentStoreTotalRepository;
- ViewEnterOutLogCusRepository = viewEnterOutLogCusRepository;
- ViewEnterOutSemiProductStoreRepository = viewEnterOutSemiProductStoreRepository;
- ViewCurrentSemiStoreTotalRepository = viewCurrentSemiStoreTotalRepository;
- SettingManager = settingManager;
- }
- [AbpAuthorize(PermissionNames.PagesFinshedStoreInfoEnterOutStoreHouseQueryMg),AuditLog("库存出入库记录")]
- public async Task<PagedResultDto<ViewEnterOutLogCus>> QueryEnterOutRecord(PagedRequestDto input)
- {
- var query = ViewEnterOutLogCusRepository.GetAll();
- if (input.SearchList != null && input.SearchList.Count > 0)
- {
- List<LambdaObject> objList = new List<LambdaObject>();
- foreach (var o in input.SearchList)
- {
- if (o.KeyWords.IsNullOrEmpty())
- continue;
- object keyWords = o.KeyWords;
- //检查查询条件中带有规格且多个分割条件的
- ProductModelSearch.CheckModelGreaterOneFilter(o, ref keyWords);
- objList.Add(new LambdaObject
- {
- FieldType = (LambdaFieldType)o.FieldType,
- FieldName = o.KeyField,
- FieldValue = keyWords,
- ExpType = (LambdaExpType)o.ExpType
- });
- }
- var exp = objList.GetExp<ViewEnterOutLogCus>();
- query = exp!=null? query.Where(exp): query;
- }
- var totalCount = await AsyncQueryableExecuter.CountAsync(query);
- query = query.OrderByDescending(i => i.ProductNo).ThenByDescending(i=>i.DateTiem);
- string pattern = ProductModelSearch.GetModelGreaterOneReg(input.SearchList);
- List<ViewEnterOutLogCus> entities;
- //检查查询条件中带有规格且多个分割条件的
- if (!pattern.IsNullOrEmpty())
- {
- var es = query.ToList();
- es = es.Where(f => f.Model != null && Regex.IsMatch(f.Model, pattern)).ToList();
- totalCount = es.Count;
- entities = es.Skip(input.SkipCount).Take(input.MaxResultCount).ToList();
- }
- else
- {
- query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
- entities = await AsyncQueryableExecuter.ToListAsync(query);
- }
- //query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
- //var entities = await AsyncQueryableExecuter.ToListAsync(query);
- var result = new PagedResultDto<ViewEnterOutLogCus>(totalCount, entities);
- return result;
- }
- [AbpAuthorize(PermissionNames.PagesFinshedStoreInfoEnterOutStoreHouseQueryMg), AuditLog("库存出入库记录")]
- public async Task<List<ViewEnterOutProductStore>> QueryEnterOutRecordTmp(List<MultiSearchDtoExt> input)
- {
- var query = Repository.GetAll();
- if (input != null && input.Count > 0)
- {
- List<LambdaObject> objList = new List<LambdaObject>();
- foreach (var o in input)
- {
- if (o.KeyWords.IsNullOrEmpty())
- continue;
- object keyWords = o.KeyWords;
- objList.Add(new LambdaObject
- {
- FieldType = (LambdaFieldType)o.FieldType,
- FieldName = o.KeyField,
- FieldValue = keyWords,
- ExpType = (LambdaExpType)o.ExpType
- });
- }
- var exp = objList.GetExp<ViewEnterOutProductStore>();
- query = query.Where(exp);
- }
-
- query = query.OrderByDescending(i => i.ProductNo).ThenByDescending(i => i.DateTiem);
-
- var entities = await AsyncQueryableExecuter.ToListAsync(query);
-
- return entities;
- }
- public async Task<List<ViewEnterOutProductStore>> QueryProductEnterOutRecord(string productNo)
- {
- return (await Repository.GetAllListAsync(i => i.ProductNo == productNo)).OrderByDescending(i=>i.DateTiem).ToList();
- }
- #region 进出库记录导出
- [AbpAuthorize(PermissionNames.PagesFinshedStoreInfoEnterOutStoreHouseQueryMgExportExcel), AuditLog("库存出入库记录导出excel")]
- public async Task<string> ExportExcel(List<MultiSearchDtoExt> input)
- {
- var query = ViewEnterOutLogCusRepository.GetAll();
- if (input != null && input.Count > 0)
- {
- List<LambdaObject> objList = new List<LambdaObject>();
- foreach (var o in input)
- {
- if (o.KeyWords.IsNullOrEmpty())
- continue;
- object keyWords = o.KeyWords;
- //检查查询条件中带有规格且多个分割条件的
- ProductModelSearch.CheckModelGreaterOneFilter(o, ref keyWords);
- objList.Add(new LambdaObject
- {
- FieldType = (LambdaFieldType)o.FieldType,
- FieldName = o.KeyField,
- FieldValue = keyWords,
- ExpType = (LambdaExpType)o.ExpType
- });
- }
- var exp = objList.GetExp<ViewEnterOutLogCus>();
- query = query.Where(exp);
- }
- query = query.OrderByDescending(i => i.ProductNo).ThenByDescending(i => i.DateTiem);
-
- var r = query.Select(i => new
- {
- i.ProductNo,
- i.ProductName,
- i.Model,
- i.SurfaceColor,
- i.Material,
- i.Rigidity,
- i.Quantity,
- EnterOutFlag = i.EnterOutFlag==1?"入库":"出库",
- i.DateTiem,
- i.UserIDLastMod,
- i.CustomerId,
- i.CustomerName,
- }).ToList();
- string pattern = ProductModelSearch.GetModelGreaterOneReg(input);
- //检查查询条件中带有规格且多个分割条件的
- if (!pattern.IsNullOrEmpty())
- {
- r = r.Where(f => f.Model != null && Regex.IsMatch(f.Model, pattern)).ToList();
- }
- string downloadUrl = await SettingManager.GetSettingValueAsync("SYSTEMDOWNLOADPATH");
- string lcFilePath = System.Web.HttpRuntime.AppDomainAppPath + "\\" +
- downloadUrl;
- List<ToExcelObj> columnsList = new List<ToExcelObj>()
- {
- new ToExcelObj(){MapColumn = "ProductNo",ShowColumn = "产品编号"},
- new ToExcelObj(){MapColumn = "ProductName",ShowColumn = "产品名称"},
- new ToExcelObj(){MapColumn = "Model",ShowColumn = "规格"},
- new ToExcelObj(){MapColumn = "SurfaceColor",ShowColumn = "表色"},
- new ToExcelObj(){MapColumn = "Material",ShowColumn = "材质"},
- new ToExcelObj(){MapColumn = "Rigidity",ShowColumn = "硬度"},
- new ToExcelObj(){MapColumn = "Quantity",ShowColumn = "数量(千件)"},
- new ToExcelObj(){MapColumn = "EnterOutFlag",ShowColumn = "进出库"},
- new ToExcelObj(){MapColumn = "DateTiem",ShowColumn = "日期"},
- new ToExcelObj(){MapColumn = "UserIDLastMod",ShowColumn = "操作人"},
- new ToExcelObj(){MapColumn = "CustomerId",ShowColumn = "客户编号"},
- new ToExcelObj(){MapColumn = "CustomerName",ShowColumn = "客户名称"},
- };
- string lcResultFileName = ExcelHelper.ToExcel2003(columnsList, r, "sheet", lcFilePath);
-
- return Path.Combine(downloadUrl, lcResultFileName);
- }
- #endregion
- [AbpAuthorize(PermissionNames.PagesFinshedStoreInfoCurrentStoreHouseQueryMg), AuditLog("库存信息查询")]
- public async Task<PagedResultDto<ViewCurrentStoreTotal>> QueryCurrentStoreTotal(PagedRequestDto input)
- {
- var query = ViewCurrentStoreTotalRepository.GetAll();
- if (input.SearchList != null && input.SearchList.Count > 0)
- {
- List<LambdaObject> objList = new List<LambdaObject>();
- foreach (var o in input.SearchList)
- {
- if (o.KeyWords.IsNullOrEmpty())
- continue;
- object keyWords = o.KeyWords;
- //检查查询条件中带有规格且多个分割条件的
- ProductModelSearch.CheckModelGreaterOneFilter(o, ref keyWords);
- objList.Add(new LambdaObject
- {
- FieldType = (LambdaFieldType)o.FieldType,
- FieldName = o.KeyField,
- FieldValue = keyWords,
- ExpType = (LambdaExpType)o.ExpType
- });
- }
- var exp = objList.GetExp<ViewCurrentStoreTotal>();
- query = query.Where(exp);
- }
- var totalCount = await AsyncQueryableExecuter.CountAsync(query);
- query = query.OrderByDescending(i => i.Id);
- string pattern = ProductModelSearch.GetModelGreaterOneReg(input.SearchList);
- List<ViewCurrentStoreTotal> entities;
- //检查查询条件中带有规格且多个分割条件的
- if (!pattern.IsNullOrEmpty())
- {
- var es = query.ToList();
- es = es.Where(f => f.Model != null && Regex.IsMatch(f.Model, pattern)).ToList();
- totalCount = es.Count;
- entities = es.Skip(input.SkipCount).Take(input.MaxResultCount).ToList();
- }
- else
- {
- query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
- entities = await AsyncQueryableExecuter.ToListAsync(query);
- }
- //query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
- //var entities = await AsyncQueryableExecuter.ToListAsync(query);
- var dtos = new PagedResultDto<ViewCurrentStoreTotal>(
- totalCount,
- entities
- );
- return dtos;
- }
- [AbpAuthorize(PermissionNames.PagesFinshedStoreInfoCurrentStoreHouseQueryMg), AuditLog("库存信息查询")]
- public async Task<ViewCurrentStoreTotal> QueryStoreTotalByProduct(string pcProductNo)
- {
- //throw new NotImplementedException();
- var query =await ViewCurrentStoreTotalRepository.FirstOrDefaultAsync(i=>i.Id==pcProductNo);
- return query;
- }
- [AbpAuthorize(PermissionNames.PagesSemiProductStoreInfoCurrentSemiStoreHouseMgQuery), AuditLog("半成品库存进出信息查询")]
- public async Task<List<ViewEnterOutSemiProductStore>> QuerySemiEnterOutRecord(string productNo)
- {
- return (await ViewEnterOutSemiProductStoreRepository.GetAllListAsync(i => i.SemiProductNo == productNo)).OrderByDescending(i => i.DateTiem).ToList();
- }
- [AbpAuthorize(PermissionNames.PagesSemiProductStoreInfoCurrentSemiStoreHouseMgQuery), AuditLog("半成品库存统计信息查询")]
- public async Task<PagedResultDto<ViewCurrentSemiStoreTotal>> QuerySemiCurrentStoreTotal(PagedRequestDto input)
- {
- var query = ViewCurrentSemiStoreTotalRepository.GetAll();
- if (input.SearchList != null && input.SearchList.Count > 0)
- {
- List<LambdaObject> objList = new List<LambdaObject>();
- foreach (var o in input.SearchList)
- {
- if (o.KeyWords.IsNullOrEmpty())
- continue;
- object keyWords = o.KeyWords;
- //检查查询条件中带有规格且多个分割条件的
- ProductModelSearch.CheckModelGreaterOneFilter(o, ref keyWords);
- objList.Add(new LambdaObject
- {
- FieldType = (LambdaFieldType)o.FieldType,
- FieldName = o.KeyField,
- FieldValue = keyWords,
- ExpType = (LambdaExpType)o.ExpType
- });
- }
- var exp = objList.GetExp<ViewCurrentSemiStoreTotal>();
- query = query.Where(exp);
- }
- var totalCount = await AsyncQueryableExecuter.CountAsync(query);
- query = query.OrderByDescending(i => i.Id);
- string pattern = ProductModelSearch.GetModelGreaterOneReg(input.SearchList);
- List<ViewCurrentSemiStoreTotal> entities;
- //检查查询条件中带有规格且多个分割条件的
- if (!pattern.IsNullOrEmpty())
- {
- var es = query.ToList();
- es = es.Where(f => f.Model != null && Regex.IsMatch(f.Model, pattern)).ToList();
- totalCount = es.Count;
- entities = es.Skip(input.SkipCount).Take(input.MaxResultCount).ToList();
- }
- else
- {
- query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
- entities = await AsyncQueryableExecuter.ToListAsync(query);
- }
- //query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
- //var entities = await AsyncQueryableExecuter.ToListAsync(query);
- var dtos = new PagedResultDto<ViewCurrentSemiStoreTotal>(
- totalCount,
- entities
- );
- return dtos;
- }
- public async Task<ViewCurrentSemiStoreTotal> QuerySemiCurrentStoreTotalByProduct(string pcProductNo)
- {
- //throw new NotImplementedException();
- var query = await ViewCurrentSemiStoreTotalRepository.FirstOrDefaultAsync(i => i.Id == pcProductNo);
- return query;
- }
- }
- }
|