//
namespace SafeCampus.System;
///
///
///
public class IndexService : DbRepository, IIndexService
{
private readonly IRelationService _relationService;
public IndexService(IRelationService relationService)
{
_relationService = relationService;
}
///
public async Task> ScheduleList(ScheduleListInput input)
{
var relations = await GetListAsync(
it => it.Category == CateGoryConst.RELATION_SYS_USER_SCHEDULE_DATA && it.ObjectId == UserManager.UserId
&& it.TargetId == input.ScheduleDate,
it => new SysRelation { ExtJson = it.ExtJson, Id = it.Id });//获取当前用户的日程列表
var userSchedules = new List();//结果集
relations.ForEach(it =>
{
var extJson = it.ExtJson.ToJsonEntity();//转成实体
var userSchedule = extJson.Adapt();//格式化
userSchedule.Id = it.Id;//赋值ID
userSchedules.Add(userSchedule);//添加到结果集
});
return userSchedules;
}
///
public async Task AddSchedule(ScheduleAddInput input)
{
input.ScheduleUserId = UserManager.UserId;
input.ScheduleUserName = UserManager.Name;
//添加日程
await _relationService.SaveRelation(CateGoryConst.RELATION_SYS_USER_SCHEDULE_DATA, UserManager.UserId, input.ScheduleDate, input.ToJson(),
false, false);
}
///
public async Task DeleteSchedule(BaseIdListInput input)
{
//获取所有ID
var ids = input.Ids;
await DeleteAsync(it => ids.Contains(it.Id) && it.ObjectId == UserManager.UserId);
}
}