Commit 148ac0e2 by lcx

添加字段确定预算年限

parent 903d85ac
......@@ -42,14 +42,15 @@ public ApiResponse<List<BudgetResponse>> Query([FromBody]BudgetRequest request)
/// <summary>
/// 保存预算管理数据
/// </summary>
/// <param name="mainYear"></param>
/// <param name="request"></param>
/// <returns></returns>
[HttpPost]
[Route("save")]
public ApiResponse Save([FromBody]List<BudgetResponse> request)
[Route("save/{mainYear}")]
public ApiResponse Save(int mainYear, [FromBody]List<BudgetResponse> request)
{
var userId = claim.GetUserId();
var result = budgetService.SaveBudgetData(request, userId);
var result = budgetService.SaveBudgetData(mainYear, request, userId);
return result ? new ApiResponse(ResponseType.OK, "保存成功") : new ApiResponse(ResponseType.Fail, "保存失败");
}
......
......@@ -25,9 +25,14 @@ public class per_budget_amount
///
/// </summary>
public int HospitalId { get; set; }
/// <summary>
///
/// 根据该年份测算下一年
/// </summary>
public int MainYear { get; set; }
/// <summary>
/// 实际年份、预算年份
/// </summary>
public int Year { get; set; }
......
......@@ -25,9 +25,14 @@ public class per_budget_ratio
///
/// </summary>
public int HospitalId { get; set; }
/// <summary>
///
/// 根据该年份测算下一年
/// </summary>
public int MainYear { get; set; }
/// <summary>
/// 实际年份、预算年份
/// </summary>
public int Year { get; set; }
......
......@@ -37,9 +37,8 @@ public class BudgetService : IAutoInjection
/// <returns></returns>
public List<BudgetResponse> QueryBudgetByYear(int hospitalid, int year)
{
var nextYear = year + 1;
var amounts = perbudgetamountRepository.GetEntities(t => t.HospitalId == hospitalid && new List<int> { year, nextYear }.Contains(t.Year));
var ratios = perbudgetratioRepository.GetEntities(t => t.HospitalId == hospitalid && new List<int> { year, nextYear }.Contains(t.Year));
var amounts = perbudgetamountRepository.GetEntities(t => t.HospitalId == hospitalid && t.MainYear == year);
var ratios = perbudgetratioRepository.GetEntities(t => t.HospitalId == hospitalid && t.MainYear == year);
var result = Mapper.Map<List<BudgetResponse>>(amounts);
if (result == null)
return Mapper.Map<List<BudgetResponse>>(ratios);
......@@ -56,14 +55,19 @@ public List<BudgetResponse> QueryBudgetByYear(int hospitalid, int year)
/// <param name="request"></param>
/// <param name="userId"></param>
/// <returns></returns>
public bool SaveBudgetData(List<BudgetResponse> request, int userId)
public bool SaveBudgetData(int mainYear, List<BudgetResponse> request, int userId)
{
if (request == null || !request.Any(t => t.Type == 1) || !request.Any(t => t.Type == 2))
throw new PerformanceException("提交数据中含无效数据");
var entity = perbudgetamountRepository.GetEntities(w => w.HospitalId == request.First().HospitalId && w.MainYear == mainYear);
if (entity != null && entity.Any())
throw new PerformanceException($"{mainYear}年数据已存在");
var amounts = Mapper.Map<List<per_budget_amount>>(request.Where(t => t.Type == 1));
amounts.ForEach(t =>
{
t.MainYear = mainYear;
t.CreateTime = DateTime.Now;
t.CreateUser = userId;
});
......@@ -72,6 +76,7 @@ public bool SaveBudgetData(List<BudgetResponse> request, int userId)
var ratios = Mapper.Map<List<per_budget_ratio>>(request.Where(t => t.Type == 2));
ratios.ForEach(t =>
{
t.MainYear = mainYear;
t.CreateTime = DateTime.Now;
t.CreateUser = userId;
});
......@@ -174,8 +179,7 @@ public List<per_budget_result> QueryResultByYear(int hospitalid, int year)
/// <returns></returns>
public List<BudgetRatioResponse> QueryBudgetRatio(int hospitalid, int year)
{
var nextYear = year + 1;
var ratios = perbudgetratioRepository.GetEntities(t => t.HospitalId == hospitalid && new List<int> { year, nextYear }.Contains(t.Year));
var ratios = perbudgetratioRepository.GetEntities(t => t.HospitalId == hospitalid && t.MainYear == year);
if (ratios != null && ratios.Any())
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment