StoreStatisticsApplicationService.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.Entity;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Text.RegularExpressions;
  8. using System.Threading.Tasks;
  9. using Abp.Application.Services;
  10. using Abp.Application.Services.Dto;
  11. using Abp.Authorization;
  12. using Abp.Configuration;
  13. using Abp.Domain.Repositories;
  14. using Abp.Extensions;
  15. using IwbZero.AppServiceBase;
  16. using IwbZero.Auditing;
  17. using IwbZero.Setting;
  18. using ShwasherSys.Authorization.Permissions;
  19. using ShwasherSys.Common;
  20. using ShwasherSys.Common.Dto;
  21. using ShwasherSys.Lambda;
  22. using ShwasherSys.ProductStoreInfo;
  23. using ShwasherSys.SemiProductStoreInfo;
  24. using ShwasherSys.StoreQuery.Dto;
  25. namespace ShwasherSys.StoreQuery
  26. {
  27. [AbpAuthorize]
  28. public class StoreStatisticsApplicationService: ShwasherAsyncCrudAppService<ViewEnterOutProductStore, ViewEnterOutProductStoreDto, string, PagedRequestDto, ViewEnterOutProductStoreDto, ViewEnterOutProductStoreDto>, IStoreStatisticsApplicationService
  29. {
  30. public IRepository<ViewCurrentStoreTotal,string> ViewCurrentStoreTotalRepository { get; }
  31. public IRepository<ViewEnterOutLogCus, string> ViewEnterOutLogCusRepository { get; }
  32. public IRepository<ViewEnterOutSemiProductStore, string> ViewEnterOutSemiProductStoreRepository { get; }
  33. public IRepository<ViewCurrentSemiStoreTotal, string> ViewCurrentSemiStoreTotalRepository { get; }
  34. 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)
  35. {
  36. ViewCurrentStoreTotalRepository = viewCurrentStoreTotalRepository;
  37. ViewEnterOutLogCusRepository = viewEnterOutLogCusRepository;
  38. ViewEnterOutSemiProductStoreRepository = viewEnterOutSemiProductStoreRepository;
  39. ViewCurrentSemiStoreTotalRepository = viewCurrentSemiStoreTotalRepository;
  40. SettingManager = settingManager;
  41. }
  42. [AbpAuthorize(PermissionNames.PagesFinshedStoreInfoEnterOutStoreHouseQueryMg),AuditLog("库存出入库记录")]
  43. public async Task<PagedResultDto<ViewEnterOutLogCus>> QueryEnterOutRecord(PagedRequestDto input)
  44. {
  45. var query = ViewEnterOutLogCusRepository.GetAll();
  46. if (input.SearchList != null && input.SearchList.Count > 0)
  47. {
  48. List<LambdaObject> objList = new List<LambdaObject>();
  49. foreach (var o in input.SearchList)
  50. {
  51. if (o.KeyWords.IsNullOrEmpty())
  52. continue;
  53. object keyWords = o.KeyWords;
  54. //检查查询条件中带有规格且多个分割条件的
  55. ProductModelSearch.CheckModelGreaterOneFilter(o, ref keyWords);
  56. objList.Add(new LambdaObject
  57. {
  58. FieldType = (LambdaFieldType)o.FieldType,
  59. FieldName = o.KeyField,
  60. FieldValue = keyWords,
  61. ExpType = (LambdaExpType)o.ExpType
  62. });
  63. }
  64. var exp = objList.GetExp<ViewEnterOutLogCus>();
  65. query = exp!=null? query.Where(exp): query;
  66. }
  67. var totalCount = await AsyncQueryableExecuter.CountAsync(query);
  68. query = query.OrderByDescending(i => i.ProductNo).ThenByDescending(i=>i.DateTiem);
  69. string pattern = ProductModelSearch.GetModelGreaterOneReg(input.SearchList);
  70. List<ViewEnterOutLogCus> entities;
  71. //检查查询条件中带有规格且多个分割条件的
  72. if (!pattern.IsNullOrEmpty())
  73. {
  74. var es = query.ToList();
  75. es = es.Where(f => f.Model != null && Regex.IsMatch(f.Model, pattern)).ToList();
  76. totalCount = es.Count;
  77. entities = es.Skip(input.SkipCount).Take(input.MaxResultCount).ToList();
  78. }
  79. else
  80. {
  81. query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
  82. entities = await AsyncQueryableExecuter.ToListAsync(query);
  83. }
  84. //query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
  85. //var entities = await AsyncQueryableExecuter.ToListAsync(query);
  86. var result = new PagedResultDto<ViewEnterOutLogCus>(totalCount, entities);
  87. return result;
  88. }
  89. [AbpAuthorize(PermissionNames.PagesFinshedStoreInfoEnterOutStoreHouseQueryMg), AuditLog("库存出入库记录")]
  90. public async Task<List<ViewEnterOutProductStore>> QueryEnterOutRecordTmp(List<MultiSearchDtoExt> input)
  91. {
  92. var query = Repository.GetAll();
  93. if (input != null && input.Count > 0)
  94. {
  95. List<LambdaObject> objList = new List<LambdaObject>();
  96. foreach (var o in input)
  97. {
  98. if (o.KeyWords.IsNullOrEmpty())
  99. continue;
  100. object keyWords = o.KeyWords;
  101. objList.Add(new LambdaObject
  102. {
  103. FieldType = (LambdaFieldType)o.FieldType,
  104. FieldName = o.KeyField,
  105. FieldValue = keyWords,
  106. ExpType = (LambdaExpType)o.ExpType
  107. });
  108. }
  109. var exp = objList.GetExp<ViewEnterOutProductStore>();
  110. query = query.Where(exp);
  111. }
  112. query = query.OrderByDescending(i => i.ProductNo).ThenByDescending(i => i.DateTiem);
  113. var entities = await AsyncQueryableExecuter.ToListAsync(query);
  114. return entities;
  115. }
  116. public async Task<List<ViewEnterOutProductStore>> QueryProductEnterOutRecord(string productNo)
  117. {
  118. return (await Repository.GetAllListAsync(i => i.ProductNo == productNo)).OrderByDescending(i=>i.DateTiem).ToList();
  119. }
  120. #region 进出库记录导出
  121. [AbpAuthorize(PermissionNames.PagesFinshedStoreInfoEnterOutStoreHouseQueryMgExportExcel), AuditLog("库存出入库记录导出excel")]
  122. public async Task<string> ExportExcel(List<MultiSearchDtoExt> input)
  123. {
  124. var query = ViewEnterOutLogCusRepository.GetAll();
  125. if (input != null && input.Count > 0)
  126. {
  127. List<LambdaObject> objList = new List<LambdaObject>();
  128. foreach (var o in input)
  129. {
  130. if (o.KeyWords.IsNullOrEmpty())
  131. continue;
  132. object keyWords = o.KeyWords;
  133. //检查查询条件中带有规格且多个分割条件的
  134. ProductModelSearch.CheckModelGreaterOneFilter(o, ref keyWords);
  135. objList.Add(new LambdaObject
  136. {
  137. FieldType = (LambdaFieldType)o.FieldType,
  138. FieldName = o.KeyField,
  139. FieldValue = keyWords,
  140. ExpType = (LambdaExpType)o.ExpType
  141. });
  142. }
  143. var exp = objList.GetExp<ViewEnterOutLogCus>();
  144. query = query.Where(exp);
  145. }
  146. query = query.OrderByDescending(i => i.ProductNo).ThenByDescending(i => i.DateTiem);
  147. var r = query.Select(i => new
  148. {
  149. i.ProductNo,
  150. i.ProductName,
  151. i.Model,
  152. i.SurfaceColor,
  153. i.Material,
  154. i.Rigidity,
  155. i.Quantity,
  156. EnterOutFlag = i.EnterOutFlag==1?"入库":"出库",
  157. i.DateTiem,
  158. i.UserIDLastMod,
  159. i.CustomerId,
  160. i.CustomerName,
  161. }).ToList();
  162. string pattern = ProductModelSearch.GetModelGreaterOneReg(input);
  163. //检查查询条件中带有规格且多个分割条件的
  164. if (!pattern.IsNullOrEmpty())
  165. {
  166. r = r.Where(f => f.Model != null && Regex.IsMatch(f.Model, pattern)).ToList();
  167. }
  168. string downloadUrl = await SettingManager.GetSettingValueAsync("SYSTEMDOWNLOADPATH");
  169. string lcFilePath = System.Web.HttpRuntime.AppDomainAppPath + "\\" +
  170. downloadUrl;
  171. List<ToExcelObj> columnsList = new List<ToExcelObj>()
  172. {
  173. new ToExcelObj(){MapColumn = "ProductNo",ShowColumn = "产品编号"},
  174. new ToExcelObj(){MapColumn = "ProductName",ShowColumn = "产品名称"},
  175. new ToExcelObj(){MapColumn = "Model",ShowColumn = "规格"},
  176. new ToExcelObj(){MapColumn = "SurfaceColor",ShowColumn = "表色"},
  177. new ToExcelObj(){MapColumn = "Material",ShowColumn = "材质"},
  178. new ToExcelObj(){MapColumn = "Rigidity",ShowColumn = "硬度"},
  179. new ToExcelObj(){MapColumn = "Quantity",ShowColumn = "数量(千件)"},
  180. new ToExcelObj(){MapColumn = "EnterOutFlag",ShowColumn = "进出库"},
  181. new ToExcelObj(){MapColumn = "DateTiem",ShowColumn = "日期"},
  182. new ToExcelObj(){MapColumn = "UserIDLastMod",ShowColumn = "操作人"},
  183. new ToExcelObj(){MapColumn = "CustomerId",ShowColumn = "客户编号"},
  184. new ToExcelObj(){MapColumn = "CustomerName",ShowColumn = "客户名称"},
  185. };
  186. string lcResultFileName = ExcelHelper.ToExcel2003(columnsList, r, "sheet", lcFilePath);
  187. return Path.Combine(downloadUrl, lcResultFileName);
  188. }
  189. #endregion
  190. [AbpAuthorize(PermissionNames.PagesFinshedStoreInfoCurrentStoreHouseQueryMg), AuditLog("库存信息查询")]
  191. public async Task<PagedResultDto<ViewCurrentStoreTotal>> QueryCurrentStoreTotal(PagedRequestDto input)
  192. {
  193. var query = ViewCurrentStoreTotalRepository.GetAll();
  194. if (input.SearchList != null && input.SearchList.Count > 0)
  195. {
  196. List<LambdaObject> objList = new List<LambdaObject>();
  197. foreach (var o in input.SearchList)
  198. {
  199. if (o.KeyWords.IsNullOrEmpty())
  200. continue;
  201. object keyWords = o.KeyWords;
  202. //检查查询条件中带有规格且多个分割条件的
  203. ProductModelSearch.CheckModelGreaterOneFilter(o, ref keyWords);
  204. objList.Add(new LambdaObject
  205. {
  206. FieldType = (LambdaFieldType)o.FieldType,
  207. FieldName = o.KeyField,
  208. FieldValue = keyWords,
  209. ExpType = (LambdaExpType)o.ExpType
  210. });
  211. }
  212. var exp = objList.GetExp<ViewCurrentStoreTotal>();
  213. query = query.Where(exp);
  214. }
  215. var totalCount = await AsyncQueryableExecuter.CountAsync(query);
  216. query = query.OrderByDescending(i => i.Id);
  217. string pattern = ProductModelSearch.GetModelGreaterOneReg(input.SearchList);
  218. List<ViewCurrentStoreTotal> entities;
  219. //检查查询条件中带有规格且多个分割条件的
  220. if (!pattern.IsNullOrEmpty())
  221. {
  222. var es = query.ToList();
  223. es = es.Where(f => f.Model != null && Regex.IsMatch(f.Model, pattern)).ToList();
  224. totalCount = es.Count;
  225. entities = es.Skip(input.SkipCount).Take(input.MaxResultCount).ToList();
  226. }
  227. else
  228. {
  229. query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
  230. entities = await AsyncQueryableExecuter.ToListAsync(query);
  231. }
  232. //query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
  233. //var entities = await AsyncQueryableExecuter.ToListAsync(query);
  234. var dtos = new PagedResultDto<ViewCurrentStoreTotal>(
  235. totalCount,
  236. entities
  237. );
  238. return dtos;
  239. }
  240. [AbpAuthorize(PermissionNames.PagesFinshedStoreInfoCurrentStoreHouseQueryMg), AuditLog("库存信息查询")]
  241. public async Task<ViewCurrentStoreTotal> QueryStoreTotalByProduct(string pcProductNo)
  242. {
  243. //throw new NotImplementedException();
  244. var query =await ViewCurrentStoreTotalRepository.FirstOrDefaultAsync(i=>i.Id==pcProductNo);
  245. return query;
  246. }
  247. [AbpAuthorize(PermissionNames.PagesSemiProductStoreInfoCurrentSemiStoreHouseMgQuery), AuditLog("半成品库存进出信息查询")]
  248. public async Task<List<ViewEnterOutSemiProductStore>> QuerySemiEnterOutRecord(string productNo)
  249. {
  250. return (await ViewEnterOutSemiProductStoreRepository.GetAllListAsync(i => i.SemiProductNo == productNo)).OrderByDescending(i => i.DateTiem).ToList();
  251. }
  252. [AbpAuthorize(PermissionNames.PagesSemiProductStoreInfoCurrentSemiStoreHouseMgQuery), AuditLog("半成品库存统计信息查询")]
  253. public async Task<PagedResultDto<ViewCurrentSemiStoreTotal>> QuerySemiCurrentStoreTotal(PagedRequestDto input)
  254. {
  255. var query = ViewCurrentSemiStoreTotalRepository.GetAll();
  256. if (input.SearchList != null && input.SearchList.Count > 0)
  257. {
  258. List<LambdaObject> objList = new List<LambdaObject>();
  259. foreach (var o in input.SearchList)
  260. {
  261. if (o.KeyWords.IsNullOrEmpty())
  262. continue;
  263. object keyWords = o.KeyWords;
  264. //检查查询条件中带有规格且多个分割条件的
  265. ProductModelSearch.CheckModelGreaterOneFilter(o, ref keyWords);
  266. objList.Add(new LambdaObject
  267. {
  268. FieldType = (LambdaFieldType)o.FieldType,
  269. FieldName = o.KeyField,
  270. FieldValue = keyWords,
  271. ExpType = (LambdaExpType)o.ExpType
  272. });
  273. }
  274. var exp = objList.GetExp<ViewCurrentSemiStoreTotal>();
  275. query = query.Where(exp);
  276. }
  277. var totalCount = await AsyncQueryableExecuter.CountAsync(query);
  278. query = query.OrderByDescending(i => i.Id);
  279. string pattern = ProductModelSearch.GetModelGreaterOneReg(input.SearchList);
  280. List<ViewCurrentSemiStoreTotal> entities;
  281. //检查查询条件中带有规格且多个分割条件的
  282. if (!pattern.IsNullOrEmpty())
  283. {
  284. var es = query.ToList();
  285. es = es.Where(f => f.Model != null && Regex.IsMatch(f.Model, pattern)).ToList();
  286. totalCount = es.Count;
  287. entities = es.Skip(input.SkipCount).Take(input.MaxResultCount).ToList();
  288. }
  289. else
  290. {
  291. query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
  292. entities = await AsyncQueryableExecuter.ToListAsync(query);
  293. }
  294. //query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
  295. //var entities = await AsyncQueryableExecuter.ToListAsync(query);
  296. var dtos = new PagedResultDto<ViewCurrentSemiStoreTotal>(
  297. totalCount,
  298. entities
  299. );
  300. return dtos;
  301. }
  302. public async Task<ViewCurrentSemiStoreTotal> QuerySemiCurrentStoreTotalByProduct(string pcProductNo)
  303. {
  304. //throw new NotImplementedException();
  305. var query = await ViewCurrentSemiStoreTotalRepository.FirstOrDefaultAsync(i => i.Id == pcProductNo);
  306. return query;
  307. }
  308. }
  309. }