refactor(产品模块): 将FinishedProductDto替换为ProFinishedProductReceipt
统一使用ProFinishedProductReceipt作为产品数据模型,移除DTO转换层 更新相关视图模型和服务接口以匹配新模型 修改XAML绑定以使用新模型属性
This commit is contained in:
@@ -28,7 +28,7 @@ namespace RIZO_Application.Modules.ModuleName.Services
|
||||
private readonly HttpClient _httpClient;
|
||||
private readonly IEventAggregator _eventAggregator;
|
||||
private readonly IPrintService _printService;
|
||||
private readonly List<FinishedProductDto> _mockData;
|
||||
private readonly List<ProFinishedProductReceipt> _mockData;
|
||||
private readonly bool _useMockData = false; // 控制是否使用模拟数据
|
||||
|
||||
private readonly string _labelFrom = PrintConfigs.Current.LabelFrom;
|
||||
@@ -41,60 +41,57 @@ namespace RIZO_Application.Modules.ModuleName.Services
|
||||
_printService = printService;
|
||||
|
||||
// 初始化模拟数据
|
||||
_mockData = new List<FinishedProductDto>
|
||||
_mockData = new List<ProFinishedProductReceipt>
|
||||
{
|
||||
new FinishedProductDto
|
||||
new ProFinishedProductReceipt
|
||||
{
|
||||
Id = 1,
|
||||
ReceiptNo = "RK202511140001",
|
||||
WorkOrder = "W20251114001",
|
||||
ProductName = "T1EJ左后门把手-新卡其白",
|
||||
ProductCode = "220707",
|
||||
Description = "T1EJ左后门把手-新卡其白",
|
||||
PartNumber = "220707",
|
||||
PackageCount = 8,
|
||||
PackageNum = 465,
|
||||
BatchCode = "20240501001",
|
||||
WarehouseLocation = "A1-01-01",
|
||||
Operator = "admin",
|
||||
WarehouseCode = "A1-01-01",
|
||||
CreatedBy = "admin",
|
||||
ProductionTime = DateTime.Now.AddDays(-1),
|
||||
Status = "未打印",
|
||||
LabelPrintStatus = "未打印",
|
||||
Remark = "正常入库"
|
||||
},
|
||||
new FinishedProductDto
|
||||
new ProFinishedProductReceipt
|
||||
{
|
||||
Id = 2,
|
||||
ReceiptNo = "RK202511140002",
|
||||
WorkOrder = "W20251114002",
|
||||
ProductName = "T1EJ右前门把手-右舵-新卡其白",
|
||||
ProductCode = "221353",
|
||||
Description = "T1EJ右前门把手-右舵-新卡其白",
|
||||
PartNumber = "221353",
|
||||
PackageCount = 7,
|
||||
PackageNum = 458,
|
||||
BatchCode = "20240502001",
|
||||
WarehouseLocation = "A1-02-01",
|
||||
Operator = "admin",
|
||||
WarehouseCode = "A1-02-01",
|
||||
CreatedBy = "admin",
|
||||
ProductionTime = DateTime.Now,
|
||||
Status = "未打印",
|
||||
LabelPrintStatus = "未打印",
|
||||
Remark = "正常入库"
|
||||
},
|
||||
new FinishedProductDto
|
||||
new ProFinishedProductReceipt
|
||||
{
|
||||
Id = 3,
|
||||
ReceiptNo = "RK202511140003",
|
||||
WorkOrder = "W20251114003",
|
||||
ProductName = "T1EJ右前门把手-左舵-新卡其白",
|
||||
ProductCode = "220701",
|
||||
Description = "T1EJ右前门把手-左舵-新卡其白",
|
||||
PartNumber = "220701",
|
||||
PackageCount = 7,
|
||||
PackageNum = 475,
|
||||
BatchCode = "20240502002",
|
||||
WarehouseLocation = "A1-02-02",
|
||||
Operator = "admin",
|
||||
WarehouseCode = "A1-02-02",
|
||||
CreatedBy = "admin",
|
||||
ProductionTime = DateTime.Now,
|
||||
Status = "未打印",
|
||||
LabelPrintStatus = "未打印",
|
||||
Remark = "正常入库"
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<FinishedProductDto>> GetFinishedProductsAsync(
|
||||
public async Task<IEnumerable<ProFinishedProductReceipt>> GetFinishedProductsAsync(
|
||||
FinishedProductQueryDto query
|
||||
)
|
||||
{
|
||||
@@ -111,7 +108,7 @@ namespace RIZO_Application.Modules.ModuleName.Services
|
||||
//var response = await _httpClient.GetAsync("api/finishedproducts");
|
||||
//response.EnsureSuccessStatusCode();
|
||||
//var content = await response.Content.ReadAsStringAsync();
|
||||
//return JsonConvert.DeserializeObject<List<FinishedProductDto>>(content);
|
||||
//return JsonConvert.DeserializeObject<List<ProFinishedProductReceipt>>(content);
|
||||
//
|
||||
DateTime? endDateInclusive = null;
|
||||
if (query.EndTime.HasValue)
|
||||
@@ -132,21 +129,6 @@ namespace RIZO_Application.Modules.ModuleName.Services
|
||||
query.EndTime.Value > DateTime.MinValue,
|
||||
it => it.CreatedTime <= endDateInclusive
|
||||
)
|
||||
.Select(it => new FinishedProductDto
|
||||
{
|
||||
ReceiptNo = it.ReceiptNo,
|
||||
WorkOrder = it.WorkOrder,
|
||||
ProductName = it.Description,
|
||||
ProductCode = it.PartNumber,
|
||||
PackageCount = it.PackageCount,
|
||||
PackageNum = it.PackageNum,
|
||||
BatchCode = it.BatchCode,
|
||||
WarehouseLocation = it.WarehouseCode,
|
||||
Operator = it.CreatedBy,
|
||||
ProductionTime = it.ProductionTime,
|
||||
Status = it.LabelPrintStatus,
|
||||
Remark = it.Remark
|
||||
})
|
||||
.OrderByDescending(it => it.ReceiptNo)
|
||||
.ToPageList(pageNumber, pageSize);
|
||||
return result;
|
||||
@@ -155,11 +137,11 @@ namespace RIZO_Application.Modules.ModuleName.Services
|
||||
catch (Exception ex)
|
||||
{
|
||||
_eventAggregator.GetEvent<SystemLogEvent>().Publish($"获取成品入库单失败: {ex.Message}");
|
||||
return new List<FinishedProductDto>();
|
||||
return new List<ProFinishedProductReceipt>();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<FinishedProductDto> GetFinishedProductByReceiptNoAsync(string receiptNo)
|
||||
public async Task<ProFinishedProductReceipt> GetFinishedProductByReceiptNoAsync(string receiptNo)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -172,21 +154,6 @@ namespace RIZO_Application.Modules.ModuleName.Services
|
||||
var result = Context
|
||||
.Queryable<ProFinishedProductReceipt>()
|
||||
.Where(it => it.ReceiptNo == receiptNo)
|
||||
.Select(it => new FinishedProductDto
|
||||
{
|
||||
ReceiptNo = it.ReceiptNo,
|
||||
WorkOrder = it.WorkOrder,
|
||||
ProductName = it.Description,
|
||||
ProductCode = it.PartNumber,
|
||||
PackageCount = it.PackageCount,
|
||||
PackageNum = it.PackageNum,
|
||||
BatchCode = it.BatchCode,
|
||||
WarehouseLocation = it.WarehouseCode,
|
||||
Operator = it.CreatedBy,
|
||||
ProductionTime = it.ProductionTime,
|
||||
Status = it.LabelPrintStatus,
|
||||
Remark = it.Remark
|
||||
})
|
||||
.OrderByDescending(it => it.ReceiptNo)
|
||||
.First();
|
||||
return result;
|
||||
@@ -199,14 +166,12 @@ namespace RIZO_Application.Modules.ModuleName.Services
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> AddFinishedProductAsync(FinishedProductDto product)
|
||||
public async Task<bool> AddFinishedProductAsync(ProFinishedProductReceipt product)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_useMockData)
|
||||
{
|
||||
product.Id = _mockData.Count > 0 ? _mockData[^1].Id + 1 : 1;
|
||||
|
||||
// 自动生成入库单号:RK + 年份 + 月份 + 日期 + 4位流水号
|
||||
string datePart = DateTime.Now.ToString("yyyyMMdd");
|
||||
int maxSerial = 0;
|
||||
@@ -224,7 +189,7 @@ namespace RIZO_Application.Modules.ModuleName.Services
|
||||
}
|
||||
|
||||
product.ReceiptNo = $"RK{datePart}{(maxSerial + 1).ToString("D4")}";
|
||||
product.Status = "未打印"; // 默认状态为未打印
|
||||
product.LabelPrintStatus = "未打印"; // 默认状态为未打印
|
||||
|
||||
_mockData.Add(product);
|
||||
_eventAggregator
|
||||
@@ -278,13 +243,13 @@ namespace RIZO_Application.Modules.ModuleName.Services
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateFinishedProductAsync(FinishedProductDto product)
|
||||
public async Task<bool> UpdateFinishedProductAsync(ProFinishedProductReceipt product)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_useMockData)
|
||||
{
|
||||
var index = _mockData.FindIndex(p => p.Id == product.Id);
|
||||
var index = _mockData.FindIndex(p => p.ReceiptNo == product.ReceiptNo);
|
||||
if (index != -1)
|
||||
{
|
||||
_mockData[index] = product;
|
||||
@@ -413,7 +378,7 @@ namespace RIZO_Application.Modules.ModuleName.Services
|
||||
// 如果打印成功,更新状态为已打印
|
||||
if (success && _useMockData)
|
||||
{
|
||||
product.Status = "已打印";
|
||||
product.LabelPrintStatus = "已打印";
|
||||
_eventAggregator
|
||||
.GetEvent<SystemLogEvent>()
|
||||
.Publish($"更新成品入库单状态为已打印: {product.ReceiptNo}");
|
||||
|
||||
@@ -6,10 +6,10 @@ namespace RIZO_Application.Modules.ModuleName.Services.IServices
|
||||
{
|
||||
public interface IFinishedProductService
|
||||
{
|
||||
Task<IEnumerable<FinishedProductDto>> GetFinishedProductsAsync(FinishedProductQueryDto query);
|
||||
Task<FinishedProductDto> GetFinishedProductByReceiptNoAsync(string receiptNo);
|
||||
Task<bool> AddFinishedProductAsync(FinishedProductDto product);
|
||||
Task<bool> UpdateFinishedProductAsync(FinishedProductDto product);
|
||||
Task<IEnumerable<ProFinishedProductReceipt>> GetFinishedProductsAsync(FinishedProductQueryDto query);
|
||||
Task<ProFinishedProductReceipt> GetFinishedProductByReceiptNoAsync(string receiptNo);
|
||||
Task<bool> AddFinishedProductAsync(ProFinishedProductReceipt product);
|
||||
Task<bool> UpdateFinishedProductAsync(ProFinishedProductReceipt product);
|
||||
Task<bool> DeleteFinishedProductAsync(string receiptNo);
|
||||
Task<bool> PrintFinishedProductAsync(string receiptNo);
|
||||
}
|
||||
|
||||
@@ -10,9 +10,9 @@ namespace RIZO_Application.Modules.ModuleName.ViewModels
|
||||
public class AddProductDialogViewModel : BindableBase, IDialogAware
|
||||
{
|
||||
private readonly IFinishedProductService _finishedProductService;
|
||||
private FinishedProductDto _product;
|
||||
private ProFinishedProductReceipt _product;
|
||||
|
||||
public FinishedProductDto Product
|
||||
public ProFinishedProductReceipt Product
|
||||
{
|
||||
get { return _product; }
|
||||
set { SetProperty(ref _product, value); }
|
||||
@@ -28,7 +28,7 @@ namespace RIZO_Application.Modules.ModuleName.ViewModels
|
||||
public AddProductDialogViewModel(IFinishedProductService finishedProductService)
|
||||
{
|
||||
_finishedProductService = finishedProductService;
|
||||
Product = new FinishedProductDto();
|
||||
Product = new ProFinishedProductReceipt();
|
||||
SaveCommand = new DelegateCommand(async () => await SaveProductAsync());
|
||||
CancelCommand = new DelegateCommand(Cancel);
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@ namespace RIZO_Application.Modules.ModuleName.ViewModels
|
||||
set { SetProperty(ref _confirmMessage, value); }
|
||||
}
|
||||
|
||||
private FinishedProductDto _product;
|
||||
public FinishedProductDto Product
|
||||
private ProFinishedProductReceipt _product;
|
||||
public ProFinishedProductReceipt Product
|
||||
{
|
||||
get { return _product; }
|
||||
set { SetProperty(ref _product, value); }
|
||||
@@ -66,8 +66,8 @@ namespace RIZO_Application.Modules.ModuleName.ViewModels
|
||||
{
|
||||
if (parameters.ContainsKey("Product"))
|
||||
{
|
||||
Product = parameters.GetValue<FinishedProductDto>("Product");
|
||||
ConfirmMessage = string.Format("确定要删除产品 '{0}'(工单号:{1})吗?", Product.ProductName, Product.WorkOrder);
|
||||
Product = parameters.GetValue<ProFinishedProductReceipt>("Product");
|
||||
ConfirmMessage = string.Format("确定要删除产品 '{0}'(工单号:{1})吗?", Product.Description, Product.WorkOrder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,9 +10,9 @@ namespace RIZO_Application.Modules.ModuleName.ViewModels
|
||||
public class EditProductDialogViewModel : BindableBase, IDialogAware
|
||||
{
|
||||
private readonly IFinishedProductService _finishedProductService;
|
||||
private FinishedProductDto _product;
|
||||
private ProFinishedProductReceipt _product;
|
||||
|
||||
public FinishedProductDto Product
|
||||
public ProFinishedProductReceipt Product
|
||||
{
|
||||
get { return _product; }
|
||||
set { SetProperty(ref _product, value); }
|
||||
@@ -60,7 +60,7 @@ namespace RIZO_Application.Modules.ModuleName.ViewModels
|
||||
{
|
||||
if (parameters.ContainsKey("Product"))
|
||||
{
|
||||
Product = parameters.GetValue<FinishedProductDto>("Product");
|
||||
Product = parameters.GetValue<ProFinishedProductReceipt>("Product");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,15 +28,15 @@ namespace RIZO_Application.Modules.ModuleName.ViewModels
|
||||
set { SetProperty(ref _message, value); }
|
||||
}
|
||||
|
||||
private List<FinishedProductDto> _finishedProducts;
|
||||
public List<FinishedProductDto> FinishedProducts
|
||||
private List<ProFinishedProductReceipt> _finishedProducts;
|
||||
public List<ProFinishedProductReceipt> FinishedProducts
|
||||
{
|
||||
get { return _finishedProducts; }
|
||||
set { SetProperty(ref _finishedProducts, value); }
|
||||
}
|
||||
|
||||
private FinishedProductDto _selectedProduct;
|
||||
public FinishedProductDto SelectedProduct
|
||||
private ProFinishedProductReceipt _selectedProduct;
|
||||
public ProFinishedProductReceipt SelectedProduct
|
||||
{
|
||||
get { return _selectedProduct; }
|
||||
set { SetProperty(ref _selectedProduct, value); }
|
||||
@@ -137,7 +137,7 @@ namespace RIZO_Application.Modules.ModuleName.ViewModels
|
||||
StartTime = _startDate,
|
||||
EndTime = _endDate,
|
||||
};
|
||||
FinishedProducts = (List<FinishedProductDto>)await _finishedProductService.GetFinishedProductsAsync(query);
|
||||
FinishedProducts = (List<ProFinishedProductReceipt>)await _finishedProductService.GetFinishedProductsAsync(query);
|
||||
}
|
||||
|
||||
private async System.Threading.Tasks.Task SearchProductsAsync()
|
||||
@@ -148,18 +148,15 @@ namespace RIZO_Application.Modules.ModuleName.ViewModels
|
||||
EndTime = _endDate,
|
||||
};
|
||||
// 获取所有产品
|
||||
var allProducts = (List<FinishedProductDto>)await _finishedProductService.GetFinishedProductsAsync(query);
|
||||
var allProducts = (List<ProFinishedProductReceipt>)await _finishedProductService.GetFinishedProductsAsync(query);
|
||||
|
||||
// 应用搜索条件
|
||||
var filteredProducts = allProducts.AsEnumerable();
|
||||
|
||||
|
||||
|
||||
|
||||
// 状态过滤
|
||||
if (!string.IsNullOrEmpty(SelectedStatus) && SelectedStatus != "全部")
|
||||
{
|
||||
filteredProducts = filteredProducts.Where(p => p.Status == SelectedStatus);
|
||||
filteredProducts = filteredProducts.Where(p => p.LabelPrintStatus == SelectedStatus);
|
||||
}
|
||||
|
||||
FinishedProducts = filteredProducts.ToList();
|
||||
|
||||
@@ -10,9 +10,9 @@ namespace RIZO_Application.Modules.ModuleName.ViewModels
|
||||
public class PrintPreviewDialogViewModel : BindableBase, IDialogAware
|
||||
{
|
||||
private readonly IFinishedProductService _finishedProductService;
|
||||
private FinishedProductDto _product;
|
||||
private ProFinishedProductReceipt _product;
|
||||
|
||||
public FinishedProductDto Product
|
||||
public ProFinishedProductReceipt Product
|
||||
{
|
||||
get { return _product; }
|
||||
set { SetProperty(ref _product, value); }
|
||||
@@ -62,7 +62,7 @@ namespace RIZO_Application.Modules.ModuleName.ViewModels
|
||||
{
|
||||
if (parameters.ContainsKey("Product"))
|
||||
{
|
||||
Product = parameters.GetValue<FinishedProductDto>("Product");
|
||||
Product = parameters.GetValue<ProFinishedProductReceipt>("Product");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,21 +61,21 @@
|
||||
<!-- 工单信息列 -->
|
||||
<DataGridTextColumn Header="入库单号" Binding="{Binding ReceiptNo}" Width="160" />
|
||||
<DataGridTextColumn Header="产线工单号" Binding="{Binding WorkOrder}" Width="120" />
|
||||
<DataGridTextColumn Header="产品名称" Binding="{Binding ProductName}" Width="150" />
|
||||
<DataGridTextColumn Header="产品编码" Binding="{Binding ProductCode}" Width="120" />
|
||||
<DataGridTextColumn Header="产品名称" Binding="{Binding Description}" Width="150" />
|
||||
<DataGridTextColumn Header="产品编码" Binding="{Binding PartNumber}" Width="120" />
|
||||
<DataGridTextColumn Header="箱数" Binding="{Binding PackageCount}" Width="80" />
|
||||
<DataGridTextColumn Header="产品数" Binding="{Binding PackageNum}" Width="80" />
|
||||
<DataGridTextColumn Header="批次号" Binding="{Binding BatchCode}" Width="120" />
|
||||
<DataGridTextColumn Header="仓库位置" Binding="{Binding WarehouseLocation}" Width="120" />
|
||||
<DataGridTextColumn Header="操作人" Binding="{Binding Operator}" Width="100" />
|
||||
<DataGridTextColumn Header="仓库位置" Binding="{Binding WarehouseCode}" Width="120" />
|
||||
<DataGridTextColumn Header="操作人" Binding="{Binding CreatedBy}" Width="100" />
|
||||
<DataGridTemplateColumn Header="状态" Width="120">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<Border Background="{Binding Status, Converter={StaticResource StatusToColorConverter}}"
|
||||
<Border Background="{Binding LabelPrintStatus, Converter={StaticResource StatusToColorConverter}}"
|
||||
CornerRadius="12"
|
||||
Padding="8,4"
|
||||
HorizontalAlignment="Center">
|
||||
<TextBlock Text="{Binding Status}"
|
||||
<TextBlock Text="{Binding LabelPrintStatus}"
|
||||
Foreground="White"
|
||||
FontWeight="Bold"
|
||||
HorizontalAlignment="Center"/>
|
||||
|
||||
Reference in New Issue
Block a user