diff --git a/DOAN.Admin.WebApi/Controllers/MES/base/BaseUnitController.cs b/DOAN.Admin.WebApi/Controllers/MES/base/BaseUnitController.cs new file mode 100644 index 0000000..1d5abde --- /dev/null +++ b/DOAN.Admin.WebApi/Controllers/MES/base/BaseUnitController.cs @@ -0,0 +1,109 @@ +using Microsoft.AspNetCore.Mvc; +using DOAN.Model.MES.base_.Dto; +using DOAN.Model.MES.base_; +using DOAN.Service.MES.base_.IService; +using DOAN.Admin.WebApi.Filters; +using DOAN.Service.MES.base_; + +//创建时间:2024-07-08 +namespace DOAN.Admin.WebApi.Controllers +{ + /// + /// 单位信息 + /// + [Verify] + [Route("mes/baseManagement/BaseUnit")] + public class BaseUnitController : BaseController + { + /// + /// 单位信息接口 + /// + private readonly IBaseUnitService _BaseUnitService; + + public BaseUnitController(IBaseUnitService BaseUnitService) + { + _BaseUnitService = BaseUnitService; + } + + /// + /// 查询单位信息列表 + /// + /// + /// + [HttpGet("list")] + [ActionPermissionFilter(Permission = "baseManagement:baseunit:list")] + public IActionResult QueryBaseUnit([FromQuery] BaseUnitQueryDto parm) + { + var response = _BaseUnitService.GetList(parm); + return SUCCESS(response); + } + + + /// + /// 查询单位信息详情 + /// + /// + /// + [HttpGet("{Id}")] + [ActionPermissionFilter(Permission = "baseManagement:baseunit:query")] + public IActionResult GetBaseUnit(int Id) + { + var response = _BaseUnitService.GetInfo(Id); + + var info = response.Adapt(); + return SUCCESS(info); + } + + /// + /// 添加单位信息 + /// + /// + [HttpPost] + [ActionPermissionFilter(Permission = "baseManagement:baseunit:add")] + [Log(Title = "单位信息", BusinessType = BusinessType.INSERT)] + public IActionResult AddBaseUnit([FromBody] BaseUnitDto parm) + { + var modal = parm.Adapt().ToCreate(HttpContext); + + var response = _BaseUnitService.AddBaseUnit(modal); + + return SUCCESS(response); + } + + /// + /// 更新单位信息 + /// + /// + [HttpPut] + [ActionPermissionFilter(Permission = "baseManagement:baseunit:edit")] + [Log(Title = "单位信息", BusinessType = BusinessType.UPDATE)] + public IActionResult UpdateBaseUnit([FromBody] BaseUnitDto parm) + { + var modal = parm.Adapt().ToUpdate(HttpContext); + var response = _BaseUnitService.UpdateBaseUnit(modal); + + return ToResponse(response); + } + + /// + /// 删除单位信息 + /// + /// + [HttpDelete("{ids}")] + [ActionPermissionFilter(Permission = "baseManagement:baseunit:delete")] + [Log(Title = "单位信息", BusinessType = BusinessType.DELETE)] + public IActionResult DeleteBaseUnit(string ids) + { + int[] idsArr = Tools.SpitIntArrary(ids); + if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); } + + var response = _BaseUnitService.Delete(idsArr); + + return ToResponse(response); + } + + + + + } +} \ No newline at end of file diff --git a/DOAN.Admin.WebApi/Controllers/MES/group/GroupScheduleController.cs b/DOAN.Admin.WebApi/Controllers/MES/group/GroupScheduleController.cs index 64e1fab..93dea81 100644 --- a/DOAN.Admin.WebApi/Controllers/MES/group/GroupScheduleController.cs +++ b/DOAN.Admin.WebApi/Controllers/MES/group/GroupScheduleController.cs @@ -225,7 +225,6 @@ namespace DOAN.Admin.WebApi.Controllers /// /// /// <日期,排组的数量> - [HttpGet("month_schedule_result")] public IActionResult GetMonthScheduleResult(string yearmonth) { diff --git a/DOAN.Model/MES/base/BaseUnit.cs b/DOAN.Model/MES/base/BaseUnit.cs new file mode 100644 index 0000000..c0feaa1 --- /dev/null +++ b/DOAN.Model/MES/base/BaseUnit.cs @@ -0,0 +1,64 @@ + + +namespace DOAN.Model.MES.base_ +{ + /// + /// 单位信息 + /// + [SugarTable("base_unit")] + public class BaseUnit + { + /// + /// 自增 + /// + [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + public int Id { get; set; } + + /// + /// 单位名称 + /// + [SugarColumn(ColumnName = "unit_name")] + public string UnitName { get; set; } + + /// + /// 单位代码 + /// + [SugarColumn(ColumnName = "unit_code")] + public string UnitCode { get; set; } + + /// + /// 备注 + /// + public string Remark { get; set; } + + /// + /// 状态 + /// + public int? Status { get; set; } + + /// + /// 创建人 + /// + [SugarColumn(ColumnName = "cREATED_BY")] + public string CreatedBy { get; set; } + + /// + /// 创建时间 + /// + [SugarColumn(ColumnName = "cREATED_TIME")] + public DateTime? CreatedTime { get; set; } + + /// + /// 更新人 + /// + [SugarColumn(ColumnName = "uPDATED_BY")] + public string UpdatedBy { get; set; } + + /// + /// 更新时间 + /// + [SugarColumn(ColumnName = "uPDATED_TIME")] + public DateTime? UpdatedTime { get; set; } + + } +} \ No newline at end of file diff --git a/DOAN.Model/MES/base/Dto/BaseUnitDto.cs b/DOAN.Model/MES/base/Dto/BaseUnitDto.cs new file mode 100644 index 0000000..270a012 --- /dev/null +++ b/DOAN.Model/MES/base/Dto/BaseUnitDto.cs @@ -0,0 +1,45 @@ +using System.ComponentModel.DataAnnotations; + +namespace DOAN.Model.MES.base_.Dto +{ + /// + /// 单位信息查询对象 + /// + public class BaseUnitQueryDto : PagerInfo + { + public string UnitName { get; set; } + + public string UnitCode { get; set; } + + + public int Status { get; set; } + } + + /// + /// 单位信息输入输出对象 + /// + public class BaseUnitDto + { + [Required(ErrorMessage = "自增不能为空")] + public int Id { get; set; } + + public string UnitName { get; set; } + + public string UnitCode { get; set; } + + public string Remark { get; set; } + + public int? Status { get; set; } + + public string CreatedBy { get; set; } + + public DateTime? CreatedTime { get; set; } + + public string UpdatedBy { get; set; } + + public DateTime? UpdatedTime { get; set; } + + + + } +} \ No newline at end of file diff --git a/DOAN.Service/MES/base/BaseUnitService.cs b/DOAN.Service/MES/base/BaseUnitService.cs new file mode 100644 index 0000000..c061eae --- /dev/null +++ b/DOAN.Service/MES/base/BaseUnitService.cs @@ -0,0 +1,88 @@ +using System; +using SqlSugar; +using Infrastructure.Attribute; +using Infrastructure.Extensions; +using DOAN.Model; +using DOAN.Model.MES.base_.Dto; +using DOAN.Model.MES.base_; +using DOAN.Repository; +using DOAN.Service.MES.base_.IService; +using System.Linq; + +namespace DOAN.Service.MES.base_ +{ + /// + /// 单位信息Service业务层处理 + /// + [AppService(ServiceType = typeof(IBaseUnitService), ServiceLifetime = LifeTime.Transient)] + public class BaseUnitService : BaseService, IBaseUnitService + { + /// + /// 查询单位信息列表 + /// + /// + /// + public PagedInfo GetList(BaseUnitQueryDto parm) + { + var predicate = Expressionable.Create() + .AndIF(!string.IsNullOrEmpty(parm.UnitCode),it=>it.UnitCode.Contains(parm.UnitCode)) + .AndIF(!string.IsNullOrEmpty(parm.UnitName),it=>it.UnitName.Contains(parm.UnitName)) + .AndIF(parm.Status>=0,it=>it.Status==parm.Status) + ; + + var response = Queryable() + .Where(predicate.ToExpression()) + .ToPage(parm); + + return response; + } + + + /// + /// 获取详情 + /// + /// + /// + public BaseUnit GetInfo(int Id) + { + var response = Queryable() + .Where(x => x.Id == Id) + .First(); + + return response; + } + + /// + /// 添加单位信息 + /// + /// + /// + public BaseUnit AddBaseUnit(BaseUnit model) + { + return Context.Insertable(model).ExecuteReturnEntity(); + } + + /// + /// 修改单位信息 + /// + /// + /// + public int UpdateBaseUnit(BaseUnit model) + { + //var response = Update(w => w.Id == model.Id, it => new BaseUnit() + //{ + // UnitName = model.UnitName, + // UnitCode = model.UnitCode, + // Remark = model.Remark, + // Status = model.Status, + // CreatedBy = model.CreatedBy, + // CreatedTime = model.CreatedTime, + // UpdatedBy = model.UpdatedBy, + // UpdatedTime = model.UpdatedTime, + //}); + //return response; + return Update(model, true); + } + + } +} \ No newline at end of file diff --git a/DOAN.Service/MES/base/BaseWorkRouteService.cs b/DOAN.Service/MES/base/BaseWorkRouteService.cs index da673ed..efbfb7d 100644 --- a/DOAN.Service/MES/base/BaseWorkRouteService.cs +++ b/DOAN.Service/MES/base/BaseWorkRouteService.cs @@ -11,7 +11,7 @@ using Infrastructure.Extensions; using JinianNet.JNTemplate.Dynamic; using SqlSugar; -namespace DOAN.Service.Business +namespace DOAN.Service.MES.base_ { /// /// 工艺路线Service业务层处理 diff --git a/DOAN.Service/MES/base/IService/IBaseUnitService.cs b/DOAN.Service/MES/base/IService/IBaseUnitService.cs new file mode 100644 index 0000000..5377f1a --- /dev/null +++ b/DOAN.Service/MES/base/IService/IBaseUnitService.cs @@ -0,0 +1,23 @@ +using System; +using DOAN.Model; +using DOAN.Model.MES.base_.Dto; +using DOAN.Model.MES.base_; +using System.Collections.Generic; + +namespace DOAN.Service.MES.base_.IService +{ + /// + /// 单位信息service接口 + /// + public interface IBaseUnitService : IBaseService + { + PagedInfo GetList(BaseUnitQueryDto parm); + + BaseUnit GetInfo(int Id); + + BaseUnit AddBaseUnit(BaseUnit parm); + + int UpdateBaseUnit(BaseUnit parm); + + } +} diff --git a/DOAN.ServiceCore/Filters/GlobalActionMonitor.cs b/DOAN.ServiceCore/Filters/GlobalActionMonitor.cs index 1507ae4..b2900c8 100644 --- a/DOAN.ServiceCore/Filters/GlobalActionMonitor.cs +++ b/DOAN.ServiceCore/Filters/GlobalActionMonitor.cs @@ -10,6 +10,8 @@ using NLog; using DOAN.Model.System; using DOAN.Service.System.IService; using Microsoft.Extensions.Primitives; +using System; +using System.Reflection; namespace DOAN.ServiceCore.Middleware { @@ -30,34 +32,33 @@ namespace DOAN.ServiceCore.Middleware /// public override Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { - var method = context.HttpContext.Request.Method; - - // 根据请求方法获取请求参数 - var parameters = GetRequestParameters(context, method); - - // 遍历每个参数并转换 DateTime 类型的参数 - foreach (var arg in parameters) + foreach (var arg in context.ActionArguments) { + var method = context.HttpContext.Request.Method; + //用来解析get请求 + //if (arg.Value is DateTime dateTime) + //{ + // context.ActionArguments[arg.Key] = dateTime.ToLocalTime(); + //} - //检查是否为 DateTime 类型 - if (arg.Value is DateTime dateTime) - { - //if (dateTime.Kind == DateTimeKind.Utc) - //{ - var localTime = dateTime.ToLocalTime(); - context.ActionArguments[arg.Key] = localTime; - //} - } - // 检查是否为 DateTime? 类型 - if (arg.Value is DateTime? && ((DateTime?)arg.Value).HasValue) - { - var nullableDateTime = (DateTime?)arg.Value; - if (nullableDateTime.Value.Kind == DateTimeKind.Utc) - { - var localTime = nullableDateTime.Value.ToLocalTime(); - context.ActionArguments[arg.Key] = localTime; - } - } + //var PropertyValue = ObjectToDictionary(arg.Value); + //foreach (var pro in PropertyValue) + //{ + // if (pro.Value is DateTime dateTime1) + // { + // PropertyValue[pro.Key] = dateTime1.ToLocalTime(); + + // // 字典属性名称一致的 + // if(arg.Value.GetType().GetProperties()== pro.Key) + // { + + // } + // foreach() + // } + + //} + + context.ActionArguments[arg.Key]= arg.Value; } @@ -174,89 +175,46 @@ namespace DOAN.ServiceCore.Middleware return attribute as LogAttribute; } - private IDictionary GetRequestParameters(ActionExecutingContext context, string method) - { - // 根据请求方法获取请求参数 - if (method.Equals("GET", StringComparison.OrdinalIgnoreCase)) - { - return ConvertToDictionary(context.HttpContext.Request.Query); - } - else if (method.Equals("POST", StringComparison.OrdinalIgnoreCase)) - { - // 假设 POST 请求参数已经绑定到了 ActionArguments 中 - return context.ActionArguments; - } - - return new Dictionary(); - } - - private IDictionary ConvertToDictionary(IQueryCollection queryCollection) + public static Dictionary ObjectToDictionary(object obj) { var dictionary = new Dictionary(); + var properties = obj.GetType().GetProperties(); - foreach (var entry in queryCollection) + foreach (var property in properties) { - // 尝试将查询字符串值转换为对象 - if (TryConvertToObjectOfType(entry.Value, out var value)) - { - dictionary[entry.Key] = value; - } + dictionary.Add(property.Name, property.GetValue(obj)); } return dictionary; } - - private bool TryConvertToObjectOfType(StringValues values, out object convertedValue) + + public static T ConvertDateTimePropertiesToLocalTime(T obj) where T : class { - if (values.Count > 1) + if (obj == null) throw new ArgumentNullException(nameof(obj)); + + var type = obj.GetType(); + var properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance); + + foreach (var property in properties) { - // 处理多个值的情况 - var list = new List(); - foreach (var value in values) + if (property.PropertyType == typeof(DateTime)) { - if (TryParse(value, out var parsedValue)) - { - list.Add(parsedValue); - } + var dateTimeValue = (DateTime)property.GetValue(obj); + var localTimeValue = dateTimeValue.ToLocalTime(); + property.SetValue(obj, localTimeValue); } + } + + return obj; - convertedValue = list; - return true; - } - else - { - return TryParse(values.First(), out convertedValue); - } } - private bool TryParse(string value, out object parsedValue) - { - if (int.TryParse(value, out int intValue)) - { - parsedValue = intValue; - return true; - } - else if (long.TryParse(value, out long longValue)) - { - parsedValue = longValue; - return true; - } - else if (double.TryParse(value, out double doubleValue)) - { - parsedValue = doubleValue; - return true; - } - else if (DateTime.TryParse(value, out DateTime dateTimeValue)) - { - parsedValue = dateTimeValue; - return true; - } - else - { - parsedValue = value; - return true; - } - } + + + } } + + +