using OpenAuth.App.BaseApp.Base; using OpenAuth.Repository.Domain; using OpenAuth.Repository; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using OpenAuth.App.Interface; using SqlSugar; using Infrastructure; using OpenAuth.App.ServiceApp.Response; namespace OpenAuth.App.ServiceApp { public class AirportMaintenanceApp : SqlSugarBaseApp { public AirportMaintenanceApp(ISugarUnitOfWork unitWork, ISimpleClient repository, IAuth auth) : base(unitWork, repository, auth) { } //获取设备绑定码 public async Task> GetDeviceBindingCode() { RefAsync totalCount = 0; using (var db = UnitWork.CreateContext()) { var info = await db.LasaDeviceBindingCode.AsQueryable().Where(r => r.BindStatus == 0).FirstAsync(); if (info != null) { return new Response { Code = 200, Message = "获取设备绑定码成功", Result = info }; } else { //如果设备绑定码不存在,则创建一个新的设备绑定码 var newBindingCode = new LasaDeviceBindingCode { Id = Guid.NewGuid().ToString(), DeviceBindingCode = Guid.NewGuid().ToString("N").Substring(0, 8), // 生成一个新的绑定码 OrgId = "371300", // 默认组织ID OrgName = "临沂市", // 默认组织名称 BindStatus = 0 // 未绑定状态 }; await db.LasaDeviceBindingCode.InsertAsync(newBindingCode); if (db.Commit()) { return new Response { Code = 200, Message = "获取设备绑定码成功", Result = newBindingCode }; } else { return new Response { Code = 500, Message = "获取设备绑定码失败", }; } } } } } }