A
bp(net core)+easyui+efcore实现仓储管理系统目录

有了前一篇文章(
abp(net core)+easyui+efcore实现仓储管理系统——模块管理升级(六十)
),对于模块管理的升级过程中解决升级中出现的问题的一些经验。我们对组织管理这个模块进行升级。

一、添加Profile定义文件

1. 在Visual Studio 2022的“解决方案资源管理器”中,右键单击“ABP.TPLMS.Application”项目,使用鼠标左键展开“Orgs” > “Dto”文件夹

2. 使用鼠标右键单击“Dto”文件夹,然后选择“添加” > “类”。 将类命名为 OrgMapProfile,然后选择“添加”。代码如下。

usingABP.TPLMS.Authorization.Users;usingABP.TPLMS.Entitys;usingABP.TPLMS.Users.Dto;usingAutoMapper;usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespaceABP.TPLMS.Orgs.Dto
{
public classOrgMapProfile:Profile
{
publicOrgMapProfile()

{

CreateMap
<OrgDto, Org>();
CreateMap
<OrgDto, CreateUpdateOrgDto>();
CreateMap
<CreateUpdateOrgDto, Org>();

}
}
}

二、修改OrgAppService类

3.在Visual Studio 2022的“解决方案资源管理器”中,在“Orgs”文件夹中找到OrgAppService.cs文件,双击在文本编辑器中打开,修改代码如下。

usingAbp.Application.Services;usingAbp.Application.Services.Dto;usingAbp.Domain.Repositories;usingAbp.Web.Models;usingABP.TPLMS.Entitys;usingABP.TPLMS.Modules.Dto;usingABP.TPLMS.Orgs.Dto;usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespaceABP.TPLMS.Orgs
{
public class OrgAppService : AsyncCrudAppService<Org, OrgDto, int, PagedOrgResultRequestDto,
CreateUpdateOrgDto, CreateUpdateOrgDto
>, IOrgAppService

{
public OrgAppService(IRepository<Org, int>repository)
:
base(repository)
{

}
[DontWrapResult]
public PagedOrgResultDto<OrgDto>GetAllOrgs(PagedOrgResultRequestDto input)
{
PagedOrgResultDto
<OrgDto> orgs = new PagedOrgResultDto<OrgDto>();
input.SkipCount
= 0;//这里需要进行参数传递
input.MaxResultCount= 1000;var allOrgs=GetAllAsync(input);

IReadOnlyList
<OrgDto> result =AddParentOrgs(input, allOrgs.Result.Items).AsReadOnly();
orgs.Rows
=result;
orgs.Total
=result.Count;returnorgs;
}
private List<OrgDto> AddParentOrgs(PagedOrgResultRequestDto input,IReadOnlyList<OrgDto>list)
{
List
<OrgDto> result = new List<OrgDto>();if (list == null)returnresult;var qry1 = base.CreateFilteredQuery(input);
List
<Org> listParent = new List<Org>();
GetParentOrgs(listParent, list[
0].ParentId, qry1);foreach (var item inlistParent)
{
result.Add(ObjectMapper.Map
<OrgDto>(item));
}
result.AddRange(list.ToArray());
returnresult;
}
protected override IQueryable<Org>CreateFilteredQuery(PagedOrgResultRequestDto input)
{
var qry = base.CreateFilteredQuery(input)
.Where(t
=> t.Name.Contains(input.OrgName == null ? string.Empty : input.OrgName))

.Where(t
=> t.BizCode.Contains(input.OrgCode == null ? string.Empty : input.OrgCode))

.Where(t
=> t.CustomCode.Contains(input.CustomCode == null ? string.Empty : input.CustomCode));returnqry;
}
private void GetParentOrgs(List<Org> orgs, int ParentId, IQueryable<Org>listOrgs)
{

List
<Org> drs = listOrgs.Where(x => x.Id ==ParentId).ToList();if (drs == null || drs.Count <= 0)
{
return;
}
else{for (int i = 0; i < drs.Count; i++)
{
var dr =drs[i];if (!orgs.Contains(dr))
{
orgs.Add(dr);
}
GetParentOrgs(orgs, dr.ParentId, listOrgs);
}
}
}
}
}

4. 上面代码中需要特别注意的一点,是GetAllOrgs方法中的input.SkipCount=0这一行代码,如果将这一行代码注释掉,在进行条件查询时,会报错。在组织管理页面的海关代码中输入“2011”,然后点击“查询”按钮。如下图。

5.Visual Studio 2022会弹出一个用记未处理的异常,错误信息,如下图。

6.在Visual Studio 2022的解决方案资源管理器中,将刚才注释掉的那一条代码“input.SkipCount=0”,还原。按F5运行应用程序。

7.在浏览器中的登录页面中输入管理员用户名和密码进行登录。

8.在主界面的菜单中,选择“Business->组织管理”菜单项,浏览器中呈现一个组织信息列表与四个按钮。组织信息能正常显示。如下图。

9. 在“组织管理”列表页面的海关代码输入框中输入“2011”,然后点击“查询”按钮。如下图。

10.这一次程序运行正常,查询出了结果,结果如下图。

11.在“组织管理”列表页面中使用鼠标点击“添加”按钮,弹出“添加组织信息”界面。如下图。

12.在“添加组织信息”中填写完信息,然后点击“保存”按钮,将新添加的组织信息保存到数据库。如下图。

标签: none

添加新评论