Commit e119d335 by lcx

申请划拨、申请划拨信息修改

parent 1482949b
......@@ -16,7 +16,7 @@ public class CostTransferItemRequest
public decimal? CalculationAmount { get; set; }
public bool IsUseRatio { get; set; }
public int IsUseRatio { get; set; }
public string Remark { get; set; }
}
......
using System;
using Performance.EntityModels;
using System;
using System.Collections.Generic;
using System.Text;
......@@ -6,6 +7,8 @@ namespace Performance.DtoModels
{
public class CostTransferRequest
{
public int AllotId { get; set; }
public Department Applicant { get; set; }
public Department Adopted { get; set; }
......@@ -19,4 +22,11 @@ public class Department
public string AccountingUnit { get; set; }
}
public class CostTransferUpdateRequest : CostTransferRequest
{
public int TransferId { get; set; }
public new List<cost_transfer_item> Items { get; set; }
}
}
......@@ -46,7 +46,7 @@ public class cost_transfer
public string AdoptedAccountingUnit { get; set; }
/// <summary>
/// 0 未审核 1 部分审核 2 全部审核
/// 0 未审核 1 部分审核 2 全部审核 3 未含有划拨明细
/// </summary>
public int Status { get; set; }
}
......
......@@ -60,5 +60,10 @@ public class cost_transfer_item
/// 备注
/// </summary>
public string Remark { get; set; }
/// <summary>
/// 0 默认 1 通过 2 驳回 3 下发驳回
/// </summary>
public int Status { get; set; }
}
}
//-----------------------------------------------------------------------
// <copyright file=" cost_transfer.cs">
// * FileName: cost_transfer.cs
// </copyright>
//-----------------------------------------------------------------------
using Performance.EntityModels;
namespace Performance.Repository
{
/// <summary>
/// cost_transfer Repository
/// </summary>
public partial class PerforCosttransferRepository : PerforRepository<cost_transfer>
{
public PerforCosttransferRepository(PerformanceDbContext context) : base(context)
{
}
}
}
//-----------------------------------------------------------------------
// <copyright file=" cost_transfer_item.cs">
// * FileName: cost_transfer_item.cs
// </copyright>
//-----------------------------------------------------------------------
using Performance.EntityModels;
namespace Performance.Repository
{
/// <summary>
/// cost_transfer_item Repository
/// </summary>
public partial class PerforCosttransferitemRepository : PerforRepository<cost_transfer_item>
{
public PerforCosttransferitemRepository(PerformanceDbContext context) : base(context)
{
}
}
}
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.Extensions.Logging;
using Performance.DtoModels;
using Performance.EntityModels;
using Performance.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Performance.Services
{
public class CostTransferService : IAutoInjection
{
private readonly ILogger<CostTransferService> logger;
private readonly PerforCosttransferRepository costtransferRepository;
private readonly PerforCosttransferitemRepository costtransferitemRepository;
public CostTransferService(
ILogger<CostTransferService> logger,
PerforCosttransferRepository costtransferRepository,
PerforCosttransferitemRepository costtransferitemRepository
)
{
this.logger = logger;
this.costtransferRepository = costtransferRepository;
this.costtransferitemRepository = costtransferitemRepository;
}
/// <summary>
/// 申请划拨
/// </summary>
public bool Applicat(CostTransferRequest request)
{
if (request.AllotId == 0)
throw new PerformanceException("参数错误,绩效记录不存在");
if (request.Applicant == null || request.Adopted == null)
throw new PerformanceException("参数错误,申请/被划拨科室信息缺失");
if (string.IsNullOrEmpty(request.Applicant.UnitType) || string.IsNullOrEmpty(request.Applicant.AccountingUnit))
throw new PerformanceException("参数错误,申请科室信息缺失");
if (string.IsNullOrEmpty(request.Adopted.UnitType) || string.IsNullOrEmpty(request.Adopted.AccountingUnit))
throw new PerformanceException("参数错误,被划拨科室信息缺失");
var transfer = new cost_transfer
{
AllotId = request.AllotId,
ApplicantAccountingUnit = request.Applicant.AccountingUnit,
ApplicantUnitType = request.Applicant.UnitType,
AdoptedAccountingUnit = request.Adopted.AccountingUnit,
AdoptedUnitType = request.Adopted.UnitType,
Status = (request.Items != null && request.Items.Any()) ? 0 : 3
};
var result = costtransferRepository.Add(transfer);
if (!result)
throw new PerformanceException("提交申请失败,请重试");
if (request.Items == null || !request.Items.Any())
return result;
var items = request.Items.Select(t => new cost_transfer_item
{
TransferId = transfer.Id,
Source = t.Source,
Category = t.Source,
Amount = t.Amount,
Ratio = t.Ratio,
CalculationAmount = t.CalculationAmount,
IsUseRatio = t.IsUseRatio,
Remark = t.Remark,
Status = 0
}).ToArray();
result = costtransferitemRepository.AddRange(items);
if (!result)
costtransferRepository.Remove(transfer);
return result;
}
/// <summary>
/// 申请划拨信息修改
/// </summary>
public void UpdateApplicat(CostTransferUpdateRequest request)
{
var transfer = costtransferRepository.GetEntity(t => t.Id == request.TransferId);
if (transfer == null)
throw new PerformanceException("划拨申请记录不存在");
transfer.AllotId = request.AllotId;
transfer.ApplicantAccountingUnit = request.Applicant.AccountingUnit;
transfer.ApplicantUnitType = request.Applicant.UnitType;
transfer.AdoptedAccountingUnit = request.Adopted.AccountingUnit;
transfer.AdoptedUnitType = request.Adopted.UnitType;
var result = costtransferRepository.Update(transfer);
if (!result)
throw new PerformanceException("修改划拨申请记录失败");
var items = costtransferitemRepository.GetEntities(t => t.TransferId == request.TransferId);
if (items == null)
{
if (request.Items != null && request.Items.Any())
{
request.Items.ForEach(t =>
{
t.Id = 0;
t.TransferId = request.TransferId;
t.Status = 0;
});
costtransferitemRepository.AddRange(request.Items.ToArray());
}
}
else
{
if (request.Items == null || !request.Items.Any())
costtransferitemRepository.RemoveRange(items.ToArray());
else
{
if (request.Items.Any(t => t.Id > 0))
{
var hasPrimaryValueItmes = request.Items.Where(t => t.Id > 0).ToList();
// 删除
var notExistItems = items.Where(item => !hasPrimaryValueItmes.Select(t => t.Id).Contains(item.Id));
if (notExistItems != null && notExistItems.Any())
costtransferitemRepository.RemoveRange(notExistItems.ToArray());
// 更新
var updateItems = items.Where(item => hasPrimaryValueItmes.Select(t => t.Id).Contains(item.Id));
foreach (var update in updateItems)
{
var item = hasPrimaryValueItmes.FirstOrDefault(t => t.Id == update.Id);
update.Source = item.Source;
update.Category = item.Source;
update.Amount = item.Amount;
update.Ratio = item.Ratio;
update.CalculationAmount = item.CalculationAmount;
update.IsUseRatio = item.IsUseRatio;
update.Remark = item.Remark;
hasPrimaryValueItmes.Remove(item);
}
costtransferitemRepository.UpdateRange(updateItems.ToArray());
// 添加
if (hasPrimaryValueItmes != null && hasPrimaryValueItmes.Any())
{
hasPrimaryValueItmes.ForEach(t =>
{
t.Id = 0;
t.TransferId = request.TransferId;
t.Status = 0;
});
costtransferitemRepository.AddRange(hasPrimaryValueItmes.ToArray());
}
}
if (request.Items.Any(t => t.Id == 0)) // 添加
{
costtransferitemRepository.AddRange(request.Items.Where(t => t.Id == 0).ToArray());
}
}
}
UpdateCostTransferStatus(request.TransferId);
}
/// <summary>
/// 删除划拨申请记录
/// </summary>
public void DeleteApplicat()
{
}
/// <summary>
/// 划拨审核
/// </summary>
public void CostTransferAudit()
{
}
/// <summary>
/// 下发驳回
/// </summary>
public bool RejectedApplicat()
{
return false;
}
/// <summary>
/// 修改申请记录的状态
/// </summary>
/// <param name="transferId"></param>
public void UpdateCostTransferStatus(int transferId)
{
try
{
var transfer = costtransferRepository.GetEntity(t => t.Id == transferId);
if (transfer == null) return;
var items = costtransferitemRepository.GetEntities(t => t.TransferId == transferId);
switch (items)
{
case var data when data == null || !data.Any():
transfer.Status = 3;
break;
case var data when !data.Any(t => t.Status == 0):
transfer.Status = 2;
break;
case var data when data.Any(t => t.Status == 0) && data.Any(t => t.Status != 0):
transfer.Status = 1;
break;
case var data when !data.Any(t => t.Status != 0):
transfer.Status = 0;
break;
default:
break;
}
costtransferRepository.Update(transfer);
}
catch (Exception ex)
{
logger.LogError($"修改申请记录的状态异常:{ex}");
}
}
}
}
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