From ddd09b07d3cd0fdd8bca31bebb4a651052e47c36 Mon Sep 17 00:00:00 2001 From: wxd <123@qq.com> Date: Tue, 30 Apr 2024 02:34:11 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=AF=B9=E5=BA=94=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E7=B1=BB=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UserItemTypes/UserItemTypeAppService.cs | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 src/Shentun.Peis.Application/UserItemTypes/UserItemTypeAppService.cs diff --git a/src/Shentun.Peis.Application/UserItemTypes/UserItemTypeAppService.cs b/src/Shentun.Peis.Application/UserItemTypes/UserItemTypeAppService.cs new file mode 100644 index 0000000..430ee25 --- /dev/null +++ b/src/Shentun.Peis.Application/UserItemTypes/UserItemTypeAppService.cs @@ -0,0 +1,84 @@ +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Shentun.Peis.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Volo.Abp.Domain.Repositories; +using Volo.Abp; + +namespace Shentun.Peis.UserItemTypes +{ + /// + /// 用户对应项目类别 + /// + [ApiExplorerSettings(GroupName = "Work")] + [Authorize] + public class UserItemTypeAppService + { + private readonly IRepository _userItemTypeRepository; + + public UserItemTypeAppService( + IRepository userItemTypeRepository + ) + { + _userItemTypeRepository = userItemTypeRepository; + } + /// + /// 设置用户对应的项目类别 先删除,后创建 + /// + /// 用户ID + /// 对应的项目类别ID集合 + /// + /// + [HttpPost("api/app/UserItemType/CreateMany")] + public async Task CreateManyAsync(Guid UserId, List ItemTypeIds) + { + + if (UserId == Guid.Empty) + { + throw new UserFriendlyException($"用户ID不能为空"); + } + + await _userItemTypeRepository.DeleteAsync(d => d.UserId == UserId, true); + + + if (ItemTypeIds.Any()) + { + + List entlist = new List(); + foreach (var itemTypeId in ItemTypeIds) + { + var ent = new UserItemType + { + UserId = UserId, + ItemTypeId = itemTypeId + }; + entlist.Add(ent); + } + + await _userItemTypeRepository.InsertManyAsync(entlist); + } + } + + + /// + /// 获取当前用户对应的项目类别 + /// + /// 用户ID + /// + [HttpPost("api/app/UserItemType/GetUserItemType")] + public async Task> GetUserItemTypeAsync(Guid UserId) + { + List guids = new List(); + var entlist = await _userItemTypeRepository.GetListAsync(m => m.UserId == UserId); + if (entlist.Any()) + { + guids = entlist.Select(s => s.ItemTypeId).ToList(); + } + return guids; + } + } +}