Update Happiness Task
This commit is contained in:
@@ -13,6 +13,7 @@ using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Drawing.Processing;
|
||||
using SixLabors.ImageSharp.Formats;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
using WebAPI.Logics;
|
||||
using WebAPI.Logics.Interface;
|
||||
|
||||
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
|
||||
@@ -24,19 +25,19 @@ namespace WebAPI.Controllers
|
||||
public class BestController : ApiControllerBase<HappinessBEST>
|
||||
{
|
||||
private readonly ICrudLogic<HappinessBEST> logic;
|
||||
private readonly ICrudLogic<HappinessGroup> groupLogic;
|
||||
private readonly ICrudLogic<HappinessWeek> weekLogic;
|
||||
private readonly PastoralDomainLogic cellGroupLogic;
|
||||
|
||||
public BestController(
|
||||
ICrudLogic<HappinessBEST> logic,
|
||||
ICrudLogic<HappinessGroup> groupLogic,
|
||||
ICrudLogic<HappinessWeek> weekLogic
|
||||
ICrudLogic<HappinessWeek> weekLogic,
|
||||
PastoralDomainLogic cellGroupLogic
|
||||
|
||||
) : base(logic)
|
||||
{
|
||||
this.logic = logic;
|
||||
this.groupLogic = groupLogic;
|
||||
this.weekLogic = weekLogic;
|
||||
this.cellGroupLogic = cellGroupLogic;
|
||||
}
|
||||
|
||||
// GET api/<BestController>/5
|
||||
@@ -49,8 +50,8 @@ namespace WebAPI.Controllers
|
||||
{
|
||||
return Task<HappinessBEST>.Run(() => {
|
||||
var best = logic.GetById(id);
|
||||
best.HappinessGroup = groupLogic.GetById(best.GroupId);
|
||||
best.HappinessGroup.Weeks = weekLogic.GetAll(w => w.GroupId == best.GroupId).OrderBy(w=>w.SEQ).ToList();
|
||||
best.HappinessGroup = cellGroupLogic.GetById(best.GroupId);
|
||||
best.HappinessGroup.HappinessWeeks = weekLogic.GetAll(w => w.GroupId == best.GroupId).OrderBy(w=>w.SEQ).ToList();
|
||||
return best;
|
||||
});
|
||||
}
|
||||
@@ -91,6 +92,13 @@ namespace WebAPI.Controllers
|
||||
|
||||
return this.NotFound();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public int UpdateBestWeek(HappinessWeek week)
|
||||
{
|
||||
return weekLogic.CreateOrUpdate(week,out string id);
|
||||
}
|
||||
|
||||
private Font arialFont;
|
||||
[NonAction]
|
||||
public Image Superimpose(string bestName, Image largeBmp, Image smallBmp, int? x = null, int? y = null)
|
||||
|
||||
@@ -18,12 +18,12 @@ namespace WebAPI.Controllers
|
||||
[ApiController]
|
||||
public class CellGroupRoutineEventsController : ApiControllerBase<CellGroupRoutineEvent>
|
||||
{
|
||||
private readonly CellGroupLogic logic;
|
||||
private readonly PastoralDomainLogic logic;
|
||||
private readonly ICombinedKeyCrudLogic<CellGroupRoutineEventPrayer> prayerLogic;
|
||||
private readonly ICombinedKeyCrudLogic<CellGroupRoutineEventAttendee> dinnerLogic;
|
||||
|
||||
public CellGroupRoutineEventsController(
|
||||
CellGroupLogic logic,
|
||||
PastoralDomainLogic logic,
|
||||
ICrudLogic<CellGroupRoutineEvent> crudLogic,
|
||||
ICombinedKeyCrudLogic<CellGroupRoutineEventPrayer> prayerLogic,
|
||||
ICombinedKeyCrudLogic<CellGroupRoutineEventAttendee> dinnerLogic
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Church.Net.DAL.EF;
|
||||
using Church.Net.Entity;
|
||||
using Church.Net.Utility;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using WebAPI.Logics;
|
||||
using WebAPI.Logics.Interface;
|
||||
|
||||
namespace WebAPI.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("[controller]/[action]")]
|
||||
public class HappinessGroupController : ApiControllerBase<HappinessGroup>
|
||||
{
|
||||
|
||||
private readonly HappinessGroupLogic logic;
|
||||
|
||||
public HappinessGroupController(
|
||||
ICrudLogic<HappinessGroup> crudLogic,
|
||||
HappinessGroupLogic logic
|
||||
):base(crudLogic)
|
||||
{
|
||||
this.logic = logic;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public override async Task<IEnumerable<HappinessGroup>> GetAll()
|
||||
{
|
||||
return await Task.Run(() => { return logic.GetAllGroups(); });
|
||||
}
|
||||
[HttpPost]
|
||||
public virtual async Task<int> UpdateBestWeek(HappinessWeek entity)
|
||||
{
|
||||
return await Task.Run(() => {
|
||||
return logic.UpdateWeekInfo(entity);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using Church.Net.Entity;
|
||||
using Church.Net.Entity.Messenger;
|
||||
using LineMessaging;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using WebAPI.Logics;
|
||||
using WebAPI.Logics.Interface;
|
||||
|
||||
namespace WebAPI.Controllers
|
||||
{
|
||||
[Route("[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class HappinessWeekTaskController : ApiControllerBase<HappinessTask>
|
||||
{
|
||||
public HappinessWeekTaskController(ICrudLogic<HappinessTask> logic) : base(logic)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -22,6 +22,8 @@ using System.Text;
|
||||
using WebAPI.Services;
|
||||
using Jint.Native;
|
||||
using WebAPI.Services.Interfaces;
|
||||
using Church.Net.DAL.EFCoreDBF.Migrations;
|
||||
using Church.Net.DAL.EFCoreDBF;
|
||||
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
|
||||
|
||||
namespace WebAPI.Controllers
|
||||
@@ -33,15 +35,17 @@ namespace WebAPI.Controllers
|
||||
{
|
||||
private readonly LineAutoBotService lineAutoBotService;
|
||||
private readonly ILoggingService loggingService;
|
||||
|
||||
private readonly ICrudDAL<LineMessagingAccount> crudDAL;
|
||||
|
||||
public LineMessageController(
|
||||
LineAutoBotService lineAutoBotService,
|
||||
ILoggingService loggingService
|
||||
ILoggingService loggingService,
|
||||
ICrudDAL<LineMessagingAccount> crudDAL
|
||||
)
|
||||
{
|
||||
this.lineAutoBotService = lineAutoBotService;
|
||||
this.loggingService = loggingService;
|
||||
this.crudDAL = crudDAL;
|
||||
}
|
||||
//private ChurchNetContext dbContext = new ChurchNetContext();
|
||||
//// GET: api/<BestController>
|
||||
@@ -65,20 +69,21 @@ namespace WebAPI.Controllers
|
||||
|
||||
// POST api/<BestController>
|
||||
[HttpPost]
|
||||
//[Route("[controller]/[action]")]
|
||||
//[Route("[controller]/[action]/{id?}")]
|
||||
public async Task PostFromLine(string id, [FromBody] object jsonData)
|
||||
public async Task PostFromLine(int seq, [FromBody] object jsonData)
|
||||
{
|
||||
//string txtPath = ServerUtils.MapPath("App_Data/LinePostRawLog.txt");
|
||||
|
||||
//System.IO.File.AppendAllText(txtPath, JsonConvert.SerializeObject(jsonData.ToString(), Formatting.Indented));
|
||||
try
|
||||
{
|
||||
LineMessagingAccount lineAccount = crudDAL.GetAll(l => l.Seq == seq).FirstOrDefault();
|
||||
if (lineAccount != null)
|
||||
{
|
||||
LineWebhookContent content = JsonConvert.DeserializeObject<LineWebhookContent>(jsonData.ToString());
|
||||
|
||||
LineWebhookContent content = JsonConvert.DeserializeObject<LineWebhookContent>(jsonData.ToString());
|
||||
|
||||
await lineAutoBotService.AutoReply(lineAccount,content);
|
||||
}
|
||||
//this.loggingService.Log("PostFromLine");
|
||||
await lineAutoBotService.AutoReply(content);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -104,11 +109,11 @@ namespace WebAPI.Controllers
|
||||
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public Task PushCommandMessage(string groupToken, string command)
|
||||
{
|
||||
return lineAutoBotService.PushCommandMessage(EnumHelper.GetEnumValueFromDescription<LineGroup>(groupToken), "#" + command);
|
||||
}
|
||||
//[HttpGet]
|
||||
//public Task PushCommandMessage(string groupToken, string command)
|
||||
//{
|
||||
// return lineAutoBotService.PushCommandMessage(EnumHelper.GetEnumValueFromDescription<LineGroup>(groupToken), "#" + command);
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Church.Net.Entity;
|
||||
using Church.Net.Entity.Messenger;
|
||||
using LineMessaging;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@@ -32,4 +33,16 @@ namespace WebAPI.Controllers
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Route("[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class LineClientController : ApiControllerBase<LineMessageClient>
|
||||
{
|
||||
public LineClientController(ICrudLogic<LineMessageClient> logic) : base(logic)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace WebAPI.Controllers
|
||||
[ApiController]
|
||||
public class PastoralDomainController : ApiControllerBase<PastoralDomain>
|
||||
{
|
||||
public PastoralDomainController(ICrudLogic<PastoralDomain> logic) : base(logic)
|
||||
public PastoralDomainController(PastoralDomainLogic logic) : base(logic)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ using WebAPI.Logics;
|
||||
using WebAPI.Services;
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
using WebAPI.Services.Interfaces;
|
||||
using WebAPI.Logics.Interface;
|
||||
|
||||
namespace WebAPI.Controllers
|
||||
{
|
||||
@@ -24,9 +25,12 @@ namespace WebAPI.Controllers
|
||||
public class PingController : ControllerBase
|
||||
{
|
||||
private readonly IEnumerable<IAutoReplyCommand> autoReplyCommands;
|
||||
private readonly PastoralDomainLogic pastoralDomainLogic;
|
||||
private readonly LineAutoBotService lineAutoBotService;
|
||||
|
||||
public PingController(VideoDownloadLogic videoDownloadLogic,
|
||||
IEnumerable<IAutoReplyCommand> autoReplyCommands)
|
||||
IEnumerable<IAutoReplyCommand> autoReplyCommands
|
||||
)
|
||||
{
|
||||
VideoDownloadLogic = videoDownloadLogic;
|
||||
this.autoReplyCommands = autoReplyCommands;
|
||||
@@ -129,41 +133,6 @@ namespace WebAPI.Controllers
|
||||
}
|
||||
|
||||
|
||||
[HttpGet]
|
||||
public async void TestAutoReply(string command)
|
||||
{
|
||||
//\\ArkNAS\Church\WorshipVideo
|
||||
//this.VideoDownloadLogic.Download(@"https://www.youtube.com/watch?v=K2bdSYim7uI", @"\\ArkNAS\home\Test.mp4");
|
||||
|
||||
|
||||
if (!String.IsNullOrWhiteSpace(command))
|
||||
{
|
||||
string text = command;
|
||||
var group = LineGroup.Chris;
|
||||
|
||||
var autoReply = autoReplyCommands.Where(ar => ar.SupportGroups.Contains(group) && ar.Commands.Contains(text)).FirstOrDefault();
|
||||
if (autoReply != null)
|
||||
{
|
||||
|
||||
if (autoReply.LineMessage != null)
|
||||
{
|
||||
ReplyLineMessage(group.EnumToDescriptionString(), autoReply.LineMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
// ReplyTextMessage(replyToken, autoReply.ReplyMessage);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
[HttpGet]
|
||||
public string[] GetFiles(string path)
|
||||
@@ -193,14 +162,6 @@ namespace WebAPI.Controllers
|
||||
|
||||
}
|
||||
|
||||
private async void ReplyLineMessage(string replyToken, IEnumerable<ILineMessage> lineMessages)
|
||||
{
|
||||
var test = new LineMessagingClient();
|
||||
|
||||
var replyMessage = new LinePushMessage() { To = replyToken };
|
||||
replyMessage.Messages = lineMessages;
|
||||
await test.PushMessage(replyMessage);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,20 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Authorization.Policy;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using WebAPI.Services;
|
||||
|
||||
public class BasicAuthorizationMiddlewareResultHandler : IAuthorizationMiddlewareResultHandler
|
||||
{
|
||||
private readonly AuthorizationMiddlewareResultHandler defaultHandler = new();
|
||||
private readonly IServiceScopeFactory serviceScopeFactory;
|
||||
|
||||
public BasicAuthorizationMiddlewareResultHandler(IServiceScopeFactory serviceScopeFactory)
|
||||
{
|
||||
this.serviceScopeFactory = serviceScopeFactory;
|
||||
}
|
||||
|
||||
public async Task HandleAsync(
|
||||
RequestDelegate next,
|
||||
@@ -33,6 +41,15 @@
|
||||
return;
|
||||
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// using (var scope = serviceScopeFactory.CreateScope())
|
||||
// {
|
||||
// var service = scope.ServiceProvider.GetService<IdentityService>();
|
||||
// service.UserAccessToken =;
|
||||
// }
|
||||
|
||||
//}
|
||||
// Fall back to the default implementation.
|
||||
//await defaultHandler.HandleAsync(next, context, policy, authorizeResult);
|
||||
await next(context);
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
using Church.Net.DAL.EFCoreDBF;
|
||||
using Church.Net.Entity;
|
||||
using Church.Net.Utility;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using WebAPI.Logics.Core;
|
||||
using WebAPI.Logics.Interface;
|
||||
using System.Linq;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace WebAPI.Logics
|
||||
{
|
||||
public class CellGroupLogic
|
||||
{
|
||||
private readonly IServiceScopeFactory serviceScopeFactory;
|
||||
private readonly ICrudDAL<CellGroupRoutineEvent> eventCrudDAL;
|
||||
private readonly ICombinedKeyCrudDAL<CellGroupRoutineEventAttendee> attendeeCrudDAL;
|
||||
private readonly ICrudDAL<FamilyMember> memberCrudDAL;
|
||||
|
||||
public CellGroupLogic(
|
||||
IServiceScopeFactory serviceScopeFactory,
|
||||
ICrudDAL<CellGroupRoutineEvent> eventCrudDAL,
|
||||
ICombinedKeyCrudDAL<CellGroupRoutineEventAttendee> attendeeCrudDAL,
|
||||
ICrudDAL<FamilyMember> memberCrudDAL
|
||||
)
|
||||
{
|
||||
this.serviceScopeFactory = serviceScopeFactory;
|
||||
this.eventCrudDAL = eventCrudDAL;
|
||||
this.attendeeCrudDAL = attendeeCrudDAL;
|
||||
this.memberCrudDAL = memberCrudDAL;
|
||||
}
|
||||
|
||||
public CellGroupRoutineEvent GetComingEvent()
|
||||
{
|
||||
var _event = eventCrudDAL.GetDbSet().Where(e => e.Time >= DateTime.UtcNow)
|
||||
.Include(e => e.Attendees).Include(e => e.Prayers).FirstOrDefault();
|
||||
if (_event == null)
|
||||
{
|
||||
_event = new CellGroupRoutineEvent()
|
||||
{
|
||||
Id = Format.Get33BaseGuid(),
|
||||
Time = DateTimeHelper.GetNextWeekday(DateTime.Today, DayOfWeek.Friday).AddHours(19).AddMinutes(30),
|
||||
Address = "1881 Forest Dr., Azusa, CA 91702",
|
||||
Attendees = new List<CellGroupRoutineEventAttendee>()
|
||||
};
|
||||
eventCrudDAL.Create(_event);
|
||||
}
|
||||
|
||||
return _event;
|
||||
}
|
||||
public CellGroupRoutineEvent GetLastEvent()
|
||||
{
|
||||
var _event = eventCrudDAL.GetDbSet().OrderByDescending(e=>e.Time)
|
||||
.Include(e => e.Attendees).Include(e => e.Prayers).FirstOrDefault();
|
||||
return _event;
|
||||
}
|
||||
|
||||
public string GetMemberFirstNameById(string memberId)
|
||||
{
|
||||
return memberCrudDAL.GetById(memberId)?.FirstName;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -30,23 +30,37 @@ namespace WebAPI.Logics.Core
|
||||
return this.crudDAL.CheckExist(obj);
|
||||
}
|
||||
|
||||
public virtual void BeforeCreate(T entity)
|
||||
{
|
||||
}
|
||||
public virtual int Create(T entity)
|
||||
{
|
||||
return this.crudDAL.Create(entity);
|
||||
BeforeCreate(entity);
|
||||
return this.crudDAL.Create(entity) + CreateDone(entity);
|
||||
}
|
||||
|
||||
public virtual Task<int> CreateAsync(T entity)
|
||||
{
|
||||
BeforeCreate(entity);
|
||||
return this.crudDAL.CreateAsync(entity);
|
||||
}
|
||||
|
||||
public void CreateDone(T entity)
|
||||
public virtual int CreateDone(T entity)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int CreateOrUpdate(T entity, out string id)
|
||||
public virtual int CreateOrUpdate(T entity, out string id)
|
||||
{
|
||||
var result= this.crudDAL.CreateOrUpdate(entity);
|
||||
int result = 0;
|
||||
if (this.crudDAL.CheckExist(entity))
|
||||
{
|
||||
result = this.Update(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = this.Create(entity);
|
||||
}
|
||||
id = entity.Id;
|
||||
return result;
|
||||
}
|
||||
@@ -56,7 +70,7 @@ namespace WebAPI.Logics.Core
|
||||
// return this.crudDAL.CreateReturnId(entity);
|
||||
//}
|
||||
|
||||
public int Delete(T obj)
|
||||
public virtual int Delete(T obj)
|
||||
{
|
||||
return this.crudDAL.Delete(obj);
|
||||
}
|
||||
@@ -70,7 +84,7 @@ namespace WebAPI.Logics.Core
|
||||
return this.crudDAL.First(filter);
|
||||
}
|
||||
|
||||
public IEnumerable<T> GetAll(Func<T, bool> filter = null)
|
||||
public virtual IEnumerable<T> GetAll(Func<T, bool> filter = null)
|
||||
{
|
||||
return this.crudDAL.GetAll(filter);
|
||||
}
|
||||
@@ -85,18 +99,39 @@ namespace WebAPI.Logics.Core
|
||||
return this.crudDAL.GetById(Id);
|
||||
}
|
||||
|
||||
public int Update(T entity)
|
||||
public virtual void BeforeUpdate(T entity)
|
||||
{
|
||||
return this.crudDAL.Update(entity);
|
||||
}
|
||||
|
||||
public void UpdateDone(T entity)
|
||||
public virtual int Update(T entity)
|
||||
{
|
||||
BeforeUpdate(entity);
|
||||
return this.crudDAL.Update(entity)+ UpdateDone(entity);
|
||||
}
|
||||
|
||||
public virtual int UpdateDone(T entity)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int UpdateRange(IEnumerable<T> entities)
|
||||
{
|
||||
return this.crudDAL.UpdateRange(entities);
|
||||
int result = 0;
|
||||
foreach (var item in entities)
|
||||
{
|
||||
result += Update(item);
|
||||
}
|
||||
return result;// this.crudDAL.UpdateRange(entities);
|
||||
}
|
||||
|
||||
public int CreateOrUpdateAll(IEnumerable<T> entities)
|
||||
{
|
||||
int result = 0;
|
||||
foreach (var item in entities)
|
||||
{
|
||||
result += CreateOrUpdate(item,out string id);
|
||||
}
|
||||
return result;// this.crudDAL.UpdateRange(entities);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,13 +7,16 @@ namespace WebAPI.Logics.Core
|
||||
public class LogicService
|
||||
{
|
||||
private readonly IServiceScopeFactory serviceScopeFactory;
|
||||
private readonly IdentityService identityService;
|
||||
|
||||
public LogicService(
|
||||
//ChurchNetContext dbContext
|
||||
IServiceScopeFactory serviceScopeFactory
|
||||
IServiceScopeFactory serviceScopeFactory,
|
||||
IdentityService identityService
|
||||
)
|
||||
{
|
||||
this.serviceScopeFactory = serviceScopeFactory;
|
||||
this.identityService = identityService;
|
||||
//DbContext = dbContext;
|
||||
}
|
||||
|
||||
@@ -22,11 +25,7 @@ namespace WebAPI.Logics.Core
|
||||
{
|
||||
get
|
||||
{
|
||||
using (var scope = serviceScopeFactory.CreateScope())
|
||||
{
|
||||
var service = scope.ServiceProvider.GetService<IdentityService>();
|
||||
return service.UserId;
|
||||
}
|
||||
return identityService.UserId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
using Church.Net.DAL.EFCoreDBF;
|
||||
using Church.Net.Entity;
|
||||
using Church.Net.Utility;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Metrics;
|
||||
using System.Linq;
|
||||
|
||||
namespace WebAPI.Logics
|
||||
{
|
||||
public class HappinessGroupLogic
|
||||
{
|
||||
private readonly ICrudDAL<HappinessGroup> groupCrudDAL;
|
||||
private readonly ICrudDAL<HappinessWeek> weekCrudDAL;
|
||||
string[] weekTitles = new string[] { "真幸福", "真相大白", "萬世巨星", "幸福連線", "當上帝來敲門", "十字架的勝利", "釋放與自由", "幸福的教會" };
|
||||
|
||||
public HappinessGroupLogic(
|
||||
ICrudDAL<HappinessGroup> groupCrudDAL,
|
||||
ICrudDAL<HappinessWeek> weekCrudDAL
|
||||
)
|
||||
{
|
||||
this.groupCrudDAL = groupCrudDAL;
|
||||
this.weekCrudDAL = weekCrudDAL;
|
||||
}
|
||||
|
||||
public List<HappinessGroup> GetAllGroups()
|
||||
{
|
||||
var list = groupCrudDAL.GetDbSet().Include(g => g.BestList).Include(g => g.Weeks).ToList();
|
||||
|
||||
foreach (var group in list)
|
||||
{
|
||||
if (group.Weeks == null || group.Weeks.Count() == 0)
|
||||
{
|
||||
group.Weeks = new List<HappinessWeek>();
|
||||
for (int i = 1; i <= 8; i++)
|
||||
{
|
||||
var week = GetHappinessWeek(group, i);
|
||||
group.Weeks.Add(week);
|
||||
weekCrudDAL.CreateOrUpdate(week);
|
||||
}
|
||||
}
|
||||
group.Weeks = group.Weeks.OrderBy(w => w.SEQ).ToList();
|
||||
}
|
||||
|
||||
|
||||
return list;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public int UpdateWeekInfo(HappinessWeek value)
|
||||
{
|
||||
if (value.UpdateRestWeekDate)
|
||||
{
|
||||
var list = weekCrudDAL.GetAll(week => week.SEQ >= value.SEQ && week.GroupId == value.GroupId).OrderBy(w => w.SEQ).ToList();
|
||||
var tempDate = new DateTime(value.Date.Year, value.Date.Month, value.Date.Day, value.Date.Hour, value.Date.Minute, value.Date.Second);
|
||||
int count = 0;
|
||||
foreach (var week in list)
|
||||
{
|
||||
week.Date = tempDate.AddDays(count * 7);
|
||||
week.Address = value.Address;
|
||||
week.CityAndZipCode = value.CityAndZipCode;
|
||||
week.InvitationText = value.InvitationText;
|
||||
count++;
|
||||
}
|
||||
return weekCrudDAL.UpdateRange(list);
|
||||
}
|
||||
return weekCrudDAL.CreateOrUpdate(value);
|
||||
|
||||
}
|
||||
|
||||
private HappinessWeek GetHappinessWeek(HappinessGroup group, int weekNo)
|
||||
{
|
||||
return new HappinessWeek()
|
||||
{
|
||||
GroupId = group.Id,
|
||||
Address = group.Address,
|
||||
CityAndZipCode = group.CityAndZipCode,
|
||||
Date = group.BeginTime.AddDays(7 * (weekNo - 1)),
|
||||
SEQ = weekNo
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,11 +17,11 @@ namespace WebAPI.Logics.Interface
|
||||
int Create(T entity);
|
||||
Task<int> CreateAsync(T entity);
|
||||
//string CreateReturnId(T entity);
|
||||
|
||||
int CreateOrUpdate(T entity, out string id);
|
||||
int CreateOrUpdateAll(IEnumerable<T> entities);
|
||||
int Update(T entity);
|
||||
void CreateDone(T entity);
|
||||
void UpdateDone(T entity);
|
||||
int CreateDone(T entity);
|
||||
int UpdateDone(T entity);
|
||||
int UpdateRange(IEnumerable<T> entities);
|
||||
int Delete(T obj);
|
||||
int Delete(Func<T, bool> filter = null);
|
||||
|
||||
@@ -11,36 +11,27 @@ namespace WebAPI.Logics
|
||||
{
|
||||
public class LineMessagingAccountLogic : LogicBase<LineMessagingAccount>, ICrudLogic<LineMessagingAccount>
|
||||
{
|
||||
private readonly ICrudDAL<HappinessGroup> happinessGroupDAL;
|
||||
private readonly ICrudDAL<PastoralDomain> cellGroupDAL;
|
||||
|
||||
public LineMessagingAccountLogic(
|
||||
LogicService logicService,
|
||||
ICrudDAL<LineMessagingAccount> crudDAL,
|
||||
ICrudDAL<HappinessGroup> happinessGroupDAL,
|
||||
ICrudDAL<PastoralDomain> cellGroupDAL
|
||||
) : base(logicService, crudDAL)
|
||||
{
|
||||
this.happinessGroupDAL = happinessGroupDAL;
|
||||
this.cellGroupDAL = cellGroupDAL;
|
||||
}
|
||||
|
||||
public HappinessGroup GetHappinessGroup(string lineGroupId)
|
||||
{
|
||||
var group= happinessGroupDAL.First(c => c.CommunityAppId == lineGroupId);
|
||||
GetLineMessagingAccount(group);
|
||||
return group;
|
||||
}
|
||||
public PastoralDomain GetCellGroup(string lineGroupId)
|
||||
{
|
||||
var group = cellGroupDAL.First(c => c.CommunityAppId == lineGroupId);
|
||||
var group = cellGroupDAL.First(c => c.LineGroupId == lineGroupId);
|
||||
GetLineMessagingAccount(group);
|
||||
return group;
|
||||
}
|
||||
|
||||
private void GetLineMessagingAccount(IMessengerClient messengerClient)
|
||||
public void GetLineMessagingAccount(IMessengerClient messengerClient)
|
||||
{
|
||||
if (messengerClient != null)
|
||||
if (messengerClient != null && messengerClient.LineAccountId != null)
|
||||
{
|
||||
messengerClient.LineMessagingAccount = crudDAL.GetById(messengerClient.LineAccountId);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,240 @@
|
||||
using Church.Net.DAL.EFCoreDBF;
|
||||
using Church.Net.Entity;
|
||||
using Church.Net.Utility;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using WebAPI.Logics.Core;
|
||||
using WebAPI.Logics.Interface;
|
||||
using System.Linq;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace WebAPI.Logics
|
||||
{
|
||||
public class PastoralDomainLogic : LogicBase<PastoralDomain>, ICrudLogic<PastoralDomain>
|
||||
{
|
||||
string[] weekTopics = new string[] { "真幸福", "真相大白", "萬世巨星", "幸福連線", "當上帝來敲門", "十字架的勝利", "釋放與自由", "幸福的教會" };
|
||||
private readonly IServiceScopeFactory serviceScopeFactory;
|
||||
private readonly ICrudDAL<CellGroupRoutineEvent> eventCrudDAL;
|
||||
private readonly ICombinedKeyCrudDAL<CellGroupRoutineEventAttendee> attendeeCrudDAL;
|
||||
private readonly ICrudDAL<FamilyMember> memberCrudDAL;
|
||||
private readonly ICrudDAL<AddressInfo> addressCrudDAL;
|
||||
private readonly ICombinedKeyCrudDAL<PastoralDomainMembers> pastoralDomainMemberDAL;
|
||||
private readonly ICrudDAL<HappinessWeek> weekCrudDAL;
|
||||
private readonly ICrudDAL<HappinessBEST> bestCrudDAL;
|
||||
private readonly ICrudDAL<HappinessTask> weekTaskCrudDAL;
|
||||
|
||||
public PastoralDomainLogic(
|
||||
IServiceScopeFactory serviceScopeFactory,
|
||||
LogicService logicService,
|
||||
ICrudDAL<PastoralDomain> crudDAL,
|
||||
ICrudDAL<CellGroupRoutineEvent> eventCrudDAL,
|
||||
ICombinedKeyCrudDAL<CellGroupRoutineEventAttendee> attendeeCrudDAL,
|
||||
ICrudDAL<FamilyMember> memberCrudDAL,
|
||||
ICrudDAL<AddressInfo> addressCrudDAL,
|
||||
ICombinedKeyCrudDAL<PastoralDomainMembers> pastoralDomainMemberDAL,
|
||||
ICrudDAL<HappinessWeek> weekCrudDAL,
|
||||
ICrudDAL<HappinessBEST> bestCrudDAL,
|
||||
ICrudDAL<HappinessTask> weekTaskCrudDAL
|
||||
) : base(logicService, crudDAL)
|
||||
{
|
||||
this.serviceScopeFactory = serviceScopeFactory;
|
||||
this.eventCrudDAL = eventCrudDAL;
|
||||
this.attendeeCrudDAL = attendeeCrudDAL;
|
||||
this.memberCrudDAL = memberCrudDAL;
|
||||
this.addressCrudDAL = addressCrudDAL;
|
||||
this.pastoralDomainMemberDAL = pastoralDomainMemberDAL;
|
||||
this.weekCrudDAL = weekCrudDAL;
|
||||
this.bestCrudDAL = bestCrudDAL;
|
||||
this.weekTaskCrudDAL = weekTaskCrudDAL;
|
||||
}
|
||||
|
||||
|
||||
#region override
|
||||
|
||||
|
||||
public override IEnumerable<PastoralDomain> GetAll(Func<PastoralDomain, bool> filter = null)
|
||||
{
|
||||
var list = base.GetAll(filter);
|
||||
foreach (var item in list)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(item.ServiceAddressId))
|
||||
{
|
||||
item.ServiceAddress = addressCrudDAL.GetById(item.ServiceAddressId);
|
||||
}
|
||||
else
|
||||
{
|
||||
item.ServiceAddress = new AddressInfo();
|
||||
}
|
||||
if (item.Type == DomainType.HappinessGroup)
|
||||
{
|
||||
GetHappinessGroupInfo(item);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public override void BeforeCreate(PastoralDomain entity)
|
||||
{
|
||||
addressCrudDAL.CreateOrUpdate(entity.ServiceAddress);
|
||||
entity.ServiceAddressId = entity.ServiceAddress.Id;
|
||||
}
|
||||
public override void BeforeUpdate(PastoralDomain entity)
|
||||
{
|
||||
addressCrudDAL.CreateOrUpdate(entity.ServiceAddress);
|
||||
entity.ServiceAddressId = entity.ServiceAddress.Id;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
public CellGroupRoutineEvent GetComingEvent(string domainId = null)
|
||||
{
|
||||
if (domainId == null)
|
||||
{
|
||||
var cellGroup = GetCurrentUserCellGroup();
|
||||
if (cellGroup != null)
|
||||
{
|
||||
domainId = cellGroup.Id;
|
||||
|
||||
var _event = eventCrudDAL.GetDbSet().OrderByDescending(e => e.Time)
|
||||
.Include(e => e.Attendees).Include(e => e.Prayers)
|
||||
.Where(e => e.PastoralDomainId == domainId).FirstOrDefault();
|
||||
return _event;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
if (domainId != null)
|
||||
{
|
||||
var _event = eventCrudDAL.GetDbSet().Where(e => e.PastoralDomainId == domainId && e.Time >= DateTime.UtcNow)
|
||||
.Include(e => e.Attendees).Include(e => e.Prayers).FirstOrDefault();
|
||||
if (_event == null)
|
||||
{
|
||||
_event = new CellGroupRoutineEvent()
|
||||
{
|
||||
Id = Format.Get33BaseGuid(),
|
||||
Time = DateTimeHelper.GetNextWeekday(DateTime.Today, DayOfWeek.Friday).AddHours(19).AddMinutes(30),
|
||||
Address = "1881 Forest Dr., Azusa, CA 91702",
|
||||
Attendees = new List<CellGroupRoutineEventAttendee>(),
|
||||
PastoralDomainId = domainId
|
||||
};
|
||||
eventCrudDAL.Create(_event);
|
||||
}
|
||||
|
||||
return _event;
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
public CellGroupRoutineEvent GetLastEvent(string domainId = null)
|
||||
{
|
||||
if (domainId == null)
|
||||
{
|
||||
var cellGroup = GetCurrentUserCellGroup();
|
||||
if (cellGroup != null)
|
||||
{
|
||||
domainId = cellGroup.Id;
|
||||
|
||||
var _event = eventCrudDAL.GetDbSet().OrderByDescending(e => e.Time)
|
||||
.Include(e => e.Attendees).Include(e => e.Prayers)
|
||||
.Where(e => e.PastoralDomainId == domainId).FirstOrDefault();
|
||||
return _event;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
if (domainId != null)
|
||||
{
|
||||
var _event = eventCrudDAL.GetDbSet().OrderByDescending(e => e.Time)
|
||||
.Include(e => e.Attendees).Include(e => e.Prayers)
|
||||
.Where(e => e.PastoralDomainId == domainId).FirstOrDefault();
|
||||
return _event;
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public string GetMemberFirstNameById(string memberId)
|
||||
{
|
||||
return memberCrudDAL.GetById(memberId)?.FirstName;
|
||||
}
|
||||
|
||||
public IEnumerable<PastoralDomain> GetCurrentUserPastoralDomain()
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(logicService.CurrentUserId))
|
||||
{
|
||||
var ids = pastoralDomainMemberDAL.GetAll(p => p.FamilyMemberId == logicService.CurrentUserId).Select(p => p.PastoralDomainId);
|
||||
return crudDAL.GetAll(p => ids.Contains(p.Id));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public PastoralDomain GetCurrentUserCellGroup()
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(logicService.CurrentUserId))
|
||||
{
|
||||
var ids = pastoralDomainMemberDAL.GetAll(p => p.FamilyMemberId == logicService.CurrentUserId).Select(p => p.PastoralDomainId);
|
||||
return crudDAL.GetAll(p => ids.Contains(p.Id) && p.Type == DomainType.CellGroup).FirstOrDefault();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public int UpdateWeekInfo(HappinessWeek value)
|
||||
{
|
||||
if (value.UpdateRestWeekDate)
|
||||
{
|
||||
var list = weekCrudDAL.GetAll(week => week.SEQ >= value.SEQ && week.GroupId == value.GroupId).OrderBy(w => w.SEQ).ToList();
|
||||
var tempDate = new DateTime(value.Date.Year, value.Date.Month, value.Date.Day, value.Date.Hour, value.Date.Minute, value.Date.Second);
|
||||
int count = 0;
|
||||
foreach (var week in list)
|
||||
{
|
||||
week.Date = tempDate.AddDays(count * 7);
|
||||
week.Address = value.Address;
|
||||
week.CityAndZipCode = value.CityAndZipCode;
|
||||
week.InvitationText = value.InvitationText;
|
||||
count++;
|
||||
}
|
||||
return weekCrudDAL.UpdateRange(list);
|
||||
}
|
||||
return weekCrudDAL.CreateOrUpdate(value);
|
||||
|
||||
}
|
||||
|
||||
private HappinessWeek GetHappinessWeek(PastoralDomain group, int weekNo)
|
||||
{
|
||||
return new HappinessWeek()
|
||||
{
|
||||
GroupId = group.Id,
|
||||
Address = group.ServiceAddress.Address,
|
||||
CityAndZipCode = group.ServiceAddress.GetCSZ(),
|
||||
Date = group.ServiceTime.Value.AddDays(7 * (weekNo - 1)),
|
||||
SEQ = weekNo
|
||||
};
|
||||
}
|
||||
public void GetHappinessGroupInfo(PastoralDomain group)
|
||||
{
|
||||
group.HappinessWeeks = weekCrudDAL.GetAll(w => w.GroupId == group.Id).OrderBy(w => w.SEQ).ToList();
|
||||
if (group.HappinessWeeks == null || group.HappinessWeeks.Count() == 0)
|
||||
{
|
||||
group.HappinessWeeks = new List<HappinessWeek>();
|
||||
for (int i = 1; i <= 8; i++)
|
||||
{
|
||||
var week = GetHappinessWeek(group, i);
|
||||
group.HappinessWeeks.Add(week);
|
||||
weekCrudDAL.CreateOrUpdate(week);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var week in group.HappinessWeeks)
|
||||
{
|
||||
week.Topic = weekTopics[week.SEQ - 1];
|
||||
week.Tasks = weekTaskCrudDAL.GetAll(t => t.WeekId == week.Id).ToList();
|
||||
}
|
||||
|
||||
group.Bests = bestCrudDAL.GetAll(b => b.GroupId == group.Id).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,24 +15,23 @@ namespace WebAPI.Services.AutoReplyCommands
|
||||
{
|
||||
public class ArArkCellGroupDinner : IAutoReplyCommand
|
||||
{
|
||||
|
||||
private PastoralDomain pastoralDomain;
|
||||
public ArArkCellGroupDinner(
|
||||
CellGroupLogic logic)
|
||||
PastoralDomainLogic logic)
|
||||
{
|
||||
this.logic = logic;
|
||||
}
|
||||
private static readonly string[] COMMANDS = { "晚餐", "dinner" };
|
||||
|
||||
private static readonly LineGroup[] GROUPS = {
|
||||
LineGroup.Ark,
|
||||
LineGroup.Chris,
|
||||
private static readonly DomainType[] GROUPS = {
|
||||
DomainType.CellGroup,
|
||||
};
|
||||
private readonly CellGroupLogic logic;
|
||||
private readonly PastoralDomainLogic logic;
|
||||
|
||||
public string Description => "顯示方舟小組聚會晚餐";
|
||||
public string Description => "顯示小組聚會晚餐";
|
||||
public IEnumerable<string> Commands => COMMANDS;
|
||||
public IEnumerable<LineGroup> SupportGroups => GROUPS;
|
||||
public IEnumerable<string> ReplyMessage => null;
|
||||
public IEnumerable<DomainType> SupportGroups => GROUPS;
|
||||
public string ReplyTextMessage => null;
|
||||
|
||||
public IEnumerable<ILineMessage> LineMessage
|
||||
{
|
||||
@@ -41,7 +40,7 @@ namespace WebAPI.Services.AutoReplyCommands
|
||||
var random = new Random();
|
||||
|
||||
List<ILineMessage> list = new List<ILineMessage>();
|
||||
var _event = logic.GetComingEvent();
|
||||
var _event = logic.GetComingEvent(pastoralDomain.Id);
|
||||
|
||||
string title = "小組晚宴,吃飯皇帝大";
|
||||
string imageUrl = "https://happiness.tours/assets/images/dinner.jpg";
|
||||
@@ -191,5 +190,15 @@ namespace WebAPI.Services.AutoReplyCommands
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
public void Initialize(PastoralDomain pastoralDomain = null)
|
||||
{
|
||||
this.pastoralDomain = pastoralDomain;
|
||||
}
|
||||
|
||||
public bool Enabled(PastoralDomain pastoralDomain = null, string command = null)
|
||||
{
|
||||
return COMMANDS.Any(c=>c.IndexOf(command)==0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using LineMessaging;
|
||||
using Church.Net.Entity;
|
||||
using LineMessaging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -9,25 +10,31 @@ namespace WebAPI.Services.AutoReplyCommands
|
||||
{
|
||||
public class ArArkCellGroupInfo : IAutoReplyCommand
|
||||
{
|
||||
private PastoralDomain pastoralDomain;
|
||||
private static readonly string[] COMMANDS = { "小組" };
|
||||
|
||||
private static readonly DomainType[] GROUPS = {
|
||||
DomainType.CellGroup,
|
||||
};
|
||||
|
||||
private static readonly string[] COMMANDS = { "方舟", "方舟小組", "ark" };
|
||||
private static readonly string[] MESSAGES = {
|
||||
public string Description => "顯示小組聚會資訊";
|
||||
public IEnumerable<string> Commands => COMMANDS;
|
||||
public string ReplyTextMessage =>
|
||||
"新生命靈糧堂 Arcadia 牧區 - 方舟小組\n" +
|
||||
"聚會時間 & 流程 周五晚上\n" +
|
||||
"07:30 PM ~ 08:30 PM - PotLuck 時光\n" +
|
||||
"08:30 PM ~ 10:00 PM - 小組分享",
|
||||
"1881 Forest Dr, Azusa, CA 91702"
|
||||
};
|
||||
private static readonly LineGroup[] GROUPS = {
|
||||
LineGroup.Ark,
|
||||
LineGroup.ArkCowoker,
|
||||
LineGroup.Chris
|
||||
};
|
||||
|
||||
public string Description => "顯示方舟小組聚會資訊";
|
||||
public IEnumerable<string> Commands => COMMANDS;
|
||||
public IEnumerable<string> ReplyMessage => MESSAGES;
|
||||
public IEnumerable<LineGroup> SupportGroups => GROUPS;
|
||||
"08:30 PM ~ 10:00 PM - 小組分享\n" +
|
||||
"1881 Forest Dr, Azusa, CA 91702";
|
||||
public IEnumerable<DomainType> SupportGroups => GROUPS;
|
||||
public IEnumerable<ILineMessage> LineMessage => null;
|
||||
|
||||
public void Initialize(PastoralDomain pastoralDomain = null)
|
||||
{
|
||||
this.pastoralDomain = pastoralDomain;
|
||||
}
|
||||
public bool Enabled(PastoralDomain pastoralDomain = null, string command = null)
|
||||
{
|
||||
return COMMANDS.Any(c => c.IndexOf(command) == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Church.Net.DAL.EF;
|
||||
using Church.Net.Entity;
|
||||
using Church.Net.Utility;
|
||||
using Esprima;
|
||||
using LineMessaging;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
@@ -15,9 +16,9 @@ namespace WebAPI.Services.AutoReplyCommands
|
||||
{
|
||||
public class ArArkCellGroupPrayer : IAutoReplyCommand
|
||||
{
|
||||
|
||||
PastoralDomain pastoralDomain;
|
||||
public ArArkCellGroupPrayer(
|
||||
CellGroupLogic logic
|
||||
PastoralDomainLogic logic
|
||||
)
|
||||
{
|
||||
this.logic = logic;
|
||||
@@ -67,67 +68,15 @@ namespace WebAPI.Services.AutoReplyCommands
|
||||
}
|
||||
private static readonly string[] COMMANDS = { "禱告", "代禱", "letspray", "pray" };
|
||||
|
||||
private static readonly LineGroup[] GROUPS = {
|
||||
LineGroup.Ark,
|
||||
LineGroup.Chris,
|
||||
LineGroup.ArkCowoker,
|
||||
private static readonly DomainType[] GROUPS = {
|
||||
DomainType.CellGroup,
|
||||
};
|
||||
private readonly CellGroupLogic logic;
|
||||
private readonly PastoralDomainLogic logic;
|
||||
|
||||
public string Description => "顯示代禱事項";
|
||||
public IEnumerable<string> Commands => COMMANDS;
|
||||
public IEnumerable<LineGroup> SupportGroups => GROUPS;
|
||||
public IEnumerable<string> ReplyMessage
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
StringBuilder comments = new StringBuilder();
|
||||
sb.AppendLine("方舟小組-禱告中心");
|
||||
var _event = logic.GetLastEvent();
|
||||
if (_event == null || _event.Prayers.Count == 0)
|
||||
{
|
||||
sb.AppendLine($"目前暫無禱告事項唷!");
|
||||
sb.AppendLine($"請使用方舟禱告系統,新增代禱項目唷!");
|
||||
sb.AppendLine("https://happiness.tours/CellGroup/prayer?openExternalBrowser=1");
|
||||
}
|
||||
var random = new Random();
|
||||
int index = random.Next(bibleReferrences.Count);
|
||||
var bibleSentence = bibleReferrences[index];
|
||||
|
||||
sb.AppendLine("======= 代禱事項 =======");
|
||||
foreach (var a in _event.Prayers)
|
||||
{
|
||||
var name = logic.GetMemberFirstNameById(a.MemberId);
|
||||
|
||||
sb.AppendLine($"{name} - {string.Join(", ", a.Prayer.Split('|'))}");
|
||||
//sb.AppendLine($"{logic.GetMemberFirstNameById (a.MemberId)} - ");
|
||||
//int count = 0;
|
||||
//foreach (var prayer in a.Prayer.Split('|'))
|
||||
//{
|
||||
// count++;
|
||||
// sb.AppendLine(prayer);
|
||||
|
||||
//}
|
||||
if (!string.IsNullOrWhiteSpace(a.Comment))
|
||||
{
|
||||
comments.AppendLine($"{name}:{a.Comment}");
|
||||
}
|
||||
}
|
||||
|
||||
if (comments.Length > 0)
|
||||
{
|
||||
sb.AppendLine("========= 備註 =========");
|
||||
sb.Append(comments.ToString());
|
||||
}
|
||||
|
||||
sb.AppendLine("");
|
||||
sb.AppendLine($"請使用方舟禱告系統,新增代禱項目唷!");
|
||||
sb.AppendLine("https://happiness.tours/CellGroup/prayer?openExternalBrowser=1");
|
||||
return new string[] { sb.ToString() };
|
||||
}
|
||||
}
|
||||
public IEnumerable<DomainType> SupportGroups => GROUPS;
|
||||
public string ReplyTextMessage => null;
|
||||
public IEnumerable<ILineMessage> LineMessage
|
||||
{
|
||||
get
|
||||
@@ -137,7 +86,7 @@ namespace WebAPI.Services.AutoReplyCommands
|
||||
var bibleSentence = bibleReferrences[index];
|
||||
|
||||
List<ILineMessage> list = new List<ILineMessage>();
|
||||
var _event = logic.GetLastEvent();
|
||||
var _event = logic.GetLastEvent(this.pastoralDomain.Id);
|
||||
|
||||
string title = "禱告中心 普壘森特";
|
||||
string imageUrl = "https://dailyverses.net/images/tc/cuv/matthew-21-22-3.jpg";
|
||||
@@ -280,6 +229,15 @@ namespace WebAPI.Services.AutoReplyCommands
|
||||
}
|
||||
|
||||
private List<BibleReferrence> bibleReferrences;
|
||||
|
||||
public void Initialize(PastoralDomain pastoralDomain = null)
|
||||
{
|
||||
this.pastoralDomain = pastoralDomain;
|
||||
}
|
||||
public bool Enabled(PastoralDomain pastoralDomain = null, string command = null)
|
||||
{
|
||||
return COMMANDS.Any(c => c.IndexOf(command) == 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using LineMessaging;
|
||||
using Church.Net.Entity;
|
||||
using LineMessaging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -11,21 +12,29 @@ namespace WebAPI.Services.AutoReplyCommands
|
||||
{
|
||||
|
||||
private static readonly string[] COMMANDS = { "教會", "church" };
|
||||
private static readonly string[] MESSAGES = {
|
||||
"新生命靈糧堂 Arcadia 牧區\n聚會時間 周日 11:00 AM - 12:30PM\n聚會後有提供精緻午餐唷!",
|
||||
"1881 S 1st Ave, Arcadia, CA 91006"
|
||||
};
|
||||
private static readonly LineGroup[] GROUPS = {
|
||||
LineGroup.Ark,
|
||||
LineGroup.ArkCowoker,
|
||||
LineGroup.Chris
|
||||
private static readonly string MESSAGES =
|
||||
"新生命靈糧堂 Arcadia 牧區\n聚會時間 周日 11:00 AM - 12:30PM\n聚會後有提供精緻午餐唷!\n"+
|
||||
"1881 S 1st Ave, Arcadia, CA 91006";
|
||||
private static readonly DomainType[] GROUPS = {
|
||||
DomainType.HappinessGroup,
|
||||
DomainType.CellGroup
|
||||
};
|
||||
|
||||
public string Description => "顯示教會主日聚會資訊";
|
||||
public IEnumerable<string> Commands => COMMANDS;
|
||||
public IEnumerable<string> ReplyMessage => MESSAGES;
|
||||
public string ReplyTextMessage => MESSAGES;
|
||||
|
||||
public IEnumerable<LineGroup> SupportGroups => GROUPS;
|
||||
public IEnumerable<ILineMessage> LineMessage => null;
|
||||
|
||||
IEnumerable<DomainType> IAutoReplyCommand.SupportGroups => GROUPS;
|
||||
|
||||
public bool Enabled(PastoralDomain pastoralDomain = null, string command = null)
|
||||
{
|
||||
return COMMANDS.Any(c => c.IndexOf(command) == 0);
|
||||
}
|
||||
|
||||
public void Initialize(PastoralDomain pastoralDomain = null)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,199 @@
|
||||
using Church.Net.DAL.EF;
|
||||
using Church.Net.Entity;
|
||||
using Church.Net.Utility;
|
||||
using LineMessaging;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WebAPI.Logics;
|
||||
using WebAPI.Services.Interfaces;
|
||||
|
||||
namespace WebAPI.Services.AutoReplyCommands
|
||||
{
|
||||
public class ArHappinessGroupTask : IAutoReplyCommand
|
||||
{
|
||||
private PastoralDomain pastoralDomain;
|
||||
public ArHappinessGroupTask(
|
||||
PastoralDomainLogic logic)
|
||||
{
|
||||
this.logic = logic;
|
||||
}
|
||||
private static readonly string[] COMMANDS = { "分工", "分工#" };
|
||||
|
||||
private static readonly DomainType[] GROUPS = {
|
||||
DomainType.HappinessGroup,
|
||||
};
|
||||
private readonly PastoralDomainLogic logic;
|
||||
|
||||
public string Description => "顯示幸福小組分工表 #代表周數";
|
||||
public IEnumerable<string> Commands => COMMANDS;
|
||||
public IEnumerable<DomainType> SupportGroups => GROUPS;
|
||||
public string ReplyTextMessage => null;
|
||||
|
||||
public IEnumerable<ILineMessage> LineMessage
|
||||
{
|
||||
get
|
||||
{
|
||||
var random = new Random();
|
||||
|
||||
List<ILineMessage> list = new List<ILineMessage>();
|
||||
string title = $"W{weekSeq} {week.Topic} 分工表";
|
||||
string imageUrl = $"https://happiness.tours/assets/images/HappinessGroup/week0{weekSeq}.jpg";
|
||||
var flexMessage = new LineFlexMessage();
|
||||
flexMessage.AltText = title;
|
||||
|
||||
#region Header
|
||||
var headerContent = flexMessage.Contents.InitHeader();
|
||||
headerContent.Add(
|
||||
new LineFlexText(title)
|
||||
{
|
||||
Size = FlexObjectSize.lg,
|
||||
Weight = FlexObjectTextWeidht.Bold,
|
||||
Align = "center"
|
||||
});
|
||||
#endregion
|
||||
#region Hero
|
||||
flexMessage.Contents.InitHero()
|
||||
.Add(
|
||||
new LineFlexImage(imageUrl)
|
||||
{
|
||||
Size = FlexObjectSize.full,
|
||||
AspectRatio = "1.5:1"
|
||||
}
|
||||
);
|
||||
#endregion
|
||||
#region Body
|
||||
|
||||
var bodyContent = flexMessage.Contents.InitBody();
|
||||
|
||||
TimeSpan ts = week.Date - DateTime.Now;
|
||||
Console.WriteLine("No. of Minutes (Difference) = {0}", ts.TotalMinutes);
|
||||
bodyContent.Add(
|
||||
new LineFlexText($"再過 {ts.TotalMinutes.ToString("N0")} 分鐘,就是萬眾期待的幸福小組啦!!!")
|
||||
{
|
||||
Size = FlexObjectSize.md,
|
||||
Weight = FlexObjectTextWeidht.Regular,
|
||||
OffsetBottom = FlexObjectSize.xxl,
|
||||
Wrap = true
|
||||
});
|
||||
//bodyContent.Add(
|
||||
// new LineFlexText($"{_event.Time.ToString("MM/dd HH:mm tt")} 準時開飯唷!!")
|
||||
// {
|
||||
// Size = FlexObjectSize.md,
|
||||
// Weight = FlexObjectTextWeidht.Regular,
|
||||
// OffsetBottom = FlexObjectSize.xl,
|
||||
// Wrap = true
|
||||
// });
|
||||
|
||||
bodyContent.Add(
|
||||
new LineFlexText("分工明細")
|
||||
{
|
||||
Size = FlexObjectSize.md,
|
||||
Weight = FlexObjectTextWeidht.Bold,
|
||||
OffsetBottom = FlexObjectSize.md
|
||||
});
|
||||
//$"目前暫無禱告事項唷, 趕快來新增代禱事項吧!!"
|
||||
List<LineFlexBox> comments = new List<LineFlexBox>();
|
||||
|
||||
foreach (var a in week.Tasks)
|
||||
{
|
||||
var name = string.IsNullOrEmpty(a.Tasker)?"N/A": a.Tasker;// logic.GetMemberFirstNameById(a.MemberId);
|
||||
|
||||
var baseLineBox = new LineFlexBox()
|
||||
{
|
||||
Layout = FlexObjectBoxLayout.Baseline,
|
||||
};
|
||||
baseLineBox.Contents.Add(
|
||||
new LineFlexText(a.Type.EnumToDescriptionString())
|
||||
{
|
||||
Size = FlexObjectSize.sm,
|
||||
Color = "#aaaaaa",
|
||||
Flex = 3
|
||||
});
|
||||
baseLineBox.Contents.Add(
|
||||
new LineFlexText(
|
||||
$"{name}"
|
||||
|
||||
)
|
||||
{
|
||||
Size = FlexObjectSize.sm,
|
||||
Color = "#666666",
|
||||
Flex = 3,
|
||||
Wrap = true
|
||||
});
|
||||
baseLineBox.Contents.Add(
|
||||
new LineFlexText(
|
||||
$"內容:{a.Content}"
|
||||
|
||||
)
|
||||
{
|
||||
Size = FlexObjectSize.sm,
|
||||
Color = "#666666",
|
||||
Flex = 7,
|
||||
Wrap = true
|
||||
});
|
||||
bodyContent.Add(baseLineBox);
|
||||
|
||||
}
|
||||
|
||||
bodyContent.Add(new LineFlexSeparator());
|
||||
#endregion
|
||||
#region Footer
|
||||
//flexMessage.Contents.InitFooter()
|
||||
// .Add(
|
||||
// new LineFlexButton()
|
||||
// {
|
||||
// Action = new UriAction()
|
||||
// {
|
||||
// Uri = "https://happiness.tours/CellGroup/dinner?openExternalBrowser=1",
|
||||
// Label = "我的菜單"
|
||||
// }
|
||||
// }
|
||||
// );
|
||||
|
||||
#endregion
|
||||
|
||||
list.Insert(0, flexMessage);
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
public void Initialize(PastoralDomain pastoralDomain = null)
|
||||
{
|
||||
this.pastoralDomain = pastoralDomain;
|
||||
}
|
||||
private int weekSeq = 0;
|
||||
private HappinessWeek week = null;
|
||||
public bool Enabled(PastoralDomain pastoralDomain = null, string command = null)
|
||||
{
|
||||
|
||||
if (pastoralDomain != null && COMMANDS.Any(c => c.IndexOf(command) == 0))
|
||||
{
|
||||
|
||||
this.pastoralDomain = pastoralDomain;
|
||||
command = command.Replace("分工", "");
|
||||
|
||||
if (command.Length > 0)
|
||||
{
|
||||
weekSeq = int.Parse(command);
|
||||
}
|
||||
logic.GetHappinessGroupInfo(pastoralDomain);
|
||||
if (weekSeq > 0)
|
||||
{
|
||||
week = pastoralDomain.HappinessWeeks.Where(w => w.SEQ == weekSeq).FirstOrDefault();
|
||||
}
|
||||
else
|
||||
{
|
||||
week = pastoralDomain.HappinessWeeks.Where(w => w.Date >= DateTime.UtcNow).FirstOrDefault();
|
||||
weekSeq = week.SEQ;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,44 @@
|
||||
using Church.Net.Entity;
|
||||
using Church.Net.DAL.EFCoreDBF;
|
||||
using Church.Net.Entity;
|
||||
using Church.Net.Utility;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using System.Collections.Generic;
|
||||
using WebAPI.Logics;
|
||||
|
||||
namespace WebAPI.Services
|
||||
{
|
||||
public class IdentityService
|
||||
{
|
||||
public string UserAccessToken { get; set; }
|
||||
public string UserId { get; set; }
|
||||
private readonly IHttpContextAccessor httpContextAccessor;
|
||||
|
||||
public PastoralDomain CellGroup
|
||||
public IdentityService(
|
||||
IHttpContextAccessor httpContextAccessor
|
||||
)
|
||||
{
|
||||
this.httpContextAccessor = httpContextAccessor;
|
||||
}
|
||||
public string UserAccessToken
|
||||
{
|
||||
get
|
||||
{
|
||||
return httpContextAccessor.HttpContext.Request.Headers["accessToken"];
|
||||
}
|
||||
}
|
||||
private string _UserId;
|
||||
|
||||
public string UserId
|
||||
{
|
||||
get {
|
||||
|
||||
TokenHelper.GetUserIdFromToken
|
||||
return null; }
|
||||
if (string.IsNullOrWhiteSpace(_UserId))
|
||||
{
|
||||
_UserId = TokenHelper.GetUserIdFromToken(UserAccessToken);
|
||||
}
|
||||
return _UserId;
|
||||
}
|
||||
set {
|
||||
_UserId = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using LineMessaging;
|
||||
using Church.Net.Entity;
|
||||
using LineMessaging;
|
||||
using NuGet.Protocol.Plugins;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -10,8 +12,10 @@ namespace WebAPI.Services.Interfaces
|
||||
{
|
||||
string Description { get; }
|
||||
IEnumerable<string> Commands { get; }
|
||||
IEnumerable<string> ReplyMessage { get; }
|
||||
IEnumerable<LineGroup> SupportGroups { get; }
|
||||
string ReplyTextMessage { get; }
|
||||
IEnumerable<DomainType> SupportGroups { get; }
|
||||
IEnumerable<ILineMessage> LineMessage { get; }
|
||||
bool Enabled(PastoralDomain pastoralDomain = null, string command = null);
|
||||
void Initialize(PastoralDomain pastoralDomain = null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Church.Net.Entity.Messenger;
|
||||
using Church.Net.Entity;
|
||||
using Church.Net.Entity.Messenger;
|
||||
using Church.Net.Utility;
|
||||
using LineMessaging;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
@@ -9,6 +10,7 @@ using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WebAPI.Logics;
|
||||
using WebAPI.Logics.Interface;
|
||||
using WebAPI.Services.Interfaces;
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
@@ -22,6 +24,8 @@ namespace WebAPI.Services
|
||||
Ark = 1 << 0,
|
||||
[Description("Ca20e3b65aa58e676815eb13c3222591a")]
|
||||
ArkCowoker = 1 << 1,
|
||||
PastoralDomain = 1 << 2,
|
||||
HappinessGroup = 1 << 3,
|
||||
[Description("U97e9e579a41a5222e33bf68a3bf479a0")]
|
||||
Chris = ~(~0 << 20),
|
||||
}
|
||||
@@ -30,20 +34,26 @@ namespace WebAPI.Services
|
||||
private readonly IEnumerable<IAutoReplyCommand> autoReplyCommands;
|
||||
private readonly ILoggingService loggingService;
|
||||
private readonly ICrudLogic<LineMessageClient> clientLogic;
|
||||
private readonly LineMessagingAccountLogic lineMessagingAccountLogic;
|
||||
private string chatToken;
|
||||
|
||||
private PastoralDomain cellGroup;
|
||||
|
||||
public LineAutoBotService(
|
||||
IEnumerable<IAutoReplyCommand> autoReplyCommands,
|
||||
ILoggingService loggingService,
|
||||
ICrudLogic<LineMessageClient> clientLogic
|
||||
ICrudLogic<LineMessageClient> clientLogic,
|
||||
LineMessagingAccountLogic lineMessagingAccountLogic
|
||||
)
|
||||
{
|
||||
this.autoReplyCommands = autoReplyCommands;
|
||||
this.loggingService = loggingService;
|
||||
this.clientLogic = clientLogic;
|
||||
this.lineMessagingAccountLogic = lineMessagingAccountLogic;
|
||||
}
|
||||
public void SendTextMessage(string text, LineGroup target)
|
||||
{
|
||||
var test = new LineMessagingClient();
|
||||
var test = new LineMessagingClient(this.chatToken);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -57,27 +67,27 @@ namespace WebAPI.Services
|
||||
}
|
||||
|
||||
}
|
||||
public async Task<bool> ReplyTextMessage(string replyToken, IEnumerable<string> textMessages)
|
||||
public async Task<bool> ReplyTextMessage(string lineId, string textMessages)
|
||||
{
|
||||
var test = new LineMessagingClient();
|
||||
var test = new LineMessagingClient(this.chatToken);
|
||||
|
||||
var replyMessage = new LineReplyMessage() { ReplyToken = replyToken };
|
||||
var messages = new List<ILineMessage>();
|
||||
foreach (var message in textMessages)
|
||||
{
|
||||
messages.Add(new LineTextMessage() { Text = message });
|
||||
}
|
||||
replyMessage.Messages = messages;
|
||||
//var replyMessage = new LineReplyMessage() { ReplyToken = replyToken };
|
||||
//var messages = new List<ILineMessage>();
|
||||
//foreach (var message in textMessages)
|
||||
//{
|
||||
// messages.Add(new LineTextMessage() { Text = message });
|
||||
//}
|
||||
//replyMessage.Messages = messages;
|
||||
//test.ReplyMessage(replyMessage);
|
||||
|
||||
try
|
||||
{
|
||||
await test.ReplyMessage(replyMessage);
|
||||
await test.PushMessage(lineId, new LineTextMessage() { Text = textMessages });
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.loggingService.Error(ex, "ReplyTextMessage:75", JsonConvert.SerializeObject(replyMessage, Formatting.Indented));
|
||||
this.loggingService.Error(ex, "ReplyTextMessage:75", textMessages);
|
||||
|
||||
if (ex.Message == "You have reached your monthly limit.")
|
||||
{
|
||||
@@ -86,11 +96,11 @@ namespace WebAPI.Services
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public async Task<bool> ReplyLineMessage(string replyToken, IEnumerable<ILineMessage> lineMessages)
|
||||
public async Task<bool> ReplyLineMessage(string lineId, IEnumerable<ILineMessage> lineMessages)
|
||||
{
|
||||
var test = new LineMessagingClient();
|
||||
var test = new LineMessagingClient(this.chatToken);
|
||||
|
||||
var replyMessage = new LinePushMessage() { To = replyToken };
|
||||
var replyMessage = new LinePushMessage() { To = lineId };
|
||||
replyMessage.Messages = lineMessages;
|
||||
|
||||
try
|
||||
@@ -112,8 +122,9 @@ namespace WebAPI.Services
|
||||
|
||||
}
|
||||
|
||||
public async Task<bool> AutoReply(LineWebhookContent content)
|
||||
public async Task<bool> AutoReply(LineMessagingAccount lineAccount, LineWebhookContent content)
|
||||
{
|
||||
chatToken = lineAccount.ChatToken;
|
||||
loggingService.Log("AutoReply", content);
|
||||
try
|
||||
{
|
||||
@@ -127,7 +138,7 @@ namespace WebAPI.Services
|
||||
string text = e.Message.Text;
|
||||
string target = "";
|
||||
bool isGroup = true;
|
||||
var client = new LineMessagingClient();
|
||||
var client = new LineMessagingClient(this.chatToken);
|
||||
switch (e.Source.Type)
|
||||
{
|
||||
case WebhookRequestSourceType.User:
|
||||
@@ -136,58 +147,74 @@ namespace WebAPI.Services
|
||||
break;
|
||||
case WebhookRequestSourceType.Group:
|
||||
target = e.Source.GroupId;
|
||||
|
||||
cellGroup = lineMessagingAccountLogic.GetCellGroup(target);
|
||||
break;
|
||||
case WebhookRequestSourceType.Room:
|
||||
target = e.Source.RoomId;
|
||||
break;
|
||||
default:
|
||||
target = e.Source.RoomId;
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
if (isGroup)
|
||||
{
|
||||
if (clientLogic.First(c => c.ClientId == e.Source.GroupId) == null)
|
||||
{
|
||||
clientLogic.CreateOrUpdate(new LineMessageClient()
|
||||
{
|
||||
ClientId = target,
|
||||
Name = client.GetGroupProfile(e.Source.GroupId).Result.GroupName,
|
||||
IsGroup = true
|
||||
}, out string id);
|
||||
}
|
||||
//TODO:Get user by user id under group
|
||||
}
|
||||
else
|
||||
{
|
||||
if (clientLogic.First(c => c.ClientId == e.Source.UserId) == null)
|
||||
{
|
||||
|
||||
clientLogic.CreateOrUpdate(new LineMessageClient()
|
||||
try
|
||||
{
|
||||
|
||||
if (isGroup)
|
||||
{
|
||||
if (clientLogic.First(c => c.ClientId == e.Source.GroupId) == null)
|
||||
{
|
||||
ClientId = target,
|
||||
Name = client.GetProfile(e.Source.UserId).Result.DisplayName,
|
||||
IsGroup = false
|
||||
}, out string id);
|
||||
clientLogic.CreateOrUpdate(new LineMessageClient()
|
||||
{
|
||||
ClientId = target,
|
||||
Name = client.GetGroupProfile(e.Source.GroupId).Result.GroupName,
|
||||
IsGroup = true
|
||||
}, out string id);
|
||||
}
|
||||
//TODO:Get user by user id under group
|
||||
}
|
||||
else
|
||||
{
|
||||
if (clientLogic.First(c => c.ClientId == e.Source.UserId) == null)
|
||||
{
|
||||
|
||||
clientLogic.CreateOrUpdate(new LineMessageClient()
|
||||
{
|
||||
ClientId = target,
|
||||
Name = client.GetProfile(e.Source.UserId).Result.DisplayName,
|
||||
IsGroup = false
|
||||
}, out string id);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (!String.IsNullOrWhiteSpace(replyToken) && text.IndexOf("#") == 0)
|
||||
{
|
||||
text = text.ToLower().Substring(1);
|
||||
var group = EnumHelper.GetEnumValueFromDescription<LineGroup>(target);
|
||||
LineGroup group = LineGroup.Chris;
|
||||
|
||||
var autoReply = autoReplyCommands.Where(ar => ar.SupportGroups.Contains(group) && ar.Commands.Contains(text)).FirstOrDefault();
|
||||
if (cellGroup == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var autoReply = autoReplyCommands.Where(ar =>
|
||||
ar.SupportGroups.Contains(cellGroup.Type) &&
|
||||
ar.Enabled(cellGroup, text)
|
||||
).FirstOrDefault();
|
||||
if (autoReply != null)
|
||||
{
|
||||
|
||||
if (autoReply.LineMessage != null)
|
||||
{
|
||||
await ReplyLineMessage(target, autoReply.LineMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
await ReplyTextMessage(replyToken, autoReply.ReplyMessage);
|
||||
await ReplyTextMessage(replyToken, autoReply.ReplyTextMessage);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -195,13 +222,13 @@ namespace WebAPI.Services
|
||||
else if (text == "help" || text == "?")
|
||||
{
|
||||
StringBuilder commandText = new StringBuilder();
|
||||
commandText.AppendLine("方舟資訊部 - 指令清單");
|
||||
foreach (var ar in autoReplyCommands.Where(ar => ar.SupportGroups.Contains(group)))
|
||||
commandText.AppendLine("NLCC資訊部 - 指令清單");
|
||||
foreach (var ar in autoReplyCommands.Where(ar => ar.SupportGroups.Contains(cellGroup.Type)))
|
||||
{
|
||||
commandText.AppendLine($"{string.Join(", ", ar.Commands.Select(s => $"#{s}"))} - {ar.Description}");
|
||||
}
|
||||
commandText.Append($"#help, #? - 顯示指令清單");
|
||||
await ReplyTextMessage(replyToken, new string[] { commandText.ToString() });
|
||||
await ReplyTextMessage(replyToken, commandText.ToString());
|
||||
}
|
||||
|
||||
|
||||
@@ -210,11 +237,11 @@ namespace WebAPI.Services
|
||||
|
||||
|
||||
}
|
||||
else if (e.Message.Type == MessageType.Sticker && e.Source.GroupId == LineGroup.Ark.EnumToDescriptionString() && e.Message.PackageId == "1011092" && e.Message.StickerId == "510712")
|
||||
{
|
||||
//else if (e.Message.Type == MessageType.Sticker && e.Source.GroupId == LineGroup.Ark.EnumToDescriptionString() && e.Message.PackageId == "1011092" && e.Message.StickerId == "510712")
|
||||
//{
|
||||
|
||||
await ReplyLineMessage(e.Source.GroupId, autoReplyCommands.Where(ar => ar.Commands.Contains("pray")).FirstOrDefault().LineMessage);
|
||||
}
|
||||
// await ReplyLineMessage(e.Source.GroupId, autoReplyCommands.Where(ar => ar.Commands.Contains("pray")).FirstOrDefault().LineMessage);
|
||||
//}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -229,7 +256,7 @@ namespace WebAPI.Services
|
||||
}
|
||||
|
||||
|
||||
public async Task<bool> PushCommandMessage(LineGroup group, string command)
|
||||
public async Task<bool> PushCommandMessage(PastoralDomain group, string command)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -238,32 +265,34 @@ namespace WebAPI.Services
|
||||
{
|
||||
command = command.ToLower().Substring(1);
|
||||
|
||||
var autoReply = autoReplyCommands.Where(ar => ar.SupportGroups.Contains(group) && ar.Commands.Contains(command)).FirstOrDefault();
|
||||
var autoReply = autoReplyCommands.Where(ar =>
|
||||
ar.SupportGroups.Contains(cellGroup.Type) &&
|
||||
ar.Enabled(cellGroup, command)).FirstOrDefault();
|
||||
if (autoReply != null)
|
||||
{
|
||||
|
||||
if (autoReply.LineMessage != null)
|
||||
{
|
||||
await ReplyLineMessage(group.EnumToDescriptionString(), autoReply.LineMessage);
|
||||
await ReplyLineMessage(cellGroup.LineGroupId, autoReply.LineMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
await ReplyTextMessage(group.EnumToDescriptionString(), autoReply.ReplyMessage);
|
||||
await ReplyTextMessage(cellGroup.LineGroupId, autoReply.ReplyTextMessage);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (command == "help" || command == "?")
|
||||
{
|
||||
StringBuilder commandText = new StringBuilder();
|
||||
commandText.AppendLine("方舟資訊部 - 指令清單");
|
||||
foreach (var ar in autoReplyCommands.Where(ar => ar.SupportGroups.Contains(group)))
|
||||
{
|
||||
commandText.AppendLine($"{string.Join(", ", ar.Commands.Select(s => $"#{s}"))} - {ar.Description}");
|
||||
}
|
||||
commandText.Append($"#help, #? - 顯示指令清單");
|
||||
await ReplyTextMessage(group.EnumToDescriptionString(), new string[] { commandText.ToString() });
|
||||
}
|
||||
//else if (command == "help" || command == "?")
|
||||
//{
|
||||
// StringBuilder commandText = new StringBuilder();
|
||||
// commandText.AppendLine("方舟資訊部 - 指令清單");
|
||||
// foreach (var ar in autoReplyCommands.Where(ar => ar.SupportGroups.Contains(group)))
|
||||
// {
|
||||
// commandText.AppendLine($"{string.Join(", ", ar.Commands.Select(s => $"#{s}"))} - {ar.Description}");
|
||||
// }
|
||||
// commandText.Append($"#help, #? - 顯示指令清單");
|
||||
// await ReplyTextMessage(group.EnumToDescriptionString(), new string[] { commandText.ToString() });
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Church.Net.Utility;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using WebAPI.Logics;
|
||||
using WebAPI.Services.Interfaces;
|
||||
|
||||
namespace WebAPI.Services.ScheduledTask
|
||||
@@ -9,14 +10,17 @@ namespace WebAPI.Services.ScheduledTask
|
||||
{
|
||||
private readonly LineAutoBotService lineAutoBotService;
|
||||
private readonly ILoggingService loggingService;
|
||||
private readonly PastoralDomainLogic pastoralDomainLogic;
|
||||
private DateTime? nextRunningTime = null;
|
||||
public MorningPrayer(
|
||||
LineAutoBotService lineAutoBotService,
|
||||
ILoggingService loggingService
|
||||
ILoggingService loggingService,
|
||||
PastoralDomainLogic pastoralDomainLogic
|
||||
)
|
||||
{
|
||||
this.lineAutoBotService = lineAutoBotService;
|
||||
this.loggingService = loggingService;
|
||||
this.pastoralDomainLogic = pastoralDomainLogic;
|
||||
this.SetNextRunningTime();
|
||||
}
|
||||
public string Description => "Sent out Ark Morning Prayer";
|
||||
@@ -35,7 +39,17 @@ namespace WebAPI.Services.ScheduledTask
|
||||
public Task<bool> RunTask()
|
||||
{
|
||||
SetNextRunningTime();
|
||||
return lineAutoBotService.PushCommandMessage(LineGroup.Ark, "#pray");
|
||||
|
||||
return Task.Run(async () =>
|
||||
{
|
||||
var list = pastoralDomainLogic.GetAll(p => p.Type == Church.Net.Entity.DomainType.CellGroup);
|
||||
foreach (var group in list)
|
||||
{
|
||||
await lineAutoBotService.PushCommandMessage(group, "#pray");
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
}
|
||||
private void SetNextRunningTime()
|
||||
{
|
||||
|
||||
@@ -7,23 +7,21 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Church.Net.Utility;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace WebAPI.Services
|
||||
{
|
||||
public class WorkerService : BackgroundService
|
||||
{
|
||||
private IEnumerable<IScheduledTask> scheduledTasks;
|
||||
private ILoggingService loggingService;
|
||||
private readonly IServiceProvider serviceProvider;
|
||||
private readonly IWebHostEnvironment env;
|
||||
private static bool initialized = false;
|
||||
|
||||
public WorkerService(
|
||||
IEnumerable<IScheduledTask> scheduledTasks,
|
||||
ILoggingService loggingService
|
||||
IServiceProvider serviceProvider
|
||||
)
|
||||
{
|
||||
this.scheduledTasks = scheduledTasks;
|
||||
this.loggingService = loggingService;
|
||||
this.serviceProvider = serviceProvider;
|
||||
}
|
||||
private const int generalDelay = 5 * 60 * 1000; // 10 seconds
|
||||
|
||||
@@ -48,21 +46,28 @@ namespace WebAPI.Services
|
||||
//}
|
||||
|
||||
var now = DateTimeHelper.Now();
|
||||
foreach (var worker in scheduledTasks)
|
||||
|
||||
using (var scope = serviceProvider.CreateScope())
|
||||
{
|
||||
try
|
||||
var scheduledTasks = scope.ServiceProvider.GetRequiredService<IEnumerable<IScheduledTask>>();
|
||||
var loggingService = scope.ServiceProvider.GetRequiredService<ILoggingService>();
|
||||
foreach (var worker in scheduledTasks)
|
||||
{
|
||||
if (worker.CheckTime(now))
|
||||
try
|
||||
{
|
||||
loggingService.Log($"Running {worker.Description}");
|
||||
await worker.RunTask();
|
||||
if (worker.CheckTime(now))
|
||||
{
|
||||
loggingService.Log($"Running {worker.Description}");
|
||||
await worker.RunTask();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
loggingService.Error(ex, worker.Description);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
loggingService.Error(ex, worker.Description);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return "Done";
|
||||
}
|
||||
|
||||
+26
-19
@@ -45,6 +45,7 @@ namespace WebAPI
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
|
||||
services.AddHttpContextAccessor();
|
||||
|
||||
services.AddControllers().AddNewtonsoftJson(options =>
|
||||
{
|
||||
@@ -63,33 +64,34 @@ namespace WebAPI
|
||||
services.AddSignalR();
|
||||
|
||||
services.AddSingleton<GameRoomLogic>();
|
||||
services.AddSingleton(_ => new DatabaseOptions { ConnectionString = "Host=192.168.86.131;Port=49154;Database=Church;Username=chris;Password=1124" });
|
||||
//services.AddSingleton(_ => new DatabaseOptions { ConnectionString = "Host=192.168.86.131;Port=49154;Database=Church;Username=chris;Password=1124" });
|
||||
services.AddSingleton(_ => new DatabaseOptions { ConnectionString = "Host=192.168.86.131;Port=49154;Database=ChurchSandbox;Username=chris;Password=1124" });
|
||||
//services.AddSingleton<ChurchNetContext>(new ChurchNetContext());
|
||||
services.AddDbContext<ChurchNetContext>(options =>
|
||||
options.UseNpgsql(
|
||||
//Configuration.GetConnectionString()
|
||||
"Host=192.168.86.131;Port=49154;Database=Church;Username=chris;Password=1124"
|
||||
"Host=192.168.86.131;Port=49154;Database=ChurchSandbox;Username=chris;Password=1124"
|
||||
));
|
||||
|
||||
services.AddSingleton<LineAutoBotService>();
|
||||
services.AddSingleton<IAutoReplyCommand, ArChurchInfo>();
|
||||
services.AddSingleton<IAutoReplyCommand, ArArkCellGroupInfo>();
|
||||
services.AddSingleton<IAutoReplyCommand, ArArkCellGroupDinner>();
|
||||
services.AddSingleton<IAutoReplyCommand, ArArkCellGroupPrayer>();
|
||||
|
||||
services.AddSingleton<IScheduledTask, MorningPrayer>();
|
||||
services.AddScoped<LineAutoBotService>();
|
||||
services.AddScoped<IAutoReplyCommand, ArChurchInfo>();
|
||||
services.AddScoped<IAutoReplyCommand, ArArkCellGroupInfo>();
|
||||
services.AddScoped<IAutoReplyCommand, ArArkCellGroupDinner>();
|
||||
services.AddScoped<IAutoReplyCommand, ArArkCellGroupPrayer>();
|
||||
services.AddScoped<IAutoReplyCommand, ArHappinessGroupTask>();
|
||||
|
||||
services.AddScoped<IScheduledTask, MorningPrayer>();
|
||||
|
||||
|
||||
services.AddSingleton<VideoDownloadLogic>();
|
||||
services.AddSingleton<LogicService>();
|
||||
services.AddSingleton<CellGroupLogic>();
|
||||
services.AddSingleton(typeof(ICrudLogic<>), typeof(LogicBase<>));
|
||||
services.AddSingleton(typeof(ICrudDAL<>), typeof(CrudDALCBase<>));
|
||||
services.AddSingleton(typeof(ICombinedKeyCrudLogic<>), typeof(CombinedKeyLogicBase<>));
|
||||
services.AddSingleton(typeof(ICombinedKeyCrudDAL<>), typeof(CombinedKeyCrudDALCBase<>));
|
||||
services.AddSingleton<HappinessGroupLogic>();
|
||||
services.AddSingleton<LineMessagingAccountLogic>();
|
||||
services.AddSingleton<ILoggingService, DbLoggingService>();
|
||||
services.AddScoped<VideoDownloadLogic>();
|
||||
services.AddScoped<LogicService>();
|
||||
services.AddScoped<PastoralDomainLogic>();
|
||||
services.AddScoped(typeof(ICrudLogic<>), typeof(LogicBase<>));
|
||||
services.AddScoped(typeof(ICrudDAL<>), typeof(CrudDALCBase<>));
|
||||
services.AddScoped(typeof(ICombinedKeyCrudLogic<>), typeof(CombinedKeyLogicBase<>));
|
||||
services.AddScoped(typeof(ICombinedKeyCrudDAL<>), typeof(CombinedKeyCrudDALCBase<>));
|
||||
services.AddScoped<LineMessagingAccountLogic>();
|
||||
services.AddScoped<ILoggingService, DbLoggingService>();
|
||||
services.AddScoped<IdentityService>();
|
||||
|
||||
|
||||
@@ -98,6 +100,11 @@ namespace WebAPI
|
||||
//services.AddMvc(o => o.Filters.Add(new HandleExceptionFilter(services.BuildServiceProvider().GetService<ILoggingService>())));
|
||||
//services.BuildServiceProvider().GetService<ILoggingService>();
|
||||
services.AddSingleton<IAuthorizationMiddlewareResultHandler, BasicAuthorizationMiddlewareResultHandler>();
|
||||
|
||||
//ObjectFactory.Initialize(x =>
|
||||
// x.For<HttpContextBase>()
|
||||
// .HybridHttpOrThreadLocalScoped()
|
||||
// .Use(() => new HttpContextWrapper(HttpContext.Current));
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
|
||||
Reference in New Issue
Block a user