public async Task Send(SupplySendDto input) { var user = _userRepository.GetAll().FirstOrDefault(ite => ite.Id == input.UserId); if (user == null) { throw new UserFriendlyException((int)ErrorCode.DataAccessErr, "未找到要发放的对象。"); } var menuInit = await _userMenuInitRepository.FirstOrDefaultAsync(r => r.MenuId == 28 && r.UserId == input.UserId); if (menuInit == null || menuInit.Status != -1) { throw new UserFriendlyException((int)ErrorCode.DataAccessErr, "当前用户还未完成用品初始化,不能发放用品。"); } var supplys = _supplyRepository.GetAll().Where(ite => input.SupplyId.Contains(ite.Id)); foreach (var s in supplys) { s.Status = (int)SupplyStatus.被领用; var has = _userSupplyRepository.FirstOrDefault(ite => ite.SupplyId == s.Id && ite.Status != (int)UserSupplyStatus.已退还 && ite.Status == (int)UserSupplyStatus.已报废); if (has != null) { throw new UserFriendlyException((int)ErrorCode.DataAccessErr, "当前用品正在被别人使用,发放失败。"); } var us = new UserSupply() { Status = (int)UserSupplyStatus.使用中, StartTime = DateTime.Now, SupplyId = s.Id, UserId = input.UserId, EndTime = s.ExpiryDate }; s.UserId = "u_" + input.UserId; await _userSupplyRepository.InsertAsync(us); await _supplyRepository.UpdateAsync(s); } await _noticeManager.CreateOrUpdateNoticeAsync(new ZCYX.FRMSCore.Application.NoticePublishInput() { Title = "用品发放", Content = "行政人员为你发放了新的个人用品,请注意查收", NoticeUserIds = input.UserId.ToString(), NoticeType = 1 }); }
public async Task CreateOrUpdate(CreateMenuInitInput <List <UserSupplyBatchCreateInput> > input) { var currentUserId = AbpSession.UserId.Value; var menuInit = await _userMenuInitRepository.FirstOrDefaultAsync(r => r.MenuId == input.MenuId && r.UserId == currentUserId); if (menuInit == null) { var init = new UserMenuInit() { MenuId = input.MenuId, UserId = currentUserId, Status = input.HasComplateInit ? -1 : 0 }; _userMenuInitRepository.Insert(init); } else { if (input.HasComplateInit) { menuInit.Status = -1; _userMenuInitRepository.Update(menuInit); } } if (input.List.Count > 50) { throw new UserFriendlyException((int)ErrorCode.DataAccessErr, "批量修改最大支持50条数据"); } var uids = input.List.Where(ite => ite.Id.HasValue).Select(ite => ite.Id).ToList(); var sids = input.List.Where(ite => ite.SupplyId.HasValue).Select(ite => ite.SupplyId).ToList(); //删除没有的数据 //_userSupplyRepository.Delete(ite => ite.CreatorUserId == AbpSession.UserId.Value && !uids.Contains(ite.Id)); //_supplyBaseRepository.Delete(ite => ite.CreatorUserId == AbpSession.UserId.Value && !sids.Contains(ite.Id)); foreach (var item in input.List) { if (item.Id.HasValue) { if (!item.SupplyId.HasValue) { throw new UserFriendlyException((int)ErrorCode.DataAccessErr, "用品数据异常"); } var model = await _supplyBaseRepository.GetAsync(item.SupplyId.Value); model.CreatorUserId = AbpSession.UserId; model.Unit = item.Unit; model.Money = item.Money; model.Version = item.Version; model.Name = item.Name; model.Type = item.Type; model.UserId = item.Supply_UserId; model.ExpiryDate = item.EndTime; //model.Status = (int)SupplyStatus.被领用; var usersupplyModel = await _userSupplyRepository.GetAsync(item.Id.Value); usersupplyModel.StartTime = item.StartTime; usersupplyModel.EndTime = item.EndTime; // usersupplyModel.Status = (int)UserSupplyStatus.使用中; } else { var supplyId = Guid.NewGuid(); var model = new SupplyBase() { Id = supplyId, Code = "", Unit = item.Unit, Money = item.Money, Name = item.Name, Type = item.Type, Version = item.Version, CreatorUserId = AbpSession.UserId, ExpiryDate = item.EndTime, ProductDate = DateTime.Now, UserId = item.Supply_UserId, Status = (int)SupplyStatus.被领用 }; await _supplyBaseRepository.InsertAsync(model); var usersupplyModel = new UserSupply() { SupplyId = supplyId, StartTime = item.StartTime, EndTime = item.EndTime, Id = Guid.NewGuid(), UserId = AbpSession.UserId.Value, Status = (int)UserSupplyStatus.使用中 }; await _userSupplyRepository.InsertAsync(usersupplyModel); } } }