using Microsoft.AspNetCore.Mvc; //using Syc.Basic.Web.Contracts; using Syc.Basic.Web.WMS.Dtos.Position; using Syc.Basic.Web.WMS.Entitys; using System; using System.Collections.Generic; using System.Linq; using System.Linq.Dynamic.Core; using System.Linq.Dynamic.Core.Tokenizer; using System.Text; using System.Threading.Tasks; using Volo.Abp.Domain.Repositories; namespace Syc.Basic.Web.Service { public class PositionService : ApiService { private readonly IRepository positionTable; public PositionService(IRepository _position) { positionTable = _position; } [HttpPost] public async Task PositionCreate(PositionCreateDto positionCreateDto) { Position position = new Position() { Code = positionCreateDto.Code, Name = positionCreateDto.Name, Description = positionCreateDto.Description, Order = positionCreateDto.Order, Status = positionCreateDto.Status, Createtime = DateTime.Now }; await positionTable.InsertAsync(position); } [HttpPost] public async Task Delete(PositionDeleteDto positionDeleteDto) { if (positionDeleteDto.Ids.Any()) { for (int i = 0; i < positionDeleteDto.Ids.Length; i++) { var _position = await positionTable.FirstOrDefaultAsync(x => x.Code == positionDeleteDto.Ids[i]); if (_position is not null) await positionTable.DeleteAsync(_position); } } } [HttpPost] public Task PositionById(PositionCreateDto positionCreateDto) { throw new NotImplementedException(); } [HttpPost] public async Task> PositionList(PositionQueryaDto positionQueryaDto) { var data = await positionTable.GetQueryableAsync(); if (!string.IsNullOrWhiteSpace(positionQueryaDto.Name)) data = data.Where(x => x.Name.Contains(positionQueryaDto.Name)); if (!string.IsNullOrWhiteSpace(positionQueryaDto.Description)) data = data.Where(x => x.Description.Contains(positionQueryaDto.Description)); if (!string.IsNullOrWhiteSpace(positionQueryaDto.Code)) data = data.Where(x => x.Code.Contains(positionQueryaDto.Code)); PageOutput pageOutput = new PageOutput(); pageOutput.Total = await positionTable.CountAsync(); pageOutput.Data = data.OrderByDescending(x => x.Createtime).Page(positionQueryaDto.Page, positionQueryaDto.PageSize); return pageOutput; } [HttpPost] public async Task Update(PositionUpdateDto positionUpdateDto) { var _position = await positionTable.FirstOrDefaultAsync(x => x.Code == positionUpdateDto.Code); if (_position is not null) { _position.Status = positionUpdateDto.Status; if (!string.IsNullOrWhiteSpace(positionUpdateDto.Name)) _position.Name = positionUpdateDto.Name; if (positionUpdateDto.Order != 0) _position.Order = positionUpdateDto.Order; if (!string.IsNullOrWhiteSpace(positionUpdateDto.Description)) _position.Description = positionUpdateDto.Description; await positionTable.UpdateAsync(_position); } else throw Oops.Oh("未能检索关于作为唯一健职业代号数据,请检测是否存在."); } } }