Commit 4ca88df8 by pengjinyang

第二版

parent 7d497c7c
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;
using static Domain.Domain.TakeStock.TakeStockEnum;
namespace Domain.Domain.TakeStock
{
public class CheckRecord
{
public CheckRecord()
{
this.TheCurrentLink = Link.创建;
this.CreationTime = DateTime.Now;
}
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
[SugarColumn(IsNullable = true, Length = 50)]
public string Sku { get; set; }
[SugarColumn(IsNullable = true, Length = 20)]
public string WarehouseCode { get; set; }
/// <summary>
/// 描述
/// </summary>
[SugarColumn(IsNullable = true, Length = 500)]
public string Description { get; set; }
public Link TheCurrentLink { get; set; }
public DateTime CreationTime { get; set; }
[SugarColumn(IsNullable = true)]
public DateTime LastModifcationTime { get; set; }
}
}
......@@ -2,17 +2,10 @@
using System.Collections.Generic;
using System.Text;
namespace TakeStock.Application.TakeStock.Dto
namespace Domain.Domain.TakeStock.Repository
{
public class CheckRecordInputDto
public interface ITakeStockScheduleRepository: IRepository<TakeStockSchedule>
{
public string Sku { get; set; }
public string WarehouseCode { get; set; }
/// <summary>
/// 描述
/// </summary>
public string Description { get; set; }
bool CreateOrder(TakeStockSchedule order, List<TakeStockOrder> orders);
}
}
......@@ -6,20 +6,21 @@ namespace Domain.Domain.TakeStock
{
public class TakeStockEnum
{
public enum Link
public enum TSScheduleState
{
创建,
冻结库存,
释放库存,
审核,
完成,
取消,
异常
}
public enum CancelACTaskState
public enum TSOrderState
{
创建,
通知OMS,
冻结库存,
释放库存,
盘点中,
完成,
取消,
异常
......
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;
using static Domain.Domain.TakeStock.TakeStockEnum;
namespace Domain.Domain.TakeStock
{
[SugarTable("stock_takestockorder")]
public class TakeStockOrder
{
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
/// <summary>
/// 盘点单号
/// </summary>
[SugarColumn(Length = 50)]
public string Code { get; set; }
public int ScheduleId { get; set; }
/// <summary>
/// 仓库编码
/// </summary>
[SugarColumn(Length = 20)]
public string WarehouseCode { get; set; }
public TSOrderState State { get; set; }
/// <summary>
/// 产品sku
/// </summary>
[SugarColumn(Length = 50)]
public string Sku { get; set; }
/// <summary>
/// 盘点前数量
/// </summary>
[SugarColumn(IsNullable = true)]
public int? BeforeQuantity { get; set; }
/// <summary>
/// 盘点后数量
/// </summary>
[SugarColumn(IsNullable = true)]
public int? AfterQuantity { get; set; }
/// <summary>
/// 备注
/// </summary>
[SugarColumn(IsNullable = true, Length = 500)]
public string Description { get; set; }
public DateTime CreationTime { get; set; }
[SugarColumn(IsNullable = true)]
public long? CreatorUserId { get; set; }
[SugarColumn(IsNullable = true)]
public DateTime? LastModificationTime { get; set; }
[SugarColumn(IsNullable = true)]
public long? LastModifierUserId { get; set; }
}
}
......@@ -6,23 +6,28 @@ using static Domain.Domain.TakeStock.TakeStockEnum;
namespace Domain.Domain.TakeStock
{
public class CheckLog
[SugarTable("stock_takestockorder_log")]
public class TakeStockOrderLog
{
public CheckLog()
{
this.CreationTime = DateTime.Now;
}
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
public int CheckRecordId { get; set; }
public int OrderId { get; set; }
public Link Link { get; set; }
public TSOrderState State { get; set; }
public DateTime CreationTime { get; set; }
[SugarColumn(Length = 500)]
public string Content { get; set; }
[SugarColumn(IsNullable = true, Length = 2000)]
public string Description { get; set; }
public string JsonData { get; set; }
public DateTime CreationTime { get; set; }
public long? CreatorUserId { get; set; }
public DateTime? LastModificationTime { get; set; }
public long? LastModifierUserId { get; set; }
}
}
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;
using static Domain.Domain.TakeStock.TakeStockEnum;
namespace Domain.Domain.TakeStock
{
[SugarTable("stock_takestockschedule")]
public class TakeStockSchedule
{
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
/// <summary>
/// 盘点单号
/// </summary>
[SugarColumn(Length = 50)]
public string Code { get; set; }
/// <summary>
/// 仓库编码
/// </summary>
[SugarColumn(Length = 20)]
public string WarehouseCode { get; set; }
/// <summary>
/// 盘点人Id
/// </summary>
public int ExecutorId { get; set; }
/// <summary>
/// 系统自动盘点
/// </summary>
public bool IsAutomation { get; set; }
/// <summary>
/// 状态
/// </summary>
public TSScheduleState State { get; set; }
/// <summary>
/// 描述
/// </summary>
[SugarColumn(IsNullable = true, Length = 500)]
public string Description { get; set; }
public DateTime CreationTime { get; set; }
[SugarColumn(IsNullable = true)]
public long? CreatorUserId { get; set; }
[SugarColumn(IsNullable = true)]
public DateTime? LastModificationTime { get; set; }
[SugarColumn(IsNullable = true)]
public long? LastModifierUserId { get; set; }
public bool IsDeleted { get; set; }
[SugarColumn(IsNullable = true)]
public long? DeleterUserId { get; set; }
[SugarColumn(IsNullable = true)]
public DateTime? DeletionTime { get; set; }
//public virtual List<TakeStockOrder> Orders { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;
......@@ -24,7 +25,7 @@ namespace Domain
////
//// 返回结果:
//// Count of entities
//int Count(Expression<Func<TEntity, bool>> predicate);
int Count(Expression<Func<TEntity, bool>> predicate);
////
//// 摘要:
//// Gets count of all entities in this repository based on given predicate.
......@@ -221,6 +222,8 @@ namespace Domain
bool InsertFulfill(TEntity entity);
int InsertOnTheBatch(params TEntity[] entityes);
////
//// 摘要:
//// Inserts a new entity and gets it's Id. It may require to save current unit of
......
using Domain.Domain.TakeStock;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace IService.TakeStock
......@@ -10,29 +11,29 @@ namespace IService.TakeStock
/// </summary>
/// <param name="record"></param>
/// <returns></returns>
Task<bool> CreateCheckRecordAsync(CheckRecord record);
Task<bool> CreateTakeStockOrderAsync(TakeStockSchedule record, List<TakeStockOrder> orders);
/// <summary>
/// 冻结库存
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
Task<bool> FreezeStockAsync(int id);
///// <summary>
///// 冻结库存
///// </summary>
///// <param name="id"></param>
///// <returns></returns>
//Task<bool> FreezeStockAsync(int id);
/// <summary>
/// 回滚库存
/// </summary>
/// <param name="warehouseCode"></param>
/// <param name="sku"></param>
/// <returns></returns>
Task<bool> RollbackStockAsync(int id);
///// <summary>
///// 回滚库存
///// </summary>
///// <param name="warehouseCode"></param>
///// <param name="sku"></param>
///// <returns></returns>
//Task<bool> RollbackStockAsync(int id);
/// <summary>
/// 同步和启用库存
/// </summary>
/// <param name="warehouseCode"></param>
/// <param name="sku"></param>
/// <returns></returns>
Task<bool> SyncAndEnabledAsync(int id);
///// <summary>
///// 同步和启用库存
///// </summary>
///// <param name="warehouseCode"></param>
///// <param name="sku"></param>
///// <returns></returns>
//Task<bool> SyncAndEnabledAsync(int id);
}
}
using Domain;
using Domain.Domain.TakeStock;
using Domain.Domain.TakeStock.Repository;
using Hangfire;
using IService.TakeStock;
using MessageQueue;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
......@@ -15,33 +17,36 @@ namespace Service.TakeStock
public class TakeStockService : ITakeStockService
{
private readonly RabbitMQClient mqClient;
private readonly IRepository<CheckRecord> checkRecordRepository;
private readonly IRepository<CheckLog> checkLogRepository;
private readonly ITakeStockScheduleRepository scheduleRepository;
private readonly IRepository<TakeStockOrder> orderRepository;
private readonly IRepository<TakeStockOrderLog> logRepository;
private readonly IHttpClientFactory httpClientFactory;
public TakeStockService(RabbitMQClient mqClient, IRepository<CheckRecord> checkRecordRepository, IRepository<CheckLog> checkLogRepository, IHttpClientFactory httpClientFactory)
public TakeStockService(IHttpClientFactory httpClientFactory, RabbitMQClient mqClient, ITakeStockScheduleRepository scheduleRepository, IRepository<TakeStockOrder> orderRepository, IRepository<TakeStockOrderLog> logRepository)
{
this.mqClient = mqClient;
this.checkRecordRepository = checkRecordRepository;
this.checkLogRepository = checkLogRepository;
this.httpClientFactory = httpClientFactory;
this.mqClient = mqClient;
this.scheduleRepository = scheduleRepository;
this.orderRepository = orderRepository;
this.logRepository = logRepository;
}
/// <summary>
/// 创建盘点记录
/// </summary>
/// <param name="record"></param>
/// <param name="schedule"></param>
/// <returns></returns>
public async Task<bool> CreateCheckRecordAsync(CheckRecord record)
public async Task<bool> CreateTakeStockOrderAsync(TakeStockSchedule schedule, List<TakeStockOrder> orders)
{
return await Task.Run(() =>
{
bool isSuccess = false;
int id = checkRecordRepository.InsertAndGetId(record);
if (id > 0)
bool isSuccess = scheduleRepository.CreateOrder(schedule, orders);
if (isSuccess)
{
BackgroundJob.Enqueue(() => FreezeStockAsync(id));
isSuccess = true;
foreach (var order in orders)
{
BackgroundJob.Enqueue(() => FreezeStockAsync(order.Id));
}
}
return isSuccess;
});
......@@ -54,50 +59,57 @@ namespace Service.TakeStock
/// <returns></returns>
public async Task<bool> FreezeStockAsync(int id)
{
var resord = checkRecordRepository.Get(id);
var order = orderRepository.Get(id);
bool isSuccess = false;
if (order.State == TakeStockEnum.TSOrderState.冻结库存)
isSuccess = true;
else
{
var client = httpClientFactory.CreateClient("WMS");
client.DefaultRequestHeaders.Add("Access-Control-Allow-Origin", "*");
string data = JsonConvert.SerializeObject(new { Data = new { WarehouseCode = resord.WarehouseCode, Sku = resord.Sku } });
//client.DefaultRequestHeaders.Add("Access-Control-Allow-Origin", "*");
string data = JsonConvert.SerializeObject(new { Data = new { WarehouseCode = order.WarehouseCode, Sku = order.Sku } });
HttpContent content = new StringContent(data);
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var response = await client.PostAsync("WMSStockService/FreezeStock", content);
bool isFreeze = false;
bool isSuccess = false;
string dataStr = await response.Content.ReadAsStringAsync();
isFreeze = Convert.ToBoolean(JObject.Parse(dataStr)["data"]);
CheckLog log = new CheckLog();
log.CheckRecordId = id;
if (response.IsSuccessStatusCode)
{
string responseContent = await response.Content.ReadAsStringAsync();
isFreeze = Convert.ToBoolean(JObject.Parse(responseContent)["data"]);
TakeStockOrderLog log = new TakeStockOrderLog();
log.OrderId = id;
if (isFreeze)
{
resord.TheCurrentLink = TakeStockEnum.Link.冻结库存;
resord.LastModifcationTime = DateTime.Now;
order.State = TakeStockEnum.TSOrderState.冻结库存;
order.LastModificationTime = DateTime.Now;
log.Link = TakeStockEnum.Link.冻结库存;
log.Description = "冻结库存成功。";
log.State = TakeStockEnum.TSOrderState.冻结库存;
log.Content = "冻结库存成功。";
isSuccess = true;
}
else
{
resord.TheCurrentLink = TakeStockEnum.Link.异常;
log.Link = TakeStockEnum.Link.异常;
log.Description = "冻结库存失败,WMS返回消息:" + JObject.Parse(dataStr)["message"];
order.State = TakeStockEnum.TSOrderState.异常;
order.LastModificationTime = DateTime.Now;
log.State = TakeStockEnum.TSOrderState.异常;
log.Content = "冻结库存失败,WMS返回消息:" + JObject.Parse(responseContent)["message"];
log.JsonData = responseContent;
}
int row = await checkRecordRepository.UpdateAsync(resord, "TheCurrentLink");
log = await checkLogRepository.InsertAsync(log);
int row = await orderRepository.UpdateAsync(order, "State", "LastModificationTime");
log = await logRepository.InsertAsync(log);
if (!(row > 0 && log.Id > 0))
isSuccess = false;
}
}
if (isSuccess)
BackgroundJob.Enqueue(() => RollbackStockAsync(id));
//await mqClient.SendAsync("takeStock.", resord).ContinueWith(task =>
//{
// isSuccess = task.Result;
//});
else
BackgroundJob.Schedule(() => FreezeStockAsync(id), DateTimeOffset.UtcNow.AddMinutes(1));
return isSuccess;
}
......@@ -109,41 +121,54 @@ namespace Service.TakeStock
/// <returns></returns>
public async Task<bool> RollbackStockAsync(int id)
{
var resord = checkRecordRepository.Get(id);
var order = orderRepository.Get(id);
bool isSuccess = false;
if (order.State == TakeStockEnum.TSOrderState.释放库存)
isSuccess = true;
else
{
var client = httpClientFactory.CreateClient("WMS");
client.DefaultRequestHeaders.Add("Access-Control-Allow-Origin", "*");
string data = JsonConvert.SerializeObject(new { Data = new { WarehouseCode = resord.WarehouseCode, Sku = resord.Sku } });
string data = JsonConvert.SerializeObject(new { Data = new { WarehouseCode = order.WarehouseCode, Sku = order.Sku } });
HttpContent content = new StringContent(data);
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var response = await client.PostAsync("ACOrderService/RollbackStock", content);
bool isSuccess = false;
if (response.IsSuccessStatusCode)
{
var responseContent = await response.Content.ReadAsStringAsync();
isSuccess = JObject.Parse(responseContent)["data"].ToObject<bool>();
CheckLog log = new CheckLog();
log.CheckRecordId = id;
TakeStockOrderLog log = new TakeStockOrderLog();
log.OrderId = id;
if (isSuccess)
{
resord.TheCurrentLink = TakeStockEnum.Link.释放库存;
order.State = TakeStockEnum.TSOrderState.释放库存;
order.LastModificationTime = DateTime.Now;
log.Link = TakeStockEnum.Link.释放库存;
log.Description = $"已释放占用库存。";
log.State = TakeStockEnum.TSOrderState.释放库存;
log.Content = $"已释放占用库存。";
}
else
{
resord.TheCurrentLink = TakeStockEnum.Link.异常;
log.Link = TakeStockEnum.Link.异常;
log.Description = "释放占用库存失败,WMS返回消息:" + responseContent;
order.State = TakeStockEnum.TSOrderState.异常;
order.LastModificationTime = DateTime.Now;
log.State = TakeStockEnum.TSOrderState.异常;
log.Content = "释放占用库存失败,WMS返回消息:" + JObject.Parse(responseContent)["message"];
log.JsonData = responseContent;
}
int row = await checkRecordRepository.UpdateAsync(resord, "TheCurrentLink");
log = await checkLogRepository.InsertAsync(log);
int row = await orderRepository.UpdateAsync(order, "State", "LastModificationTime");
log = await logRepository.InsertAsync(log);
if (!(row > 0 && log.Id > 0)) isSuccess = false;
}
}
if (isSuccess)
{
var schedule = scheduleRepository.Get(order.ScheduleId);
if(schedule.IsAutomation)
BackgroundJob.Enqueue(() => SyncAndEnabledAsync(id));
}
else
BackgroundJob.Schedule(() => RollbackStockAsync(id), DateTimeOffset.UtcNow.AddMinutes(1));
......@@ -158,41 +183,71 @@ namespace Service.TakeStock
/// <returns></returns>
public async Task<bool> SyncAndEnabledAsync(int id)
{
var resord = checkRecordRepository.Get(id);
var order = orderRepository.Get(id);
bool isSuccess = false;
if (order.State == TakeStockEnum.TSOrderState.完成)
isSuccess = true;
else
{
var client = httpClientFactory.CreateClient("WMS");
client.DefaultRequestHeaders.Add("Access-Control-Allow-Origin", "*");
string data = JsonConvert.SerializeObject(new { Data = new { WarehouseCode = resord.WarehouseCode, Sku = resord.Sku } });
string data = JsonConvert.SerializeObject(new { Data = new { WarehouseCode = order.WarehouseCode, Sku = order.Sku } });
HttpContent content = new StringContent(data);
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var response = await client.PostAsync("WMSStockService/SyncAndEnabledStock", content);
bool isSuccess = false;
if (response.IsSuccessStatusCode)
{
var responseContent = await response.Content.ReadAsStringAsync();
isSuccess = Convert.ToBoolean(JObject.Parse(responseContent)["data"]);
CheckLog log = new CheckLog();
log.CheckRecordId = id;
TakeStockOrderLog log = new TakeStockOrderLog();
log.OrderId = id;
if (isSuccess)
{
resord.TheCurrentLink = TakeStockEnum.Link.完成;
log.Link = TakeStockEnum.Link.完成;
log.Description = $"同步并启用库存,盘点完成。";
order.State = TakeStockEnum.TSOrderState.完成;
log.State = TakeStockEnum.TSOrderState.完成;
log.Content = $"同步并启用库存,盘点完成。";
}
else
{
resord.TheCurrentLink = TakeStockEnum.Link.异常;
log.Link = TakeStockEnum.Link.异常;
log.Description = "盘点失败,WMS返回消息:" + JObject.Parse(responseContent)["message"];
BackgroundJob.Schedule(() => SyncAndEnabledAsync(id), DateTimeOffset.UtcNow.AddMinutes(1));
order.State = TakeStockEnum.TSOrderState.异常;
log.State = TakeStockEnum.TSOrderState.异常;
log.Content = "盘点失败,WMS返回消息:" + JObject.Parse(responseContent)["message"];
log.JsonData = responseContent;
}
int row = await checkRecordRepository.UpdateAsync(resord, "TheCurrentLink");
log = await checkLogRepository.InsertAsync(log);
int row = await orderRepository.UpdateAsync(order, "State", "LastModificationTime");
log = await logRepository.InsertAsync(log);
if (!(row > 0 && log.Id > 0))
isSuccess = false;
}
}
if (isSuccess)
BackgroundJob.Enqueue(() => CheckComplete(order.ScheduleId));
else
BackgroundJob.Schedule(() => SyncAndEnabledAsync(id), DateTimeOffset.UtcNow.AddMinutes(1));
return isSuccess;
}
public async Task CheckComplete(int scheduleId)
{
bool isComplete = orderRepository.Count(o => o.ScheduleId == scheduleId && (o.State != TakeStockEnum.TSOrderState.完成 || o.State != TakeStockEnum.TSOrderState.取消)) <= 0;
if (isComplete)
{
var schedule = scheduleRepository.Get(scheduleId);
schedule.State = TakeStockEnum.TSScheduleState.审核;
schedule.LastModificationTime = DateTime.Now;
int row = await scheduleRepository.UpdateAsync(schedule, "State", "LastModificationTime");
//发起报溢报损
//BackgroundJob.Enqueue(() => GainLoss(schedule.Id));
}
}
public async Task GainLoss(int scheduleId)
{
}
}
}
......@@ -44,7 +44,7 @@ namespace TakeStock.API.Controllers
//}
[HttpPost]
public async Task<bool> PostCheckRecord([FromBody] CheckRecordInputDto record)
public async Task<bool> PostCheckRecord([FromBody] ScheduleInputDto record)
{
var result = await takeStockAppService.CreateCheckRecord(record);
return result;
......@@ -56,7 +56,7 @@ namespace TakeStock.API.Controllers
{
//queryStockPoolService.AcquireStockPool().Wait();
//takeStockAppService.FreezeStockAsync(id).Wait();
takeStockAppService.RollbackStockAsync(id).Wait();
//takeStockAppService.RollbackStockAsync(id).Wait();
}
// DELETE: api/ApiWithActions/5
......
using Domain;
using Domain.Domain.TakeStock.Repository;
using Hangfire;
using Hangfire.MySql;
using IService.TakeStock;
......@@ -18,6 +19,7 @@ using System.Transactions;
using TakeStock.API.Extensions;
using TakeStock.Application.TakeStock;
using TakeStock.SqlSugar;
using TakeStock.SqlSugar.Repository.TakeStock;
namespace TakeStock.API
{
......@@ -58,6 +60,7 @@ namespace TakeStock.API
services.AddScoped<ITakeStockService, TakeStockService>();
services.AddScoped<DbContext>();
services.AddScoped(typeof(IRepository<>), typeof(Repository<>));
services.AddScoped(typeof(ITakeStockScheduleRepository), typeof(TakeStockScheduleRepository));
services.AddScoped<TakeStockAppService>();
services.AddHttpClient();
......
......@@ -13,9 +13,10 @@
"Timeout": 120
},
"ConnectionStrings": {
//"Localhost": "server=db;database=takestock;uid=root;pwd=123456;port=3306;Allow User Variables=true;",
"Localhost": "server=gz-cdb-hqmznu0w.sql.tencentcdb.com;port=63523;database=bailun_wms;uid=root;password=#7kfnymAM$Y9-Ntf;Convert Zero Datetime=True;Allow User Variables=true;",
"Redis": "redis"
//"Localhost": "server=gz-cdb-hqmznu0w.sql.tencentcdb.com;port=63523;database=bailun_wms;uid=root;password=#7kfnymAM$Y9-Ntf;Convert Zero Datetime=True;Allow User Variables=true;",
"Localhost": "server=db;database=takestock;uid=root;pwd=123456;port=3306;Allow User Variables=true;",
//"Redis": "127.0.0.1"
"Redis": "172.31.3.191"
},
"App": {
"CorsOrigins": "*"
......
using System;
using System.Collections.Generic;
using System.Text;
using static Domain.Domain.TakeStock.TakeStockEnum;
namespace TakeStock.Application.TakeStock.Dto
{
public class OrderInputDto
{
/// <summary>
/// 盘点单号
/// </summary>
public string Code { get; set; }
/// <summary>
/// 仓库编码
/// </summary>
public string WarehouseCode { get; set; }
public TSOrderState State { get; set; }
/// <summary>
/// 产品sku
/// </summary>
public string Sku { get; set; }
/// <summary>
/// 盘点前数量
/// </summary>
public int? BeforeQuantity { get; set; }
/// <summary>
/// 盘点后数量
/// </summary>
public int? AfterQuantity { get; set; }
/// <summary>
/// 备注
/// </summary>
public string Description { get; set; }
public DateTime CreationTime { get; set; }
public long? CreatorUserId { get; set; }
public DateTime? LastModificationTime { get; set; }
public long? LastModifierUserId { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
using static Domain.Domain.TakeStock.TakeStockEnum;
namespace TakeStock.Application.TakeStock.Dto
{
public class ScheduleInputDto
{
/// <summary>
/// 盘点单号
/// </summary>
public string Code { get; set; }
/// <summary>
/// 仓库编码
/// </summary>
public string WarehouseCode { get; set; }
/// <summary>
/// 盘点人Id
/// </summary>
public int ExecutorId { get; set; }
/// <summary>
/// 状态
/// </summary>
public TSScheduleState State { get; set; }
/// <summary>
/// 描述
/// </summary>
public string Description { get; set; }
public DateTime CreationTime { get; set; }
public long? CreatorUserId { get; set; }
public DateTime? LastModificationTime { get; set; }
public long? LastModifierUserId { get; set; }
public bool IsDeleted { get; set; }
public long? DeleterUserId { get; set; }
public DateTime? DeletionTime { get; set; }
public virtual List<OrderInputDto> Orders { get; set; }
}
}
using Domain.Domain.TakeStock;
using IService.TakeStock;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Text;
......@@ -18,21 +19,22 @@ namespace TakeStock.Application.TakeStock
this.takeStockService = takeStockService;
}
public async Task<bool> CreateCheckRecord(CheckRecordInputDto input)
public async Task<bool> CreateCheckRecord(ScheduleInputDto input)
{
var str = JsonConvert.SerializeObject(input);
CheckRecord record = JsonConvert.DeserializeObject<CheckRecord>(str);
return await takeStockService.CreateCheckRecordAsync(record);
TakeStockSchedule schedule = JsonConvert.DeserializeObject<TakeStockSchedule>(str);
List<TakeStockOrder> orders = JObject.Parse(str)["Orders"].ToObject<List<TakeStockOrder>>();
return await takeStockService.CreateTakeStockOrderAsync(schedule, orders);
}
public async Task<bool> FreezeStockAsync(int id)
{
return await takeStockService.FreezeStockAsync(id);
}
//public async Task<bool> FreezeStockAsync(int id)
//{
// return await takeStockService.FreezeStockAsync(id);
//}
public async Task<bool> RollbackStockAsync(int id)
{
return await takeStockService.RollbackStockAsync(id);
}
//public async Task<bool> RollbackStockAsync(int id)
//{
// return await takeStockService.RollbackStockAsync(id);
//}
}
}
......@@ -59,8 +59,8 @@ namespace SqlSugar
public void Migration()
{
Db.CodeFirst.SetStringDefaultLength(20/*设置varchar默认长度为200*/)
.InitTables(typeof(CheckRecord), typeof(CheckLog));//执行完数据库就有这个表了
//Db.CodeFirst.SetStringDefaultLength(20/*设置varchar默认长度为200*/)
// .InitTables(typeof(TakeStockSchedule), typeof(TakeStockOrder), typeof(TakeStockOrderLog));//执行完数据库就有这个表了
}
}
}
\ No newline at end of file
using Domain;
using SqlSugar;
using System;
using System.Collections;
using System.Threading.Tasks;
namespace TakeStock.SqlSugar
{
public class Repository<TEntity> : IRepository<TEntity> where TEntity : class, new()
{
private readonly SqlSugarClient client;
protected readonly SqlSugarClient client;
public Repository(DbContext dbContext)
{
......@@ -21,7 +22,7 @@ namespace TakeStock.SqlSugar
public int Count(System.Linq.Expressions.Expression<Func<TEntity, bool>> predicate)
{
throw new NotImplementedException();
return client.Queryable<TEntity>().Count(predicate);
}
public Task<int> CountAsync(System.Linq.Expressions.Expression<Func<TEntity, bool>> predicate)
......@@ -134,6 +135,11 @@ namespace TakeStock.SqlSugar
return client.Insertable(entity).ExecuteCommand() > 0;
}
public int InsertOnTheBatch(params TEntity[] entityes)
{
return client.Insertable(entityes).ExecuteCommand();
}
public int InsertAndGetId(TEntity entity)
{
return client.Insertable(entity).ExecuteReturnIdentity();
......
using Domain.Domain.TakeStock;
using Domain.Domain.TakeStock.Repository;
using SqlSugar;
using System;
using System.Collections.Generic;
namespace TakeStock.SqlSugar.Repository.TakeStock
{
public class TakeStockScheduleRepository : Repository<TakeStockSchedule>, ITakeStockScheduleRepository
{
public TakeStockScheduleRepository(DbContext dbContext) : base(dbContext)
{
}
public bool CreateOrder(TakeStockSchedule schedule, List<TakeStockOrder> orders)
{
try
{
client.Ado.BeginTran();
int scheduleId = InsertAndGetId(schedule);
for (int i = 0; i < orders.Count; i++)
{
var order = orders[i];
order.ScheduleId = scheduleId;
order = client.Insertable(order).ExecuteReturnEntity();
}
client.Ado.CommitTran();
return true;
}
catch (Exception ex)
{
client.Ado.RollbackTran();
return false;
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment