QueryAppService.cs 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.Entity;
  4. using System.Globalization;
  5. using System.Linq;
  6. using System.Linq.Dynamic.Core;
  7. using System.Reflection;
  8. using System.Text.RegularExpressions;
  9. using System.Threading.Tasks;
  10. using System.Web.Http.Results;
  11. using System.Web.Mvc;
  12. using System.Web.UI.WebControls;
  13. using System.Xml;
  14. using Abp.Application.Services;
  15. using Abp.Application.Services.Dto;
  16. using Abp.Auditing;
  17. using Abp.Authorization;
  18. using Abp.Domain.Repositories;
  19. using Abp.Extensions;
  20. using Abp.Linq;
  21. using Abp.Linq.Extensions;
  22. using Abp.Runtime.Caching;
  23. using IwbZero.AppServiceBase;
  24. using IwbZero.IdentityFramework;
  25. using IwbZero.Setting;
  26. using Microsoft.AspNet.Identity;
  27. using NPOI.SS.Formula.Functions;
  28. using ShwasherSys.BasicInfo;
  29. using ShwasherSys.BasicInfo.OutFactory;
  30. using ShwasherSys.BasicInfo.OutFactory.Dto;
  31. using ShwasherSys.BasicInfo.StoreHouseLocations.Dto;
  32. using ShwasherSys.Common.Dto;
  33. using ShwasherSys.CompanyInfo;
  34. using ShwasherSys.CompanyInfo.DeviceInfo.Dto;
  35. using ShwasherSys.CompanyInfo.FixedAssetInfo.Dto;
  36. using ShwasherSys.CompanyInfo.MoldInfo.Dto;
  37. using ShwasherSys.CustomerInfo;
  38. using ShwasherSys.CustomerInfo.Dto;
  39. using ShwasherSys.Inspection;
  40. using ShwasherSys.Invoice;
  41. using ShwasherSys.Lambda;
  42. using ShwasherSys.NotificationInfo;
  43. using ShwasherSys.NotificationInfo.Dto;
  44. using ShwasherSys.Order;
  45. using ShwasherSys.OrderSendInfo;
  46. using ShwasherSys.PackageInfo;
  47. using ShwasherSys.ProductInfo;
  48. using ShwasherSys.ProductInfo.Dto;
  49. using ShwasherSys.ProductionOrderInfo;
  50. using ShwasherSys.ProductionOrderInfo.Dto;
  51. using ShwasherSys.ProductStoreInfo;
  52. using ShwasherSys.RmStore;
  53. using ShwasherSys.SemiProductStoreInfo;
  54. using TemplateInfo = ShwasherSys.Inspection.TemplateInfo;
  55. namespace ShwasherSys.Common
  56. {
  57. public interface IQueryAppService : IApplicationService
  58. {
  59. /// <summary>
  60. /// 查询外协厂商信息
  61. /// </summary>
  62. /// <param name="input"></param>
  63. /// <returns></returns>
  64. Task<PagedResultDto<OutFactoryDto>> GetOutFactory(IwbPagedRequestDto input);
  65. /// <summary>
  66. /// 查询客户信息
  67. /// </summary>
  68. /// <param name="input"></param>
  69. /// <returns></returns>
  70. Task<PagedResultDto<CustomerDto>> GetCustomer(IwbPagedRequestDto input);
  71. /// <summary>
  72. /// 查询半成品实时库存信息
  73. /// </summary>
  74. /// <param name="input"></param>
  75. /// <returns></returns>
  76. Task<PagedResultDto<ViewCurrentSemiStoreHouse>> GetCurrentSemiStore(IwbPagedRequestDto input);
  77. /// <summary>
  78. /// 查询半成品信息
  79. /// </summary>
  80. /// <param name="input"></param>
  81. /// <returns></returns>
  82. Task<PagedResultDto<SemiProductDto>> GetSemiProduct(IwbPagedRequestDto input);
  83. Task<string> GetSemiProductName(string id);
  84. Task<SemiProductDto> GetSingleSemiProduct(string input);
  85. /// <summary>
  86. /// 查询产品信息
  87. /// </summary>
  88. /// <param name="input"></param>
  89. /// <returns></returns>
  90. Task<PagedResultDto<ProductDto>> GetProduct(IwbPagedRequestDto input);
  91. Task<Product> GetProductById(EntityDto<string> input);
  92. Task<string> GetProductName(string id);
  93. /// <summary>
  94. /// 查询库位信息
  95. /// </summary>
  96. /// <param name="input"></param>
  97. /// <returns></returns>
  98. Task<PagedResultDto<StoreHouseLocationDto>> GetStoreHouseLocation(IwbPagedRequestDto input);
  99. Task<PagedResultDto<ProductionLogDto>> QueryProductionLog(IwbPagedRequestDto input);
  100. string GetDefualtProductByOrderNo(string orderNo);
  101. string GetDefaultProductByPartNo(string partNo,string orderNo);
  102. string QueryProductByCustomerAndPartNo(string partNo, string customerId) ;
  103. string GetDefualtProductByCustomerId(string customerId);
  104. Customer GetCustomerInfo(EntityDto<string> input);
  105. CustomerSend GetCustomerSendInfo(EntityDto<int> input);
  106. List<CustomerSendDto> GetCustomerSendDtoByCustomerId(CustomerSendDto customerId);
  107. List<SelectListItem> GetProductPropertyList(string pcPropertyName);
  108. List<CurrentProductStoreHouse> QueryStore(string productNo);
  109. List<CurrentProductStoreHouse> QueryStoreFilter(string productNo,string customerId);
  110. BulletinInfo GetBulletinInfo(EntityDto input);
  111. ShortMessage GetShortMsgDetailInfo(ShortMsgDetailDto input);
  112. Task<PagedResultDto<Product>> GetQueryCustomerDefaultProduct(IwbPagedRequestDto input);
  113. List<StoreHouse> QueryStoreHouse(int houseType=0);
  114. List<SelectListItem> QueryStoreHouseSelect(int houseType=0);
  115. string QueryStoreHouseSelectStr(int houseType = 0);
  116. List<ViewSemiEnterStore> QueryEnterStoresByPoNo(string productionOrderNo);
  117. Task<TemplateInfo> QueryTemplate(string tmpKey, int type);
  118. Task<List<Currency>> QueryAllCurrency();
  119. Task<List<CurrencyExchangeRate>> QueryCurrencyRate(string from,string to);
  120. Task<string> GetExpressNameById(int id);
  121. PagedResultDto<ViewEmployee> QueryEmployee(IwbPagedRequestDto input);
  122. Task<PagedResultDto<MoldDto>> QueryMold(IwbPagedRequestDto input);
  123. Task<PagedResultDto<FixedAssetDto>> QueryFixedAsset(IwbPagedRequestDto input);
  124. Task<PagedResultDto<ViewOrderSend>> QuerySendGood(IwbPagedRequestDto input);
  125. Task<PagedResultDto<ViewStickBill>> QueryInvoice(IwbPagedRequestDto input);
  126. Task<PagedResultDto<RmProduct>> GetRmProduct(IwbPagedRequestDto input);
  127. Task<PagedResultDto<ViewCurrentRmStoreHouse>> GetRmCurrentStore(IwbPagedRequestDto input);
  128. Task<PagedResultDto<ViewSemiEnterStore>> GetSemiEnterStoreCheckUnqualified(IwbPagedRequestDto input);
  129. Task<PagedResultDto<ProductPropertyDto>> GetProductProperty(IwbPagedRequestDto input);
  130. Task<string> CalcTaxPrice(int type, string input,string rate);
  131. Task<PagedResultDto<ViewOrderItems>> QueryOrderItem(IwbPagedRequestDto input);
  132. Task<OrderProductProcessDto> QueryOrderProductProcess(int orderItemId);
  133. #region 2023
  134. Task<PagedResultDto<ProductionOrderDto>> QueryProductionOrderDtoByProNo(PagedRequestDto input);
  135. Task<PagedResultDto<ViewCurrentProductStoreHouse>> QueryViewCurrentProductStoreHouseByProNo(
  136. PagedRequestDto input);
  137. Task<PagedResultDto<ViewCurrentSemiStoreHouse>> QueryViewCurrentSemiStoreHouseByProNo(PagedRequestDto input);
  138. #endregion
  139. #region 2024
  140. Task<Dictionary<int, List<DeviceMgPlanDto>>> QueryNeedMaintenanceMoldPlan();
  141. #endregion
  142. #region 2025
  143. Task<List<CustomerDefaultProduct>> GetCustomerDefaultProductByCustomerId(string customerId);
  144. Task<List<ProductProperty>> GetProductPropertyEntity(string productPropertyType);
  145. ShortMsgDetail ReadShortMsgDetailInfo(ShortMsgDetailDto input);
  146. Task<List<CurrentProductStoreHouse>> GetCurrentProductStoreHouseByNo(List<string> currentProductionOrderNos);
  147. #endregion
  148. }
  149. [AbpAuthorize,DisableAuditing]
  150. public class QueryAppService : ApplicationService, IQueryAppService
  151. {
  152. protected ICacheManager CacheManager { get; set; }
  153. protected new IIwbSettingManager SettingManager { get; set; }
  154. public QueryAppService(
  155. IRepository<Customer,string> customerRepository,
  156. IRepository<ViewCurrentSemiStoreHouse> currentSemiRepository,
  157. IRepository<SemiProducts, string> semiProductRepository,
  158. IRepository<Product, string> productRepository,
  159. IRepository<StoreHouseLocation> shlRepository,
  160. IIwbSettingManager settingManager,
  161. ICacheManager cacheManager, IRepository<CustomerDefaultProduct> customerDefaultProductRepository, IRepository<CustomerSend> customerSendRepository, IRepository<OrderHeader, string> orderHeaderRepository, IRepository<CurrentProductStoreHouse> currentProductStoreHouseRepository, IRepository<BulletinInfo> bulletinInfoRepository, IRepository<ShortMessage> shortMessageRepository, IRepository<ShortMsgDetail> shortMsgDetailRepository, IRepository<StoreHouse> storeHouseRepository, IRepository<ViewSemiEnterStore> viewSemiEnterStoreRepository, IRepository<OutFactory, string> outFactoryRepository, IRepository<TemplateInfo> templateInfoRepository, IRepository<Currency, string> currencyRepository, IRepository<CurrencyExchangeRate> currencyExchangeRateRepository, IRepository<ViewEmployee> viewEmployeeRepository, IRepository<RmProduct, string> rmRepository, IRepository<ViewCurrentRmStoreHouse, string> viewCurrentRmStoreHouseRepository, IRepository<ProductionLog> productionLogRepository, IRepository<CustomerDisabledProduct> customerDisabledProductRepository, IRepository<ExpressLogistics> expressRepository, IRepository<Mold> moldRepository, IRepository<FixedAsset> fixedAssetRepository, IRepository<ViewOrderSend> viewOrderSendRepository, IRepository<ViewStickBill, string> viewStickBillRepository, IRepository<ProductProperty> productPropertyRepository, IRepository<ViewOrderItems> viewOrderItemsRepository, IRepository<OrderProduction> orderProductionRepository, IRepository<ProductionOrder> productionOrderRepository, IRepository<PackageApply> packageApplyRepository, IRepository<ViewCurrentProductStoreHouse> viewCurrentProductStoreHouseRepository, IRepository<ViewCurrentSemiStoreHouse> viewCurrentSemiStoreHouseRepository, IRepository<DeviceMgPlan> deviceMgPlanRepository,IRepository<FinshedEnterStore> finshedEnterStoreRepository)
  162. {
  163. CustomerRepository = customerRepository;
  164. CurrentSemiRepository = currentSemiRepository;
  165. SemiProductRepository = semiProductRepository;
  166. ProductRepository = productRepository;
  167. ShlRepository = shlRepository;
  168. CacheManager = cacheManager;
  169. CustomerDefaultProductRepository = customerDefaultProductRepository;
  170. CustomerSendRepository = customerSendRepository;
  171. OrderHeaderRepository = orderHeaderRepository;
  172. CurrentProductStoreHouseRepository = currentProductStoreHouseRepository;
  173. BulletinInfoRepository = bulletinInfoRepository;
  174. SettingManager = settingManager;
  175. ShortMessageRepository = shortMessageRepository;
  176. ShortMsgDetailRepository = shortMsgDetailRepository;
  177. StoreHouseRepository = storeHouseRepository;
  178. ViewSemiEnterStoreRepository = viewSemiEnterStoreRepository;
  179. OutFactoryRepository = outFactoryRepository;
  180. TemplateInfoRepository = templateInfoRepository;
  181. CurrencyRepository = currencyRepository;
  182. CurrencyExchangeRateRepository = currencyExchangeRateRepository;
  183. ViewEmployeeRepository = viewEmployeeRepository;
  184. RmRepository = rmRepository;
  185. ViewCurrentRmStoreHouseRepository = viewCurrentRmStoreHouseRepository;
  186. ProductionLogRepository = productionLogRepository;
  187. CustomerDisabledProductRepository = customerDisabledProductRepository;
  188. ExpressRepository = expressRepository;
  189. MoldRepository = moldRepository;
  190. FixedAssetRepository = fixedAssetRepository;
  191. ViewOrderSendRepository = viewOrderSendRepository;
  192. ViewStickBillRepository = viewStickBillRepository;
  193. ProductPropertyRepository = productPropertyRepository;
  194. ViewOrderItemsRepository = viewOrderItemsRepository;
  195. OrderProductionRepository = orderProductionRepository;
  196. ProductionOrderRepository = productionOrderRepository;
  197. PackageApplyRepository = packageApplyRepository;
  198. ViewCurrentProductStoreHouseRepository = viewCurrentProductStoreHouseRepository;
  199. ViewCurrentSemiStoreHouseRepository = viewCurrentSemiStoreHouseRepository;
  200. AsyncQueryableExecuter = NullAsyncQueryableExecuter.Instance;
  201. DeviceMgPlanRepository = deviceMgPlanRepository;
  202. FinshedEnterStoreRepository = finshedEnterStoreRepository;
  203. }
  204. protected IRepository<FixedAsset> FixedAssetRepository { get; }
  205. protected IRepository<Mold> MoldRepository { get; }
  206. protected IRepository<ExpressLogistics> ExpressRepository { get; }
  207. protected IRepository<ProductionLog> ProductionLogRepository { get; }
  208. protected IRepository<OutFactory, string> OutFactoryRepository { get; }
  209. protected IRepository<Customer, string> CustomerRepository { get; }
  210. protected IRepository<ViewCurrentSemiStoreHouse> CurrentSemiRepository { get; }
  211. protected IRepository<SemiProducts, string> SemiProductRepository { get; }
  212. protected IRepository<Product, string> ProductRepository { get; }
  213. public IRepository<StoreHouseLocation> ShlRepository { get; }
  214. protected IRepository<CustomerDefaultProduct> CustomerDefaultProductRepository { get; }
  215. protected IRepository<CustomerSend> CustomerSendRepository { get; }
  216. protected IRepository<OrderHeader, string> OrderHeaderRepository { get; }
  217. protected IRepository<CurrentProductStoreHouse> CurrentProductStoreHouseRepository { get; }
  218. protected IRepository<BulletinInfo> BulletinInfoRepository { get; }
  219. protected IRepository<ShortMessage> ShortMessageRepository { get; }
  220. protected IRepository<ShortMsgDetail> ShortMsgDetailRepository { get; }
  221. protected IRepository<StoreHouse> StoreHouseRepository { get; }
  222. protected IRepository<ViewSemiEnterStore> ViewSemiEnterStoreRepository { get; }
  223. protected IRepository<TemplateInfo> TemplateInfoRepository { get; }
  224. protected IRepository<Currency,string> CurrencyRepository { get; }
  225. protected IRepository<CurrencyExchangeRate> CurrencyExchangeRateRepository { get; }
  226. protected IRepository<ViewEmployee> ViewEmployeeRepository { get; }
  227. protected IRepository<RmProduct,string> RmRepository { get; }
  228. protected IRepository<ViewCurrentRmStoreHouse, string> ViewCurrentRmStoreHouseRepository { get; }
  229. protected IRepository<CustomerDisabledProduct> CustomerDisabledProductRepository { get; }
  230. protected IRepository<ViewOrderSend> ViewOrderSendRepository { get; }
  231. public IAsyncQueryableExecuter AsyncQueryableExecuter { get; set; }
  232. protected IRepository<ProductProperty> ProductPropertyRepository { get; }
  233. protected IRepository<ViewOrderItems> ViewOrderItemsRepository { get; }
  234. protected IRepository<OrderProduction> OrderProductionRepository { get; }
  235. protected IRepository<ProductionOrder> ProductionOrderRepository { get; }
  236. protected IRepository<PackageApply> PackageApplyRepository { get; }
  237. protected IRepository<ViewCurrentProductStoreHouse> ViewCurrentProductStoreHouseRepository { get; }
  238. protected IRepository<ViewCurrentSemiStoreHouse> ViewCurrentSemiStoreHouseRepository { get; }
  239. protected IRepository<DeviceMgPlan> DeviceMgPlanRepository { get; }
  240. protected IRepository<FinshedEnterStore> FinshedEnterStoreRepository { get; }
  241. /// <summary>
  242. /// 查询快递名称
  243. /// </summary>
  244. /// <param name="id"></param>
  245. /// <returns></returns>
  246. public async Task<string> GetExpressNameById(int id)
  247. {
  248. var express = await ExpressRepository.FirstOrDefaultAsync(a => a.Id == id);
  249. return express?.ExpressName ?? "";
  250. }
  251. /// <summary>
  252. /// 查询外协厂商信息
  253. /// </summary>
  254. /// <param name="input"></param>
  255. /// <returns></returns>
  256. public async Task<PagedResultDto<OutFactoryDto>> GetOutFactory(IwbPagedRequestDto input)
  257. {
  258. var query = OutFactoryRepository.GetAll().Where(a => a.IsLock == "N");
  259. if (input.SearchList != null && input.SearchList.Count > 0)
  260. {
  261. List<LambdaObject> objList = new List<LambdaObject>();
  262. foreach (var o in input.SearchList)
  263. {
  264. if (o.KeyWords.IsNullOrEmpty())
  265. continue;
  266. object keyWords = o.KeyWords;
  267. objList.Add(new LambdaObject
  268. {
  269. FieldType = (LambdaFieldType)o.FieldType,
  270. FieldName = o.KeyField,
  271. FieldValue = keyWords,
  272. ExpType = (LambdaExpType)o.ExpType
  273. });
  274. }
  275. var exp = objList.GetExp<OutFactory>();
  276. query = query.Where(exp);
  277. }
  278. var totalCount = await query.CountAsync();
  279. query = query.OrderByDescending(i => i.TimeCreated);
  280. query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
  281. var entities = await query.ToListAsync();
  282. var dtos = new PagedResultDto<OutFactoryDto>(
  283. totalCount,
  284. entities.Select(ObjectMapper.Map<OutFactoryDto>).ToList()
  285. );
  286. return dtos;
  287. }
  288. /// <summary>
  289. /// 查询客户信息
  290. /// </summary>
  291. /// <param name="input"></param>
  292. /// <returns></returns>
  293. public async Task<PagedResultDto<CustomerDto>> GetCustomer(IwbPagedRequestDto input)
  294. {
  295. var query = CustomerRepository.GetAll().Where(a => a.IsLock == "N");
  296. if (input.SearchList != null && input.SearchList.Count > 0)
  297. {
  298. List<LambdaObject> objList = new List<LambdaObject>();
  299. foreach (var o in input.SearchList)
  300. {
  301. if (o.KeyWords.IsNullOrEmpty())
  302. continue;
  303. object keyWords = o.KeyWords;
  304. objList.Add(new LambdaObject
  305. {
  306. FieldType = (LambdaFieldType)o.FieldType,
  307. FieldName = o.KeyField,
  308. FieldValue = keyWords,
  309. ExpType = (LambdaExpType)o.ExpType
  310. });
  311. }
  312. var exp = objList.GetExp<Customer>();
  313. query = query.Where(exp);
  314. }
  315. var totalCount = await query.CountAsync();
  316. query = query.OrderByDescending(i => i.TimeCreated);
  317. query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
  318. var entities = await query.ToListAsync();
  319. var dtos = new PagedResultDto<CustomerDto>(
  320. totalCount,
  321. entities.Select(ObjectMapper.Map<CustomerDto>).ToList()
  322. );
  323. return dtos;
  324. }
  325. /// <summary>
  326. /// 查询半成品实时库存信息
  327. /// </summary>
  328. /// <param name="input"></param>
  329. /// <returns></returns>
  330. public async Task<PagedResultDto<ViewCurrentSemiStoreHouse>> GetCurrentSemiStore(IwbPagedRequestDto input)
  331. {
  332. var query = CurrentSemiRepository.GetAll();
  333. if (input.SearchList != null && input.SearchList.Count > 0)
  334. {
  335. List<LambdaObject> objList = new List<LambdaObject>();
  336. foreach (var o in input.SearchList)
  337. {
  338. if (o.KeyWords.IsNullOrEmpty())
  339. continue;
  340. object keyWords = o.KeyWords;
  341. objList.Add(new LambdaObject
  342. {
  343. FieldType = (LambdaFieldType)o.FieldType,
  344. FieldName = o.KeyField,
  345. FieldValue = keyWords,
  346. ExpType = (LambdaExpType)o.ExpType
  347. });
  348. }
  349. var exp = objList.GetExp<ViewCurrentSemiStoreHouse>();
  350. query = query.Where(exp);
  351. }
  352. query = query.Where(i => (i.ActualQuantity - i.FreezeQuantity) > 0);//过滤掉可用数量小于等于0
  353. var totalCount = await query.CountAsync();
  354. query = query.OrderByDescending(i => i.TimeCreated);
  355. query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
  356. var entities = await query.ToListAsync();
  357. var dtos = new PagedResultDto<ViewCurrentSemiStoreHouse>(totalCount,entities);
  358. return dtos;
  359. }
  360. /// <summary>
  361. /// 查询半成品信息
  362. /// </summary>
  363. /// <param name="input"></param>
  364. /// <returns></returns>
  365. public async Task<PagedResultDto<SemiProductDto>> GetSemiProduct(IwbPagedRequestDto input)
  366. {
  367. var query = SemiProductRepository.GetAll().Where(a => a.IsLock == "N");
  368. if (input.SearchList != null && input.SearchList.Count > 0)
  369. {
  370. List<LambdaObject> objList = new List<LambdaObject>();
  371. foreach (var o in input.SearchList)
  372. {
  373. if (o.KeyWords.IsNullOrEmpty())
  374. continue;
  375. object keyWords = o.KeyWords;
  376. //检查查询条件中带有规格且多个分割条件的
  377. ProductModelSearch.CheckModelGreaterOneFilter(o, ref keyWords);
  378. objList.Add(new LambdaObject
  379. {
  380. FieldType = (LambdaFieldType)o.FieldType,
  381. FieldName = o.KeyField,
  382. FieldValue = keyWords,
  383. ExpType = (LambdaExpType)o.ExpType
  384. });
  385. }
  386. var exp = objList.GetExp<SemiProducts>();
  387. query = query.Where(exp);
  388. }
  389. var totalCount = await query.CountAsync();
  390. query = query.OrderByDescending(i => i.TimeCreated);
  391. //query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
  392. //var entities = await query.ToListAsync();
  393. string pattern = ProductModelSearch.GetModelGreaterOneReg(input.SearchList);
  394. List<SemiProducts> entities;
  395. //检查查询条件中带有规格且多个分割条件的
  396. if (!pattern.IsNullOrEmpty())
  397. {
  398. var es = query.ToList();
  399. es = es.Where(f => f.Model != null && Regex.IsMatch(f.Model, pattern)).ToList();
  400. totalCount = es.Count;
  401. entities = es.Skip(input.SkipCount).Take(input.MaxResultCount).ToList();
  402. }
  403. else
  404. {
  405. query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
  406. entities = await AsyncQueryableExecuter.ToListAsync(query);
  407. }
  408. var dtos = new PagedResultDto<SemiProductDto>(
  409. totalCount,
  410. entities.Select(ObjectMapper.Map<SemiProductDto>).ToList()
  411. );
  412. return dtos;
  413. }
  414. public async Task<SemiProductDto> GetSingleSemiProduct(string input)
  415. {
  416. var query = await SemiProductRepository.FirstOrDefaultAsync(i=>i.Id==input);
  417. return ObjectMapper.Map<SemiProductDto>(query);
  418. }
  419. public async Task<string> GetSemiProductName(string id)
  420. {
  421. var entity = await CacheManager.GetCache(ShwasherConsts.SemiProductCache)
  422. .GetAsync(id, () => SemiProductRepository.FirstOrDefaultAsync(i => i.Id == id));
  423. return entity?.SemiProductName ?? "";
  424. }
  425. public async Task<string> GetProductName(string id)
  426. {
  427. var entity = await CacheManager.GetCache(ShwasherConsts.FinshedProductCache)
  428. .GetAsync(id, () => ProductRepository.FirstOrDefaultAsync(i => i.Id == id));
  429. return entity?.ProductName ?? "";
  430. }
  431. /// <summary>
  432. /// 查询产品信息
  433. /// </summary>
  434. /// <param name="input"></param>
  435. /// <returns></returns>
  436. public async Task<PagedResultDto<ProductDto>> GetProduct(IwbPagedRequestDto input)
  437. {
  438. var query = ProductRepository.GetAll().Where(a => a.IsLock == "N");
  439. if (input.SearchList != null && input.SearchList.Count > 0)
  440. {
  441. List<LambdaObject> objList = new List<LambdaObject>();
  442. foreach (var o in input.SearchList)
  443. {
  444. if (o.KeyWords.IsNullOrEmpty())
  445. continue;
  446. object keyWords = o.KeyWords;
  447. //检查查询条件中带有规格且多个分割条件的
  448. ProductModelSearch.CheckModelGreaterOneFilter(o, ref keyWords);
  449. objList.Add(new LambdaObject
  450. {
  451. FieldType = (LambdaFieldType)o.FieldType,
  452. FieldName = o.KeyField,
  453. FieldValue = keyWords,
  454. ExpType = (LambdaExpType)o.ExpType
  455. });
  456. }
  457. var exp = objList.GetExp<Product>();
  458. query = query.Where(exp);
  459. }
  460. var totalCount = await query.CountAsync();
  461. query = !input.Sorting.IsNullOrWhiteSpace() ? query.OrderBy(input.Sorting) : query.OrderByDescending(i => i.TimeCreated);
  462. string pattern = ProductModelSearch.GetModelGreaterOneReg(input.SearchList);
  463. List<Product> entities;
  464. //检查查询条件中带有规格且多个分割条件的
  465. if (!pattern.IsNullOrEmpty())
  466. {
  467. var es = query.ToList();
  468. es = es.Where(f => f.Model != null && Regex.IsMatch(f.Model, pattern)).ToList();
  469. totalCount = es.Count;
  470. entities = es.Skip(input.SkipCount).Take(input.MaxResultCount).ToList();
  471. }
  472. else
  473. {
  474. query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
  475. entities = await AsyncQueryableExecuter.ToListAsync(query);
  476. }
  477. //query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
  478. //var entities = await query.ToListAsync();
  479. var dtos = new PagedResultDto<ProductDto>(
  480. totalCount,
  481. entities.Select(ObjectMapper.Map<ProductDto>).ToList()
  482. );
  483. return dtos;
  484. }
  485. public async Task<Product> GetProductById(EntityDto<string> input)
  486. {
  487. return await ProductRepository.FirstOrDefaultAsync(input.Id);
  488. }
  489. /// <summary>
  490. /// 查询库位信息
  491. /// </summary>
  492. /// <param name="input"></param>
  493. /// <returns></returns>
  494. public async Task<PagedResultDto<StoreHouseLocationDto>> GetStoreHouseLocation(IwbPagedRequestDto input)
  495. {
  496. var query = ShlRepository.GetAll();
  497. if (input.SearchList != null && input.SearchList.Count > 0)
  498. {
  499. List<LambdaObject> objList = new List<LambdaObject>();
  500. foreach (var o in input.SearchList)
  501. {
  502. if (o.KeyWords.IsNullOrEmpty())
  503. continue;
  504. object keyWords = o.KeyWords;
  505. objList.Add(new LambdaObject
  506. {
  507. FieldType = (LambdaFieldType)o.FieldType,
  508. FieldName = o.KeyField,
  509. FieldValue = keyWords,
  510. ExpType = (LambdaExpType)o.ExpType
  511. });
  512. }
  513. var exp = objList.GetExp<StoreHouseLocation>();
  514. query = query.Where(exp);
  515. }
  516. var totalCount = await query.CountAsync();
  517. query = query.OrderByDescending(i => i.CreationTime);
  518. query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
  519. var entities = await query.ToListAsync();
  520. var dtos = new PagedResultDto<StoreHouseLocationDto>(
  521. totalCount,
  522. entities.Select(ObjectMapper.Map<StoreHouseLocationDto>).ToList()
  523. );
  524. return dtos;
  525. }
  526. /// <summary>
  527. /// 根据订单号查询当前客户默认的产品
  528. /// </summary>
  529. /// <param name="orderNo"></param>
  530. /// <returns></returns>
  531. public string GetDefualtProductByOrderNo(string orderNo)
  532. {
  533. var orderHeader = OrderHeaderRepository.Get(orderNo);
  534. return GetDefualtProductByCustomerId(orderHeader.CustomerId);
  535. }
  536. /// <summary>
  537. /// 根据订单号和零件号查询当前客户默认的产品
  538. /// </summary>
  539. /// <param name="partNo"></param>
  540. /// <param name="orderNo"></param>
  541. /// <returns></returns>
  542. public string GetDefaultProductByPartNo(string partNo,string orderNo)
  543. {
  544. var orderHeader = OrderHeaderRepository.Get(orderNo);
  545. var defaultProduct = CustomerDefaultProductRepository.FirstOrDefault(i => i.CustomerId == orderHeader.CustomerId&&i.PartNo== partNo);
  546. if (defaultProduct != null)
  547. {
  548. return defaultProduct.ProductNo;
  549. }
  550. return "";
  551. }
  552. /// <summary>
  553. /// 根据订单号和客户编码查询当前客户默认的产品
  554. /// </summary>
  555. /// <param name="partNo"></param>
  556. /// <param name="customerId"></param>
  557. /// <returns></returns>
  558. public string QueryProductByCustomerAndPartNo(string partNo, string customerId)
  559. {
  560. var defaultProduct = CustomerDefaultProductRepository.FirstOrDefault(i => i.CustomerId == customerId && i.PartNo == partNo);
  561. if (defaultProduct != null)
  562. {
  563. return defaultProduct.ProductNo;
  564. }
  565. return "";
  566. }
  567. /// <summary>
  568. /// 根据客户号查询当前客户默认的产品
  569. /// </summary>
  570. /// <param name="orderNo"></param>
  571. /// <returns></returns>
  572. public string GetDefualtProductByCustomerId(string customerId)
  573. {
  574. var defualtProducts = CustomerDefaultProductRepository.GetAll().Where(i => i.CustomerId == customerId);
  575. string lcRetval = "";
  576. foreach (var item in defualtProducts)
  577. {
  578. lcRetval += $"<option value=\"{item.ProductNo}\">{item.ProductNo}</option>";
  579. }
  580. return lcRetval;
  581. }
  582. public Customer GetCustomerInfo(EntityDto<string> input)
  583. {
  584. return CustomerRepository.FirstOrDefault(input.Id);
  585. }
  586. public CustomerSend GetCustomerSendInfo(EntityDto<int> input)
  587. {
  588. return CustomerSendRepository.FirstOrDefault(input.Id);
  589. }
  590. [DisableAuditing]
  591. public List<SelectListItem> GetProductPropertyList(string pcPropertyName)
  592. {
  593. var objList = new List<SelectListItem>();
  594. if (pcPropertyName.IsNullOrEmpty())
  595. {
  596. return objList;
  597. }
  598. var entitys = ProductRepository.GetAll().Where(i => i.IsLock == "N");
  599. var loPropertyInfo = typeof(Product).GetProperty(pcPropertyName,
  600. BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.Public);
  601. if (loPropertyInfo == null)
  602. {
  603. throw new ArgumentException($"{pcPropertyName} is not a property of type {typeof(Product)}.");
  604. }
  605. IQueryable<string> query = null;
  606. switch (pcPropertyName)
  607. {
  608. case "Material":
  609. query = entitys.Select(i => i.Material).Distinct();
  610. break;
  611. case "SurfaceColor":
  612. query = entitys.Select(i => i.SurfaceColor).Distinct();
  613. break;
  614. case "Rigidity":
  615. query = entitys.Select(i => i.Rigidity).Distinct();
  616. break;
  617. }
  618. if (query != null)
  619. {
  620. foreach (var product in query)
  621. {
  622. objList.Add(new SelectListItem()
  623. {
  624. Text = product,
  625. Value = product
  626. });
  627. }
  628. }
  629. return objList;
  630. }
  631. #region 库存记录查询
  632. public List<CurrentProductStoreHouse> QueryStore(string productNo)
  633. {
  634. if (string.IsNullOrEmpty(productNo))
  635. {
  636. CheckErrors(IwbIdentityResult.Failed("请求的产品编码不存在!"));
  637. }
  638. var entity = CurrentProductStoreHouseRepository.GetAll().Where(i => i.ProductNo == productNo && (i.Quantity > 0||i.ProductionOrderNo.StartsWith("VS"))).OrderByDescending(i => i.TimeLastMod);
  639. List<CurrentProductStoreHouse> productionOrder = new List<CurrentProductStoreHouse>();
  640. List<CurrentProductStoreHouse> hasProductionOrder = new List<CurrentProductStoreHouse>();
  641. if (entity.Any())
  642. {
  643. productionOrder = entity.Where(i => string.IsNullOrEmpty(i.ProductionOrderNo)).ToList();
  644. hasProductionOrder = entity.Where(i => !string.IsNullOrEmpty(i.ProductionOrderNo)).ToList();
  645. }
  646. productionOrder.AddRange(hasProductionOrder);
  647. return productionOrder;
  648. }
  649. public List<CurrentProductStoreHouse> QueryStoreFilter(string productNo,string customerId)
  650. {
  651. if (string.IsNullOrEmpty(productNo))
  652. {
  653. CheckErrors(IwbIdentityResult.Failed("请求的产品编码不存在!"));
  654. }
  655. var entity = CurrentProductStoreHouseRepository.GetAll().Where(i => i.ProductNo == productNo && (i.Quantity > 0 || i.ProductionOrderNo.StartsWith("VS"))&&i.InventoryCheckState!=2);
  656. var disabledOrderNo = CustomerDisabledProductRepository.GetAll().Where(i => i.CustomerNo == customerId)
  657. .Select(i => i.ProductOrderNo).Distinct();
  658. entity = entity.Where(i => !disabledOrderNo.Contains(i.ProductionOrderNo))
  659. .OrderByDescending(i => i.TimeLastMod);
  660. List<CurrentProductStoreHouse> productionOrder = new List<CurrentProductStoreHouse>();
  661. List<CurrentProductStoreHouse> hasProductionOrder = new List<CurrentProductStoreHouse>();
  662. if (entity.Any())
  663. {
  664. productionOrder = entity.Where(i => string.IsNullOrEmpty(i.ProductionOrderNo)&& i.Quantity>0).ToList();
  665. hasProductionOrder = entity.Where(i => !string.IsNullOrEmpty(i.ProductionOrderNo)&& i.Quantity>0).ToList();
  666. }
  667. productionOrder.AddRange(hasProductionOrder);
  668. return productionOrder;
  669. }
  670. #endregion
  671. public BulletinInfo GetBulletinInfo(EntityDto input)
  672. {
  673. var entity = BulletinInfoRepository.FirstOrDefault(i => i.Id == input.Id);
  674. return entity;
  675. }
  676. protected virtual void CheckErrors(IdentityResult identityResult)
  677. {
  678. identityResult.CheckErrors(LocalizationManager);
  679. }
  680. protected virtual void CheckErrors(String error)
  681. {
  682. var identityResult = IdentityResult.Failed(error);
  683. CheckErrors(identityResult);
  684. //identityResult.CheckErrors(LocalizationManager);
  685. }
  686. public ShortMessage GetShortMsgDetailInfo(ShortMsgDetailDto input)
  687. {
  688. var entity = ShortMessageRepository.FirstOrDefault(input.MsgID);
  689. //var detailInfo = ShortMsgDetailRepository.FirstOrDefault(input.Id);
  690. //detailInfo.IsRead = "Y";
  691. //ShortMsgDetailRepository.UpdateAsync(detailInfo);
  692. return entity;
  693. }
  694. public ShortMsgDetail ReadShortMsgDetailInfo(ShortMsgDetailDto input)
  695. {
  696. //var entity = ShortMessageRepository.FirstOrDefault(input.MsgID);
  697. var detailInfo = ShortMsgDetailRepository.FirstOrDefault(input.Id);
  698. detailInfo.IsRead = "Y";
  699. ShortMsgDetailRepository.UpdateAsync(detailInfo);
  700. return detailInfo;
  701. }
  702. public List<CustomerSendDto> GetCustomerSendDtoByCustomerId(CustomerSendDto customerId)
  703. {
  704. var entities = CustomerSendRepository.GetAll().Where(i => i.CustomerId == customerId.CustomerId && i.IsLock == "N");
  705. return ObjectMapper.Map<List<CustomerSendDto>>(entities.ToList());
  706. }
  707. public async Task<PagedResultDto<Product>> GetQueryCustomerDefaultProduct(IwbPagedRequestDto input)
  708. {
  709. var query = ProductRepository.GetAll();
  710. query = query.Where(i => i.IsLock == "N");
  711. string lcCustomerId = "";
  712. if (input.SearchList != null && input.SearchList.Count > 0)
  713. {
  714. List<LambdaObject> objList = new List<LambdaObject>();
  715. foreach (var o in input.SearchList)
  716. {
  717. if (o.KeyWords.IsNullOrEmpty())
  718. continue;
  719. object keyWords = o.KeyWords;
  720. if (o.KeyField == "CustomerId" || o.KeyField == "customerId")
  721. {
  722. lcCustomerId = keyWords + "";
  723. continue;
  724. }
  725. objList.Add(new LambdaObject
  726. {
  727. FieldType = (LambdaFieldType)o.FieldType,
  728. FieldName = o.KeyField,
  729. FieldValue = keyWords,
  730. ExpType = (LambdaExpType)o.ExpType
  731. });
  732. }
  733. var exp = objList.GetExp<Product>();
  734. if (exp != null)
  735. {
  736. query = query.Where(exp);
  737. }
  738. }
  739. List<string> loNotContain = new List<string>();
  740. if (!lcCustomerId.IsNullOrEmpty())
  741. {
  742. var loDefualtProducts = CustomerDefaultProductRepository.GetAll().Where(i => i.CustomerId == lcCustomerId);
  743. foreach (CustomerDefaultProduct defaultProduct in loDefualtProducts)
  744. {
  745. loNotContain.Add(defaultProduct.ProductNo);
  746. }
  747. }
  748. if (loNotContain.Any())
  749. {
  750. query = query.Where(i => !loNotContain.Contains(i.Id));
  751. }
  752. var totalCount = query.Count();
  753. query = query.SortBy("Id");
  754. query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
  755. var entities = query.ToList();
  756. var dtos = new PagedResultDto<Product>(
  757. totalCount,
  758. entities
  759. );
  760. return dtos;
  761. }
  762. public async Task<PagedResultDto<ProductionLogDto>> QueryProductionLog(IwbPagedRequestDto input)
  763. {
  764. var query = ProductionLogRepository.GetAllIncluding(a=>a.EmployeeInfo);
  765. query = ApplyFilter<ProductionLog>(query,input);
  766. var totalCount = await AsyncQueryableExecuter.CountAsync(query);
  767. query = query.OrderBy(a=>a.CreationTime);
  768. query = _ApplyPaging(query, input);
  769. var entities = await AsyncQueryableExecuter.ToListAsync(query);
  770. var dtoList = new PagedResultDto<ProductionLogDto>(totalCount, entities.Select(a=>new ProductionLogDto
  771. {
  772. Id = a.Id,
  773. ProductionNo = a.ProductionNo,
  774. ProductOrderNo = a.ProductOrderNo,
  775. EmployeeId = a.EmployeeId,
  776. EmployeeNo = a.EmployeeInfo.No,
  777. EmployeeName = a.EmployeeInfo.Name,
  778. CarNo = a.CarNo,
  779. QuantityWeight = a.QuantityWeight,
  780. QuantityPcs = a.QuantityPcs,
  781. KgWeight = a.KgWeight,
  782. CreationTime = a.CreationTime
  783. }).ToList());
  784. return dtoList;
  785. }
  786. public List<StoreHouse> QueryStoreHouse(int houseType=0)
  787. {
  788. /*List<StoreHouse> result = CacheManager.GetCache(ShwasherConsts.StoreHouseCache).Get("All",
  789. () => { return StoreHouseRepository.GetAllList(i => i.IsLock == "N"); });*/
  790. var query = StoreHouseRepository.GetAll().Where(i => i.IsLock == "N" );
  791. if (houseType > 0)
  792. {
  793. query = query.Where(i => i.StoreHouseTypeId == houseType);
  794. }
  795. return query.ToList();
  796. }
  797. public List<SelectListItem> QueryStoreHouseSelect(int houseType=0)
  798. {
  799. var query = StoreHouseRepository.GetAll().Where(i => i.IsLock == "N");
  800. if (houseType > 0)
  801. {
  802. query = query.Where(i => i.StoreHouseTypeId == houseType);
  803. }
  804. List<SelectListItem> resultList = new List<SelectListItem>()
  805. {
  806. new SelectListItem()
  807. {
  808. Text = @"请选择仓库...",
  809. Value = "",
  810. Selected = true
  811. }
  812. };
  813. foreach (var entityHouse in query)
  814. {
  815. SelectListItem item = new SelectListItem()
  816. {
  817. Text = entityHouse.StoreHouseName,
  818. Value = entityHouse.Id.ToString()
  819. };
  820. resultList.Add(item);
  821. }
  822. return resultList;
  823. }
  824. public string QueryStoreHouseSelectStr(int houseType=0)
  825. {
  826. var query = StoreHouseRepository.GetAll().Where(i => i.IsLock == "N");
  827. if (houseType > 0)
  828. {
  829. query = query.Where(i => i.StoreHouseTypeId == houseType);
  830. }
  831. string str = "";// "<option data-type=\"\" value=\"\">请选择仓库...</option>";
  832. foreach (var l in query)
  833. {
  834. str += $"<option data-type=\"{l.StoreHouseTypeId}\" value=\"{l.Id}\">{l.StoreHouseName}</option>";
  835. }
  836. return str;
  837. }
  838. public List<ViewSemiEnterStore> QueryEnterStoresByPoNo(string productionOrderNo)
  839. {
  840. var entities = ViewSemiEnterStoreRepository.GetAllList(i => i.ProductionOrderNo == productionOrderNo);
  841. return entities;
  842. }
  843. public async Task<TemplateInfo> QueryTemplate(string tmpKey, int type)
  844. {
  845. var tmps =await TemplateInfoRepository.FirstOrDefaultAsync(i => i.TempKey == tmpKey && i.Type == type);
  846. return tmps;
  847. }
  848. public async Task<List<Currency>> QueryAllCurrency()
  849. {
  850. return await CurrencyRepository.GetAllListAsync();
  851. }
  852. public async Task<List<CurrencyExchangeRate>> QueryCurrencyRate(string from="", string to="")
  853. {
  854. if (from.IsNullOrEmpty()&&!to.IsNullOrEmpty())
  855. {
  856. return await CurrencyExchangeRateRepository.GetAllListAsync(i => i.ToCurrencyId == to);
  857. }
  858. else if (!from.IsNullOrEmpty() && to.IsNullOrEmpty())
  859. {
  860. return await CurrencyExchangeRateRepository.GetAllListAsync(i => i.FromCurrencyId == from );
  861. }
  862. else
  863. {
  864. return await CurrencyExchangeRateRepository.GetAllListAsync(i => i.FromCurrencyId == from && i.ToCurrencyId == to);
  865. }
  866. }
  867. public PagedResultDto<ViewEmployee> QueryEmployee(IwbPagedRequestDto input)
  868. {
  869. var query = ViewEmployeeRepository.GetAll();
  870. if (input.SearchList != null && input.SearchList.Count > 0)
  871. {
  872. List<LambdaObject> objList = new List<LambdaObject>();
  873. foreach (var o in input.SearchList)
  874. {
  875. if (o.KeyWords.IsNullOrEmpty())
  876. continue;
  877. object keyWords = o.KeyWords;
  878. objList.Add(new LambdaObject
  879. {
  880. FieldType = (LambdaFieldType)o.FieldType,
  881. FieldName = o.KeyField,
  882. FieldValue = keyWords,
  883. ExpType = (LambdaExpType)o.ExpType
  884. });
  885. }
  886. var exp = objList.GetExp<ViewEmployee>();
  887. if (exp != null)
  888. {
  889. query = query.Where(exp);
  890. }
  891. }
  892. var totalCount = query.Count();
  893. query = query.SortBy("No");
  894. query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
  895. var entities = query.ToList();
  896. var dtos = new PagedResultDto<ViewEmployee>(
  897. totalCount,
  898. entities
  899. );
  900. return dtos;
  901. }
  902. /// <summary>
  903. /// 查询模具信息
  904. /// </summary>
  905. /// <param name="input"></param>
  906. /// <returns></returns>
  907. public async Task<PagedResultDto<MoldDto>> QueryMold(IwbPagedRequestDto input)
  908. {
  909. var query = MoldRepository.GetAll();
  910. query = ApplyFilter(query,input);
  911. var totalCount = await AsyncQueryableExecuter.CountAsync(query);
  912. query = _ApplySorting(query, input);
  913. query = _ApplyPaging(query, input);
  914. var entities = await AsyncQueryableExecuter.ToListAsync(query);
  915. var dtoList = new PagedResultDto<MoldDto>(totalCount, entities.Select(ObjectMapper.Map<MoldDto>).ToList());
  916. return dtoList;
  917. }
  918. /// <summary>
  919. /// 查询模具信息
  920. /// </summary>
  921. /// <param name="input"></param>
  922. /// <returns></returns>
  923. public async Task<PagedResultDto<FixedAssetDto>> QueryFixedAsset(IwbPagedRequestDto input)
  924. {
  925. var query = FixedAssetRepository.GetAll();
  926. query = ApplyFilter(query,input);
  927. var totalCount = await AsyncQueryableExecuter.CountAsync(query);
  928. query = _ApplySorting(query, input);
  929. query = _ApplyPaging(query, input);
  930. var entities = await AsyncQueryableExecuter.ToListAsync(query);
  931. var dtoList = new PagedResultDto<FixedAssetDto>(totalCount, entities.Select(ObjectMapper.Map<FixedAssetDto>).ToList());
  932. return dtoList;
  933. }
  934. /// <summary>
  935. /// 查询发货明细信息
  936. /// </summary>
  937. /// <param name="input"></param>
  938. /// <returns></returns>
  939. public async Task<PagedResultDto<ViewOrderSend>> QuerySendGood(IwbPagedRequestDto input)
  940. {
  941. var query = ViewOrderSendRepository.GetAll().Where(a=>!string.IsNullOrEmpty(a.OrderSendBillNo));
  942. query = ApplyFilter(query,input);
  943. var totalCount = await AsyncQueryableExecuter.CountAsync(query);
  944. query = query.OrderByDescending(a=>a.OrderItemId);
  945. query = _ApplyPaging(query, input);
  946. var entities = await AsyncQueryableExecuter.ToListAsync(query);
  947. var dtoList = new PagedResultDto<ViewOrderSend>(totalCount, entities);
  948. return dtoList;
  949. }
  950. protected IRepository<ViewStickBill, string> ViewStickBillRepository { get; }
  951. /// <summary>
  952. /// 查询发票信息
  953. /// </summary>
  954. /// <param name="input"></param>
  955. /// <returns></returns>
  956. public async Task<PagedResultDto<ViewStickBill>> QueryInvoice(IwbPagedRequestDto input)
  957. {
  958. var query = ViewStickBillRepository.GetAll();
  959. query = ApplyFilter(query,input);
  960. var totalCount = await AsyncQueryableExecuter.CountAsync(query);
  961. query = query.OrderByDescending(a=>a.TimeCreated);
  962. query = _ApplyPaging(query, input);
  963. var entities = await AsyncQueryableExecuter.ToListAsync(query);
  964. var dtoList = new PagedResultDto<ViewStickBill>(totalCount, entities);
  965. return dtoList;
  966. }
  967. public async Task<PagedResultDto<RmProduct>> GetRmProduct(IwbPagedRequestDto input)
  968. {
  969. var query = RmRepository.GetAll();
  970. query = ApplyFilter<RmProduct>(query,input);
  971. var totalCount = await AsyncQueryableExecuter.CountAsync(query);
  972. query = _ApplySorting(query, input);
  973. query = _ApplyPaging(query, input);
  974. var entities = await AsyncQueryableExecuter.ToListAsync(query);
  975. var dtoList = new PagedResultDto<RmProduct>(totalCount, entities);
  976. return dtoList;
  977. }
  978. public async Task<PagedResultDto<ViewCurrentRmStoreHouse>> GetRmCurrentStore(IwbPagedRequestDto input)
  979. {
  980. var query = ViewCurrentRmStoreHouseRepository.GetAll();
  981. query = ApplyFilter<ViewCurrentRmStoreHouse>(query, input);
  982. var totalCount = await AsyncQueryableExecuter.CountAsync(query);
  983. query = _ApplySorting(query, input);
  984. query = _ApplyPaging(query, input);
  985. var entities = await AsyncQueryableExecuter.ToListAsync(query);
  986. var dtoList = new PagedResultDto<ViewCurrentRmStoreHouse>(totalCount, entities);
  987. return dtoList;
  988. }
  989. public async Task<PagedResultDto<ViewSemiEnterStore>> GetSemiEnterStoreCheckUnqualified(IwbPagedRequestDto input)
  990. {
  991. var checkState = EnterStoreApplyStatusEnum.UnChecked.ToInt() + "";
  992. var query = ViewSemiEnterStoreRepository.GetAll().Where(a => a.ApplyStatus == checkState);
  993. query = ApplyFilter<ViewSemiEnterStore>(query, input);
  994. var totalCount = query.Count();
  995. query = query.OrderByDescending(i => i.TimeCreated);
  996. query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
  997. var entities = await AsyncQueryableExecuter.ToListAsync(query);
  998. var dots = new PagedResultDto<ViewSemiEnterStore>(
  999. totalCount, entities
  1000. );
  1001. return dots;
  1002. }
  1003. /// <summary>
  1004. /// 查询产品属性
  1005. /// </summary>
  1006. /// <param name="input"></param>
  1007. /// <returns></returns>
  1008. public async Task<PagedResultDto<ProductPropertyDto>> GetProductProperty(IwbPagedRequestDto input)
  1009. {
  1010. var query = ProductPropertyRepository.GetAll();
  1011. query = ApplyFilter(query, input);
  1012. var totalCount = await AsyncQueryableExecuter.CountAsync(query);
  1013. query = _ApplySorting(query, input);
  1014. query = _ApplyPaging(query, input);
  1015. var entities = await AsyncQueryableExecuter.ToListAsync(query);
  1016. var dtoList = new PagedResultDto<ProductPropertyDto>(totalCount, entities.Select(ObjectMapper.Map<ProductPropertyDto>).ToList());
  1017. return dtoList;
  1018. }
  1019. /// <summary>
  1020. /// 查询订单明细信息
  1021. /// </summary>
  1022. /// <param name="input"></param>
  1023. /// <returns></returns>
  1024. public async Task<PagedResultDto<ViewOrderItems>> QueryOrderItem(IwbPagedRequestDto input)
  1025. {
  1026. var query = ViewOrderItemsRepository.GetAll();
  1027. query = ApplyFilter(query, input);
  1028. var totalCount = await AsyncQueryableExecuter.CountAsync(query);
  1029. query = query.OrderByDescending(a => a.SendDate);
  1030. string pattern = ProductModelSearch.GetModelGreaterOneReg(input.SearchList);
  1031. List<ViewOrderItems> entities;
  1032. //检查查询条件中带有规格且多个分割条件的
  1033. if (!pattern.IsNullOrEmpty())
  1034. {
  1035. var es = query.ToList();
  1036. es = es.Where(f => f.Model != null && Regex.IsMatch(f.Model, pattern)).ToList();
  1037. totalCount = es.Count;
  1038. entities = es.Skip(input.SkipCount).Take(input.MaxResultCount).ToList();
  1039. }
  1040. else
  1041. {
  1042. query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
  1043. entities = await AsyncQueryableExecuter.ToListAsync(query);
  1044. }
  1045. //query = _ApplyPaging(query, input);
  1046. //var entities = await AsyncQueryableExecuter.ToListAsync(query);
  1047. var dtoList = new PagedResultDto<ViewOrderItems>(totalCount, entities);
  1048. return dtoList;
  1049. }
  1050. public async Task<OrderProductProcessDto> QueryOrderProductProcess(int orderItemId)
  1051. {
  1052. OrderProductProcessDto result = new OrderProductProcessDto();
  1053. var rs = OrderProductionRepository.GetAllList(i => i.OrderItemId == orderItemId);
  1054. if (rs.Any())
  1055. {
  1056. var productionNoArr = rs.Select(i => i.ProductionOrderNo);
  1057. List<PackageApply> pas =
  1058. await PackageApplyRepository.GetAllListAsync(i => productionNoArr.Contains(i.ProductionOrderNo));
  1059. List<ProductionOrder> pos = await ProductionOrderRepository.GetAllListAsync(i => productionNoArr.Contains(i.ProductionOrderNo));
  1060. result.PackageApplyList = pas;
  1061. result.ProductionOrderList = pos;
  1062. }
  1063. return result;
  1064. }
  1065. protected IQueryable<T> ApplyFilter<T>(IQueryable<T> query, IwbPagedRequestDto input)
  1066. {
  1067. var pagedInput = input as IIwbPagedRequest;
  1068. if (pagedInput == null)
  1069. {
  1070. return query;
  1071. }
  1072. if (!string.IsNullOrEmpty(pagedInput.KeyWords))
  1073. {
  1074. object keyWords = pagedInput.KeyWords;
  1075. LambdaObject obj = new LambdaObject()
  1076. {
  1077. FieldType = (LambdaFieldType)pagedInput.FieldType,
  1078. FieldName = pagedInput.KeyField,
  1079. FieldValue = keyWords,
  1080. ExpType = (LambdaExpType)pagedInput.ExpType
  1081. };
  1082. var exp = obj.GetExp<T>();
  1083. query = exp != null ? query.Where(exp) : query;
  1084. }
  1085. if (pagedInput.SearchList != null && pagedInput.SearchList.Count > 0)
  1086. {
  1087. List<LambdaObject> objList = new List<LambdaObject>();
  1088. foreach (var o in pagedInput.SearchList)
  1089. {
  1090. if (string.IsNullOrEmpty(o.KeyWords))
  1091. continue;
  1092. object keyWords = o.KeyWords;
  1093. //检查查询条件中带有规格且多个分割条件的
  1094. ProductModelSearch.CheckModelGreaterOneFilter(o, ref keyWords);
  1095. objList.Add(new LambdaObject
  1096. {
  1097. FieldType = (LambdaFieldType)o.FieldType,
  1098. FieldName = o.KeyField,
  1099. FieldValue = keyWords,
  1100. ExpType = (LambdaExpType)o.ExpType
  1101. });
  1102. }
  1103. var exp = objList.GetExp<T>();
  1104. query = exp != null ? query.Where(exp) : query;
  1105. }
  1106. return query;
  1107. }
  1108. /// <summary>
  1109. /// 分页
  1110. /// </summary>
  1111. /// <param name="query">The query.</param>
  1112. /// <param name="input">The input.</param>
  1113. protected IQueryable<T> _ApplyPaging<T>(IQueryable<T> query, IwbPagedRequestDto input)
  1114. {
  1115. //Try to use paging if available
  1116. var pagedInput = input as IPagedResultRequest;
  1117. if (pagedInput != null)
  1118. {
  1119. return query.PageBy(pagedInput);
  1120. }
  1121. //Try to limit query result if available
  1122. var limitedInput = input as ILimitedResultRequest;
  1123. if (limitedInput != null)
  1124. {
  1125. return query.Take(limitedInput.MaxResultCount);
  1126. }
  1127. //No paging
  1128. return query;
  1129. }
  1130. /// <summary>
  1131. /// 排序
  1132. /// </summary>
  1133. /// <param name="query">The query.</param>
  1134. /// <param name="input">The input.</param>
  1135. protected IQueryable<T> _ApplySorting<T>(IQueryable<T> query, IwbPagedRequestDto input)
  1136. {
  1137. //Try to sort query if available
  1138. var sortInput = input as ISortedResultRequest;
  1139. if (sortInput != null)
  1140. {
  1141. if (!sortInput.Sorting.IsNullOrWhiteSpace())
  1142. {
  1143. return query.OrderBy(sortInput.Sorting);
  1144. }
  1145. }
  1146. //IQueryable.Task requires sorting, so we should sort if Take will be used.
  1147. if (input is ILimitedResultRequest)
  1148. {
  1149. return query.OrderBy("CreationTime DESC");
  1150. }
  1151. //No sorting
  1152. return query;
  1153. }
  1154. public async Task<string> CalcTaxPrice(int type, string input,string rate)
  1155. {
  1156. decimal result = 0;
  1157. try
  1158. {
  1159. decimal inputDec = Convert.ToDecimal(input);
  1160. decimal rateDec = Convert.ToDecimal(rate);
  1161. switch (type)
  1162. {
  1163. case 1:
  1164. result = inputDec / (1 + (rateDec / 100));
  1165. break;
  1166. case 2:
  1167. result = inputDec * (1 + (rateDec / 100));
  1168. break;
  1169. }
  1170. }
  1171. catch (Exception e)
  1172. {
  1173. result = 0;
  1174. }
  1175. return Convert.ToDouble(result).ToString("f3");
  1176. }
  1177. #region 2023
  1178. private void GetPropertiesNo(List<MultiSearchDto> searchList,ref string modelNo, ref string materialNo, ref string rigidityNo, ref string surfaceColorNo)
  1179. {
  1180. foreach (var o in searchList)
  1181. {
  1182. if (o.KeyWords.IsNullOrEmpty())
  1183. continue;
  1184. object keyWords = o.KeyWords;
  1185. if (o.KeyField?.ToLower() == "modelno")
  1186. {
  1187. modelNo = keyWords.ToString();
  1188. }
  1189. if (o.KeyField?.ToLower() == "materialno")
  1190. {
  1191. materialNo = keyWords.ToString();
  1192. }
  1193. if (o.KeyField?.ToLower() == "rigidityno")
  1194. {
  1195. rigidityNo = keyWords.ToString();
  1196. }
  1197. if (o.KeyField?.ToLower() == "surfacecolorno")
  1198. {
  1199. surfaceColorNo = keyWords.ToString();
  1200. }
  1201. }
  1202. }
  1203. public async Task<PagedResultDto<ProductionOrderDto>> QueryProductionOrderDtoByProNo(PagedRequestDto input)
  1204. {
  1205. var query = ProductionOrderRepository.GetAll();
  1206. var result = from u in query
  1207. join s in SemiProductRepository.GetAll() on u.SemiProductNo equals s.Id into l
  1208. from luq in l.DefaultIfEmpty()
  1209. select new ProductionOrderDto
  1210. {
  1211. Model = luq.Model ?? "",
  1212. CarNo = u.CarNo,
  1213. EnterQuantity = u.EnterQuantity,
  1214. Id = u.Id,
  1215. ProductionType = u.ProductionType,
  1216. OutsourcingFactory = u.OutsourcingFactory,
  1217. CreatorUserId = u.CreatorUserId,
  1218. IsChecked = u.IsChecked,
  1219. IsLock = u.IsLock,
  1220. Material = luq.Material ?? "",
  1221. PartNo = luq.PartNo ?? "",
  1222. PlanProduceDate = u.PlanProduceDate,
  1223. RawMaterials = u.RawMaterials,
  1224. SurfaceColor = luq.SurfaceColor ?? "",
  1225. Rigidity = luq.Rigidity ?? "",
  1226. Remark = u.Remark,
  1227. UserIDLastMod = u.UserIDLastMod,
  1228. TimeCreated = u.TimeCreated,
  1229. TimeLastMod = u.TimeLastMod,
  1230. Size = u.Size,
  1231. ProcessingType = u.ProcessingType,
  1232. ProcessingLevel = u.ProcessingLevel,
  1233. SourceProductionOrderNo = u.SourceProductionOrderNo,
  1234. StoveNo = u.StoveNo,
  1235. Quantity = u.Quantity,
  1236. ProductionOrderNo = u.ProductionOrderNo,
  1237. ProductionOrderStatus = u.ProductionOrderStatus,
  1238. SemiProductNo = u.SemiProductNo,
  1239. SemiProductName = luq.SemiProductName,
  1240. KgWeight = u.KgWeight,
  1241. EnterDate = u.EnterDate,
  1242. InspectDate = u.InspectDate,
  1243. HasExported = u.HasExported
  1244. };
  1245. var endState = ProductionOrderStatusEnum.End.ToInt();
  1246. result = result.Where(a => (a.ProductionOrderStatus != endState));
  1247. var searchList = input.SearchList;
  1248. if (searchList != null && searchList.Count > 0)
  1249. {
  1250. //List<LambdaObject> objList = new List<LambdaObject>();
  1251. string modelNo = "", materialNo = "", rigidityNo = "", surfaceColorNo = "";
  1252. GetPropertiesNo(searchList,ref modelNo, ref materialNo, ref rigidityNo, ref surfaceColorNo);
  1253. if (modelNo.IsNullOrEmpty())
  1254. {
  1255. CheckErrors("规格不能为空!");
  1256. }
  1257. //111,110,100,000
  1258. if ((materialNo.IsNullOrEmpty() && rigidityNo.IsNullOrEmpty() && surfaceColorNo.IsNullOrEmpty())||(!materialNo.IsNullOrEmpty() && !rigidityNo.IsNullOrEmpty() && !surfaceColorNo.IsNullOrEmpty())|| (!materialNo.IsNullOrEmpty() && !rigidityNo.IsNullOrEmpty() && surfaceColorNo.IsNullOrEmpty()) || (!materialNo.IsNullOrEmpty() && rigidityNo.IsNullOrEmpty() && surfaceColorNo.IsNullOrEmpty()))
  1259. {
  1260. result = result.Where(i => i.SemiProductNo.StartsWith("s" + modelNo + materialNo + rigidityNo + surfaceColorNo));
  1261. }//101,001,011
  1262. else if((!materialNo.IsNullOrEmpty() && rigidityNo.IsNullOrEmpty() && !surfaceColorNo.IsNullOrEmpty()) || (materialNo.IsNullOrEmpty() && rigidityNo.IsNullOrEmpty() && !surfaceColorNo.IsNullOrEmpty()) || (materialNo.IsNullOrEmpty() && !rigidityNo.IsNullOrEmpty() && !surfaceColorNo.IsNullOrEmpty()))
  1263. {
  1264. result = result.Where(i => i.SemiProductNo.StartsWith("s" + modelNo + materialNo) && i.SemiProductNo.Contains(rigidityNo + surfaceColorNo));
  1265. }//010
  1266. else if (materialNo.IsNullOrEmpty() && !rigidityNo.IsNullOrEmpty() && surfaceColorNo.IsNullOrEmpty())
  1267. {
  1268. result = result.Where(i => i.SemiProductNo.StartsWith("s" + modelNo));
  1269. result = result.Where(i => i.SemiProductNo.Contains( rigidityNo));
  1270. }
  1271. }
  1272. var totalCount = await AsyncQueryableExecuter.CountAsync(result);
  1273. result = result.OrderByDescending(i => i.TimeCreated);
  1274. result = result.Skip(input.SkipCount).Take(input.MaxResultCount);
  1275. var dtos = new PagedResultDto<ProductionOrderDto>(
  1276. totalCount,
  1277. result.ToList()
  1278. );
  1279. return dtos;
  1280. }
  1281. public async Task<PagedResultDto<ViewCurrentProductStoreHouse>> QueryViewCurrentProductStoreHouseByProNo(PagedRequestDto input)
  1282. {
  1283. var query = ViewCurrentProductStoreHouseRepository.GetAll();
  1284. var searchList = input.SearchList;
  1285. if (searchList != null && searchList.Count > 0)
  1286. {
  1287. //List<LambdaObject> objList = new List<LambdaObject>();
  1288. //foreach (var o in searchList)
  1289. //{
  1290. // if (o.KeyWords.IsNullOrEmpty())
  1291. // continue;
  1292. // object keyWords = o.KeyWords;
  1293. // if (o.KeyField?.ToLower() == "productno")
  1294. // {
  1295. // query = query.Where(a => a.ProductNo.StartsWith(o.KeyWords));
  1296. // }
  1297. //}
  1298. string modelNo = "", materialNo = "", rigidityNo = "", surfaceColorNo = "";
  1299. GetPropertiesNo(searchList, ref modelNo, ref materialNo, ref rigidityNo, ref surfaceColorNo);
  1300. if (modelNo.IsNullOrEmpty())
  1301. {
  1302. CheckErrors("规格不能为空!");
  1303. }
  1304. //111,110,100,000
  1305. if ((materialNo.IsNullOrEmpty() && rigidityNo.IsNullOrEmpty() && surfaceColorNo.IsNullOrEmpty()) || (!materialNo.IsNullOrEmpty() && !rigidityNo.IsNullOrEmpty() && !surfaceColorNo.IsNullOrEmpty()) || (!materialNo.IsNullOrEmpty() && !rigidityNo.IsNullOrEmpty() && surfaceColorNo.IsNullOrEmpty()) || (!materialNo.IsNullOrEmpty() && rigidityNo.IsNullOrEmpty() && surfaceColorNo.IsNullOrEmpty()))
  1306. {
  1307. query = query.Where(i => i.ProductNo.StartsWith("s" + modelNo + materialNo + rigidityNo + surfaceColorNo));
  1308. }//101,001,011
  1309. else if ((!materialNo.IsNullOrEmpty() && rigidityNo.IsNullOrEmpty() && !surfaceColorNo.IsNullOrEmpty()) || (materialNo.IsNullOrEmpty() && rigidityNo.IsNullOrEmpty() && !surfaceColorNo.IsNullOrEmpty()) || (materialNo.IsNullOrEmpty() && !rigidityNo.IsNullOrEmpty() && !surfaceColorNo.IsNullOrEmpty()))
  1310. {
  1311. query = query.Where(i => i.ProductNo.StartsWith("s" + modelNo + materialNo) && i.ProductNo.Contains(rigidityNo + surfaceColorNo));
  1312. //query = query.Where(i => i.ProductNo.EndsWith(rigidityNo + surfaceColorNo));
  1313. }//010
  1314. else if (materialNo.IsNullOrEmpty() && !rigidityNo.IsNullOrEmpty() && surfaceColorNo.IsNullOrEmpty())
  1315. {
  1316. query = query.Where(i => i.ProductNo.StartsWith("s" + modelNo));
  1317. query = query.Where(i => i.ProductNo.Contains(rigidityNo));
  1318. }
  1319. }
  1320. query = query.Where(i => i.ActualQuantity > 0);
  1321. var totalCount = await AsyncQueryableExecuter.CountAsync(query);
  1322. query = query.OrderByDescending(i => i.TimeCreated);
  1323. query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
  1324. var dtos = new PagedResultDto<ViewCurrentProductStoreHouse>(
  1325. totalCount,
  1326. query.ToList()
  1327. );
  1328. return dtos;
  1329. }
  1330. public async Task<PagedResultDto<ViewCurrentSemiStoreHouse>> QueryViewCurrentSemiStoreHouseByProNo(PagedRequestDto input)
  1331. {
  1332. var query = ViewCurrentSemiStoreHouseRepository.GetAll();
  1333. var searchList = input.SearchList;
  1334. if (searchList != null && searchList.Count > 0)
  1335. {
  1336. //List<LambdaObject> objList = new List<LambdaObject>();
  1337. //foreach (var o in searchList)
  1338. //{
  1339. // if (o.KeyWords.IsNullOrEmpty())
  1340. // continue;
  1341. // object keyWords = o.KeyWords;
  1342. // if (o.KeyField?.ToLower() == "productno")
  1343. // {
  1344. // query = query.Where(a => a.SemiProductNo.StartsWith(o.KeyWords));
  1345. // }
  1346. //}
  1347. string modelNo = "", materialNo = "", rigidityNo = "", surfaceColorNo = "";
  1348. GetPropertiesNo(searchList, ref modelNo, ref materialNo, ref rigidityNo, ref surfaceColorNo);
  1349. if (modelNo.IsNullOrEmpty())
  1350. {
  1351. CheckErrors("规格不能为空!");
  1352. }
  1353. //111,110,100,000
  1354. if ((materialNo.IsNullOrEmpty() && rigidityNo.IsNullOrEmpty() && surfaceColorNo.IsNullOrEmpty()) || (!materialNo.IsNullOrEmpty() && !rigidityNo.IsNullOrEmpty() && !surfaceColorNo.IsNullOrEmpty()) || (!materialNo.IsNullOrEmpty() && !rigidityNo.IsNullOrEmpty() && surfaceColorNo.IsNullOrEmpty()) || (!materialNo.IsNullOrEmpty() && rigidityNo.IsNullOrEmpty() && surfaceColorNo.IsNullOrEmpty()))
  1355. {
  1356. query = query.Where(i => i.SemiProductNo.StartsWith("s" + modelNo + materialNo + rigidityNo + surfaceColorNo));
  1357. }//101,001,011
  1358. else if ((!materialNo.IsNullOrEmpty() && rigidityNo.IsNullOrEmpty() && !surfaceColorNo.IsNullOrEmpty()) || (materialNo.IsNullOrEmpty() && rigidityNo.IsNullOrEmpty() && !surfaceColorNo.IsNullOrEmpty()) || (materialNo.IsNullOrEmpty() && !rigidityNo.IsNullOrEmpty() && !surfaceColorNo.IsNullOrEmpty()))
  1359. {
  1360. query = query.Where(i => i.SemiProductNo.StartsWith("s" + modelNo + materialNo)&& i.SemiProductNo.Contains(rigidityNo + surfaceColorNo));
  1361. }//010
  1362. else if (materialNo.IsNullOrEmpty() && !rigidityNo.IsNullOrEmpty() && surfaceColorNo.IsNullOrEmpty())
  1363. {
  1364. query = query.Where(i => i.SemiProductNo.StartsWith("s" + modelNo));
  1365. query = query.Where(i => i.SemiProductNo.Contains(rigidityNo));
  1366. }
  1367. }
  1368. query = query.Where(i => i.ActualQuantity > 0);
  1369. var totalCount = await AsyncQueryableExecuter.CountAsync(query);
  1370. query = query.OrderByDescending(i => i.TimeCreated);
  1371. query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
  1372. var dtos = new PagedResultDto<ViewCurrentSemiStoreHouse>(
  1373. totalCount,
  1374. query.ToList()
  1375. );
  1376. return dtos;
  1377. }
  1378. #endregion
  1379. #region 2024
  1380. public async Task<Dictionary<int, List<DeviceMgPlanDto>>> QueryNeedMaintenanceMoldPlan()
  1381. {
  1382. Dictionary<int, List<DeviceMgPlanDto>> result = new Dictionary<int, List<DeviceMgPlanDto>>();
  1383. var over =await DeviceMgPlanRepository.GetAllListAsync(i=>i.PlanType==1&&i.NumberOfUsers>=i.MaintenanceCycle );
  1384. var comingSoon = await DeviceMgPlanRepository.GetAllListAsync(i => i.PlanType == 1
  1385. && i.MaintenanceCycle > i.NumberOfUsers
  1386. && ((i.MaintenanceCycle -
  1387. i.NumberOfUsers) >= 10000));
  1388. var overDtos = ObjectMapper.Map<List<DeviceMgPlanDto>>(over);
  1389. var comingsoonDtos = ObjectMapper.Map<List<DeviceMgPlanDto>>(comingSoon);
  1390. result.Add(1,overDtos);
  1391. result.Add(2, comingsoonDtos);
  1392. return result;
  1393. }
  1394. #endregion
  1395. #region 2025
  1396. /// <summary>
  1397. /// 获取客户默认的产品信息
  1398. /// </summary>
  1399. /// <param name="customerId"></param>
  1400. /// <returns></returns>
  1401. public async Task<List<CustomerDefaultProduct>> GetCustomerDefaultProductByCustomerId(string customerId)
  1402. {
  1403. var allListAsync = await CustomerDefaultProductRepository.GetAllListAsync(i=>i.CustomerId == customerId);
  1404. return allListAsync;
  1405. }
  1406. /// <summary>
  1407. /// 获取产品属性
  1408. /// </summary>
  1409. /// <param name="productPropertyType"></param>
  1410. /// <returns></returns>
  1411. public async Task<List<ProductProperty>> GetProductPropertyEntity(string productPropertyType)
  1412. {
  1413. var types = new string[]{"1","2","3","4","5"};
  1414. if (productPropertyType == "" || !types.Contains(productPropertyType))
  1415. {
  1416. return await ProductPropertyRepository.GetAllListAsync();
  1417. }
  1418. return await ProductPropertyRepository.GetAllListAsync(i=>i.PropertyType == productPropertyType);
  1419. }
  1420. /// <summary>
  1421. /// 获取库存信息根据库存编号
  1422. /// </summary>
  1423. /// <param name="currentProductionOrderNos"></param>
  1424. /// <returns></returns>
  1425. public async Task<List<CurrentProductStoreHouse>> GetCurrentProductStoreHouseByNo(List<string> currentProductionOrderNos)
  1426. {
  1427. var allRecords =
  1428. await CurrentProductStoreHouseRepository.GetAllListAsync(i => currentProductionOrderNos.Contains(i.CurrentProductStoreHouseNo));
  1429. // 根据 ProductionOrderNo 分组
  1430. if (allRecords.Count == 0)
  1431. {
  1432. return new List<CurrentProductStoreHouse>();
  1433. }
  1434. return allRecords;
  1435. }
  1436. #endregion
  1437. }
  1438. public class CommonQueryService
  1439. {
  1440. /// <summary>
  1441. /// 获取产品海关编码
  1442. /// </summary>
  1443. /// <param name="customerId"></param>
  1444. /// <param name="productNo"></param>
  1445. /// <param name="customerDefaultProducts"></param>
  1446. /// <returns></returns>
  1447. public static string GetProductHsCode(string customerId, string productNo,
  1448. List<CustomerDefaultProduct> customerDefaultProducts)
  1449. {
  1450. var customerDefaultProduct = customerDefaultProducts.FirstOrDefault(i => i.CustomerId == customerId && i.ProductNo == productNo);
  1451. return customerDefaultProduct == null ? "" : customerDefaultProduct.ProductHsCode;
  1452. }
  1453. /// <summary>
  1454. /// 根据产品编号获取产品HS码
  1455. /// </summary>
  1456. /// <param name="productNo"></param>
  1457. /// <param name="productProperties"></param>
  1458. /// <returns></returns>
  1459. public static string GetMaterialHsCode(string productNo,
  1460. List<ProductProperty> productProperties)
  1461. {
  1462. string materialNo = "";
  1463. //新的产品编码标准,旧编码不处理
  1464. if (productNo.StartsWith("s") && productNo.Length == 14)
  1465. {
  1466. // 提取第6到7个字符(索引5和6)
  1467. materialNo = productNo.Substring(5, 2);
  1468. }
  1469. var type = ProductProperty.ProductMaterial + "";
  1470. var property = productProperties.FirstOrDefault(i => i.PropertyType == type && i.PropertyNo == materialNo);
  1471. return property != null ? property.HsCode : "";
  1472. }
  1473. }
  1474. }