123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- using AutoMapper;
- using Bozhon.Wms.Util.Cache;
- using Microsoft.AspNetCore.Mvc;
- using Newtonsoft.Json;
- using System.Collections.Generic;
- using System;
- using Wms.Screen.Dto.ZhongTian.Request;
- using Wms.Screen.Dto.ZhongTian.Response;
- using Wms.Screen.Dto.ZhongTian;
- using Wms.Screen.Service.IService;
- using System.Linq;
- using Wms.Screen.Dto;
- using Wms.Screen.Service.Service;
- namespace Wms.Screen.Api.Controllers
- {
- /// <summary>
- /// 中天成品看板
- /// </summary>
- [Route("api/[controller]/[action]")]
- [ApiController]
- public class ZhongTianCpController : ControllerBase
- {
- private IZhongTianCpService _zhongTianCpService;
- private IMapper _mapper;
- private IRedisClient _redisClient;
- public ZhongTianCpController(IZhongTianCpService zhongTianCpService, IMapper mapper, IRedisClient redisClient)
- {
- _zhongTianCpService = zhongTianCpService;
- _mapper = mapper;
- _redisClient = redisClient;
- }
- #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> GetCpInfo(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(_zhongTianCpService.GetCpEquips(new GetEquipsRequest()
- {
- WarehouseCodeList = new List<string>() {
- Const.Cphouse_putong}
- }));
- }
- else
- {
- result.Add("");
- }
- if (request.StrRequest.Split(',').Contains("2")) //库龄统计占比
- {
- //领料 涂布领料汇总,不区分车间
- result.Add(_zhongTianCpService.GetCpBillList(new GetWorkPlanBillListRequest()
- {
- WarehouseDocumentType = Const.WorkPlanBill,
- WarehouseCodeList = new List<string>() { Const.Cphouse_putong },
- WarehouseDocumentStateList = new List<string>() { Const.WarehouseDocumentState_ExecuteCode, Const.WarehouseDocumentState_CreateCode }
- }));
- }
- 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 = _zhongTianCpService.GetCpTaskInfo(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("");
- }
- return result;
- }
- #endregion
- #region 货位利用率
- /// <summary>
- /// 成品货位利用率
- /// </summary>
- /// <param name="strRequest"></param>
- /// <returns></returns>
- [HttpPost]
- public PageResult<ZtLocationUsageReportViewDto> GetCpLocationStateList()
- {
- return _zhongTianCpService.GetCpLocationUsageViewList();
- }
- #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 == "cp").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>();
- //读取redis缓存(wcs实时传递设备信息)
- //var strMsgList = _redisClient.Get(Const.equi_list);
- //获取单据错误信息
- //List<SqlSugar.Model.BillErrorInfo> ErrorList = new List<SqlSugar.Model.BillErrorInfo>();
- //try
- //{
- // ErrorList = _yongGuanDataService.GetBillErrorInfoList(reqEntity.EquipNo);
- // if (ErrorList.Count() > 0)
- // {
- // list.AddRange(ErrorList.Select(s => new StockInAndOutRecordDto { dateTime = s.CreatedTime.ToString("HH:mm:ss"), Message = s.Msg }).ToList());
- // }
- // //if (ErrorList.Count() > 0)
- // //{
- // // //显示近一天的数据
- // // //DateTime end = DateTime.Now.AddDays(1);
- // // ErrorList = ErrorList.Where(x => x.CreatedTime.Date == DateTime.Now.Date).ToList();
- // //}
- //}
- //catch (Exception ex)
- //{
- // list.Add(new StockInAndOutRecordDto { dateTime = DateTime.Now.ToString("HH:mm:ss"), Message = $"数据库报警信息读取失败:{ex.Message}" });
- //}
- try
- {
- foreach (var equipno in reqEntity.EquCodeList)
- {
- var msg1 = _redisClient.Get("equone" + equipno);
- var msg2 = _redisClient.Get("equsecond" + equipno);
- if (!string.IsNullOrEmpty(msg1))
- {
- var msgdto = JsonConvert.DeserializeObject<I_WCS_PutDevInfoRequestDto>(msg1);
- if (!string.IsNullOrEmpty(msgdto.STA_ALARMSMSG))
- list.Add(new StockInAndOutRecordDto { dateTime = msgdto.InOutTime.ToString("HH:mm:ss"), Message = msgdto.STA_ALARMSMSG });
- }
- if (!string.IsNullOrEmpty(msg2))
- {
- var msgdto = JsonConvert.DeserializeObject<I_WCS_PutDevInfoRequestDto>(msg2);
- if (!string.IsNullOrEmpty(msgdto.STA_ALARMSMSG) && msgdto.InOutTime.Date == DateTime.Now.Date)
- {
- list.Add(new StockInAndOutRecordDto { dateTime = msgdto.InOutTime.ToString("HH:mm:ss"), Message = msgdto.STA_ALARMSMSG });
- }
- }
- }
- }
- catch (Exception ex)
- {
- list.Add(new StockInAndOutRecordDto { dateTime = DateTime.Now.ToString("HH:mm:ss"), Message = $"缓存报警读取失败:{ex.Message}" });
- }
- if (list.Any())
- {
- list = list.OrderByDescending(p => p.dateTime).ToList();
- }
- return list;
- }
- #endregion
- }
- }
|