Compare commits

...

2 Commits

Author SHA1 Message Date
quowingwang
5d847999b7 BUG修改 2026-01-23 21:14:11 +08:00
quowingwang
79d4c95be1 修改BUG 2026-01-23 21:05:58 +08:00
5 changed files with 37 additions and 27 deletions

View File

@ -18,7 +18,7 @@ namespace MDM.Model.Material.Dto
public class MaterialBomDto
{
[Required(ErrorMessage = "雪花id不能为空")]
public int Id { get; set; }
public string Id { get; set; }
public string? InvCode { get; set; }

View File

@ -21,7 +21,7 @@ namespace MDM.Model.Material.Dto
public class MaterialListDto
{
[Required(ErrorMessage = "雪花id不能为空")]
public int Id { get; set; }
public string Id { get; set; }
public string? FkMaterialTypeCode { get; set; }

View File

@ -63,7 +63,7 @@ namespace MDM.Model.Material
/// CreatedTime
/// </summary>
[SugarColumn(ColumnName = "created_time")]
public DateTime? CreatedTime { get; set; }
public DateTime CreatedTime { get; set; }
/// <summary>
/// UpdatedBy

View File

@ -52,34 +52,43 @@ namespace MDM.Services.Material
{
var predicate = Expressionable.Create<MaterialBom>()
.AndIF(!string.IsNullOrEmpty(parm.InvCode), it => it.InvCode.Contains(parm.InvCode))
.AndIF(!string.IsNullOrEmpty(parm.SubInvCode), it => it.SubInvCode.Contains(parm.SubInvCode))
;
.AndIF(!string.IsNullOrEmpty(parm.SubInvCode), it => it.SubInvCode.Contains(parm.SubInvCode));
var query = Context.Queryable<MaterialBom>()
.Where(predicate.ToExpression())
.GroupBy(it => it.InvCode)
.Select(it => new MaterialBomDto()
{
.Where(predicate.ToExpression())
.GroupBy(it => it.InvCode)
.Select(it => new MaterialBomDto()
{
Id = SqlFunc.AggregateMax(it.Id),
InvCode = SqlFunc.AggregateMax(it.InvCode),
InvName = SqlFunc.AggregateMax(it.InvName),
SubInvName = SqlFunc.AggregateMax(it.SubInvName),
Iusequantity = SqlFunc.AggregateMax(it.Iusequantity),
BOMVersion = SqlFunc.AggregateMax(it.BOMVersion),
CreatedBy = SqlFunc.AggregateMax(it.CreatedBy),
// 改动1注释掉CreatedTime聚合临时避开
// CreatedTime = SqlFunc.AggregateMax(it.CreatedTime),
UpdatedBy = SqlFunc.AggregateMax(it.UpdatedBy),
UpdatedTime = SqlFunc.AggregateMax(it.UpdatedTime)
})
// 改动2手动指定用UpdatedTime数据库列updated_time排序避开CreatedTime
.OrderBy("MAX(updated_time) DESC");
//Id = SqlFunc.AggregateMax(it.Id),
InvCode = it.InvCode,
InvName = SqlFunc.AggregateMax(it.InvName),
SubInvName = SqlFunc.AggregateMax(it.SubInvName),
Iusequantity = SqlFunc.AggregateMax(it.Iusequantity),
BOMVersion = SqlFunc.AggregateMax(it.BOMVersion),
CreatedBy = SqlFunc.AggregateMax(it.CreatedBy),
CreatedTime = SqlFunc.AggregateMax(it.CreatedTime),
UpdatedBy = SqlFunc.AggregateMax(it.UpdatedBy),
UpdatedTime = SqlFunc.AggregateMax(it.UpdatedTime)
}).OrderBy("created_time DESC"); // 核心修复:手动指定数据库列名排序;
var response = query.ToPage<MaterialBomDto, MaterialBomDto>(parm);
// 匹配你的PagedInfo类的分页逻辑
int pageIndex = 1;
int pageSize = 10;
int totalNum = query.Count();
var response = new PagedInfo<MaterialBomDto>()
{
PageIndex = pageIndex,
PageSize = pageSize,
TotalNum = totalNum,
Result = query.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList(),
Extra = new Dictionary<string, object>()
};
return response;
}
/// <summary>
@ -157,10 +166,10 @@ namespace MDM.Services.Material
//目前没加物料是否正确校验
if (currentRow != null && currentRow.GetCell(0) != null) // 确保行不为空
{
MaterialBom item = new MaterialBom();
item.Id = XueHua;
//母件编码
if (currentRow.GetCell(0) != null && currentRow.GetCell(0).CellType == CellType.String)
item.InvCode = currentRow.GetCell(0).ToString();

View File

@ -109,7 +109,7 @@ namespace MDM.Services.Material
try
{
IWorkbook workbook = new XSSFWorkbook(stream);
ISheet sheet = workbook.GetSheet("物料类型");
ISheet sheet = workbook.GetSheet("物料台账");
List<MaterialList> materialLists = new List<MaterialList>();
// 遍历每一行
for (int row = 1; row <= sheet.LastRowNum; row++)
@ -118,6 +118,7 @@ namespace MDM.Services.Material
if (currentRow != null && currentRow.GetCell(0) != null) // 确保行不为空
{
MaterialList item = new MaterialList();
item.Id = XueHua;
//物料类型code
if (currentRow.GetCell(0) != null && currentRow.GetCell(0).CellType == CellType.String)
item.FkMaterialTypeCode = currentRow.GetCell(0).ToString();