public DataResult PutManufactureTaskItem([FromBody] IEnumerable <ManufactureTaskItem> manufactureTaskItems) { if (manufactureTaskItems == null) { return(Result.GenError <DataResult>(Error.ManufactureTaskItemNotExist)); } if (manufactureTaskItems.Any(x => x.TaskId == 0) || manufactureTaskItems.GroupBy(x => x.TaskId).Count() != 1) { return(Result.GenError <DataResult>(Error.ManufactureTaskNotExist)); } var taskId = manufactureTaskItems.First(x => x.TaskId != 0).TaskId; var cnt = ServerConfig.ApiDb.Query <int>("SELECT COUNT(1) FROM `manufacture_task` WHERE Id = @Id AND `MarkedDelete` = 0;", new { Id = taskId }).FirstOrDefault(); if (cnt == 0) { return(Result.GenError <DataResult>(Error.ManufactureTaskNotExist)); } if (manufactureTaskItems.Any(x => x.Item.IsNullOrEmpty())) { return(Result.GenError <DataResult>(Error.ManufactureTaskItemNotEmpty)); } var data = ServerConfig.ApiDb.Query <ManufactureTaskItem>("SELECT * FROM `manufacture_task_item` WHERE TaskId = @taskId AND MarkedDelete = 0;", new { taskId }); var update = false; var createUserId = Request.GetIdentityInformation(); var markedDateTime = DateTime.Now; if (manufactureTaskItems.GroupBy(x => x.Order).Any(y => y.Count() > 1)) { return(Result.GenError <DataResult>(Error.ManufactureTaskItemOrderDuplicate)); } var result = new DataResult(); manufactureTaskItems = manufactureTaskItems.OrderBy(x => x.Order); var error = 0; foreach (var manufactureTaskItem in manufactureTaskItems) { manufactureTaskItem.TaskId = taskId; if (error != 2 && manufactureTaskItem.Order <= manufactureTaskItem.Relation || (manufactureTaskItem.Relation != 0 && manufactureTaskItems.All(x => x.Order != manufactureTaskItem.Relation))) { error = 1; result.datas.Add(manufactureTaskItem.Item); } else if (error != 1 && manufactureTaskItem.IsCheck && manufactureTaskItem.Relation == 0) { error = 2; result.datas.Add(manufactureTaskItem.Item); } if (error != 0) { continue; } var item = data.FirstOrDefault(x => x.Id == manufactureTaskItem.Id); if (item != null) { manufactureTaskItem.Item = manufactureTaskItem.Item ?? item.Item; manufactureTaskItem.Desc = manufactureTaskItem.Desc ?? item.Desc; if (manufactureTaskItem.Item != item.Item || manufactureTaskItem.Desc != item.Desc || manufactureTaskItem.Order != item.Order || manufactureTaskItem.Person != item.Person || manufactureTaskItem.ModuleId != item.ModuleId || manufactureTaskItem.EstimatedHour != item.EstimatedHour || manufactureTaskItem.EstimatedMin != item.EstimatedMin || manufactureTaskItem.Score != item.Score || manufactureTaskItem.Relation != item.Relation) { update = true; manufactureTaskItem.MarkedDateTime = markedDateTime; } if (manufactureTaskItem.IsCheck != item.IsCheck) { update = true; manufactureTaskItem.MarkedDateTime = markedDateTime; } if (manufactureTaskItem.IsCheck && manufactureTaskItem.CheckId != item.CheckId) { update = true; manufactureTaskItem.MarkedDateTime = markedDateTime; } } else { manufactureTaskItem.CreateUserId = createUserId; manufactureTaskItem.MarkedDateTime = markedDateTime; manufactureTaskItem.Desc = manufactureTaskItem.Desc ?? ""; } } if (result.datas.Any()) { result.errno = error == 1 ? Error.ManufactureTaskItemRelationError : Error.ManufactureCheckItemNoRelation; return(result); } #region 更新 var updateItems = manufactureTaskItems.Where(x => x.Id != 0 && data.Any(y => y.Id == x.Id) && ClassExtension.HaveChange(data.First(y => y.Id == x.Id), x)); if (updateItems.Any() && update) { ServerConfig.ApiDb.Execute("UPDATE manufacture_task_item SET `MarkedDateTime` = @MarkedDateTime, `Order` = @Order, `Person` = @Person, `ModuleId` = @ModuleId, `IsCheck` = @IsCheck, " + "`CheckId` = @CheckId, `Item` = @Item, `EstimatedHour` = @EstimatedHour, `EstimatedMin` = @EstimatedMin, `Score` = @Score, `Desc` = @Desc, `Relation` = @Relation WHERE `Id` = @Id;", updateItems); } #endregion #region 除 var delItems = data.Where(x => manufactureTaskItems.All(y => y.Id != x.Id)); if (delItems.Any()) { foreach (var delItem in delItems) { delItem.MarkedDateTime = markedDateTime; delItem.MarkedDelete = true; } ServerConfig.ApiDb.Execute("UPDATE `manufacture_task_item` SET `MarkedDateTime`= @MarkedDateTime, `MarkedDelete`= @MarkedDelete WHERE `Id` = @Id;", delItems); } #endregion #region 添加 var addItems = manufactureTaskItems.Where(x => x.Id == 0); if (addItems.Any()) { ServerConfig.ApiDb.Execute( "INSERT INTO manufacture_task_item (`CreateUserId`, `MarkedDateTime`, `TaskId`, `Order`, `Person`, `ModuleId`, `IsCheck`, `CheckId`, `Item`, `EstimatedHour`, `EstimatedMin`, `Score`, `Desc`, `Relation`) " + "VALUES (@CreateUserId, @MarkedDateTime, @TaskId, @Order, @Person, @ModuleId, @IsCheck, @CheckId, @Item, @EstimatedHour, @EstimatedMin, @Score, @Desc, @Relation);", addItems); } #endregion return(Result.GenError <DataResult>(Error.Success)); }
public Result PutProcessManagement([FromBody] Models.ProcessManagement.ProcessManagement processManagement) { var pms = ProcessManagementHelper.Instance.GetAll <Models.ProcessManagement.ProcessManagement>(); if (pms.All(x => x.Id != processManagement.Id)) { return(Result.GenError <DataResult>(Error.ProcessManagementNotExist)); } if (pms.Any(x => x.Id != processManagement.Id && x.ProcessNumber == processManagement.ProcessNumber)) { return(Result.GenError <DataResult>(Error.ProcessManagementIsExist)); } var old = pms.First(x => x.Id == processManagement.Id); var change = ClassExtension.HaveChange(old, processManagement); if (!change) { return(Result.GenError <Result>(Error.Success)); } pms = pms.Where(x => x.Id != processManagement.Id); try { var workshopId = 1; var deviceModelList = processManagement.DeviceModelList; if (deviceModelList.Any()) { var cnt = DeviceModelHelper.Instance.GetCountByIds(deviceModelList); if (deviceModelList.Count() != cnt) { return(Result.GenError <Result>(Error.DeviceModelNotExist)); } } else { return(Result.GenError <Result>(Error.DeviceModelNotExist)); } var deviceIdList = processManagement.DeviceIdList; if (deviceIdList.Any()) { var deviceLibraries = DeviceHelper.GetDetailsByModelIds(workshopId, processManagement.DeviceModelList).ToDictionary(x => x.Id); if (deviceIdList.Any(x => !deviceLibraries.ContainsKey(x))) { return(Result.GenError <Result>(Error.DeviceNotExist)); } var rawMaterial = processManagement.RawMaterial; if (rawMaterial.IsNullOrEmpty()) { var productionList = processManagement.ProductionList; pms = pms.Where(x => x.RawMaterial.IsNullOrEmpty()); if (productionList.Any()) { var cnt = ProductionHelper.Instance.GetCountByIds(processManagement.ProductionList); if (productionList.Count() != cnt) { return(Result.GenError <Result>(Error.ProductionNotExist)); } var pManagements = pms.Where(x => x.ProductionList.Any(y => productionList.Contains(y))); if (pManagements.Any(x => x.DeviceIdList.Any(y => deviceIdList.Contains(y)))) { return(Result.GenError <Result>(Error.ProcessManagementAddError)); } } else { return(Result.GenError <Result>(Error.ProductionNotExist)); } } else { pms = pms.Where(x => !x.RawMaterial.IsNullOrEmpty()); var pManagements = pms.Where(x => x.RawMaterial == rawMaterial); if (pManagements.Any(x => x.DeviceIdList.Any(y => deviceIdList.Contains(y)))) { return(Result.GenError <Result>(Error.ProcessManagementAddRawMaterialError)); } } } else { processManagement.DeviceIds = ""; } } catch (Exception) { return(Result.GenError <Result>(Error.Fail)); } var createUserId = Request.GetIdentityInformation(); var time = DateTime.Now; processManagement.CreateUserId = createUserId; processManagement.MarkedDateTime = time; ProcessManagementHelper.Instance.Update(processManagement); var processData = processManagement.ProcessData; var i = 1; foreach (var pd in processData) { pd.ProcessOrder = i++; pd.ProcessManagementId = processManagement.Id; pd.CreateUserId = createUserId; pd.MarkedDateTime = time; } var exist = ProcessDataHelper.Instance.GetFromParent <ProcessData>(processManagement.Id); var add = processData.Where(x => x.Id == 0); if (add.Any()) { ProcessDataHelper.Instance.Add(add); } var update = processData.Where(x => x.Id != 0 && exist.Any(y => y.Id == x.Id && ClassExtension.HaveChange(x, y))); if (update.Any()) { ProcessDataHelper.Instance.Update(update); } var del = exist.Where(x => processData.All(y => y.Id != x.Id)).Select(x => x.Id); if (del.Any()) { ProcessDataHelper.Instance.Delete(del); } return(Result.GenError <Result>(Error.Success)); }
/// <summary> /// /// </summary> /// <returns></returns> public static void AddOrUpdate(IEnumerable <MonitoringKanBan> kanBans) { if (kanBans != null && kanBans.Any()) { var workshopIds = kanBans.Select(x => x.WorkshopId).Distinct(); var dates = kanBans.Select(x => x.Date).Distinct(); var ids = kanBans.Select(x => x.Id).Distinct(); var data = GetDetails(dates, workshopIds, ids); var add = kanBans.Where(x => !data.Any(y => y.Date == x.Date && y.Id == x.Id && y.WorkshopId == x.WorkshopId)); if (add.Any()) { ServerConfig.ApiDb.Execute( "INSERT INTO kanban_log (`Date`, `Time`, `Id`, `WorkshopId`, `AllDevice`, `NormalDevice`, `ProcessDevice`, `IdleDevice`, `FaultDevice`, `ConnectErrorDevice`, `MaxUse`, `UseListStr`, " + "`MaxUseListStr`, `MaxUseRate`, `MinUse`, `MinUseRate`, `MaxSimultaneousUseRate`, `MinSimultaneousUseRate`, `SingleProcessRateStr`, `AllProcessRate`, `RunTime`, `ProcessTime`, `IdleTime`, " + "`DayTotal`, `DayQualified`, `DayUnqualified`, `DayQualifiedRate`, `DayUnqualifiedRate`, " + "`ProductionData`) " + "VALUES (@Date, @Time, @Id, @WorkshopId, @AllDevice, @NormalDevice, @ProcessDevice, @IdleDevice, @FaultDevice, @ConnectErrorDevice, @MaxUse, @UseListStr, " + "@MaxUseListStr ,@MaxUseRate, @MinUse, @MinUseRate, @MaxSimultaneousUseRate, @MinSimultaneousUseRate, @SingleProcessRateStr, @AllProcessRate, @RunTime, @ProcessTime, @IdleTime, " + "@DayTotal, @DayQualified, @DayUnqualified, @DayQualifiedRate, @DayUnqualifiedRate, " + "@ProductionData) " + "ON DUPLICATE KEY UPDATE `Time` = @Time, `AllDevice` = @AllDevice, `NormalDevice` = @NormalDevice, `ProcessDevice` = @ProcessDevice, `IdleDevice` = @IdleDevice, " + "`FaultDevice` = @FaultDevice, `ConnectErrorDevice` = @ConnectErrorDevice, `MaxUse` = @MaxUse, `MaxUseListStr` = @MaxUseListStr, `UseListStr` = @UseListStr, " + "`MaxUseRate` = @MaxUseRate, `MinUse` = @MinUse, `MinUseRate` = @MinUseRate, `MaxSimultaneousUseRate` = @MaxSimultaneousUseRate, `MinSimultaneousUseRate` = @MinSimultaneousUseRate, " + "`SingleProcessRateStr` = @SingleProcessRateStr, `AllProcessRate` = @AllProcessRate, `RunTime` = @RunTime, `ProcessTime` = @ProcessTime, `IdleTime` = @IdleTime, " + "`DayTotal` = @DayTotal, `DayQualified` = @DayQualified, `DayUnqualified` = @DayUnqualified, `DayQualifiedRate` = @DayQualifiedRate, `DayUnqualifiedRate` = @DayUnqualifiedRate, " + "`ProductionData` = @ProductionData, `VariableData` = @VariableData;" , add, 1000); } var update = kanBans.Where(x => data.Any(y => y.Date == x.Date && y.Id == x.Id && y.WorkshopId == x.WorkshopId && ClassExtension.HaveChange(x, y))); if (update.Any()) { ServerConfig.ApiDb.Execute( "UPDATE kanban_log SET `Time` = @Time, `AllDevice` = @AllDevice, `NormalDevice` = @NormalDevice, `ProcessDevice` = @ProcessDevice, `IdleDevice` = @IdleDevice, " + "`FaultDevice` = @FaultDevice, `ConnectErrorDevice` = @ConnectErrorDevice, `MaxUse` = @MaxUse, `MaxUseListStr` = @MaxUseListStr, `UseListStr` = @UseListStr, " + "`MaxUseRate` = @MaxUseRate, `MinUse` = @MinUse, `MinUseRate` = @MinUseRate, `MaxSimultaneousUseRate` = @MaxSimultaneousUseRate, `MinSimultaneousUseRate` = @MinSimultaneousUseRate, " + "`SingleProcessRateStr` = @SingleProcessRateStr, `AllProcessRate` = @AllProcessRate, `RunTime` = @RunTime, `ProcessTime` = @ProcessTime, `IdleTime` = @IdleTime, " + "`DayTotal` = @DayTotal, `DayQualified` = @DayQualified, `DayUnqualified` = @DayUnqualified, `DayQualifiedRate` = @DayQualifiedRate, `DayUnqualifiedRate` = @DayUnqualifiedRate, " + "`ProductionData` = @ProductionData, `VariableData` = @VariableData WHERE Date = @Date AND Id = @Id AND WorkshopId = @WorkshopId;" , update, 1000); } } }
/// <summary> /// /// </summary> /// <returns></returns> public static void AddOrUpdate(IEnumerable <MonitoringProcess> devices) { if (devices != null && devices.Any()) { var dates = devices.Select(x => x.Date).Distinct(); var dIds = devices.Select(x => x.DeviceId).Distinct(); var data = GetDetails(dates, dIds); var add = devices.Where(x => !data.Any(y => y.Date == x.Date && y.DeviceId == x.DeviceId)); if (add.Any()) { //ServerConfig.ApiDb.Execute( // "INSERT INTO kanban_device_state (`Date`, `Time`, `DeviceId`, `NormalDevice`, `ProcessDevice`, `IdleDevice`, `FaultDevice`, `UsedDevice`, `ProcessCount`, `ProcessTime`, `IdleTime`, `RunTime`, " + // "`ProcessTimeRate`, `TotalProcessCount`, `TotalProcessTime`, `TotalIdleTime`, `TotalRunTime`, `StartTime`, `EndTime`, `Data`, `DayTotal`, `DayQualified`, `DayUnqualified`, " + // "`DayQualifiedRate`, `DayUnqualifiedRate`, `LastTotal`, `LastQualified`, `LastUnqualified`, `LastQualifiedRate`, `LastUnqualifiedRate`, `DeviceWarnings`, `ProductWarnings`) " + // "VALUES (@Date, @Time, @DeviceId, @NormalDevice, @ProcessDevice, @IdleDevice, @FaultDevice, @UsedDevice, @ProcessCount, @ProcessTime, @IdleTime, @RunTime, @ProcessTimeRate, " + // "@TotalProcessCount, @TotalProcessTime, @TotalIdleTime, @TotalRunTime, @StartTime, @EndTime, @Data, @DayTotal, @DayQualified, @DayUnqualified, @DayQualifiedRate, " + // "@DayUnqualifiedRate, @LastTotal, @LastQualified, @LastUnqualified, @LastQualifiedRate, @LastUnqualifiedRate, @DeviceWarnings, @ProductWarnings);" // , add, 1000); ServerConfig.ApiDb.Execute( "INSERT INTO kanban_device_state (`Date`, `Time`, `DeviceId`, `NormalDevice`, `ProcessDevice`, `IdleDevice`, `FaultDevice`, `UsedDevice`, `ProcessCount`, `ProcessTime`, `IdleTime`, `RunTime`, " + "`ProcessTimeRate`, `TotalProcessCount`, `TotalProcessTime`, `TotalIdleTime`, `TotalRunTime`, `StartTime`, `EndTime`, `Data`, `DayTotal`, `DayQualified`, `DayUnqualified`, " + "`DayQualifiedRate`, `DayUnqualifiedRate`, `LastTotal`, `LastQualified`, `LastUnqualified`, `LastQualifiedRate`, `LastUnqualifiedRate`, `DeviceWarnings`, `ProductWarnings`) " + "VALUES (@Date, @Time, @DeviceId, @NormalDevice, @ProcessDevice, @IdleDevice, @FaultDevice, @UsedDevice, @ProcessCount, @ProcessTime, @IdleTime, @RunTime, @ProcessTimeRate, " + "@TotalProcessCount, @TotalProcessTime, @TotalIdleTime, @TotalRunTime, @StartTime, @EndTime, @Data, @DayTotal, @DayQualified, @DayUnqualified, @DayQualifiedRate, " + "@DayUnqualifiedRate, @LastTotal, @LastQualified, @LastUnqualified, @LastQualifiedRate, @LastUnqualifiedRate, @DeviceWarnings, @ProductWarnings) " + "ON DUPLICATE KEY UPDATE `Time` = @Time, `DeviceId` = @DeviceId, `NormalDevice` = @NormalDevice, `ProcessDevice` = @ProcessDevice, `IdleDevice` = @IdleDevice, " + "`FaultDevice` = @FaultDevice, `UsedDevice` = @UsedDevice, `ProcessCount` = @ProcessCount, `ProcessTime` = @ProcessTime, `IdleTime` = @IdleTime, `RunTime` = @RunTime, " + "`ProcessTimeRate` = @ProcessTimeRate, `TotalProcessCount` = @TotalProcessCount, `TotalProcessTime` = @TotalProcessTime, `TotalIdleTime` = @TotalIdleTime, " + "`TotalRunTime` = @TotalRunTime, `StartTime` = @StartTime, `EndTime` = @EndTime, `Data` = @Data, `DayTotal` = @DayTotal, `DayQualified` = @DayQualified, " + "`DayUnqualified` = @DayUnqualified, `DayQualifiedRate` = @DayQualifiedRate, `DayUnqualifiedRate` = @DayUnqualifiedRate, `LastTotal` = @LastTotal, " + "`LastQualified` = @LastQualified, `LastUnqualified` = @LastUnqualified, `LastQualifiedRate` = @LastQualifiedRate, `LastUnqualifiedRate` = @LastUnqualifiedRate, " + "`DeviceWarnings` = @DeviceWarnings, `ProductWarnings` = @ProductWarnings;", add, 1000); } var update = devices.Where(x => data.Any(y => y.Date == x.Date && y.DeviceId == x.DeviceId && ClassExtension.HaveChange(x, y))); if (update.Any()) { ServerConfig.ApiDb.Execute( "UPDATE kanban_device_state SET `Time` = @Time, `DeviceId` = @DeviceId, `NormalDevice` = @NormalDevice, `ProcessDevice` = @ProcessDevice, `IdleDevice` = @IdleDevice, " + "`FaultDevice` = @FaultDevice, `UsedDevice` = @UsedDevice, `ProcessCount` = @ProcessCount, `ProcessTime` = @ProcessTime, `IdleTime` = @IdleTime, `RunTime` = @RunTime, " + "`ProcessTimeRate` = @ProcessTimeRate, `TotalProcessCount` = @TotalProcessCount, `TotalProcessTime` = @TotalProcessTime, `TotalIdleTime` = @TotalIdleTime, " + "`TotalRunTime` = @TotalRunTime, `StartTime` = @StartTime, `EndTime` = @EndTime, `Data` = @Data, `DayTotal` = @DayTotal, `DayQualified` = @DayQualified, " + "`DayUnqualified` = @DayUnqualified, `DayQualifiedRate` = @DayQualifiedRate, `DayUnqualifiedRate` = @DayUnqualifiedRate, `LastTotal` = @LastTotal, " + "`LastQualified` = @LastQualified, `LastUnqualified` = @LastUnqualified, `LastQualifiedRate` = @LastQualifiedRate, `LastUnqualifiedRate` = @LastUnqualifiedRate, " + "`DeviceWarnings` = @DeviceWarnings, `ProductWarnings` = @ProductWarnings WHERE Date = @Date AND DeviceId = @DeviceId;" , update, 1000); } //ServerConfig.ApiDb.Execute( // "INSERT INTO kanban_device_state (`Date`, `Time`, `DeviceId`, `NormalDevice`, `ProcessDevice`, `IdleDevice`, `FaultDevice`, `UsedDevice`, `ProcessCount`, `ProcessTime`, `IdleTime`, `RunTime`, " + // "`ProcessTimeRate`, `TotalProcessCount`, `TotalProcessTime`, `TotalIdleTime`, `TotalRunTime`, `StartTime`, `EndTime`, `Data`, `DayTotal`, `DayQualified`, `DayUnqualified`, " + // "`DayQualifiedRate`, `DayUnqualifiedRate`, `LastTotal`, `LastQualified`, `LastUnqualified`, `LastQualifiedRate`, `LastUnqualifiedRate`, `DeviceWarnings`, `ProductWarnings`) " + // "VALUES (@Date, @Time, @DeviceId, @NormalDevice, @ProcessDevice, @IdleDevice, @FaultDevice, @UsedDevice, @ProcessCount, @ProcessTime, @IdleTime, @RunTime, @ProcessTimeRate, " + // "@TotalProcessCount, @TotalProcessTime, @TotalIdleTime, @TotalRunTime, @StartTime, @EndTime, @Data, @DayTotal, @DayQualified, @DayUnqualified, @DayQualifiedRate, " + // "@DayUnqualifiedRate, @LastTotal, @LastQualified, @LastUnqualified, @LastQualifiedRate, @LastUnqualifiedRate, @DeviceWarnings, @ProductWarnings) " + // "ON DUPLICATE KEY UPDATE `Time` = @Time, `DeviceId` = @DeviceId, `NormalDevice` = @NormalDevice, `ProcessDevice` = @ProcessDevice, `IdleDevice` = @IdleDevice, " + // "`FaultDevice` = @FaultDevice, `UsedDevice` = @UsedDevice, `ProcessCount` = @ProcessCount, `ProcessTime` = @ProcessTime, `IdleTime` = @IdleTime, `RunTime` = @RunTime, " + // "`ProcessTimeRate` = @ProcessTimeRate, `TotalProcessCount` = @TotalProcessCount, `TotalProcessTime` = @TotalProcessTime, `TotalIdleTime` = @TotalIdleTime, " + // "`TotalRunTime` = @TotalRunTime, `StartTime` = @StartTime, `EndTime` = @EndTime, `Data` = @Data, `DayTotal` = @DayTotal, `DayQualified` = @DayQualified, " + // "`DayUnqualified` = @DayUnqualified, `DayQualifiedRate` = @DayQualifiedRate, `DayUnqualifiedRate` = @DayUnqualifiedRate, `LastTotal` = @LastTotal, " + // "`LastQualified` = @LastQualified, `LastUnqualified` = @LastUnqualified, `LastQualifiedRate` = @LastQualifiedRate, `LastUnqualifiedRate` = @LastUnqualifiedRate, " + // "`DeviceWarnings` = @DeviceWarnings, `ProductWarnings` = @ProductWarnings;", devices, 60); } }
public Result PutSmartProcessCodeCategory([FromBody] IEnumerable <SmartProcessCodeCategoryDetail> processCodeCategories) { if (processCodeCategories == null || !processCodeCategories.Any()) { return(Result.GenError <Result>(Error.ParamError)); } if (processCodeCategories.Any(x => x.Category.IsNullOrEmpty())) { return(Result.GenError <Result>(Error.SmartProcessCodeCategoryNotEmpty)); } if (processCodeCategories.GroupBy(x => x.Category).Any(y => y.Count() > 1)) { return(Result.GenError <Result>(Error.SmartProcessCodeCategoryDuplicate)); } var wId = processCodeCategories.FirstOrDefault()?.WorkshopId ?? 0; var sames = processCodeCategories.Select(x => x.Category); var ids = processCodeCategories.Select(x => x.Id); if (SmartProcessCodeCategoryHelper.GetHaveSame(wId, sames, ids)) { return(Result.GenError <Result>(Error.SmartProcessCodeCategoryIsExist)); } var cnt = SmartProcessCodeCategoryHelper.Instance.GetCountByIds(ids); if (cnt != processCodeCategories.Count()) { return(Result.GenError <Result>(Error.SmartProcessCodeCategoryNotExist)); } var processCodeCategoryIds = processCodeCategories.Select(x => x.Id); var data = SmartProcessCodeCategoryHelper.Instance.GetByIds <SmartProcessCodeCategory>(processCodeCategoryIds); if (data.Count() != processCodeCategories.Count()) { return(Result.GenError <Result>(Error.SmartProcessCodeCategoryNotExist)); } var userId = Request.GetIdentityInformation(); var markedDateTime = DateTime.Now; var add = new List <SmartProcessCodeCategoryProcess>(); var update = new List <SmartProcessCodeCategoryProcess>(); var exist = SmartProcessCodeCategoryProcessHelper.GetDetailByCategoryId(processCodeCategories.Select(x => x.Id)); foreach (var processCodeCategory in processCodeCategories) { processCodeCategory.CreateUserId = userId; processCodeCategory.MarkedDateTime = markedDateTime; processCodeCategory.Remark = processCodeCategory.Remark ?? ""; processCodeCategory.Processes = processCodeCategory.Processes.Select(x => { x.ProcessCodeCategoryId = processCodeCategory.Id; return(x); }); var categoryProcesses = exist.Where(x => x.ProcessCodeCategoryId == processCodeCategory.Id); if (processCodeCategory.Processes != null && processCodeCategory.Processes.Any()) { add.AddRange(processCodeCategory.Processes.Where(x => x.Id == 0 && categoryProcesses.FirstOrDefault(a => a.Order == x.Order && a.ProcessId == x.ProcessId) == null) .Select(y => { y.CreateUserId = userId; y.MarkedDateTime = markedDateTime; y.ProcessCodeCategoryId = processCodeCategory.Id; return(y); })); update.AddRange(processCodeCategory.Processes .Where(x => categoryProcesses.Any(y => y.Id == x.Id) && (ClassExtension.HaveChange(categoryProcesses.First(y => y.Id == x.Id), x))).Select(z => //|| (x.Id == 0 && categoryProcesses.FirstOrDefault(a => a.Order == x.Order && a.ProcessId == x.ProcessId) != null)).Select(z => { var first = categoryProcesses.First(a => a.Id == z.Id); z.Id = first.Id; z.MarkedDateTime = markedDateTime; return(z); })); update.AddRange(categoryProcesses.Where(x => processCodeCategory.Processes.All(y => y.Id != x.Id)).Select(z => { z.MarkedDateTime = markedDateTime; z.MarkedDelete = true; return(z); })); } else { update.AddRange(categoryProcesses.Select(x => { x.MarkedDateTime = markedDateTime; x.MarkedDelete = true; return(x); })); } } if (add.Any()) { SmartProcessCodeCategoryProcessHelper.Instance.Add <SmartProcessCodeCategoryProcess>(add); } if (update.Any()) { SmartProcessCodeCategoryProcessHelper.Instance.Update <SmartProcessCodeCategoryProcess>(update); } SmartProcessCodeCategoryHelper.Instance.Update(processCodeCategories); return(Result.GenError <Result>(Error.Success)); }
public object PutOrder([FromBody] IEnumerable <OrderDetail> details) { if (details == null || !details.Any()) { return(Result.GenError <Result>(Error.ParamError)); } if (details.Any(x => x.Id == 0)) { return(Result.GenError <Result>(Error.OrderNotExist)); } if (details.Any(x => x.ExNumber.IsNullOrEmpty())) { return(Result.GenError <Result>(Error.OrderNotEmpty)); } if (details.GroupBy(x => x.ExNumber).Any(y => y.Count() > 1)) { return(Result.GenError <Result>(Error.OrderDuplicate)); } if (details.Count(detail => detail.Pros.GroupBy(x => x.DeliveryTime).Any(y => y.Count() > 1)) > 0) { return(Result.GenError <Result>(Error.OrderProductionDuplicate)); } var userId = Request.GetIdentityInformation(); var markedDateTime = DateTime.Now; foreach (var detail in details) { detail.CreateUserId = userId; detail.MarkedDateTime = markedDateTime; detail.CreateTime = markedDateTime; detail.List = detail.Pros?.Select(x => x.ProductionId).Distinct().Join() ?? ""; detail.DeliveryTime = detail.Pros?.Max(x => x.DeliveryTime) ?? default(DateTime); detail.Count = detail.Pros?.Sum(x => x.Count) ?? 0; detail.Pros = detail.Pros ?? new List <OrderProductionDetail>(); foreach (var d in detail.Pros) { d.OrderId = detail.Id; } detail.Remark = detail.Remark ?? ""; } if (details.Count(detail => detail.Pros.GroupBy(x => x.DeliveryTime).Any(y => y.Count() > 1)) > 0) { return(Result.GenError <Result>(Error.OrderProductionDuplicate)); } var sames = details.Select(x => x.ExNumber); var ids = details.Select(x => x.Id); if (OrderHelper.GetHaveSame(sames, ids)) { return(Result.GenError <Result>(Error.OrderIsExist)); } var oIds = details.Select(x => x.Id); var pIds = details.SelectMany(x => x.PIds); var sameDs = details.SelectMany(x => x.Pros.Select(y => y.DeliveryTime)); var opIds = details.SelectMany(x => x.Pros.Select(y => y.Id)); if (OrderProductionHelper.GetHaveSame(oIds, pIds, sameDs, opIds)) { return(Result.GenError <Result>(Error.OrderProductionIsExist)); } var oldOrders = OrderHelper.GetDetails(oIds).ToDictionary(x => x.Id); if (oldOrders.Count != oIds.Count()) { return(Result.GenError <Result>(Error.OrderNotExist)); } var upOrders = details.Where(x => ClassExtension.HaveChange(x, oldOrders[x.Id], true)); if (upOrders.Any()) { OrderHelper.Instance.Update(upOrders); } var oldOrderProductions = OrderProductionHelper.GetDetails(oIds, pIds); var add = new List <OrderProduction>(); var up = new List <OrderProduction>(); var del = new List <OrderProduction>(); foreach (var detail in details) { var oldOPs = oldOrderProductions.Where(x => x.OrderId == detail.Id).ToDictionary(x => x.Id); del.AddRange(oldOPs.Where(x => detail.Pros.All(y => y.Id != x.Key)).Select(x => x.Value)); foreach (var pro in detail.Pros) { if (oldOPs.ContainsKey(pro.Id)) { if (ClassExtension.HaveChange(pro, oldOPs[pro.Id], true)) { pro.MarkedDateTime = markedDateTime; pro.Remark = pro.Remark ?? ""; up.Add(pro); } } else { add.Add(pro); } } } if (add.Any()) { OrderProductionHelper.Instance.Add(add); } if (up.Any()) { OrderProductionHelper.Instance.Update <OrderProduction>(up); } if (del.Any()) { OrderProductionHelper.Instance.Delete(del.Select(x => x.Id)); } return(Result.GenError <Result>(Error.Success)); }
public Result PutSet([FromBody] WarningSetWithItems set) { var oldSet = WarningSetHelper.Instance.Get <WarningSet>(set.Id); if (oldSet == null) { return(Result.GenError <Result>(Error.WarningSetNotExist)); } if (set.Name.IsNullOrEmpty()) { return(Result.GenError <Result>(Error.WarningSetNotEmpty)); } if (set.DataType == WarningDataType.生产数据 && set.StepId == set.BindId) { return(Result.GenError <Result>(Error.WarningSetStepBindDuplicate)); } var names = new List <string> { set.Name }; var ids = new List <int> { set.Id }; if (WarningSetHelper.GetHaveSame(1, names, ids)) { return(Result.GenError <Result>(Error.WarningSetIsExist)); } var createUserId = Request.GetIdentityInformation(); var markedDateTime = DateTime.Now; if (set.Items != null) { if (set.Items.Any()) { switch (set.DataType) { case WarningDataType.设备数据: set.Items = set.Items.Where(x => x.DictionaryId != 0).ToList(); foreach (var item in set.Items) { item.Item = ""; } break; case WarningDataType.生产数据: set.Items = set.Items.Where(x => x.ItemType != WarningItemType.Default).ToList(); foreach (var item in set.Items) { if (HWarningHelper.生产数据单设备加工信息字段.All(x => x.Item2 != item.ItemType)) { item.DeviceIds = set.DeviceIds; } } break; case WarningDataType.故障数据: set.Items = set.Items; break; case WarningDataType.流程卡数据: set.Items = set.Items.Where(x => x.ItemType != WarningItemType.Default).ToList(); break; default: set.Items.Clear(); break; } //if (set.Items.Any(x => !x.ValidDataType())) //{ // return Result.GenError<Result>(Error.WarningSetItemDataTypeError); //} foreach (var item in set.Items) { item.MarkedDateTime = markedDateTime; item.SetId = set.Id; } if (set.Items.Any(x => x.ItemType == WarningItemType.SpecifyStepTimeOut && x.StepId == 0)) { return(Result.GenError <Result>(Error.WarningSetItemFlowCardStepError)); } if (set.Items.Any(x => !x.ValidFrequency())) { return(Result.GenError <Result>(Error.WarningSetItemFrequencyError)); } if (set.Items.Any(x => !x.ValidCondition())) { return(Result.GenError <Result>(Error.WarningSetItemConditionError)); } var oldWarningSetItems = WarningSetItemHelper.GetWarningSetItemsBySetId(set.Id); var delItems = oldWarningSetItems.Where(x => set.Items.All(y => y.Id != x.Id)); if (delItems.Any()) { WarningSetItemHelper.Instance.Delete(delItems.Select(x => x.Id)); } var updateItems = set.Items.Where(x => x.Id != 0); if (updateItems.Any()) { var uIds = new List <int>(); foreach (var item in updateItems) { var oldItem = oldWarningSetItems.FirstOrDefault(x => x.Id == item.Id); if (oldItem != null && ClassExtension.HaveChange(oldItem, item)) { if (HWarningHelper.生产数据单设备加工信息字段.All(x => x.Item2 != item.ItemType)) { item.DeviceIds = set.DeviceIds; } uIds.Add(item.Id); } } WarningSetItemHelper.Instance.Update(updateItems.Where(x => uIds.Contains(x.Id))); } var newItems = set.Items.Where(x => x.Id == 0); if (newItems.Any()) { foreach (var item in newItems) { item.CreateUserId = createUserId; } WarningSetItemHelper.Instance.Add(newItems); } } else { WarningSetItemHelper.Instance.DeleteFromParent(set.Id); } } if (ClassExtension.HaveChange(oldSet, set)) { set.MarkedDateTime = markedDateTime; WarningSetHelper.Instance.Update(set); } HWarningHelper.UpdateConfig(); return(Result.GenError <Result>(Error.Success)); }
public Result PutRawMaterial([FromBody] RawMaterial rawMaterial) { if (rawMaterial == null) { return(Result.GenError <Result>(Error.ParamError)); } if (rawMaterial.RawMaterialName.IsNullOrEmpty()) { return(Result.GenError <Result>(Error.RawMaterialNotExist)); } var sames = new List <string> { rawMaterial.RawMaterialName }; var ids = new List <int> { rawMaterial.Id }; if (RawMaterialHelper.GetHaveSame(sames, ids)) { return(Result.GenError <Result>(Error.RawMaterialIsExist)); } var data = RawMaterialHelper.Instance.Get <RawMaterial>(rawMaterial.Id); if (data == null) { return(Result.GenError <Result>(Error.RawMaterialNotExist)); } var createUserId = Request.GetIdentityInformation(); var time = DateTime.Now; var change = false; //if (rawMaterial.RawMaterialSpecifications.Any()) { var specifications = rawMaterial.Specifications; foreach (var specification in specifications) { specification.RawMaterialId = rawMaterial.Id; specification.CreateUserId = createUserId; specification.MarkedDateTime = time; } if (specifications.Any(x => x.Id == 0)) { change = true; RawMaterialSpecificationHelper.Instance.Add(specifications.Where(x => x.Id == 0)); } var existSpecifications = RawMaterialSpecificationHelper.Instance.GetFromParent <RawMaterialSpecification>(rawMaterial.Id); var updateSpecifications = specifications.Where(x => x.Id != 0 && existSpecifications.Any(y => y.Id == x.Id && (y.SpecificationName != x.SpecificationName || y.SpecificationValue != x.SpecificationValue))).ToList(); updateSpecifications.AddRange(existSpecifications.Where(x => specifications.All(y => x.Id != y.Id)).Select(x => { x.MarkedDateTime = DateTime.Now; x.MarkedDelete = true; return(x); })); if (updateSpecifications.Any()) { change = true; RawMaterialSpecificationHelper.Instance.Update <RawMaterialSpecification>(updateSpecifications); } } if (change || ClassExtension.HaveChange(rawMaterial, data)) { rawMaterial.MarkedDateTime = time; RawMaterialHelper.Instance.Update(rawMaterial); } return(Result.GenError <Result>(Error.Success)); }
public object PutProduction([FromBody] IEnumerable <ProductionDetail> details) { if (details == null || !details.Any()) { return(Result.GenError <Result>(Error.ParamError)); } if (details.Any(x => x.Id == 0)) { return(Result.GenError <Result>(Error.ProductionNotExist)); } if (details.Any(x => x.Name.IsNullOrEmpty())) { var ids = details.Select(x => x.Id); var cnt = ProductionHelper.Instance.GetCountByIds(ids); if (cnt != details.Count()) { return(Result.GenError <Result>(Error.ProductionNotExist)); } var markedDateTime = DateTime.Now; foreach (var detail in details) { detail.MarkedDateTime = markedDateTime; } ProductionHelper.Enable(details); } else { if (details.GroupBy(x => x.Name).Any(y => y.Count() > 1)) { return(Result.GenError <Result>(Error.ProductionDuplicate)); } if (details.Any(x => x.StepIds.Count != x.Rates.Count || x.StepIds.Count != x.Costs.Count)) { return(Result.GenError <Result>(Error.ProductionCapacityListError)); } var ids = details.Select(x => x.Id); var data = ProductionHelper.Instance.GetByIds <Production>(ids); if (data.Count() != details.Count()) { return(Result.GenError <Result>(Error.ProductionNotExist)); } var wId = details.FirstOrDefault()?.WorkshopId ?? 0; var userId = Request.GetIdentityInformation(); var markedDateTime = DateTime.Now; foreach (var detail in details) { detail.CreateUserId = userId; detail.MarkedDateTime = markedDateTime; detail.Remark = detail.Remark ?? ""; detail.FlowList = detail.Args?.Select(x => x.FlowId).Distinct().Join() ?? ""; foreach (var arg in detail.Args) { arg.WorkshopId = wId; arg.CreateUserId = userId; arg.MarkedDateTime = markedDateTime; arg.ProductionId = detail.Id; arg.Para = arg.Para ?? ""; arg.Other = arg.Other ?? ""; } } var newDetails = details.Where(x => ClassExtension.HaveChange(x, data.First(y => y.Id == x.Id))); if (newDetails.Any()) { var tIds = newDetails.Select(x => x.TypeId).Distinct(); var flowTypes = FlowTypeHelper.Instance.GetByIds <FlowType>(tIds).ToDictionary(x => x.Id); if (tIds.Count() != flowTypes.Count) { return(Result.GenError <Result>(Error.FlowTypeNotExist)); } var cIds = newDetails.Select(x => x.CapacityId).Distinct(); var cnt = CapacityHelper.Instance.GetCountByIds(cIds); if (cIds.Count() != cnt) { return(Result.GenError <Result>(Error.CapacityNotExist)); } var aTypeFlows = FlowCodeHelper.GetDetails(wId, null, tIds); var flowIds = newDetails.SelectMany(x => x.FlowIds).Distinct(); if (flowIds.Any(x => aTypeFlows.All(y => y.Id != x))) { return(Result.GenError <Result>(Error.FlowCodeNotExist)); } var typeFlows = aTypeFlows.Where(x => flowIds.Contains(x.Id)); var flowCodes = typeFlows.ToDictionary(x => x.Id); if (flowIds.Count() != flowCodes.Count) { return(Result.GenError <Result>(Error.FlowCodeNotExist)); } if (newDetails.Count(detail => { var fIds = detail.Args.Select(arg => arg.FlowId).Distinct(); return(fIds.Any(fId => { var mFcDic = detail.Args.Where(x => x.FlowId == fId).GroupBy(x => x.StepId).ToDictionary(y => y.Key, y => y.Count()); var fcDic = flowCodes[fId].StepIds.GroupBy(y => y).ToDictionary(y => y.Key, y => y.Count()); return detail.Args.Count(x => x.FlowId == fId) != flowCodes[fId].StepIds.Count || mFcDic.Any(x => x.Value != fcDic[x.Key]); })); }) > 0) { return(Result.GenError <Result>(Error.ProductionFlowCodeStepCountError)); } var sames = newDetails.Select(x => x.Name); if (ProductionHelper.GetHaveSame(wId, sames, ids)) { return(Result.GenError <Result>(Error.ProductionIsExist)); } var stepIds = newDetails.SelectMany(x => x.StepIds).Distinct(); if (stepIds.Any()) { var steps = FlowStepHelper.Instance.GetByIds <FlowStep>(stepIds).ToDictionary(x => x.Id); var formatIds = steps.Values.Select(x => x.FormatId).Distinct(); if (formatIds.Any()) { var formats = ArgsFormatHelper.Instance.GetByIds <ArgsFormat>(formatIds).ToDictionary(x => x.Id); if (newDetails.Any(x => x.Args.Any(arg => { if (steps.ContainsKey(arg.StepId) && steps[arg.StepId].FormatId != 0 && formats.ContainsKey(steps[arg.StepId].FormatId)) { var format = formats[steps[arg.StepId].FormatId]; return(ArgsFormatHelper.CheckPara(format, arg.Para)); } return(false); }))) { return(Result.GenError <Result>(Error.ProductionFlowCodeStepFormatError)); } } } ProductionHelper.Instance.Update(newDetails); } var args = ProductionArgHelper.GetMenus(ids, null); var argTmps = details.SelectMany(x => x.Args); var add = new List <ProductionArg>(); var up = new List <ProductionArg>(); var del = new List <int>(); add.AddRange(argTmps.Where(x => x.Id == 0)); up.AddRange(argTmps.Where(x => x.Id != 0).Where(x => argTmps.Any(y => ClassExtension.HaveChange(y, x)))); del.AddRange(args.Where(x => !argTmps.Any(y => y.Id == x.Id)).Select(x => x.Id)); if (add.Any()) { ProductionArgHelper.Instance.Add(add); } if (up.Any()) { ProductionArgHelper.Instance.Update <ProductionArg>(up); } if (del.Any()) { ProductionArgHelper.Instance.Delete(del); } } return(Result.GenError <Result>(Error.Success)); }