Merge branch 'development'

This commit is contained in:
2024-02-21 15:21:23 +08:00
15 changed files with 488 additions and 20 deletions

View File

@@ -162,4 +162,44 @@ public class DevicesController : ControllerBase
{
return await _deviceService.GetAttendanceDevicesAsync();
}
/// <summary>
/// 获取考勤设备在线、离线及总数
/// </summary>
/// <returns></returns>
[HttpGet("devicesnumber")]
public async Task<DeviceNumberResponse> GetDeviceNumberAsync()
{
return await _deviceService.GetDeviceNumberAsync();
}
/// <summary>
/// 获取考勤设备详情列表
/// </summary>
/// <returns></returns>
[HttpGet("attendancestotal")]
public async Task<Pagination<DevicePageResponse>> GetAttendanceTotalAsync([FromQuery]AttendanceTotalRequest request)
{
return await _deviceService.GetAttendanceTotalAsync(request);
}
/// <summary>
/// 获取考勤在线/离线设备详情列表
/// </summary>
/// <returns></returns>
[HttpGet("attendancesoffline")]
public async Task<Pagination<DevicePageResponse>> GetAttendanceOfflineAsync([FromQuery] DeviceOnlineAndofflineRequest request)
{
return await _deviceService.GetAttendanceOfflineAsync(request);
}
/// <summary>
/// 获取近期30天新增设备数
/// </summary>
/// <returns></returns>
[HttpGet("recentnumbers")]
public async Task<Dictionary<string, int>> GetRecentNumbersAsync()
{
return await _deviceService.GetRecentNumbersAsync();
}
}

View File

@@ -0,0 +1,8 @@
using Kurisu.Core.DataAccess.Dto;
namespace Dlhis.Basic.Device.Request
{
public class AttendanceTotalRequest : PageDto
{
}
}

View File

@@ -0,0 +1,9 @@
using Kurisu.Core.DataAccess.Dto;
namespace Dlhis.Basic.Device.Request
{
public class DeviceOnlineAndofflineRequest :PageDto
{
public bool IsOnAndOff { get; set; }
}
}

View File

@@ -0,0 +1,20 @@
namespace Dlhis.Basic.Device.Response
{
public class DeviceNumberResponse
{
/// <summary>
///在线
/// </summary>
public int OnlineNumber { get; set; }
/// <summary>
/// 离线
/// </summary>
public int OfflineNumber { get; set; }
/// <summary>
/// 总数
/// </summary>
public int TotalNumber { get; set; }
}
}

View File

@@ -1,6 +1,7 @@
using Dlhis.Basic.Device.Request;
using Dlhis.Basic.Device.Response;
using Kurisu.Core.DataAccess.Dto;
using Microsoft.AspNetCore.Mvc;
namespace Dlhis.Basic.Device.Services;
@@ -15,4 +16,12 @@ public interface IDeviceService : IScopeDependency
Task<DeviceResponse> GetDeviceByNoAsync(DeviceByNoRequest request);
Task<List<DeviceResponse>> GetAttendanceDevicesAsync();
Task<DeviceNumberResponse> GetDeviceNumberAsync();
Task<Pagination<DevicePageResponse>> GetAttendanceTotalAsync(AttendanceTotalRequest request);
Task<Pagination<DevicePageResponse>> GetAttendanceOfflineAsync(DeviceOnlineAndofflineRequest request);
Task<Dictionary<string, int>> GetRecentNumbersAsync();
}

View File

@@ -10,6 +10,7 @@ using Kurisu.SqlSugar.Attributes;
using Kurisu.SqlSugar.Extensions;
using Kurisu.SqlSugar.Services;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
@@ -194,5 +195,78 @@ public class DeviceService : IDeviceService
return devices.Where(x => x.Funcs.Contains(DeviceFuncEnumType.Attendance)).ToList();
}
public async Task<DeviceNumberResponse> GetDeviceNumberAsync()
{
var devices = await _dbContext.Queryable<DeviceEntity>()
.Where(x => x.Type == DeviceTypeEnumType.Attendance)
.ToListAsync();
var onlineNumber = devices.Where(x => x.Enable).Count();
var offlineNumber = devices.Where(x => x.Enable == false).Count();
var res = new DeviceNumberResponse
{
OnlineNumber = onlineNumber,
OfflineNumber = offlineNumber,
TotalNumber = devices.Count()
};
return res;
}
public async Task<Pagination<DevicePageResponse>> GetAttendanceTotalAsync(AttendanceTotalRequest request)
{
var page = await _dbContext.Queryable<DeviceEntity>()
.LeftJoin<DeviceTemplateEntity>((d, dt) => d.TemplateCode == dt.Code)
.Where(d => d.Type == DeviceTypeEnumType.Attendance)
.Select((d, dt) => new DevicePageResponse
{
FuncsStr = d.Funcs.ToString(),
Brand = dt.Brand,
Type = d.Type,
}, true)
.ToPageListAsync(request);
return page;
}
public async Task<Pagination<DevicePageResponse>> GetAttendanceOfflineAsync(DeviceOnlineAndofflineRequest request)
{
var page = await _dbContext.Queryable<DeviceEntity>()
.LeftJoin<DeviceTemplateEntity>((d, dt) => d.TemplateCode == dt.Code)
.Where(d => d.Type == DeviceTypeEnumType.Attendance && d.Enable == request.IsOnAndOff)
.Select((d, dt) => new DevicePageResponse
{
FuncsStr = d.Funcs.ToString(),
Brand = dt.Brand,
Type = d.Type,
}, true)
.ToPageListAsync(request);
return page;
}
public async Task<Dictionary<string, int>> GetRecentNumbersAsync()
{
//获取近30天并转化为"yyyy-MM-dd"集合
DateTime currentDate = DateTime.Now;
List<string> times = new List<string>();
for (int i = 0; i < 30; i++)
{
DateTime date = currentDate.AddDays(-i);
string dateString = date.ToString("yyyy-MM-dd");
times.Add(dateString);
}
var devices = await _dbContext.Queryable<DeviceEntity>().ToListAsync();
var dic = new Dictionary<string, int>();
times.ForEach(time =>
{
var count = devices.Where(x => x.CreateTime.ToString("yyyy-MM-dd") == time).Count();
dic[time] = count;
});
return dic;
}
}

View File

@@ -2,6 +2,7 @@
using Dlhis.Basic.Organization.Request;
using Dlhis.Basic.Organization.Response;
using Dlhis.Basic.Organization.Services;
using Dlhis.Entity.Basic.Entity;
using Kurisu.AspNetCore.MVC;
using Kurisu.Core.DataAccess.Dto;
using Microsoft.AspNetCore.Authorization;
@@ -156,5 +157,57 @@ public class GainfosController : ControllerBase
{
return await _gainfoService.GetGainfoDetailTaskAsync(request);
}
/// <summary>
/// 获取近七天入职人数及列表
/// </summary>
/// <returns></returns>
[HttpGet("weeknumber")]
public async Task<Dictionary<string, Pagination<GainfoDetailResponse>>> GetWeekNumberAsync([FromQuery] WeekNumberRequest request)
{
// 从请求头中获取 Token
string token = HttpContext.Request.Headers["Authorization"].ToString().Replace("Bearer ", "");
return await _gainfoService.GetWeekNumberAsync(request,token);
}
/// <summary>
/// 获取近七天离职人数及列表
/// </summary>
/// <returns></returns>
[HttpGet("weeknumberdimission")]
public async Task<Dictionary<string, Pagination<GainfoDetailResponse>>> GetDimissionWeekNumberAsync([FromQuery] WeekNumberRequest request)
{
// 从请求头中获取 Token
string token = HttpContext.Request.Headers["Authorization"].ToString().Replace("Bearer ", "");
return await _gainfoService.GetDimissionWeekNumberAsync(request,token);
}
/// <summary>
/// 获取基地在职、离职、考勤数
/// </summary>
/// <returns></returns>
[HttpGet("gainfonumbers")]
public async Task<GainfoGainfoNumbersResponse> GetGainfoNumbersAsync()
{
// 从请求头中获取 Token
string token = HttpContext.Request.Headers["Authorization"].ToString().Replace("Bearer ", "");
return await _gainfoService.GetGainfoNumbersAsync(token);
}
/// <summary>
/// 获取本基地管理员列表
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpGet("administrator")]
public async Task<Pagination<GainfoDetailResponse>> GetAdministratorAsync([FromQuery] WeekNumberRequest request)
{
// 从请求头中获取 Token
string token = HttpContext.Request.Headers["Authorization"].ToString().Replace("Bearer ", "");
return await _gainfoService.GetAdministratorAsync(request,token);
}
}

View File

@@ -0,0 +1,8 @@
using Kurisu.Core.DataAccess.Dto;
namespace Dlhis.Basic.Organization.Request
{
public class WeekNumberRequest : PageDto
{
}
}

View File

@@ -0,0 +1,9 @@
namespace Dlhis.Basic.Organization.Response
{
public class GainfoGainfoNumbersResponse
{
public int OnlineNumber { get; set; }
public int OfflineNumber { get; set; }
public int AttendanceNumber{ get; set; }
}
}

View File

@@ -1,5 +1,6 @@
using Dlhis.Basic.Organization.Request;
using Dlhis.Basic.Organization.Response;
using Dlhis.Entity.Basic.Entity;
using Kurisu.Core.DataAccess.Dto;
using Microsoft.AspNetCore.Mvc;
@@ -30,4 +31,12 @@ public interface IGainfoService : IScopeDependency
Task<Pagination<GainfoListResponse>> GetGainfoListTaskAsync(GainfoListRequest request);
Task<GainfoDetailResponse> GetGainfoDetailTaskAsync(GainfoDetailRequest request);
Task<Dictionary<string, Pagination<GainfoDetailResponse>>> GetWeekNumberAsync(WeekNumberRequest request, string token);
Task<Dictionary<string, Pagination<GainfoDetailResponse>>> GetDimissionWeekNumberAsync([FromQuery] WeekNumberRequest request, string token);
Task<GainfoGainfoNumbersResponse> GetGainfoNumbersAsync(string token);
Task<Pagination<GainfoDetailResponse>> GetAdministratorAsync(WeekNumberRequest request,string token);
}

View File

@@ -16,6 +16,7 @@ using Kurisu.SqlSugar.Services;
using Mapster;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Mvc;
using System.IdentityModel.Tokens.Jwt;
namespace Dlhis.Basic.Organization.Services.Implements;
@@ -313,7 +314,7 @@ public class GainfoService : IGainfoService
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public async Task<Pagination<GainfoListResponse>> GetGainfoListTaskAsync( GainfoListRequest request)
public async Task<Pagination<GainfoListResponse>> GetGainfoListTaskAsync(GainfoListRequest request)
{
var page = await _gainfoStore.Queryable(request.Status)
.LeftJoin<DepartmentEntity>((ga, de) => ga.DepartmentNo == de.No)
@@ -345,12 +346,12 @@ public class GainfoService : IGainfoService
{
var info = await _gainfoStore.Queryable(request.Status)
.LeftJoin<DepartmentEntity>((ga, de) => ga.DepartmentNo == de.No)
.LeftJoin<BasicTypeEntity>((ga,de,type) => ga.Native == type.Code && type.Type == "native")
.LeftJoin<PositionEntity>((ga, de, type,posi) => ga.Position == posi.Name)
.LeftJoin<BasicTypeEntity>((ga, de, type, posi,type2) => ga.CountryNo == type2.Code && type2.Type == "country")
.LeftJoin<BasicTypeEntity>((ga, de, type, posi, type2,type3) => ga.Nation == type3.Code && type3.Type == "nation")
.LeftJoin<BasicTypeEntity>((ga, de, type) => ga.Native == type.Code && type.Type == "native")
.LeftJoin<PositionEntity>((ga, de, type, posi) => ga.Position == posi.Name)
.LeftJoin<BasicTypeEntity>((ga, de, type, posi, type2) => ga.CountryNo == type2.Code && type2.Type == "country")
.LeftJoin<BasicTypeEntity>((ga, de, type, posi, type2, type3) => ga.Nation == type3.Code && type3.Type == "nation")
.Where(ga => ga.No == request.No)
.Select((ga, de,type,posi,type2, type3) => new GainfoDetailResponse
.Select((ga, de, type, posi, type2, type3) => new GainfoDetailResponse
{
No = ga.No,
SapNo = ga.SapNo,
@@ -377,6 +378,180 @@ public class GainfoService : IGainfoService
return info;
}
public async Task<Dictionary<string, Pagination<GainfoDetailResponse>>> GetWeekNumberAsync(WeekNumberRequest request, string token)
{
var werks = GetClaimValueFromToken(token, "tenant");
//获取近7天并转化为"yyyy-MM-dd"集合
DateTime currentDate = DateTime.Now;
List<string> times = new List<string>();
for (int i = 0; i < 7; i++)
{
DateTime date = currentDate.AddDays(-i);
string dateString = date.ToString("yyyy-MM-dd");
times.Add(dateString);
}
var dic = new Dictionary<string, Pagination<GainfoDetailResponse>>();
foreach (var time in times)
{
var infos = await _gainfoStore.Queryable(GainfoStatusEnumType.Working)
.LeftJoin<DepartmentEntity>((ga, de) => ga.DepartmentNo == de.No)
.LeftJoin<BasicTypeEntity>((ga, de, type) => ga.Native == type.Code && type.Type == "native")
.LeftJoin<PositionEntity>((ga, de, type, posi) => ga.Position == posi.Name)
.LeftJoin<BasicTypeEntity>((ga, de, type, posi, type2) => ga.CountryNo == type2.Code && type2.Type == "country")
.LeftJoin<BasicTypeEntity>((ga, de, type, posi, type2, type3) => ga.Nation == type3.Code && type3.Type == "nation")
.Where(ga => ga.CreateTime.ToString("yyyy-MM-dd") == time && ga.Werks == werks)
.Select((ga, de, type, posi, type2, type3) => new GainfoDetailResponse
{
No = ga.No,
SapNo = ga.SapNo,
Name = ga.Name,
Code = ga.Code,
DepartmentName = de.Name,
IdClass = ga.IdClass,
IdNo = ga.IdNo,
Gender = ga.Gender,
NativeName = type.Display,
Address = ga.Address,
Birthday = ga.Birthday,
Phone = ga.Phone,
Position = ga.Position,
Grade = posi.Grade,
Degree = ga.Degree,
Werks = ga.Werks,
CostId = ga.CostId,
Marital = ga.Marital,
CountryName = type2.Display,
NationName = type3.Display,
IsActive = ga.Employed == "Active" ? true : false,
}).ToPageListAsync(request);
//var infos = await _gainfoStore.Queryable(GainfoStatusEnumType.Working)
// .Where(ga => ga.CreateTime.ToString("yyyy-MM-dd") == time)
// .ToPageListAsync(request);
dic[time] = infos;
}
return dic;
}
public async Task<Dictionary<string, Pagination<GainfoDetailResponse>>> GetDimissionWeekNumberAsync(WeekNumberRequest request, string token)
{
var werks = GetClaimValueFromToken(token, "tenant");
//获取近7天并转化为"yyyy-MM-dd"集合
DateTime currentDate = DateTime.Now;
List<string> times = new List<string>();
for (int i = 0; i < 7; i++)
{
DateTime date = currentDate.AddDays(-i);
string dateString = date.ToString("yyyy-MM-dd");
times.Add(dateString);
}
var dic = new Dictionary<string, Pagination<GainfoDetailResponse>>();
foreach (var time in times)
{
var infos = await _gainfoStore.Queryable(GainfoStatusEnumType.Leave)
.LeftJoin<DepartmentEntity>((ga, de) => ga.DepartmentNo == de.No)
.LeftJoin<BasicTypeEntity>((ga, de, type) => ga.Native == type.Code && type.Type == "native")
.LeftJoin<PositionEntity>((ga, de, type, posi) => ga.Position == posi.Name)
.LeftJoin<BasicTypeEntity>((ga, de, type, posi, type2) => ga.CountryNo == type2.Code && type2.Type == "country")
.LeftJoin<BasicTypeEntity>((ga, de, type, posi, type2, type3) => ga.Nation == type3.Code && type3.Type == "nation")
.Where(ga => ga.CreateTime.ToString("yyyy-MM-dd") == time && ga.Werks == werks)
.Select((ga, de, type, posi, type2, type3) => new GainfoDetailResponse
{
No = ga.No,
SapNo = ga.SapNo,
Name = ga.Name,
Code = ga.Code,
DepartmentName = de.Name,
IdClass = ga.IdClass,
IdNo = ga.IdNo,
Gender = ga.Gender,
NativeName = type.Display,
Address = ga.Address,
Birthday = ga.Birthday,
Phone = ga.Phone,
Position = ga.Position,
Grade = posi.Grade,
Degree = ga.Degree,
Werks = ga.Werks,
CostId = ga.CostId,
Marital = ga.Marital,
CountryName = type2.Display,
NationName = type3.Display,
IsActive = ga.Employed == "Active" ? true : false,
}).ToPageListAsync(request);
dic[time] = infos;
}
return dic;
}
public async Task<GainfoGainfoNumbersResponse> GetGainfoNumbersAsync(string token)
{
var werks = GetClaimValueFromToken(token, "tenant");
//在职人数
var onlineNumber = await _gainfoStore.Queryable(GainfoStatusEnumType.Working)
.Where(ga => ga.Werks == werks)
.CountAsync();
//离职人数
var offlineNumber = await _gainfoStore.Queryable(GainfoStatusEnumType.Leave)
.Where(ga => ga.Werks == werks)
.CountAsync();
//考勤总人数
var attendanceNumber = onlineNumber + offlineNumber;
var res = new GainfoGainfoNumbersResponse
{
OnlineNumber = onlineNumber,
OfflineNumber = offlineNumber,
AttendanceNumber = attendanceNumber
};
return res;
}
public async Task<Pagination<GainfoDetailResponse>> GetAdministratorAsync( WeekNumberRequest request, string token)
{
var werks = GetClaimValueFromToken(token, "tenant");
var info = await _gainfoStore.Queryable(GainfoStatusEnumType.Working)
.LeftJoin<DepartmentEntity>((ga, de) => ga.DepartmentNo == de.No)
.LeftJoin<BasicTypeEntity>((ga, de, type) => ga.Native == type.Code && type.Type == "native")
.LeftJoin<PositionEntity>((ga, de, type, posi) => ga.Position == posi.Name)
.LeftJoin<BasicTypeEntity>((ga, de, type, posi, type2) => ga.CountryNo == type2.Code && type2.Type == "country")
.LeftJoin<BasicTypeEntity>((ga, de, type, posi, type2, type3) => ga.Nation == type3.Code && type3.Type == "nation")
.Where(ga => ga.Werks == werks && ga.IdentityUserId != 0)
.Select((ga, de, type, posi, type2, type3) => new GainfoDetailResponse
{
No = ga.No,
SapNo = ga.SapNo,
Name = ga.Name,
Code = ga.Code,
DepartmentName = de.Name,
IdClass = ga.IdClass,
IdNo = ga.IdNo,
Gender = ga.Gender,
NativeName = type.Display,
Address = ga.Address,
Birthday = ga.Birthday,
Phone = ga.Phone,
Position = ga.Position,
Grade = posi.Grade,
Degree = ga.Degree,
Werks = ga.Werks,
CostId = ga.CostId,
Marital = ga.Marital,
CountryName = type2.Display,
NationName = type3.Display,
IsActive = ga.Employed == "Active" ? true : false,
}).ToPageListAsync(request);
return info;
}
//-------------------------------------------help methods ------------------------------------------------
/// <summary>
@@ -415,4 +590,31 @@ public class GainfoService : IGainfoService
}
}
}
/// <summary>
/// 解析token
/// </summary>
/// <param name="token"></param>
/// <param name="claimType"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
private string GetClaimValueFromToken(string token, string claimType)
{
try
{
var handler = new JwtSecurityTokenHandler();
var jsonToken = handler.ReadToken(token) as JwtSecurityToken;
if (jsonToken == null)
throw new Exception("Invalid JWT Token");
var claimValue = jsonToken.Claims.FirstOrDefault(c => c.Type == claimType)?.Value;
return claimValue;
}
catch (Exception ex)
{
return null;
}
}
}

View File

@@ -2,7 +2,7 @@
namespace Dlhis.ScheduledTask.SyncSapInfo.Services;
public interface IJinkoSapService : IScopeDependency
public interface IJinkoSapService : ISingletonDependency
{
Task<SapOrganizationResponse> GetSapOrganizationsAsync();

View File

@@ -1,4 +1,5 @@
using System.Text;
using System.Net.Http.Headers;
using System.Text;
using Dlhis.ScheduledTask.SyncSapInfo.Dto;
using Dlhis.ScheduledTask.SyncSapInfo.Response;
using Dlhis.Sys.Api;
@@ -8,22 +9,35 @@ namespace Dlhis.ScheduledTask.SyncSapInfo.Services.Implements;
public class JinkoSapService : IJinkoSapService
{
private readonly HttpClient _httpClient;
private readonly ILogger<JinkoSapService> _logger;
private readonly IHttpClientFactory _httpClientFactory;
private readonly ITenantApi _tenantApi;
public JinkoSapService(IHttpClientFactory httpClientFactory, ILogger<JinkoSapService> logger, ITenantApi tenantApi)
{
_httpClient = httpClientFactory.CreateClient("jinko:sap");
_logger = logger;
_httpClientFactory = httpClientFactory;
_tenantApi = tenantApi;
}
private HttpClient GetHttpClient()
{
var httpClient = _httpClientFactory.CreateClient("jinko:sap");
//http://sappidap.jinkosolar.cn:51000
httpClient.BaseAddress = new Uri("http://sappipap01.jinkosolar.cn:50100");
httpClient.Timeout = TimeSpan.FromMinutes(10);
var credentials = string.Format("{0}:{1}", "EHS_USER", "y3R1hd2h*RICAC");
var headerValue = Convert.ToBase64String(Encoding.UTF8.GetBytes(credentials));
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", headerValue);
return httpClient;
}
public async Task<SapOrganizationResponse> GetSapOrganizationsAsync()
{
string apiUrl = "http://sappidap.jinkosolar.cn:51000/RESTAdapter/Rest/EHR_ORGANIZATION/";
string apiUrl = "/RESTAdapter/Rest/EHR_ORGANIZATION/";
var response = await _httpClient.PostAsync(apiUrl, new StringContent("{}", Encoding.UTF8, "application/json"));
var response = await GetHttpClient().PostAsync(apiUrl, new StringContent("{}", Encoding.UTF8, "application/json"));
response.EnsureSuccessStatusCode();
string responseJson = await response.Content.ReadAsStringAsync();
@@ -34,9 +48,9 @@ public class JinkoSapService : IJinkoSapService
public async Task<SapPositionResponse> GetPositionsAsync()
{
string apiUrl = "http://sappidap.jinkosolar.cn:51000/RESTAdapter/Rest/EHR_POSITION/";
string apiUrl = "/RESTAdapter/Rest/EHR_POSITION/";
var response = await _httpClient.PostAsync(apiUrl, new StringContent("{}", Encoding.UTF8, "application/json"));
var response = await GetHttpClient().PostAsync(apiUrl, new StringContent("{}", Encoding.UTF8, "application/json"));
response.EnsureSuccessStatusCode();
string responseJson = await response.Content.ReadAsStringAsync();
@@ -48,7 +62,7 @@ public class JinkoSapService : IJinkoSapService
public async Task<SapPersonResponse> GetPersonsAsync()
{
var apiUrl = "http://sappipap01.jinkosolar.cn:50100/RESTAdapter/Rest/EHR_PERSONNEL/";
var apiUrl = "/RESTAdapter/Rest/EHR_PERSONNEL/";
var tenantResult = await _tenantApi.GetTenantsInternalAsync();
var tenants = tenantResult.Data;
@@ -75,7 +89,7 @@ public class JinkoSapService : IJinkoSapService
};
var content = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json");
var response = await _httpClient.PostAsync(apiUrl, content);
var response = await GetHttpClient().PostAsync(apiUrl, content);
response.EnsureSuccessStatusCode();
var jsonResponse = await response.Content.ReadAsStringAsync();

View File

@@ -9,7 +9,7 @@ public interface IMenuService : IScopeDependency
{
Task<List<MenuResponse>> GetListAsync(PlatformEnumType platform);
Task SaveMenuAsync(SaveMenuRequest request);
Task<string> SaveMenuAsync(SaveMenuRequest request);
Task AssignmentAsync(MenuPermissionAssignmentRequest request);

View File

@@ -42,7 +42,7 @@ public class MenuService : IMenuService
}
[Transactional]
public async Task SaveMenuAsync(SaveMenuRequest request)
public async Task<string> SaveMenuAsync(SaveMenuRequest request)
{
await CheckAsync(request);
@@ -50,6 +50,7 @@ public class MenuService : IMenuService
{
var entity = request.Adapt<MenuEntity>();
await _dbContext.InsertAsync(entity);
return entity.Code;
}
else
{
@@ -59,6 +60,7 @@ public class MenuService : IMenuService
request.Adapt(entity);
await _dbContext.UpdateAsync(entity);
return entity.Code;
}
}
@@ -187,8 +189,10 @@ public class MenuService : IMenuService
foreach (var item in request)
{
var code = await SaveMenuAsync(item);
if (item.Items?.Any() == true)
{
item.Items.ForEach(x => x.PCode = code);
await RecursionSaveNextAsync(item.Items);
}
}
@@ -198,9 +202,11 @@ public class MenuService : IMenuService
{
foreach (var item in menus)
{
await SaveMenuAsync(item);
var code = await SaveMenuAsync(item);
if (item.Items?.Any() == true)
{
item.Items.ForEach(x => x.PCode = code);
await RecursionSaveNextAsync(item.Items);
}
}
@@ -220,6 +226,7 @@ public class MenuService : IMenuService
private async Task CheckAsync(SaveMenuRequest request)
{
//检查重复code
var exists = await _dbContext.Queryable<MenuEntity>()
.Where(x => x.Code == request.Code)
@@ -247,7 +254,11 @@ public class MenuService : IMenuService
if (request.MenuType == MenuEnumType.Folder)
{
request.PCode = null;
//request.PCode = null;
if (string.IsNullOrEmpty(request.PCode))
{
request.PCode = null;
}
}
else if (request.MenuType == MenuEnumType.Menu)
{
@@ -299,4 +310,6 @@ public class MenuService : IMenuService
await _dbContext.UpdateAsync(permissions);
}
}
}