This commit is contained in:
sardq 2024-05-28 20:51:44 +04:00
commit 0409356c5e
10 changed files with 189 additions and 214 deletions

View File

@ -1,4 +1,6 @@
using FactoryContracts.BindingModels;
using FactoryBusinessLogic.OfficePackage;
using FactoryBusinessLogic.OfficePackage.HelperModels;
using FactoryContracts.BindingModels;
using FactoryContracts.BusinessLogicsContracts;
using FactoryContracts.SearchModels;
using FactoryContracts.StoragesContracts;
@ -10,30 +12,54 @@ namespace FactoryBusinessLogic.BusinessLogics
{
private readonly IMachineStorage _machineStorage;
private readonly IProductStorage _productStorage;
public StorekeeperReportLogic(IMachineStorage machineStorage, IProductStorage productStorage)
private readonly AbstractSaveToWord _saveToWord;
private readonly AbstractSaveToExcel _saveToExcel;
private readonly AbstractSaveToPdf _saveToPdf;
public StorekeeperReportLogic(IMachineStorage machineStorage, IProductStorage productStorage, AbstractSaveToWord saveToWord, AbstractSaveToExcel saveToExcel, AbstractSaveToPdf saveToPdf)
{
_machineStorage = machineStorage;
_productStorage = productStorage;
_saveToWord = saveToWord;
_saveToExcel = saveToExcel;
_saveToPdf = saveToPdf;
}
public List<ProductPlanProductionReportViewModel> GetPlanProductionsByProduct(List<ProductSearchModel> products)
{
_machineStorage = machineStorage;
_productStorage = productStorage;
}
public List<ProductPlanProductionReportViewModel> GetPlanProductionsByProduct(List<ProductSearchModel> products)
{
return _productStorage.GetPlanProductions(products);
List<int> ids = products.Select(x => (int)x.Id).ToList();
return _productStorage.GetPlanProductions(ids);
}
public List<MachinePeriodReportViewModel> GetMachines(ClientSearchModel client, ReportBindingModel model)
{
return _machineStorage.GetMachinesByPeriod(client, model);
}
public void SaveMachinesToPdfFile(ReportBindingModel model)
public void SaveMachinesToPdfFile(ClientSearchModel client, ReportBindingModel model)
{
throw new NotImplementedException();
_saveToPdf.CreateStorekeeperDoc(new StorekeeperPdfInfo
{
FileName = model.FileName,
Title = "Список станков",
DateFrom = model.DateFrom!.Value,
DateTo = model.DateTo!.Value,
Machines = GetMachines(client, model)
});
}
public void SavePlanProductionsToExcelFile(ReportBindingModel model)
public void SavePlanProductionsToExcelFile(ReportBindingModel model, List<ProductSearchModel> products)
{
throw new NotImplementedException();
_saveToExcel.CreateStorekeeperReport(new StorekeeperExcelInfo
{
FileName = model.FileName,
Title = "Список планов производств",
ProductPlanProductions = GetPlanProductionsByProduct(products)
});
}
public void SavePlanProductionsToWordFile(ReportBindingModel model)
public void SavePlanProductionsToWordFile(ReportBindingModel model, List<ProductSearchModel> products)
{
throw new NotImplementedException();
}
_saveToWord.CreateStorekeeperDoc(new StorekeeperWordInfo
{
FileName = model.FileName,
Title = "Список планов производств",
ProductPlanProductions = GetPlanProductionsByProduct(products)
});
}
}
}

View File

@ -8,8 +8,8 @@ namespace FactoryContracts.BusinessLogicsContracts
{
List<ProductPlanProductionReportViewModel> GetPlanProductionsByProduct(List<ProductSearchModel> products);
List<MachinePeriodReportViewModel> GetMachines(ClientSearchModel client, ReportBindingModel model);
void SavePlanProductionsToWordFile(ReportBindingModel model);
void SavePlanProductionsToExcelFile(ReportBindingModel model);
void SaveMachinesToPdfFile(ReportBindingModel model);
void SavePlanProductionsToWordFile(ReportBindingModel model, List<ProductSearchModel> products);
void SavePlanProductionsToExcelFile(ReportBindingModel model, List<ProductSearchModel> products);
void SaveMachinesToPdfFile(ClientSearchModel client, ReportBindingModel model);
}
}

View File

@ -1,4 +1,6 @@
namespace FactoryContracts.SearchModels
using FactoryDataModels.Enums;
namespace FactoryContracts.SearchModels
{
public class ClientSearchModel
{
@ -7,5 +9,7 @@
public string? Login { get; set; }
public string? Password { get; set; }
public ClientRole? Role { get; set; }
}
}

View File

@ -18,6 +18,6 @@ namespace FactoryContracts.StoragesContracts
ProductViewModel? Delete(ProductBindingModel model);
List<ProductPlanProductionReportViewModel> GetPlanProductions(List<ProductSearchModel> products);
List<ProductPlanProductionReportViewModel> GetPlanProductions(List<int> ids);
}
}

View File

@ -112,27 +112,19 @@ namespace FactoryDatabaseImplement.Implements
return null;
}
public List<ProductPlanProductionReportViewModel> GetPlanProductions(List<ProductSearchModel> products)
public List<ProductPlanProductionReportViewModel> GetPlanProductions(List<int> ids)
{
using var context = new FactoryDatabase();
// not sure if it works
return context.Products
.Include(x => x.Client)
.Include(x => x.Machines)
.ThenInclude(x => x.Machine)
.Where(x => products.Any(y => x.ProductName == y.ProductName && x.ClientId == y.ClientId))
.Select(x => new ProductPlanProductionReportViewModel()
.Where(prod => ids.Contains(prod.Id))
.Select(prod => new ProductPlanProductionReportViewModel()
{
ProductName = x.ProductName,
PlanProductions = context.PlanProductions
.Include(y => y.Workpieces).
ThenInclude(y => y.Workpiece)
.ThenInclude(y => y.Products)
.ThenInclude(y => y.Product)
.Where(y => y.Workpieces.Any(z => z.Workpiece.Products.Any(v => v.Product.ProductName == x.ProductName)))
.Select(y => y.GetViewModel)
.ToList()
ProductName = prod.ProductName,
PlanProductions = context.PlanProductionWorkpieces
.Include(x => x.PlanProduction)
.Where(plan => prod.Id == plan.PlanProduction.Id)
.Select(x => x.PlanProduction.GetViewModel)
.ToList(),
})
.ToList();
}

View File

@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace FactoryDatabaseImplement.Migrations
{
[DbContext(typeof(FactoryDatabase))]
[Migration("20240528135247_InitCreate")]
[Migration("20240528144223_InitCreate")]
partial class InitCreate
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -81,7 +81,8 @@ namespace FactoryDatabaseImplement.Migrations
b.HasIndex("ClientId");
b.HasIndex("PlanProductionId");
b.HasIndex("PlanProductionId")
.IsUnique();
b.ToTable("ExecutionPhases");
});
@ -157,9 +158,6 @@ namespace FactoryDatabaseImplement.Migrations
b.Property<DateTime>("Deadline")
.HasColumnType("timestamp without time zone");
b.Property<int?>("ExecutionPhaseId")
.HasColumnType("integer");
b.Property<string>("ProductionName")
.IsRequired()
.HasColumnType("text");
@ -168,8 +166,6 @@ namespace FactoryDatabaseImplement.Migrations
b.HasIndex("ClientId");
b.HasIndex("ExecutionPhaseId");
b.ToTable("PlanProductions");
});
@ -349,8 +345,8 @@ namespace FactoryDatabaseImplement.Migrations
.IsRequired();
b.HasOne("FactoryDatabaseImplement.Models.PlanProduction", "PlanProduction")
.WithMany()
.HasForeignKey("PlanProductionId")
.WithOne("ExecutionPhase")
.HasForeignKey("FactoryDatabaseImplement.Models.ExecutionPhase", "PlanProductionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@ -397,10 +393,6 @@ namespace FactoryDatabaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FactoryDatabaseImplement.Models.ExecutionPhase", null)
.WithMany("PlanProductions")
.HasForeignKey("ExecutionPhaseId");
b.Navigation("Client");
});
@ -517,11 +509,6 @@ namespace FactoryDatabaseImplement.Migrations
b.Navigation("Workpieces");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.ExecutionPhase", b =>
{
b.Navigation("PlanProductions");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Machine", b =>
{
b.Navigation("PlanProductions");
@ -531,6 +518,9 @@ namespace FactoryDatabaseImplement.Migrations
modelBuilder.Entity("FactoryDatabaseImplement.Models.PlanProduction", b =>
{
b.Navigation("ExecutionPhase")
.IsRequired();
b.Navigation("Machines");
b.Navigation("Workpieces");

View File

@ -48,6 +48,28 @@ namespace FactoryDatabaseImplement.Migrations
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "PlanProductions",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ClientId = table.Column<int>(type: "integer", nullable: false),
ProductionName = table.Column<string>(type: "text", nullable: false),
Count = table.Column<int>(type: "integer", nullable: false),
Deadline = table.Column<DateTime>(type: "timestamp without time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_PlanProductions", x => x.Id);
table.ForeignKey(
name: "FK_PlanProductions_Clients_ClientId",
column: x => x.ClientId,
principalTable: "Clients",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Products",
columns: table => new
@ -92,6 +114,62 @@ namespace FactoryDatabaseImplement.Migrations
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "ExecutionPhases",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ClientId = table.Column<int>(type: "integer", nullable: false),
PlanProductionId = table.Column<int>(type: "integer", nullable: false),
ExecutionPhaseName = table.Column<string>(type: "text", nullable: false),
ImplementerFIO = table.Column<string>(type: "text", nullable: false),
Status = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ExecutionPhases", x => x.Id);
table.ForeignKey(
name: "FK_ExecutionPhases_Clients_ClientId",
column: x => x.ClientId,
principalTable: "Clients",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_ExecutionPhases_PlanProductions_PlanProductionId",
column: x => x.PlanProductionId,
principalTable: "PlanProductions",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "MachinePlanProductions",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
MachineId = table.Column<int>(type: "integer", nullable: false),
PlanProductionId = table.Column<int>(type: "integer", nullable: false),
Count = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_MachinePlanProductions", x => x.Id);
table.ForeignKey(
name: "FK_MachinePlanProductions_Machines_MachineId",
column: x => x.MachineId,
principalTable: "Machines",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_MachinePlanProductions_PlanProductions_PlanProductionId",
column: x => x.PlanProductionId,
principalTable: "PlanProductions",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "ProductMachines",
columns: table => new
@ -147,111 +225,6 @@ namespace FactoryDatabaseImplement.Migrations
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "WorkpieceProducts",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
WorkpieceId = table.Column<int>(type: "integer", nullable: false),
ProductId = table.Column<int>(type: "integer", nullable: false),
Count = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_WorkpieceProducts", x => x.Id);
table.ForeignKey(
name: "FK_WorkpieceProducts_Products_ProductId",
column: x => x.ProductId,
principalTable: "Products",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_WorkpieceProducts_Workpieces_WorkpieceId",
column: x => x.WorkpieceId,
principalTable: "Workpieces",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "ExecutionPhases",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ClientId = table.Column<int>(type: "integer", nullable: false),
PlanProductionId = table.Column<int>(type: "integer", nullable: false),
ExecutionPhaseName = table.Column<string>(type: "text", nullable: false),
ImplementerFIO = table.Column<string>(type: "text", nullable: false),
Status = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ExecutionPhases", x => x.Id);
table.ForeignKey(
name: "FK_ExecutionPhases_Clients_ClientId",
column: x => x.ClientId,
principalTable: "Clients",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "PlanProductions",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ClientId = table.Column<int>(type: "integer", nullable: false),
ProductionName = table.Column<string>(type: "text", nullable: false),
Count = table.Column<int>(type: "integer", nullable: false),
Deadline = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
ExecutionPhaseId = table.Column<int>(type: "integer", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_PlanProductions", x => x.Id);
table.ForeignKey(
name: "FK_PlanProductions_Clients_ClientId",
column: x => x.ClientId,
principalTable: "Clients",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_PlanProductions_ExecutionPhases_ExecutionPhaseId",
column: x => x.ExecutionPhaseId,
principalTable: "ExecutionPhases",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "MachinePlanProductions",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
MachineId = table.Column<int>(type: "integer", nullable: false),
PlanProductionId = table.Column<int>(type: "integer", nullable: false),
Count = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_MachinePlanProductions", x => x.Id);
table.ForeignKey(
name: "FK_MachinePlanProductions_Machines_MachineId",
column: x => x.MachineId,
principalTable: "Machines",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_MachinePlanProductions_PlanProductions_PlanProductionId",
column: x => x.PlanProductionId,
principalTable: "PlanProductions",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "PlanProductionWorkpieces",
columns: table => new
@ -279,6 +252,33 @@ namespace FactoryDatabaseImplement.Migrations
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "WorkpieceProducts",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
WorkpieceId = table.Column<int>(type: "integer", nullable: false),
ProductId = table.Column<int>(type: "integer", nullable: false),
Count = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_WorkpieceProducts", x => x.Id);
table.ForeignKey(
name: "FK_WorkpieceProducts_Products_ProductId",
column: x => x.ProductId,
principalTable: "Products",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_WorkpieceProducts_Workpieces_WorkpieceId",
column: x => x.WorkpieceId,
principalTable: "Workpieces",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_ExecutionPhases_ClientId",
table: "ExecutionPhases",
@ -287,7 +287,8 @@ namespace FactoryDatabaseImplement.Migrations
migrationBuilder.CreateIndex(
name: "IX_ExecutionPhases_PlanProductionId",
table: "ExecutionPhases",
column: "PlanProductionId");
column: "PlanProductionId",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_MachinePlanProductions_MachineId",
@ -309,11 +310,6 @@ namespace FactoryDatabaseImplement.Migrations
table: "PlanProductions",
column: "ClientId");
migrationBuilder.CreateIndex(
name: "IX_PlanProductions_ExecutionPhaseId",
table: "PlanProductions",
column: "ExecutionPhaseId");
migrationBuilder.CreateIndex(
name: "IX_PlanProductionWorkpieces_PlanProductionId",
table: "PlanProductionWorkpieces",
@ -364,29 +360,12 @@ namespace FactoryDatabaseImplement.Migrations
name: "IX_Workpieces_ClientId",
table: "Workpieces",
column: "ClientId");
migrationBuilder.AddForeignKey(
name: "FK_ExecutionPhases_PlanProductions_PlanProductionId",
table: "ExecutionPhases",
column: "PlanProductionId",
principalTable: "PlanProductions",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_ExecutionPhases_Clients_ClientId",
table: "ExecutionPhases");
migrationBuilder.DropForeignKey(
name: "FK_PlanProductions_Clients_ClientId",
table: "PlanProductions");
migrationBuilder.DropForeignKey(
name: "FK_ExecutionPhases_PlanProductions_PlanProductionId",
table: "ExecutionPhases");
migrationBuilder.DropTable(
name: "ExecutionPhases");
migrationBuilder.DropTable(
name: "MachinePlanProductions");
@ -403,6 +382,9 @@ namespace FactoryDatabaseImplement.Migrations
migrationBuilder.DropTable(
name: "WorkpieceProducts");
migrationBuilder.DropTable(
name: "PlanProductions");
migrationBuilder.DropTable(
name: "Machines");
@ -414,12 +396,6 @@ namespace FactoryDatabaseImplement.Migrations
migrationBuilder.DropTable(
name: "Clients");
migrationBuilder.DropTable(
name: "PlanProductions");
migrationBuilder.DropTable(
name: "ExecutionPhases");
}
}
}

View File

@ -79,7 +79,8 @@ namespace FactoryDatabaseImplement.Migrations
b.HasIndex("ClientId");
b.HasIndex("PlanProductionId");
b.HasIndex("PlanProductionId")
.IsUnique();
b.ToTable("ExecutionPhases");
});
@ -155,9 +156,6 @@ namespace FactoryDatabaseImplement.Migrations
b.Property<DateTime>("Deadline")
.HasColumnType("timestamp without time zone");
b.Property<int?>("ExecutionPhaseId")
.HasColumnType("integer");
b.Property<string>("ProductionName")
.IsRequired()
.HasColumnType("text");
@ -166,8 +164,6 @@ namespace FactoryDatabaseImplement.Migrations
b.HasIndex("ClientId");
b.HasIndex("ExecutionPhaseId");
b.ToTable("PlanProductions");
});
@ -347,8 +343,8 @@ namespace FactoryDatabaseImplement.Migrations
.IsRequired();
b.HasOne("FactoryDatabaseImplement.Models.PlanProduction", "PlanProduction")
.WithMany()
.HasForeignKey("PlanProductionId")
.WithOne("ExecutionPhase")
.HasForeignKey("FactoryDatabaseImplement.Models.ExecutionPhase", "PlanProductionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@ -395,10 +391,6 @@ namespace FactoryDatabaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FactoryDatabaseImplement.Models.ExecutionPhase", null)
.WithMany("PlanProductions")
.HasForeignKey("ExecutionPhaseId");
b.Navigation("Client");
});
@ -515,11 +507,6 @@ namespace FactoryDatabaseImplement.Migrations
b.Navigation("Workpieces");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.ExecutionPhase", b =>
{
b.Navigation("PlanProductions");
});
modelBuilder.Entity("FactoryDatabaseImplement.Models.Machine", b =>
{
b.Navigation("PlanProductions");
@ -529,6 +516,9 @@ namespace FactoryDatabaseImplement.Migrations
modelBuilder.Entity("FactoryDatabaseImplement.Models.PlanProduction", b =>
{
b.Navigation("ExecutionPhase")
.IsRequired();
b.Navigation("Machines");
b.Navigation("Workpieces");

View File

@ -16,18 +16,15 @@ namespace FactoryDatabaseImplement.Models
[Required]
public int PlanProductionId { get; private set; }
public virtual PlanProduction PlanProduction { get; private set; }
public virtual PlanProduction PlanProduction { get; private set; } = null!;
[Required]
[Required]
public string ExecutionPhaseName { get; private set; } = string.Empty;
[Required]
public string ImplementerFIO { get; private set; } = string.Empty;
[Required]
public ExecutionPhaseStatus Status { get; private set; } = ExecutionPhaseStatus.Неизвестен;
[ForeignKey("ExecutionPhaseId")]
public virtual List<PlanProduction> PlanProductions { get; set; } = new();
public static ExecutionPhase? Create(ExecutionPhaseBindingModel model)
{
if (model == null)

View File

@ -57,7 +57,7 @@ namespace FactoryStorekeeperApp.Controllers
[HttpPost]
public IActionResult Enter(string login, string password)
{
var existsClient = clientLogic.ReadElement(new ClientSearchModel { Login = login, Password = password });
var existsClient = clientLogic.ReadElement(new ClientSearchModel { Login = login, Password = password, Role = ClientRole.Кладовщик });
if (existsClient != null)
{