提交
This commit is contained in:
134
api_v1/Appointment.Repository/ApptAuditorRepo.cs
Normal file
134
api_v1/Appointment.Repository/ApptAuditorRepo.cs
Normal file
@@ -0,0 +1,134 @@
|
||||
using Appointment.Entity;
|
||||
using Appointment.IRepository;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Appointment.Repository
|
||||
{
|
||||
public class ApptAuditorRepo : DbContext, IApptAuditorRepo
|
||||
{
|
||||
private List<ApptAuditor> cache = null;
|
||||
|
||||
IApptLogRepo _ApptLogRepo;
|
||||
public ApptAuditorRepo(IApptLogRepo apptLogRepo)
|
||||
{
|
||||
_ApptLogRepo = apptLogRepo;
|
||||
}
|
||||
|
||||
public ApiResult<ApptAuditor> Add(ApptAuditor req)
|
||||
{
|
||||
var apptType = Db.Queryable<ApptType>()
|
||||
.Where(t => t.Id == req.ApptTypeId)
|
||||
.Any();
|
||||
if (!apptType) return ApiResult<ApptAuditor>.Failed($"操作失败,预订类型无效!");
|
||||
|
||||
var groupAny = Db.Queryable<UcGroup>()
|
||||
.Where(t => t.OpGroup == req.OpGroup.Trim() && t.Descript == req.OpDescript.Trim())
|
||||
.Any();
|
||||
if (!groupAny) return ApiResult<ApptAuditor>.Failed($"操作失败,组别无效!");
|
||||
|
||||
cache = Db.Queryable<ApptAuditor>().Where(t => t.ApptTypeId == req.ApptTypeId).ToList();
|
||||
if (req.Pid > 0)
|
||||
{
|
||||
var rootEntity = cache.Where(t => t.Id == req.Pid).FirstOrDefault();
|
||||
if (rootEntity == null) return ApiResult<ApptAuditor>.Failed($"操作失败,上级审核组无效!");
|
||||
}
|
||||
var auditorAny = cache.Where(t => t.Pid == req.Pid).FirstOrDefault();
|
||||
if (auditorAny != null) return ApiResult<ApptAuditor>.Failed($"操作失败,当前位置已经配置了审核组!");
|
||||
|
||||
var result = InsertReturnId(req);
|
||||
if (!result.IsSuccess) return ApiResult<ApptAuditor>.Failed(result.Msg);
|
||||
|
||||
req.Id = result.Info;
|
||||
return ApiResult<ApptAuditor>.Success(string.Empty, req);
|
||||
}
|
||||
|
||||
public ApiResult Delete(int id)
|
||||
{
|
||||
var childData = Db.Queryable<ApptAuditor>().Where(t => t.Pid == id).Any();
|
||||
if (childData) return ApiResult.Failed("操作失败,请先删除子级数据!");
|
||||
|
||||
var apptAuditor = GetById<ApptAuditor>(id);
|
||||
if (apptAuditor == null) return ApiResult.Success(string.Empty);
|
||||
|
||||
var ls = Db.Queryable<ApptSummary>().Where(
|
||||
t => t.ApptTypeId == apptAuditor.ApptTypeId && t.AuditorId == apptAuditor.Id
|
||||
&& t.AuditorStatus == (int)EnumAuditorStatus.审核中)
|
||||
.Select(t => t.Id).ToList();
|
||||
if (ls.Count > 0) return ApiResult.Failed($"操作失败,有待审核的预订[{string.Join(",", ls)}],请审核后再删除!");
|
||||
|
||||
|
||||
_ApptLogRepo.SetLog("ppt_auditor", apptAuditor.Id.ToString(), JsonConvert.SerializeObject(apptAuditor), null, null, 1);
|
||||
DeleteById<ApptSummary>(id);
|
||||
return ApiResult.Success();
|
||||
}
|
||||
|
||||
public ApiResult<ApptAuditor> GetModel(int id)
|
||||
{
|
||||
var entity = GetById<ApptAuditor>(id);
|
||||
|
||||
return ApiResult<ApptAuditor>.Success(string.Empty, entity);
|
||||
}
|
||||
|
||||
public ApiResult<List<ApptAuditor>> GetList(ApptAuditor req)
|
||||
{
|
||||
var ls = Db.Queryable<ApptAuditor>()
|
||||
.Where(t => req.Pid == 0)
|
||||
.WhereIF(req.Id > 0, t => t.Id == req.Id)
|
||||
.WhereIF(req.ApptTypeId > 0, t => t.ApptTypeId == req.ApptTypeId)
|
||||
.WhereIF(!string.IsNullOrWhiteSpace(req.OpGroup), t => t.OpGroup == req.OpGroup)
|
||||
.WhereIF(!string.IsNullOrWhiteSpace(req.OpDescript), t => t.OpDescript.Contains(req.OpDescript))
|
||||
.WhereIF(req.Pid > 0, t => t.Pid == req.Pid)
|
||||
.ToList();
|
||||
|
||||
|
||||
return ApiResult<List<ApptAuditor>>.Success(string.Empty, ls);
|
||||
}
|
||||
|
||||
public ApiResult<PagerData<ApptAuditor>> Page(CommPageReq req)
|
||||
{
|
||||
int total = 0;
|
||||
var ls = Db.Queryable<ApptAuditor>()
|
||||
.WhereIF(!string.IsNullOrWhiteSpace(req.Keywords), t => t.OpDescript.Contains(req.Keywords))
|
||||
.ToPageList(req.PageIndex, req.PageSize, ref total);
|
||||
|
||||
|
||||
PagerData<ApptAuditor> result = new PagerData<ApptAuditor>()
|
||||
{
|
||||
PageIndex = req.PageIndex,
|
||||
PageSize = req.PageSize,
|
||||
Total = total,
|
||||
Data = ls
|
||||
};
|
||||
|
||||
return ApiResult<PagerData<ApptAuditor>>.Success(string.Empty, result);
|
||||
}
|
||||
|
||||
public ApiResult<ApptAuditor> AuditorLine(int apptTypeId)
|
||||
{
|
||||
cache = Db.Queryable<ApptAuditor>().Where(t => t.ApptTypeId == apptTypeId).ToList();
|
||||
if (cache.Count == 0) return ApiResult<ApptAuditor>.Success(string.Empty, null);
|
||||
|
||||
ApptAuditor apptAuditor = cache.Where(t => t.ApptTypeId == apptTypeId && t.Pid == 0).FirstOrDefault();
|
||||
|
||||
if (apptAuditor == null) return ApiResult<ApptAuditor>.Success(string.Empty, null);
|
||||
|
||||
apptAuditor = GetRecursion(apptAuditor);
|
||||
|
||||
return ApiResult<ApptAuditor>.Success(string.Empty, apptAuditor);
|
||||
}
|
||||
|
||||
private ApptAuditor GetRecursion(ApptAuditor req)
|
||||
{
|
||||
var entity = cache.Where(t => t.Pid == req.Id).FirstOrDefault();
|
||||
if (entity == null) return req;
|
||||
|
||||
req.Child = GetRecursion(entity);
|
||||
|
||||
return req;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user