Commit 96c4bb19 by pengjinyang

提交

parent e441a1e4
......@@ -52,6 +52,7 @@ namespace Domain.Domain.TakeStock
[SugarColumn(IsNullable = true, Length = 500)]
public string Description { get; set; }
[SugarColumn(IsOnlyIgnoreInsert = true)]
public DateTime CreationTime { get; set; }
[SugarColumn(IsNullable = true)]
......
......@@ -44,7 +44,8 @@ namespace Domain.Domain.TakeStock
/// </summary>
[SugarColumn(IsNullable = true, Length = 500)]
public string Description { get; set; }
[SugarColumn(IsOnlyIgnoreInsert = true)]
public DateTime CreationTime { get; set; }
[SugarColumn(IsNullable = true)]
......
......@@ -174,7 +174,7 @@ namespace Domain
////
//// 返回结果:
//// List of all entities
//List<TEntity> GetAllList(Expression<Func<TEntity, bool>> predicate);
List<TEntity> GetAllList(Expression<Func<TEntity, bool>> predicate);
////
//// 摘要:
//// Used to get all entities.
......
......@@ -13,6 +13,20 @@ namespace IService.TakeStock
/// <returns></returns>
Task<bool> CreateTakeStockOrderAsync(TakeStockSchedule record, List<TakeStockOrder> orders);
/// <summary>
/// 发起线下盘点
/// </summary>
/// <param name="order"></param>
/// <returns></returns>
Task<bool> StartTakeStock(int id, int beforeQuantity);
/// <summary>
/// 盘点结果反馈
/// </summary>
/// <param name="order"></param>
/// <returns></returns>
Task<bool> Feedback(int id, int afterQuantity);
///// <summary>
///// 冻结库存
///// </summary>
......
......@@ -8,9 +8,11 @@ using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using static Domain.Domain.TakeStock.TakeStockEnum;
namespace Service.TakeStock
{
......@@ -132,7 +134,7 @@ namespace Service.TakeStock
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);
var response = await client.PostAsync("TakeStockScheduleService/RollbackStock", content);
if (response.IsSuccessStatusCode)
{
var responseContent = await response.Content.ReadAsStringAsync();
......@@ -166,7 +168,7 @@ namespace Service.TakeStock
if (isSuccess)
{
var schedule = scheduleRepository.Get(order.ScheduleId);
if(schedule.IsAutomation)
if (schedule.IsAutomation)
BackgroundJob.Enqueue(() => SyncAndEnabledAsync(id));
}
else
......@@ -232,11 +234,11 @@ namespace Service.TakeStock
public async Task CheckComplete(int scheduleId)
{
bool isComplete = orderRepository.Count(o => o.ScheduleId == scheduleId && (o.State != TakeStockEnum.TSOrderState.完成 || o.State != TakeStockEnum.TSOrderState.取消)) <= 0;
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.State = TakeStockEnum.TSScheduleState.完成;
schedule.LastModificationTime = DateTime.Now;
int row = await scheduleRepository.UpdateAsync(schedule, "State", "LastModificationTime");
......@@ -244,10 +246,187 @@ namespace Service.TakeStock
//BackgroundJob.Enqueue(() => GainLoss(schedule.Id));
}
}
/// <summary>
/// 发起线下盘点
/// </summary>
/// <param name="order"></param>
/// <returns></returns>
public async Task<bool> StartTakeStock(int id, int beforeQuantity)
{
var order = orderRepository.Get(id);
order.State = TSOrderState.盘点中;
order.BeforeQuantity = beforeQuantity;
order.LastModificationTime = DateTime.Now;
var record =await orderRepository.UpdateAsync(order, "State", "BeforeQuantity", "LastModificationTime");
return record > 0;
}
/// <summary>
/// 盘点反馈
/// </summary>
/// <param name="order"></param>
/// <returns></returns>
public async Task<bool> Feedback(int id, int afterQuantity)
{
var order = orderRepository.Get(id);
order.AfterQuantity = afterQuantity;
order.LastModificationTime = DateTime.Now;
var record = await orderRepository.UpdateAsync(order, "AfterQuantity", "LastModificationTime");
bool isSuccess = record > 0;
if (isSuccess)
BackgroundJob.Enqueue(() => ModifAndEnabledAsync(order.Id));
return isSuccess;
}
/// <summary>
/// 同步和启用库存
/// </summary>
/// <param name="warehouseCode"></param>
/// <param name="sku"></param>
/// <returns></returns>
public async Task<bool> ModifAndEnabledAsync(int 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 = order.WarehouseCode, Sku = order.Sku, Quantity = order.AfterQuantity } });
HttpContent content = new StringContent(data);
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var response = await client.PostAsync("WMSStockService/ModifAndEnabled", content);
if (response.IsSuccessStatusCode)
{
var responseContent = await response.Content.ReadAsStringAsync();
isSuccess = Convert.ToBoolean(JObject.Parse(responseContent)["data"]);
TakeStockOrderLog log = new TakeStockOrderLog();
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;
}
}
if (isSuccess)
BackgroundJob.Enqueue(() => Audit(order.ScheduleId));
else
BackgroundJob.Schedule(() => ModifAndEnabledAsync(id), DateTimeOffset.UtcNow.AddMinutes(1));
return isSuccess;
}
public async Task GainLoss(int scheduleId)
/// <summary>
/// 盘点审核
/// 线下盘点完成
/// </summary>
/// <returns></returns>
public async Task<bool> Audit(int scheduleId)
{
bool isSuccess = false;
var orders = orderRepository.GetAllList(o => o.ScheduleId == scheduleId);
int count = orders.Count(o => o.State != TSOrderState.完成 && o.State != TSOrderState.取消);
if (count <= 0)
{
var schedule = scheduleRepository.Get(scheduleId);
bool isAudit = orders.Any(o => o.BeforeQuantity != o.AfterQuantity);
if (isAudit)
{
schedule.State = TSScheduleState.审核;
BackgroundJob.Enqueue(() => GainLoss(schedule.Id));
}
else
schedule.State = TSScheduleState.完成;
int record = await scheduleRepository.UpdateAsync(schedule);
isSuccess = record > 0;
}
else
isSuccess = true;
return isSuccess;
}
public void GainLoss(int scheduleId)
{
var schedule = scheduleRepository.Get(scheduleId);
var orders = orderRepository.GetAllList(o => o.ScheduleId == scheduleId && o.BeforeQuantity != o.AfterQuantity);
//报损
var orders2 = orders.Where(o => o.BeforeQuantity > o.AfterQuantity);
if (orders2?.Count() > 0)
{
var data = new
{
Type = 1,
ExternalCode = schedule.Code,
WarehouseCode = schedule.WarehouseCode,
Details = orders.Where(o => o.BeforeQuantity > o.AfterQuantity).Select(o => new
{
Sku = o.Sku,
Quantity = o.BeforeQuantity - o.AfterQuantity,
Description = o.Description
})
};
AddGainLoss(data);
}
orders2 = orders.Where(o => o.BeforeQuantity < o.AfterQuantity);
if (orders2.Count() > 0)
{
//报溢
var data = new
{
Type = 0,
ExternalCode = schedule.Code,
WarehouseCode = schedule.WarehouseCode,
Details = orders.Where(o => o.BeforeQuantity < o.AfterQuantity).Select(o => new
{
Sku = o.Sku,
Quantity = o.AfterQuantity - o.BeforeQuantity,
Description = o.Description
})
};
AddGainLoss(data);
}
}
public async Task<string> AddGainLoss(object obj)
{
string code = string.Empty;
var client = httpClientFactory.CreateClient("WMS");
client.DefaultRequestHeaders.Add("Access-Control-Allow-Origin", "*");
string dataStr = JsonConvert.SerializeObject(new { Data = obj });
HttpContent content = new StringContent(dataStr);
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var response = await client.PostAsync("GainLossOrderService/AddGainLoss", content);
if (response.IsSuccessStatusCode)
{
var responseContent = await response.Content.ReadAsStringAsync();
code = JObject.Parse(responseContent)["data"].ToString();
}
if (string.IsNullOrWhiteSpace(code))
BackgroundJob.Schedule(() => AddGainLoss(obj), DateTimeOffset.UtcNow.AddMinutes(1));
return code;
}
}
}
......@@ -49,14 +49,17 @@ namespace TakeStock.API.Controllers
var result = await takeStockAppService.CreateCheckRecord(record);
return result;
}
[HttpPost("StartTakeStock")]
public async Task<bool> StartTakeStock([FromBody] StartTakeStockInputDto input)
{
return await takeStockAppService.StartTakeStock(input);
}
// PUT: api/TakeStock/5
[HttpPut("{id}")]
public void Put(int id)
[HttpPost("Feedback")]
public async Task<bool> Feedback([FromBody] FeedbackInputDto input)
{
//queryStockPoolService.AcquireStockPool().Wait();
//takeStockAppService.FreezeStockAsync(id).Wait();
//takeStockAppService.RollbackStockAsync(id).Wait();
return await takeStockAppService.Feedback(input);
}
// DELETE: api/ApiWithActions/5
......
......@@ -82,6 +82,9 @@ namespace TakeStock.API
{
app.UseDeveloperExceptionPage();
}
app.UseCors("Default");
var options = new DashboardOptions
{
IgnoreAntiforgeryToken = true,
......
......@@ -32,4 +32,6 @@
<ProjectReference Include="..\TakeStock.SqlSugar\TakeStock.SqlSugar.csproj" />
</ItemGroup>
<ProjectExtensions><VisualStudio><UserProperties /></VisualStudio></ProjectExtensions>
</Project>
......@@ -13,10 +13,9 @@
"Timeout": 120
},
"ConnectionStrings": {
//"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;",
"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": "127.0.0.1"
"Redis": "172.31.3.191"
"Redis": "172.31.255.235"
},
"App": {
"CorsOrigins": "*"
......
using System;
using System.Collections.Generic;
using System.Text;
namespace TakeStock.Application.TakeStock.Dto
{
public class FeedbackInputDto
{
public int Id { get; set; }
public int AfterQuantity { get; set; }
}
}
......@@ -23,6 +23,11 @@ namespace TakeStock.Application.TakeStock.Dto
public int ExecutorId { get; set; }
/// <summary>
/// 系统自动盘点
/// </summary>
public bool IsAutomation { get; set; }
/// <summary>
/// 状态
/// </summary>
public TSScheduleState State { get; set; }
......
using System;
using System.Collections.Generic;
using System.Text;
namespace TakeStock.Application.TakeStock.Dto
{
public class StartTakeStockInputDto
{
public int Id { get; set; }
public int BeforeQuantity { get; set; }
}
}
......@@ -27,14 +27,14 @@ namespace TakeStock.Application.TakeStock
return await takeStockService.CreateTakeStockOrderAsync(schedule, orders);
}
//public async Task<bool> FreezeStockAsync(int id)
//{
// return await takeStockService.FreezeStockAsync(id);
//}
public async Task<bool> StartTakeStock(StartTakeStockInputDto input)
{
return await takeStockService.StartTakeStock(input.Id, input.BeforeQuantity);
}
//public async Task<bool> RollbackStockAsync(int id)
//{
// return await takeStockService.RollbackStockAsync(id);
//}
public async Task<bool> Feedback(FeedbackInputDto input)
{
return await takeStockService.Feedback(input.Id, input.AfterQuantity);
}
}
}
......@@ -2,6 +2,7 @@
using SqlSugar;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace TakeStock.SqlSugar
......@@ -100,10 +101,10 @@ namespace TakeStock.SqlSugar
// throw new NotImplementedException();
//}
//public List<TEntity> GetAllList(System.Linq.Expressions.Expression<Func<TEntity, bool>> predicate)
//{
// throw new NotImplementedException();
//}
public List<TEntity> GetAllList(System.Linq.Expressions.Expression<Func<TEntity, bool>> predicate)
{
return client.Queryable<TEntity>().Where(predicate).ToList();
}
//public List<TEntity> GetAllList()
//{
......
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