Commit 1bbde191 by pengjinyang

提交

parent d9b9ffde
using System;
using System.Linq;
using System.Linq.Expressions;
namespace Common.Extensions
{
/// <summary>
/// 表达树扩展方法
/// </summary>
public static class ExpressionExtensions
{
/// <summary>
/// 或拼接
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="expr1"></param>
/// <param name="expr2"></param>
/// <returns></returns>
public static Expression<Func<T, bool>> Or<T>(this Expression<Func<T, bool>> expr1, Expression<Func<T, bool>> expr2)
{
var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast<Expression>());
return Expression.Lambda<Func<T, bool>>
(Expression.Or(expr1.Body, invokedExpr), expr1.Parameters);
}
/// <summary>
/// 与拼接
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="expr1"></param>
/// <param name="expr2"></param>
/// <returns></returns>
public static Expression<Func<T, bool>> And<T>(this Expression<Func<T, bool>> expr1, Expression<Func<T, bool>> expr2)
{
var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast<Expression>());
return Expression.Lambda<Func<T, bool>>
(Expression.And(expr1.Body, invokedExpr), expr1.Parameters);
}
}
}
......@@ -426,5 +426,7 @@ namespace Domain
//// entity:
//// Entity
Task<int> UpdateAsync(TEntity entity, params string[] columns);
List<TEntity> PageList<TEntity>(int pageIndex, int pageSize, System.Linq.Expressions.Expression<Func<TEntity, bool>> predicate, out int totalCount, string orderBy = "Id desc");
}
}
using Domain.Domain.TakeStock;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;
namespace IService.TakeStock
......@@ -36,6 +38,8 @@ namespace IService.TakeStock
/// <returns></returns>
Task<bool> CancelOrder(int id);
(int total, List<TakeStockSchedule> items) SearchScheduleByPage(int pageIndex, int pageSize, Expression<Func<TakeStockSchedule, bool>> expr);
///// <summary>
///// 冻结库存
///// </summary>
......
......@@ -10,6 +10,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Common\Common.csproj" />
<ProjectReference Include="..\IService\IService.csproj" />
<ProjectReference Include="..\MessageQueue\MessageQueue.csproj" />
</ItemGroup>
......
......@@ -10,6 +10,7 @@ using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Linq.Expressions;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
......@@ -127,12 +128,12 @@ namespace Service.TakeStock
{
string responseContent = await response.Content.ReadAsStringAsync();
var resultObj = JObject.Parse(responseContent)["data"];
isFreeze = resultObj["IsFreeze"].ToObject<bool>();
isFreeze = resultObj["isFreeze"].ToObject<bool>();
Task<bool> logTask = null;
if (isFreeze)
{
order.State = TSOrderState.冻结库存;
order.BeforeQuantity = resultObj["Quantity"].ToObject<int>();
order.BeforeQuantity = resultObj["quantity"].ToObject<int>();
order.LastModificationTime = DateTime.Now;
logTask = AddOrUpdateLog(id, TSOrderState.冻结库存, "冻结库存成功。");
......@@ -264,12 +265,12 @@ namespace Service.TakeStock
{
var responseContent = await response.Content.ReadAsStringAsync();
var resultObj = JObject.Parse(responseContent)["data"];
isSuccess = resultObj["IsSuccess"].ToObject<bool>();
isSuccess = resultObj["isSuccess"].ToObject<bool>();
Task<bool> logTask = null;
if (isSuccess)
{
order.State = TSOrderState.完成;
order.AfterQuantity = resultObj["Quantity"].ToObject<int>();
order.AfterQuantity = resultObj["quantity"].ToObject<int>();
logTask = AddOrUpdateLog(id, TSOrderState.完成, "同步并启用库存,盘点完成。", responseContent);
}
else
......@@ -596,7 +597,13 @@ namespace Service.TakeStock
BackgroundJob.Schedule(() => CancelSchedule(scheduleId), DateTimeOffset.UtcNow.AddMinutes(delay));
}
//public
public (int total, List<TakeStockSchedule> items) SearchScheduleByPage(int pageIndex, int pageSize, Expression<Func<TakeStockSchedule, bool>> expr)
{
int totalCount = 0;
var data = scheduleRepository.PageList(pageIndex, pageSize, expr, out totalCount);
return (totalCount, data);
}
}
}
......@@ -79,5 +79,11 @@ namespace TakeStock.API.Controllers
public void Delete(int id)
{
}
[HttpPost("GetScheduleByPage")]
public async Task<SearchScheduleByPageOutputDto> GetScheduleByPage([FromBody] SearchScheduleByPageInputDto input)
{
return await takeStockAppService.SearchScheduleByPage(input);
}
}
}
using Domain;
using AutoMapper;
using Domain;
using Domain.Domain.TakeStock.Repository;
using Hangfire;
using Hangfire.MySql;
......@@ -56,6 +57,8 @@ namespace TakeStock.API
RegisterHttpClient(services);
services.AddAutoMapper();
services.AddScoped<RabbitMQClient>();
services.AddScoped<ITakeStockService, TakeStockService>();
services.AddScoped<DbContext>();
......@@ -66,11 +69,11 @@ namespace TakeStock.API
services.AddHttpClient();
// Add Hangfire services.
services.AddHangfire(configuration => configuration.UseRedisStorage(Redis)
);
services.AddHangfire(configuration => configuration.UseRedisStorage(Redis));
// Add the processing server as IHostedService
services.AddHangfireServer();
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
}
......
......@@ -7,6 +7,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="6.1.1" />
<PackageReference Include="Hangfire.AspNetCore" Version="1.7.3" />
<PackageReference Include="Hangfire.Core" Version="1.7.3" />
<PackageReference Include="Hangfire.Dashboard.Authorization" Version="2.1.0" />
......@@ -32,6 +33,6 @@
<ProjectReference Include="..\TakeStock.SqlSugar\TakeStock.SqlSugar.csproj" />
</ItemGroup>
<ProjectExtensions><VisualStudio><UserProperties appsettings_1json__JSONSchema="" /></VisualStudio></ProjectExtensions>
<ProjectExtensions><VisualStudio><UserProperties appsettings_1json__JSONSchema="http://json.schemastore.org/2.0.0-csd.2.beta.2018-10-10.json" /></VisualStudio></ProjectExtensions>
</Project>
using System;
using System.Collections.Generic;
using System.Text;
namespace TakeStock.Application.Page
{
public class PageInputDto
{
public PageInputDto()
{
this.Page = 1;
this.Rows = 50;
}
public int Page { get; set; }
public int Rows { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace TakeStock.Application.Page
{
public class PageOutputDto
{
public int Total { get; set; }
public int CurrentPage { get; set; }
public int PageSize { get; set; }
}
}
......@@ -5,8 +5,17 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Common\Common.csproj" />
<ProjectReference Include="..\Domain\Domain.csproj" />
<ProjectReference Include="..\IService\IService.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Extensions\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="8.1.1" />
</ItemGroup>
</Project>
using AutoMapper;
using Domain.Domain.TakeStock;
using System;
using System.Collections.Generic;
using System.Text;
using TakeStock.Application.TakeStock.Dto;
namespace TakeStock.Application.TakeStock.AutoMapper
{
public class TakeStockProfile: Profile
{
public TakeStockProfile()
{
CreateMap<TakeStockSchedule, ScheduleOutputDto>();
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using static Domain.Domain.TakeStock.TakeStockEnum;
namespace TakeStock.Application.TakeStock.Dto
{
public class ScheduleOutputDto
{
public int Id { get; set; }
/// <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 bool IsAutomation { get; set; }
/// <summary>
/// 状态
/// </summary>
public string 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; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
using TakeStock.Application.Page;
namespace TakeStock.Application.TakeStock.Dto
{
public class SearchScheduleByPageInputDto
{
public SearchScheduleInputDto Search{ get; set; }
public PageInputDto Page { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
using TakeStock.Application.Page;
namespace TakeStock.Application.TakeStock.Dto
{
public class SearchScheduleByPageOutputDto
{
public List<ScheduleOutputDto> Items { get; set; }
public PageOutputDto PageItem { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
using static Domain.Domain.TakeStock.TakeStockEnum;
namespace TakeStock.Application.TakeStock.Dto
{
public class SearchScheduleInputDto
{
public string Code { get; set; }
public TSScheduleState? State { get; set; }
}
}
using Domain.Domain.TakeStock;
using AutoMapper;
using Common.Extensions;
using Domain.Domain.TakeStock;
using IService.TakeStock;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq.Expressions;
using System.Threading.Tasks;
using TakeStock.Application.TakeStock.Dto;
......@@ -13,9 +15,11 @@ namespace TakeStock.Application.TakeStock
public class TakeStockAppService
{
private readonly ITakeStockService takeStockService;
private readonly IMapper _mapper;
public TakeStockAppService(ITakeStockService takeStockService)
public TakeStockAppService(IMapper mapper, ITakeStockService takeStockService)
{
this._mapper = mapper;
this.takeStockService = takeStockService;
}
......@@ -46,5 +50,36 @@ namespace TakeStock.Application.TakeStock
{
return await takeStockService.CancelOrder(id);
}
private Expression<Func<TakeStockSchedule, bool>> ScheduleQuery(SearchScheduleInputDto search)
{
Expression<Func<TakeStockSchedule, bool>> expr = s => true;
if (!string.IsNullOrWhiteSpace(search.Code))
expr.And(s => s.Code.Equals(search.Code));
if (search.State != null)
expr.And(s => s.State.Equals(search.State));
return expr;
}
public async Task<SearchScheduleByPageOutputDto> SearchScheduleByPage(SearchScheduleByPageInputDto input)
{
int pageIndex = input.Page.Page;
int pageSize = input.Page.Rows;
var expr = ScheduleQuery(input.Search);
var data = takeStockService.SearchScheduleByPage(pageIndex, pageSize, expr);
var total = data.total;
var items = data.items;
return new SearchScheduleByPageOutputDto
{
Items = _mapper.Map<List<ScheduleOutputDto>>(items),
PageItem = new Page.PageOutputDto
{
Total = total,
CurrentPage = pageIndex,
PageSize = pageSize
}
};
}
}
}
......@@ -2,6 +2,7 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace TakeStock.SqlSugar
......@@ -90,10 +91,10 @@ namespace TakeStock.SqlSugar
return client.Queryable<TEntity>().InSingle(id);
}
//public IQueryable<TEntity> GetAll()
//{
// throw new NotImplementedException();
//}
public ISugarQueryable<TEntity> GetAll()
{
return client.Queryable<TEntity>();
}
//public IQueryable<TEntity> GetAllIncluding(params System.Linq.Expressions.Expression<Func<TEntity, object>>[] propertySelectors)
//{
......@@ -241,11 +242,15 @@ namespace TakeStock.SqlSugar
return client.Updateable(entity).ExecuteCommandAsync();
}
// public void PageList(TEntity entity)
// {
// var pageJoin = client.Queryable<Student, School>((st, sc) => new object[] {
// JoinType.Left,st.SchoolId==sc.Id
//}).ToPageList(pageIndex, pageSize, ref totalCount);
// }
public List<TEntity> PageList<TEntity>(int pageIndex, int pageSize, System.Linq.Expressions.Expression<Func<TEntity, bool>> predicate, out int totalCount, string orderBy = "Id desc")
{
totalCount = 0;
var page = client.Queryable<TEntity>()
.Where(predicate)
.OrderBy(orderBy)
.ToPageList(pageIndex, pageSize, ref totalCount);
return page;
}
}
}
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