You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
243 lines
9.4 KiB
243 lines
9.4 KiB
namespace Tiobon.Core.Services;
|
|
|
|
/// <summary>
|
|
/// 问卷调查 (服务)
|
|
/// </summary>
|
|
public class Ghre_SurveyServices : BaseServices<Ghre_Survey, Ghre_SurveyDto, InsertGhre_SurveyInput, EditGhre_SurveyInput>, IGhre_SurveyServices
|
|
{
|
|
private readonly IBaseRepository<Ghre_Survey> _dal;
|
|
public Ghre_SurveyServices(ICaching caching, IBaseRepository<Ghre_Survey> dal)
|
|
{
|
|
this._dal = dal;
|
|
base.BaseDal = dal;
|
|
base._caching = caching;
|
|
}
|
|
|
|
|
|
public override async Task<ServicePageResult<Ghre_SurveyDto>> QueryFilterPage(QueryBody filter, string condition, bool? IsEnable = true)
|
|
{
|
|
|
|
var result = await base.QueryFilterPage(filter, condition, IsEnable);
|
|
|
|
return result;
|
|
}
|
|
|
|
public override async Task<long> Add(InsertGhre_SurveyInput entity)
|
|
{
|
|
var result = await base.Add(entity);
|
|
|
|
return result;
|
|
}
|
|
|
|
public override async Task<bool> Update(long Id, EditGhre_SurveyInput editModel)
|
|
{
|
|
var result = await base.Update(Id, editModel, null, ["Status"]);
|
|
return result;
|
|
}
|
|
|
|
public override async Task<ServiceFormResult<Ghre_SurveyDto>> QueryForm(QueryForm body)
|
|
{
|
|
var result = await base.QueryForm(body);
|
|
return result;
|
|
}
|
|
|
|
public async Task<ServiceResult<InsertGhre_SurveyExtend>> QueryData(long id)
|
|
{
|
|
var entity = await base.QueryById(id);
|
|
var data = Mapper.Map(entity).ToANew<InsertGhre_SurveyExtend>();
|
|
|
|
data.BeginEndTime.Add(data.BeginTime);
|
|
data.BeginEndTime.Add(data.EndTime);
|
|
if (entity.StaffId.IsNotEmptyOrNull())
|
|
data.StaffIds = JsonHelper.JsonToObj<List<int>>(entity.StaffId);
|
|
if (entity.DeptId.IsNotEmptyOrNull())
|
|
data.DeptIds = JsonHelper.JsonToObj<List<int>>(entity.DeptId);
|
|
|
|
var questions = await Db.Queryable<Ghre_SurveyQuestion>().OrderBy(x => x.SortNo).Where(x => x.SurveyId == id).ToListAsync();
|
|
var options = await Db.Queryable<Ghre_SurveyOption>().OrderBy(x => x.SortNo).Where(x => x.SurveyId == id).ToListAsync();
|
|
|
|
data.Questions = Mapper.Map(questions).ToANew<List<InsertGhre_SurveyQuestionExtend>>();
|
|
data.Questions.ForEach(x =>
|
|
{
|
|
x.Options = Mapper.Map(options.Where(o => o.SurveyQuestionId == x.Id)).ToANew<List<InsertGhre_SurveyOptionExtend>>();
|
|
});
|
|
return ServiceResult<InsertGhre_SurveyExtend>.OprateSuccess("成功", data);
|
|
}
|
|
public async Task<ServiceResult<long>> InsertByStatus(InsertGhre_SurveyInput insertModel, string status)
|
|
{
|
|
|
|
var data = ServiceResult<long>.OprateSuccess("新增成功", 0);
|
|
insertModel.Status = status;
|
|
var id = await Add(insertModel);
|
|
|
|
data.Success = id > 0;
|
|
if (data.Success)
|
|
data.Data = id;
|
|
else
|
|
return ServiceResult<long>.OprateFailed("失败!");
|
|
|
|
return data;
|
|
}
|
|
|
|
public async Task<ServiceResult> UpdateStatus(InsertGhre_SurveyInput input, string status)
|
|
{
|
|
|
|
HttpRequest request = UserContext.Context.Request;
|
|
var api = request.Path.ObjToString().TrimEnd('/').ToLower();
|
|
var ip = GetUserIp(UserContext.Context);
|
|
|
|
var entities = new List<Ghre_Survey>();
|
|
foreach (var id in input.Ids)
|
|
{
|
|
if (!BaseDal.Any(id))
|
|
continue;
|
|
|
|
var entity = await BaseDal.QueryById(id);
|
|
|
|
entity.UpdateIP = ip;
|
|
entity.UpdateProg = api;
|
|
entity.Status = status;
|
|
entities.Add(entity);
|
|
}
|
|
|
|
var result = await BaseDal.Update(entities);
|
|
return ServiceResult.OprateSuccess("执行成功!");
|
|
|
|
}
|
|
|
|
|
|
public async Task<ServiceResult<long>> InsertData(long id, InsertGhre_SurveyExtend insertModel)
|
|
{
|
|
|
|
if (insertModel.BeginEndTime != null && insertModel.BeginEndTime.Count == 2)
|
|
{
|
|
insertModel.BeginTime = insertModel.BeginEndTime[0];
|
|
insertModel.EndTime = insertModel.BeginEndTime[1];
|
|
}
|
|
|
|
var data = ServiceResult<long>.OprateSuccess("新增成功", id);
|
|
if (id == 0)
|
|
{
|
|
|
|
var insert = Mapper.Map(insertModel).ToANew<InsertGhre_SurveyInput>();
|
|
insert.Status = "Temporary";
|
|
|
|
if (insertModel.StaffIds != null && insertModel.StaffIds.Any())
|
|
insert.StaffId = JsonHelper.ObjToJson(insertModel.StaffIds);
|
|
|
|
if (insertModel.DeptIds != null && insertModel.DeptIds.Any())
|
|
insert.DeptId = JsonHelper.ObjToJson(insertModel.DeptIds);
|
|
|
|
id = await Add(insert);
|
|
|
|
for (int i = 0; i < insertModel.Questions.Count; i++)
|
|
{
|
|
var question = Mapper.Map(insertModel.Questions[i]).ToANew<Ghre_SurveyQuestion>();
|
|
//question.Id = SnowFlakeSingle.instance.getID();
|
|
|
|
question.SurveyId = id;
|
|
question.SortNo = i;
|
|
var questionId = await Db.Insertable(question).ExecuteReturnSnowflakeIdAsync();
|
|
|
|
for (int j = 0; j < insertModel.Questions[i].Options.Count; j++)
|
|
{
|
|
var option = Mapper.Map(insertModel.Questions[i].Options[j]).ToANew<Ghre_SurveyOption>();
|
|
option.SurveyId = id;
|
|
option.SurveyQuestionId = questionId;
|
|
option.SortNo = j;
|
|
await Db.Insertable(option).ExecuteReturnSnowflakeIdAsync();
|
|
}
|
|
}
|
|
data.Data = id;
|
|
}
|
|
else
|
|
{
|
|
await Db.Deleteable<Ghre_SurveyQuestion>().Where(x => x.SurveyId == id).ExecuteCommandAsync();
|
|
await Db.Deleteable<Ghre_SurveyOption>().Where(x => x.SurveyId == id).ExecuteCommandAsync();
|
|
|
|
|
|
var insert = Mapper.Map(insertModel).ToANew<EditGhre_SurveyInput>();
|
|
|
|
|
|
if (insertModel.StaffIds != null && insertModel.StaffIds.Any())
|
|
insert.StaffId = JsonHelper.ObjToJson(insertModel.StaffIds);
|
|
|
|
if (insertModel.DeptIds != null && insertModel.DeptIds.Any())
|
|
insert.DeptId = JsonHelper.ObjToJson(insertModel.DeptIds);
|
|
await Update(id, insert, null, ["Status"]);
|
|
|
|
for (int i = 0; i < insertModel.Questions.Count; i++)
|
|
{
|
|
var question = Mapper.Map(insertModel.Questions[i]).ToANew<Ghre_SurveyQuestion>();
|
|
//question.Id = SnowFlakeSingle.instance.getID();
|
|
|
|
question.SurveyId = id;
|
|
var questionId = await Db.Insertable(question).ExecuteReturnSnowflakeIdAsync();
|
|
|
|
for (int j = 0; j < insertModel.Questions[i].Options.Count; j++)
|
|
{
|
|
var option = Mapper.Map(insertModel.Questions[i].Options[j]).ToANew<Ghre_SurveyOption>();
|
|
option.SurveyId = id;
|
|
option.SurveyQuestionId = questionId;
|
|
await Db.Insertable(option).ExecuteReturnSnowflakeIdAsync();
|
|
}
|
|
}
|
|
data.Message = "修改成功!";
|
|
}
|
|
return data;
|
|
}
|
|
|
|
|
|
public async Task<ServiceResult<Ghre_SurveyExtend>> QueryESSData(long id)
|
|
{
|
|
var entity = await base.QueryById(id);
|
|
var data = Mapper.Map(entity).ToANew<Ghre_SurveyExtend>();
|
|
|
|
data.BeginEndTime.Add(data.BeginTime);
|
|
data.BeginEndTime.Add(data.EndTime);
|
|
if (entity.StaffId.IsNotEmptyOrNull())
|
|
data.StaffIds = JsonHelper.JsonToObj<List<int>>(entity.StaffId);
|
|
if (entity.DeptId.IsNotEmptyOrNull())
|
|
data.DeptIds = JsonHelper.JsonToObj<List<int>>(entity.DeptId);
|
|
|
|
var questions = await Db.Queryable<Ghre_SurveyQuestion>().OrderBy(x => x.SortNo).Where(x => x.SurveyId == id).ToListAsync();
|
|
var options = await Db.Queryable<Ghre_SurveyOption>().OrderBy(x => x.SortNo).Where(x => x.SurveyId == id).ToListAsync();
|
|
|
|
data.Questions = Mapper.Map(questions).ToANew<List<Ghre_SurveyQuestionExtend>>();
|
|
data.Questions.ForEach(x =>
|
|
{
|
|
x.Options = Mapper.Map(options.Where(o => o.SurveyQuestionId == x.Id)).ToANew<List<Ghre_SurveyOptionExtend>>();
|
|
});
|
|
|
|
#region 是否存在已提交问卷数据
|
|
data.IsSubmit = await Db.Queryable<Ghre_SurveyRecord>().Where(x => x.StaffId == App.User.StaffId && x.SurveyId == id).AnyAsync();
|
|
#endregion
|
|
|
|
return ServiceResult<Ghre_SurveyExtend>.OprateSuccess("成功", data);
|
|
}
|
|
|
|
|
|
public async Task<ServiceResult<Ghre_SurveyExtend>> SubmitESSData(long id)
|
|
{
|
|
var entity = await base.QueryById(id);
|
|
var data = Mapper.Map(entity).ToANew<Ghre_SurveyExtend>();
|
|
|
|
data.BeginEndTime.Add(data.BeginTime);
|
|
data.BeginEndTime.Add(data.EndTime);
|
|
if (entity.StaffId.IsNotEmptyOrNull())
|
|
data.StaffIds = JsonHelper.JsonToObj<List<int>>(entity.StaffId);
|
|
if (entity.DeptId.IsNotEmptyOrNull())
|
|
data.DeptIds = JsonHelper.JsonToObj<List<int>>(entity.DeptId);
|
|
|
|
var questions = await Db.Queryable<Ghre_SurveyQuestion>().OrderBy(x => x.SortNo).Where(x => x.SurveyId == id).ToListAsync();
|
|
var options = await Db.Queryable<Ghre_SurveyOption>().OrderBy(x => x.SortNo).Where(x => x.SurveyId == id).ToListAsync();
|
|
|
|
data.Questions = Mapper.Map(questions).ToANew<List<Ghre_SurveyQuestionExtend>>();
|
|
data.Questions.ForEach(x =>
|
|
{
|
|
x.Options = Mapper.Map(options.Where(o => o.SurveyQuestionId == x.Id)).ToANew<List<Ghre_SurveyOptionExtend>>();
|
|
});
|
|
return ServiceResult<Ghre_SurveyExtend>.OprateSuccess("成功", data);
|
|
}
|
|
|
|
} |