Commit b11f42efa83ee8ae35aead90facf8898ae7e2098

Authored by 杨鑫
1 parent 28fa41e9

修改

Showing 17 changed files with 95 additions and 351 deletions
美国版/Food Labeling Management App UniApp/src/utils/labelPreview/normalizePreviewTemplate.ts
1 import type { SystemLabelTemplate, SystemTemplateElementBase } from '../print/types/printer' 1 import type { SystemLabelTemplate, SystemTemplateElementBase } from '../print/types/printer'
2 -import { normalizePrintOrientation } from '../print/printOrientation'  
3 import { 2 import {
4 applyLiveDateTimeFieldsToTemplate, 3 applyLiveDateTimeFieldsToTemplate,
5 resolveTemplateDefaultValueForElement, 4 resolveTemplateDefaultValueForElement,
@@ -428,6 +427,11 @@ function pickTemplateRootRecord (payload: Record<string, unknown>): Record<strin @@ -428,6 +427,11 @@ function pickTemplateRootRecord (payload: Record<string, unknown>): Record<strin
428 return payload 427 return payload
429 } 428 }
430 429
  430 +export function normalizeTemplatePrintOrientation(raw: unknown): 'horizontal' | 'vertical' {
  431 + const v = String(raw ?? '').trim().toLowerCase()
  432 + return v === 'horizontal' ? 'horizontal' : 'vertical'
  433 +}
  434 +
431 /** 435 /**
432 * 将接口 8.2 返回的 template(或整段 DTO)规范为 SystemLabelTemplate,供打印适配器与预览画布使用。 436 * 将接口 8.2 返回的 template(或整段 DTO)规范为 SystemLabelTemplate,供打印适配器与预览画布使用。
433 */ 437 */
@@ -493,7 +497,9 @@ export function normalizeLabelTemplateFromPreviewApi(payload: unknown): SystemLa @@ -493,7 +497,9 @@ export function normalizeLabelTemplateFromPreviewApi(payload: unknown): SystemLa
493 showRuler: !!(t.showRuler ?? t.ShowRuler), 497 showRuler: !!(t.showRuler ?? t.ShowRuler),
494 showGrid: !!(t.showGrid ?? t.ShowGrid), 498 showGrid: !!(t.showGrid ?? t.ShowGrid),
495 border: String(t.border ?? t.Border ?? t.BorderType ?? t.borderType ?? 'none'), 499 border: String(t.border ?? t.Border ?? t.BorderType ?? t.borderType ?? 'none'),
496 - printOrientation: normalizePrintOrientation(t.printOrientation ?? t.PrintOrientation), 500 + printOrientation: normalizeTemplatePrintOrientation(
  501 + t.printOrientation ?? t.PrintOrientation,
  502 + ),
497 elements, 503 elements,
498 } 504 }
499 } 505 }
美国版/Food Labeling Management App UniApp/src/utils/labelPreview/renderLabelPreviewCanvas.ts
1 import type { RawImageDataSource, SystemLabelTemplate, SystemTemplateElementBase } from '../print/types/printer' 1 import type { RawImageDataSource, SystemLabelTemplate, SystemTemplateElementBase } from '../print/types/printer'
2 -import { applyPrintOrientationCanvasTransform, normalizePrintOrientation } from '../print/printOrientation'  
3 import { resolveMediaUrlForApp, storedValueLooksLikeImagePath } from '../resolveMediaUrl' 2 import { resolveMediaUrlForApp, storedValueLooksLikeImagePath } from '../resolveMediaUrl'
4 -import { sortElementsForPreview } from './normalizePreviewTemplate' 3 +import { sortElementsForPreview, normalizeTemplatePrintOrientation } from './normalizePreviewTemplate'
5 import { resolveElementDateTimeDisplay } from './printInputOffset' 4 import { resolveElementDateTimeDisplay } from './printInputOffset'
6 import { getLoggedInEmployeeDisplayName, isEmployeeTemplateElement } from './employeeElement' 5 import { getLoggedInEmployeeDisplayName, isEmployeeTemplateElement } from './employeeElement'
7 import QRCode from 'qrcode' 6 import QRCode from 'qrcode'
@@ -403,6 +402,15 @@ function strokeTemplatePaperBorder ( @@ -403,6 +402,15 @@ function strokeTemplatePaperBorder (
403 } 402 }
404 } 403 }
405 404
  405 +/** 横打:与 Web printContentLayerStyle rotate(90deg) 一致,纸张尺寸不变 */
  406 +function applyPrintContentRotation(ctx: UniApp.CanvasContext, cw: number, ch: number): void {
  407 + const cx = cw / 2
  408 + const cy = ch / 2
  409 + ctx.translate(cx, cy)
  410 + ctx.rotate(Math.PI / 2)
  411 + ctx.translate(-cx, -cy)
  412 +}
  413 +
406 /** 与屏幕预览 / 位图打印共用绘制逻辑(坐标系:设计宽 cw × ch,ctx 已 scale) */ 414 /** 与屏幕预览 / 位图打印共用绘制逻辑(坐标系:设计宽 cw × ch,ctx 已 scale) */
407 function runLabelPreviewCanvasDraw( 415 function runLabelPreviewCanvasDraw(
408 canvasId: string, 416 canvasId: string,
@@ -413,24 +421,24 @@ function runLabelPreviewCanvasDraw( @@ -413,24 +421,24 @@ function runLabelPreviewCanvasDraw(
413 scale: number 421 scale: number
414 ): Promise<void> { 422 ): Promise<void> {
415 const sorted = sortElementsForPreview(template.elements || []) 423 const sorted = sortElementsForPreview(template.elements || [])
416 - const printOrientation = normalizePrintOrientation(template.printOrientation) 424 + const rotateContent = normalizeTemplatePrintOrientation(template.printOrientation) === 'horizontal'
417 425
418 return new Promise((resolve) => { 426 return new Promise((resolve) => {
419 const ctx = uni.createCanvasContext(canvasId, componentInstance) 427 const ctx = uni.createCanvasContext(canvasId, componentInstance)
420 ctx.setFillStyle('#ffffff') 428 ctx.setFillStyle('#ffffff')
421 ctx.scale(scale, scale) 429 ctx.scale(scale, scale)
422 ctx.fillRect(0, 0, cw, ch) 430 ctx.fillRect(0, 0, cw, ch)
423 -  
424 - const rotated = printOrientation === 'horizontal'  
425 - if (rotated) { 431 + if (rotateContent) {
426 ctx.save() 432 ctx.save()
427 - applyPrintOrientationCanvasTransform(ctx, cw, ch, printOrientation) 433 + applyPrintContentRotation(ctx, cw, ch)
428 } 434 }
429 435
430 const drawRest = (index: number) => { 436 const drawRest = (index: number) => {
431 if (index >= sorted.length) { 437 if (index >= sorted.length) {
  438 + if (rotateContent) {
  439 + ctx.restore()
  440 + }
432 strokeTemplatePaperBorder(ctx, template, cw, ch) 441 strokeTemplatePaperBorder(ctx, template, cw, ch)
433 - if (rotated) ctx.restore()  
434 ctx.draw(false, () => resolve()) 442 ctx.draw(false, () => resolve())
435 return 443 return
436 } 444 }
美国版/Food Labeling Management App UniApp/src/utils/print/printOrientation.ts deleted
1 -export type PrintOrientation = 'horizontal' | 'vertical'  
2 -  
3 -/** 与 Web normalizePrintOrientation 一致:默认竖打 */  
4 -export function normalizePrintOrientation(raw: unknown): PrintOrientation {  
5 - const v = String(raw ?? '').trim().toLowerCase()  
6 - return v === 'horizontal' ? 'horizontal' : 'vertical'  
7 -}  
8 -  
9 -/** 横打时内容相对纸张旋转 90°(纸张 W×H 不变) */  
10 -export function shouldRotatePrintContent(orientation: PrintOrientation): boolean {  
11 - return orientation === 'horizontal'  
12 -}  
13 -  
14 -/** 在 canvas 上应用模板级打印方向(与 Web printContentLayerStyle 一致) */  
15 -export function applyPrintOrientationCanvasTransform(  
16 - ctx: UniApp.CanvasContext,  
17 - cw: number,  
18 - ch: number,  
19 - orientation: PrintOrientation,  
20 -): void {  
21 - if (!shouldRotatePrintContent(orientation)) return  
22 - ctx.translate(cw / 2, ch / 2)  
23 - ctx.rotate(Math.PI / 2)  
24 - ctx.translate(-cw / 2, -ch / 2)  
25 -}  
美国版/Food Labeling Management App UniApp/src/utils/print/types/printer.ts
@@ -63,8 +63,8 @@ export type LabelTemplateValue = string | number @@ -63,8 +63,8 @@ export type LabelTemplateValue = string | number
63 export type LabelTemplateData = Record<string, LabelTemplateValue> 63 export type LabelTemplateData = Record<string, LabelTemplateValue>
64 export type PrinterTemplateUnit = 'inch' | 'mm' | 'cm' | 'px' 64 export type PrinterTemplateUnit = 'inch' | 'mm' | 'cm' | 'px'
65 export type SystemTemplateRotation = 'horizontal' | 'vertical' 65 export type SystemTemplateRotation = 'horizontal' | 'vertical'
  66 +export type SystemTemplatePrintOrientation = 'horizontal' | 'vertical'
66 export type SystemTemplateTextAlign = 'left' | 'center' | 'right' 67 export type SystemTemplateTextAlign = 'left' | 'center' | 'right'
67 -export type PrintOrientation = 'horizontal' | 'vertical'  
68 68
69 export interface SystemTemplateElementBase { 69 export interface SystemTemplateElementBase {
70 id: string 70 id: string
@@ -94,8 +94,8 @@ export interface SystemLabelTemplate { @@ -94,8 +94,8 @@ export interface SystemLabelTemplate {
94 showGrid?: boolean 94 showGrid?: boolean
95 /** 整标签外框:none / line / dotted */ 95 /** 整标签外框:none / line / dotted */
96 border?: string 96 border?: string
97 - /** 模板打印方向:horizontal=横打(内容旋转90°),vertical=竖打(默认) */  
98 - printOrientation?: PrintOrientation 97 + /** vertical=竖打(默认);horizontal=横打(内容整体旋转 90°,纸张 W×H 不变) */
  98 + printOrientation?: SystemTemplatePrintOrientation
99 elements: SystemTemplateElementBase[] 99 elements: SystemTemplateElementBase[]
100 } 100 }
101 101
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/Label/LabelTemplatePreviewDto.cs
@@ -40,10 +40,6 @@ public class LabelTemplatePreviewDto @@ -40,10 +40,6 @@ public class LabelTemplatePreviewDto
40 [JsonPropertyName("border")] 40 [JsonPropertyName("border")]
41 public string Border { get; set; } = "none"; 41 public string Border { get; set; } = "none";
42 42
43 - /// <summary>打印方向:vertical / horizontal</summary>  
44 - [JsonPropertyName("printOrientation")]  
45 - public string PrintOrientation { get; set; } = "vertical";  
46 -  
47 [JsonPropertyName("elements")] 43 [JsonPropertyName("elements")]
48 public List<LabelTemplateElementDto> Elements { get; set; } = new(); 44 public List<LabelTemplateElementDto> Elements { get; set; } = new();
49 } 45 }
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelTemplate/LabelTemplateCreateInputVo.cs
@@ -60,10 +60,6 @@ public class LabelTemplateCreateInputVo @@ -60,10 +60,6 @@ public class LabelTemplateCreateInputVo
60 [JsonPropertyName("border")] 60 [JsonPropertyName("border")]
61 public string BorderType { get; set; } = "none"; 61 public string BorderType { get; set; } = "none";
62 62
63 - /// <summary>打印方向:vertical / horizontal</summary>  
64 - [JsonPropertyName("printOrientation")]  
65 - public string PrintOrientationType { get; set; } = "vertical";  
66 -  
67 /// <summary> 63 /// <summary>
68 /// 预留:前端可能不传;如果不传则默认 true 64 /// 预留:前端可能不传;如果不传则默认 true
69 /// </summary> 65 /// </summary>
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelTemplate/LabelTemplateGetOutputDto.cs
@@ -34,10 +34,6 @@ public class LabelTemplateGetOutputDto @@ -34,10 +34,6 @@ public class LabelTemplateGetOutputDto
34 [JsonPropertyName("border")] 34 [JsonPropertyName("border")]
35 public string BorderType { get; set; } = "none"; 35 public string BorderType { get; set; } = "none";
36 36
37 - /// <summary>打印方向:vertical / horizontal</summary>  
38 - [JsonPropertyName("printOrientation")]  
39 - public string PrintOrientationType { get; set; } = "vertical";  
40 -  
41 public int VersionNo { get; set; } 37 public int VersionNo { get; set; }
42 38
43 public bool State { get; set; } 39 public bool State { get; set; }
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/ReportsPrintLogDailyLabelIdHelper.cs
1 -using System.Globalization;  
2 using FoodLabeling.Application.Services.DbModels; 1 using FoodLabeling.Application.Services.DbModels;
3 using SqlSugar; 2 using SqlSugar;
4 3
@@ -129,88 +128,6 @@ public static class ReportsPrintLogDailyLabelIdHelper @@ -129,88 +128,6 @@ public static class ReportsPrintLogDailyLabelIdHelper
129 return result; 128 return result;
130 } 129 }
131 130
132 - /// <summary>  
133 - /// App Print Log 单日筛选:解析 <paramref name="printDate"/> / <paramref name="printDateDay"/> 为服务器本地自然日。  
134 - /// 两者均未传时返回 null(不按日过滤,兼容 App 未传 printDate 的历史行为)。  
135 - /// </summary>  
136 - public static DateTime? ResolvePrintLogFilterCalendarDay(DateTime? printDate, string? printDateDay)  
137 - {  
138 - var text = printDateDay?.Trim();  
139 - if (!string.IsNullOrWhiteSpace(text))  
140 - {  
141 - if (DateTime.TryParseExact(  
142 - text,  
143 - "yyyy-MM-dd",  
144 - CultureInfo.InvariantCulture,  
145 - DateTimeStyles.None,  
146 - out var parsedExact))  
147 - {  
148 - return parsedExact.Date;  
149 - }  
150 -  
151 - if (DateTime.TryParse(  
152 - text,  
153 - CultureInfo.InvariantCulture,  
154 - DateTimeStyles.AllowWhiteSpaces,  
155 - out var parsed))  
156 - {  
157 - return parsed.Date;  
158 - }  
159 -  
160 - throw new Volo.Abp.UserFriendlyException("printDate 格式不正确,请使用 yyyy-MM-dd");  
161 - }  
162 -  
163 - if (!printDate.HasValue)  
164 - {  
165 - return null;  
166 - }  
167 -  
168 - var value = printDate.Value;  
169 - return value.Kind == DateTimeKind.Utc ? value.ToLocalTime().Date : value.Date;  
170 - }  
171 -  
172 - /// <summary>  
173 - /// 按自然日过滤打印任务(MySQL <c>DATE(IFNULL(PrintedAt, CreationTime))</c>,避免 DateTime 区间比较时区偏差)。  
174 - /// </summary>  
175 - public static ISugarQueryable<FlLabelPrintTaskDbEntity> ApplyPrintTaskCalendarDayFilter(  
176 - ISugarQueryable<FlLabelPrintTaskDbEntity> query,  
177 - DateTime filterDay)  
178 - {  
179 - var dayText = filterDay.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);  
180 - return query.Where("DATE(IFNULL(PrintedAt, CreationTime)) = @filterDay", new { filterDay = dayText });  
181 - }  
182 -  
183 - /// <summary>  
184 - /// 多表 Join 查询按自然日过滤(首表别名 <c>t</c>)。  
185 - /// </summary>  
186 - public static ISugarQueryable<FlLabelPrintTaskDbEntity, T2> ApplyPrintTaskCalendarDayFilter<T2>(  
187 - ISugarQueryable<FlLabelPrintTaskDbEntity, T2> query,  
188 - DateTime filterDay)  
189 - {  
190 - var dayText = filterDay.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);  
191 - return query.Where("DATE(IFNULL(t.PrintedAt, t.CreationTime)) = @filterDay", new { filterDay = dayText });  
192 - }  
193 -  
194 - /// <summary>  
195 - /// 五表 Join(首表别名 <c>t</c>)。  
196 - /// </summary>  
197 - public static ISugarQueryable<FlLabelPrintTaskDbEntity, T2, T3, T4, T5> ApplyPrintTaskCalendarDayFilter<T2, T3, T4, T5>(  
198 - ISugarQueryable<FlLabelPrintTaskDbEntity, T2, T3, T4, T5> query,  
199 - DateTime filterDay)  
200 - {  
201 - var dayText = filterDay.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);  
202 - return query.Where("DATE(IFNULL(t.PrintedAt, t.CreationTime)) = @filterDay", new { filterDay = dayText });  
203 - }  
204 -  
205 - /// <summary>  
206 - /// App Print Log 单日筛选:<c>printDate</c> 的自然日区间;未传则默认服务器当天。  
207 - /// </summary>  
208 - public static (DateTime dayStart, DateTime dayEndExcl) ResolvePrintLogFilterDayRange(DateTime? printDate)  
209 - {  
210 - var day = ResolvePrintLogFilterCalendarDay(printDate, null) ?? DateTime.Today;  
211 - return (day, day.AddDays(1));  
212 - }  
213 -  
214 public readonly struct PrintTaskScopeKey 131 public readonly struct PrintTaskScopeKey
215 { 132 {
216 public PrintTaskScopeKey(string taskId, string? locationId, DateTime printedAt) 133 public PrintTaskScopeKey(string taskId, string? locationId, DateTime printedAt)
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/DbModels/FlLabelTemplateDbEntity.cs
@@ -34,6 +34,12 @@ public class FlLabelTemplateDbEntity @@ -34,6 +34,12 @@ public class FlLabelTemplateDbEntity
34 34
35 public string AppliedLocationType { get; set; } = "ALL"; 35 public string AppliedLocationType { get; set; } = "ALL";
36 36
  37 + /// <summary>适用 Company 范围:ALL / SPECIFIED(见 fl_label_template_partner)</summary>
  38 + public string AppliedPartnerType { get; set; } = "ALL";
  39 +
  40 + /// <summary>适用 Region 范围:ALL / SPECIFIED(见 fl_label_template_region)</summary>
  41 + public string AppliedRegionType { get; set; } = "ALL";
  42 +
37 public bool ShowRuler { get; set; } 43 public bool ShowRuler { get; set; }
38 44
39 public bool ShowGrid { get; set; } 45 public bool ShowGrid { get; set; }
@@ -41,10 +47,8 @@ public class FlLabelTemplateDbEntity @@ -41,10 +47,8 @@ public class FlLabelTemplateDbEntity
41 /// <summary>整标签外框:none / line / dotted</summary> 47 /// <summary>整标签外框:none / line / dotted</summary>
42 public string BorderType { get; set; } = "none"; 48 public string BorderType { get; set; } = "none";
43 49
44 - /// <summary>打印方向:vertical=竖打(默认),horizontal=横打(内容旋转90°,纸张尺寸不变)</summary>  
45 - public string PrintOrientationType { get; set; } = "vertical";  
46 -  
47 public int VersionNo { get; set; } 50 public int VersionNo { get; set; }
48 51
49 public bool State { get; set; } 52 public bool State { get; set; }
50 } 53 }
  54 +
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelAppService.cs
@@ -298,8 +298,7 @@ public class LabelAppService : ApplicationService, ILabelAppService @@ -298,8 +298,7 @@ public class LabelAppService : ApplicationService, ILabelAppService
298 throw new UserFriendlyException("标签不存在"); 298 throw new UserFriendlyException("标签不存在");
299 } 299 }
300 300
301 - var template = await LabelTemplateQueryHelper.ProjectListColumns(  
302 - _dbContext.SqlSugarClient.Queryable<FlLabelTemplateDbEntity>()) 301 + var template = await _dbContext.SqlSugarClient.Queryable<FlLabelTemplateDbEntity>()
303 .FirstAsync(x => x.Id == label.TemplateId); 302 .FirstAsync(x => x.Id == label.TemplateId);
304 var category = await _dbContext.SqlSugarClient.Queryable<FlLabelCategoryDbEntity>() 303 var category = await _dbContext.SqlSugarClient.Queryable<FlLabelCategoryDbEntity>()
305 .FirstAsync(x => x.Id == label.LabelCategoryId); 304 .FirstAsync(x => x.Id == label.LabelCategoryId);
@@ -405,8 +404,7 @@ public class LabelAppService : ApplicationService, ILabelAppService @@ -405,8 +404,7 @@ public class LabelAppService : ApplicationService, ILabelAppService
405 input.LocationId, 404 input.LocationId,
406 input.LocationIds); 405 input.LocationIds);
407 406
408 - var template = await LabelTemplateQueryHelper.ProjectListColumns(  
409 - _dbContext.SqlSugarClient.Queryable<FlLabelTemplateDbEntity>()) 407 + var template = await _dbContext.SqlSugarClient.Queryable<FlLabelTemplateDbEntity>()
410 .FirstAsync(x => !x.IsDeleted && x.TemplateCode == input.TemplateCode.Trim()); 408 .FirstAsync(x => !x.IsDeleted && x.TemplateCode == input.TemplateCode.Trim());
411 if (template is null) 409 if (template is null)
412 { 410 {
@@ -522,8 +520,7 @@ public class LabelAppService : ApplicationService, ILabelAppService @@ -522,8 +520,7 @@ public class LabelAppService : ApplicationService, ILabelAppService
522 input.LocationId, 520 input.LocationId,
523 input.LocationIds); 521 input.LocationIds);
524 522
525 - var template = await LabelTemplateQueryHelper.ProjectListColumns(  
526 - _dbContext.SqlSugarClient.Queryable<FlLabelTemplateDbEntity>()) 523 + var template = await _dbContext.SqlSugarClient.Queryable<FlLabelTemplateDbEntity>()
527 .FirstAsync(x => !x.IsDeleted && x.TemplateCode == input.TemplateCode.Trim()); 524 .FirstAsync(x => !x.IsDeleted && x.TemplateCode == input.TemplateCode.Trim());
528 if (template is null) 525 if (template is null)
529 { 526 {
@@ -674,8 +671,7 @@ public class LabelAppService : ApplicationService, ILabelAppService @@ -674,8 +671,7 @@ public class LabelAppService : ApplicationService, ILabelAppService
674 } 671 }
675 672
676 // 取模板头 & elements 673 // 取模板头 & elements
677 - var template = await LabelTemplateQueryHelper.ProjectListColumns(  
678 - _dbContext.SqlSugarClient.Queryable<FlLabelTemplateDbEntity>()) 674 + var template = await _dbContext.SqlSugarClient.Queryable<FlLabelTemplateDbEntity>()
679 .FirstAsync(x => !x.IsDeleted && x.Id == label.TemplateId); 675 .FirstAsync(x => !x.IsDeleted && x.Id == label.TemplateId);
680 if (template is null) 676 if (template is null)
681 { 677 {
@@ -898,22 +894,9 @@ public class LabelAppService : ApplicationService, ILabelAppService @@ -898,22 +894,9 @@ public class LabelAppService : ApplicationService, ILabelAppService
898 ShowRuler = template.ShowRuler, 894 ShowRuler = template.ShowRuler,
899 ShowGrid = template.ShowGrid, 895 ShowGrid = template.ShowGrid,
900 Border = NormalizeTemplateBorderType(template.BorderType), 896 Border = NormalizeTemplateBorderType(template.BorderType),
901 - PrintOrientation = NormalizePrintOrientationType(template.PrintOrientationType),  
902 Elements = resolvedElements 897 Elements = resolvedElements
903 }; 898 };
904 } 899 }
905 900
906 - private static string NormalizeTemplateBorderType(string? raw)  
907 - {  
908 - var v = (raw ?? string.Empty).Trim().ToLowerInvariant();  
909 - return v is "line" or "dotted" ? v : "none";  
910 - }  
911 -  
912 - private static string NormalizePrintOrientationType(string? raw)  
913 - {  
914 - var v = (raw ?? string.Empty).Trim().ToLowerInvariant();  
915 - return v == "horizontal" ? "horizontal" : "vertical";  
916 - }  
917 -  
918 } 901 }
919 902
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelTemplateAppService.cs
@@ -29,11 +29,10 @@ public class LabelTemplateAppService : ApplicationService, ILabelTemplateAppServ @@ -29,11 +29,10 @@ public class LabelTemplateAppService : ApplicationService, ILabelTemplateAppServ
29 29
30 public async Task<PagedResultWithPageDto<LabelTemplateGetListOutputDto>> GetListAsync(LabelTemplateGetListInputVo input) 30 public async Task<PagedResultWithPageDto<LabelTemplateGetListOutputDto>> GetListAsync(LabelTemplateGetListInputVo input)
31 { 31 {
32 - input ??= new LabelTemplateGetListInputVo();  
33 RefAsync<int> total = 0; 32 RefAsync<int> total = 0;
34 var keyword = input.Keyword?.Trim(); 33 var keyword = input.Keyword?.Trim();
35 - var scopedLocationIds = await LocationScopeBindingHelper.ResolveFilteredLocationIdsForListAsync(  
36 - _dbContext.SqlSugarClient, input.PartnerId, input.GroupId, input.LocationId); 34 + var scopedLocationIds = await LocationScopeBindingHelper.ResolveScopedLocationIdsAsync(
  35 + _dbContext.SqlSugarClient, input.GroupId, input.LocationId);
37 36
38 var query = _dbContext.SqlSugarClient.Queryable<FlLabelTemplateDbEntity>() 37 var query = _dbContext.SqlSugarClient.Queryable<FlLabelTemplateDbEntity>()
39 .Where(x => !x.IsDeleted) 38 .Where(x => !x.IsDeleted)
@@ -45,30 +44,25 @@ public class LabelTemplateAppService : ApplicationService, ILabelTemplateAppServ @@ -45,30 +44,25 @@ public class LabelTemplateAppService : ApplicationService, ILabelTemplateAppServ
45 query = await LabelTemplateScopeHelper.ApplyTemplateScopeFilterAsync( 44 query = await LabelTemplateScopeHelper.ApplyTemplateScopeFilterAsync(
46 _dbContext.SqlSugarClient, query, scopedLocationIds); 45 _dbContext.SqlSugarClient, query, scopedLocationIds);
47 46
48 - query = ApplyLabelTemplateListSorting(query, input.Sorting);  
49 - query = LabelTemplateQueryHelper.ProjectListColumns(query); 47 + query = !string.IsNullOrWhiteSpace(input.Sorting)
  48 + ? query.OrderBy(input.Sorting)
  49 + : query.OrderByDescending(x => x.LastModificationTime ?? x.CreationTime);
50 50
51 - var pageSize = input.MaxResultCount <= 0 ? 10 : input.MaxResultCount;  
52 - var pageEntities = await query.ToPageListAsync(input.SkipCount, pageSize, total); 51 + var pageEntities = await query.ToPageListAsync(input.SkipCount, input.MaxResultCount, total);
53 var templateIds = pageEntities.Select(x => x.Id).ToList(); 52 var templateIds = pageEntities.Select(x => x.Id).ToList();
54 53
55 - var elementCountMap = new Dictionary<string, int>(StringComparer.Ordinal);  
56 - if (templateIds.Count > 0)  
57 - {  
58 - var elementCounts = await _dbContext.SqlSugarClient.Queryable<FlLabelTemplateElementDbEntity>()  
59 - .Where(x => templateIds.Contains(x.TemplateId))  
60 - .GroupBy(x => x.TemplateId)  
61 - .Select(x => new { TemplateId = x.TemplateId, Count = SqlFunc.AggregateCount(x.Id) })  
62 - .ToListAsync();  
63 - elementCountMap = elementCounts.ToDictionary(x => x.TemplateId, x => (int)x.Count);  
64 - } 54 + // element count (Contents)
  55 + var elementCounts = await _dbContext.SqlSugarClient.Queryable<FlLabelTemplateElementDbEntity>()
  56 + .Where(x => templateIds.Contains(x.TemplateId))
  57 + .GroupBy(x => x.TemplateId)
  58 + .Select(x => new { TemplateId = x.TemplateId, Count = SqlFunc.AggregateCount(x.Id) })
  59 + .ToListAsync();
  60 + var elementCountMap = elementCounts.ToDictionary(x => x.TemplateId, x => (int)x.Count);
65 61
66 var scopeMap = await LabelTemplateScopeHelper.BuildScopeDisplayMapAsync( 62 var scopeMap = await LabelTemplateScopeHelper.BuildScopeDisplayMapAsync(
67 _dbContext.SqlSugarClient, pageEntities); 63 _dbContext.SqlSugarClient, pageEntities);
68 - var itemsMap = templateIds.Count > 0  
69 - ? await LabelTemplateListItemsHelper.ResolveTemplateItemsMapAsync(  
70 - _dbContext.SqlSugarClient, templateIds)  
71 - : new Dictionary<string, LabelTemplateListItemsHelper.TemplateItemsDisplay>(StringComparer.Ordinal); 64 + var itemsMap = await LabelTemplateListItemsHelper.ResolveTemplateItemsMapAsync(
  65 + _dbContext.SqlSugarClient, templateIds);
72 66
73 var items = pageEntities.Select(x => 67 var items = pageEntities.Select(x =>
74 { 68 {
@@ -103,69 +97,12 @@ public class LabelTemplateAppService : ApplicationService, ILabelTemplateAppServ @@ -103,69 +97,12 @@ public class LabelTemplateAppService : ApplicationService, ILabelTemplateAppServ
103 }; 97 };
104 }).ToList(); 98 }).ToList();
105 99
106 - return BuildPagedResult(input.SkipCount, pageSize, total, items);  
107 - }  
108 -  
109 - /// <summary>  
110 - /// 列表排序:白名单字段 + IFNULL(LastModificationTime, CreationTime),避免 <c>??</c> 与原始 Sorting 拼接导致 SQL 异常。  
111 - /// </summary>  
112 - private static ISugarQueryable<FlLabelTemplateDbEntity> ApplyLabelTemplateListSorting(  
113 - ISugarQueryable<FlLabelTemplateDbEntity> query,  
114 - string? sorting)  
115 - {  
116 - if (!string.IsNullOrWhiteSpace(sorting))  
117 - {  
118 - var s = sorting.Trim();  
119 - if (s.Equals("TemplateName asc", StringComparison.OrdinalIgnoreCase))  
120 - {  
121 - return query.OrderBy(x => x.TemplateName);  
122 - }  
123 -  
124 - if (s.Equals("TemplateName desc", StringComparison.OrdinalIgnoreCase))  
125 - {  
126 - return query.OrderByDescending(x => x.TemplateName);  
127 - }  
128 -  
129 - if (s.Equals("TemplateCode asc", StringComparison.OrdinalIgnoreCase))  
130 - {  
131 - return query.OrderBy(x => x.TemplateCode);  
132 - }  
133 -  
134 - if (s.Equals("TemplateCode desc", StringComparison.OrdinalIgnoreCase))  
135 - {  
136 - return query.OrderByDescending(x => x.TemplateCode);  
137 - }  
138 -  
139 - if (s.Equals("CreationTime asc", StringComparison.OrdinalIgnoreCase))  
140 - {  
141 - return query.OrderBy(x => x.CreationTime);  
142 - }  
143 -  
144 - if (s.Equals("CreationTime desc", StringComparison.OrdinalIgnoreCase))  
145 - {  
146 - return query.OrderByDescending(x => x.CreationTime);  
147 - }  
148 -  
149 - if (s.Equals("LastModificationTime asc", StringComparison.OrdinalIgnoreCase))  
150 - {  
151 - return query.OrderBy(x => x.LastModificationTime);  
152 - }  
153 -  
154 - if (s.Equals("LastModificationTime desc", StringComparison.OrdinalIgnoreCase))  
155 - {  
156 - return query.OrderByDescending(x => x.LastModificationTime);  
157 - }  
158 - }  
159 -  
160 - return query  
161 - .OrderBy(x => SqlFunc.IsNull(x.LastModificationTime, x.CreationTime), OrderByType.Desc)  
162 - .OrderBy(x => x.TemplateCode, OrderByType.Asc); 100 + return BuildPagedResult(input.SkipCount, input.MaxResultCount, total, items);
163 } 101 }
164 102
165 public async Task<LabelTemplateGetOutputDto> GetAsync(string id) 103 public async Task<LabelTemplateGetOutputDto> GetAsync(string id)
166 { 104 {
167 - var template = await LabelTemplateQueryHelper.ProjectListColumns(  
168 - _dbContext.SqlSugarClient.Queryable<FlLabelTemplateDbEntity>()) 105 + var template = await _dbContext.SqlSugarClient.Queryable<FlLabelTemplateDbEntity>()
169 .FirstAsync(x => !x.IsDeleted && x.TemplateCode == id); 106 .FirstAsync(x => !x.IsDeleted && x.TemplateCode == id);
170 if (template is null) 107 if (template is null)
171 { 108 {
@@ -243,12 +180,11 @@ public class LabelTemplateAppService : ApplicationService, ILabelTemplateAppServ @@ -243,12 +180,11 @@ public class LabelTemplateAppService : ApplicationService, ILabelTemplateAppServ
243 Width = template.Width, 180 Width = template.Width,
244 Height = template.Height, 181 Height = template.Height,
245 AppliedLocationType = template.AppliedLocationType, 182 AppliedLocationType = template.AppliedLocationType,
246 - AppliedPartnerType = LabelTemplateScopeHelper.ScopeAll,  
247 - AppliedRegionType = LabelTemplateScopeHelper.ScopeAll, 183 + AppliedPartnerType = template.AppliedPartnerType,
  184 + AppliedRegionType = template.AppliedRegionType,
248 ShowRuler = template.ShowRuler, 185 ShowRuler = template.ShowRuler,
249 ShowGrid = template.ShowGrid, 186 ShowGrid = template.ShowGrid,
250 BorderType = NormalizeTemplateBorderType(template.BorderType), 187 BorderType = NormalizeTemplateBorderType(template.BorderType),
251 - PrintOrientationType = NormalizePrintOrientationType(template.PrintOrientationType),  
252 VersionNo = template.VersionNo, 188 VersionNo = template.VersionNo,
253 State = template.State, 189 State = template.State,
254 Elements = MapElements(), 190 Elements = MapElements(),
@@ -273,8 +209,7 @@ public class LabelTemplateAppService : ApplicationService, ILabelTemplateAppServ @@ -273,8 +209,7 @@ public class LabelTemplateAppService : ApplicationService, ILabelTemplateAppServ
273 throw new UserFriendlyException("模板名称不能为空"); 209 throw new UserFriendlyException("模板名称不能为空");
274 } 210 }
275 211
276 - var duplicated = await LabelTemplateQueryHelper.ProjectListColumns(  
277 - _dbContext.SqlSugarClient.Queryable<FlLabelTemplateDbEntity>()) 212 + var duplicated = await _dbContext.SqlSugarClient.Queryable<FlLabelTemplateDbEntity>()
278 .AnyAsync(x => !x.IsDeleted && x.TemplateCode == code); 213 .AnyAsync(x => !x.IsDeleted && x.TemplateCode == code);
279 if (duplicated) 214 if (duplicated)
280 { 215 {
@@ -301,10 +236,11 @@ public class LabelTemplateAppService : ApplicationService, ILabelTemplateAppServ @@ -301,10 +236,11 @@ public class LabelTemplateAppService : ApplicationService, ILabelTemplateAppServ
301 Width = input.Width, 236 Width = input.Width,
302 Height = input.Height, 237 Height = input.Height,
303 AppliedLocationType = scope.AppliedLocationType, 238 AppliedLocationType = scope.AppliedLocationType,
  239 + AppliedPartnerType = scope.AppliedPartnerType,
  240 + AppliedRegionType = scope.AppliedRegionType,
304 ShowRuler = input.ShowRuler, 241 ShowRuler = input.ShowRuler,
305 ShowGrid = input.ShowGrid, 242 ShowGrid = input.ShowGrid,
306 BorderType = NormalizeTemplateBorderType(input.BorderType), 243 BorderType = NormalizeTemplateBorderType(input.BorderType),
307 - PrintOrientationType = NormalizePrintOrientationType(input.PrintOrientationType),  
308 VersionNo = 1, 244 VersionNo = 1,
309 State = input.State 245 State = input.State
310 }; 246 };
@@ -324,20 +260,13 @@ public class LabelTemplateAppService : ApplicationService, ILabelTemplateAppServ @@ -324,20 +260,13 @@ public class LabelTemplateAppService : ApplicationService, ILabelTemplateAppServ
324 CurrentUser?.Id?.ToString(), 260 CurrentUser?.Id?.ToString(),
325 now); 261 now);
326 262
327 - await LabelTemplateScopeSchemaHelper.SetAppliedScopeTypesAsync(  
328 - _dbContext.SqlSugarClient,  
329 - entity.Id,  
330 - scope.AppliedPartnerType,  
331 - scope.AppliedRegionType);  
332 -  
333 return await GetAsync(code); 263 return await GetAsync(code);
334 } 264 }
335 265
336 [UnitOfWork] 266 [UnitOfWork]
337 public async Task<LabelTemplateGetOutputDto> UpdateAsync(string id, LabelTemplateUpdateInputVo input) 267 public async Task<LabelTemplateGetOutputDto> UpdateAsync(string id, LabelTemplateUpdateInputVo input)
338 { 268 {
339 - var template = await LabelTemplateQueryHelper.ProjectListColumns(  
340 - _dbContext.SqlSugarClient.Queryable<FlLabelTemplateDbEntity>()) 269 + var template = await _dbContext.SqlSugarClient.Queryable<FlLabelTemplateDbEntity>()
341 .FirstAsync(x => !x.IsDeleted && x.TemplateCode == id); 270 .FirstAsync(x => !x.IsDeleted && x.TemplateCode == id);
342 if (template is null) 271 if (template is null)
343 { 272 {
@@ -348,8 +277,7 @@ public class LabelTemplateAppService : ApplicationService, ILabelTemplateAppServ @@ -348,8 +277,7 @@ public class LabelTemplateAppService : ApplicationService, ILabelTemplateAppServ
348 var name = input.TemplateName?.Trim(); 277 var name = input.TemplateName?.Trim();
349 if (!string.IsNullOrWhiteSpace(code) && !string.Equals(code, template.TemplateCode, StringComparison.OrdinalIgnoreCase)) 278 if (!string.IsNullOrWhiteSpace(code) && !string.Equals(code, template.TemplateCode, StringComparison.OrdinalIgnoreCase))
350 { 279 {
351 - var duplicated = await LabelTemplateQueryHelper.ProjectListColumns(  
352 - _dbContext.SqlSugarClient.Queryable<FlLabelTemplateDbEntity>()) 280 + var duplicated = await _dbContext.SqlSugarClient.Queryable<FlLabelTemplateDbEntity>()
353 .AnyAsync(x => !x.IsDeleted && x.TemplateCode == code); 281 .AnyAsync(x => !x.IsDeleted && x.TemplateCode == code);
354 if (duplicated) 282 if (duplicated)
355 { 283 {
@@ -365,10 +293,11 @@ public class LabelTemplateAppService : ApplicationService, ILabelTemplateAppServ @@ -365,10 +293,11 @@ public class LabelTemplateAppService : ApplicationService, ILabelTemplateAppServ
365 template.Width = input.Width; 293 template.Width = input.Width;
366 template.Height = input.Height; 294 template.Height = input.Height;
367 template.AppliedLocationType = scope.AppliedLocationType; 295 template.AppliedLocationType = scope.AppliedLocationType;
  296 + template.AppliedPartnerType = scope.AppliedPartnerType;
  297 + template.AppliedRegionType = scope.AppliedRegionType;
368 template.ShowRuler = input.ShowRuler; 298 template.ShowRuler = input.ShowRuler;
369 template.ShowGrid = input.ShowGrid; 299 template.ShowGrid = input.ShowGrid;
370 template.BorderType = NormalizeTemplateBorderType(input.BorderType); 300 template.BorderType = NormalizeTemplateBorderType(input.BorderType);
371 - template.PrintOrientationType = NormalizePrintOrientationType(input.PrintOrientationType);  
372 template.State = input.State; 301 template.State = input.State;
373 template.VersionNo = template.VersionNo + 1; 302 template.VersionNo = template.VersionNo + 1;
374 template.LastModifierId = CurrentUser?.Id?.ToString(); 303 template.LastModifierId = CurrentUser?.Id?.ToString();
@@ -393,20 +322,13 @@ public class LabelTemplateAppService : ApplicationService, ILabelTemplateAppServ @@ -393,20 +322,13 @@ public class LabelTemplateAppService : ApplicationService, ILabelTemplateAppServ
393 CurrentUser?.Id?.ToString(), 322 CurrentUser?.Id?.ToString(),
394 template.LastModificationTime ?? DateTime.Now); 323 template.LastModificationTime ?? DateTime.Now);
395 324
396 - await LabelTemplateScopeSchemaHelper.SetAppliedScopeTypesAsync(  
397 - _dbContext.SqlSugarClient,  
398 - template.Id,  
399 - scope.AppliedPartnerType,  
400 - scope.AppliedRegionType);  
401 -  
402 return await GetAsync(template.TemplateCode); 325 return await GetAsync(template.TemplateCode);
403 } 326 }
404 327
405 [UnitOfWork] 328 [UnitOfWork]
406 public async Task DeleteAsync(string id) 329 public async Task DeleteAsync(string id)
407 { 330 {
408 - var template = await LabelTemplateQueryHelper.ProjectListColumns(  
409 - _dbContext.SqlSugarClient.Queryable<FlLabelTemplateDbEntity>()) 331 + var template = await _dbContext.SqlSugarClient.Queryable<FlLabelTemplateDbEntity>()
410 .FirstAsync(x => !x.IsDeleted && x.TemplateCode == id); 332 .FirstAsync(x => !x.IsDeleted && x.TemplateCode == id);
411 if (template is null) 333 if (template is null)
412 { 334 {
@@ -433,15 +355,12 @@ public class LabelTemplateAppService : ApplicationService, ILabelTemplateAppServ @@ -433,15 +355,12 @@ public class LabelTemplateAppService : ApplicationService, ILabelTemplateAppServ
433 await _dbContext.SqlSugarClient.Deleteable<FlLabelTemplateLocationDbEntity>() 355 await _dbContext.SqlSugarClient.Deleteable<FlLabelTemplateLocationDbEntity>()
434 .Where(x => x.TemplateId == template.Id) 356 .Where(x => x.TemplateId == template.Id)
435 .ExecuteCommandAsync(); 357 .ExecuteCommandAsync();
436 - if (await LabelTemplateScopeSchemaHelper.HasPartnerRegionScopeTablesAsync(_dbContext.SqlSugarClient))  
437 - {  
438 - await _dbContext.SqlSugarClient.Deleteable<FlLabelTemplatePartnerDbEntity>()  
439 - .Where(x => x.TemplateId == template.Id)  
440 - .ExecuteCommandAsync();  
441 - await _dbContext.SqlSugarClient.Deleteable<FlLabelTemplateRegionDbEntity>()  
442 - .Where(x => x.TemplateId == template.Id)  
443 - .ExecuteCommandAsync();  
444 - } 358 + await _dbContext.SqlSugarClient.Deleteable<FlLabelTemplatePartnerDbEntity>()
  359 + .Where(x => x.TemplateId == template.Id)
  360 + .ExecuteCommandAsync();
  361 + await _dbContext.SqlSugarClient.Deleteable<FlLabelTemplateRegionDbEntity>()
  362 + .Where(x => x.TemplateId == template.Id)
  363 + .ExecuteCommandAsync();
445 await _dbContext.SqlSugarClient.Deleteable<FlLabelTemplateProductDefaultDbEntity>() 364 await _dbContext.SqlSugarClient.Deleteable<FlLabelTemplateProductDefaultDbEntity>()
446 .Where(x => x.TemplateId == template.Id) 365 .Where(x => x.TemplateId == template.Id)
447 .ExecuteCommandAsync(); 366 .ExecuteCommandAsync();
@@ -617,11 +536,5 @@ public class LabelTemplateAppService : ApplicationService, ILabelTemplateAppServ @@ -617,11 +536,5 @@ public class LabelTemplateAppService : ApplicationService, ILabelTemplateAppServ
617 var v = (raw ?? string.Empty).Trim().ToLowerInvariant(); 536 var v = (raw ?? string.Empty).Trim().ToLowerInvariant();
618 return v is "line" or "dotted" ? v : "none"; 537 return v is "line" or "dotted" ? v : "none";
619 } 538 }
620 -  
621 - private static string NormalizePrintOrientationType(string? raw)  
622 - {  
623 - var v = (raw ?? string.Empty).Trim().ToLowerInvariant();  
624 - return v == "horizontal" ? "horizontal" : "vertical";  
625 - }  
626 } 539 }
627 540
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/UsAppLabelingAppService.cs
@@ -396,16 +396,12 @@ public class UsAppLabelingAppService : ApplicationService, IUsAppLabelingAppServ @@ -396,16 +396,12 @@ public class UsAppLabelingAppService : ApplicationService, IUsAppLabelingAppServ
396 } 396 }
397 397
398 var previewProductId = await ResolvePreviewProductIdAsync(labelRow.Id, input.ProductId); 398 var previewProductId = await ResolvePreviewProductIdAsync(labelRow.Id, input.ProductId);
399 - var baseTime = input.BaseTime ?? DateTime.Now;  
400 - var dailyLabelId = await ReportsPrintLogDailyLabelIdHelper.ResolveNextDailyLabelIdAsync(  
401 - _dbContext.SqlSugarClient, locationId, baseTime);  
402 399
403 var template = await _labelAppService.PreviewAsync(new LabelPreviewResolveInputVo 400 var template = await _labelAppService.PreviewAsync(new LabelPreviewResolveInputVo
404 { 401 {
405 LabelCode = labelCode, 402 LabelCode = labelCode,
406 ProductId = previewProductId, 403 ProductId = previewProductId,
407 BaseTime = input.BaseTime, 404 BaseTime = input.BaseTime,
408 - LocationId = locationId,  
409 PrintInputJson = input.PrintInputJson?.ToDictionary(x => x.Key, x => (object?)x.Value) 405 PrintInputJson = input.PrintInputJson?.ToDictionary(x => x.Key, x => (object?)x.Value)
410 }); 406 });
411 407
@@ -469,7 +465,7 @@ public class UsAppLabelingAppService : ApplicationService, IUsAppLabelingAppServ @@ -469,7 +465,7 @@ public class UsAppLabelingAppService : ApplicationService, IUsAppLabelingAppServ
469 465
470 return new UsAppLabelPreviewDto 466 return new UsAppLabelPreviewDto
471 { 467 {
472 - LabelId = dailyLabelId, 468 + LabelId = labelRow.Id,
473 PrintLabelDisplayId = printLabelDisplayId, 469 PrintLabelDisplayId = printLabelDisplayId,
474 LocationId = locationId, 470 LocationId = locationId,
475 LabelCode = labelCode, 471 LabelCode = labelCode,
@@ -572,7 +568,6 @@ public class UsAppLabelingAppService : ApplicationService, IUsAppLabelingAppServ @@ -572,7 +568,6 @@ public class UsAppLabelingAppService : ApplicationService, IUsAppLabelingAppServ
572 LabelCode = labelCode, 568 LabelCode = labelCode,
573 ProductId = previewProductId, 569 ProductId = previewProductId,
574 BaseTime = input.BaseTime, 570 BaseTime = input.BaseTime,
575 - LocationId = locationId,  
576 PrintInputJson = normalizedPrintInput 571 PrintInputJson = normalizedPrintInput
577 }); 572 });
578 573
@@ -861,7 +856,6 @@ public class UsAppLabelingAppService : ApplicationService, IUsAppLabelingAppServ @@ -861,7 +856,6 @@ public class UsAppLabelingAppService : ApplicationService, IUsAppLabelingAppServ
861 /// ```json 856 /// ```json
862 /// { 857 /// {
863 /// "locationId": "11111111-1111-1111-1111-111111111111", 858 /// "locationId": "11111111-1111-1111-1111-111111111111",
864 - /// "printDate": "2026-06-16T00:00:00",  
865 /// "skipCount": 1, 859 /// "skipCount": 1,
866 /// "maxResultCount": 20 860 /// "maxResultCount": 20
867 /// } 861 /// }
@@ -869,7 +863,6 @@ public class UsAppLabelingAppService : ApplicationService, IUsAppLabelingAppServ @@ -869,7 +863,6 @@ public class UsAppLabelingAppService : ApplicationService, IUsAppLabelingAppServ
869 /// 863 ///
870 /// 参数说明: 864 /// 参数说明:
871 /// - locationId: 当前门店 Id(必填) 865 /// - locationId: 当前门店 Id(必填)
872 - /// - printDate: 打印日期(自然日,可选;未传默认当天;按 PrintedAt ?? CreationTime 筛选)  
873 /// - skipCount: 页码(从 1 开始,遵循本项目约定) 866 /// - skipCount: 页码(从 1 开始,遵循本项目约定)
874 /// - maxResultCount: 每页条数 867 /// - maxResultCount: 每页条数
875 /// </remarks> 868 /// </remarks>
@@ -925,18 +918,8 @@ public class UsAppLabelingAppService : ApplicationService, IUsAppLabelingAppServ @@ -925,18 +918,8 @@ public class UsAppLabelingAppService : ApplicationService, IUsAppLabelingAppServ
925 918
926 RefAsync<int> total = 0; 919 RefAsync<int> total = 0;
927 920
928 - var filterDay = ReportsPrintLogDailyLabelIdHelper.ResolvePrintLogFilterCalendarDay(  
929 - input.PrintDate, input.PrintDateDay);  
930 -  
931 - var baseQuery = UsAppPrintLogScopeHelper.BuildLocationPrintTaskQuery(  
932 - _dbContext.SqlSugarClient, locationId, restrictToCreator, currentUserIdStr);  
933 -  
934 - if (filterDay.HasValue)  
935 - {  
936 - baseQuery = ReportsPrintLogDailyLabelIdHelper.ApplyPrintTaskCalendarDayFilter(baseQuery, filterDay.Value);  
937 - }  
938 -  
939 - var query = baseQuery 921 + var query = UsAppPrintLogScopeHelper.BuildLocationPrintTaskQuery(
  922 + _dbContext.SqlSugarClient, locationId, restrictToCreator, currentUserIdStr)
940 .OrderBy((t, l, p, lt, tpl) => SqlFunc.IsNull(t.PrintedAt, t.CreationTime), OrderByType.Desc) 923 .OrderBy((t, l, p, lt, tpl) => SqlFunc.IsNull(t.PrintedAt, t.CreationTime), OrderByType.Desc)
941 .OrderBy((t, l, p, lt, tpl) => t.CreationTime, OrderByType.Desc) 924 .OrderBy((t, l, p, lt, tpl) => t.CreationTime, OrderByType.Desc)
942 .Select((t, l, p, lt, tpl) => new 925 .Select((t, l, p, lt, tpl) => new
@@ -960,13 +943,6 @@ public class UsAppLabelingAppService : ApplicationService, IUsAppLabelingAppServ @@ -960,13 +943,6 @@ public class UsAppLabelingAppService : ApplicationService, IUsAppLabelingAppServ
960 943
961 var pageRows = await query.ToPageListAsync(input.SkipCount, input.MaxResultCount, total); 944 var pageRows = await query.ToPageListAsync(input.SkipCount, input.MaxResultCount, total);
962 945
963 - var dailyLabelIdMap = await ReportsPrintLogDailyLabelIdHelper.ResolveDailyLabelIdsAsync(  
964 - _dbContext.SqlSugarClient,  
965 - pageRows.Select(x => new ReportsPrintLogDailyLabelIdHelper.PrintTaskScopeKey(  
966 - x.Id,  
967 - locationId,  
968 - x.PrintedAt ?? x.CreationTime)).ToList());  
969 -  
970 var operatorMap = await UsAppPrintLogScopeHelper.LoadOperatorNameMapAsync( 946 var operatorMap = await UsAppPrintLogScopeHelper.LoadOperatorNameMapAsync(
971 _dbContext.SqlSugarClient, 947 _dbContext.SqlSugarClient,
972 pageRows.Select(x => x.CreatedBy)); 948 pageRows.Select(x => x.CreatedBy));
@@ -976,8 +952,7 @@ public class UsAppLabelingAppService : ApplicationService, IUsAppLabelingAppServ @@ -976,8 +952,7 @@ public class UsAppLabelingAppService : ApplicationService, IUsAppLabelingAppServ
976 TaskId = x.Id, 952 TaskId = x.Id,
977 BatchId = x.BatchId, 953 BatchId = x.BatchId,
978 CopyIndex = x.CopyIndex, 954 CopyIndex = x.CopyIndex,
979 - LabelId = dailyLabelIdMap.TryGetValue(x.Id, out var dailyId) ? dailyId : "无",  
980 - LabelEntityId = x.LabelId ?? string.Empty, 955 + LabelId = x.LabelId,
981 LabelCode = x.LabelCode ?? string.Empty, 956 LabelCode = x.LabelCode ?? string.Empty,
982 ProductId = x.ProductId, 957 ProductId = x.ProductId,
983 ProductName = string.IsNullOrWhiteSpace(x.ProductName) ? "无" : x.ProductName.Trim(), 958 ProductName = string.IsNullOrWhiteSpace(x.ProductName) ? "无" : x.ProductName.Trim(),
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/scripts/fl_label_template_print_orientation.sql deleted
1 --- fl_label_template 增加打印方向字段(vertical=竖打默认,horizontal=横打内容旋转90°)  
2 -SET @db = DATABASE();  
3 -  
4 -SET @sql = IF(  
5 - (SELECT COUNT(*) FROM information_schema.COLUMNS  
6 - WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'fl_label_template' AND COLUMN_NAME = 'PrintOrientationType') = 0,  
7 - 'ALTER TABLE `fl_label_template` ADD COLUMN `PrintOrientationType` varchar(20) NOT NULL DEFAULT ''vertical'' COMMENT ''打印方向:vertical/horizontal'' AFTER `BorderType`',  
8 - 'SELECT ''PrintOrientationType already exists'' AS msg'  
9 -);  
10 -PREPARE stmt FROM @sql;  
11 -EXECUTE stmt;  
12 -DEALLOCATE PREPARE stmt;  
美国版/Food Labeling Management Platform/src/components/labels/LabelTemplateEditor/LabelCanvas.tsx
@@ -99,7 +99,7 @@ export function mapPointerDeltaToTemplateSpace( @@ -99,7 +99,7 @@ export function mapPointerDeltaToTemplateSpace(
99 return { dx: dy, dy: -dx }; 99 return { dx: dy, dy: -dx };
100 } 100 }
101 101
102 -/** 根据指针位置与抓取偏移计算模板坐标(横打跟随视觉方向) */ 102 +/** 根据指针位置与抓取偏移计算模板坐标(竖打跟随视觉方向) */
103 export function templatePositionFromPointerGrab( 103 export function templatePositionFromPointerGrab(
104 localX: number, 104 localX: number,
105 localY: number, 105 localY: number,
@@ -143,7 +143,7 @@ export function elementResizeDeltaFromPointer( @@ -143,7 +143,7 @@ export function elementResizeDeltaFromPointer(
143 return { dw, dh }; 143 return { dw, dh };
144 } 144 }
145 145
146 -/** 将画布本地坐标系中的指针位移转为模板坐标系增量(横打已含 rotate 逆变换) */ 146 +/** 将画布本地坐标系中的指针位移转为模板坐标系增量(竖打已含 rotate 逆变换) */
147 export function templatePointerDeltaFromCanvasLocals( 147 export function templatePointerDeltaFromCanvasLocals(
148 startLocalX: number, 148 startLocalX: number,
149 startLocalY: number, 149 startLocalY: number,
@@ -316,7 +316,7 @@ function snapToGrid(value: number): number { @@ -316,7 +316,7 @@ function snapToGrid(value: number): number {
316 /** 画布内安全边距(px),与主题色虚线框一致;控件不可移出 */ 316 /** 画布内安全边距(px),与主题色虚线框一致;控件不可移出 */
317 export const LABEL_CANVAS_SAFE_MARGIN_PX = 16; 317 export const LABEL_CANVAS_SAFE_MARGIN_PX = 16;
318 318
319 -/** 蓝色虚线安全区(固定在纸张坐标系,竖打时不随控件旋转) */ 319 +/** 蓝色虚线安全区(固定在纸张坐标系,横打时不随控件旋转) */
320 function CanvasSafeMarginOverlay({ baseW, baseH }: { baseW: number; baseH: number }) { 320 function CanvasSafeMarginOverlay({ baseW, baseH }: { baseW: number; baseH: number }) {
321 if (baseW <= LABEL_CANVAS_SAFE_MARGIN_PX * 2 || baseH <= LABEL_CANVAS_SAFE_MARGIN_PX * 2) { 321 if (baseW <= LABEL_CANVAS_SAFE_MARGIN_PX * 2 || baseH <= LABEL_CANVAS_SAFE_MARGIN_PX * 2) {
322 return null; 322 return null;
@@ -602,9 +602,9 @@ function ElementSelectionFrame({ @@ -602,9 +602,9 @@ function ElementSelectionFrame({
602 const heightLineX = heightOnLeft ? x - 12 : x + w + 12; 602 const heightLineX = heightOnLeft ? x - 12 : x + w + 12;
603 const heightTextX = heightOnLeft ? heightLineX - 8 : heightLineX + 8; 603 const heightTextX = heightOnLeft ? heightLineX - 8 : heightLineX + 8;
604 // 横打预览旋转后,屏幕上的横/竖跨度与模板宽/高对调,标注跟随视觉 604 // 横打预览旋转后,屏幕上的横/竖跨度与模板宽/高对调,标注跟随视觉
605 - const isRotatedPrintPreview = printOrientation === 'horizontal';  
606 - const displayWidthLabel = isRotatedPrintPreview ? hValue : wValue;  
607 - const displayHeightLabel = isRotatedPrintPreview ? wValue : hValue; 605 + const isRotatedPrint = printOrientation === 'horizontal';
  606 + const displayWidthLabel = isRotatedPrint ? hValue : wValue;
  607 + const displayHeightLabel = isRotatedPrint ? wValue : hValue;
608 608
609 return ( 609 return (
610 <> 610 <>
@@ -1812,7 +1812,7 @@ export function LabelCanvas({ @@ -1812,7 +1812,7 @@ export function LabelCanvas({
1812 const widthPx = baseW * scale; 1812 const widthPx = baseW * scale;
1813 const heightPx = baseH * scale; 1813 const heightPx = baseH * scale;
1814 const showGrid = template.showGrid !== false; 1814 const showGrid = template.showGrid !== false;
1815 - const isRotatedPrintPreview = printOrientation === 'horizontal'; 1815 + const isRotatedPrint = printOrientation === 'horizontal';
1816 const effectiveCanvasBorder = canvasBorder ?? template.border ?? 'none'; 1816 const effectiveCanvasBorder = canvasBorder ?? template.border ?? 'none';
1817 const canvasBorderClass = 1817 const canvasBorderClass =
1818 effectiveCanvasBorder === 'line' 1818 effectiveCanvasBorder === 'line'
@@ -1990,7 +1990,7 @@ export function LabelCanvas({ @@ -1990,7 +1990,7 @@ export function LabelCanvas({
1990 baseW, 1990 baseW,
1991 baseH, 1991 baseH,
1992 ); 1992 );
1993 - const resized = computeResizedElementBox(elX, elY, w, h, corner, dtx, dty, 'horizontal'); 1993 + const resized = computeResizedElementBox(elX, elY, w, h, corner, dtx, dty, printOrientation);
1994 const clamped = clampLabelElementBox( 1994 const clamped = clampLabelElementBox(
1995 snapToGrid(resized.x), 1995 snapToGrid(resized.x),
1996 snapToGrid(resized.y), 1996 snapToGrid(resized.y),
@@ -2183,7 +2183,7 @@ export function LabelCanvas({ @@ -2183,7 +2183,7 @@ export function LabelCanvas({
2183 baseW, 2183 baseW,
2184 baseH, 2184 baseH,
2185 ); 2185 );
2186 - const resized = computeResizedElementBox(elX, elY, w, h, corner, dtx, dty, 'horizontal'); 2186 + const resized = computeResizedElementBox(elX, elY, w, h, corner, dtx, dty, printOrientation);
2187 const clamped = clampLabelElementBox( 2187 const clamped = clampLabelElementBox(
2188 snapToGrid(resized.x), 2188 snapToGrid(resized.x),
2189 snapToGrid(resized.y), 2189 snapToGrid(resized.y),
@@ -2688,7 +2688,7 @@ export function LabelCanvas({ @@ -2688,7 +2688,7 @@ export function LabelCanvas({
2688 tabIndex={0} 2688 tabIndex={0}
2689 className={cn( 2689 className={cn(
2690 'absolute left-0 top-0 shadow-lg outline-none', 2690 'absolute left-0 top-0 shadow-lg outline-none',
2691 - isRotatedPrintPreview ? 'overflow-visible' : 'overflow-hidden', 2691 + isRotatedPrint ? 'overflow-visible' : 'overflow-hidden',
2692 canvasBorderClass, 2692 canvasBorderClass,
2693 isPanning ? 'cursor-grabbing' : 'cursor-grab' 2693 isPanning ? 'cursor-grabbing' : 'cursor-grab'
2694 )} 2694 )}
美国版/Food Labeling Management Platform/src/components/labels/LabelsList.tsx
@@ -75,7 +75,6 @@ import { @@ -75,7 +75,6 @@ import {
75 isDataEntryTableColumnElement, 75 isDataEntryTableColumnElement,
76 isDateTimeDataEntryField, 76 isDateTimeDataEntryField,
77 labelElementsToApiPayload, 77 labelElementsToApiPayload,
78 - normalizePrintOrientation,  
79 normalizeTemplateBorder, 78 normalizeTemplateBorder,
80 sortTemplateElementsForDisplay, 79 sortTemplateElementsForDisplay,
81 } from "../../types/labelTemplate"; 80 } from "../../types/labelTemplate";
@@ -592,9 +591,6 @@ function dtoToEditorTemplate(apiTemplate: LabelTemplateDto): LabelTemplate { @@ -592,9 +591,6 @@ function dtoToEditorTemplate(apiTemplate: LabelTemplateDto): LabelTemplate {
592 showRuler: apiTemplate.showRuler ?? true, 591 showRuler: apiTemplate.showRuler ?? true,
593 showGrid: apiTemplate.showGrid ?? true, 592 showGrid: apiTemplate.showGrid ?? true,
594 border: normalizeTemplateBorder(apiTemplate.border), 593 border: normalizeTemplateBorder(apiTemplate.border),
595 - printOrientation: normalizePrintOrientation(  
596 - apiTemplate.printOrientation ?? (apiTemplate as Record<string, unknown>).PrintOrientation,  
597 - ),  
598 elements: (apiTemplate.elements ?? []).map((raw, idx) => { 594 elements: (apiTemplate.elements ?? []).map((raw, idx) => {
599 const el = raw as LabelElement; 595 const el = raw as LabelElement;
600 const en = (el.elementName ?? "").trim(); 596 const en = (el.elementName ?? "").trim();
美国版/Food Labeling Management Platform/src/components/people/PeopleView.tsx
@@ -187,19 +187,10 @@ function normLocationId(id: string | null | undefined): string { @@ -187,19 +187,10 @@ function normLocationId(id: string | null | undefined): string {
187 return String(id ?? "").trim().toLowerCase(); 187 return String(id ?? "").trim().toLowerCase();
188 } 188 }
189 189
190 -function memberMatchesLocationScope(  
191 - m: TeamMemberDto,  
192 - allowedLocationIds: Set<string> | null,  
193 - allowedPartnerId?: string | null,  
194 -): boolean {  
195 - if (allowedPartnerId) {  
196 - const partnerKey = allowedPartnerId.trim().toLowerCase();  
197 - const partnerIds = (m.partnerIds ?? []).map((x) => String(x).trim().toLowerCase());  
198 - if (partnerIds.includes(partnerKey)) return true;  
199 - } 190 +function memberMatchesLocationScope(m: TeamMemberDto, allowedLocationIds: Set<string> | null): boolean {
200 if (allowedLocationIds === null) return true; 191 if (allowedLocationIds === null) return true;
201 if (allowedLocationIds.size === 0) return false; 192 if (allowedLocationIds.size === 0) return false;
202 - const ids = (m.locationIds ?? []).map((x) => normLocationId(x)).filter(Boolean); 193 + const ids = (m.locationIds ?? []).map((x) => String(x).trim()).filter(Boolean);
203 return ids.some((id) => allowedLocationIds.has(id)); 194 return ids.some((id) => allowedLocationIds.has(id));
204 } 195 }
205 196
@@ -584,7 +575,7 @@ export function PeopleView({ @@ -584,7 +575,7 @@ export function PeopleView({
584 if (memberLocationFilter !== "all" || !memberUsesClientScopeFilter) return null; 575 if (memberLocationFilter !== "all" || !memberUsesClientScopeFilter) return null;
585 const ids = new Set<string>(); 576 const ids = new Set<string>();
586 for (const loc of memberLocationsForSelect) { 577 for (const loc of memberLocationsForSelect) {
587 - if (loc.id) ids.add(normLocationId(loc.id)); 578 + if (loc.id) ids.add(loc.id);
588 } 579 }
589 return ids; 580 return ids;
590 }, [memberLocationFilter, memberUsesClientScopeFilter, memberLocationsForSelect]); 581 }, [memberLocationFilter, memberUsesClientScopeFilter, memberLocationsForSelect]);
@@ -781,14 +772,11 @@ export function PeopleView({ @@ -781,14 +772,11 @@ export function PeopleView({
781 skipCount: 1, 772 skipCount: 1,
782 maxResultCount: 500, 773 maxResultCount: 500,
783 keyword: debouncedMemberKeyword || undefined, 774 keyword: debouncedMemberKeyword || undefined,
784 - partnerId: memberPartnerFilter !== "all" ? memberPartnerFilter : undefined,  
785 - groupId: memberGroupFilter !== "all" ? memberGroupFilter : undefined,  
786 }, 775 },
787 ac.signal, 776 ac.signal,
788 ); 777 );
789 - const allowedPartnerId = memberPartnerFilter !== "all" ? memberPartnerFilter : null;  
790 const filtered = (res.items ?? []).filter((m) => 778 const filtered = (res.items ?? []).filter((m) =>
791 - memberMatchesLocationScope(m, memberAllowedLocationIds, allowedPartnerId), 779 + memberMatchesLocationScope(m, memberAllowedLocationIds),
792 ); 780 );
793 const total = filtered.length; 781 const total = filtered.length;
794 const start = (memberPageIndex - 1) * memberPageSize; 782 const start = (memberPageIndex - 1) * memberPageSize;
@@ -800,8 +788,6 @@ export function PeopleView({ @@ -800,8 +788,6 @@ export function PeopleView({
800 skipCount: Math.max(1, memberPageIndex), 788 skipCount: Math.max(1, memberPageIndex),
801 maxResultCount: memberPageSize, 789 maxResultCount: memberPageSize,
802 keyword: debouncedMemberKeyword || undefined, 790 keyword: debouncedMemberKeyword || undefined,
803 - partnerId: memberPartnerFilter !== "all" ? memberPartnerFilter : undefined,  
804 - groupId: memberGroupFilter !== "all" ? memberGroupFilter : undefined,  
805 locationId: locationIdParam, 791 locationId: locationIdParam,
806 }, 792 },
807 ac.signal, 793 ac.signal,
美国版/Food Labeling Management Platform/src/types/labelTemplate.ts
@@ -10,7 +10,7 @@ export type Unit = &#39;cm&#39; | &#39;inch&#39;; @@ -10,7 +10,7 @@ export type Unit = &#39;cm&#39; | &#39;inch&#39;;
10 export type AppliedLocation = 'ALL' | 'SPECIFIED'; 10 export type AppliedLocation = 'ALL' | 'SPECIFIED';
11 export type Rotation = 'horizontal' | 'vertical'; 11 export type Rotation = 'horizontal' | 'vertical';
12 12
13 -/** 模板打印方向:横打 / 竖打(纸张 W×H 不变,横打时内容整体旋转 90° 打印) */ 13 +/** 模板打印方向:vertical=竖打(默认,内容不旋转);horizontal=横打(纸张 W×H 不变,内容整体旋转 90°) */
14 export type PrintOrientation = 'horizontal' | 'vertical'; 14 export type PrintOrientation = 'horizontal' | 'vertical';
15 15
16 export function normalizePrintOrientation(raw: unknown): PrintOrientation { 16 export function normalizePrintOrientation(raw: unknown): PrintOrientation {
@@ -18,6 +18,11 @@ export function normalizePrintOrientation(raw: unknown): PrintOrientation { @@ -18,6 +18,11 @@ export function normalizePrintOrientation(raw: unknown): PrintOrientation {
18 return v === 'horizontal' ? 'horizontal' : 'vertical'; 18 return v === 'horizontal' ? 'horizontal' : 'vertical';
19 } 19 }
20 20
  21 +/** 横打时内容层需整体旋转 90° */
  22 +export function isRotatedPrintOrientation(orientation: PrintOrientation | string | undefined): boolean {
  23 + return normalizePrintOrientation(orientation) === 'horizontal';
  24 +}
  25 +
21 export type Border = 'none' | 'line' | 'dotted'; 26 export type Border = 'none' | 'line' | 'dotted';
22 27
23 /** 归一化模板级整纸边框(与元素 border 字段语义相同,作用范围不同) */ 28 /** 归一化模板级整纸边框(与元素 border 字段语义相同,作用范围不同) */