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