abp(net core)+easyui+efcore实现仓储管理系统——入库管理之四(四十)
abp(net core)+easyui+efcore实现仓储管理系统目录
abp(net core)+easyui+efcore实现仓储管理系统——EasyUI前端页面框架 (十八)
abp(net core)+easyui+efcore实现仓储管理系统——ABP WebAPI与EasyUI结合增删改查之八(三十四)
在上一篇abp(net core)+easyui+efcore实现仓储管理系统——入库管理之三存储过程(三十九) 文章中我们学习了如何在ABP中调用存储过程并创建相关的类。接下来我们要来实现调用存储过程,同时实现应用层。
六、定义应用层接口
1. 在Visual Studio 2017的“解决方案资源管理器”中,鼠标右键单击“InStocks”文件夹,然后选择“添加” > “新建项”,在弹出对话框中选择“接口”。为应用服务定义一个名为 IInStockOrderAppService 的接口。代码如下。
using System;
using System.Collections.Generic;
using System.Text;
using Abp.Application.Services;
using ABP.TPLMS.InStocks.Dto;
namespace ABP.TPLMS.InStocks
{
public interface IInStockOrderAppService : IAsyncCrudAppService<//定义了CRUD方法
InStockOrderDto, //用来展示入库单信息
int, //Org实体的主键
PagedInStockResultRequestDto, //获取入库单信息的时候用于分页
CreateUpdateInStockOrderDto, //用于创建入库单信息
CreateUpdateInStockOrderDto> //用于更新入库单信息
{
/// <summary>
/// 创建入库单号
/// </summary>
/// <returns></returns>
string GetNo();
/// <summary>
/// 保存入库单数据
/// </summary>
/// <param name="iso"></param>
/// <returns></returns>
string Save(InStockOrderDto iso);
/// <summary>
/// 导入货物信息
/// </summary>
/// <param name="ids">导入货物信息的ID</param>
/// <param name="No">入库单单号</param>
/// <returns></returns>
string ImportCargo(string ids,string No);
/// <summary>
/// 批量删除
/// </summary>
/// <param name="ids">入库单ID集合</param>
/// <returns></returns>
bool DeleteById(string ids);
}
}
2.在Visual Studio 2017的“解决方案资源管理器”中,鼠标右键单击“InStocks”文件夹,然后选择“添加” > “新建项”,在弹出对话框中选择“接口”。为应用服务定义一个名为 IInStockOrderDetailAppService 的接口。代码如下。
using System;
using System.Collections.Generic;
using System.Text;
using Abp.Application.Services;
using ABP.TPLMS.InStocks.Dto;
namespace ABP.TPLMS.InStocks
{
public interface IInStockOrderDetailAppService : IAsyncCrudAppService<//定义了CRUD方法
InStockOrderDetailDto, //用来展示入库单明细信息
int, //Org实体的主键
PagedInStockDetailResultRequestDto, //获取入库单信息的时候用于分页
CreateUpdateInStockOrderDetailDto, //用于创建入库单明细信息
CreateUpdateInStockOrderDetailDto > //用于更新入库单明细信息
{
}
}
using Abp.Application.Services;
using ABP.TPLMS.InStocks.Dto;
using System;
using System.Collections.Generic;
using System.Text;
namespace ABP.TPLMS.InStocks
{
public interface IInStockOrderDetailLocAppService :IAsyncCrudAppService<//定义了CRUD方法
InStockOrderDetailLocDto, //用来展示入库单中的库位信息
int, //实体的主键
PagedInStockDetailLocResultRequestDto, //获取入库单库位信息的时候用于分页
CreateUpdateInStockOrderDetailLocDto, //用于创建入库单库位信息
CreateUpdateInStockOrderDetailLocDto> //用于更新入库单库位信息
{
}
}
七、实现应用层接口
4.在Visual Studio 2017的“解决方案资源管理器”中,右键单击“InStocks”文件夹,然后选择“添加” > “新建项”,在弹出对话框中选择“类”。为应用服务定义一个名为 InStockOrderAppService 的服务类,实现IInStockOrderAppService接口中的方法。特别注意在构造函数中定义IInStockOrderRepository 接口,方便注入。代码如下。
using Abp.Application.Services;
using Abp.Application.Services.Dto;
using Abp.Domain.Repositories;
using Abp.Web.Models;
using ABP.TPLMS.Entitys;
using ABP.TPLMS.InStocks.Dto;
using ABP.TPLMS.IRepositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABP.TPLMS.InStocks
{
public class InStockOrderAppService : AsyncCrudAppService<InStockOrder, InStockOrderDto, int, PagedInStockResultRequestDto,
CreateUpdateInStockOrderDto, CreateUpdateInStockOrderDto>, IInStockOrderAppService
{
IInStockOrderRepository rep = null;
IInStockOrderDetailAppService isodApp=null;
IInStockOrderDetailLocAppService isodLocApp = null;
public InStockOrderAppService(IRepository<InStockOrder, int> repository,
IInStockOrderRepository isdRepository,IInStockOrderDetailAppService isodAppSer
,IInStockOrderDetailLocAppService isodLocAppSer)
: base(repository)
{
rep = isdRepository;
isodApp = isodAppSer;
isodLocApp = isodLocAppSer;
}
public override Task<PagedResultDto<InStockOrderDto>> GetAll(PagedInStockResultRequestDto input)
{
return base.GetAll(input);
}
[DontWrapResult]
public PagedInStockOrderResultDto<InStockOrderDto> GetAllInStockOrders(PagedInStockResultRequestDto input)
{
PagedInStockOrderResultDto<InStockOrderDto> inSOs = new PagedInStockOrderResultDto<InStockOrderDto>();
var allOrgs=GetAll(input);
inSOs.Rows = allOrgs.Result.Items;
inSOs.Total = allOrgs.Result.TotalCount;
return inSOs;
}
protected override IQueryable<InStockOrder> CreateFilteredQuery(PagedInStockResultRequestDto input)
{
var qry= base.CreateFilteredQuery(input)
.Where(t=>t.OwnerName.Contains(input.OwnerName==null?string.Empty:input.OwnerName))
.Where(t => t.No.Contains(input.No == null ? string.Empty : input.No))
.Where(t => t.CreationTime>input.BeginTime)
.Where(t => t.CreationTime<input.EndTime);
return qry;
}
[DontWrapResult]
public string GetNo()
{
string no = rep.GetNo("GDE");
return no;
}
[DontWrapResult]
public string ImportCargo(string ids,string No)
{
try
{
//导入货物信息
rep.ImportCargo(ids, No);
}
catch (Exception ex)
{
throw ex;
}
return "OK";
}
public string Save(InStockOrderDto iso)
{
try
{
CreateUpdateInStockOrderDto order = ObjectMapper.Map<CreateUpdateInStockOrderDto>(iso);
foreach (var item in order.InStockOrderDetail)
{
CreateUpdateInStockOrderDetailDto isod = ObjectMapper.Map<CreateUpdateInStockOrderDetailDto>(item);
isodApp.Update(isod);
}
order.InStockOrderDetail = null;
order.Status = 1 ;
Update(order);
}
catch (Exception ex)
{
throw ex;
}
return "OK";
}
public bool DeleteById(string Ids)
{
var idList = Ids.Split(',');
bool result = true;
try
{
foreach (var id in idList)
{
int.TryParse(id, out int intId);
var iso = GetEntityByIdAsync(intId).GetAwaiter().GetResult();
PagedInStockDetailResultRequestDto PagedDetail = new PagedInStockDetailResultRequestDto
{
InStockNo = iso.No
};
var isods = isodApp.GetAll(PagedDetail).GetAwaiter().GetResult();
foreach (var dod in isods.Items)
{
PagedInStockDetailLocResultRequestDto PagedLoc = new PagedInStockDetailLocResultRequestDto
{
InStockOrderDetailId = dod.Id
};
var isodLocs = isodLocApp.GetAll(PagedLoc).GetAwaiter().GetResult();
foreach (var loc in isodLocs.Items)
{
isodLocApp.Delete(loc);
}
isodApp.Delete(dod);
}
InStockOrderDto order = ObjectMapper.Map<InStockOrderDto>(iso);
Delete(order);
}
}
catch (Exception ex)
{
result = false;
throw ex;
}
return result;
}
}
}
5.在Visual Studio 2017的“解决方案资源管理器”中,右键单击“InStocks”文件夹,然后选择“添加” > “新建项”,在弹出对话框中选择“类”。为应用服务定义一个名为 InStockOrderDetailAppService 的服务类,实现IInStockOrderDetailAppService接口。代码如下。
using Abp.Application.Services;
using Abp.Application.Services.Dto;
using Abp.Domain.Repositories;
using Abp.Web.Models;
using ABP.TPLMS.Entitys;
using ABP.TPLMS.InStocks.Dto;
using ABP.TPLMS.IRepositories;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABP.TPLMS.InStocks
{
public class InStockOrderDetailAppService : AsyncCrudAppService<InStockOrderDetail
, InStockOrderDetailDto, int , PagedInStockDetailResultRequestDto,
CreateUpdateInStockOrderDetailDto, CreateUpdateInStockOrderDetailDto>
, IInStockOrderDetailAppService
{
public InStockOrderDetailAppService( IRepository<InStockOrderDetail, int> repository)
: base(repository)
{
}
protected override IQueryable<InStockOrderDetail> CreateFilteredQuery(
PagedInStockDetailResultRequestDto input)
{
var qry = base.CreateFilteredQuery(input)
.Where(t => t.InStockNo == input.InStockNo);
return qry;
}
}
}
using Abp.Application.Services;
using Abp.Application.Services.Dto;
using Abp.Domain.Repositories;
using Abp.Web.Models;
using ABP.TPLMS.Entitys;
using ABP.TPLMS.InStocks.Dto;
using ABP.TPLMS.IRepositories;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABP.TPLMS.InStocks
{
public class InStockOrderDetailLocAppService : AsyncCrudAppService<InStockOrderDetailLoc
, InStockOrderDetailLocDto, int, PagedInStockDetailLocResultRequestDto,
CreateUpdateInStockOrderDetailLocDto, CreateUpdateInStockOrderDetailLocDto>
, IInStockOrderDetailLocAppService
{
public InStockOrderDetailLocAppService( IRepository<InStockOrderDetailLoc, int> repository)
: base(repository)
{
}
protected override IQueryable<InStockOrderDetailLoc> CreateFilteredQuery(
PagedInStockDetailLocResultRequestDto input)
{
var qry = base.CreateFilteredQuery(input)
.Where(t => t.InStockOrderDetailId == input.InStockOrderDetailId);
return qry;
}
}
}