Jelajahi Sumber

Merge branch 'master' of http://git.12345lm.cn/Fengwo/hotline

Dun.Jason 1 tahun lalu
induk
melakukan
374b76c29d

+ 44 - 1
src/Hotline.Api/Controllers/SchedulingController.cs

@@ -9,6 +9,12 @@ using XF.Domain.Repository;
 using Hotline.Share.Dtos.Schedulings;
 using MapsterMapper;
 using Hotline.Users;
+using System.Data;
+using Hotline.Repository.SqlSugar.TextSearch;
+using Microsoft.AspNetCore.Components;
+using System.Dynamic;
+using Microsoft.EntityFrameworkCore.Query.Internal;
+using NetTaste;
 
 namespace Hotline.Api.Controllers
 {
@@ -240,7 +246,7 @@ namespace Hotline.Api.Controllers
 								SchedulingUserId = user.UserId,
 								SchedulingUserName = user.UserName,
 								ShiftId = dtos.ShiftId,
-								ShiftName = dtos.ShiftName,
+								ShiftName = shift.Name,
 								SchedulingTime = schedulingTime,
 								WorkingTime = shift.WorkingTime,
 								OffDutyTime = shift.OffDutyTime,
@@ -297,7 +303,11 @@ namespace Hotline.Api.Controllers
 			var scheduling = await _schedulingRepository.GetAsync(dto.Id, HttpContext.RequestAborted);
 			if (scheduling is null)
 				throw UserFriendlyException.SameMessage("无效排班信息");
+			var shift = await _schedulingShiftRepository.GetAsync(dto.ShiftId, HttpContext.RequestAborted);
+			if (shift == null)
+				throw UserFriendlyException.SameMessage("传入排班班次信息错误");
 			_mapper.Map(dto, scheduling);
+			scheduling.ShiftName = shift.Name;
 			await _schedulingRepository.UpdateAsync(scheduling, HttpContext.RequestAborted);
 		}
 
@@ -341,6 +351,39 @@ namespace Hotline.Api.Controllers
 			return new PagedDto<Scheduling>(total, items);
 		}
 
+		/// <summary>
+		/// 排班数据查询
+		/// </summary>
+		/// <param name="dto"></param>
+		/// <returns></returns>
+		[HttpGet("data")]
+		public async Task<List<IDictionary<string, object>>> Data([FromQuery] DataDto dto) 
+		{
+			List<IDictionary<string, object>> res = new List<IDictionary<string, object>>();
+			var startTime = DateTime.Parse(dto.Time.ToString("yyyy-MM") + "-01");
+			var endTime =startTime.AddMonths(1).AddDays(-1);
+			DataTable data = await _schedulingRepository.Queryable().Where(x=>x.SchedulingTime >= startTime && x.SchedulingTime <= endTime).ToDataTableAsync();
+			if (data == null || data.Rows.Count <= 0) return res;
+			var names = data.AsEnumerable().Select(x=>x.Field<string>("SchedulingUserName")).Distinct().ToList();
+		
+			foreach (var item in names)
+			{
+				dynamic dynamicObj = new ExpandoObject();
+				var dict = (IDictionary<string, object>)dynamicObj;
+				var userName = "SchedulingUserName";
+				dict[userName] = item;
+				var scheduling = data.AsEnumerable().Where(x => x.Field<string>("SchedulingUserName") == item).OrderBy(x => x.Field<DateTime>("SchedulingTime")).ToList();
+				foreach (DataRow row in scheduling)
+				{
+					var obj = new { Name = row.Field<string>("ShiftName"), Id = row.Field<string>("Id") };
+					var tiem = row.Field<DateTime>("SchedulingTime").ToString("yyyy-MM-dd");
+					dict[tiem] = obj;
+				}
+				res.Add(dict);
+			}
+			return res;
+		}
+
 		/// <summary>
 		/// 获取排班管理实体
 		/// </summary>

+ 8 - 0
src/Hotline.Share/Dtos/Schedulings/SchedulingDto.cs

@@ -140,4 +140,12 @@ namespace Hotline.Share.Dtos.Schedulings
 		/// </summary>
 		public DateTime? EndTime { get; set; }
 	}
+
+	public record DataDto { 
+	
+		/// <summary>
+		/// 时间
+		/// </summary>
+		public DateTime Time { get; set; }
+	}
 }

+ 4 - 0
src/Hotline/Settings/SystemOrganize.cs

@@ -3,6 +3,7 @@ using SqlSugar;
 using System.ComponentModel;
 using XF.Domain.Exceptions;
 using XF.Domain.Repository;
+using XF.Utility.EnumExtensions;
 
 namespace Hotline.Settings;
 
@@ -72,6 +73,9 @@ public class SystemOrganize : CreationSoftDeleteEntity
     [SugarColumn(IsIgnore = true)] 
     public List<SystemOrganize> Children { get; set; }
 
+    [SugarColumn(IsIgnore = true)]
+    public string OrgTypeText => OrgType.GetDescription();
+
     public void InitOrgLevel() => Level = Id.CalcOrgLevel();
 
     /// <summary>