diff --git a/DOAN.Admin.WebApi/Controllers/Bydlms/BydWorkorderController.cs b/DOAN.Admin.WebApi/Controllers/Bydlms/BydWorkorderController.cs index 72f43cf..0dbf50a 100644 --- a/DOAN.Admin.WebApi/Controllers/Bydlms/BydWorkorderController.cs +++ b/DOAN.Admin.WebApi/Controllers/Bydlms/BydWorkorderController.cs @@ -11,7 +11,7 @@ namespace DOAN.Admin.WebApi.Controllers.Bydlms /// /// 生产工单 /// - [Verify] + [Route("bydlms/BydWorkorder")] public class BydWorkorderController : BaseController { @@ -25,11 +25,51 @@ namespace DOAN.Admin.WebApi.Controllers.Bydlms _BydWorkorderService = BydWorkorderService; } + /// + /// BYD-MES传入生产工单 + /// + /// + [HttpPost("accept_BYD_MES_wrokorder_list")] + [AllowAnonymousAttribute] + [Log(Title = "BYD-MES传入生产工单", BusinessType = BusinessType.INSERT)] + public IActionResult BatchAddBydWorkorder([FromBody] QueryParam parm) + { + try + { + var modalList = parm.Data.Adapt>(); + var response = _BydWorkorderService.AddBydWorkorderList(modalList); + Dictionary result = new Dictionary(); + + if (response) + { + result.Add("code", "000000"); + result.Add("mesg", "操作成功"); + return Ok(result); // 返回成功的响应 + } + else + { + result.Add("code", "999999"); + result.Add("mesg", "传入数据为空"); + return BadRequest(result); // 返回失败的响应 + } + } + catch (Exception ex) + { + Dictionary errorResult = new Dictionary + { + { "code", "999999" }, + { "mesg", ex.Message } + }; + return StatusCode(500, errorResult); // 返回异常响应 + } + } + /// /// 查询生产工单列表 /// /// /// + [Verify] [HttpGet("list")] [ActionPermissionFilter(Permission = "bydworkorder:list")] public IActionResult QueryBydWorkorder([FromQuery] BydWorkorderQueryDto parm) @@ -46,6 +86,7 @@ namespace DOAN.Admin.WebApi.Controllers.Bydlms /// [HttpGet("{Id}")] [ActionPermissionFilter(Permission = "bydworkorder:query")] + [Verify] public IActionResult GetBydWorkorder(string Id) { var response = _BydWorkorderService.GetInfo(Id); @@ -61,6 +102,7 @@ namespace DOAN.Admin.WebApi.Controllers.Bydlms [HttpPost] [ActionPermissionFilter(Permission = "bydworkorder:add")] [Log(Title = "生产工单", BusinessType = BusinessType.INSERT)] + [Verify] public IActionResult AddBydWorkorder([FromBody] BydWorkorderDto parm) { var modal = parm.Adapt().ToCreate(HttpContext); @@ -70,27 +112,7 @@ namespace DOAN.Admin.WebApi.Controllers.Bydlms return SUCCESS(response); } - /// - /// 批量添加生产工单 - /// - /// - [HttpPost("BatchAddBydWorkorder")] - [AllowAnonymous] - [Log(Title = "批量添加生产工单", BusinessType = BusinessType.INSERT)] - public IActionResult BatchAddBydWorkorder([FromBody] List parm) - { - try - { - var modal = parm.Adapt().ToCreate(HttpContext); - var response = _BydWorkorderService.AddBydWorkorder(modal); - return ToResponse(new ApiResult(000000,"ok", response)); - } - catch (Exception ex) - { - return ToResponse(new ApiResult(500, "error", ex.Message)); - } - - } + /// /// 更新生产工单 @@ -99,6 +121,7 @@ namespace DOAN.Admin.WebApi.Controllers.Bydlms [HttpPut] [ActionPermissionFilter(Permission = "bydworkorder:edit")] [Log(Title = "生产工单", BusinessType = BusinessType.UPDATE)] + [Verify] public IActionResult UpdateBydWorkorder([FromBody] BydWorkorderDto parm) { var modal = parm.Adapt().ToUpdate(HttpContext); @@ -114,6 +137,7 @@ namespace DOAN.Admin.WebApi.Controllers.Bydlms [HttpPost("delete/{ids}")] [ActionPermissionFilter(Permission = "bydworkorder:delete")] [Log(Title = "生产工单", BusinessType = BusinessType.DELETE)] + [Verify] public IActionResult DeleteBydWorkorder([FromRoute]string ids) { var idArr = Tools.SplitAndConvert(ids); diff --git a/DOAN.Admin.WebApi/Program.cs b/DOAN.Admin.WebApi/Program.cs index 4b33ef3..278dea2 100644 --- a/DOAN.Admin.WebApi/Program.cs +++ b/DOAN.Admin.WebApi/Program.cs @@ -52,6 +52,7 @@ builder.Services.AddAppService(); builder.Services.AddTaskSchedulers(); //请求大小限制 builder.Services.AddRequestLimit(builder.Configuration); +//builder.Services.AddHostedService(); //注册REDIS 服务 var openRedis = builder.Configuration["RedisServer:open"]; diff --git a/DOAN.Admin.WebApi/Properties/PublishProfiles/FolderProfile.pubxml b/DOAN.Admin.WebApi/Properties/PublishProfiles/FolderProfile.pubxml index 426a9b5..7fba46f 100644 --- a/DOAN.Admin.WebApi/Properties/PublishProfiles/FolderProfile.pubxml +++ b/DOAN.Admin.WebApi/Properties/PublishProfiles/FolderProfile.pubxml @@ -14,8 +14,9 @@ https://go.microsoft.com/fwlink/?LinkID=208121. FileSystem <_TargetId>Folder - net7.0 + net8.0 e5497bb4-b0c1-4794-9fae-163f626ec399 - false + true + linux-x64 \ No newline at end of file diff --git a/DOAN.Model/Bydlms/BydLine.cs b/DOAN.Model/Bydlms/BydLine.cs new file mode 100644 index 0000000..2096db6 --- /dev/null +++ b/DOAN.Model/Bydlms/BydLine.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DOAN.Model.Bydlms +{ + /// + /// 产线MES预警消息记录 + /// + [SugarTable("byd_line")] + public class BydLine + { + /// + /// 主键 + /// + [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + public int Id { get; set; } + + + + /// + /// 线code + /// + [SugarColumn(ColumnName = "line_code")] + public string LineCode { get; set; } + + + + + /// + /// 线name + /// + [SugarColumn(ColumnName = "line_name")] + public string LineName { get; set; } + + + /// + /// 创建人 + /// + [SugarColumn(ColumnName = "created_by")] + public string CreatedBy { get; set; } + + + /// + /// 创建时间 + /// + [SugarColumn(ColumnName = "created_time")] + public DateTime? CreatedTime { get; set; } + + } + +} diff --git a/DOAN.Model/Bydlms/BydWorkorder.cs b/DOAN.Model/Bydlms/BydWorkorder.cs index 2212337..bd0c0f8 100644 --- a/DOAN.Model/Bydlms/BydWorkorder.cs +++ b/DOAN.Model/Bydlms/BydWorkorder.cs @@ -157,5 +157,17 @@ namespace DOAN.Model.Bydlms [SugarColumn(ColumnName = "uPDATED_TIME")] public DateTime? UpdatedTime { get; set; } + /// + /// 是否已经上传MES + /// + [SugarColumn(ColumnName = "isupload")] + public int Isupload { get; set; } + + /// + /// 同日同线排序25030509001 + /// + [SugarColumn(ColumnName = "sort")] + public int Sort { get; set; } + } } \ No newline at end of file diff --git a/DOAN.Model/Bydlms/DataUpload.cs b/DOAN.Model/Bydlms/DataUpload.cs new file mode 100644 index 0000000..db91de0 --- /dev/null +++ b/DOAN.Model/Bydlms/DataUpload.cs @@ -0,0 +1,150 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DOAN.Model.Bydlms +{ + public class DataUpload + { + public string serviceId { get; set; } + public string factoryCode { get; set; } + + public MachineInfo[] data { get; set; } + } + /// + /// 生产信息参数 + /// + public class MachineInfo + { + /// + /// 产线编码 + /// + public string lineCode { get; set; } + /// + /// 设备编码 + /// + public string machineCode { get; set; } + /// + /// 产品编号 + /// + public string materialCode { get; set; } + /// + /// 产品名称 + /// + public string materialName { get; set; } + /// + /// 产品版本 + /// + public string materialVersion { get; set; } + + /// + /// SN编码 + /// + public string snNumber { get; set; } + + /// + /// 参数名称 + /// + public string paramName { get; set; } + + /// + /// 参数编号 + /// + public string paramCode { get; set; } + + /// + /// 参数地址 + /// + public string paramAddress { get; set; } + + /// + /// 标准值 + /// + public string standardValue { get; set; } + /// + /// 实际值 + /// + public string realValue { get; set; } + /// + /// 参数范围下限 + /// + public double paramRange1 { get; set; } + /// + /// 参数范围上限 + /// + + public double paramRange2 { get; set; } + /// + /// 参数时间 + /// + public DateTime paramTime { get; set; } + /// + /// 数采设备编码 + /// + public string acquisitCode { get; set; } + + /// + /// 工位编码 + /// + public string stationCode { get; set; } + + /// + /// 检测结果标志(PASS:通过,FAIL:不通过) + /// + public string resultFlag { get; set; } + + /// + /// 附件类型 + /// + public string resourceType { get; set; } + /// + /// 附件路径 + /// + public string resourceValue { get; set; } + /// + /// 生产详细参数信息 + /// + public ParamInfo[] data { get; set; } + } + + public class ParamInfo + { + /// + /// 参数名称 + /// + public string paramName { get; set; } + /// + /// 参数编号 + /// + public string paramCode { get; set; } + /// + /// 标准值 + /// + public string standardValue { get; set; } + /// + /// 实际值 + /// + public string realValue { get; set; } + /// + /// 参数范围下限 + /// + public double paramRange1 { get; set; } + /// + /// 参数范围上限 + /// + public double paramRange2 { get; set; } + /// + /// 参数时间 + /// + public DateTime paramTime { get; set; } + /// + /// 判定结果(1是合格,0是不合格) + /// + public int checkResult { get; set; } + + + + } +} diff --git a/DOAN.Model/Bydlms/Dto/BydWorkorderDto.cs b/DOAN.Model/Bydlms/Dto/BydWorkorderDto.cs index e8927b6..bdd90de 100644 --- a/DOAN.Model/Bydlms/Dto/BydWorkorderDto.cs +++ b/DOAN.Model/Bydlms/Dto/BydWorkorderDto.cs @@ -8,12 +8,20 @@ namespace DOAN.Model.Bydlms.Dto { } + public class QueryParam + { + public string LineCode { get; set; } + + public BydWorkorderDto[] Data { get; set; } + + } + /// /// 生产工单输入输出对象 /// public class BydWorkorderDto { - [Required(ErrorMessage = "主键不能为空")] + public string Id { get; set; } public string FactoryCode { get; set; } diff --git a/DOAN.Service/BackService/MyBackgroundService.cs b/DOAN.Service/BackService/MyBackgroundService.cs new file mode 100644 index 0000000..3a8ca6d --- /dev/null +++ b/DOAN.Service/BackService/MyBackgroundService.cs @@ -0,0 +1,53 @@ +using Microsoft.Extensions.Hosting; +using System.Diagnostics.Metrics; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +public class MyBackgroundService : BackgroundService +{ + protected override async Task ExecuteAsync(CancellationToken stoppingToken) + { + while (!stoppingToken.IsCancellationRequested) + { + //具体的后台任务逻辑 + var url = "/api/product/Product_Information?Product006_ProductParameters"; // 替换成你的URL + var data = new { serviceId = "John Doe", Age = 30 }; // 创建要发送的数据对象 + + var jsonData = JsonConvert.SerializeObject(data); + var content = new StringContent(jsonData, Encoding.UTF8, "application/json"); + + var request = new HttpRequestMessage(HttpMethod.Post, url) + { + Content = content + }; + + // 添加请求头 + request.Headers.Add("appId", "61320D6EEF5A48B7C32149DF991BED41"); + request.Headers.Add("appKey", "85725BB0BCCEE8DB1AE2D5A48D393ABE"); + + HttpClient client = new HttpClient(); + HttpResponseMessage response = await client.SendAsync(request); + + response.EnsureSuccessStatusCode(); + + string responseBody = await response.Content.ReadAsStringAsync(); + Console.WriteLine(responseBody); + + + + + + try + { + await Task.Delay(TimeSpan.FromMinutes(10), stoppingToken); // 每隔10分钟执行一次 + } + catch (TaskCanceledException) + { + // 当CancellationToken被触发时,Task.Delay会抛出TaskCanceledException。 + // 这里可以什么都不做或者记录日志等,然后退出循环。 + break; + } + } + } +} \ No newline at end of file diff --git a/DOAN.Service/Bydlms/BydWorkorderService.cs b/DOAN.Service/Bydlms/BydWorkorderService.cs index e3503b9..de81426 100644 --- a/DOAN.Service/Bydlms/BydWorkorderService.cs +++ b/DOAN.Service/Bydlms/BydWorkorderService.cs @@ -13,6 +13,22 @@ namespace DOAN.Service.Bydlms [AppService(ServiceType = typeof(IBydWorkorderService), ServiceLifetime = LifeTime.Transient)] public class BydWorkorderService : BaseService, IBydWorkorderService { + /// + /// 接受比亚迪工单 + /// + /// + /// + public bool AddBydWorkorderList(List workorders) + { + foreach (var workorder in workorders) + { + workorder.Id = SnowFlakeSingle.Instance.NextId().ToString(); + workorder.CreatedBy = "BYD_MES"; + workorder.CreatedTime = DateTime.Now; + } + return Context.Insertable(workorders).ExecuteCommand() > 0; + + } /// /// 查询生产工单列表 /// diff --git a/DOAN.Service/Bydlms/IBydlmsService/IBydWorkorderService.cs b/DOAN.Service/Bydlms/IBydlmsService/IBydWorkorderService.cs index 50e2c80..0fdd3e1 100644 --- a/DOAN.Service/Bydlms/IBydlmsService/IBydWorkorderService.cs +++ b/DOAN.Service/Bydlms/IBydlmsService/IBydWorkorderService.cs @@ -12,7 +12,7 @@ namespace DOAN.Service.Bydlms.IBydlmsService BydWorkorder GetInfo(string Id); - + bool AddBydWorkorderList(List workorders); BydWorkorder AddBydWorkorder(BydWorkorder parm); int UpdateBydWorkorder(BydWorkorder parm); diff --git a/Infrastructure/Controllers/BaseController.cs b/Infrastructure/Controllers/BaseController.cs index 9ef8573..1d39ef4 100644 --- a/Infrastructure/Controllers/BaseController.cs +++ b/Infrastructure/Controllers/BaseController.cs @@ -44,6 +44,7 @@ namespace Infrastructure.Controllers return Content(jsonStr, "application/json"); } + protected IActionResult ToResponse(long rows, string timeFormatStr = "yyyy-MM-dd HH:mm:ss") { string jsonStr = GetJsonStr(ToJson(rows), timeFormatStr);