单位
This commit is contained in:
parent
59089a6814
commit
cc5e008f2b
109
DOAN.Admin.WebApi/Controllers/MES/base/BaseUnitController.cs
Normal file
109
DOAN.Admin.WebApi/Controllers/MES/base/BaseUnitController.cs
Normal file
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// 单位信息
|
||||
/// </summary>
|
||||
[Verify]
|
||||
[Route("mes/baseManagement/BaseUnit")]
|
||||
public class BaseUnitController : BaseController
|
||||
{
|
||||
/// <summary>
|
||||
/// 单位信息接口
|
||||
/// </summary>
|
||||
private readonly IBaseUnitService _BaseUnitService;
|
||||
|
||||
public BaseUnitController(IBaseUnitService BaseUnitService)
|
||||
{
|
||||
_BaseUnitService = BaseUnitService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询单位信息列表
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("list")]
|
||||
[ActionPermissionFilter(Permission = "baseManagement:baseunit:list")]
|
||||
public IActionResult QueryBaseUnit([FromQuery] BaseUnitQueryDto parm)
|
||||
{
|
||||
var response = _BaseUnitService.GetList(parm);
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 查询单位信息详情
|
||||
/// </summary>
|
||||
/// <param name="Id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{Id}")]
|
||||
[ActionPermissionFilter(Permission = "baseManagement:baseunit:query")]
|
||||
public IActionResult GetBaseUnit(int Id)
|
||||
{
|
||||
var response = _BaseUnitService.GetInfo(Id);
|
||||
|
||||
var info = response.Adapt<BaseUnit>();
|
||||
return SUCCESS(info);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加单位信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[ActionPermissionFilter(Permission = "baseManagement:baseunit:add")]
|
||||
[Log(Title = "单位信息", BusinessType = BusinessType.INSERT)]
|
||||
public IActionResult AddBaseUnit([FromBody] BaseUnitDto parm)
|
||||
{
|
||||
var modal = parm.Adapt<BaseUnit>().ToCreate(HttpContext);
|
||||
|
||||
var response = _BaseUnitService.AddBaseUnit(modal);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新单位信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
[ActionPermissionFilter(Permission = "baseManagement:baseunit:edit")]
|
||||
[Log(Title = "单位信息", BusinessType = BusinessType.UPDATE)]
|
||||
public IActionResult UpdateBaseUnit([FromBody] BaseUnitDto parm)
|
||||
{
|
||||
var modal = parm.Adapt<BaseUnit>().ToUpdate(HttpContext);
|
||||
var response = _BaseUnitService.UpdateBaseUnit(modal);
|
||||
|
||||
return ToResponse(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除单位信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -225,7 +225,6 @@ namespace DOAN.Admin.WebApi.Controllers
|
||||
/// </summary>
|
||||
/// <param name="month_str"></param>
|
||||
/// <returns> <日期,排组的数量></returns>
|
||||
|
||||
[HttpGet("month_schedule_result")]
|
||||
public IActionResult GetMonthScheduleResult(string yearmonth)
|
||||
{
|
||||
|
||||
64
DOAN.Model/MES/base/BaseUnit.cs
Normal file
64
DOAN.Model/MES/base/BaseUnit.cs
Normal file
@ -0,0 +1,64 @@
|
||||
|
||||
|
||||
namespace DOAN.Model.MES.base_
|
||||
{
|
||||
/// <summary>
|
||||
/// 单位信息
|
||||
/// </summary>
|
||||
[SugarTable("base_unit")]
|
||||
public class BaseUnit
|
||||
{
|
||||
/// <summary>
|
||||
/// 自增
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 单位名称
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "unit_name")]
|
||||
public string UnitName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 单位代码
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "unit_code")]
|
||||
public string UnitCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
public string Remark { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 状态
|
||||
/// </summary>
|
||||
public int? Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建人
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "cREATED_BY")]
|
||||
public string CreatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "cREATED_TIME")]
|
||||
public DateTime? CreatedTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 更新人
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "uPDATED_BY")]
|
||||
public string UpdatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 更新时间
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "uPDATED_TIME")]
|
||||
public DateTime? UpdatedTime { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
45
DOAN.Model/MES/base/Dto/BaseUnitDto.cs
Normal file
45
DOAN.Model/MES/base/Dto/BaseUnitDto.cs
Normal file
@ -0,0 +1,45 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace DOAN.Model.MES.base_.Dto
|
||||
{
|
||||
/// <summary>
|
||||
/// 单位信息查询对象
|
||||
/// </summary>
|
||||
public class BaseUnitQueryDto : PagerInfo
|
||||
{
|
||||
public string UnitName { get; set; }
|
||||
|
||||
public string UnitCode { get; set; }
|
||||
|
||||
|
||||
public int Status { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 单位信息输入输出对象
|
||||
/// </summary>
|
||||
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; }
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
88
DOAN.Service/MES/base/BaseUnitService.cs
Normal file
88
DOAN.Service/MES/base/BaseUnitService.cs
Normal file
@ -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_
|
||||
{
|
||||
/// <summary>
|
||||
/// 单位信息Service业务层处理
|
||||
/// </summary>
|
||||
[AppService(ServiceType = typeof(IBaseUnitService), ServiceLifetime = LifeTime.Transient)]
|
||||
public class BaseUnitService : BaseService<BaseUnit>, IBaseUnitService
|
||||
{
|
||||
/// <summary>
|
||||
/// 查询单位信息列表
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
public PagedInfo<BaseUnitDto> GetList(BaseUnitQueryDto parm)
|
||||
{
|
||||
var predicate = Expressionable.Create<BaseUnit>()
|
||||
.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<BaseUnit, BaseUnitDto>(parm);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取详情
|
||||
/// </summary>
|
||||
/// <param name="Id"></param>
|
||||
/// <returns></returns>
|
||||
public BaseUnit GetInfo(int Id)
|
||||
{
|
||||
var response = Queryable()
|
||||
.Where(x => x.Id == Id)
|
||||
.First();
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加单位信息
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public BaseUnit AddBaseUnit(BaseUnit model)
|
||||
{
|
||||
return Context.Insertable(model).ExecuteReturnEntity();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改单位信息
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -11,7 +11,7 @@ using Infrastructure.Extensions;
|
||||
using JinianNet.JNTemplate.Dynamic;
|
||||
using SqlSugar;
|
||||
|
||||
namespace DOAN.Service.Business
|
||||
namespace DOAN.Service.MES.base_
|
||||
{
|
||||
/// <summary>
|
||||
/// 工艺路线Service业务层处理
|
||||
|
||||
23
DOAN.Service/MES/base/IService/IBaseUnitService.cs
Normal file
23
DOAN.Service/MES/base/IService/IBaseUnitService.cs
Normal file
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// 单位信息service接口
|
||||
/// </summary>
|
||||
public interface IBaseUnitService : IBaseService<BaseUnit>
|
||||
{
|
||||
PagedInfo<BaseUnitDto> GetList(BaseUnitQueryDto parm);
|
||||
|
||||
BaseUnit GetInfo(int Id);
|
||||
|
||||
BaseUnit AddBaseUnit(BaseUnit parm);
|
||||
|
||||
int UpdateBaseUnit(BaseUnit parm);
|
||||
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
/// <returns></returns>
|
||||
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<string, object> 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<string, object>();
|
||||
}
|
||||
|
||||
private IDictionary<string, object> ConvertToDictionary(IQueryCollection queryCollection)
|
||||
public static Dictionary<string, object> ObjectToDictionary(object obj)
|
||||
{
|
||||
var dictionary = new Dictionary<string, object>();
|
||||
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>(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<object>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user