22 changed files with 16437 additions and 399 deletions
File diff suppressed because it is too large
@ -0,0 +1,126 @@ |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
|
|||
#nullable disable |
|||
|
|||
namespace TaskManager.EntityFramework.Migrations |
|||
{ |
|||
/// <inheritdoc />
|
|||
public partial class z202506090009 : Migration |
|||
{ |
|||
/// <inheritdoc />
|
|||
protected override void Up(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "Version", |
|||
table: "TaskLogs", |
|||
type: "nvarchar(30)", |
|||
maxLength: 30, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(20)", |
|||
oldMaxLength: 20, |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "Type", |
|||
table: "TaskLogs", |
|||
type: "nvarchar(30)", |
|||
maxLength: 30, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(20)", |
|||
oldMaxLength: 20, |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "TaskName", |
|||
table: "TaskLogs", |
|||
type: "nvarchar(30)", |
|||
maxLength: 30, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(20)", |
|||
oldMaxLength: 20, |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "Path", |
|||
table: "TaskLogs", |
|||
type: "nvarchar(30)", |
|||
maxLength: 30, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(20)", |
|||
oldMaxLength: 20, |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "Info", |
|||
table: "TaskLogs", |
|||
type: "nvarchar(max)", |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(20)", |
|||
oldMaxLength: 20, |
|||
oldNullable: true); |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
protected override void Down(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "Version", |
|||
table: "TaskLogs", |
|||
type: "nvarchar(20)", |
|||
maxLength: 20, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(30)", |
|||
oldMaxLength: 30, |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "Type", |
|||
table: "TaskLogs", |
|||
type: "nvarchar(20)", |
|||
maxLength: 20, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(30)", |
|||
oldMaxLength: 30, |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "TaskName", |
|||
table: "TaskLogs", |
|||
type: "nvarchar(20)", |
|||
maxLength: 20, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(30)", |
|||
oldMaxLength: 30, |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "Path", |
|||
table: "TaskLogs", |
|||
type: "nvarchar(20)", |
|||
maxLength: 20, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(30)", |
|||
oldMaxLength: 30, |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "Info", |
|||
table: "TaskLogs", |
|||
type: "nvarchar(20)", |
|||
maxLength: 20, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(max)", |
|||
oldNullable: true); |
|||
} |
|||
} |
|||
} |
File diff suppressed because it is too large
@ -0,0 +1,34 @@ |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
|
|||
#nullable disable |
|||
|
|||
namespace TaskManager.EntityFramework.Migrations |
|||
{ |
|||
/// <inheritdoc />
|
|||
public partial class z202506090010 : Migration |
|||
{ |
|||
/// <inheritdoc />
|
|||
protected override void Up(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "IsDelete", |
|||
table: "SUPPLIER_PRO_TSCHEDUL", |
|||
type: "nvarchar(max)", |
|||
nullable: false, |
|||
oldClrType: typeof(int), |
|||
oldType: "int"); |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
protected override void Down(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.AlterColumn<int>( |
|||
name: "IsDelete", |
|||
table: "SUPPLIER_PRO_TSCHEDUL", |
|||
type: "int", |
|||
nullable: false, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(max)"); |
|||
} |
|||
} |
|||
} |
File diff suppressed because it is too large
@ -0,0 +1,36 @@ |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
|
|||
#nullable disable |
|||
|
|||
namespace TaskManager.EntityFramework.Migrations |
|||
{ |
|||
/// <inheritdoc />
|
|||
public partial class z202506090011 : Migration |
|||
{ |
|||
/// <inheritdoc />
|
|||
protected override void Up(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "IsDelete", |
|||
table: "SUPPLIER_PRO_TSCHEDUL", |
|||
type: "nvarchar(5)", |
|||
maxLength: 5, |
|||
nullable: false, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(max)"); |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
protected override void Down(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "IsDelete", |
|||
table: "SUPPLIER_PRO_TSCHEDUL", |
|||
type: "nvarchar(max)", |
|||
nullable: false, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(5)", |
|||
oldMaxLength: 5); |
|||
} |
|||
} |
|||
} |
@ -1,196 +0,0 @@ |
|||
|
|||
using Microsoft.AspNetCore.Authorization; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Microsoft.Extensions.Options; |
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Net.Http; |
|||
using System.Net.Http.Headers; |
|||
using System.Security.Cryptography; |
|||
using System.Text; |
|||
using System.Text.Json; |
|||
using System.Text.Json.Serialization; |
|||
using System.Text.RegularExpressions; |
|||
using System.Threading.Tasks; |
|||
using TaskManager.Entity; |
|||
using TaskManager.EntityFramework; |
|||
using Wood.Entity; |
|||
|
|||
|
|||
|
|||
|
|||
namespace TaskManager.Controllers |
|||
{ |
|||
[AllowAnonymous] |
|||
public class CheryRecurringJobBaseController :ControllerBase, IDoExecute,IScoped |
|||
{ |
|||
protected string appKey = "8EG566b9bedd2bf46d"; |
|||
protected string appSecret = "48edc4425647425d87f806a1ba492580"; |
|||
protected readonly HttpClient _httpClient; |
|||
protected readonly JobDbContext _jobDbContext; |
|||
|
|||
public virtual int PageSizeOut { set; get; } = 50; |
|||
public virtual int PageSizeIn { set; get; } = 50; |
|||
|
|||
protected string Client { set; get; } = "Chery"; |
|||
protected string Path { set; get; } = "/v2/get/supplierProPlaning"; |
|||
protected string Url { set; get; } = "/v2/get/supplierProPlaning"; |
|||
protected virtual string TaskName { set; get; } = "SupplierProPlaning"; |
|||
|
|||
protected readonly LogController _logger; |
|||
|
|||
|
|||
public CheryRecurringJobBaseController( |
|||
HttpClient httpClient, |
|||
JobDbContext jobDbContext, |
|||
LogController log |
|||
) |
|||
{ |
|||
_httpClient = new HttpClient(); |
|||
_jobDbContext = jobDbContext; |
|||
_logger = log; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 提交给接口
|
|||
/// </summary>
|
|||
/// <param name="url"></param>
|
|||
/// <param name="jsonData">录入DTOJson</param>
|
|||
/// <returns>返回DTOJson</returns>
|
|||
protected async Task<string> Post(string url, string path, string jsonData) |
|||
{ |
|||
try |
|||
{ |
|||
// 生成签名参数
|
|||
string timeStamp = GetCurrentTimestamp(); |
|||
string nonce = GenerateNonce(); |
|||
var sign = GenerateSign(HttpMethod.Post.Method, path, appKey, appSecret, timeStamp, nonce, jsonData); |
|||
// 构建请求
|
|||
var request = new HttpRequestMessage(HttpMethod.Post, url); |
|||
request.Content = new StringContent(jsonData, Encoding.UTF8, "application/json"); |
|||
request.Headers.Add("appKey", appKey); |
|||
request.Headers.Add("appSecret", appSecret); |
|||
request.Headers.Add("timestamp", timeStamp); |
|||
request.Headers.Add("sign", sign); |
|||
request.Headers.Add("nonce", nonce); |
|||
|
|||
// 发送请求
|
|||
var response = await _httpClient.SendAsync(request); |
|||
response.EnsureSuccessStatusCode(); // 抛出异常处理状态码
|
|||
var str = await response.Content.ReadAsStringAsync(); |
|||
await _logger.AddInfoRemark("test", TaskName,str); |
|||
|
|||
return str; |
|||
} |
|||
catch (HttpRequestException ex) |
|||
{ |
|||
await _logger.AddError(ex.Message, this.TaskName); |
|||
//error = ex.Message;
|
|||
return string.Empty; |
|||
} |
|||
} |
|||
|
|||
private string GenerateSign(string method, string path, string appKey, string appSecret, string timestamp, string nonce, string jsonBody) |
|||
{ |
|||
|
|||
string paramStr = $"method={method.ToUpper()}&path={path}&appKey={appKey}&appSecret={appSecret}×tamp={timestamp}&nonce={nonce}&jsonBody={jsonBody}"; |
|||
return ComputeSHA512(paramStr); |
|||
|
|||
} |
|||
private string ComputeSHA512(string input) |
|||
{ |
|||
using (SHA512 sha512 = SHA512.Create()) |
|||
{ |
|||
byte[] bytes = Encoding.UTF8.GetBytes(input); |
|||
byte[] hash = sha512.ComputeHash(bytes); |
|||
|
|||
StringBuilder builder = new StringBuilder(); |
|||
for (int i = 0; i < hash.Length; i++) |
|||
{ |
|||
builder.Append(hash[i].ToString("x2")); // "x2" 表示小写十六进制
|
|||
} |
|||
return builder.ToString(); |
|||
} |
|||
} |
|||
private string GetCurrentTimestamp() |
|||
{ |
|||
return ((long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds).ToString(); |
|||
} |
|||
private string GenerateNonce() |
|||
{ |
|||
const string chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; |
|||
Random random = new Random(); |
|||
int length = random.Next(10, 51); |
|||
return new string(Enumerable.Repeat(chars, length) |
|||
.Select(s => s[random.Next(s.Length)]).ToArray()); |
|||
} |
|||
|
|||
|
|||
private async Task BeforeExecuteAsync(string uid) |
|||
{ |
|||
await _logger.AddInfo($"{TaskName}开始执行作业{uid}", TaskName); |
|||
} |
|||
private async Task AfterExecuteAsync(string uid) |
|||
{ |
|||
await _logger.AddInfo($"{TaskName}结束执行作业{uid}", TaskName); |
|||
} |
|||
[NonAction] |
|||
public async Task ExecuteAsync(string url, string path, string taskName,string client) |
|||
{ |
|||
var str = DateTime.Now.ToLongTimeString(); |
|||
await BeforeExecuteAsync(str); |
|||
|
|||
await DoExecutingAsync(url, path, taskName,client); |
|||
|
|||
await AfterExecuteAsync(str); |
|||
|
|||
} |
|||
protected async virtual Task DoExecutingAsync(string url, string path, string takName,string client) |
|||
{ |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
protected static string RemoveWhitespace(string input) |
|||
{ |
|||
if (string.IsNullOrEmpty(input)) |
|||
return input; |
|||
// 使用正则表达式移除空格和换行
|
|||
return Regex.Replace(input, @"[\s]+", ""); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
Loading…
Reference in new issue