27 changed files with 23548 additions and 739 deletions
File diff suppressed because it is too large
@ -0,0 +1,49 @@ |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
|
|||
#nullable disable |
|||
|
|||
namespace TaskManager.EntityFramework.Migrations |
|||
{ |
|||
/// <inheritdoc />
|
|||
public partial class z2025061000024 : Migration |
|||
{ |
|||
/// <inheritdoc />
|
|||
protected override void Up(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.AddColumn<int>( |
|||
name: "PageSize", |
|||
table: "TaskConifgure", |
|||
type: "int", |
|||
nullable: false, |
|||
defaultValue: 0); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "Id", |
|||
table: "SUPPLIER_PRO_PLANING", |
|||
type: "nvarchar(50)", |
|||
maxLength: 50, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(450)", |
|||
oldNullable: true); |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
protected override void Down(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.DropColumn( |
|||
name: "PageSize", |
|||
table: "TaskConifgure"); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "Id", |
|||
table: "SUPPLIER_PRO_PLANING", |
|||
type: "nvarchar(450)", |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(50)", |
|||
oldMaxLength: 50, |
|||
oldNullable: true); |
|||
} |
|||
} |
|||
} |
File diff suppressed because it is too large
@ -0,0 +1,158 @@ |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
|
|||
#nullable disable |
|||
|
|||
namespace TaskManager.EntityFramework.Migrations |
|||
{ |
|||
/// <inheritdoc />
|
|||
public partial class z20250610000240002 : Migration |
|||
{ |
|||
/// <inheritdoc />
|
|||
protected override void Up(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "Url", |
|||
table: "TaskConifgure", |
|||
type: "nvarchar(500)", |
|||
maxLength: 500, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(max)", |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "TaskName", |
|||
table: "TaskConifgure", |
|||
type: "nvarchar(200)", |
|||
maxLength: 200, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(max)", |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "TableName", |
|||
table: "TaskConifgure", |
|||
type: "nvarchar(100)", |
|||
maxLength: 100, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(max)", |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "Module", |
|||
table: "TaskConifgure", |
|||
type: "nvarchar(400)", |
|||
maxLength: 400, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(max)", |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "Corn", |
|||
table: "TaskConifgure", |
|||
type: "nvarchar(400)", |
|||
maxLength: 400, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(max)", |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "Client", |
|||
table: "TaskConifgure", |
|||
type: "nvarchar(50)", |
|||
maxLength: 50, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(max)", |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "Api", |
|||
table: "TaskConifgure", |
|||
type: "nvarchar(400)", |
|||
maxLength: 400, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(max)", |
|||
oldNullable: true); |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
protected override void Down(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "Url", |
|||
table: "TaskConifgure", |
|||
type: "nvarchar(max)", |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(500)", |
|||
oldMaxLength: 500, |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "TaskName", |
|||
table: "TaskConifgure", |
|||
type: "nvarchar(max)", |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(200)", |
|||
oldMaxLength: 200, |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "TableName", |
|||
table: "TaskConifgure", |
|||
type: "nvarchar(max)", |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(100)", |
|||
oldMaxLength: 100, |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "Module", |
|||
table: "TaskConifgure", |
|||
type: "nvarchar(max)", |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(400)", |
|||
oldMaxLength: 400, |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "Corn", |
|||
table: "TaskConifgure", |
|||
type: "nvarchar(max)", |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(400)", |
|||
oldMaxLength: 400, |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "Client", |
|||
table: "TaskConifgure", |
|||
type: "nvarchar(max)", |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(50)", |
|||
oldMaxLength: 50, |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "Api", |
|||
table: "TaskConifgure", |
|||
type: "nvarchar(max)", |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(400)", |
|||
oldMaxLength: 400, |
|||
oldNullable: true); |
|||
} |
|||
} |
|||
} |
File diff suppressed because it is too large
@ -0,0 +1,69 @@ |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
|
|||
#nullable disable |
|||
|
|||
namespace TaskManager.EntityFramework.Migrations |
|||
{ |
|||
/// <inheritdoc />
|
|||
public partial class z20250610000240003 : Migration |
|||
{ |
|||
/// <inheritdoc />
|
|||
protected override void Up(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "Id", |
|||
table: "SUPPLIER_CON_MMRP", |
|||
type: "nvarchar(450)", |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(max)", |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_CON_PO_Id", |
|||
table: "SUPPLIER_CON_PO", |
|||
column: "Id", |
|||
unique: true, |
|||
filter: "[Id] IS NOT NULL"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_CON_MMRP_Id", |
|||
table: "SUPPLIER_CON_MMRP", |
|||
column: "Id", |
|||
unique: true, |
|||
filter: "[Id] IS NOT NULL"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_CON_DATE_Id", |
|||
table: "SUPPLIER_CON_DATE", |
|||
column: "Id", |
|||
unique: true, |
|||
filter: "[Id] IS NOT NULL"); |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
protected override void Down(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_CON_PO_Id", |
|||
table: "SUPPLIER_CON_PO"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_CON_MMRP_Id", |
|||
table: "SUPPLIER_CON_MMRP"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_CON_DATE_Id", |
|||
table: "SUPPLIER_CON_DATE"); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "Id", |
|||
table: "SUPPLIER_CON_MMRP", |
|||
type: "nvarchar(max)", |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(450)", |
|||
oldNullable: true); |
|||
} |
|||
} |
|||
} |
File diff suppressed because it is too large
@ -0,0 +1,741 @@ |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
|
|||
#nullable disable |
|||
|
|||
namespace TaskManager.EntityFramework.Migrations |
|||
{ |
|||
/// <inheritdoc />
|
|||
public partial class z2025061100001 : Migration |
|||
{ |
|||
/// <inheritdoc />
|
|||
protected override void Up(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "MaterialDescription", |
|||
table: "SUPPLIER_SA_WEEK", |
|||
type: "nvarchar(100)", |
|||
maxLength: 100, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(50)", |
|||
oldMaxLength: 50, |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "MaterialDescription", |
|||
table: "SUPPLIER_RETURN", |
|||
type: "nvarchar(100)", |
|||
maxLength: 100, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(50)", |
|||
oldMaxLength: 50, |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "MaterialDescription", |
|||
table: "SUPPLIER_PRO_TSCHEDUL", |
|||
type: "nvarchar(100)", |
|||
maxLength: 100, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(50)", |
|||
oldMaxLength: 50, |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "MaterialDescription", |
|||
table: "SUPPLIER_PRO_HSCHEDUL", |
|||
type: "nvarchar(100)", |
|||
maxLength: 100, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(50)", |
|||
oldMaxLength: 50, |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "MaterialDescription", |
|||
table: "SUPPLIER_PRO_CSCHEDUL", |
|||
type: "nvarchar(100)", |
|||
maxLength: 100, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(50)", |
|||
oldMaxLength: 50, |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "MaterialDescription", |
|||
table: "SUPPLIER_PO", |
|||
type: "nvarchar(100)", |
|||
maxLength: 100, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(50)", |
|||
oldMaxLength: 50, |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "MaterialDescription", |
|||
table: "SUPPLIER_MRP_WARNING", |
|||
type: "nvarchar(100)", |
|||
maxLength: 100, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(50)", |
|||
oldMaxLength: 50, |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "MaterialDescription", |
|||
table: "SUPPLIER_MRP_STATE", |
|||
type: "nvarchar(100)", |
|||
maxLength: 100, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(50)", |
|||
oldMaxLength: 50, |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "MaterialDescription", |
|||
table: "SUPPLIER_MRP_MONTH", |
|||
type: "nvarchar(100)", |
|||
maxLength: 100, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(50)", |
|||
oldMaxLength: 50, |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "MaterialDescription", |
|||
table: "SUPPLIER_MRP_DATE", |
|||
type: "nvarchar(100)", |
|||
maxLength: 100, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(50)", |
|||
oldMaxLength: 50, |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "MaterialDescription", |
|||
table: "SUPPLIER_INV_DATA", |
|||
type: "nvarchar(100)", |
|||
maxLength: 100, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(50)", |
|||
oldMaxLength: 50, |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "MaterialDescription", |
|||
table: "SUPPLIER_DEL_STATE", |
|||
type: "nvarchar(100)", |
|||
maxLength: 100, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(50)", |
|||
oldMaxLength: 50, |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_SINV_DATA_ReadState", |
|||
table: "SUPPLIER_SINV_DATA", |
|||
column: "ReadState"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_SINV_DATA_TaskId", |
|||
table: "SUPPLIER_SINV_DATA", |
|||
column: "TaskId"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_SINV_DATA_WriteState", |
|||
table: "SUPPLIER_SINV_DATA", |
|||
column: "WriteState"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_SA_WEEK_ReadState", |
|||
table: "SUPPLIER_SA_WEEK", |
|||
column: "ReadState"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_SA_WEEK_TaskId", |
|||
table: "SUPPLIER_SA_WEEK", |
|||
column: "TaskId"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_SA_WEEK_WriteState", |
|||
table: "SUPPLIER_SA_WEEK", |
|||
column: "WriteState"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_RETURN_ReadState", |
|||
table: "SUPPLIER_RETURN", |
|||
column: "ReadState"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_RETURN_TaskId", |
|||
table: "SUPPLIER_RETURN", |
|||
column: "TaskId"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_RETURN_WriteState", |
|||
table: "SUPPLIER_RETURN", |
|||
column: "WriteState"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_PRO_TSCHEDUL_ReadState", |
|||
table: "SUPPLIER_PRO_TSCHEDUL", |
|||
column: "ReadState"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_PRO_TSCHEDUL_TaskId", |
|||
table: "SUPPLIER_PRO_TSCHEDUL", |
|||
column: "TaskId"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_PRO_TSCHEDUL_WriteState", |
|||
table: "SUPPLIER_PRO_TSCHEDUL", |
|||
column: "WriteState"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_PRO_PLANING_ReadState", |
|||
table: "SUPPLIER_PRO_PLANING", |
|||
column: "ReadState"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_PRO_PLANING_TaskId", |
|||
table: "SUPPLIER_PRO_PLANING", |
|||
column: "TaskId"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_PRO_PLANING_WriteState", |
|||
table: "SUPPLIER_PRO_PLANING", |
|||
column: "WriteState"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_PRO_HSCHEDUL_ReadState", |
|||
table: "SUPPLIER_PRO_HSCHEDUL", |
|||
column: "ReadState"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_PRO_HSCHEDUL_TaskId", |
|||
table: "SUPPLIER_PRO_HSCHEDUL", |
|||
column: "TaskId"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_PRO_HSCHEDUL_WriteState", |
|||
table: "SUPPLIER_PRO_HSCHEDUL", |
|||
column: "WriteState"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_PRO_CSCHEDUL_ReadState", |
|||
table: "SUPPLIER_PRO_CSCHEDUL", |
|||
column: "ReadState"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_PRO_CSCHEDUL_TaskId", |
|||
table: "SUPPLIER_PRO_CSCHEDUL", |
|||
column: "TaskId"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_PRO_CSCHEDUL_WriteState", |
|||
table: "SUPPLIER_PRO_CSCHEDUL", |
|||
column: "WriteState"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_PO_ReadState", |
|||
table: "SUPPLIER_PO", |
|||
column: "ReadState"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_PO_TaskId", |
|||
table: "SUPPLIER_PO", |
|||
column: "TaskId"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_PO_WriteState", |
|||
table: "SUPPLIER_PO", |
|||
column: "WriteState"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_MRP_WARNING_ReadState", |
|||
table: "SUPPLIER_MRP_WARNING", |
|||
column: "ReadState"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_MRP_WARNING_TaskId", |
|||
table: "SUPPLIER_MRP_WARNING", |
|||
column: "TaskId"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_MRP_WARNING_WriteState", |
|||
table: "SUPPLIER_MRP_WARNING", |
|||
column: "WriteState"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_MRP_STATE_ReadState", |
|||
table: "SUPPLIER_MRP_STATE", |
|||
column: "ReadState"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_MRP_STATE_TaskId", |
|||
table: "SUPPLIER_MRP_STATE", |
|||
column: "TaskId"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_MRP_STATE_WriteState", |
|||
table: "SUPPLIER_MRP_STATE", |
|||
column: "WriteState"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_MRP_MONTH_ReadState", |
|||
table: "SUPPLIER_MRP_MONTH", |
|||
column: "ReadState"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_MRP_MONTH_TaskId", |
|||
table: "SUPPLIER_MRP_MONTH", |
|||
column: "TaskId"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_MRP_MONTH_WriteState", |
|||
table: "SUPPLIER_MRP_MONTH", |
|||
column: "WriteState"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_MRP_DATE_ReadState", |
|||
table: "SUPPLIER_MRP_DATE", |
|||
column: "ReadState"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_MRP_DATE_TaskId", |
|||
table: "SUPPLIER_MRP_DATE", |
|||
column: "TaskId"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_MRP_DATE_WriteState", |
|||
table: "SUPPLIER_MRP_DATE", |
|||
column: "WriteState"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_INV_DATA_ReadState", |
|||
table: "SUPPLIER_INV_DATA", |
|||
column: "ReadState"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_INV_DATA_TaskId", |
|||
table: "SUPPLIER_INV_DATA", |
|||
column: "TaskId"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_INV_DATA_WriteState", |
|||
table: "SUPPLIER_INV_DATA", |
|||
column: "WriteState"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_DEL_STATE_ReadState", |
|||
table: "SUPPLIER_DEL_STATE", |
|||
column: "ReadState"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_DEL_STATE_TaskId", |
|||
table: "SUPPLIER_DEL_STATE", |
|||
column: "TaskId"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_DEL_STATE_WriteState", |
|||
table: "SUPPLIER_DEL_STATE", |
|||
column: "WriteState"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_CON_PO_ReadState", |
|||
table: "SUPPLIER_CON_PO", |
|||
column: "ReadState"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_CON_PO_TaskId", |
|||
table: "SUPPLIER_CON_PO", |
|||
column: "TaskId"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_CON_PO_WriteState", |
|||
table: "SUPPLIER_CON_PO", |
|||
column: "WriteState"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_CON_MMRP_ReadState", |
|||
table: "SUPPLIER_CON_MMRP", |
|||
column: "ReadState"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_CON_MMRP_TaskId", |
|||
table: "SUPPLIER_CON_MMRP", |
|||
column: "TaskId"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_CON_MMRP_WriteState", |
|||
table: "SUPPLIER_CON_MMRP", |
|||
column: "WriteState"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_CON_DATE_ReadState", |
|||
table: "SUPPLIER_CON_DATE", |
|||
column: "ReadState"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_CON_DATE_TaskId", |
|||
table: "SUPPLIER_CON_DATE", |
|||
column: "TaskId"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_SUPPLIER_CON_DATE_WriteState", |
|||
table: "SUPPLIER_CON_DATE", |
|||
column: "WriteState"); |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
protected override void Down(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_SINV_DATA_ReadState", |
|||
table: "SUPPLIER_SINV_DATA"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_SINV_DATA_TaskId", |
|||
table: "SUPPLIER_SINV_DATA"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_SINV_DATA_WriteState", |
|||
table: "SUPPLIER_SINV_DATA"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_SA_WEEK_ReadState", |
|||
table: "SUPPLIER_SA_WEEK"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_SA_WEEK_TaskId", |
|||
table: "SUPPLIER_SA_WEEK"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_SA_WEEK_WriteState", |
|||
table: "SUPPLIER_SA_WEEK"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_RETURN_ReadState", |
|||
table: "SUPPLIER_RETURN"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_RETURN_TaskId", |
|||
table: "SUPPLIER_RETURN"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_RETURN_WriteState", |
|||
table: "SUPPLIER_RETURN"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_PRO_TSCHEDUL_ReadState", |
|||
table: "SUPPLIER_PRO_TSCHEDUL"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_PRO_TSCHEDUL_TaskId", |
|||
table: "SUPPLIER_PRO_TSCHEDUL"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_PRO_TSCHEDUL_WriteState", |
|||
table: "SUPPLIER_PRO_TSCHEDUL"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_PRO_PLANING_ReadState", |
|||
table: "SUPPLIER_PRO_PLANING"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_PRO_PLANING_TaskId", |
|||
table: "SUPPLIER_PRO_PLANING"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_PRO_PLANING_WriteState", |
|||
table: "SUPPLIER_PRO_PLANING"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_PRO_HSCHEDUL_ReadState", |
|||
table: "SUPPLIER_PRO_HSCHEDUL"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_PRO_HSCHEDUL_TaskId", |
|||
table: "SUPPLIER_PRO_HSCHEDUL"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_PRO_HSCHEDUL_WriteState", |
|||
table: "SUPPLIER_PRO_HSCHEDUL"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_PRO_CSCHEDUL_ReadState", |
|||
table: "SUPPLIER_PRO_CSCHEDUL"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_PRO_CSCHEDUL_TaskId", |
|||
table: "SUPPLIER_PRO_CSCHEDUL"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_PRO_CSCHEDUL_WriteState", |
|||
table: "SUPPLIER_PRO_CSCHEDUL"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_PO_ReadState", |
|||
table: "SUPPLIER_PO"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_PO_TaskId", |
|||
table: "SUPPLIER_PO"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_PO_WriteState", |
|||
table: "SUPPLIER_PO"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_MRP_WARNING_ReadState", |
|||
table: "SUPPLIER_MRP_WARNING"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_MRP_WARNING_TaskId", |
|||
table: "SUPPLIER_MRP_WARNING"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_MRP_WARNING_WriteState", |
|||
table: "SUPPLIER_MRP_WARNING"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_MRP_STATE_ReadState", |
|||
table: "SUPPLIER_MRP_STATE"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_MRP_STATE_TaskId", |
|||
table: "SUPPLIER_MRP_STATE"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_MRP_STATE_WriteState", |
|||
table: "SUPPLIER_MRP_STATE"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_MRP_MONTH_ReadState", |
|||
table: "SUPPLIER_MRP_MONTH"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_MRP_MONTH_TaskId", |
|||
table: "SUPPLIER_MRP_MONTH"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_MRP_MONTH_WriteState", |
|||
table: "SUPPLIER_MRP_MONTH"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_MRP_DATE_ReadState", |
|||
table: "SUPPLIER_MRP_DATE"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_MRP_DATE_TaskId", |
|||
table: "SUPPLIER_MRP_DATE"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_MRP_DATE_WriteState", |
|||
table: "SUPPLIER_MRP_DATE"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_INV_DATA_ReadState", |
|||
table: "SUPPLIER_INV_DATA"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_INV_DATA_TaskId", |
|||
table: "SUPPLIER_INV_DATA"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_INV_DATA_WriteState", |
|||
table: "SUPPLIER_INV_DATA"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_DEL_STATE_ReadState", |
|||
table: "SUPPLIER_DEL_STATE"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_DEL_STATE_TaskId", |
|||
table: "SUPPLIER_DEL_STATE"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_DEL_STATE_WriteState", |
|||
table: "SUPPLIER_DEL_STATE"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_CON_PO_ReadState", |
|||
table: "SUPPLIER_CON_PO"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_CON_PO_TaskId", |
|||
table: "SUPPLIER_CON_PO"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_CON_PO_WriteState", |
|||
table: "SUPPLIER_CON_PO"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_CON_MMRP_ReadState", |
|||
table: "SUPPLIER_CON_MMRP"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_CON_MMRP_TaskId", |
|||
table: "SUPPLIER_CON_MMRP"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_CON_MMRP_WriteState", |
|||
table: "SUPPLIER_CON_MMRP"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_CON_DATE_ReadState", |
|||
table: "SUPPLIER_CON_DATE"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_CON_DATE_TaskId", |
|||
table: "SUPPLIER_CON_DATE"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_SUPPLIER_CON_DATE_WriteState", |
|||
table: "SUPPLIER_CON_DATE"); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "MaterialDescription", |
|||
table: "SUPPLIER_SA_WEEK", |
|||
type: "nvarchar(50)", |
|||
maxLength: 50, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(100)", |
|||
oldMaxLength: 100, |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "MaterialDescription", |
|||
table: "SUPPLIER_RETURN", |
|||
type: "nvarchar(50)", |
|||
maxLength: 50, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(100)", |
|||
oldMaxLength: 100, |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "MaterialDescription", |
|||
table: "SUPPLIER_PRO_TSCHEDUL", |
|||
type: "nvarchar(50)", |
|||
maxLength: 50, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(100)", |
|||
oldMaxLength: 100, |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "MaterialDescription", |
|||
table: "SUPPLIER_PRO_HSCHEDUL", |
|||
type: "nvarchar(50)", |
|||
maxLength: 50, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(100)", |
|||
oldMaxLength: 100, |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "MaterialDescription", |
|||
table: "SUPPLIER_PRO_CSCHEDUL", |
|||
type: "nvarchar(50)", |
|||
maxLength: 50, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(100)", |
|||
oldMaxLength: 100, |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "MaterialDescription", |
|||
table: "SUPPLIER_PO", |
|||
type: "nvarchar(50)", |
|||
maxLength: 50, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(100)", |
|||
oldMaxLength: 100, |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "MaterialDescription", |
|||
table: "SUPPLIER_MRP_WARNING", |
|||
type: "nvarchar(50)", |
|||
maxLength: 50, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(100)", |
|||
oldMaxLength: 100, |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "MaterialDescription", |
|||
table: "SUPPLIER_MRP_STATE", |
|||
type: "nvarchar(50)", |
|||
maxLength: 50, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(100)", |
|||
oldMaxLength: 100, |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "MaterialDescription", |
|||
table: "SUPPLIER_MRP_MONTH", |
|||
type: "nvarchar(50)", |
|||
maxLength: 50, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(100)", |
|||
oldMaxLength: 100, |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "MaterialDescription", |
|||
table: "SUPPLIER_MRP_DATE", |
|||
type: "nvarchar(50)", |
|||
maxLength: 50, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(100)", |
|||
oldMaxLength: 100, |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "MaterialDescription", |
|||
table: "SUPPLIER_INV_DATA", |
|||
type: "nvarchar(50)", |
|||
maxLength: 50, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(100)", |
|||
oldMaxLength: 100, |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "MaterialDescription", |
|||
table: "SUPPLIER_DEL_STATE", |
|||
type: "nvarchar(50)", |
|||
maxLength: 50, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(100)", |
|||
oldMaxLength: 100, |
|||
oldNullable: true); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,86 @@ |
|||
using Microsoft.Extensions.Configuration; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using TaskManager.Entity; |
|||
using TaskManager.EntityFramework; |
|||
using Wood.Entity; |
|||
|
|||
namespace Wood.Service.Controllers |
|||
{ |
|||
public class CheryDataMaintenanceService:IScoped,IDoExecute |
|||
{ |
|||
private readonly IServiceProvider _serviceProvider; |
|||
private readonly IConfiguration _configuration; |
|||
public CheryDataMaintenanceService(IServiceProvider serviceProvider, IConfiguration configuration) |
|||
{ |
|||
_serviceProvider = serviceProvider; |
|||
_configuration = configuration; |
|||
|
|||
} |
|||
|
|||
public async Task ExecuteAsync(string url, string path, string takName, string client, int pageSize) |
|||
{ |
|||
|
|||
using var scope = _serviceProvider.CreateScope(); |
|||
var db = scope.ServiceProvider.GetRequiredService<JobDbContext>(); |
|||
var tasklist=db.TaskConifgure.Where(p=>p.Client=="Chery").Select(x => x.TaskName); |
|||
|
|||
|
|||
//DateTime.Now.AddDays(-1).ToString("yyyyMMdd")
|
|||
|
|||
foreach (var task in tasklist) |
|||
{ |
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
public async Task SyncDataAsync(string version,string taskName) |
|||
{ |
|||
|
|||
using var scope = _serviceProvider.CreateScope(); |
|||
var db = scope.ServiceProvider.GetRequiredService<JobDbContext>(); |
|||
|
|||
var list = db.TaskLogs.Where(x => x.TaskName == taskName && x.Version == version |
|||
|
|||
&& !string.IsNullOrEmpty(x.Path) && x.Type == "应答"); |
|||
|
|||
if (list.Any()) |
|||
{ |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
} |
@ -0,0 +1,21 @@ |
|||
using Microsoft.Extensions.Configuration; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using TaskManager.Entity; |
|||
using TaskManager.EntityFramework; |
|||
|
|||
namespace Wood.Service.Controllers |
|||
{ |
|||
/// <summary>
|
|||
/// 读取日志服务
|
|||
/// </summary>
|
|||
public class CustomLogService : NormalBaseController<TaskLog> |
|||
{ |
|||
public CustomLogService(JobDbContext context, IServiceProvider builder, IConfiguration configuration, IRepository<TaskLog> repository) : base(context, builder, configuration, repository) |
|||
{ |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,286 @@ |
|||
using Microsoft.AspNetCore.Builder; |
|||
using Microsoft.AspNetCore.Identity.Data; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Microsoft.Extensions.Configuration; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Microsoft.Extensions.Hosting; |
|||
using Microsoft.Extensions.Logging; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Net.Http.Json; |
|||
using System.Text; |
|||
using System.Text.Encodings.Web; |
|||
using System.Text.Json; |
|||
using System.Threading.Channels; |
|||
using System.Threading.Tasks; |
|||
using TaskManager.Entity; |
|||
using TaskManager.EntityFramework; |
|||
using Wood.Entity; |
|||
using Wood.Service.SystemManage; |
|||
|
|||
namespace TaskManager.Controllers |
|||
{ |
|||
public class LogConsumerService : BackgroundService |
|||
{ |
|||
private readonly ChannelReader<TaskLog> _logReader; |
|||
|
|||
private readonly ILogger<LogConsumerService> _logger; |
|||
private const int BatchSize = 100; // 批量写入大小
|
|||
private readonly string _logDirectory; |
|||
private readonly IServiceProvider _serviceProvider; |
|||
|
|||
|
|||
public LogConsumerService( |
|||
LogController logService, |
|||
|
|||
ILogger<LogConsumerService> logger, IServiceProvider serviceProvider) |
|||
{ |
|||
_logReader = logService.GetLogReader(); |
|||
|
|||
_logger = logger; |
|||
_serviceProvider = serviceProvider; ; |
|||
_logDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CustomLogs"); // 使用更安全的路径获取方式
|
|||
|
|||
EnsureDirectoryExists(_logDirectory); |
|||
|
|||
|
|||
} |
|||
|
|||
protected override async Task ExecuteAsync(CancellationToken stoppingToken) |
|||
{ |
|||
_logger.LogInformation("日志消费服务已启动"); |
|||
|
|||
// 批量处理日志,减少数据库写入次数
|
|||
while (!stoppingToken.IsCancellationRequested && |
|||
await _logReader.WaitToReadAsync(stoppingToken)) |
|||
{ |
|||
try |
|||
{ |
|||
var logs = new List<TaskLog>(); |
|||
int count = 0; |
|||
|
|||
// 读取一批日志
|
|||
while (_logReader.TryRead(out var log) && count < BatchSize) |
|||
{ |
|||
logs.Add(log); |
|||
count++; |
|||
} |
|||
|
|||
if (logs.Any()) |
|||
{ |
|||
|
|||
using var scope = _serviceProvider.CreateScope(); |
|||
var db = scope.ServiceProvider.GetRequiredService<JobDbContext>(); |
|||
|
|||
List<TaskLog> logsToSave = new List<TaskLog>(); |
|||
foreach (var log in logs) |
|||
{ |
|||
if (!string.IsNullOrEmpty(log.Remark)) |
|||
{ |
|||
log.Path = WriteLogToFile(log.Remark); |
|||
} |
|||
log.Remark = string.Empty; |
|||
logsToSave.Add(log); |
|||
} |
|||
|
|||
await db.TaskLogs.AddRangeAsync(logsToSave, stoppingToken); |
|||
await db.SaveChangesAsync(stoppingToken); |
|||
|
|||
|
|||
_logger.LogInformation($"已写入 {logs.Count} 条日志"); |
|||
} |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
_logger.LogError(ex, "日志写入数据库失败"); |
|||
// 错误处理:可记录到临时文件或重试
|
|||
await Task.Delay(1000, stoppingToken); // 短暂延迟后重试
|
|||
} |
|||
} |
|||
} |
|||
|
|||
public override async Task StopAsync(CancellationToken stoppingToken) |
|||
{ |
|||
_logger.LogInformation("日志消费服务正在停止"); |
|||
// 处理剩余日志
|
|||
await base.StopAsync(stoppingToken); |
|||
} |
|||
private void EnsureDirectoryExists(string directoryPath) |
|||
{ |
|||
if (!Directory.Exists(directoryPath)) |
|||
{ |
|||
Directory.CreateDirectory(directoryPath); |
|||
} |
|||
} |
|||
// 修改后的日志写入方法
|
|||
private string WriteLogToFile(string jsonContent) |
|||
{ |
|||
//if string.IsNullOrEmpty(logMessage.RawRemark)) return null; // 必须提供JSON数据
|
|||
|
|||
// 创建日期目录
|
|||
string dateDirectory = DateTime.Now.ToString("yyyy-MM-dd"); |
|||
string fullDatePath = Path.Combine(_logDirectory, dateDirectory); |
|||
EnsureDirectoryExists(fullDatePath); |
|||
|
|||
// 生成唯一文件名(时间戳+随机数)
|
|||
string fileName = $"log_{DateTime.Now.Ticks}_{Random.Shared.Next(1000, 9999)}.json"; |
|||
string fullPath = Path.Combine(fullDatePath, fileName); |
|||
|
|||
try |
|||
{ |
|||
|
|||
// 写入文件(使用UTF-8无BOM格式)
|
|||
File.WriteAllText(fullPath, jsonContent, new UTF8Encoding(false)); |
|||
|
|||
// 存储相对路径(从日志根目录开始,使用正斜杠兼容API)
|
|||
return Path.Combine(dateDirectory, fileName).Replace('\\', '/'); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
Console.WriteLine($"JSON文件写入失败:{ex.Message}"); |
|||
|
|||
return null; |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
// 后台服务
|
|||
//public class LogBackgroundService : BackgroundService
|
|||
//{
|
|||
|
|||
// private readonly Channel<TaskLog> _logChannel;
|
|||
// private readonly IServiceProvider _serviceProvider;
|
|||
// private readonly string _logDirectory;
|
|||
|
|||
// public LogBackgroundService(IServiceProvider serviceProvider, IConfiguration configuration)
|
|||
// {
|
|||
// Console.WriteLine("LogService 初始化");
|
|||
// _serviceProvider = serviceProvider;
|
|||
// _logDirectory = configuration["Logging:Directory"] ??
|
|||
// Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CustomLogs"); // 使用更安全的路径获取方式
|
|||
|
|||
// EnsureDirectoryExists(_logDirectory);
|
|||
// _logChannel = Channel.CreateUnbounded<TaskLog>();
|
|||
// }
|
|||
|
|||
// public void EnqueueLog(TaskLog log)
|
|||
// {
|
|||
// _logChannel.Writer.TryWrite(log);
|
|||
// }
|
|||
// public override async Task StartAsync(CancellationToken cancellationToken)
|
|||
// {
|
|||
// // 服务启动前的准备工作
|
|||
// // _logger.LogInformation("Worker starting up...");
|
|||
|
|||
// // 调用基类方法
|
|||
// await base.StartAsync(cancellationToken);
|
|||
// }
|
|||
|
|||
// public override async Task StopAsync(CancellationToken cancellationToken)
|
|||
// {
|
|||
// // 服务停止前的清理工作
|
|||
// //_logger.LogInformation("Worker shutting down...");
|
|||
|
|||
// // 调用基类方法
|
|||
// await base.StopAsync(cancellationToken);
|
|||
// }
|
|||
|
|||
// public override void Dispose()
|
|||
// {
|
|||
// // 资源释放
|
|||
// // _logger.LogInformation("Worker disposing resources");
|
|||
// base.Dispose();
|
|||
// }
|
|||
// protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
|||
// {
|
|||
// Console.WriteLine("LogService 开始执行后台任务");
|
|||
|
|||
|
|||
// using PeriodicTimer timer = new(TimeSpan.FromSeconds(10));
|
|||
|
|||
|
|||
// // 主循环 - 使用 PeriodicTimer 等待下一个触发时间
|
|||
// while (await timer.WaitForNextTickAsync(stoppingToken))
|
|||
// {
|
|||
// await foreach (var log in _logChannel.Reader.ReadAllAsync(stoppingToken))
|
|||
// {
|
|||
// try
|
|||
// {
|
|||
// if (!string.IsNullOrEmpty(log.Remark))
|
|||
// {
|
|||
// log.Path = WriteLogToFile(log.Remark);
|
|||
// }
|
|||
// log.Remark = string.Empty;
|
|||
// using var scope = _serviceProvider.CreateScope();
|
|||
// var db = scope.ServiceProvider.GetRequiredService<JobDbContext>();
|
|||
// await db.TaskLogs.AddAsync(log, stoppingToken);
|
|||
// await db.SaveChangesAsync(stoppingToken);
|
|||
// Console.WriteLine($"日志已保存: {log.Info}");
|
|||
// }
|
|||
// catch (Exception ex)
|
|||
// {
|
|||
// Console.WriteLine($"日志处理失败: {ex.Message}");
|
|||
// }
|
|||
// }
|
|||
// }
|
|||
|
|||
// Console.WriteLine("LogService 后台任务已停止");
|
|||
// }
|
|||
// private void EnsureDirectoryExists(string directoryPath)
|
|||
// {
|
|||
// if (!Directory.Exists(directoryPath))
|
|||
// {
|
|||
// Directory.CreateDirectory(directoryPath);
|
|||
// }
|
|||
// }
|
|||
// // 修改后的日志写入方法
|
|||
// private string WriteLogToFile(string jsonContent)
|
|||
// {
|
|||
// //if string.IsNullOrEmpty(logMessage.RawRemark)) return null; // 必须提供JSON数据
|
|||
|
|||
// // 创建日期目录
|
|||
// string dateDirectory = DateTime.Now.ToString("yyyy-MM-dd");
|
|||
// string fullDatePath = Path.Combine(_logDirectory, dateDirectory);
|
|||
// EnsureDirectoryExists(fullDatePath);
|
|||
|
|||
// // 生成唯一文件名(时间戳+随机数)
|
|||
// string fileName = $"log_{DateTime.Now.Ticks}_{Random.Shared.Next(1000, 9999)}.json";
|
|||
// string fullPath = Path.Combine(fullDatePath, fileName);
|
|||
|
|||
// try
|
|||
// {
|
|||
|
|||
// // 写入文件(使用UTF-8无BOM格式)
|
|||
// File.WriteAllText(fullPath, jsonContent, new UTF8Encoding(false));
|
|||
|
|||
// // 存储相对路径(从日志根目录开始,使用正斜杠兼容API)
|
|||
// return Path.Combine(dateDirectory, fileName).Replace('\\', '/');
|
|||
// }
|
|||
// catch (Exception ex)
|
|||
// {
|
|||
// Console.WriteLine($"JSON文件写入失败:{ex.Message}");
|
|||
|
|||
// return null;
|
|||
// }
|
|||
// }
|
|||
//}
|
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
@ -1,162 +0,0 @@ |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Microsoft.Extensions.Configuration; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Microsoft.Extensions.Hosting; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Channels; |
|||
using System.Threading.Tasks; |
|||
using TaskManager.Entity; |
|||
using TaskManager.EntityFramework; |
|||
|
|||
namespace Wood.Service.Controllers |
|||
{ |
|||
public class LogController1 : BackgroundService |
|||
{ |
|||
private readonly IServiceProvider _serviceProvider; |
|||
private readonly Channel<TaskLog> _logChannel; |
|||
private readonly string _logDirectory; |
|||
|
|||
public LogController1( |
|||
IServiceProvider serviceProvider, |
|||
IConfiguration configuration) |
|||
{ |
|||
_serviceProvider = serviceProvider; |
|||
_logDirectory = configuration["Logging:Directory"] ?? |
|||
Path.Combine(Directory.GetCurrentDirectory(), "Logs"); |
|||
|
|||
EnsureDirectoryExists(_logDirectory); |
|||
_logChannel = Channel.CreateUnbounded<TaskLog>(); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
public void EnqueueLog(TaskLog logMessage) |
|||
{ |
|||
// 设置日志路径并写入文件
|
|||
logMessage.Path= WriteLogToFile(logMessage); |
|||
|
|||
// 将日志加入处理队列
|
|||
_logChannel.Writer.TryWrite(logMessage); |
|||
} |
|||
|
|||
private string WriteLogToFile(TaskLog logMessage) |
|||
{ |
|||
// 获取今天的日期目录
|
|||
string todayDirectory = Path.Combine(_logDirectory, DateTime.Now.ToString("yyyy-MM-dd")); |
|||
|
|||
// 确保目录存在
|
|||
EnsureDirectoryExists(todayDirectory); |
|||
|
|||
// 创建或追加到日志文件
|
|||
string logFilePath = Path.Combine(todayDirectory, "application.log"); |
|||
|
|||
try |
|||
{ |
|||
// 写入日志内容到文件
|
|||
File.AppendAllText(logFilePath, |
|||
$"[{logMessage.CreationTime:yyyy-MM-dd HH:mm:ss}] [{logMessage.Type}] {logMessage.Info}{Environment.NewLine}"); |
|||
|
|||
// 返回相对路径(从日志根目录开始)
|
|||
return Path.GetRelativePath(_logDirectory, logFilePath); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
// 记录日志写入失败的错误
|
|||
Console.WriteLine($"Error writing log to file: {ex.Message}"); |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
private void EnsureDirectoryExists(string directoryPath) |
|||
{ |
|||
if (!Directory.Exists(directoryPath)) |
|||
{ |
|||
Directory.CreateDirectory(directoryPath); |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
[HttpGet("AddError")] |
|||
public async Task<bool> AddError(string message, string taskname, Guid taskid, Version version) |
|||
{ |
|||
var log = new TaskLog |
|||
{ |
|||
Info = message, |
|||
Type = "错误", |
|||
TaskName = taskname, |
|||
CreationTime = DateTime.Now, |
|||
TaskId = taskid, |
|||
Version = version?.ToString() |
|||
}; |
|||
|
|||
EnqueueLog(log); |
|||
|
|||
return true; // 日志已入队,视为成功
|
|||
} |
|||
|
|||
[HttpGet("AddInfo")] |
|||
public async Task<bool> AddInfo(string message, string taskname, Guid taskid, Version version) |
|||
{ |
|||
var log = new TaskLog |
|||
{ |
|||
Info = message, |
|||
Type = "错误", |
|||
TaskName = taskname, |
|||
CreationTime = DateTime.Now, |
|||
TaskId = taskid, |
|||
Version = version?.ToString() |
|||
}; |
|||
|
|||
EnqueueLog(log); |
|||
|
|||
return true; |
|||
} |
|||
|
|||
[HttpGet("AddInfoRemark")] |
|||
public async Task<bool> AddInfoRemark(string message, string taskname, string remark) |
|||
{ |
|||
var log = new TaskLog |
|||
{ |
|||
Info = message, |
|||
Type = "记录", |
|||
TaskName = taskname, |
|||
CreationTime = DateTime.Now, |
|||
Remark = remark |
|||
}; |
|||
|
|||
EnqueueLog(log); |
|||
|
|||
return true; |
|||
} |
|||
|
|||
|
|||
// 其他方法保持不变...
|
|||
|
|||
protected override async Task ExecuteAsync(CancellationToken stoppingToken) |
|||
{ |
|||
await foreach (var logMessage in _logChannel.Reader.ReadAllAsync(stoppingToken)) |
|||
{ |
|||
// 使用IServiceScopeFactory创建独立的作用域
|
|||
using var scope = _serviceProvider.CreateScope(); |
|||
var dbContext = scope.ServiceProvider.GetRequiredService<JobDbContext>(); |
|||
|
|||
try |
|||
{ |
|||
dbContext.TaskLogs.Add(logMessage); |
|||
await dbContext.SaveChangesAsync(stoppingToken); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
Console.WriteLine($"Error saving log: {ex.Message}"); |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
} |
|||
} |
Loading…
Reference in new issue