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 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)] [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);
} }
} }
...@@ -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