Browse Source

优化代码

shengtang
747575620@qq.com 1 year ago
parent
commit
c3f6f1380d
9 changed files with 120 additions and 19 deletions
  1. +26
    -1
      backend/BPA.MES.Base.Application/BPA.MES.Base.Application.xml
  2. +4
    -0
      backend/BPA.MES.Base.Application/Entitys/App/Pztj_CraftStepsEntity.cs
  3. +4
    -3
      backend/BPA.MES.Base.Application/MQTT/MQTTService.cs
  4. +4
    -1
      backend/BPA.MES.Base.Application/MQTT/MsgPackage.cs
  5. +21
    -1
      backend/BPA.MES.Base.Application/Services/WorkInfoService/Dtos/WorkInfoDto.cs
  6. +1
    -1
      backend/BPA.MES.Base.Application/Services/WorkInfoService/Services/IWorkInfoService.cs
  7. +31
    -5
      backend/BPA.MES.Base.Application/Services/WorkInfoService/Services/WorkInfoService.cs
  8. +28
    -5
      backend/BPA.MES.Base.Web.Core/Handlers/JwtHandler.cs
  9. +1
    -2
      backend/BPA.MES.Base.Web.Core/Startup.cs

+ 26
- 1
backend/BPA.MES.Base.Application/BPA.MES.Base.Application.xml View File

@@ -225,6 +225,11 @@
描 述 :
</summary>
</member>
<member name="P:BPA.MES.Base.Application.Entitys.Pztj_CraftStepsEntity.CraftId">
<summary>
步骤Id
</summary>
</member>
<member name="P:BPA.MES.Base.Application.Entitys.Pztj_CraftStepsEntity.Step">
<summary>
步骤
@@ -1051,6 +1056,11 @@
消息长度
</summary>
</member>
<member name="P:BPA.MES.Base.Application.MsgPackage`1.MsgVersion">
<summary>
消息版本
</summary>
</member>
<member name="T:BPA.MES.Base.Application.Topics">
<summary>
名 称 :
@@ -3976,7 +3986,22 @@
</member>
<member name="P:BPA.MES.Base.Application.Services.WorkInfoOutput.Status">
<summary>
产线状态
工单状态
</summary>
</member>
<member name="T:BPA.MES.Base.Application.Services.WorkInfoDetailOutput">
<summary>
详情输出
</summary>
</member>
<member name="P:BPA.MES.Base.Application.Services.WorkInfoDetailOutput.CraftList">
<summary>
工艺步骤
</summary>
</member>
<member name="P:BPA.MES.Base.Application.Services.WorkInfoDetailOutput.MaterialList">
<summary>
物料信息
</summary>
</member>
<member name="T:BPA.MES.Base.Application.Services.WorkInfoItemDto">


+ 4
- 0
backend/BPA.MES.Base.Application/Entitys/App/Pztj_CraftStepsEntity.cs View File

@@ -9,6 +9,10 @@
[SugarTable("craft_Steps")]
public class Pztj_CraftStepsEntity : DEntityBase
{
/// <summary>
/// 步骤Id
/// </summary>
public string CraftId { get; set; }
/// <summary>
/// 步骤
/// </summary>


+ 4
- 3
backend/BPA.MES.Base.Application/MQTT/MQTTService.cs View File

@@ -33,7 +33,8 @@ namespace BPA.MES.Base.Application
public async Task<bool> MqttPublish<T>(T payload, string topic,int messageId)
{
bool result = false;
string mqttAddress = MQTTConfig.Address;
var mqttentity = await _dbContext.Queryable<MQTTInfoEntity>().FirstAsync();
string mqttAddress = mqttentity.Address;
try
{
//组装MQTT消息
@@ -45,14 +46,14 @@ namespace BPA.MES.Base.Application
};
var tem = await $"http://{mqttAddress}/api/v4/mqtt/publish".SetHeaders(new
{
Authorization = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes($"{MQTTConfig.Account}:{MQTTConfig.Pwd}"))
Authorization = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes($"{mqttentity.Account}:{mqttentity.Pwd}"))
}).SetBody(new
{
topic,
payload = JSON.Serialize(entity),
qos = 2,
retain = false,
clientid = "st_service"
clientid = "pztj_service"
}).PostAsStringAsync();
var res = JSON.Deserialize<MqttResult>(tem);
if (res.Code == 0)


+ 4
- 1
backend/BPA.MES.Base.Application/MQTT/MsgPackage.cs View File

@@ -12,10 +12,13 @@
/// </summary>
//[JsonProperty(TypeNameHandling = TypeNameHandling.Auto)]
public T Message { get; set; }

/// <summary>
/// 消息长度
/// </summary>
public int MessageLen { get; set; }
/// <summary>
/// 消息版本
/// </summary>
public Version MsgVersion { get; set; } = new Version(1, 0, 0, 0);
}
}

+ 21
- 1
backend/BPA.MES.Base.Application/Services/WorkInfoService/Dtos/WorkInfoDto.cs View File

@@ -110,10 +110,30 @@
/// </summary>
public string LineName { get; set; }
/// <summary>
/// 产线状态
/// 工单状态
/// </summary>
public WorkOrderStatusEnum? Status { get; set; }
}
/// <summary>
/// 详情输出
/// </summary>
public class WorkInfoDetailOutput : WorkInfoOutput
{
public WorkInfoDetailOutput()
{

CraftList = new();
MaterialList = new();
}
/// <summary>
/// 工艺步骤
/// </summary>
public List<Pztj_CraftStepsEntity> CraftList { get; set; }
/// <summary>
/// 物料信息
/// </summary>
public List<RecipeMaterialEntity> MaterialList { get; set; }
}
}

+ 1
- 1
backend/BPA.MES.Base.Application/Services/WorkInfoService/Services/IWorkInfoService.cs View File

@@ -43,7 +43,7 @@
/// </summary>
/// <param name="Id"></param>
/// <returns></returns>
Task<WorkInfoOutput> Detail(string Id);
Task<WorkInfoDetailOutput> Detail(string Id);
/// <summary>
/// 更改状态
/// </summary>


+ 31
- 5
backend/BPA.MES.Base.Application/Services/WorkInfoService/Services/WorkInfoService.cs View File

@@ -67,11 +67,37 @@ namespace BPA.MES.Base.Application.Services.WorkInfoService.Services
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
[HttpGet]
public async Task<WorkInfoOutput> Detail(string Id)
public async Task<WorkInfoDetailOutput> Detail(string Id)
{
var entity = await _dbContext.Queryable<Pztj_WorkInfoEntity>().FirstAsync(x => x.Id == Id);
WorkInfoOutput output = entity.Adapt<WorkInfoOutput>();
return output;
var entity = await _dbContext.Queryable<Pztj_WorkInfoEntity>()
.LeftJoin<Pztj_FinalsInfoEntity>((a, b) => a.FinalId == b.Id)
.LeftJoin<ProductLineEntity>((a, b, c) => a.LineId == c.Id)
.LeftJoin<Pztj_WorkInfoStatusEntity>((a, b, c, d) => d.Id == SqlFunc.Subqueryable<Pztj_WorkInfoStatusEntity>().Where(s => s.WorkId == a.Id).OrderByDesc(s => s.CreateTime).Select(s => s.Id))
.Where((a, b, c, d) => a.Id == Id)
.Select((a, b, c, d) => new WorkInfoDetailOutput
{
Id = a.Id.SelectAll(),
FinalName = b.Name,
LineName = c.Name,
Status = d.Status == null ? WorkOrderStatusEnum.Draft : d.Status
}).FirstAsync();
if (entity==null)
{
throw Oops.Bah("没有找到工单信息!");
}
//获取成品信息
var finainfo = await _dbContext.Queryable<Pztj_FinalsInfoEntity>().FirstAsync(x => x.Id == entity.FinalId);
if (finainfo==null)
{
throw Oops.Bah("没有找到成品信息!");
}
//获取工艺步骤
var craftlist = await _dbContext.Queryable<Pztj_CraftStepsEntity>().Where(x => x.CraftId == finainfo.CraftId).ToListAsync();
//获取物料信息
var materiallist = await _dbContext.Queryable<RecipeMaterialEntity>().Where(x => x.RecipesId == finainfo.RecipeId).ToListAsync();
entity.CraftList = craftlist;
entity.MaterialList = materiallist;
return entity;
}
/// <summary>
/// 列表
@@ -139,7 +165,7 @@ namespace BPA.MES.Base.Application.Services.WorkInfoService.Services
var entity = await _dbContext.Queryable<Pztj_WorkInfoEntity>().FirstAsync(x => x.Id == workId);
if (res)
{
await _MQTTService.MqttPublish(entity, Topics.DeviceDataPush, MessageID.WorkOrderIssued);
await _MQTTService.MqttPublish(entity, Topics.WorkOrderPush, MessageID.WorkOrderIssued);
}
return true;
}


+ 28
- 5
backend/BPA.MES.Base.Web.Core/Handlers/JwtHandler.cs View File

@@ -1,4 +1,5 @@
using Furion.Authorization;
using Furion;
using Furion.Authorization;
using Furion.DataEncryption;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
@@ -15,12 +16,29 @@ public class JwtHandler : AppAuthorizeHandler
/// <returns></returns>
public override async Task HandleAsync(AuthorizationHandlerContext context)
{
// 自动刷新 token
if (JWTEncryption.AutoRefreshToken(context, context.GetCurrentHttpContext(), expiredTime: 20, refreshTokenExpiredTime: 25))
var IsClient = App.HttpContext.Request.Headers["IsClient"].ToString();
if (IsClient == "true")
{
await AuthorizeHandleAsync(context);
//获取所有未成功验证的需求
var pendingRequirements = context.PendingRequirements;
// 通过授权验证
foreach (var requirement in pendingRequirements)
{
context.Succeed(requirement);
}
}
else
{
// 自动刷新 token
if (JWTEncryption.AutoRefreshToken(context, context.GetCurrentHttpContext(), expiredTime: 20, refreshTokenExpiredTime: 25))
{
await AuthorizeHandleAsync(context);
}
else
{
context.Fail(); // 授权失败
}
}
else context.Fail(); // 授权失败
}
public override Task<bool> PipelineAsync(AuthorizationHandlerContext context, DefaultHttpContext httpContext)
{
@@ -36,6 +54,11 @@ public class JwtHandler : AppAuthorizeHandler
private static bool CheckAuthorzie(DefaultHttpContext httpContext)
{
// 获取权限特性
var IsClient = App.HttpContext.Request.Headers["IsClient"].ToString();
if (IsClient == "true")
{
return true;
}
var securityDefineAttribute = httpContext.GetMetadata<SecurityDefineAttribute>();
if (securityDefineAttribute == null)
{


+ 1
- 2
backend/BPA.MES.Base.Web.Core/Startup.cs View File

@@ -29,6 +29,7 @@ public class Startup : AppStartup
// 通过类型注册
builder.AddSubscriber(typeof(ToDoEventSubscriber));
});
services.AddRemoteRequest();
services.AddControllers()
.AddInjectWithUnifyResult();
}
@@ -55,7 +56,5 @@ public class Startup : AppStartup
{
endpoints.MapControllers();
});
var server = App.GetService<IMQTTService>();
server.GetMQTTConfig();
}
}

Loading…
Cancel
Save