123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350 |
- using AutoMapper;
- using Bozhon.Wms.Util.Cache;
- using CSRedis;
- using Microsoft.AspNetCore.Mvc;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Wms.Screen.Dto;
- using Wms.Screen.Dto.ZhongTian;
- using Wms.Screen.Dto.ZhongTian.Request;
- using Wms.Screen.Dto.ZhongTian.Response;
- using Wms.Screen.Service.IService;
- namespace zt.screen.api.Controllers
- {
- /// <summary>
- /// 中天盘条看板
- /// </summary>
- [Route("api/[controller]/[action]")]
- [ApiController]
- public class ZhongTianPtController : ControllerBase
- {
- private IZhongTianPtService _zhongTianPtService;
- private IMapper _mapper;
- private readonly CSRedisClient _CSRedisClient;
- private readonly FreeRedis.RedisClient _freeRedisClient;
- public ZhongTianPtController(IZhongTianPtService zhongTianPtService, IMapper mapper, CSRedisClient cSRedisClient, FreeRedis.RedisClient freeRedisClient)
- {
- _zhongTianPtService = zhongTianPtService;
- _mapper = mapper;
- _CSRedisClient = cSRedisClient;
- _freeRedisClient = freeRedisClient;
- }
- #region 查询配置文件信息
- /// <summary>
- /// 查询配置的车间设备信息
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- public List<WorkShopWithEquipment> GetWorkShopWithEquipment()
- {
- List<WorkShopWithEquipment> workShopWithEquipmentList = new List<WorkShopWithEquipment>();
- workShopWithEquipmentList.AddRange(InOutEquipment.WorkShopWithEquipment);
- workShopWithEquipmentList.AddRange(InOutEquipment.YTWorkShopWithEquipment);
- return workShopWithEquipmentList;
- }
- #endregion
- #region 盘条看板
- /// <summary>
- /// 盘条看板
- /// </summary>
- /// <param name="strRequest"></param>
- /// <param name="workshop"></param>
- /// <param name="boardCode"></param>
- /// <returns></returns>
- [HttpPost]
- public List<dynamic> GetPtInfo(StrRequestDto request)
- {
- if (string.IsNullOrEmpty(request.StrRequest))
- {
- return new List<dynamic> { new object(), new object(), new object(), new object(), new object() };
- }
- var result = new List<dynamic>();
- if (request.StrRequest.Split(',').Contains("1")) //堆垛机状态
- {
-
- //查询设备状态 ,读redis
- result.Add(_zhongTianPtService.GetPtEquips(new GetEquipsRequest()
- {
- }, _freeRedisClient));
- }
- else
- {
- result.Add("");
- }
- if (request.StrRequest.Split(',').Contains("2")) //根据物料号显示当前库存数量
- {
- result.Add(_zhongTianPtService.GetMatCodeBarDatas());
- }
- else
- {
- result.Add("");
- }
- if (request.StrRequest.Split(',').Contains("3")) //任务信息
- {
- //List<string> equipNoList = new List<string>();
- //InOutEquipment.WorkShopWithEquipment.Where(s => s.InOrOut == "Out" && InOutEquipment.DeopWithWOrkShops.Where(m => m.Dept == request.Workshop).FirstOrDefault().WorkShopList.Contains(s.WorkShop)).Distinct().ToList().ForEach(
- // n => equipNoList.AddRange(n.Equipments));
- //任务信息:出库和入库任务
- //设备号数据,做成配置
- var taskInfos = _zhongTianPtService.GetPtTaskInfo(new GetWcsTaskInfoRequest()
- {
- //EquipList = equipNoList,
- TaskTypelist = new List<TaskType> { TaskType.OutDepot, TaskType.EnterDepot }
- });
- result.Add(taskInfos);
- }
- else
- {
- result.Add("");
- }
- if (request.StrRequest.Split(',').Contains("4")) //报警信息
- {
- List<string> equipNoList = new List<string>();
- InOutEquipment.WorkShopWithEquipment.Where(s => s.InOrOut == "Out" && InOutEquipment.DeopWithWOrkShops.Where(m => m.Dept == request.Workshop).FirstOrDefault().WorkShopList.Contains(s.WorkShop)).ToList().ForEach(
- n => equipNoList.AddRange(n.Equipments));
- //获取报警信息
- //设备号数据,做成配置
- result.Add(GetStockInAndOutRecordInfo(new GetEquipsRequest
- {
- EquCodeList = equipNoList.Distinct().ToList()
- }));
- }
- else
- {
- result.Add("");
- }
- if (request.StrRequest.Split(',').Contains("5")) //同炉号各规格数量
- {
- result.Add(_zhongTianPtService.GetBoilerNoMatCodeQtyList());
- }
- else
- {
- result.Add("");
- }
- return result;
- }
- [HttpPost]
- public List<dynamic> GetPtStatsInfo(StrRequestDto request)
- {
- if (string.IsNullOrEmpty(request.StrRequest))
- {
- return new List<dynamic> { new object(), new object(), new object(), new object(), new object() };
- }
- var result = new List<dynamic>();
- if (request.StrRequest.Split(',').Contains("1")) //货位分布占比
- {
- result.Add(_zhongTianPtService.GetLocaitonList());
- }
- else
- {
- result.Add("");
- }
- if (request.StrRequest.Split(',').Contains("2")) //空满轮占比
- {
- //领料 涂布领料汇总,不区分车间
- // result.Add(_zhongTianPtService.GetEmptyFullDist());
- result.Add("");
- }
- else
- {
- result.Add("");
- }
- if (request.StrRequest.Split(',').Contains("3")) //7天出入库统计
- {
- var taskInfos = _zhongTianPtService.GeHistoryTaskInfo(new GeHistoryTaskInfoRequest()
- {
- BusTypeList = new List<string>() { "采购入库单", "生产领料" },
- StartTime = DateTime.Now.AddDays(-7),
- EndTime = DateTime.Now.AddDays(1)
- });
- result.Add(taskInfos);
- }
- else
- {
- result.Add("");
- }
- if (request.StrRequest.Split(',').Contains("4")) //物料重量分布
- {
- var taskInfos = _zhongTianPtService. GetInvReports();
- result.Add(taskInfos);
- }
- else
- {
- result.Add("");
- }
- if (request.StrRequest.Split(',').Contains("5")) //报警信息
- {
- List<string> equipNoList = new List<string>();
- InOutEquipment.WorkShopWithEquipment.Where(s => s.InOrOut == "Out" && InOutEquipment.DeopWithWOrkShops.Where(m => m.Dept == request.Workshop).FirstOrDefault().WorkShopList.Contains(s.WorkShop)).ToList().ForEach(
- n => equipNoList.AddRange(n.Equipments));
- //获取报警信息
- //设备号数据,做成配置
- result.Add(GetStockInAndOutRecordInfo(new GetEquipsRequest
- {
- EquCodeList = equipNoList.Distinct().ToList()
- }));
- }
- else
- {
- result.Add("");
- }
- return result;
- }
- #endregion
- #region 货位利用率
- /// <summary>
- /// 盘条货位利用率
- /// </summary>
- /// <param name="strRequest"></param>
- /// <returns></returns>
- [HttpPost]
- public PageResult<ZtLocationUsageReportViewDto> GetPtLocationStateList()
- {
- return _zhongTianPtService.GetPtLocationUsageViewList();
- }
- #endregion
- #region 异常信息汇总
- /// <summary>
- /// 盘条异常信息汇总
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- public List<dynamic> GetTotalErrorInfo()
- {
- var result = new List<dynamic>();
- List<string> equipNoList = new List<string>();
- InOutEquipment.WorkShopWithEquipment.Where(s => InOutEquipment.DeopWithWOrkShops.Where(m => m.Dept == "pt").FirstOrDefault().WorkShopList.Contains(s.WorkShop)).ToList().ForEach(
- n => equipNoList.AddRange(n.Equipments));
- //报警信息
- result.Add(GetStockInAndOutRecordInfo(new GetEquipsRequest()
- {
- EquCodeList = equipNoList.Distinct().ToList()
- }));
- return result;
- }
- #endregion
- #region 私有方法:将报表方法提取出来
- /// <summary>
- /// 报警信息
- /// </summary>
- /// <param name="reqEntity"></param>
- /// <returns></returns>
- private List<StockInAndOutRecordDto> GetStockInAndOutRecordInfo(GetEquipsRequest reqEntity)
- {
- var list = new List<StockInAndOutRecordDto>();
- try
- {
- foreach (var equipno in reqEntity.EquCodeList)
- {
- var msg1 = _CSRedisClient.Get("Pt:EquipmentAlarm:" + equipno); //设备报警
- if (!string.IsNullOrEmpty(msg1))
- {
- var msgdto = JsonConvert.DeserializeObject<I_WCS_PutDevInfoRequestDto>(msg1);
- if (msgdto.Msg == "0" || msgdto.Msg == "无")
- {
- continue;
- }
- if (!string.IsNullOrEmpty(msgdto.Msg) && msgdto.Time.Date == DateTime.Now.Date)
- list.Add(new StockInAndOutRecordDto { dateTime = msgdto.Time.ToString("HH:mm:ss"), Message = msgdto.Code + "," + msgdto.Msg });
- }
- }
- var msg2 = _CSRedisClient.Get("Pt:BusinessAlarm:MainWorld"); //业务报警
- var msgdto2 = JsonConvert.DeserializeObject<List<BusinessDto>>(msg2);
- if (msgdto2.Any())
- {
- foreach (var item in msgdto2)
- {
- if (!string.IsNullOrEmpty(item.Con) && item.Time.Date == DateTime.Now.Date)
- {
- item.Con = item.Con.Substring(item.Con.LastIndexOf("内容:") + 3);
- if (item.Con.StartsWith("[SRM1]") || item.Con.StartsWith("[SRM2]") || item.Con.StartsWith("[SRM3]") || item.Con.StartsWith("[SRM4]"))
- {
- item.Con = item.Con.Substring(item.Con.LastIndexOf("]") + 1);
- }
- else if (item.Con.StartsWith("1011") || item.Con.StartsWith("1012") || item.Con.StartsWith("1014") || item.Con.StartsWith("1016"))
- {
- item.Con = item.Con.Substring(4);
- }
- else if (item.Con.StartsWith("SRM1") || item.Con.StartsWith("SRM2") || item.Con.StartsWith("SRM3") || item.Con.StartsWith("SRM4"))
- {
- item.Con = item.Con.Substring(4);
- }
- list.Add(new StockInAndOutRecordDto { dateTime = item.Time.ToString("HH:mm:ss"), Message = item.DevNo + "," + item.Con });
- }
- }
- }
- var msg3 = _CSRedisClient.Get("Pt:BusinessAlarm:MainWorldd"); //AGV交互报错信息
- if (msg3 != null)
- {
- var msgdto3 = JsonConvert.DeserializeObject<List<BusinessDto>>(msg3);
- if (msgdto3.Any())
- {
- List<StockInAndOutRecordDto> agv = new List<StockInAndOutRecordDto>();
- foreach (var item in msgdto3)
- {
- if (!string.IsNullOrEmpty(item.Con) && (DateTime.Now - item.Time).Minutes.ToString().GetHashCode() < 2)
- {
- var mes = item.Con.Substring(item.Con.LastIndexOf("内容:") + 3);
- if (mes.StartsWith("[1011]--"))
- {
- mes = mes.Substring(mes.LastIndexOf("--") + 2);
- }
- agv.Add(new StockInAndOutRecordDto { dateTime = item.Time.ToString("HH:mm:ss"), Message = "海康报错信息" + "," + mes });
- }
- }
- if (agv.Any())
- {
- var agv1 = agv.Select(p => p.Message).Distinct().ToList();
- foreach (var item in agv1)
- {
- list.Add(new StockInAndOutRecordDto { dateTime = DateTime.Now.ToString("HH:mm:ss"), Message = item });
- }
- }
- }
- }
- for (int i = 1; i < 20; i++) //WMS业务报警
- {
- var msg = RedisHelper.Get("Pt:WMSErrorInfo:" + i); //WMS业务报警
- if (msg != null)
- {
- var msgdto = JsonConvert.DeserializeObject<BusinessDto2>(msg);
- list.Add(new StockInAndOutRecordDto { dateTime = msgdto.Time.ToString("HH:mm:ss"), Message = "WMS业务报警:" + msgdto.Con });
- }
- if (i == 5 && DateTime.Now.Hour == 0 && DateTime.Now.Minute < 10)//凌晨清理下报警
- {
- RedisHelper.Del("Pt:WMSErrorInfo:" + i);
- }
- }
- }
- catch (Exception ex)
- {
- list.Add(new StockInAndOutRecordDto { dateTime = DateTime.Now.ToString("HH:mm:ss"), Message = $"缓存报警读取失败:{ex.Message}" });
- }
- if (list.Any())
- {
- list = list.OrderBy(p => p.Code).ToList();
- }
- return list;
- }
- #endregion
- }
- }
|