临时

parent b2ccb395
using Microsoft.AspNetCore.Http; using FluentValidation.AspNetCore;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Performance.DtoModels; using Performance.DtoModels;
using Performance.Services;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
...@@ -12,10 +14,13 @@ namespace Performance.Api.Controllers ...@@ -12,10 +14,13 @@ namespace Performance.Api.Controllers
public class SecondAllotController : ControllerBase public class SecondAllotController : ControllerBase
{ {
private readonly ClaimService claimService; private readonly ClaimService claimService;
private readonly SecondAllotService secondAllotService;
public SecondAllotController(ClaimService claimService) public SecondAllotController(ClaimService claimService,
SecondAllotService secondAllotService)
{ {
this.claimService = claimService; this.claimService = claimService;
this.secondAllotService = secondAllotService;
} }
/// <summary> /// <summary>
...@@ -27,8 +32,8 @@ public SecondAllotController(ClaimService claimService) ...@@ -27,8 +32,8 @@ public SecondAllotController(ClaimService claimService)
public ApiResponse List() public ApiResponse List()
{ {
var userId = claimService.GetUserId(); var userId = claimService.GetUserId();
var result = secondAllotService.GetSecondList(userId);
return new ApiResponse(ResponseType.OK); return new ApiResponse(ResponseType.OK, result);
} }
/// <summary> /// <summary>
...@@ -59,9 +64,10 @@ public ApiResponse SaveCompute() ...@@ -59,9 +64,10 @@ public ApiResponse SaveCompute()
/// <returns></returns> /// <returns></returns>
[Route("api/second/workload/list")] [Route("api/second/workload/list")]
[HttpPost] [HttpPost]
public ApiResponse WorkloadList() public ApiResponse WorkloadList([CustomizeValidator(RuleSet = "Query"), FromBody]WorkloadRequest request)
{ {
return new ApiResponse(ResponseType.OK); var result = secondAllotService.GetWorkloadList(request.SecondId);
return new ApiResponse(ResponseType.OK, result);
} }
/// <summary> /// <summary>
...@@ -70,9 +76,10 @@ public ApiResponse WorkloadList() ...@@ -70,9 +76,10 @@ public ApiResponse WorkloadList()
/// <returns></returns> /// <returns></returns>
[Route("api/second/workload/add")] [Route("api/second/workload/add")]
[HttpPost] [HttpPost]
public ApiResponse WorkloadAdd() public ApiResponse WorkloadAdd([CustomizeValidator(RuleSet = "Add"), FromBody]WorkloadRequest request)
{ {
return new ApiResponse(ResponseType.OK); var result = secondAllotService.WorkloadAdd(request);
return new ApiResponse(result ? ResponseType.OK : ResponseType.Fail);
} }
/// <summary> /// <summary>
...@@ -81,9 +88,10 @@ public ApiResponse WorkloadAdd() ...@@ -81,9 +88,10 @@ public ApiResponse WorkloadAdd()
/// <returns></returns> /// <returns></returns>
[Route("api/second/workload/update")] [Route("api/second/workload/update")]
[HttpPost] [HttpPost]
public ApiResponse WorkloadUpdate() public ApiResponse WorkloadUpdate([CustomizeValidator(RuleSet = "Update"), FromBody]WorkloadRequest request)
{ {
return new ApiResponse(ResponseType.OK); var result = secondAllotService.WorkloadUpdate(request);
return new ApiResponse(result ? ResponseType.OK : ResponseType.Fail);
} }
/// <summary> /// <summary>
...@@ -92,9 +100,10 @@ public ApiResponse WorkloadUpdate() ...@@ -92,9 +100,10 @@ public ApiResponse WorkloadUpdate()
/// <returns></returns> /// <returns></returns>
[Route("api/second/workload/delete")] [Route("api/second/workload/delete")]
[HttpPost] [HttpPost]
public ApiResponse WorkloadDelete() public ApiResponse WorkloadDelete([CustomizeValidator(RuleSet = "Delete"), FromBody]WorkloadRequest request)
{ {
return new ApiResponse(ResponseType.OK); var result = secondAllotService.WorkloadDelete(request.SecondId);
return new ApiResponse(result ? ResponseType.OK : ResponseType.Fail);
} }
/// <summary> /// <summary>
...@@ -105,7 +114,9 @@ public ApiResponse WorkloadDelete() ...@@ -105,7 +114,9 @@ public ApiResponse WorkloadDelete()
[HttpPost] [HttpPost]
public ApiResponse Temp() public ApiResponse Temp()
{ {
return new ApiResponse(ResponseType.OK); var userId = claimService.GetUserId();
var result = secondAllotService.GetTemp(userId);
return new ApiResponse(ResponseType.OK, result);
} }
/// <summary> /// <summary>
...@@ -114,8 +125,9 @@ public ApiResponse Temp() ...@@ -114,8 +125,9 @@ public ApiResponse Temp()
/// <returns></returns> /// <returns></returns>
[Route("api/temp/usetemp")] [Route("api/temp/usetemp")]
[HttpPost] [HttpPost]
public ApiResponse UseTemp() public ApiResponse UseTemp(UseTempRequest request)
{ {
var result = secondAllotService.UseTemp(request.TempId);
return new ApiResponse(ResponseType.OK); return new ApiResponse(ResponseType.OK);
} }
......
using FluentValidation;
using System;
using System.Collections.Generic;
using System.Text;
namespace Performance.DtoModels
{
public class UseTempRequest
{
public int TempId { get; set; }
}
public class UseTempRequestValidator : AbstractValidator<UseTempRequest>
{
public UseTempRequestValidator()
{
RuleFor(x => x.TempId).NotNull().GreaterThan(0);
}
}
}
using FluentValidation;
using System;
using System.Collections.Generic;
using System.Text;
namespace Performance.DtoModels
{
public class WorkloadRequest
{
/// <summary>
/// 绩效ID
/// </summary>
public int Id { get; set; }
/// <summary>
/// 绩效ID
/// </summary>
public int AllotId { get; set; }
/// <summary>
/// 二次绩效ID
/// </summary>
public int SecondId { get; set; }
/// <summary>
/// 工作量名称
/// </summary>
public string ItemName { get; set; }
/// <summary>
/// 工作量系数
/// </summary>
public Nullable<decimal> FactorValue { get; set; }
/// <summary>
///
/// </summary>
public Nullable<decimal> Sort { get; set; }
}
public class WorkloadRequestValidator : AbstractValidator<WorkloadRequest>
{
public WorkloadRequestValidator()
{
RuleSet("Add", () =>
{
RuleFor(x => x.AllotId).NotNull().GreaterThan(0);
RuleFor(x => x.SecondId).NotNull().GreaterThan(0);
RuleFor(x => x.ItemName).NotNull().NotEmpty();
});
RuleSet("Update", () =>
{
RuleFor(x => x.Id).NotNull().GreaterThan(0);
RuleFor(x => x.AllotId).NotNull().GreaterThan(0);
RuleFor(x => x.SecondId).NotNull().GreaterThan(0);
RuleFor(x => x.ItemName).NotNull().NotEmpty();
});
RuleSet("Delete", () =>
{
RuleFor(x => x.Id).NotNull().GreaterThan(0);
});
RuleSet("Query", () =>
{
RuleFor(x => x.SecondId).NotNull().GreaterThan(0);
});
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Performance.DtoModels.Response
{
public class SecondTempResponse
{
}
}
using Microsoft.Extensions.Options;
using Performance.DtoModels;
using Performance.DtoModels.AppSettings;
using Performance.EntityModels;
using Performance.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Performance.Services
{
public class SecondAllotService : IAutoInjection
{
private readonly Application application;
private readonly PerforUserRepository perforUserRepository;
private readonly PerforUserhospitalRepository perforUserhospitalRepository;
private readonly PerforPerallotRepository perforPerallotRepository;
private readonly PerforAgsecondallotRepository perforAgsecondallotRepository;
private readonly PerforResaccountRepository perforResaccountRepository;
private readonly PerforUserroleRepository userroleRepository;
private readonly PerforAgworkloadRepository perforAgworkloadRepository;
private readonly PerforAgtempRepository perforAgtempRepository;
private readonly PerforAgtempitemRepository perforAgtempitemRepository;
public SecondAllotService(IOptions<Application> application,
PerforUserRepository perforUserRepository,
PerforUserhospitalRepository perforUserhospitalRepository,
PerforPerallotRepository perforPerallotRepository,
PerforAgsecondallotRepository perforAgsecondallotRepository,
PerforResaccountRepository perforResaccountRepository,
PerforUserroleRepository userroleRepository,
PerforAgworkloadRepository perforAgworkloadRepository,
PerforAgtempRepository perforAgtempRepository,
PerforAgtempitemRepository perforAgtempitemRepository)
{
this.application = application.Value;
this.perforUserRepository = perforUserRepository;
this.perforUserhospitalRepository = perforUserhospitalRepository;
this.perforPerallotRepository = perforPerallotRepository;
this.perforAgsecondallotRepository = perforAgsecondallotRepository;
this.perforResaccountRepository = perforResaccountRepository;
this.userroleRepository = userroleRepository;
this.perforAgworkloadRepository = perforAgworkloadRepository;
this.perforAgtempRepository = perforAgtempRepository;
this.perforAgtempitemRepository = perforAgtempitemRepository;
}
public List<ag_secondallot> GetSecondList(int userId)
{
var user = perforUserRepository.GetEntity(t => t.ID == userId);
if (user == null)
throw new NotImplementedException("人员ID无效");
var role = userroleRepository.GetEntity(t => t.UserID == userId);
var hospital = perforUserhospitalRepository.GetEntity(t => t.UserID == userId);
if (hospital == null)
throw new NotImplementedException("人员未选择医院");
var allotList = perforPerallotRepository.GetEntities(t => t.HospitalId == hospital.HospitalID && t.States == 6);
if (allotList == null || allotList.Count == 0)
throw new NotImplementedException("该医院未生成绩效");
var allotListId = allotList.Select(t => t.ID).ToList();
var secondList = perforAgsecondallotRepository.GetEntities(t => allotListId.Contains(t.AllotId.Value) && t.Department == user.Department);
//各科室绩效分配结果
var accountList = perforResaccountRepository.GetEntities(t => allotListId.Contains(t.AllotID.Value) && t.Department == user.Department);
//取得未生成二次绩效的绩效id
var exceptListId = secondList == null ? allotListId : allotListId.Except(secondList.Select(t => t.AllotId.Value));
List<ag_secondallot> newSecond = new List<ag_secondallot>();
foreach (var item in exceptListId)
{
var allot = allotList.FirstOrDefault(t => t.ID == item);
if (allot == null) continue;
res_account account = null;
if (role.RoleID == application.DirectorRole)
account = accountList.FirstOrDefault(t => t.AllotID == item && (t.UnitType == (int)UnitType.医生组 || t.UnitType == (int)UnitType.医技组));
else if (role.RoleID == application.NurseRole)
account = accountList.FirstOrDefault(t => t.AllotID == item && t.UnitType == (int)UnitType.护理组);
if (account == null) continue;
var second = new ag_secondallot
{
AllotId = item,
Year = allot.Year,
Month = allot.Month,
Department = user.Department,
UnitType = ((UnitType)account.UnitType).ToString(),
RealGiveFee = account.RealGiveFee
};
newSecond.Add(second);
}
if (newSecond.Count > 0)
{
perforAgsecondallotRepository.AddRange(newSecond.ToArray());
if (secondList == null)
secondList = newSecond;
else
secondList.AddRange(newSecond);
}
return secondList;
}
public List<ag_temp> GetTemp(int userId)
{
return perforAgtempRepository.GetEntities();
}
public bool UseTemp(int tempId)
{
var temp = perforAgtempRepository.GetEntity(t => t.Id == tempId);
var tempItems = perforAgtempitemRepository.GetEntities(t => t.TempId == tempId);
return ;
}
public List<ag_workload> GetWorkloadList(int secondId)
{
return perforAgworkloadRepository.GetEntities(t => t.SecondId == secondId);
}
public bool WorkloadAdd(WorkloadRequest request)
{
var workloadList = perforAgworkloadRepository.GetEntities(t => t.SecondId == request.SecondId);
if (workloadList.Any(t => t.ItemName == request.ItemName))
throw new PerformanceException("项目名称重复");
ag_workload workload = new ag_workload
{
AllotId = request.AllotId,
FactorValue = request.FactorValue ?? 1,
ItemName = request.ItemName,
SecondId = request.SecondId,
Sort = request.Sort ?? 1,
};
var result = perforAgworkloadRepository.Add(workload);
if (result)
{
workload.ItemId = $"Feild{workload.Id}";
perforAgworkloadRepository.Update(workload);
}
return result;
}
public bool WorkloadUpdate(WorkloadRequest request)
{
var workloadList = perforAgworkloadRepository.GetEntities(t => t.SecondId == request.SecondId);
if (workloadList.Any(t => t.Id != request.Id && t.ItemName == request.ItemName))
throw new PerformanceException("项目名称重复");
var workload = workloadList.FirstOrDefault(t => t.Id == request.Id);
workload.AllotId = request.AllotId;
workload.FactorValue = request.FactorValue;
workload.ItemName = request.ItemName;
workload.SecondId = request.SecondId;
workload.Sort = request.Sort;
workload.ItemId = $"Feild{workload.Id}";
return perforAgworkloadRepository.Update(workload);
}
public bool WorkloadDelete(int id)
{
var workload = perforAgworkloadRepository.GetEntity(t => t.Id == id);
return perforAgworkloadRepository.Remove(workload);
}
}
}
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