| | |
| | | using System.Linq; |
| | | using System.Linq.Dynamic.Core; |
| | | using System.Text; |
| | | using System.Text.RegularExpressions; |
| | | using System.Web; |
| | | using static OfficeOpenXml.FormulaParsing.EpplusExcelDataProvider; |
| | | |
| | | namespace iWare.Wms.Application |
| | | { |
| | |
| | | /// </summary> |
| | | [ApiDescriptionSettings("数据查询服务", Name = "WorkPieceProcess", Order = 100)] |
| | | [Route("api/[Controller]")] |
| | | [DisableOpLog] |
| | | public class WorkPieceProcessService : IWorkPieceProcessService, IDynamicApiController, ITransient |
| | | { |
| | | private readonly IRepository<WorkPieceProcess,MasterDbContextLocator> _workPieceProcessRep; |
| | | private readonly IRepository<WorkPieceProcess, MasterDbContextLocator> _workPieceProcessRep; |
| | | private readonly IRepository<WorkPieceInfo, MasterDbContextLocator> _workPieceInfoRep; |
| | | private readonly IRepository<EquipmentBaseInfo, MasterDbContextLocator> _equipmentBaseInfoRep; |
| | | private readonly IRepository<SysDictType, MasterDbContextLocator> _sysDictTypeRep; |
| | |
| | | /// <param name="sysDictTypeRep"></param> |
| | | /// <param name="sysDictDataRep"></param> |
| | | public WorkPieceProcessService( |
| | | IRepository<WorkPieceProcess,MasterDbContextLocator> workPieceProcessRep, |
| | | IRepository<WorkPieceProcess, MasterDbContextLocator> workPieceProcessRep, |
| | | IRepository<WorkPieceInfo, MasterDbContextLocator> workPieceInfoRep, |
| | | IRepository<EquipmentBaseInfo, MasterDbContextLocator> equipmentBaseInfoRep, |
| | | IRepository<SysDictType, MasterDbContextLocator> sysDictTypeRep, |
| | |
| | | // EmployeeName = emp.Name, |
| | | // DepartmentName = dept != null ? dept.Name : null |
| | | // }; |
| | | var workPieceProcesss = await(from process in _workPieceProcessRep.DetachedEntities |
| | | join baseinfo in _equipmentBaseInfoRep.DetachedEntities |
| | | on process.EquipmentID equals baseinfo.EquipmentId into joinedEmpty |
| | | from baseinfo2 in joinedEmpty.DefaultIfEmpty() |
| | | where process.IsDeleted == false && process.WorkPieceID.Contains(string.IsNullOrEmpty(input.WorkPieceID)?"": input.WorkPieceID) |
| | | && process.QualityState == (input.QualityState.HasValue? input.QualityState.Value: process.QualityState) |
| | | && process.EquipmentID == (string.IsNullOrEmpty(input.EquipmentID) ? process.EquipmentID : input.EquipmentID) |
| | | && process.WorkingProcedureCurrent == (string.IsNullOrEmpty(input.WorkingProcedureCurrent) ? process.WorkingProcedureCurrent : input.WorkingProcedureCurrent) |
| | | && process.EquipmentID == (string.IsNullOrEmpty(input.EquipmentID) ? process.EquipmentID : input.EquipmentID) |
| | | && process.OperationType==(string.IsNullOrEmpty(input.OperationType) ? process.OperationType : input.OperationType) |
| | | && !string.IsNullOrEmpty(process.WorkPieceID) |
| | | &&process.StartTime>= (input.StartTimeBeginTime.HasValue?input.StartTimeBeginTime:DateTime.MinValue) |
| | | && process.StartTime <= (input.StartTimeEndTime.HasValue ? input.StartTimeEndTime : DateTime.MaxValue) |
| | | select new WorkPieceProcessOutput |
| | | { |
| | | var workPieceProcesss = await (from process in _workPieceProcessRep.DetachedEntities |
| | | join baseinfo in _equipmentBaseInfoRep.DetachedEntities on process.EquipmentID equals baseinfo.EquipmentId into joinedEmpty |
| | | from baseinfo2 in joinedEmpty.DefaultIfEmpty() |
| | | join workPiece in _workPieceInfoRep.DetachedEntities on process.WorkPieceID equals workPiece.WorkPieceID into joined2Empty |
| | | from workPiece2 in joined2Empty.DefaultIfEmpty() |
| | | where process.IsDeleted == false && process.WorkPieceID.Contains(string.IsNullOrEmpty(input.WorkPieceID) ? "" : input.WorkPieceID) |
| | | && process.QualityState == (input.QualityState.HasValue ? input.QualityState.Value : process.QualityState) |
| | | && process.EquipmentID == (string.IsNullOrEmpty(input.EquipmentID) ? process.EquipmentID : input.EquipmentID) |
| | | && process.WorkingProcedureCurrent == (string.IsNullOrEmpty(input.WorkingProcedureCurrent) ? process.WorkingProcedureCurrent : input.WorkingProcedureCurrent) |
| | | && workPiece2.OP80NewCode == (string.IsNullOrEmpty(input.OP80NewCode) ? workPiece2.OP80NewCode : input.OP80NewCode) |
| | | && process.EquipmentID == (string.IsNullOrEmpty(input.EquipmentID) ? process.EquipmentID : input.EquipmentID) |
| | | && process.OperationType == (string.IsNullOrEmpty(input.OperationType) ? process.OperationType : input.OperationType) |
| | | && !string.IsNullOrEmpty(process.WorkPieceID) |
| | | && process.StartTime >= (input.StartTimeBeginTime.HasValue ? input.StartTimeBeginTime : DateTime.MinValue) |
| | | && process.StartTime <= (input.StartTimeEndTime.HasValue ? input.StartTimeEndTime : DateTime.MaxValue) |
| | | select new WorkPieceProcessOutput |
| | | { |
| | | |
| | | Id = process.Id, |
| | | WorkPieceID = process.WorkPieceID, |
| | | EquipmentID = process.EquipmentID, |
| | | EquipmentName = (baseinfo2 == null ? "" : baseinfo2.EquipmentName), |
| | | WorkingProcedureCurrent = process.WorkingProcedureCurrent, |
| | | StartTime = process.StartTime, |
| | | EndTime = process.EndTime, |
| | | QualityState = process.QualityState, |
| | | QualityDataInfoID = process.QualityDataInfoID, |
| | | OperationType=process.OperationType, |
| | | CreateUserName=process.CreatedUserName |
| | | }).OrderBy(o=>o.StartTime) |
| | | Id = process.Id, |
| | | WorkPieceID = process.WorkPieceID, |
| | | EquipmentID = process.EquipmentID, |
| | | EquipmentName = (baseinfo2 == null ? "" : baseinfo2.EquipmentName), |
| | | OP80NewCode = workPiece2.OP80NewCode, |
| | | |
| | | WorkingProcedureCurrent = process.WorkingProcedureCurrent, |
| | | StartTime = process.StartTime, |
| | | EndTime = process.EndTime, |
| | | QualityState = process.QualityState, |
| | | QualityDataInfoID = process.QualityDataInfoID, |
| | | OperationType = process.OperationType, |
| | | CreateUserName = process.CreatedUserName |
| | | }).OrderBy(o => o.StartTime) |
| | | .ProjectToType<WorkPieceProcessOutput>() |
| | | .ToADPagedListAsync(input.PageNo, input.PageSize); |
| | | |
| | |
| | | join baseinfo in _equipmentBaseInfoRep.DetachedEntities |
| | | on process.EquipmentID equals baseinfo.EquipmentId into joinedEmpty |
| | | from baseinfo2 in joinedEmpty.DefaultIfEmpty() |
| | | join workPiece in _workPieceInfoRep.DetachedEntities on process.WorkPieceID equals workPiece.WorkPieceID into joined2Empty |
| | | from workPiece2 in joined2Empty.DefaultIfEmpty() |
| | | where process.IsDeleted == false && process.WorkPieceID.Contains(string.IsNullOrEmpty(input.WorkPieceID) ? "" : input.WorkPieceID) |
| | | && process.QualityState == (input.QualityState.HasValue ? input.QualityState.Value : process.QualityState) |
| | | && process.EquipmentID == (string.IsNullOrEmpty(input.EquipmentID) ? process.EquipmentID : input.EquipmentID) |
| | | && process.WorkingProcedureCurrent == (string.IsNullOrEmpty(input.WorkingProcedureCurrent) ? process.WorkingProcedureCurrent : input.WorkingProcedureCurrent) |
| | | && process.EquipmentID == (string.IsNullOrEmpty(input.EquipmentID) ? process.EquipmentID : input.EquipmentID) |
| | | && workPiece2.OP80NewCode == (string.IsNullOrEmpty(input.OP80NewCode) ? workPiece2.OP80NewCode : input.OP80NewCode) |
| | | && process.OperationType == (string.IsNullOrEmpty(input.OperationType) ? process.OperationType : input.OperationType) |
| | | && !string.IsNullOrEmpty(process.WorkPieceID) |
| | | && process.StartTime >= (input.StartTimeBeginTime.HasValue ? input.StartTimeBeginTime : DateTime.MinValue) |
| | | && process.StartTime <= (input.StartTimeEndTime.HasValue ? input.StartTimeEndTime : DateTime.MaxValue) |
| | | select new WorkPieceProcessExcelOutput |
| | | { |
| | | OP80NewCode = workPiece2.OP80NewCode, |
| | | |
| | | Id = process.Id, |
| | | WorkPieceID = process.WorkPieceID, |
| | |
| | | WorkingProcedureCurrent = process.WorkingProcedureCurrent, |
| | | StartTime = process.StartTime.ToString(), |
| | | EndTime = process.EndTime.ToString(), |
| | | QualityState = process.QualityState, |
| | | CreateUserName=process.CreatedUserName |
| | | //QualityState = process.QualityState, |
| | | CreateUserName = process.CreatedUserName |
| | | }).OrderBy(o => o.StartTime).Distinct() |
| | | .ProjectToType<WorkPieceProcessExcelOutput>() |
| | | .ToListAsync(); |
| | |
| | | |
| | | foreach (WorkPieceProcessExcelOutput item in workPieceMachiningInfos) |
| | | { |
| | | item.StartTime = string.IsNullOrEmpty(item.StartTime) ? "" :Convert.ToDateTime(item.StartTime).ToString("yyyy-MM-dd hh:mm:ss"); |
| | | item.StartTime = string.IsNullOrEmpty(item.StartTime) ? "" : Convert.ToDateTime(item.StartTime).ToString("yyyy-MM-dd hh:mm:ss"); |
| | | item.EndTime = string.IsNullOrEmpty(item.EndTime) ? "" : Convert.ToDateTime(item.EndTime).ToString("yyyy-MM-dd hh:mm:ss"); |
| | | } |
| | | |
| | |
| | | var fileName = HttpUtility.UrlEncode($"{sheetName}[{DateTimeOffset.Now:yyyy-MM-dd}].xlsx", Encoding.GetEncoding("UTF-8")); |
| | | return new FileStreamResult(ms, "application/octet-stream") { FileDownloadName = fileName }; |
| | | } |
| | | |
| | | |
| | | #region 产量查询 [Editby shaocx,2024-06-08] |
| | | |
| | | /// <summary> |
| | | /// 产量查询 |
| | | /// </summary> |
| | | /// <param name="input"></param> |
| | | /// <returns></returns> |
| | | [HttpGet("queryYield")] |
| | | public async Task<PageResult<QueryYieldOutput>> QueryYield([FromQuery] WorkPieceProcessSearch input) |
| | | { |
| | | |
| | | var workPieceProcesss2 = await (from process in _workPieceProcessRep.DetachedEntities |
| | | //join baseinfo in _equipmentBaseInfoRep.DetachedEntities on process.EquipmentID equals baseinfo.EquipmentId into joinedEmpty |
| | | //from baseinfo2 in joinedEmpty.DefaultIfEmpty() |
| | | //join workPiece in _workPieceInfoRep.DetachedEntities on process.WorkPieceID equals workPiece.WorkPieceID into joined2Empty |
| | | //from workPiece2 in joined2Empty.DefaultIfEmpty() |
| | | where process.IsDeleted == false && process.WorkPieceID.Contains(string.IsNullOrEmpty(input.WorkPieceID) ? "" : input.WorkPieceID) |
| | | && process.QualityState == (input.QualityState.HasValue ? input.QualityState.Value : process.QualityState) |
| | | && process.EquipmentID == (string.IsNullOrEmpty(input.EquipmentID) ? process.EquipmentID : input.EquipmentID) |
| | | && process.WorkingProcedureCurrent == (string.IsNullOrEmpty(input.WorkingProcedureCurrent) ? process.WorkingProcedureCurrent : input.WorkingProcedureCurrent) |
| | | //&& workPiece2.OP80NewCode == (string.IsNullOrEmpty(input.OP80NewCode) ? workPiece2.OP80NewCode : input.OP80NewCode) |
| | | && process.EquipmentID == (string.IsNullOrEmpty(input.EquipmentID) ? process.EquipmentID : input.EquipmentID) |
| | | && process.OperationType == (string.IsNullOrEmpty(input.OperationType) ? process.OperationType : input.OperationType) |
| | | && !string.IsNullOrEmpty(process.WorkPieceID) |
| | | && process.StartTime >= (input.StartTimeBeginTime.HasValue ? input.StartTimeBeginTime : DateTime.MinValue) |
| | | && process.StartTime <= (input.StartTimeEndTime.HasValue ? input.StartTimeEndTime : DateTime.MaxValue) |
| | | select new QueryYieldOutput |
| | | { |
| | | //EquipmentID = process.EquipmentID, |
| | | //EquipmentName = baseinfo2.EquipmentName, |
| | | WorkingProcedureCurrent = process.WorkingProcedureCurrent, |
| | | //StartTime = grouped.Key.StartTime, |
| | | YieldCount = 0 |
| | | }).ToListAsync(); |
| | | |
| | | var workPieceProcesss = workPieceProcesss2.GroupBy(x => new { x.WorkingProcedureCurrent }).Select(y => new QueryYieldOutput |
| | | { |
| | | //EquipmentID = y.Key.EquipmentID, |
| | | //EquipmentName = y.Key.EquipmentName, |
| | | WorkingProcedureCurrent = y.Key.WorkingProcedureCurrent, |
| | | //StartTime = grouped.Key.StartTime, |
| | | YieldCount = y.ToList().Count |
| | | }) |
| | | .OrderBy(x => x.WorkingProcedureCurrent) |
| | | .ToADPagedList(input.PageNo, input.PageSize); |
| | | |
| | | //var workPieceProcesss = await (from process in _workPieceProcessRep.DetachedEntities |
| | | // join baseinfo in _equipmentBaseInfoRep.DetachedEntities on process.EquipmentID equals baseinfo.EquipmentId into joinedEmpty |
| | | // from baseinfo2 in joinedEmpty.DefaultIfEmpty() |
| | | // join workPiece in _workPieceInfoRep.DetachedEntities on process.WorkPieceID equals workPiece.WorkPieceID into joined2Empty |
| | | // from workPiece2 in joined2Empty.DefaultIfEmpty() |
| | | // where process.IsDeleted == false && process.WorkPieceID.Contains(string.IsNullOrEmpty(input.WorkPieceID) ? "" : input.WorkPieceID) |
| | | // && process.QualityState == (input.QualityState.HasValue ? input.QualityState.Value : process.QualityState) |
| | | // && process.EquipmentID == (string.IsNullOrEmpty(input.EquipmentID) ? process.EquipmentID : input.EquipmentID) |
| | | // && process.WorkingProcedureCurrent == (string.IsNullOrEmpty(input.WorkingProcedureCurrent) ? process.WorkingProcedureCurrent : input.WorkingProcedureCurrent) |
| | | // && workPiece2.OP80NewCode == (string.IsNullOrEmpty(input.OP80NewCode) ? workPiece2.OP80NewCode : input.OP80NewCode) |
| | | // && process.EquipmentID == (string.IsNullOrEmpty(input.EquipmentID) ? process.EquipmentID : input.EquipmentID) |
| | | // && process.OperationType == (string.IsNullOrEmpty(input.OperationType) ? process.OperationType : input.OperationType) |
| | | // && !string.IsNullOrEmpty(process.WorkPieceID) |
| | | // && process.StartTime >= (input.StartTimeBeginTime.HasValue ? input.StartTimeBeginTime : DateTime.MinValue) |
| | | // && process.StartTime <= (input.StartTimeEndTime.HasValue ? input.StartTimeEndTime : DateTime.MaxValue) |
| | | // //group new { process, baseinfo2 } by new { process.WorkingProcedureCurrent, process.EquipmentID, baseinfo2.EquipmentName } into grouped |
| | | // //group process by new { process.WorkingProcedureCurrent, process.EquipmentID } into grouped |
| | | // group process by new { process.WorkingProcedureCurrent } into grouped |
| | | // select new QueryYieldOutput |
| | | // { |
| | | // // EquipmentID = grouped.Key.EquipmentID, |
| | | // //EquipmentName = grouped.Key.EquipmentName, |
| | | // WorkingProcedureCurrent = grouped.Key.WorkingProcedureCurrent, |
| | | // //StartTime = grouped.Key.StartTime, |
| | | // YieldCount = grouped.ToList().Count, |
| | | |
| | | // }).OrderBy(o => o.StartTime) |
| | | // .ProjectToType<QueryYieldOutput>() |
| | | // .ToADPagedListAsync(input.PageNo, input.PageSize); |
| | | |
| | | return workPieceProcesss; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 导出产量查询 |
| | | /// </summary> |
| | | /// <param name="input"></param> |
| | | /// <returns>导出的Excel文件</returns> |
| | | [HttpGet("exportYield")] |
| | | public async Task<IActionResult> ExportYield([FromQuery] WorkPieceProcessSearch input) |
| | | { |
| | | input.PageNo = 1; |
| | | input.PageSize = 1000000; |
| | | var workPieceMachiningInfos2 = QueryYield(input); |
| | | var workPieceMachiningInfos = workPieceMachiningInfos2.Result.Rows.ToList(); |
| | | var daList = workPieceMachiningInfos.Adapt<List<ExportYieldOutput>>(); |
| | | |
| | | MemoryStream ms = new(); |
| | | DataConvertUtil.ToExcelData(daList, _sysDictTypeRep, _sysDictDataRep, out List<string> headers, |
| | | out List<List<object>> data, out string sheetName); |
| | | |
| | | ExcelUtil.ToExcel(headers, data, sheetName, ms); |
| | | ms.Position = 0; |
| | | var fileName = HttpUtility.UrlEncode($"{sheetName}[{DateTimeOffset.Now:yyyy-MM-dd}].xlsx", Encoding.GetEncoding("UTF-8")); |
| | | return new FileStreamResult(ms, "application/octet-stream") { FileDownloadName = fileName }; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | /// <summary> |
| | | /// 分页查询工件加工(工件信息表) |
| | |
| | | .Join(_sysDictTypeRep.DetachedEntities, g => g.f.TypeId, h => h.Id, (f, g) => new { f, g }) |
| | | .Where(x => (x.g.Code.Equals("workpiece_state") && (string.IsNullOrEmpty(input.WorkPieceState.ToString()) ? true : x.f.f.Code.Equals(input.WorkPieceState.ToString())))) |
| | | .Where(!string.IsNullOrEmpty(input.WorkPieceID), u => u.f.e.a.WorkPieceID.Contains(input.WorkPieceID)) |
| | | .Where(!string.IsNullOrEmpty(input.OP80NewCode), u => u.f.e.a.OP80NewCode.Contains(input.OP80NewCode)) |
| | | .Where(!string.IsNullOrEmpty(input.WorkPieceState.ToString()), u => u.f.e.a.WorkPieceState == input.WorkPieceState) |
| | | .Where(!string.IsNullOrEmpty(input.EquipmentID), u => u.f.e.a.EquipmentID.Equals(input.EquipmentID)) |
| | | .Where(!string.IsNullOrEmpty(input.WorkingProcedureCurrent), u => u.f.e.a.WorkingProcedureCurrent.Equals(input.WorkingProcedureCurrent)) |
| | | .Where(!string.IsNullOrEmpty(input.StartTimeBeginTime.ToString()), u => u.f.e.a.WorkPieceinitOnlineTime >= input.StartTimeBeginTime) |
| | | .Where(!string.IsNullOrEmpty(input.StartTimeEndTime.ToString()), u => u.f.e.a.WorkPieceinitOnlineTime <= input.StartTimeEndTime) |
| | | .Where(o => !string.IsNullOrEmpty(o.f.e.a.WorkPieceID)) |
| | | .Where(o=>o.f.e.a.QualityState== (input.QualityState.HasValue ? input.QualityState.Value : o.f.e.a.QualityState)) |
| | | .Where(o => o.f.e.a.QualityState == (input.QualityState.HasValue ? input.QualityState.Value : o.f.e.a.QualityState)) |
| | | .Select(s => new WorkPieceInfoMachiningPageOutput |
| | | { |
| | | Id = s.f.e.a.Id, |
| | |
| | | QualityState = s.f.e.a.QualityState, |
| | | EquipmentID = s.f.e.a.EquipmentID, |
| | | EquipmentName = s.f.e.b.EquipmentName, |
| | | OperationType = "正常" |
| | | OperationType = "正常", |
| | | OP80NewCode = s.f.e.a.OP80NewCode, |
| | | }) |
| | | .OrderBy(PageInputOrder.OrderBuilder<WorkPieceProcessSearch>(input)) |
| | | .ProjectToType<WorkPieceInfoMachiningPageOutput>() |
| | |
| | | .Join(_sysDictTypeRep.DetachedEntities, g => g.f.TypeId, h => h.Id, (f, g) => new { f, g }) |
| | | .Where(x => (x.g.Code.Equals("workpiece_state") && (string.IsNullOrEmpty(input.WorkPieceState.ToString()) ? true : x.f.f.Code.Equals(input.WorkPieceState.ToString())))) |
| | | .Where(!string.IsNullOrEmpty(input.WorkPieceID), u => u.f.e.a.WorkPieceID.Contains(input.WorkPieceID)) |
| | | .Where(!string.IsNullOrEmpty(input.OP80NewCode), u => u.f.e.a.OP80NewCode.Contains(input.OP80NewCode)) |
| | | .Where(!string.IsNullOrEmpty(input.WorkPieceState.ToString()), u => u.f.e.a.WorkPieceState == input.WorkPieceState) |
| | | .Where(!string.IsNullOrEmpty(input.EquipmentID), u => u.f.e.a.EquipmentID.Equals(input.EquipmentID)) |
| | | .Where(!string.IsNullOrEmpty(input.WorkingProcedureCurrent), u => u.f.e.a.WorkingProcedureCurrent.Equals(input.WorkingProcedureCurrent)) |
| | |
| | | WorkPieceLastOfflineTime = s.f.e.a.WorkPieceLastOfflineTime.ToString(), |
| | | WorkPieceStateName = s.f.f.Value, |
| | | EquipmentName = s.f.e.b.EquipmentName, |
| | | QualityState = s.f.e.a.QualityState, |
| | | //QualityState = s.f.e.a.QualityState, |
| | | OP80NewCode = s.f.e.a.OP80NewCode, |
| | | }) |
| | | .Distinct() |
| | | .OrderBy(PageInputOrder.OrderBuilder<WorkPieceProcessSearch>(input)) |