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> //用于更新入库单信息
{
///
/// 创建入库单号
///
///
string GetNo();
///
/// 保存入库单数据
///
///
///
string Save(InStockOrderDto iso);
///
/// 导入货物信息
///
/// 导入货物信息的ID
/// 入库单单号
///
string ImportCargo(string ids,string No);
///
/// 批量删除
///
/// 入库单ID集合
///
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 : AsyncCrudAppServiceint , PagedInStockResultRequestDto, CreateUpdateInStockOrderDto, CreateUpdateInStockOrderDto>, IInStockOrderAppService { IInStockOrderRepository rep = null; IInStockOrderDetailAppService isodApp=null; IInStockOrderDetailLocAppService isodLocApp = null; public InStockOrderAppService(IRepositoryint> repository, IInStockOrderRepository isdRepository,IInStockOrderDetailAppService isodAppSer ,IInStockOrderDetailLocAppService isodLocAppSer) : base(repository) { rep = isdRepository; isodApp = isodAppSer; isodLocApp = isodLocAppSer; } public override Task > GetAll(PagedInStockResultRequestDto input) { return base.GetAll(input); } [DontWrapResult] public PagedInStockOrderResultDto GetAllInStockOrders(PagedInStockResultRequestDto input) { PagedInStockOrderResultDto inSOs = new PagedInStockOrderResultDto (); var allOrgs=GetAll(input); inSOs.Rows = allOrgs.Result.Items; inSOs.Total = allOrgs.Result.TotalCount; return inSOs; } protected override IQueryable 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 (iso); foreach (var item in order.InStockOrderDetail) { CreateUpdateInStockOrderDetailDto isod = ObjectMapper.Map (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 (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, InStockOrderDetailDto, int , PagedInStockDetailResultRequestDto, CreateUpdateInStockOrderDetailDto, CreateUpdateInStockOrderDetailDto> > repository) : base(repository) { } protected override IQueryable
, IInStockOrderDetailAppService { public InStockOrderDetailAppService( IRepositoryint 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, InStockOrderDetailLocDto, int, PagedInStockDetailLocResultRequestDto, > repository) : base(repository) { } protected override IQueryable
CreateUpdateInStockOrderDetailLocDto, CreateUpdateInStockOrderDetailLocDto>
, IInStockOrderDetailLocAppService { public InStockOrderDetailLocAppService( IRepositoryint CreateFilteredQuery(
PagedInStockDetailLocResultRequestDto input) { var qry = base.CreateFilteredQuery(input) .Where(t => t.InStockOrderDetailId == input.InStockOrderDetailId); return qry; } } }