change - 服务注册、Swagger配置

master
wenjy 1 year ago
parent 34abe6cb1f
commit b37d649e28

@ -1,72 +0,0 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Security.Principal;
using System.Text;
namespace Durkee.Mes.Api.Model
{
[SugarTable("BASE_BOMINFO"),TenantAttribute("mes")]
public class BaseBomInfo
{
/// <summary>
/// 主键标识
///</summary>
[SugarColumn(ColumnName = "OBJ_ID", IsPrimaryKey = true, IsIdentity = true)]
public int objId { get; set; }
/// <summary>
/// BOM编号
/// </summary>
[SugarColumn(ColumnName = "BOM_CODE")]
public string bomCode { get; set; }
/// <summary>
/// 物料编号
/// </summary>
[SugarColumn(ColumnName = "MATERIAL_CODE")]
public string materialCode { get; set; }
/// <summary>
/// 物料名称
/// </summary>
[SugarColumn(ColumnName = "MATERIAL_NAME")]
public string materialName { get; set; }
/// <summary>
/// 物料类别
/// </summary>
[SugarColumn(ColumnName = "MATERIAL_TYPE")]
public string materialType { get; set; }
/// <summary>
/// 标准数量
/// </summary>
[SugarColumn(ColumnName = "STANDARD_AMOUNT")]
public int standardAmount { get; set; }
/// <summary>
/// 父级编号
/// </summary>
[SugarColumn(ColumnName = "PARENT_ID")]
public string parentId { get; set; }
/// <summary>
/// 工厂编号
/// </summary>
[SugarColumn(ColumnName = "PLANT_CODE")]
public string plantCode { get; set; }
/// <summary>
/// 产线/工位
/// </summary>
[SugarColumn(ColumnName = "PRODUCT_LINE_CODE")]
public string productLineCode { get; set; }
/// <summary>
/// 是否标识
/// </summary>
[SugarColumn(ColumnName = "IS_FLAG")]
public int isFlag { get; set; }
}
}

@ -0,0 +1,105 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Xml.Linq;
using SqlSugar;
namespace Durkee.Mes.Api.Model.domain
{
/// <summary>
/// 系统基础资料-人员基础资料 yuany
///</summary>
[SugarTable("BasUser"), TenantAttribute("mes")]
[DataContract(Name = "BaseUser 人员基础资料")]
public class BaseUser
{
/// <summary>
///
///</summary>
[SugarColumn(ColumnName="ObjID" ,IsPrimaryKey = true ,IsIdentity = true )]
public int ObjID { get; set; }
/// <summary>
///
///</summary>
[SugarColumn(ColumnName="UserName" )]
public string UserName { get; set; }
/// <summary>
///
///</summary>
[SugarColumn(ColumnName="UserPWD" )]
public string UserPWD { get; set; }
/// <summary>
///
///</summary>
[SugarColumn(ColumnName="RealName" )]
public string RealName { get; set; }
/// <summary>
///
/// 默认值: ((1))
///</summary>
[SugarColumn(ColumnName="Sex" )]
public int? Sex { get; set; }
/// <summary>
///
///</summary>
[SugarColumn(ColumnName="Telephone" )]
public string Telephone { get; set; }
/// <summary>
///
///</summary>
[SugarColumn(ColumnName="WorkBarcode" )]
public string WorkBarcode { get; set; }
/// <summary>
///
///</summary>
[SugarColumn(ColumnName="DeptCode" )]
public string DeptCode { get; set; }
/// <summary>
///
///</summary>
[SugarColumn(ColumnName="WorkID" )]
public int? WorkID { get; set; }
/// <summary>
///
///</summary>
[SugarColumn(ColumnName="ShiftID" )]
public int? ShiftID { get; set; }
/// <summary>
///
///</summary>
[SugarColumn(ColumnName="WorkShopID" )]
public int? WorkShopID { get; set; }
/// <summary>
///
///</summary>
[SugarColumn(ColumnName="HRCode" )]
public string HRCode { get; set; }
/// <summary>
///
///</summary>
[SugarColumn(ColumnName="ERPCode" )]
public string ERPCode { get; set; }
/// <summary>
///
/// 默认值: ((0))
///</summary>
[SugarColumn(ColumnName="DeleteFlag" )]
public string DeleteFlag { get; set; }
/// <summary>
///
///</summary>
[SugarColumn(ColumnName="Remark" )]
public string Remark { get; set; }
/// <summary>
///
/// 默认值: ((1))
///</summary>
[SugarColumn(ColumnName="IsEmployee" )]
public string IsEmployee { get; set; }
/// <summary>
///
///</summary>
[SugarColumn(ColumnName="RecordTime" )]
public DateTime? RecordTime { get; set; }
}
}

@ -9,6 +9,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Configuration; using System.Configuration;
using System.Text; using System.Text;
using Durkee.Mes.Api.Model.domain;
namespace Durkee.Mes.Api.Repository namespace Durkee.Mes.Api.Repository
{ {
@ -28,7 +29,7 @@ namespace Durkee.Mes.Api.Repository
new ConnectionConfig() new ConnectionConfig()
{ {
ConfigId = "mes", ConfigId = "mes",
DbType = DbType.Oracle, DbType = DbType.SqlServer,
ConnectionString = appConfig.mesConnStr, ConnectionString = appConfig.mesConnStr,
InitKeyType = InitKeyType.Attribute, InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true, IsAutoCloseConnection = true,
@ -57,8 +58,8 @@ namespace Durkee.Mes.Api.Repository
/// <param name="services"></param> /// <param name="services"></param>
public static void AddServices(this IServiceCollection services) public static void AddServices(this IServiceCollection services)
{ {
services.AddSingleton<Repository<BaseBomInfo>>(); services.AddSingleton<Repository<BaseUser>>();
services.AddSingleton<IBaseBomInfoService, BaseBomInfoServiceImpl>(); services.AddSingleton<IBaseUserService, BaseUserServiceImpl>();
} }
} }
} }

@ -1,12 +0,0 @@
using Durkee.Mes.Api.Model;
using System;
using System.Collections.Generic;
using System.Text;
namespace Durkee.Mes.Api.Repository.service
{
public interface IBaseBomInfoService
{
List<BaseBomInfo> GetBomInfos();
}
}

@ -0,0 +1,16 @@
using Durkee.Mes.Api.Model.domain;
using System;
using System.Collections.Generic;
using System.Text;
namespace Durkee.Mes.Api.Repository.service
{
public interface IBaseUserService
{
/// <summary>
/// 获取用户信息
/// </summary>
/// <returns></returns>
List<BaseUser> GetUsers();
}
}

@ -1,37 +0,0 @@
using Durkee.Mes.Api.Model;
using Microsoft.Extensions.Logging;
using Microsoft.IdentityModel.Logging;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;
namespace Durkee.Mes.Api.Repository.service.Impl
{
public class BaseBomInfoServiceImpl : IBaseBomInfoService
{
private readonly ILogger<BaseBomInfoServiceImpl> _logger;
private readonly Repository<BaseBomInfo> _bomInfoRepository;
public BaseBomInfoServiceImpl(ILogger<BaseBomInfoServiceImpl> logger,Repository<BaseBomInfo> bomInfoRepository)
{
_logger = logger;
_bomInfoRepository = bomInfoRepository;
}
public List<BaseBomInfo> GetBomInfos()
{
try
{
var info = _bomInfoRepository.GetList();
return info;
}
catch (Exception ex)
{
//logHelper.Error("获取BOM集合异常", ex);
_logger.LogError($"获取BOM集合异常:{ex.Message}");
return null;
}
}
}
}

@ -0,0 +1,35 @@
using Durkee.Mes.Api.Model.domain;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Text;
namespace Durkee.Mes.Api.Repository.service.Impl
{
public class BaseUserServiceImpl : IBaseUserService
{
private readonly ILogger<BaseUser> _logger;
private readonly Repository<BaseUser> _rep;
public BaseUserServiceImpl(ILogger<BaseUser> logger, Repository<BaseUser> rep)
{
_logger = logger;
_rep = rep;
}
public List<BaseUser> GetUsers()
{
List<BaseUser> users = null;
try
{
users = _rep.GetList();
}catch(Exception ex)
{
_logger.LogError($"获取用户信息异常{ex.Message}");
}
return users;
}
}
}

@ -0,0 +1,80 @@
using Durkee.Mes.Api.Model.domain;
using Durkee.Mes.Api.Repository.service;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using SqlSugar;
using System;
using System.Collections.Generic;
namespace Durkee.Mes.Api.Controllers
{
/// <summary>
/// 人员基础信息
/// </summary>
[Route("api/[controller]")]
[ApiController]
public class BaseUserController : ControllerBase
{
private readonly ILogger<BaseUserController> _logger;
private readonly IBaseUserService _service;
public BaseUserController(ILogger<BaseUserController> logger, IBaseUserService service)
{
_logger = logger;
_service = service;
}
/// <summary>
/// 获取人员基础信息
/// </summary>
/// <returns></returns>
[HttpGet]
public IEnumerable<BaseUser> Get()
{
IEnumerable<BaseUser> users = null;
try
{
users = _service.GetUsers();
}
catch(Exception ex)
{
_logger.LogError($"获取用户信息接口调用异常:{ex.Message}");
}
return users;
}
/// <summary>
/// 通过用户名称获取指定用户信息
/// </summary>
/// <param name="userName">用户名称</param>
/// <returns></returns>
[HttpGet("Gets/{userName}")]
public IEnumerable<BaseUser> GetUserByUserName(string userName)
{
IEnumerable<BaseUser> users = null;
try
{
users = _service.GetUsers();
}
catch (Exception ex)
{
_logger.LogError($"获取用户信息接口调用异常:{ex.Message}");
}
return users;
}
/// <summary>
/// 添加用户信息
/// </summary>
/// <param name="user">用户信息</param>
/// <returns></returns>
[HttpPut]
public bool InsertUserInfo(BaseUser user)
{
var info = user;
return true;
}
}
}

@ -1,54 +0,0 @@
using Durkee.Mes.Api.Config;
using Durkee.Mes.Api.Repository;
using Durkee.Mes.Api.Repository.service;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Durkee.Mes.Api.Controllers
{
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ILogger<WeatherForecastController> _logger;
private IBaseBomInfoService _service;
public WeatherForecastController(ILogger<WeatherForecastController> logger, AppConfig appConfig, IBaseBomInfoService service)
{
_logger = logger;
_service = service;
}
[HttpGet]
public IEnumerable<WeatherForecast> Get()
{
try
{
var info = _service.GetBomInfos();
var rng = new Random();
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = rng.Next(-20, 55),
Summary = Summaries[rng.Next(Summaries.Length)]
})
.ToArray();
}catch(Exception ex)
{
_logger.LogError("异常", ex);
}
return null;
}
}
}

@ -4,6 +4,8 @@
<TargetFramework>netcoreapp3.1</TargetFramework> <TargetFramework>netcoreapp3.1</TargetFramework>
<!-- Other project properties --> <!-- Other project properties -->
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings> <SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<ProduceReferenceAssembly>True</ProduceReferenceAssembly>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

@ -1,21 +1,17 @@
using Durkee.Mes.Api.Config; using Durkee.Mes.Api.Config;
using Durkee.Mes.Api.Model;
using Durkee.Mes.Api.Repository; using Durkee.Mes.Api.Repository;
using Durkee.Mes.Api.Repository.service;
using Durkee.Mes.Api.Repository.service.Impl;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.IdentityModel.Logging;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
using Serilog; using Serilog;
using Serilog.Events; using Serilog.Events;
using SqlSugar;
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Runtime.Serialization;
namespace Durkee.Mes.Api namespace Durkee.Mes.Api
{ {
@ -36,7 +32,27 @@ namespace Durkee.Mes.Api
//配置Swagger //配置Swagger
services.AddSwaggerGen(swagger => services.AddSwaggerGen(swagger =>
{ {
swagger.SwaggerDoc("v1", new OpenApiInfo { Title = "杜肯MES Web Api", Version = "v1" }); //自定义接口信息
swagger.SwaggerDoc("V1.0", new OpenApiInfo {
Title = "杜肯MES Web Api",
Version = "V1.0",
Description = $"API版本V1.0",
Contact = new OpenApiContact
{
Name = "MES Web Api",
Email = "wenjy@mesnac.com"
}
});
//自定义实体别名
swagger.CustomSchemaIds(type => type.GetCustomAttributes(typeof(DataContractAttribute), true)
.Cast<DataContractAttribute>()
.FirstOrDefault()?.Name);
//配置Action名称
var path = Path.Combine(AppContext.BaseDirectory, "Durkee.Mes.Api.xml");
swagger.IncludeXmlComments(path, true); // true : 显示控制器层注释
swagger.OrderActionsBy(o => o.RelativePath); // 对action的名称进行排序如果有多个就可以看见效果了。
}); });
//注册配置类 //注册配置类
@ -65,10 +81,8 @@ namespace Durkee.Mes.Api
app.UseSwagger(); app.UseSwagger();
app.UseSwaggerUI(c => app.UseSwaggerUI(c =>
{ {
c.SwaggerEndpoint("/swagger/v1/swagger.json", "杜肯MES Web Api"); c.SwaggerEndpoint("/swagger/V1.0/swagger.json", "杜肯MES Web Api V1.0");
c.RoutePrefix = ""; c.RoutePrefix = "";
//c.DefaultModelRendering(ModelRendering.Example); // 设置默认的模型渲染方式(可选)
//c.DisplayRequestDuration(); // 显示请求持续时间(可选)
}); });
//启用Serilog中间件 //启用Serilog中间件

@ -1,15 +0,0 @@
using System;
namespace Durkee.Mes.Api
{
public class WeatherForecast
{
public DateTime Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string Summary { get; set; }
}
}

@ -9,7 +9,7 @@
"AllowedHosts": "*", "AllowedHosts": "*",
"AppConfig": { "AppConfig": {
"logPath": "E:/代码生成/日志信息", "logPath": "E:/代码生成/日志信息",
"mesConnStr": "Data Source=175.27.215.92/helowin;User ID=aucma_mes;Password=aucma", "mesConnStr": "server=.;uid=sa;pwd=123456;database=JiangYinMENS",
"mcsConnStr": "Data Source=175.27.215.92/helowin;User ID=aucma_scada;Password=aucma" "mcsConnStr": "Data Source=175.27.215.92/helowin;User ID=aucma_scada;Password=aucma"
} }
} }

Loading…
Cancel
Save