diff --git a/XPrint.Image/Tools/ChannelImageTool.cs b/XPrint.Image/Tools/ChannelImageTool.cs new file mode 100644 index 0000000..404ac87 --- /dev/null +++ b/XPrint.Image/Tools/ChannelImageTool.cs @@ -0,0 +1,178 @@ +using HPPH; +using ImageMagick; +using ImageMagick.Formats; +using Pipelines.Sockets.Unofficial.Arenas; +using SixLabors.ImageSharp.PixelFormats; +using System.Drawing; +using System.Drawing.Imaging; +using System.Text; +using System.Threading.Tasks; + +namespace XPrint.Image.Tools +{ + public class ChannelImageTool + { + + /// + /// 分色接口 + /// + /// 输入图片路径 + /// 输出图片路径 + /// icc名称 + /// icc文件路径 + public static void SplitColor(string inputPath, string outputPath, string iccProfilePath = "") + { + using (var image = new MagickImage(inputPath) + { + ColorSpace = ColorSpace.sRGB // 若需与 CMYK 工作流对接,改为 CMYK 并与源一致 + }) + { + //var profileBim1 = image.Get8BimProfile(); + //if (profileBim1 != null) + //{ + // var data = profileBim1.ToByteArray(); + // File.WriteAllBytes(@"D:\8bim_white_channel", data); + //} + + + // 配置大端字节序 + var writeSettings = new TiffWriteDefines(); + writeSettings.Endian = Endian.MSB;//大端模式,兼容性好些 + image.Alpha(AlphaOption.On); + image.MetaChannelCount = 0; + + ushort[] area; + var pixels = image.GetPixels(); + var areaAlpha = pixels.GetArea(0, 0, image.Width, image.Height)!; + + image.Alpha(AlphaOption.Off); + image.MetaChannelCount = 1; + + var pixels2 = image.GetPixels(); + + area = pixels2.GetArea(0, 0, image.Width, image.Height)!; + // 遍历每个像素,根据Alpha值设置White通道 + for (int i = 0; i < areaAlpha.Length; i += 4) + { + // 获取原始图像的Alpha值 + ushort alpha = areaAlpha[i + 3]; + + var r = area[i]; + var g = area[i + 1]; + var b = area[i + 2]; + + // 2. 计算白色墨量:通过RGB值计算灰度值(灰度越高,白色墨量越多) + // 公式:gray = 0.299*R + 0.587*G + 0.114*B(适配16位范围) + double grayValue = 0.299 * r + 0.587 * g + 0.114 * b; + ushort whiteInkAmount = (ushort)Math.Clamp(grayValue, 0, 65535); // 确保在0~65535范围内 + + // 3. 黑色填充深度 = 白色墨量(墨量越多,黑色越深) + // 将白色墨量直接映射到目标通道(i+4),值越高表示黑色越深 + area[i + 3] = whiteInkAmount; + } + + pixels2.SetPixels(area); + + + + string bimFileName = "8bim_white_channel"; + var bimData = File.ReadAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"assets/{bimFileName}")); + var profileBim = new EightBimProfile(image, bimData); + + //image.Alpha(AlphaOption.Remove); + profileBim.SetExifProfile(image.GetExifProfile()); + profileBim.SetIptcProfile(image.GetIptcProfile()); + profileBim.SetXmpProfile(image.GetXmpProfile()); + image.SetProfile(profileBim); + + profileBim.GetExifProfile()?.CreateThumbnail(); + + image.Settings.Compression = CompressionMethod.LZW; + image.SetCompression(CompressionMethod.LZW);//LZW压缩避免竖线问题 + //writeSettings.Alpha = TiffAlpha.Associated; + // 保存 + // 4. 保存结果 + image.Write(outputPath); + Console.WriteLine($"填充完成,结果已保存至:{outputPath}"); + //} + + //var profileBim = image.Get8BimProfile()!; + //profileBim.GetExifProfile()?.RemoveThumbnail(); + //File.WriteAllBytes(@$"D:\{bimFileName}", profileBim.ToByteArray()); + + //if (bimProfile != null) + //{ + // var exifProfile = bimProfile.GetExifProfile(); + // var xmpProfile = bimProfile.GetXmpProfile(); + // var iptcProfile = bimProfile.GetIptcProfile(); + + // profileBim.SetExifProfile(exifProfile); + // profileBim.SetIptcProfile(iptcProfile); + // profileBim.SetXmpProfile(xmpProfile); + //} + + + //image.Compose = CompositeOperator.Overlay; + + //var channelNames = new Dictionary + //{ + // { 0, "C" }, // 假设通道索引1对应红色 + // { 1, "M" }, + // { 2, "Y" }, + // { 3, "K" }, + // { 4, "A" }, + // { 5, "W" } + //}; + + //TiffModifier.RenameCustomChannels(@"D:\2.tiff", Path.Combine(Path.GetDirectoryName(outputPath)!, "3.tif"), channelNames); + // 创建包含 4 个自定义通道的图像 + //using (System.Drawing.Image imageA = new Bitmap(new MemoryStream(image.ToByteArray()))) + //{ + // var items = imageA.PropertyItems; + //} + } + } + + //private static string AddCustomXmpChannelName(string xmpXml, string channelName) + //{ + // // 注意:此方法需要根据实际 XMP 结构和命名空间调整 + // // 示例:添加自定义命名空间 "mychannel" + // if (!xmpXml.Contains("xmlns:mychannel")) + // { + // xmpXml = xmpXml.Replace("{channelName}"; + // int insertPos = xmpXml.IndexOf(""); + // if (insertPos > 0) + // { + // xmpXml = xmpXml.Insert(insertPos, channelProperty); + // } + + // return xmpXml; + //} + + + //public static void GenerateMultiPageCmykTiff(MagickImage[] imagePages, string outputPath) + //{ + // using (var images = new MagickImageCollection()) + // { + // for (int i = 0; i < imagePages.Length; i++) + // { + // //设置dpi + // //imagePages[i].Density = new Density(300.00, 300.00); + // images.Add(imagePages[i]); + // } + + + // // 配置大端字节序 + // var writeSettings = new WriteTiffBigEndianDefines(); + + // // 保存多页 + // images.Write(outputPath, writeSettings); + // } + //} + } +} diff --git a/XPrintServer.Admin.Api/Controllers/BackstageUserController.cs b/XPrintServer.Admin.Api/Controllers/BackstageUserController.cs index 41a6c84..2a39717 100644 --- a/XPrintServer.Admin.Api/Controllers/BackstageUserController.cs +++ b/XPrintServer.Admin.Api/Controllers/BackstageUserController.cs @@ -1,5 +1,6 @@ using CrazyStudio.Core.Common.CryptHelper; using CrazyStudio.Core.Common.Eitities; +using CrazyStudio.Core.Common.Eitities.Page; using CrazyStudio.Core.Common.JWT; using CrazyStudio.Core.Common.Tools; using Duende.IdentityModel; @@ -13,7 +14,7 @@ using XPrintServer.Business.Dto; using XPrintServer.Business.Services; using XPrintServer.DataModel.Models; -namespace XPrintServer.Api.Controllers +namespace XPrintServer.Admin.Api.Controllers { [Route("api/[controller]/[action]")] @@ -190,5 +191,23 @@ namespace XPrintServer.Api.Controllers { return true; } + + + + [HttpPost] + public async Task>> GetBackstageUserList([FromBody] PageData pageData) + { + try + { + var userList = await _backstatgeUserService.GetBackstageUserList(pageData); + return Ok(userList); + } + catch (Exception ex) + { + await _actionLogService.AddActionLog(new ActionLog { Title = "GetBackstageUserList Error", Content = ex.Message + " " + ex.StackTrace, DateTime = DateTime.Now }); + return StatusCode(500, ex.Message); + } + } + } } diff --git a/XPrintServer.Admin.Api/Controllers/MenuController.cs b/XPrintServer.Admin.Api/Controllers/MenuController.cs new file mode 100644 index 0000000..33b0ef9 --- /dev/null +++ b/XPrintServer.Admin.Api/Controllers/MenuController.cs @@ -0,0 +1,156 @@ +using CrazyStudio.Core.Common.Eitities.Page; +using Microsoft.AspNetCore.Mvc; +using StackExchange.Redis; +using XPrintServer.Business.Dto; +using XPrintServer.Business.Services; +using XPrintServer.DataModel.Models; + +namespace XPrintServer.Admin.Api.Controllers +{ + + [Route("api/[controller]/[action]")] + [ApiController] + public class MenuController : ControllerBase + { + + private readonly IHttpContextAccessor _httpContextAccessor; + private readonly MenuService _menuService; + private readonly UserMenuInRoleService _userMenuInRoleService; + private readonly ActionLogService _actionLogService; + + public MenuController(IHttpContextAccessor httpContextAccessor, MenuService menuService, UserMenuInRoleService userMenuInRoleService, ActionLogService actionLogService) + { + _httpContextAccessor = httpContextAccessor; + _menuService = menuService; + _userMenuInRoleService = userMenuInRoleService; + _actionLogService = actionLogService; + } + + [HttpPost] + public async Task AddOrUpdateMenu([FromBody] Menu menu) + { + try + { + await _menuService.AddOrUpdateMenu(menu); + return Ok(menu); + } + catch (Exception ex) + { + await _actionLogService.AddActionLog(new ActionLog { Title = "AddOrUpdateMenu Error", Content = ex.Message + " " + ex.StackTrace, DateTime = DateTime.Now }); + return StatusCode(500, ex.Message); + } + } + + + [HttpPost] + public async Task MenuList([FromBody] PageData pageData) + { + try + { + var menuList = await _menuService.GetMenuList(pageData, false); + return Ok(menuList); + } + catch (Exception ex) + { + await _actionLogService.AddActionLog(new ActionLog { Title = "MenuList Error", Content = ex.Message + " " + ex.StackTrace, DateTime = DateTime.Now }); + return StatusCode(500, ex.Message); + } + } + + [HttpPost] + public async Task>> AllMenuList() + { + try + { + var menuList = await _menuService.GetListAsync().ConfigureAwait(false); + List menuTreelist = menuList.ConvertAll(m => new MenuTreeData + { + Id = m.Id, + ComponentPath = m.ComponentPath, + MenuName = m.MenuName, + RouteName = m.RouteName, + ParentId = m.ParentId, + IsActive = m.IsActive + })!; + List removeList = new List(); + foreach (var menu in menuTreelist) + { + var parentMenu = menuTreelist.Find(m => m.Id == menu.ParentId); + if (parentMenu != null) + { + parentMenu.Children.Add(menu); + removeList.Add(menu); + } + } + foreach (var removeMenu in removeList) + { + menuTreelist.Remove(removeMenu); + } + + return Ok(menuTreelist); + } + catch (Exception ex) + { + await _actionLogService.AddActionLog(new ActionLog { Title = "AllMenuList Error", Content = ex.Message + " " + ex.StackTrace, DateTime = DateTime.Now }); + return StatusCode(500, ex.Message); + } + } + + [HttpPost] + public async Task ActiveMenuList([FromBody] PageData pageData) + { + try + { + var menuList = await _menuService.GetMenuList(pageData, true); + return Ok(menuList); + } + catch (Exception ex) + { + await _actionLogService.AddActionLog(new ActionLog { Title = "ActiveMenuList Error", Content = ex.Message + " " + ex.StackTrace, DateTime = DateTime.Now }); + return StatusCode(500, ex.Message); + } + } + + + [HttpPost] + public async Task MenuById([FromBody] Guid Id) + { + try + { + var menu = await _menuService.GetByIdAsync(Id).ConfigureAwait(false); + return Ok(menu); + } + catch (Exception ex) + { + await _actionLogService.AddActionLog(new ActionLog { Title = "MenuById Error", Content = ex.Message + " " + ex.StackTrace, DateTime = DateTime.Now }); + return StatusCode(500, ex.Message); + } + } + + + [HttpPost] + public async Task DeleteMenu([FromBody] Guid Id) + { + try + { + //ʼ + await _menuService.Context.Ado.BeginTranAsync(); + var isOK = await _menuService.DeleteByIdAsync(Id); + + var deleteDatas = await _userMenuInRoleService.Context.Queryable().Where(um => um.MenuId == Id).SplitTable().ToListAsync().ConfigureAwait(false); + await _userMenuInRoleService.Context.Deleteable(deleteDatas).SplitTable().ExecuteCommandAsync().ConfigureAwait(false); + + //ύ + await _menuService.Context.Ado.CommitTranAsync(); + return Ok(isOK); + } + catch (Exception ex) + { + //쳣ع + await _menuService.Context.Ado.RollbackTranAsync(); + await _actionLogService.AddActionLog(new ActionLog { Title = "DeleteMenu Error", Content = ex.Message + " " + ex.StackTrace, DateTime = DateTime.Now }); + return StatusCode(500, ex.Message); + } + } + } +} diff --git a/XPrintServer.Admin.Api/Controllers/RoleController.cs b/XPrintServer.Admin.Api/Controllers/RoleController.cs new file mode 100644 index 0000000..49e3cde --- /dev/null +++ b/XPrintServer.Admin.Api/Controllers/RoleController.cs @@ -0,0 +1,137 @@ +using CrazyStudio.Core.Common.Eitities.Page; +using Microsoft.AspNetCore.Mvc; +using XPrintServer.Business.Dto; +using XPrintServer.Business.Services; +using XPrintServer.DataModel.Models; + +namespace XPrintServer.Admin.Api.Controllers +{ + + [Route("api/[controller]/[action]")] + [ApiController] + public class RoleController : ControllerBase + { + + private readonly IHttpContextAccessor _httpContextAccessor; + private readonly RoleService _roleService; + private readonly UserMenuInRoleService _userMenuInRoleService; + private readonly ActionLogService _actionLogService; + + public RoleController(IHttpContextAccessor httpContextAccessor, RoleService roleService, UserMenuInRoleService userMenuInRoleService, ActionLogService actionLogService) + { + _httpContextAccessor = httpContextAccessor; + _roleService = roleService; + _userMenuInRoleService = userMenuInRoleService; + _actionLogService = actionLogService; + } + + [HttpPost] + public async Task AddOrUpdateRole([FromBody] RoleInfo roleInfo) + { + try + { + //ʼ + await _roleService.Context.Ado.BeginTranAsync(); + + await _roleService.AddOrUpdateRole(roleInfo.Role); + + await _userMenuInRoleService.AddOrUpdateUserMenuInRoles(roleInfo.Role.Id, roleInfo.MenuIds); + //ύ + await _roleService.Context.Ado.CommitTranAsync(); + return Ok(roleInfo.Role); + } + catch (Exception ex) + { + //쳣ع + await _roleService.Context.Ado.RollbackTranAsync(); + + await _actionLogService.AddActionLog(new ActionLog { Title = "AddOrUpdateRole Error", Content = ex.Message + " " + ex.StackTrace, DateTime = DateTime.Now }); + return StatusCode(500, ex.Message); + } + } + + + [HttpPost] + public async Task>> RoleList([FromBody] PageData pageData) + { + try + { + var roleList = await _roleService.GetRoleList(pageData); + return Ok(roleList); + } + catch (Exception ex) + { + await _actionLogService.AddActionLog(new ActionLog { Title = "RoleList Error", Content = ex.Message + " " + ex.StackTrace, DateTime = DateTime.Now }); + return StatusCode(500, ex.Message); + } + } + + [HttpPost] + public async Task>> AllRoleList() + { + try + { + var roleList = await _roleService.AllRoleList(); + return Ok(roleList); + } + catch (Exception ex) + { + await _actionLogService.AddActionLog(new ActionLog { Title = "AllRoleList Error", Content = ex.Message + " " + ex.StackTrace, DateTime = DateTime.Now }); + return StatusCode(500, ex.Message); + } + } + + [HttpPost] + public async Task RoleById([FromBody] Guid Id) + { + try + { + var role = await _roleService.GetByIdAsync(Id).ConfigureAwait(false); + return Ok(role); + } + catch (Exception ex) + { + await _actionLogService.AddActionLog(new ActionLog { Title = "RoleById Error", Content = ex.Message + " " + ex.StackTrace, DateTime = DateTime.Now }); + return StatusCode(500, ex.Message); + } + } + + [HttpPost] + public async Task>> RoleMenus([FromBody] Guid Id) + { + try + { + var roleMenus = await _userMenuInRoleService.SelectRoleUserMenuIdsInRoles(Id).ConfigureAwait(false); + return Ok(roleMenus); + } + catch (Exception ex) + { + await _actionLogService.AddActionLog(new ActionLog { Title = "RoleMenus Error", Content = ex.Message + " " + ex.StackTrace, DateTime = DateTime.Now }); + return StatusCode(500, ex.Message); + } + } + + + [HttpPost] + public async Task DeleteRole([FromBody] Guid Id) + { + try + { + //ʼ + await _roleService.Context.Ado.BeginTranAsync(); + var isOK = await _roleService.DeleteByIdAsync(Id); + await _userMenuInRoleService.DeleteRoleUserMenuInRoles(Id); + //ύ + await _roleService.Context.Ado.CommitTranAsync(); + return Ok(isOK); + } + catch (Exception ex) + { + //쳣ع + await _roleService.Context.Ado.RollbackTranAsync(); + await _actionLogService.AddActionLog(new ActionLog { Title = "DeleteRole Error", Content = ex.Message + " " + ex.StackTrace, DateTime = DateTime.Now }); + return StatusCode(500, ex.Message); + } + } + } +} diff --git a/XPrintServer.Admin.Api/Controllers/UserController.cs b/XPrintServer.Admin.Api/Controllers/UserController.cs index dc6bf1c..58fd087 100644 --- a/XPrintServer.Admin.Api/Controllers/UserController.cs +++ b/XPrintServer.Admin.Api/Controllers/UserController.cs @@ -8,7 +8,7 @@ using System.Text.Json; using System.Threading.Tasks; using File = System.IO.File; -namespace XPrintServer.Api.Controllers +namespace XPrintServer.Admin.Api.Controllers { [Route("api/[controller]/[action]")] diff --git a/XPrintServer.Api/Controllers/Common/OrderController.cs b/XPrintServer.Api/Controllers/Common/OrderController.cs index 031b992..fc30999 100644 --- a/XPrintServer.Api/Controllers/Common/OrderController.cs +++ b/XPrintServer.Api/Controllers/Common/OrderController.cs @@ -141,7 +141,7 @@ namespace XPrintServer.Api.Controllers.Common try { //ѯ12µ֧ - var isOK = await _orderService.BatchChangeOrderStatusToProductionFinish(orderIds); + var isOK = await _orderService.BatchChangeOrderStatusToProductionStatus(orderIds, OrderStatus.ProductionFinish); return Ok(isOK); } catch (Exception ex) diff --git a/XPrintServer.Api/Controllers/Common/OrderInfoController.cs b/XPrintServer.Api/Controllers/Common/OrderInfoController.cs index 4918bd4..5566518 100644 --- a/XPrintServer.Api/Controllers/Common/OrderInfoController.cs +++ b/XPrintServer.Api/Controllers/Common/OrderInfoController.cs @@ -38,9 +38,15 @@ namespace XPrintServer.Api.Controllers.Common { try { - var now = DateTime.Now; - //ѯ12µ֧ - var infoResult = await _orderInfoService.GetOrderInfoListForTime(pageData, now.AddMonths(-12), now); + //var now = DateTime.Now; + //if (pageData.StartTime == null) + //{ + // pageData.StartTime = now.AddDays(-7); + // pageData.EndTime = now; + //} + + //ѯһڵ֧ + var infoResult = await _orderInfoService.GetOrderInfoListForTime(pageData, pageData.StartTime, pageData.EndTime); return Ok(infoResult); } catch (Exception ex) @@ -64,8 +70,36 @@ namespace XPrintServer.Api.Controllers.Common //ʼ await _orderService.Context.Ado.BeginTranAsync(); //ѯ12µ֧ - var finishOrderIds = await _orderInfoService.BatchChangeOrderInfoStatusToProductionFinish(orderInfoIds); - bool isOK = await _orderService.BatchChangeOrderStatusToProductionFinish(finishOrderIds); + var finishOrderIds = await _orderInfoService.BatchChangeOrderInfoStatusToProductionFinish(orderInfoIds, ResourceStatus.ProductionFinish); + bool isOK = await _orderService.BatchChangeOrderStatusToProductionStatus(finishOrderIds, OrderStatus.ProductionFinish); + + //ύ + await _orderService.Context.Ado.CommitTranAsync(); + return Ok(isOK); + } + catch (Exception ex) + { + await _orderService.Context.Ado.RollbackTranAsync(); + await _actionLogService.AddActionLog(new ActionLog { Title = "ProductionBatchFinish Error", Content = ex.Message + " " + ex.StackTrace, DateTime = DateTime.Now }); + return StatusCode(500, ex.Message); + } + } + + /// + /// Դ״̬Ϊ + /// + /// + /// + [HttpPost] + public async Task> ProductionBatchDelete([FromBody] HashSet orderInfoIds) + { + try + { + //ʼ + await _orderService.Context.Ado.BeginTranAsync(); + //ѯ֧ + var finishOrderIds = await _orderInfoService.BatchChangeOrderInfoStatusToProductionFinish(orderInfoIds, ResourceStatus.Delete); + bool isOK = await _orderService.BatchChangeOrderStatusToProductionStatus(finishOrderIds, OrderStatus.ProductionFinish); //ύ await _orderService.Context.Ado.CommitTranAsync(); diff --git a/XPrintServer.Api/Controllers/WeatherForecastController.cs b/XPrintServer.Api/Controllers/WeatherForecastController.cs index 1f3e753..894526f 100644 --- a/XPrintServer.Api/Controllers/WeatherForecastController.cs +++ b/XPrintServer.Api/Controllers/WeatherForecastController.cs @@ -39,7 +39,7 @@ namespace XPrintServer.Api.Controllers public void TestImage() { //SvgTool.ImageToSvg(); - //CmykImageTool.SplitColor(@"D:\ն.png", @"D:\նOutput.tif"); + ChannelImageTool.SplitColor(@"D:\.tif", @"D:\111.tif"); } } } diff --git a/XPrintServer.Api/XPrintServer.Api.csproj b/XPrintServer.Api/XPrintServer.Api.csproj index 5369064..9201381 100644 --- a/XPrintServer.Api/XPrintServer.Api.csproj +++ b/XPrintServer.Api/XPrintServer.Api.csproj @@ -25,6 +25,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/XPrintServer.Api/assets/8bim_white_channel b/XPrintServer.Api/assets/8bim_white_channel new file mode 100644 index 0000000..c44c5d3 Binary files /dev/null and b/XPrintServer.Api/assets/8bim_white_channel differ diff --git a/XPrintServer.Business/Dto/MenuTreeData.cs b/XPrintServer.Business/Dto/MenuTreeData.cs new file mode 100644 index 0000000..101be52 --- /dev/null +++ b/XPrintServer.Business/Dto/MenuTreeData.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using XPrintServer.DataModel.Models; + +namespace XPrintServer.Business.Dto +{ + public class MenuTreeData : Menu + { + public List Children { get; set; } = new List(); + } +} diff --git a/XPrintServer.Business/Dto/RoleInfo.cs b/XPrintServer.Business/Dto/RoleInfo.cs new file mode 100644 index 0000000..e563677 --- /dev/null +++ b/XPrintServer.Business/Dto/RoleInfo.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using XPrintServer.DataModel.Models; + +namespace XPrintServer.Business.Dto +{ + public class RoleInfo + { + public Role Role { get; set; } = null!; + + public List MenuIds { get; set; } = new List(); + } +} diff --git a/XPrintServer.Business/Enums/PageOrderStatusData.cs b/XPrintServer.Business/Enums/PageOrderStatusData.cs index 56f25f5..75720b4 100644 --- a/XPrintServer.Business/Enums/PageOrderStatusData.cs +++ b/XPrintServer.Business/Enums/PageOrderStatusData.cs @@ -13,5 +13,9 @@ namespace XPrintServer.Business.Enums /// 订单状态 /// public OrderStatus Status { get; set; } = OrderStatus.None; + + public DateTime? StartTime { get; set; } = null; + + public DateTime? EndTime { get; set; } = null; } } diff --git a/XPrintServer.Business/Services/BackstatgeUserService.cs b/XPrintServer.Business/Services/BackstatgeUserService.cs index a3d81eb..690ab46 100644 --- a/XPrintServer.Business/Services/BackstatgeUserService.cs +++ b/XPrintServer.Business/Services/BackstatgeUserService.cs @@ -1,4 +1,5 @@ -using SqlSugar; +using CrazyStudio.Core.Common.Eitities.Page; +using SqlSugar; using System; using System.Collections.Generic; using System.Linq; @@ -45,5 +46,18 @@ namespace XPrintServer.Business.Services } return dbUser; } + + public async Task> GetBackstageUserList(PageData pageData) + { + var userList = await Context.Queryable().WhereIF(!string.IsNullOrEmpty(pageData.SearchText), bu => bu.UserName.Contains(pageData.SearchText) + || bu.NickName == null ? false : bu.NickName.Contains(pageData.SearchText)).SplitTable() + .ToPageListAsync(pageData.Page, pageData.PageSize).ConfigureAwait(false); + return new PageResult + { + Data = userList, + PageSize = pageData.PageSize, + Total = await Context.Queryable().SplitTable().CountAsync().ConfigureAwait(false) + }; + } } } diff --git a/XPrintServer.Business/Services/MenuService.cs b/XPrintServer.Business/Services/MenuService.cs new file mode 100644 index 0000000..2390057 --- /dev/null +++ b/XPrintServer.Business/Services/MenuService.cs @@ -0,0 +1,56 @@ +using CrazyStudio.Core.Common.Eitities.Page; +using CrazyStudio.Core.Common.Tools.Extensions; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using XPrintServer.Business.Services.Interface; +using XPrintServer.DataModel; +using XPrintServer.DataModel.Models; + +namespace XPrintServer.Business.Services +{ + public class MenuService : SqlSugarRepository, IBusinessService + { + public MenuService(ConnectionConfig config) : base(config) + { + } + + public async Task AddOrUpdateMenu(Menu menu) + { + if (menu.ParentId.IsNullOrGuidEmpty()) + { + menu.ParentId = null; + } + + if (menu.Id.IsNullOrGuidEmpty()) + { + await Context.Insertable(menu).ExecuteCommandAsync().ConfigureAwait(false); + } + else + { + await Context.Updateable(menu).ExecuteCommandAsync().ConfigureAwait(false); + } + } + + public async Task> GetMenuList(PageData pageData, bool isCheckActive) + { + var menuList = await Context.Queryable().WhereIF(isCheckActive, m => m.IsActive) + .ToPageListAsync(pageData.Page, pageData.PageSize).ConfigureAwait(false); + return new PageResult + { + Data = menuList, + PageSize = pageData.PageSize, + Total = await Context.Queryable().WhereIF(isCheckActive, m => m.IsActive).CountAsync().ConfigureAwait(false) + }; + } + + public async Task GetMenu(Guid Id) + { + var menu = await Context.Queryable().Where(m => m.Id == Id).FirstAsync().ConfigureAwait(false); + return menu; + } + } +} diff --git a/XPrintServer.Business/Services/OrderInfoService.cs b/XPrintServer.Business/Services/OrderInfoService.cs index 4e8b969..d148bba 100644 --- a/XPrintServer.Business/Services/OrderInfoService.cs +++ b/XPrintServer.Business/Services/OrderInfoService.cs @@ -68,7 +68,13 @@ namespace XPrintServer.Business.Services //infoQuery = infoQuery.InnerJoin(orderQuery, (info, order) => info.OrderId == order.Id); - var infoList = await infoQuery!.Where(i => i.ResourceStatus == (int)ResourceStatus.WaitProduction).Select(info => info).OrderByDescending(info => info.SubmitTime).ToPageListAsync(pageData.Page, pageData.PageSize).ConfigureAwait(false); + var infoList = await infoQuery! + + .WhereIF(pageData.StartTime != null, i => i.SubmitTime >= pageData.StartTime) + .WhereIF(pageData.EndTime != null, i => i.SubmitTime <= pageData.EndTime) + .Where(i => i.ResourceStatus != (int)ResourceStatus.Delete) + + .Select(info => info).OrderByDescending(info => info.SubmitTime).ToPageListAsync(pageData.Page, pageData.PageSize).ConfigureAwait(false); return new PageResult { Data = infoList, @@ -101,21 +107,21 @@ namespace XPrintServer.Business.Services /// - /// 批量更改支付资源状态为已生产完成 + /// 批量更改支付资源状态为已指定状态 /// /// 返回全部资源生产完成的订单 /// - public async Task> BatchChangeOrderInfoStatusToProductionFinish(HashSet orderInfoIds) + public async Task> BatchChangeOrderInfoStatusToProductionFinish(HashSet orderInfoIds, ResourceStatus resourceStatus = ResourceStatus.ProductionFinish) { var orderInfos = await Context.Queryable().Where(o => orderInfoIds.Contains(o.Id)).SplitTable().ToListAsync().ConfigureAwait(false); - + HashSet orderIds = new HashSet(); for (int i = 0; i < orderInfos.Count; i++) { var info = orderInfos[i]; - if (info.ResourceStatus == (int)ResourceStatus.WaitProduction || info.ResourceStatus == (int)OrderStatus.InProduction)//order.OrderStatus == (int)OrderStatus.Unpaid Debug + if (info.ResourceStatus == (int)ResourceStatus.WaitProduction || info.ResourceStatus == (int)OrderStatus.InProduction || info.ResourceStatus == (int)OrderStatus.ProductionFinish)//order.OrderStatus == (int)OrderStatus.Unpaid Debug { - info.ResourceStatus = (int)ResourceStatus.ProductionFinish; + info.ResourceStatus = (int)resourceStatus; if (!orderIds.Contains(info.OrderId)) { orderIds.Add(info.OrderId); diff --git a/XPrintServer.Business/Services/OrderService.cs b/XPrintServer.Business/Services/OrderService.cs index 9384935..8c056a6 100644 --- a/XPrintServer.Business/Services/OrderService.cs +++ b/XPrintServer.Business/Services/OrderService.cs @@ -43,7 +43,7 @@ namespace XPrintServer.Business.Services /// /// /// - public async Task BatchChangeOrderStatusToProductionFinish(HashSet orderIds) + public async Task BatchChangeOrderStatusToProductionStatus(HashSet orderIds, OrderStatus orderStatus) { var orders = await Context.Queryable().Where(o => orderIds.Contains(o.Id)).SplitTable().ToListAsync().ConfigureAwait(false); bool isOK = false; @@ -54,7 +54,7 @@ namespace XPrintServer.Business.Services var order = orders[i]; if (order.OrderStatus == (int)OrderStatus.Paid || order.OrderStatus == (int)OrderStatus.Unpaid)//order.OrderStatus == (int)OrderStatus.Unpaid Debug { - order.OrderStatus = (int)OrderStatus.ProductionFinish; + order.OrderStatus = (int)orderStatus; isOK = true; } } diff --git a/XPrintServer.Business/Services/RoleService.cs b/XPrintServer.Business/Services/RoleService.cs new file mode 100644 index 0000000..ddda519 --- /dev/null +++ b/XPrintServer.Business/Services/RoleService.cs @@ -0,0 +1,58 @@ +using CrazyStudio.Core.Common.Eitities.Page; +using CrazyStudio.Core.Common.Tools.Extensions; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using XPrintServer.Business.Services.Interface; +using XPrintServer.DataModel; +using XPrintServer.DataModel.Models; + +namespace XPrintServer.Business.Services +{ + public class RoleService : SqlSugarRepository, IBusinessService + { + public RoleService(ConnectionConfig config) : base(config) + { + } + + public async Task AddOrUpdateRole(Role role) + { + if (role.Id.IsNullOrGuidEmpty()) + { + await Context.Insertable(role).ExecuteCommandAsync().ConfigureAwait(false); + } + else + { + await Context.Updateable(role).ExecuteCommandAsync().ConfigureAwait(false); + } + } + + public async Task> GetRoleList(PageData pageData) + { + var roleList = await Context.Queryable() + .ToPageListAsync(pageData.Page, pageData.PageSize).ConfigureAwait(false); + return new PageResult + { + Data = roleList, + PageSize = pageData.PageSize, + Total = await Context.Queryable().CountAsync().ConfigureAwait(false) + }; + } + + public async Task> AllRoleList() + { + var roleList = await Context.Queryable() + .ToListAsync().ConfigureAwait(false); + return roleList; + } + + public async Task GetRole(Guid Id) + { + var role = await Context.Queryable().Where(m => m.Id == Id).FirstAsync().ConfigureAwait(false); + return role; + } + } +} diff --git a/XPrintServer.Business/Services/UserMenuInRoleService.cs b/XPrintServer.Business/Services/UserMenuInRoleService.cs new file mode 100644 index 0000000..c222faa --- /dev/null +++ b/XPrintServer.Business/Services/UserMenuInRoleService.cs @@ -0,0 +1,63 @@ +using CrazyStudio.Core.Common.Tools.Extensions; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using XPrintServer.Business.Services.Interface; +using XPrintServer.DataModel; +using XPrintServer.DataModel.Models; + +namespace XPrintServer.Business.Services +{ + public class UserMenuInRoleService : SqlSugarRepository, IBusinessService + { + public UserMenuInRoleService(ConnectionConfig config) : base(config) + { + } + + + public async Task AddOrUpdateUserMenuInRoles(Guid roleId, List menuIds) + { + if (!roleId.IsNullOrGuidEmpty()) + { + await DeleteRoleUserMenuInRoles(roleId); + if (menuIds.Any()) + { + List addList = new List(); + DateTime now = DateTime.Now; + foreach (var menuId in menuIds) + { + addList.Add(new UserMenuInRole + { + RoleId = roleId, + CreateTime = now, + MenuId = menuId + }); + } + await Context.Insertable(addList).SplitTable().ExecuteCommandAsync().ConfigureAwait(false); + } + } + } + + public async Task DeleteRoleUserMenuInRoles(Guid roleId) + { + if (!roleId.IsNullOrGuidEmpty()) + { + var deleteDatas = await Context.Queryable().Where(r => r.RoleId == roleId).SplitTable().ToListAsync().ConfigureAwait(false); + await Context.Deleteable(deleteDatas).SplitTable().ExecuteCommandAsync().ConfigureAwait(false); + } + } + + public async Task> SelectRoleUserMenuIdsInRoles(Guid roleId) + { + if (!roleId.IsNullOrGuidEmpty()) + { + var menuIds = await Context.Queryable().Where(r => r.RoleId == roleId).SplitTable().Select(r => r.MenuId).ToListAsync().ConfigureAwait(false); + return menuIds; + } + return new List(); + } + } +} diff --git a/XPrintServer.Business/Workflows/Workflow.cs b/XPrintServer.Business/Workflows/Workflow.cs index e83ecaa..b03eb68 100644 --- a/XPrintServer.Business/Workflows/Workflow.cs +++ b/XPrintServer.Business/Workflows/Workflow.cs @@ -38,7 +38,7 @@ namespace XPrintServer.Business.Workflows // // 1. 加载工作流JSON文件 // workflowJson = File.ReadAllText(_createImageworkflowPath); //} - if (string.IsNullOrWhiteSpace(workflowJson)) + if (string.IsNullOrWhiteSpace(workflowJson) && !string.IsNullOrWhiteSpace(workflowPath)) { workflowJson = File.ReadAllText(workflowPath); } diff --git a/XPrintServer.DataModel/Models/BackstageUser.cs b/XPrintServer.DataModel/Models/BackstageUser.cs index 4d78070..0190c4a 100644 --- a/XPrintServer.DataModel/Models/BackstageUser.cs +++ b/XPrintServer.DataModel/Models/BackstageUser.cs @@ -33,7 +33,7 @@ namespace XPrintServer.DataModel.Models /// /// Desc:用户名 /// Default: - /// Nullable:True + /// Nullable:False /// [Key("UserName")] [SugarColumn(IsNullable = false, ColumnDescription = "用户名")] @@ -42,7 +42,7 @@ namespace XPrintServer.DataModel.Models /// /// Desc:Password /// Default: - /// Nullable:True + /// Nullable:False /// [Key("Password")] [SugarColumn(IsNullable = false, ColumnDescription = "用户密码")] diff --git a/XPrintServer.DataModel/Models/Menu.cs b/XPrintServer.DataModel/Models/Menu.cs index 280c2f6..15dce27 100644 --- a/XPrintServer.DataModel/Models/Menu.cs +++ b/XPrintServer.DataModel/Models/Menu.cs @@ -1,4 +1,5 @@ using SqlSugar; +using StackExchange.Redis; using System; using System.Collections.Generic; using System.Linq; @@ -10,6 +11,8 @@ namespace XPrintServer.DataModel.Models /// /// 菜单表 /// + [SugarIndex("idx_ids", nameof(ParentId), OrderByType.Desc)] + [SugarIndex("idx_menu_name", nameof(MenuName), OrderByType.Desc)] //[SplitTable(SplitType.Year)]//按年分表 (自带分表支持 年、季、月、周、日) //[SugarTable("menu_{year}{month}{day}")]//3个变量必须要有,这么设计为了兼容开始按年,后面改成按月、按日 public class Menu @@ -22,17 +25,44 @@ namespace XPrintServer.DataModel.Models [SugarColumn(IsPrimaryKey = true, ColumnDescription = "主键Id")] public Guid Id { get; set; } - [SugarColumn(IsNullable = true, ColumnDescription = "父级Id,Null则为顶级菜单")] + [SugarColumn(IsNullable = true, DefaultValue = null, ColumnDescription = "父级Id,Null则为顶级菜单")] public Guid? ParentId { get; set; } = null; /// - /// Desc:用户名 + /// Desc:菜单名称 /// Default: /// Nullable:False /// - [SugarColumn(IsNullable = false, ColumnDescription = "菜单名")] + [SugarColumn(IsNullable = false, ColumnDescription = "菜单名称")] public string MenuName { get; set; } = null!; + + /// + /// Desc:路由名称 + /// Default: + /// Nullable:False + /// + [SugarColumn(IsNullable = false, ColumnDescription = "路由名称")] + public string RouteName { get; set; } = null!; + + + /// + /// Desc:组件路径 + /// Default: + /// Nullable:False + /// + [SugarColumn(IsNullable = false, ColumnDescription = "组件路径")] + public string ComponentPath { get; set; } = null!; + + + /// + /// Desc:是否启用 + /// Default: + /// Nullable:False + /// + [SugarColumn(IsNullable = false, ColumnDescription = "是否启用")] + public bool IsActive { get; set; } = false; + ///// ///// 分表字段 在插入的时候会根据这个字段插入哪个表,在更新删除的时候用这个字段找出相关表 ///// diff --git a/XPrintServer.DataModel/Models/Model.cs b/XPrintServer.DataModel/Models/Model.cs index 54c9e3f..f036e00 100644 --- a/XPrintServer.DataModel/Models/Model.cs +++ b/XPrintServer.DataModel/Models/Model.cs @@ -58,6 +58,15 @@ namespace XPrintServer.DataModel.Models public string? ModelPictureUrl { get; set; } = null; + /// + /// Desc:模型场景Y坐标偏移值 + /// Nullable:False + /// + [Key("OffsetY")] + [SugarColumn(IsNullable = false, DefaultValue = "0", ColumnDescription = "模型场景Y坐标偏移值")] + public float OffsetY { get; set; } = 0f; + + /// /// Desc:摄像头最小可视范围 /// Nullable:False diff --git a/XPrintServer.DataModel/Models/Role.cs b/XPrintServer.DataModel/Models/Role.cs index 5009a81..b5a8001 100644 --- a/XPrintServer.DataModel/Models/Role.cs +++ b/XPrintServer.DataModel/Models/Role.cs @@ -11,6 +11,7 @@ namespace XPrintServer.DataModel.Models /// ///角色表 /// + [SugarIndex("idx_role_name", nameof(RoleName), OrderByType.Desc)] //[SplitTable(SplitType.Year)]//按年分表 (自带分表支持 年、季、月、周、日) //[SugarTable("role_{year}{month}{day}")]//3个变量必须要有,这么设计为了兼容开始按年,后面改成按月、按日 public partial class Role diff --git a/XPrintServer.DataModel/Models/UserMenuInRole.cs b/XPrintServer.DataModel/Models/UserMenuInRole.cs index bc54280..cea52cb 100644 --- a/XPrintServer.DataModel/Models/UserMenuInRole.cs +++ b/XPrintServer.DataModel/Models/UserMenuInRole.cs @@ -11,6 +11,8 @@ namespace XPrintServer.DataModel.Models /// ///用户角色的菜单表 /// + [SugarIndex("idx_{split_table}_create_time", nameof(CreateTime), OrderByType.Desc)] + [SugarIndex("idx_{split_table}_ids", [nameof(MenuId), nameof(RoleId)], [OrderByType.Desc, OrderByType.Desc])] [SplitTable(SplitType.Year)]//按年分表 (自带分表支持 年、季、月、周、日) [SugarTable("user_menu_in_role_{year}{month}{day}")]//3个变量必须要有,这么设计为了兼容开始按年,后面改成按月、按日 public partial class UserMenuInRole