超级管理员操作数据不受时间限制

This commit is contained in:
fuenmao
2025-10-13 09:51:04 +08:00
parent 8d5a094408
commit 21d11a9805
2 changed files with 24 additions and 28 deletions
@@ -53,7 +53,10 @@ public class PrescriptionService : DbRepository<Prescription>, IPrescriptionServ
// 设置可编辑状态
foreach (var item in prescriptionPage.List)
{
item.CanEdit = item.CreateTime.Date == DateTime.Now.Date;
if (item.CreateTime.Date == DateTime.Now.Date || UserManager.SuperAdmin)
{
item.CanEdit = true;
}
}
// 获取当前页所有处方的药材明细
@@ -109,7 +112,6 @@ public class PrescriptionService : DbRepository<Prescription>, IPrescriptionServ
//家属成本多十个点
if (item.PersonType== PersonType.Relative)
{
// 四舍五入规则
item.TotalMedicineCost = Math.Round(item.TotalMedicineCost * (decimal)1.1, 2, MidpointRounding.AwayFromZero);
}
}
@@ -133,7 +135,7 @@ public class PrescriptionService : DbRepository<Prescription>, IPrescriptionServ
// 批量查询所有涉及药材的入库记录(按时间排序)
var addLogs = await Context.Queryable<MedicinalAddLog>()
.Where(l => medicinalIds.Contains(l.MedicinalId))
.OrderBy(l => l.CreateTime) // FIFO核心:按入库时间排序
.OrderBy(l => l.CreateTime)
.Select(l => new MedicinalFifoRecord
{
MedicinalId = l.MedicinalId,
@@ -228,7 +230,7 @@ public class PrescriptionService : DbRepository<Prescription>, IPrescriptionServ
Name = pe.Name
})
.FirstAsync();
employee = empPerson;
}
var RelationShipName = await GetRelationTypes();
@@ -392,7 +394,7 @@ public class PrescriptionService : DbRepository<Prescription>, IPrescriptionServ
};
await Context.Storageable(person).ExecuteCommandAsync();
// ---------- 4. 处方保存/编辑逻辑(沿用原逻辑) ----------
// ---------- 4. 处方保存/编辑逻辑----------
Prescription prescription;
if (input.Id.HasValue) // 编辑
{
@@ -402,7 +404,7 @@ public class PrescriptionService : DbRepository<Prescription>, IPrescriptionServ
if (prescription == null)
throw Oops.Bah("处方不存在");
if (prescription.CreateTime.Value.Date != DateTime.Now.Date)
if (prescription.CreateTime.Value.Date != DateTime.Now.Date && !UserManager.SuperAdmin)
throw Oops.Bah("只能编辑当天的处方");
// 查询原有消耗记录并恢复库存
@@ -415,7 +417,6 @@ public class PrescriptionService : DbRepository<Prescription>, IPrescriptionServ
foreach (var g in oldHerbs.GroupBy(x => x.MedicinalId))
{
// 恢复库存(加回已消耗)
// 注意:使用 Updateable 批量操作替换为 SetColumns 表达式累加数值
await Context.Updateable<Medicinal>()
.SetColumns(m => new Medicinal { Number = m.Number + g.Sum(x => x.AmountG) })
.Where(m => m.Id == g.Key)
@@ -423,7 +424,7 @@ public class PrescriptionService : DbRepository<Prescription>, IPrescriptionServ
}
}
// 删除原有处方药材(物理删除或软删按你系统策略)
// 删除原有处方药材
await Context.Deleteable<PrescriptionHerb>()
.Where(ph => ph.PrescriptionId == input.Id.Value)
.ExecuteCommandAsync();