98 lines
		
	
	
		
			3.5 KiB
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			98 lines
		
	
	
		
			3.5 KiB
		
	
	
	
		
			C#
		
	
	
	
| 
								 | 
							
								using langguanApi.Extensions.AutoDI;
							 | 
						|||
| 
								 | 
							
								using langguanApi.Model;
							 | 
						|||
| 
								 | 
							
								using Mapster;
							 | 
						|||
| 
								 | 
							
								using System.Linq.Expressions;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								namespace langguanApi.Service
							 | 
						|||
| 
								 | 
							
								{
							 | 
						|||
| 
								 | 
							
								    /// <summary>
							 | 
						|||
| 
								 | 
							
								    /// OrganizedService
							 | 
						|||
| 
								 | 
							
								    /// </summary>
							 | 
						|||
| 
								 | 
							
								    [ServiceInjection(InjectionType.Transient)]
							 | 
						|||
| 
								 | 
							
								    public class OrganizedService : BaseService<Organized>
							 | 
						|||
| 
								 | 
							
								    {
							 | 
						|||
| 
								 | 
							
								        private readonly DeviceService _deviceService;
							 | 
						|||
| 
								 | 
							
								        public OrganizedService(IConfiguration config, DeviceService device) : base(config, nameof(Organized))
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            _deviceService = device;
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								        /// <summary>
							 | 
						|||
| 
								 | 
							
								        /// Add 工序
							 | 
						|||
| 
								 | 
							
								        /// </summary>
							 | 
						|||
| 
								 | 
							
								        /// <param name="input"></param>
							 | 
						|||
| 
								 | 
							
								        /// <returns></returns>
							 | 
						|||
| 
								 | 
							
								        public async Task<ApiResult> Add(OrganizedDto input)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            var entity = input.Adapt<Organized>();
							 | 
						|||
| 
								 | 
							
								            await CreateAsync(entity);
							 | 
						|||
| 
								 | 
							
								            return new ApiResult() { code = 0 };
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								        /// <summary>
							 | 
						|||
| 
								 | 
							
								        /// Update
							 | 
						|||
| 
								 | 
							
								        /// </summary>
							 | 
						|||
| 
								 | 
							
								        /// <param name="input"></param>
							 | 
						|||
| 
								 | 
							
								        /// <returns></returns>
							 | 
						|||
| 
								 | 
							
								        public async Task<ApiResult> Update(OrganizedUpdateDto input)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            var entity = input.Adapt<Organized>();
							 | 
						|||
| 
								 | 
							
								            await UpdateAsync(input.Id, entity);
							 | 
						|||
| 
								 | 
							
								            return new ApiResult() { code = 0 };
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								        /// <summary>
							 | 
						|||
| 
								 | 
							
								        /// Delete
							 | 
						|||
| 
								 | 
							
								        /// </summary>
							 | 
						|||
| 
								 | 
							
								        /// <param name="ids"></param>
							 | 
						|||
| 
								 | 
							
								        /// <returns></returns>
							 | 
						|||
| 
								 | 
							
								        public async Task<ApiResult> Delete(IEnumerable<string> ids)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            if (ids.Any())
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                foreach (var id in ids)
							 | 
						|||
| 
								 | 
							
								                {
							 | 
						|||
| 
								 | 
							
								                    await RemoveAsync(id);
							 | 
						|||
| 
								 | 
							
								                }
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								            else
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                return new ApiResult() { code = 1, msg = "请选择要删除的记录" };
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								            return new ApiResult() { code = 0 };
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								        /// <summary>
							 | 
						|||
| 
								 | 
							
								        /// ListAndDevice
							 | 
						|||
| 
								 | 
							
								        /// </summary>
							 | 
						|||
| 
								 | 
							
								        /// <param name="OrganizedType">1,有组织,2无组织</param>
							 | 
						|||
| 
								 | 
							
								        /// <returns></returns>
							 | 
						|||
| 
								 | 
							
								        public async Task<ApiResult> ListAndDevice(int OrganizedType = 1)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            Expression<Func<Organized, bool>> exp = filter => filter.OrganizedType == OrganizedType && filter.IsDelete == false;
							 | 
						|||
| 
								 | 
							
								            var result = (await base.GetListWithExp(exp)).OrderByDescending(x => x.Order).ToList();
							 | 
						|||
| 
								 | 
							
								            List<OrganizedByDeviceDto> list = new List<OrganizedByDeviceDto>();
							 | 
						|||
| 
								 | 
							
								            var devices = await _deviceService.GetDeviceByOrgids(result.Select(s => s.Id));
							 | 
						|||
| 
								 | 
							
								            foreach (var item in result)
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                list.Add(new OrganizedByDeviceDto
							 | 
						|||
| 
								 | 
							
								                {
							 | 
						|||
| 
								 | 
							
								                    Items = devices.Where(s => s.OrgId == item.Id).ToList(),
							 | 
						|||
| 
								 | 
							
								                    Order = item.Order,
							 | 
						|||
| 
								 | 
							
								                    Name = item.Name,
							 | 
						|||
| 
								 | 
							
								                    OrganizedType = item.OrganizedType,
							 | 
						|||
| 
								 | 
							
								                    Id = item.Id
							 | 
						|||
| 
								 | 
							
								                });
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								            return new ApiResult() { code = 0, data = list };
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								        /// <summary>
							 | 
						|||
| 
								 | 
							
								        /// List
							 | 
						|||
| 
								 | 
							
								        /// </summary>
							 | 
						|||
| 
								 | 
							
								        /// <param name="OrganizedType">1,有组织,2无组织</param>
							 | 
						|||
| 
								 | 
							
								        /// <returns></returns>
							 | 
						|||
| 
								 | 
							
								        public async Task<ApiResult> List(int OrganizedType = 1)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            Expression<Func<Organized, bool>> exp = filter => filter.OrganizedType == OrganizedType && filter.IsDelete == false;
							 | 
						|||
| 
								 | 
							
								            var result = (await base.GetListWithExp(exp)).OrderByDescending(x => x.Order).ToList();
							 | 
						|||
| 
								 | 
							
								            return new ApiResult() { code = 0, data = result };
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								    }
							 | 
						|||
| 
								 | 
							
								}
							 |