ZhongTianPtService.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. using AutoMapper;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using Wms.Screen.DataService.Impl;
  6. using Wms.Screen.DataService.Interface;
  7. using Wms.Screen.Dto.ZhongTian.Request;
  8. using Wms.Screen.Dto.ZhongTian.Response;
  9. using Wms.Screen.Dto.ZhongTian;
  10. using Wms.Screen.Service.IService;
  11. using Wms.Screen.Dto;
  12. using System.Linq;
  13. using Newtonsoft.Json;
  14. using CSRedis;
  15. using WCS.Entity.Protocol.DataStructure;
  16. using WCS.Entity.Protocol.SRM;
  17. namespace Wms.Screen.Service.Service
  18. {
  19. /// <summary>
  20. /// 盘条
  21. /// </summary>
  22. public class ZhongTianPtService : IZhongTianPtService
  23. {
  24. private IZhongTianPtDataService _zhongTianPtDataService;
  25. private IMapper _mapper;
  26. public ZhongTianPtService(IZhongTianPtDataService zhongTianPtDataService, IMapper mapper)
  27. {
  28. _zhongTianPtDataService = zhongTianPtDataService;
  29. _mapper = mapper;
  30. }
  31. public List<EquipDto> GetPtEquips(GetEquipsRequest reqEntity, FreeRedis.RedisClient freeRedisClient)
  32. {
  33. var real = new List<EquipDto>();
  34. var list = _zhongTianPtDataService.GetPtEquips(reqEntity);
  35. //var tuncount = (from tun in list.GroupBy(p => p.Tunnel)
  36. // select new TunnelCountTemp
  37. // {
  38. // Tunnel = tun.Key,
  39. // Count = tun.Count()
  40. // }).ToList();
  41. using (var db = freeRedisClient.GetDatabase(13))
  42. {
  43. var srm = db.Get<DeviceDataPack>("Pt:DeviceDataPack");
  44. if (srm != null)
  45. {
  46. foreach (var item in srm.SRMDatas?.Datas)
  47. {
  48. EquipDto equip = new EquipDto();
  49. switch (item.Code)
  50. {
  51. case "SRM1":
  52. if ((int)item.D537.Alarm > 0)
  53. {
  54. equip.EquipState = "3";
  55. }
  56. else if (item.D521.AutoStatus == SrmAutoStatus.Automatic)
  57. {
  58. equip.EquipState = "1";
  59. }
  60. else if (item.D521.AutoStatus == SrmAutoStatus.Manual || item.D521.AutoStatus == SrmAutoStatus.KeepInRepair || item.D521.AutoStatus == SrmAutoStatus.SemiAutomatic)
  61. {
  62. equip.EquipState = "2";
  63. }
  64. equip.Code = "SRM1";
  65. equip.ResidueTask = list.Where(p => p.Tunnel == "1" || p.Tunnel == "2").Count();
  66. real.Add(equip);
  67. break;
  68. case "SRM2":
  69. if ((int)item.D537.Alarm > 0)
  70. {
  71. equip.EquipState = "3";
  72. }
  73. else if (item.D521.AutoStatus == SrmAutoStatus.Automatic)
  74. {
  75. equip.EquipState = "1";
  76. }
  77. else if (item.D521.AutoStatus == SrmAutoStatus.Manual || item.D521.AutoStatus == SrmAutoStatus.KeepInRepair || item.D521.AutoStatus == SrmAutoStatus.SemiAutomatic)
  78. {
  79. equip.EquipState = "2";
  80. equip.ResidueTask = list.Where(p => p.Tunnel == "1" || p.Tunnel == "2").Count();
  81. }
  82. equip.Code = "SRM2";
  83. real.Add(equip);
  84. break;
  85. case "SRM3":
  86. if ((int)item.D537.Alarm > 0)
  87. {
  88. equip.EquipState = "3";
  89. }
  90. else if (item.D521.AutoStatus == SrmAutoStatus.Automatic)
  91. {
  92. equip.EquipState = "1";
  93. equip.ResidueTask = list.Where(p => p.Tunnel == "1" || p.Tunnel == "2").Count();
  94. }
  95. else if (item.D521.AutoStatus == SrmAutoStatus.Manual || item.D521.AutoStatus == SrmAutoStatus.KeepInRepair || item.D521.AutoStatus == SrmAutoStatus.SemiAutomatic)
  96. {
  97. equip.EquipState = "2";
  98. equip.ResidueTask = list.Where(p => p.Tunnel == "1" || p.Tunnel == "2").Count();
  99. }
  100. equip.Code = "SRM3";
  101. equip.ResidueTask = list.Where(p => p.Tunnel == "1" || p.Tunnel == "2").Count();
  102. real.Add(equip);
  103. break;
  104. case "SRM4":
  105. if ((int)item.D537.Alarm > 0)
  106. {
  107. equip.EquipState = "3";
  108. }
  109. else if (item.D521.AutoStatus == SrmAutoStatus.Automatic)
  110. {
  111. equip.EquipState = "1";
  112. }
  113. else if (item.D521.AutoStatus == SrmAutoStatus.Manual || item.D521.AutoStatus == SrmAutoStatus.KeepInRepair || item.D521.AutoStatus == SrmAutoStatus.SemiAutomatic)
  114. {
  115. equip.EquipState = "2";
  116. }
  117. equip.Code = "SRM4";
  118. equip.ResidueTask = list.Where(p => p.Tunnel == "1" || p.Tunnel == "2").Count();
  119. real.Add(equip);
  120. break;
  121. default:
  122. break;
  123. }
  124. }
  125. }
  126. }
  127. return real.OrderBy(p => p.Code).ToList();
  128. }
  129. public List<EquipDto> GetPtEquips(GetEquipsRequest reqEntity, CSRedisClient CSRedisClient)
  130. {
  131. var real = new List<EquipDto>();
  132. var list = _zhongTianPtDataService.GetPtEquips(reqEntity);
  133. //var tuncount = (from tun in list.GroupBy(p => p.Tunnel)
  134. // select new TunnelCountTemp
  135. // {
  136. // Tunnel = tun.Key,
  137. // Count = tun.Count()
  138. // }).ToList();
  139. var srm = RedisHelper.Get("Pt:SrmStatus");
  140. var msgdto = JsonConvert.DeserializeObject<List<SRMEquipDto>>(srm);
  141. foreach (var item in msgdto)
  142. {
  143. EquipDto equip = new EquipDto();
  144. switch (item.Item1)
  145. {
  146. case "SRM1":
  147. if (item.Item2 == "Automatic")
  148. {
  149. equip.EquipState = "1";
  150. equip.Code = "SRM1";
  151. equip.ResidueTask = list.Where(p => p.Tunnel == "1" || p.Tunnel == "2").Count();
  152. }
  153. else if (item.Item2 == "Manual")
  154. {
  155. equip.EquipState = "2";
  156. equip.Code = "SRM1";
  157. equip.ResidueTask = list.Where(p => p.Tunnel == "1" || p.Tunnel == "2").Count();
  158. }
  159. else
  160. {
  161. equip.EquipState = "3";
  162. equip.Code = "SRM1";
  163. equip.ResidueTask = list.Where(p => p.Tunnel == "1" || p.Tunnel == "2").Count();
  164. }
  165. real.Add(equip);
  166. break;
  167. case "SRM2":
  168. if (item.Item2 == "Automatic")
  169. {
  170. equip.EquipState = "1";
  171. equip.Code = "SRM2";
  172. equip.ResidueTask = list.Where(p => p.Tunnel == "3" || p.Tunnel == "4").Count();
  173. }
  174. else if (item.Item2 == "Manual")
  175. {
  176. equip.EquipState = "2";
  177. equip.Code = "SRM2";
  178. equip.ResidueTask = list.Where(p => p.Tunnel == "3" || p.Tunnel == "4").Count();
  179. }
  180. else
  181. {
  182. equip.EquipState = "3";
  183. equip.Code = "SRM2";
  184. equip.ResidueTask = list.Where(p => p.Tunnel == "3" || p.Tunnel == "4").Count();
  185. }
  186. real.Add(equip);
  187. break;
  188. case "SRM3":
  189. if (item.Item2 == "Automatic")
  190. {
  191. equip.EquipState = "1";
  192. equip.Code = "SRM3";
  193. equip.ResidueTask = list.Where(p => p.Tunnel == "5" || p.Tunnel == "6").Count();
  194. }
  195. else if (item.Item2 == "Manual")
  196. {
  197. equip.EquipState = "2";
  198. equip.Code = "SRM3";
  199. equip.ResidueTask = list.Where(p => p.Tunnel == "5" || p.Tunnel == "6").Count();
  200. }
  201. else
  202. {
  203. equip.EquipState = "3";
  204. equip.Code = "SRM3";
  205. equip.ResidueTask = list.Where(p => p.Tunnel == "5" || p.Tunnel == "6").Count();
  206. }
  207. real.Add(equip);
  208. break;
  209. case "SRM4":
  210. if (item.Item2 == "Automatic")
  211. {
  212. equip.EquipState = "1";
  213. equip.Code = "SRM4";
  214. equip.ResidueTask = list.Where(p => p.Tunnel == "7" || p.Tunnel == "8").Count();
  215. }
  216. else if (item.Item2 == "Manual")
  217. {
  218. equip.EquipState = "2";
  219. equip.Code = "SRM4";
  220. equip.ResidueTask = list.Where(p => p.Tunnel == "7" || p.Tunnel == "8").Count();
  221. }
  222. else
  223. {
  224. equip.EquipState = "3";
  225. equip.Code = "SRM4";
  226. equip.ResidueTask = list.Where(p => p.Tunnel == "7" || p.Tunnel == "8").Count();
  227. }
  228. real.Add(equip);
  229. break;
  230. default:
  231. break;
  232. }
  233. }
  234. return real.OrderBy(p => p.Code).ToList();
  235. }
  236. public List<TaskInfoDto> GetPtTaskInfo(GetWcsTaskInfoRequest ReqEntity)
  237. {
  238. List<TaskInfoDto> taskInfoDtos = new List<TaskInfoDto>();
  239. taskInfoDtos = _zhongTianPtDataService.GetPtRunWcsTaskInfo(ReqEntity);
  240. return taskInfoDtos;
  241. }
  242. public List<ZTBillDto> GetPtBillList(GetWorkPlanBillListRequest reqEntity)
  243. {
  244. var list = _zhongTianPtDataService.GetPtBillList(reqEntity);
  245. return list;
  246. }
  247. public List<ItemVal> GetLocaitonList()
  248. {
  249. List<ItemVal> res = new List<ItemVal>();
  250. var list = _zhongTianPtDataService.GetLocationList();
  251. res.Add(new ItemVal() { Name = "空", Value = list.Where(p => p.StateNum == 1).Any() ? list.Where(p => p.StateNum == 1).Count() : 0 });
  252. res.Add(new ItemVal() { Name = "满", Value = list.Where(p => p.StateNum == 2).Any() ? list.Where(p => p.StateNum == 2).Count() : 0 });
  253. res.Add(new ItemVal() { Name = "锁定", Value = list.Where(p => p.StateNum == 3 || p.StateNum == 4).Any() ? list.Where(p => p.StateNum == 3 || p.StateNum == 4).Count() : 0 });
  254. res.Add(new ItemVal() { Name = "禁用", Value = list.Where(p => p.IsStop == 1).Any() ? list.Where(p => p.IsStop == 1).Count() : 0 });
  255. return res;
  256. }
  257. public GeHistoryTaskInfoRes GeHistoryTaskInfo(GeHistoryTaskInfoRequest ReqEntity)
  258. {
  259. GeHistoryTaskInfoRes res = new GeHistoryTaskInfoRes();
  260. var list = _zhongTianPtDataService.GeHistoryTaskInfo(ReqEntity);
  261. res.DateList = new List<string>() { DateTime.Now.AddDays(-6).ToShortDateString(),
  262. DateTime.Now.AddDays(-5).ToShortDateString(),DateTime.Now.AddDays(-4).ToShortDateString(),DateTime.Now.AddDays(-3).ToShortDateString(),
  263. DateTime.Now.AddDays(-2).ToShortDateString(),DateTime.Now.AddDays(-1).ToShortDateString(),DateTime.Now.ToShortDateString()};
  264. res.StockInList = new List<int>() {
  265. list.Where(p=>p.BusType == "采购入库单" && p.EndTime.Value.Date == DateTime.Now.AddDays(-6).Date).Any() ? list.Where(p=>p.BusType == "采购入库单" && p.EndTime.Value.Date == DateTime.Now.AddDays(-6).Date).Count():0 ,
  266. list.Where(p=>p.BusType == "采购入库单" && p.EndTime.Value.Date == DateTime.Now.AddDays(-5).Date).Any() ? list.Where(p=>p.BusType == "采购入库单" && p.EndTime.Value.Date == DateTime.Now.AddDays(-5).Date).Count():0 ,
  267. list.Where(p=>p.BusType == "采购入库单" && p.EndTime.Value.Date == DateTime.Now.AddDays(-4).Date).Any() ? list.Where(p=>p.BusType == "采购入库单" && p.EndTime.Value.Date == DateTime.Now.AddDays(-4).Date).Count():0 ,
  268. list.Where(p=>p.BusType == "采购入库单" && p.EndTime.Value.Date == DateTime.Now.AddDays(-3).Date).Any() ? list.Where(p=>p.BusType == "采购入库单" && p.EndTime.Value.Date == DateTime.Now.AddDays(-3).Date).Count():0 ,
  269. list.Where(p=>p.BusType == "采购入库单" && p.EndTime.Value.Date == DateTime.Now.AddDays(-2).Date).Any() ? list.Where(p=>p.BusType == "采购入库单" && p.EndTime.Value.Date == DateTime.Now.AddDays(-2).Date).Count():0 ,
  270. list.Where(p=>p.BusType == "采购入库单" && p.EndTime.Value.Date == DateTime.Now.AddDays(-1).Date).Any() ? list.Where(p=>p.BusType == "采购入库单" && p.EndTime.Value.Date == DateTime.Now.AddDays(-1).Date).Count():0 ,
  271. list.Where(p=>p.BusType == "采购入库单" && p.EndTime.Value.Date == DateTime.Now.Date).Any() ? list.Where(p=>p.BusType == "采购入库单" && p.EndTime.Value.Date == DateTime.Now.Date).Count():0 ,
  272. };
  273. res.StockOutList = new List<int>() {
  274. list.Where(p=> p.Type == TaskType.OutDepot && p.EndTime.Value.Date == DateTime.Now.AddDays(-6).Date).Any() ? list.Where(p=>p.Type == TaskType.OutDepot && p.EndTime.Value.Date == DateTime.Now.AddDays(-6).Date).Count():0 ,
  275. list.Where(p=> p.Type == TaskType.OutDepot && p.EndTime.Value.Date == DateTime.Now.AddDays(-5).Date).Any() ? list.Where(p=>p.Type == TaskType.OutDepot && p.EndTime.Value.Date == DateTime.Now.AddDays(-5).Date).Count():0 ,
  276. list.Where(p=> p.Type == TaskType.OutDepot && p.EndTime.Value.Date == DateTime.Now.AddDays(-4).Date).Any() ? list.Where(p=>p.Type == TaskType.OutDepot && p.EndTime.Value.Date == DateTime.Now.AddDays(-4).Date).Count():0 ,
  277. list.Where(p=> p.Type == TaskType.OutDepot && p.EndTime.Value.Date == DateTime.Now.AddDays(-3).Date).Any() ? list.Where(p=>p.Type == TaskType.OutDepot && p.EndTime.Value.Date == DateTime.Now.AddDays(-3).Date).Count():0 ,
  278. list.Where(p=> p.Type == TaskType.OutDepot && p.EndTime.Value.Date == DateTime.Now.AddDays(-2).Date).Any() ? list.Where(p=>p.Type == TaskType.OutDepot && p.EndTime.Value.Date == DateTime.Now.AddDays(-2).Date).Count():0 ,
  279. list.Where(p=> p.Type == TaskType.OutDepot && p.EndTime.Value.Date == DateTime.Now.AddDays(-1).Date).Any() ? list.Where(p=>p.Type == TaskType.OutDepot && p.EndTime.Value.Date == DateTime.Now.AddDays(-1).Date).Count():0 ,
  280. list.Where(p=> p.Type == TaskType.OutDepot && p.EndTime.Value.Date == DateTime.Now.Date).Any() ? list.Where(p=> p.Type == TaskType.OutDepot && p.EndTime.Value.Date == DateTime.Now.Date).Count():0 ,
  281. };
  282. return res;
  283. }
  284. public List<PTStockDto> GetInvReports()
  285. {
  286. List<PTStockDto> PTStockDtos = new List<PTStockDto>();
  287. var list = _zhongTianPtDataService.GetBillInvnowList();
  288. foreach (var item in list.GroupBy(p => new { p.MatCode, p.BoilerNo }))
  289. {
  290. PTStockDtos.Add(new PTStockDto
  291. {
  292. BoilerNo = item.Key.BoilerNo,
  293. MatCode = item.Key.MatCode,
  294. Qty = item.Count(o => !string.IsNullOrEmpty(o.BoilerNo)),
  295. TolWQty = item.Sum(o => o.TolWQty)
  296. });
  297. };
  298. return PTStockDtos.OrderBy(o => o.BoilerNo).ToList();
  299. }
  300. public PageResult<ZtLocationUsageReportViewDto> GetPtLocationUsageViewList()
  301. {
  302. var result = new PageResult<ZtLocationUsageReportViewDto>() { ReturnValue = new List<ZtLocationUsageReportViewDto>() };
  303. var list = _zhongTianPtDataService.GetPtLocationUsageReportList();
  304. result.ReturnValue = list.ToList();
  305. result.ItemGroupSum = new List<ItemGroup>() {
  306. new ItemGroup(){ UnitName="总货位",qty=list.Sum(s=>s.AllLocationTotal)},
  307. new ItemGroup(){ UnitName="有效货位",qty=list.Sum(s=>s.CanUseLocation)},
  308. new ItemGroup(){ UnitName="空余货位",qty=list.Sum(s=>s.SpareLocation)},
  309. new ItemGroup(){ UnitName="锁定货位",qty=list.Sum(s=>s.LockLocation)},
  310. new ItemGroup(){ UnitName="停用货位",qty=list.Sum(s=>s.StopLocation)},
  311. new ItemGroup(){ UnitName="有料货位",qty=list.Sum(s=>s.MaterilLocation)},
  312. new ItemGroup(){ UnitName="有容器货位",qty=list.Sum(s=>s.ContainLocation)}
  313. };
  314. return result;
  315. }
  316. /// <summary>
  317. /// 根据物料号显示当前库存数量
  318. /// </summary>
  319. /// <returns></returns>
  320. public BarModelRes GetMatCodeBarDatas()
  321. {
  322. BarModelRes res = new BarModelRes();
  323. List<ItemVal> listtemp = new List<ItemVal>();
  324. var list = _zhongTianPtDataService.GetBillInvnowList().Where(p => p.InvStateCode == "InvEcecState_In");
  325. foreach (var item in list.GroupBy(p => p.MatCode).OrderBy(x=>x.Key))
  326. {
  327. res.xData.Add(item.Key);
  328. res.yData.Add(item.Count());
  329. }
  330. return res;
  331. }
  332. public BarModel2Res GetBoilerNoMatCodeQtyList()
  333. {
  334. BarModel2Res res = new BarModel2Res();
  335. var lists= _zhongTianPtDataService.GetBoilerNoMatCodeQtyList();
  336. if (lists != null && lists.Any())
  337. {
  338. res.xData = lists.Select(o => o.BoilerNo).ToList();
  339. res.x2Data = lists.Select(o => o.MatCode).ToList();
  340. res.yData = lists.Select(o => o.Qty).ToList();
  341. }
  342. return res;
  343. }
  344. }
  345. }