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 @@ ...@@ -2,17 +2,10 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; 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; } bool CreateOrder(TakeStockSchedule order, List<TakeStockOrder> orders);
public string WarehouseCode { get; set; }
/// <summary>
/// 描述
/// </summary>
public string Description { get; set; }
} }
} }
...@@ -6,20 +6,21 @@ namespace Domain.Domain.TakeStock ...@@ -6,20 +6,21 @@ namespace Domain.Domain.TakeStock
{ {
public class TakeStockEnum 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; ...@@ -6,23 +6,28 @@ using static Domain.Domain.TakeStock.TakeStockEnum;
namespace Domain.Domain.TakeStock 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)] [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; } public int Id { get; set; }
public int CheckRecordId { get; set; }
public Link Link { get; set; } public int OrderId { get; set; }
public TSOrderState State { get; set; }
[SugarColumn(Length = 500)]
public string Content { get; set; }
public DateTime CreationTime { get; set; }
[SugarColumn(IsNullable = true, Length = 2000)] [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;
using System.Collections.Generic;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Threading.Tasks; using System.Threading.Tasks;
...@@ -24,7 +25,7 @@ namespace Domain ...@@ -24,7 +25,7 @@ namespace Domain
//// ////
//// 返回结果: //// 返回结果:
//// Count of entities //// 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. //// Gets count of all entities in this repository based on given predicate.
...@@ -221,6 +222,8 @@ namespace Domain ...@@ -221,6 +222,8 @@ namespace Domain
bool InsertFulfill(TEntity entity); 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 //// Inserts a new entity and gets it's Id. It may require to save current unit of
......
using Domain.Domain.TakeStock; using Domain.Domain.TakeStock;
using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace IService.TakeStock namespace IService.TakeStock
...@@ -10,29 +11,29 @@ namespace IService.TakeStock ...@@ -10,29 +11,29 @@ namespace IService.TakeStock
/// </summary> /// </summary>
/// <param name="record"></param> /// <param name="record"></param>
/// <returns></returns> /// <returns></returns>
Task<bool> CreateCheckRecordAsync(CheckRecord record); Task<bool> CreateTakeStockOrderAsync(TakeStockSchedule record, List<TakeStockOrder> orders);
/// <summary> ///// <summary>
/// 冻结库存 ///// 冻结库存
/// </summary> ///// </summary>
/// <param name="id"></param> ///// <param name="id"></param>
/// <returns></returns> ///// <returns></returns>
Task<bool> FreezeStockAsync(int id); //Task<bool> FreezeStockAsync(int id);
/// <summary> ///// <summary>
/// 回滚库存 ///// 回滚库存
/// </summary> ///// </summary>
/// <param name="warehouseCode"></param> ///// <param name="warehouseCode"></param>
/// <param name="sku"></param> ///// <param name="sku"></param>
/// <returns></returns> ///// <returns></returns>
Task<bool> RollbackStockAsync(int id); //Task<bool> RollbackStockAsync(int id);
/// <summary> ///// <summary>
/// 同步和启用库存 ///// 同步和启用库存
/// </summary> ///// </summary>
/// <param name="warehouseCode"></param> ///// <param name="warehouseCode"></param>
/// <param name="sku"></param> ///// <param name="sku"></param>
/// <returns></returns> ///// <returns></returns>
Task<bool> SyncAndEnabledAsync(int id); //Task<bool> SyncAndEnabledAsync(int id);
} }
} }
using Domain; using Domain;
using Domain.Domain.TakeStock; using Domain.Domain.TakeStock;
using Domain.Domain.TakeStock.Repository;
using Hangfire; using Hangfire;
using IService.TakeStock; using IService.TakeStock;
using MessageQueue; using MessageQueue;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System; using System;
using System.Collections.Generic;
using System.Net.Http; using System.Net.Http;
using System.Net.Http.Headers; using System.Net.Http.Headers;
using System.Threading.Tasks; using System.Threading.Tasks;
...@@ -15,33 +17,36 @@ namespace Service.TakeStock ...@@ -15,33 +17,36 @@ namespace Service.TakeStock
public class TakeStockService : ITakeStockService public class TakeStockService : ITakeStockService
{ {
private readonly RabbitMQClient mqClient; private readonly RabbitMQClient mqClient;
private readonly IRepository<CheckRecord> checkRecordRepository; private readonly ITakeStockScheduleRepository scheduleRepository;
private readonly IRepository<CheckLog> checkLogRepository; private readonly IRepository<TakeStockOrder> orderRepository;
private readonly IRepository<TakeStockOrderLog> logRepository;
private readonly IHttpClientFactory httpClientFactory; 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.httpClientFactory = httpClientFactory;
this.mqClient = mqClient;
this.scheduleRepository = scheduleRepository;
this.orderRepository = orderRepository;
this.logRepository = logRepository;
} }
/// <summary> /// <summary>
/// 创建盘点记录 /// 创建盘点记录
/// </summary> /// </summary>
/// <param name="record"></param> /// <param name="schedule"></param>
/// <returns></returns> /// <returns></returns>
public async Task<bool> CreateCheckRecordAsync(CheckRecord record) public async Task<bool> CreateTakeStockOrderAsync(TakeStockSchedule schedule, List<TakeStockOrder> orders)
{ {
return await Task.Run(() => return await Task.Run(() =>
{ {
bool isSuccess = false; bool isSuccess = scheduleRepository.CreateOrder(schedule, orders);
int id = checkRecordRepository.InsertAndGetId(record); if (isSuccess)
if (id > 0)
{ {
BackgroundJob.Enqueue(() => FreezeStockAsync(id)); foreach (var order in orders)
isSuccess = true; {
BackgroundJob.Enqueue(() => FreezeStockAsync(order.Id));
}
} }
return isSuccess; return isSuccess;
}); });
...@@ -54,50 +59,57 @@ namespace Service.TakeStock ...@@ -54,50 +59,57 @@ namespace Service.TakeStock
/// <returns></returns> /// <returns></returns>
public async Task<bool> FreezeStockAsync(int id) public async Task<bool> FreezeStockAsync(int id)
{ {
var resord = checkRecordRepository.Get(id); var order = orderRepository.Get(id);
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 } });
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; bool isSuccess = false;
string dataStr = await response.Content.ReadAsStringAsync(); if (order.State == TakeStockEnum.TSOrderState.冻结库存)
isFreeze = Convert.ToBoolean(JObject.Parse(dataStr)["data"]);
CheckLog log = new CheckLog();
log.CheckRecordId = id;
if (isFreeze)
{
resord.TheCurrentLink = TakeStockEnum.Link.冻结库存;
resord.LastModifcationTime = DateTime.Now;
log.Link = TakeStockEnum.Link.冻结库存;
log.Description = "冻结库存成功。";
isSuccess = true; isSuccess = true;
}
else else
{ {
resord.TheCurrentLink = TakeStockEnum.Link.异常; var client = httpClientFactory.CreateClient("WMS");
log.Link = TakeStockEnum.Link.异常; //client.DefaultRequestHeaders.Add("Access-Control-Allow-Origin", "*");
log.Description = "冻结库存失败,WMS返回消息:" + JObject.Parse(dataStr)["message"]; 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;
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)
{
order.State = TakeStockEnum.TSOrderState.冻结库存;
order.LastModificationTime = DateTime.Now;
log.State = TakeStockEnum.TSOrderState.冻结库存;
log.Content = "冻结库存成功。";
isSuccess = true;
}
else
{
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 orderRepository.UpdateAsync(order, "State", "LastModificationTime");
log = await logRepository.InsertAsync(log);
if (!(row > 0 && log.Id > 0))
isSuccess = false;
}
} }
int row = await checkRecordRepository.UpdateAsync(resord, "TheCurrentLink");
log = await checkLogRepository.InsertAsync(log);
if (!(row > 0 && log.Id > 0))
isSuccess = false;
if (isSuccess) if (isSuccess)
BackgroundJob.Enqueue(() => RollbackStockAsync(id)); BackgroundJob.Enqueue(() => RollbackStockAsync(id));
//await mqClient.SendAsync("takeStock.", resord).ContinueWith(task =>
//{
// isSuccess = task.Result;
//});
else else
BackgroundJob.Schedule(() => FreezeStockAsync(id), DateTimeOffset.UtcNow.AddMinutes(1)); BackgroundJob.Schedule(() => FreezeStockAsync(id), DateTimeOffset.UtcNow.AddMinutes(1));
return isSuccess; return isSuccess;
} }
...@@ -109,41 +121,54 @@ namespace Service.TakeStock ...@@ -109,41 +121,54 @@ namespace Service.TakeStock
/// <returns></returns> /// <returns></returns>
public async Task<bool> RollbackStockAsync(int id) public async Task<bool> RollbackStockAsync(int id)
{ {
var resord = checkRecordRepository.Get(id); var order = orderRepository.Get(id);
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 } });
HttpContent content = new StringContent(data);
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var response = await client.PostAsync("ACOrderService/RollbackStock", content);
bool isSuccess = false; bool isSuccess = false;
if (response.IsSuccessStatusCode) if (order.State == TakeStockEnum.TSOrderState.释放库存)
isSuccess = true;
else
{ {
var responseContent = await response.Content.ReadAsStringAsync(); var client = httpClientFactory.CreateClient("WMS");
isSuccess = JObject.Parse(responseContent)["data"].ToObject<bool>(); client.DefaultRequestHeaders.Add("Access-Control-Allow-Origin", "*");
CheckLog log = new CheckLog(); string data = JsonConvert.SerializeObject(new { Data = new { WarehouseCode = order.WarehouseCode, Sku = order.Sku } });
log.CheckRecordId = id; HttpContent content = new StringContent(data);
if (isSuccess) content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var response = await client.PostAsync("ACOrderService/RollbackStock", content);
if (response.IsSuccessStatusCode)
{ {
resord.TheCurrentLink = TakeStockEnum.Link.释放库存; var responseContent = await response.Content.ReadAsStringAsync();
isSuccess = JObject.Parse(responseContent)["data"].ToObject<bool>();
log.Link = TakeStockEnum.Link.释放库存; TakeStockOrderLog log = new TakeStockOrderLog();
log.Description = $"已释放占用库存。"; log.OrderId = id;
} if (isSuccess)
else {
{ order.State = TakeStockEnum.TSOrderState.释放库存;
resord.TheCurrentLink = TakeStockEnum.Link.异常; order.LastModificationTime = DateTime.Now;
log.Link = TakeStockEnum.Link.异常;
log.Description = "释放占用库存失败,WMS返回消息:" + responseContent; log.State = TakeStockEnum.TSOrderState.释放库存;
log.Content = $"已释放占用库存。";
}
else
{
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 orderRepository.UpdateAsync(order, "State", "LastModificationTime");
log = await logRepository.InsertAsync(log);
if (!(row > 0 && log.Id > 0)) isSuccess = false;
} }
int row = await checkRecordRepository.UpdateAsync(resord, "TheCurrentLink");
log = await checkLogRepository.InsertAsync(log);
if (!(row > 0 && log.Id > 0)) isSuccess = false;
} }
if (isSuccess) if (isSuccess)
BackgroundJob.Enqueue(() => SyncAndEnabledAsync(id)); {
var schedule = scheduleRepository.Get(order.ScheduleId);
if(schedule.IsAutomation)
BackgroundJob.Enqueue(() => SyncAndEnabledAsync(id));
}
else else
BackgroundJob.Schedule(() => RollbackStockAsync(id), DateTimeOffset.UtcNow.AddMinutes(1)); BackgroundJob.Schedule(() => RollbackStockAsync(id), DateTimeOffset.UtcNow.AddMinutes(1));
...@@ -158,41 +183,71 @@ namespace Service.TakeStock ...@@ -158,41 +183,71 @@ namespace Service.TakeStock
/// <returns></returns> /// <returns></returns>
public async Task<bool> SyncAndEnabledAsync(int id) public async Task<bool> SyncAndEnabledAsync(int id)
{ {
var resord = checkRecordRepository.Get(id); var order = orderRepository.Get(id);
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 } });
HttpContent content = new StringContent(data);
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var response = await client.PostAsync("WMSStockService/SyncAndEnabledStock", content);
bool isSuccess = false; bool isSuccess = false;
if (response.IsSuccessStatusCode) if (order.State == TakeStockEnum.TSOrderState.完成)
isSuccess = true;
else
{ {
var responseContent = await response.Content.ReadAsStringAsync(); var client = httpClientFactory.CreateClient("WMS");
isSuccess = Convert.ToBoolean(JObject.Parse(responseContent)["data"]); client.DefaultRequestHeaders.Add("Access-Control-Allow-Origin", "*");
CheckLog log = new CheckLog(); string data = JsonConvert.SerializeObject(new { Data = new { WarehouseCode = order.WarehouseCode, Sku = order.Sku } });
log.CheckRecordId = id; HttpContent content = new StringContent(data);
if (isSuccess) content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
{ var response = await client.PostAsync("WMSStockService/SyncAndEnabledStock", content);
resord.TheCurrentLink = TakeStockEnum.Link.完成; if (response.IsSuccessStatusCode)
log.Link = TakeStockEnum.Link.完成;
log.Description = $"同步并启用库存,盘点完成。";
}
else
{ {
resord.TheCurrentLink = TakeStockEnum.Link.异常; var responseContent = await response.Content.ReadAsStringAsync();
log.Link = TakeStockEnum.Link.异常; isSuccess = Convert.ToBoolean(JObject.Parse(responseContent)["data"]);
log.Description = "盘点失败,WMS返回消息:" + JObject.Parse(responseContent)["message"]; TakeStockOrderLog log = new TakeStockOrderLog();
BackgroundJob.Schedule(() => SyncAndEnabledAsync(id), DateTimeOffset.UtcNow.AddMinutes(1)); log.OrderId = id;
if (isSuccess)
{
order.State = TakeStockEnum.TSOrderState.完成;
log.State = TakeStockEnum.TSOrderState.完成;
log.Content = $"同步并启用库存,盘点完成。";
}
else
{
order.State = TakeStockEnum.TSOrderState.异常;
log.State = TakeStockEnum.TSOrderState.异常;
log.Content = "盘点失败,WMS返回消息:" + JObject.Parse(responseContent)["message"];
log.JsonData = responseContent;
}
int row = await orderRepository.UpdateAsync(order, "State", "LastModificationTime");
log = await logRepository.InsertAsync(log);
if (!(row > 0 && log.Id > 0))
isSuccess = false;
} }
int row = await checkRecordRepository.UpdateAsync(resord, "TheCurrentLink");
log = await checkLogRepository.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; 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 ...@@ -44,7 +44,7 @@ namespace TakeStock.API.Controllers
//} //}
[HttpPost] [HttpPost]
public async Task<bool> PostCheckRecord([FromBody] CheckRecordInputDto record) public async Task<bool> PostCheckRecord([FromBody] ScheduleInputDto record)
{ {
var result = await takeStockAppService.CreateCheckRecord(record); var result = await takeStockAppService.CreateCheckRecord(record);
return result; return result;
...@@ -56,7 +56,7 @@ namespace TakeStock.API.Controllers ...@@ -56,7 +56,7 @@ namespace TakeStock.API.Controllers
{ {
//queryStockPoolService.AcquireStockPool().Wait(); //queryStockPoolService.AcquireStockPool().Wait();
//takeStockAppService.FreezeStockAsync(id).Wait(); //takeStockAppService.FreezeStockAsync(id).Wait();
takeStockAppService.RollbackStockAsync(id).Wait(); //takeStockAppService.RollbackStockAsync(id).Wait();
} }
// DELETE: api/ApiWithActions/5 // DELETE: api/ApiWithActions/5
......
using Domain; using Domain;
using Domain.Domain.TakeStock.Repository;
using Hangfire; using Hangfire;
using Hangfire.MySql; using Hangfire.MySql;
using IService.TakeStock; using IService.TakeStock;
...@@ -18,6 +19,7 @@ using System.Transactions; ...@@ -18,6 +19,7 @@ using System.Transactions;
using TakeStock.API.Extensions; using TakeStock.API.Extensions;
using TakeStock.Application.TakeStock; using TakeStock.Application.TakeStock;
using TakeStock.SqlSugar; using TakeStock.SqlSugar;
using TakeStock.SqlSugar.Repository.TakeStock;
namespace TakeStock.API namespace TakeStock.API
{ {
...@@ -58,6 +60,7 @@ namespace TakeStock.API ...@@ -58,6 +60,7 @@ namespace TakeStock.API
services.AddScoped<ITakeStockService, TakeStockService>(); services.AddScoped<ITakeStockService, TakeStockService>();
services.AddScoped<DbContext>(); services.AddScoped<DbContext>();
services.AddScoped(typeof(IRepository<>), typeof(Repository<>)); services.AddScoped(typeof(IRepository<>), typeof(Repository<>));
services.AddScoped(typeof(ITakeStockScheduleRepository), typeof(TakeStockScheduleRepository));
services.AddScoped<TakeStockAppService>(); services.AddScoped<TakeStockAppService>();
services.AddHttpClient(); services.AddHttpClient();
......
...@@ -13,9 +13,10 @@ ...@@ -13,9 +13,10 @@
"Timeout": 120 "Timeout": 120
}, },
"ConnectionStrings": { "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;",
"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": "redis" //"Redis": "127.0.0.1"
"Redis": "172.31.3.191"
}, },
"App": { "App": {
"CorsOrigins": "*" "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 Domain.Domain.TakeStock;
using IService.TakeStock; using IService.TakeStock;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
...@@ -18,21 +19,22 @@ namespace TakeStock.Application.TakeStock ...@@ -18,21 +19,22 @@ namespace TakeStock.Application.TakeStock
this.takeStockService = takeStockService; this.takeStockService = takeStockService;
} }
public async Task<bool> CreateCheckRecord(CheckRecordInputDto input) public async Task<bool> CreateCheckRecord(ScheduleInputDto input)
{ {
var str = JsonConvert.SerializeObject(input); var str = JsonConvert.SerializeObject(input);
CheckRecord record = JsonConvert.DeserializeObject<CheckRecord>(str); TakeStockSchedule schedule = JsonConvert.DeserializeObject<TakeStockSchedule>(str);
return await takeStockService.CreateCheckRecordAsync(record); List<TakeStockOrder> orders = JObject.Parse(str)["Orders"].ToObject<List<TakeStockOrder>>();
return await takeStockService.CreateTakeStockOrderAsync(schedule, orders);
} }
public async Task<bool> FreezeStockAsync(int id) //public async Task<bool> FreezeStockAsync(int id)
{ //{
return await takeStockService.FreezeStockAsync(id); // return await takeStockService.FreezeStockAsync(id);
} //}
public async Task<bool> RollbackStockAsync(int id) //public async Task<bool> RollbackStockAsync(int id)
{ //{
return await takeStockService.RollbackStockAsync(id); // return await takeStockService.RollbackStockAsync(id);
} //}
} }
} }
...@@ -59,8 +59,8 @@ namespace SqlSugar ...@@ -59,8 +59,8 @@ namespace SqlSugar
public void Migration() public void Migration()
{ {
Db.CodeFirst.SetStringDefaultLength(20/*设置varchar默认长度为200*/) //Db.CodeFirst.SetStringDefaultLength(20/*设置varchar默认长度为200*/)
.InitTables(typeof(CheckRecord), typeof(CheckLog));//执行完数据库就有这个表了 // .InitTables(typeof(TakeStockSchedule), typeof(TakeStockOrder), typeof(TakeStockOrderLog));//执行完数据库就有这个表了
} }
} }
} }
\ No newline at end of file
using Domain; using Domain;
using SqlSugar; using SqlSugar;
using System; using System;
using System.Collections;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace TakeStock.SqlSugar namespace TakeStock.SqlSugar
{ {
public class Repository<TEntity> : IRepository<TEntity> where TEntity : class, new() public class Repository<TEntity> : IRepository<TEntity> where TEntity : class, new()
{ {
private readonly SqlSugarClient client; protected readonly SqlSugarClient client;
public Repository(DbContext dbContext) public Repository(DbContext dbContext)
{ {
...@@ -21,7 +22,7 @@ namespace TakeStock.SqlSugar ...@@ -21,7 +22,7 @@ namespace TakeStock.SqlSugar
public int Count(System.Linq.Expressions.Expression<Func<TEntity, bool>> predicate) 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) public Task<int> CountAsync(System.Linq.Expressions.Expression<Func<TEntity, bool>> predicate)
...@@ -134,6 +135,11 @@ namespace TakeStock.SqlSugar ...@@ -134,6 +135,11 @@ namespace TakeStock.SqlSugar
return client.Insertable(entity).ExecuteCommand() > 0; return client.Insertable(entity).ExecuteCommand() > 0;
} }
public int InsertOnTheBatch(params TEntity[] entityes)
{
return client.Insertable(entityes).ExecuteCommand();
}
public int InsertAndGetId(TEntity entity) public int InsertAndGetId(TEntity entity)
{ {
return client.Insertable(entity).ExecuteReturnIdentity(); 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