Commit cc60725d by 赵剑炜

增加消息队列的日志存储

parent 2f1d9517
...@@ -2,3 +2,6 @@ ...@@ -2,3 +2,6 @@
# CS8600: 将 null 字面量或可能为 null 的值转换为非 null 类型。 # CS8600: 将 null 字面量或可能为 null 的值转换为非 null 类型。
dotnet_diagnostic.CS8600.severity = none dotnet_diagnostic.CS8600.severity = none
# CS8618: 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
dotnet_diagnostic.CS8618.severity = silent
...@@ -3,6 +3,7 @@ using APIs.Dto; ...@@ -3,6 +3,7 @@ using APIs.Dto;
using APIs.Req; using APIs.Req;
using Autofac.Core; using Autofac.Core;
using AutoMapper; using AutoMapper;
using Common.Utility.Model;
using Common.Utility.RabbitMQ; using Common.Utility.RabbitMQ;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.AspNetCore.Mvc.ModelBinding;
...@@ -201,8 +202,29 @@ namespace APIs.Controllers ...@@ -201,8 +202,29 @@ namespace APIs.Controllers
public async Task<string> GetTime() public async Task<string> GetTime()
{ {
DateTime reqTime = DateTime.Now; try
return JsonConvert.SerializeObject(reqTime.ToString("yyyy-MM-dd")); {
var src = new ApiResult
{
code = ResultCode.OPERATE_SUCCESS.Code,
msg = ResultCode.OPERATE_SUCCESS.Msg,
data = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
};
return JsonConvert.SerializeObject(src);
}
catch (Exception ex)
{
var error = new ApiResult
{
code = ResultCode.OPERATE_FAILED.Code,
msg = ex.Message,
};
return JsonConvert.SerializeObject(error);
}
} }
/// <summary> /// <summary>
/// 发送消息队列测试 /// 发送消息队列测试
......
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics.CodeAnalysis;
namespace APIs.Req
{
public class RecordsReq
{
public String id { get; set; }
public DateTime useTime { get; set; }
public String userName { get; set; }
public String type { get; set; }
public String equipments { get; set; }
[FromBody]
public List<EquipmentList> equipmentList { get; set; }
[FromBody]
public List<CarList> carList { get; set; }
//
}
public class EquipmentList
{
public String epc { get; set; }
public String equipmentName { get; set; }
public String equipmentSize { get; set; }
public String outInState { get; set; }
public String errorState { get; set; }
}
public class CarList
{
public String carId { get; set; }
public String outInState { get; set; }
public String errorState { get; set; }
}
}
using System; using SqlSugar;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Services.Interface namespace Models
{ {
public interface IEqTypeService public class BaseTable
{ {
[SugarColumn(ColumnName = "update_time")]
public DateTime? updateTime { get; set; }
[SugarColumn(ColumnName = "create_time")]
public DateTime? createTime { get; set; }
} }
} }
...@@ -12,8 +12,4 @@ ...@@ -12,8 +12,4 @@
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Entity\" />
</ItemGroup>
</Project> </Project>
...@@ -21,6 +21,7 @@ namespace Common.Utility.Model ...@@ -21,6 +21,7 @@ namespace Common.Utility.Model
public class EquipmentList public class EquipmentList
{ {
public String invId { get; set; }
public String epc { get; set; } public String epc { get; set; }
public String equipmentName { get; set; } public String equipmentName { get; set; }
public String equipmentSize { get; set; } public String equipmentSize { get; set; }
...@@ -31,8 +32,8 @@ namespace Common.Utility.Model ...@@ -31,8 +32,8 @@ namespace Common.Utility.Model
public class CarList public class CarList
{ {
public String carId { get; set; } public int carId { get; set; }
public String outInState { get; set; } public int outInState { get; set; }
public String errorState { get; set; } public String errorState { get; set; }
} }
......
...@@ -10,7 +10,7 @@ namespace Models.Table ...@@ -10,7 +10,7 @@ namespace Models.Table
{ {
[SugarTable("base_car")] [SugarTable("base_car")]
public class Car public class Car: BaseTable
{ {
[SugarColumn(IsIdentity = true, IsPrimaryKey = true)] [SugarColumn(IsIdentity = true, IsPrimaryKey = true)]
...@@ -22,9 +22,5 @@ namespace Models.Table ...@@ -22,9 +22,5 @@ namespace Models.Table
public String? state { get; set; } public String? state { get; set; }
[SugarColumn(ColumnName = "update_time")]
public DateTime? updateTime { get; set; }
[SugarColumn(ColumnName = "create_time")]
public DateTime? createTime { get; set; }
} }
} }
...@@ -11,7 +11,7 @@ namespace Models.Table ...@@ -11,7 +11,7 @@ namespace Models.Table
{ {
[SugarTable("base_equipment_size")] [SugarTable("base_equipment_size")]
public class EquipmentSize public class EquipmentSize: BaseTable
{ {
[SugarColumn(IsIdentity = true, IsPrimaryKey = true)] [SugarColumn(IsIdentity = true, IsPrimaryKey = true)]
...@@ -30,9 +30,6 @@ namespace Models.Table ...@@ -30,9 +30,6 @@ namespace Models.Table
public String? state { get; set; } public String? state { get; set; }
[SugarColumn(ColumnName = "update_time")]
public DateTime? updateTime { get; set; }
[SugarColumn(ColumnName = "create_time")]
public DateTime? createTime { get; set; }
} }
} }
...@@ -10,7 +10,7 @@ namespace Models.SqlModel ...@@ -10,7 +10,7 @@ namespace Models.SqlModel
{ {
[SugarTable("base_equipment_type")] [SugarTable("base_equipment_type")]
public class EquipmentType public class EquipmentType : BaseTable
{ {
[SugarColumn(IsIdentity = true, IsPrimaryKey = true)] [SugarColumn(IsIdentity = true, IsPrimaryKey = true)]
...@@ -31,10 +31,7 @@ namespace Models.SqlModel ...@@ -31,10 +31,7 @@ namespace Models.SqlModel
public String? note { get; set; } public String? note { get; set; }
public String? type { get; set; } public String? type { get; set; }
[SugarColumn(ColumnName = "update_time")]
public DateTime? updateTime { get; set; }
[SugarColumn(ColumnName = "create_time")]
public DateTime? createTime { get; set; }
} }
} }
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
namespace Models.Table
{
[SugarTable("base_inventory")]
public class Inventory : BaseTable
{
[SugarColumn(IsIdentity = true, IsPrimaryKey = true)]
public String id { get; set; }
[SugarColumn(ColumnName = "type_id")]
public String typeId { get; set; }
[SugarColumn(ColumnName = "size_id")]
public String sizeId { get; set; }
[SugarColumn(ColumnName = "supplier_id")]
public String supplierId { get; set; }
public String epc { get; set; }
[SugarColumn(ColumnName = "org_id")]
public String orgId { get; set; }
public String state { get; set; }
[SugarColumn(ColumnName = "bussiness_state")]
public String bussinessState { get; set; }
[SugarColumn(ColumnName = "production_date")]
public DateTime? productionDate { get; set; }
[SugarColumn(ColumnName = "warranty_period")]
public String warrantyPeriod { get; set; }
[SugarColumn(ColumnName = "maintenance_period")]
public String maintenancePeriod { get; set; }
[SugarColumn(ColumnName = "fix_count")]
public String fixCount { get; set; }
[SugarColumn(ColumnName = "location_id")]
public String locationId { get; set; }
[SugarColumn(ColumnName = "location_type")]
public String locationType { get; set; }
[SugarColumn(ColumnName = "lost_flag")]
public String lostFlag { get; set; }
public String price { get; set; }
}
}
...@@ -11,7 +11,7 @@ namespace Models.Table ...@@ -11,7 +11,7 @@ namespace Models.Table
[SugarTable("base_log_detail")] [SugarTable("base_log_detail")]
public class LogDetail public class LogDetail : BaseTable
{ {
[SugarColumn(IsIdentity = true, IsPrimaryKey = true)] [SugarColumn(IsIdentity = true, IsPrimaryKey = true)]
...@@ -32,9 +32,6 @@ namespace Models.Table ...@@ -32,9 +32,6 @@ namespace Models.Table
[SugarColumn(ColumnName = "car_id")] [SugarColumn(ColumnName = "car_id")]
public int? carid { get; set; } public int? carid { get; set; }
[SugarColumn(ColumnName = "update_time")]
public DateTime? updateTime { get; set; }
[SugarColumn(ColumnName = "create_time")]
public DateTime? createTime { get; set; }
} }
} }
...@@ -10,7 +10,7 @@ namespace Models.Table ...@@ -10,7 +10,7 @@ namespace Models.Table
{ {
[SugarTable("base_log_summary")] [SugarTable("base_log_summary")]
public class LogSummary public class LogSummary : BaseTable
{ {
[SugarColumn(IsIdentity = true, IsPrimaryKey = true)] [SugarColumn(IsIdentity = true, IsPrimaryKey = true)]
...@@ -30,10 +30,8 @@ namespace Models.Table ...@@ -30,10 +30,8 @@ namespace Models.Table
[SugarColumn(ColumnName = "plan_name")] [SugarColumn(ColumnName = "plan_name")]
public String? planName { get; set; } public String? planName { get; set; }
[SugarColumn(ColumnName = "update_time")]
public DateTime? updateTime { get; set; }
[SugarColumn(ColumnName = "create_time")]
public DateTime? createTime { get; set; }
[Navigate(NavigateType.OneToMany, nameof(LogDetail.summaryId))] [Navigate(NavigateType.OneToMany, nameof(LogDetail.summaryId))]
public List<LogDetail> DetailList { get; set; } = new List<LogDetail>(); public List<LogDetail> DetailList { get; set; } = new List<LogDetail>();
} }
......
...@@ -11,7 +11,7 @@ namespace Models.Table ...@@ -11,7 +11,7 @@ namespace Models.Table
[SugarTable("base_personnel")] [SugarTable("base_personnel")]
public class Police public class Police : BaseTable
{ {
[SugarColumn( IsIdentity = true, IsPrimaryKey = true)] [SugarColumn( IsIdentity = true, IsPrimaryKey = true)]
...@@ -25,9 +25,5 @@ namespace Models.Table ...@@ -25,9 +25,5 @@ namespace Models.Table
[SugarColumn(ColumnName = "id_card")] [SugarColumn(ColumnName = "id_card")]
public String? idCard { get; set; } public String? idCard { get; set; }
public String? sex { get; set; } public String? sex { get; set; }
[SugarColumn(ColumnName = "update_time")]
public DateTime? updateTime { get; set; }
[SugarColumn(ColumnName = "create_time")]
public DateTime? createTime { get; set; }
} }
} }
using System; using Models.SqlModel;
using Models.Table;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Services.Interface namespace Repositories.IRepository.IBussiness
{ {
public class IEqSizeService public interface IInventoryRepository : IBaseRepository<Inventory>
{ {
} }
} }
...@@ -16,7 +16,7 @@ namespace Repositories.IRepository.IBussiness ...@@ -16,7 +16,7 @@ namespace Repositories.IRepository.IBussiness
/// </summary> /// </summary>
/// <param name="model"></param> /// <param name="model"></param>
/// <returns></returns> /// <returns></returns>
Task<bool> AddLogs(LogSummary model); Task<bool> AddLogs(LogSummary model, List<Inventory> invs, List<Car> cars);
} }
} }
using Models.SqlModel;
using Models.Table;
using Repositories.IRepository.IBussiness;
using Repositories.IRepository.IUnitOfWork;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Repositories.Repository.Bussiness
{
public class InventoryRepository : BaseRepository<Inventory>, IInventoryRepository
{
public InventoryRepository(ILocalSugarUnitOfWork sugarUnitOfWork) : base(sugarUnitOfWork)
{
}
}
}
...@@ -20,17 +20,20 @@ namespace Repositories.Repository.Bussiness ...@@ -20,17 +20,20 @@ namespace Repositories.Repository.Bussiness
_suger = sugarUnitOfWork; _suger = sugarUnitOfWork;
} }
public async Task<bool> AddLogs(LogSummary model) public async Task<bool> AddLogs(LogSummary model, List<Inventory> inv, List<Car> cars)
{ {
using (var context = _suger.GetDbClient()) using (var context = _suger.GetDbClient())
{ {
try try
{ {
//var invs = await context.Queryable<Inventory>().Where(x =>
//model.DetailList.Select(x => x.epc).Contains(x.epc)).ToListAsync();
context.BeginTran(); context.BeginTran();
var logSum = context.InsertNav(model) await context.Updateable(cars).ExecuteCommandAsync();//实体有多少列更新多少列
var result = await context.Updateable(inv).ExecuteCommandAsync();//实体有多少列更新多少列
var logSum = await context.InsertNav(model)
.Include(z1=>z1.DetailList) .Include(z1=>z1.DetailList)
.ExecuteCommand(); .ExecuteCommandAsync();
context.CommitTran(); context.CommitTran();
} }
catch (Exception e) catch (Exception e)
......
using System; using Models.SqlModel;
using Models.Table;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
...@@ -6,7 +8,8 @@ using System.Threading.Tasks; ...@@ -6,7 +8,8 @@ using System.Threading.Tasks;
namespace Services.Interface namespace Services.Interface
{ {
public class IInventoryService
public interface IInventoryService : IBaseServices<Inventory>
{ {
} }
} }
using Models.SqlModel;
using Models.Table;
using Repositories.IRepository.IBussiness;
using Services.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Services
{
public class InventoryService : BaseService<Inventory>, IInventoryService
{
private readonly IInventoryRepository _inventoryRepository;
public InventoryService(IInventoryRepository inventoryRepository)
{
base.BaseDal = inventoryRepository;
_inventoryRepository = inventoryRepository;
}
}
}
...@@ -39,9 +39,31 @@ namespace Services ...@@ -39,9 +39,31 @@ namespace Services
LogDetail logdetail = mapper.Map<LogDetail>(item); LogDetail logdetail = mapper.Map<LogDetail>(item);
logdetail.createTime = DateTime.Now; logdetail.createTime = DateTime.Now;
logdetail.updateTime = DateTime.Now; logdetail.updateTime = DateTime.Now;
logdetail.state = item.outInState;
log.DetailList.Add(logdetail); log.DetailList.Add(logdetail);
} }
return _logSummaryRepository.AddLogs(log); foreach (var item in model.carList)
{
LogDetail logdetail = new LogDetail();
logdetail.createTime = DateTime.Now;
logdetail.updateTime = DateTime.Now;
logdetail.state = item.outInState;
logdetail.carid = item.carId;
log.DetailList.Add(logdetail);
}
List<Inventory> inveqList = model.equipmentList.Select(x => new Inventory()
{
updateTime = DateTime.Now,
id = x.invId,
state = x.outInState.ToString()
}).ToList();
List<Car> invCarList = model.carList?.Select(x => new Car()
{
updateTime=DateTime.Now,
id = x.carId,
state = x.outInState.ToString()
}).ToList();
return _logSummaryRepository.AddLogs(log, inveqList, invCarList);
} }
} }
} }
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
<ItemGroup> <ItemGroup>
<Compile Remove="Interface\IEqSizeService.cs" /> <Compile Remove="Interface\IEqSizeService.cs" />
<Compile Remove="Interface\IEqTypeService.cs" /> <Compile Remove="Interface\IEqTypeService.cs" />
<Compile Remove="Interface\IInventoryService.cs" />
<Compile Remove="UserService.cs" /> <Compile Remove="UserService.cs" />
</ItemGroup> </ItemGroup>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论