This commit is contained in:
Chris Chen
2023-08-20 11:28:47 -07:00
parent 2c491b63de
commit ad0bc0e49b
78 changed files with 3640 additions and 5639 deletions
+5 -4
View File
@@ -41,12 +41,12 @@ namespace WebAPI.Controllers
}
[HttpPost]
public virtual async Task<string> CreateOrUpdate([FromBody] T entity)
public virtual async Task<T> CreateOrUpdate([FromBody] T entity)
{
return await Task.Run(() =>
{
logic.CreateOrUpdate(entity, out string id);
return id;
return entity;
});
}
[HttpPost]
@@ -109,11 +109,12 @@ namespace WebAPI.Controllers
}
[HttpPost]
public virtual async Task<int> CreateOrUpdate([FromBody] T entity)
public virtual async Task<T> CreateOrUpdate([FromBody] T entity)
{
return await Task.Run(() =>
{
return logic.CreateOrUpdate(entity);
logic.CreateOrUpdate(entity);
return entity;
});
}
[HttpPost]
+1 -1
View File
@@ -96,7 +96,7 @@ namespace WebAPI.Controllers
[HttpPost]
public int UpdateBestWeek(HappinessWeek week)
{
return weekLogic.CreateOrUpdate(week,out string id);
return cellGroupLogic.UpdateWeekInfo(week);
}
private Font arialFont;
@@ -0,0 +1,16 @@
using Church.Net.Entity;
using Microsoft.AspNetCore.Mvc;
using WebAPI.Logics.Interface;
namespace WebAPI.Controllers
{
[Route("[controller]/[action]")]
[ApiController]
public class ContributionController : ApiControllerBase<Contribution>
{
public ContributionController(ICrudLogic<Contribution> logic) : base(logic)
{
}
}
}
@@ -0,0 +1,18 @@
using Church.Net.Entity;
using Microsoft.AspNetCore.Mvc;
using WebAPI.Logics.Interface;
namespace WebAPI.Controllers
{
[Route("[controller]/[action]")]
[ApiController]
public class HappinessCostController : ApiControllerBase<HappinessCost>
{
public HappinessCostController(ICrudLogic<HappinessCost> logic) : base(logic)
{
}
}
}
+10 -6
View File
@@ -24,6 +24,7 @@ using Jint.Native;
using WebAPI.Services.Interfaces;
using Church.Net.DAL.EFCoreDBF.Migrations;
using Church.Net.DAL.EFCoreDBF;
using WebAPI.Logics;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
namespace WebAPI.Controllers
@@ -36,16 +37,19 @@ namespace WebAPI.Controllers
private readonly LineAutoBotService lineAutoBotService;
private readonly ILoggingService loggingService;
private readonly ICrudDAL<LineMessagingAccount> crudDAL;
private readonly PastoralDomainLogic pastoralDomainLogic;
public LineMessageController(
LineAutoBotService lineAutoBotService,
ILoggingService loggingService,
ICrudDAL<LineMessagingAccount> crudDAL
ICrudDAL<LineMessagingAccount> crudDAL,
PastoralDomainLogic pastoralDomainLogic
)
{
this.lineAutoBotService = lineAutoBotService;
this.loggingService = loggingService;
this.crudDAL = crudDAL;
this.pastoralDomainLogic = pastoralDomainLogic;
}
//private ChurchNetContext dbContext = new ChurchNetContext();
//// GET: api/<BestController>
@@ -109,11 +113,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 groupId, string command)
{
return lineAutoBotService.PushCommandMessage(pastoralDomainLogic.GetById(groupId), "#" + command);
}
}
+39 -4
View File
@@ -2,28 +2,39 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Church.Net.DAL.EF;
using Church.Net.Entity;
using WebAPI.Logics;
using WebAPI.Logics.Interface;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace WebAPI.Controllers
{
[Route("[controller]/[action]")]
[Authorize]
[ApiController]
public class PastoralDomainController : ApiControllerBase<PastoralDomain>
{
private readonly PastoralDomainLogic logic;
public PastoralDomainController(PastoralDomainLogic logic) : base(logic)
{
this.logic = logic;
}
[HttpGet]
public Task<IEnumerable<PastoralDomain>> GetCurrentUserPastoralDomain()
{
return Task.Run(() =>
{
return logic.GetCurrentUserPastoralDomain();
});
}
}
[Route("[controller]/[action]")]
[ApiController]
[Authorize]
public class DomainMemberShipController : CombinedKeyApiControllerBase<PastoralDomainMembers>
{
public DomainMemberShipController(ICombinedKeyCrudLogic<PastoralDomainMembers> logic) : base(logic)
@@ -43,5 +54,29 @@ namespace WebAPI.Controllers
return 1;
}
[HttpGet]
public int AddMemberIntoGroup(string domainId, string memberId)
{
return logic.CreateOrUpdate(new PastoralDomainMembers() { PastoralDomainId = domainId, FamilyMemberId = memberId });
}
[HttpGet]
public int RemoveMemberFromGroup(string domainId, string memberId)
{
return logic.Delete(r => r.PastoralDomainId == domainId && r.FamilyMemberId == memberId);
}
[HttpPost]
public int UpdateMembersInGroup(PastoralDomain domain)
{
logic.Delete(r => r.PastoralDomainId == domain.Id);
foreach (var member in domain.FamilyMembers)
{
//logic.Delete(r => r.FamilyMemberId == relation.FamilyMemberId);
logic.Create(new PastoralDomainMembers() { PastoralDomainId = domain.Id, FamilyMemberId = member.Id });
}
return 1;
}
}
}
+1 -1
View File
@@ -113,7 +113,7 @@ namespace WebAPI.Controllers
var templateMessage = new LineTemplateMessage<ButtonTemplateObject>();
var addPrayerBtn = new UriAction()
{
Uri = "https://happiness.tours/CellGroup/prayer?openExternalBrowser=1",
Uri = "https://happiness.tours/CellGroup/prayer",
Label = "Prayer"
};
templateMessage.AltText = "代禱事項";
+23
View File
@@ -0,0 +1,23 @@
using Church.Net.DAL.EFCoreDBF;
using Church.Net.Entity;
using WebAPI.Logics.Core;
using WebAPI.Logics.Interface;
namespace WebAPI.Logics
{
public class MemberLogic : LogicBase<FamilyMember>, ICrudLogic<FamilyMember>
{
public MemberLogic(
LogicService logicService,
ICrudDAL<FamilyMember> crudDAL
) : base(logicService, crudDAL)
{
}
public override void BeforeUpdate(FamilyMember entity)
{
entity.Password = crudDAL.First(m => m.Id == entity.Id).Password;
}
}
}
+50 -19
View File
@@ -17,37 +17,40 @@ namespace WebAPI.Logics
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;
private readonly ICrudDAL<HappinessCost> happinessCostCrudDAL;
private readonly ICrudDAL<Contribution> contributionCrudDAL;
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
ICrudDAL<HappinessTask> weekTaskCrudDAL,
ICrudDAL<Contribution> contributionCrudDALL,
ICrudDAL<HappinessCost> happinessCostCrudDAL
) : 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;
this.happinessCostCrudDAL = happinessCostCrudDAL;
this.contributionCrudDAL = contributionCrudDALL;
}
@@ -57,20 +60,26 @@ namespace WebAPI.Logics
public override IEnumerable<PastoralDomain> GetAll(Func<PastoralDomain, bool> filter = null)
{
var list = base.GetAll(filter);
foreach (var item in list)
foreach (var group in list)
{
if (!string.IsNullOrEmpty(item.ServiceAddressId))
if (!string.IsNullOrEmpty(group.ServiceAddressId))
{
item.ServiceAddress = addressCrudDAL.GetById(item.ServiceAddressId);
group.ServiceAddress = addressCrudDAL.GetById(group.ServiceAddressId);
}
else
{
item.ServiceAddress = new AddressInfo();
group.ServiceAddress = new AddressInfo();
}
if (item.Type == DomainType.HappinessGroup)
if (group.Type == DomainType.HappinessGroup)
{
GetHappinessGroupInfo(item);
GetHappinessGroupInfo(group);
}
group.FamilyMembers =
memberCrudDAL.GetAllById(
pastoralDomainMemberDAL.GetAll(d => d.PastoralDomainId == group.Id).Select(d => d.FamilyMemberId).ToList()
).ToList();
group.Contributions = contributionCrudDAL.GetAll(d => d.GroupId == group.Id).ToList();
}
return list;
}
@@ -91,31 +100,42 @@ namespace WebAPI.Logics
public CellGroupRoutineEvent GetComingEvent(string domainId = null)
{
PastoralDomain cellGroup;
if (domainId == null)
{
var cellGroup = GetCurrentUserCellGroup();
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;
//var _event = eventCrudDAL.GetDbSet().OrderByDescending(e => e.Time)
// .Include(e => e.Attendees).Include(e => e.Prayers)
// .Where(e => e.PastoralDomainId == domainId).FirstOrDefault();
//return _event;
}
}
else
{
cellGroup= crudDAL.GetById(domainId);
}
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)
{
var serviceLocalTime = cellGroup.ServiceTime.Value.ToUniversalTime().ToLocal(cellGroup.TimeZone);
var serviceWeekDay = serviceLocalTime.DayOfWeek;
var nextServiceTime = DateTimeHelper.GetNextWeekday(DateTimeHelper.Today(cellGroup.TimeZone), DayOfWeek.Friday)
.AddHours(serviceLocalTime.Hour).AddMinutes(serviceLocalTime.Minute);
_event = new CellGroupRoutineEvent()
{
Id = Format.Get33BaseGuid(),
Time = DateTimeHelper.GetNextWeekday(DateTime.Today, DayOfWeek.Friday).AddHours(19).AddMinutes(30),
Time = nextServiceTime.ToUtc(cellGroup.TimeZone),
Address = "1881 Forest Dr., Azusa, CA 91702",
Attendees = new List<CellGroupRoutineEventAttendee>(),
PastoralDomainId = domainId
@@ -167,7 +187,17 @@ namespace WebAPI.Logics
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));
var list = crudDAL.GetAll(p => ids.Contains(p.Id));
foreach (var group in list)
{
if (group.Type == DomainType.HappinessGroup)
{
GetHappinessGroupInfo(group);
}
group.Contributions = contributionCrudDAL.GetAll(d => d.GroupId == group.Id).ToList();
}
return list;
}
return null;
}
@@ -231,10 +261,11 @@ namespace WebAPI.Logics
foreach (var week in group.HappinessWeeks)
{
week.Topic = weekTopics[week.SEQ - 1];
week.Tasks = weekTaskCrudDAL.GetAll(t => t.WeekId == week.Id).ToList();
week.Tasks = weekTaskCrudDAL.GetAll(t => t.WeekId == week.Id).OrderBy(t => t.Type).ToList();
week.Costs = happinessCostCrudDAL.GetAll(t => t.WeekId == week.Id).ToList();
}
group.Bests = bestCrudDAL.GetAll(b => b.GroupId == group.Id).ToList();
group.Bests = bestCrudDAL.GetAll(b => b.GroupId == group.Id).OrderBy(b => b.Name).ToList();
}
}
}
@@ -32,6 +32,7 @@ namespace WebAPI.Services.AutoReplyCommands
public IEnumerable<string> Commands => COMMANDS;
public IEnumerable<DomainType> SupportGroups => GROUPS;
public string ReplyTextMessage => null;
public string ReplyJsonMessage => null;
public IEnumerable<ILineMessage> LineMessage
{
@@ -178,7 +179,7 @@ namespace WebAPI.Services.AutoReplyCommands
{
Action = new UriAction()
{
Uri = "https://happiness.tours/CellGroup/dinner?openExternalBrowser=1",
Uri = $"https://happiness.tours/myapp/dinner/{pastoralDomain.Id}",
Label = "我的菜單"
}
}
@@ -28,6 +28,8 @@ namespace WebAPI.Services.AutoReplyCommands
public IEnumerable<DomainType> SupportGroups => GROUPS;
public IEnumerable<ILineMessage> LineMessage => null;
public string ReplyJsonMessage => null;
public void Initialize(PastoralDomain pastoralDomain = null)
{
this.pastoralDomain = pastoralDomain;
@@ -77,6 +77,7 @@ namespace WebAPI.Services.AutoReplyCommands
public IEnumerable<string> Commands => COMMANDS;
public IEnumerable<DomainType> SupportGroups => GROUPS;
public string ReplyTextMessage => null;
public string ReplyJsonMessage => null;
public IEnumerable<ILineMessage> LineMessage
{
get
@@ -215,7 +216,7 @@ namespace WebAPI.Services.AutoReplyCommands
{
Action = new UriAction()
{
Uri = "https://happiness.tours/CellGroup/prayer?openExternalBrowser=1",
Uri = $"https://happiness.tours/myapp/prayer/{pastoralDomain.Id}",
Label = "我的代禱事項"
}
}
@@ -236,6 +237,7 @@ namespace WebAPI.Services.AutoReplyCommands
}
public bool Enabled(PastoralDomain pastoralDomain = null, string command = null)
{
this.pastoralDomain = pastoralDomain;
return COMMANDS.Any(c => c.IndexOf(command) == 0);
}
}
@@ -24,11 +24,13 @@ namespace WebAPI.Services.AutoReplyCommands
public string ReplyTextMessage => MESSAGES;
public IEnumerable<ILineMessage> LineMessage => null;
public string ReplyJsonMessage => null;
IEnumerable<DomainType> IAutoReplyCommand.SupportGroups => GROUPS;
public bool Enabled(PastoralDomain pastoralDomain = null, string command = null)
{
//this.pastoralDomain = pastoralDomain;
return COMMANDS.Any(c => c.IndexOf(command, StringComparison.OrdinalIgnoreCase) == 0);
}
@@ -32,6 +32,7 @@ namespace WebAPI.Services.AutoReplyCommands
public IEnumerable<string> Commands => COMMANDS;
public IEnumerable<DomainType> SupportGroups => GROUPS;
public string ReplyTextMessage => null;
public string ReplyJsonMessage => null;
public IEnumerable<ILineMessage> LineMessage
{
@@ -83,7 +84,8 @@ namespace WebAPI.Services.AutoReplyCommands
Text = $"親愛的 {best.Name},想邀請你來參加這周的幸福聚會唷! 這是這周的邀請函!\n\nhttps://happiness.tours/invitation/{best.Id}",
Label = best.Name,
//InputOption= "openKeyboard"
}
},
Height = FlexObjectSize.sm,
}
);
@@ -28,138 +28,14 @@ namespace WebAPI.Services.AutoReplyCommands
};
private readonly PastoralDomainLogic logic;
public string Description => "顯示幸福小組分工表 #代表周數";
public string Description => "顯示幸福小組分工表 #代表周數 9顯示所有分工";
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 string ReplyJsonMessage => jsonMessage;
private string jsonMessage;
private IEnumerable<ILineMessage> lineMessages;
public IEnumerable<ILineMessage> LineMessage => lineMessages;
public void Initialize(PastoralDomain pastoralDomain = null)
{
@@ -170,7 +46,7 @@ namespace WebAPI.Services.AutoReplyCommands
public bool Enabled(PastoralDomain pastoralDomain = null, string command = null)
{
if (pastoralDomain != null && COMMANDS.Any(c => c.IndexOf(command) == 0))
if (pastoralDomain != null && command.IndexOf("分工")>-1)
{
this.pastoralDomain = pastoralDomain;
@@ -190,10 +66,288 @@ namespace WebAPI.Services.AutoReplyCommands
week = pastoralDomain.HappinessWeeks.Where(w => w.Date >= DateTime.UtcNow).FirstOrDefault();
weekSeq = week.SEQ;
}
if (week != null)
{
PrepareLineMessage();
}
else
{
PrepareAllTaskMessage();
}
return true;
};
return false;
}
private void PrepareAllTaskMessage()
{
this.lineMessages = null;
StringBuilder messageContent = new StringBuilder();
messageContent.AppendLine("{ ");
messageContent.AppendLine(" \"altText\": \"幸福小組 8 週分工\", ");
messageContent.AppendLine(" \"type\": \"flex\", ");
messageContent.AppendLine(" \"contents\": { ");
messageContent.AppendLine(" \"type\": \"carousel\", ");
messageContent.AppendLine(" \"contents\": [ ");
foreach (var week in pastoralDomain.HappinessWeeks.OrderBy(w => w.SEQ))
{
messageContent.AppendLine("{ ");
messageContent.AppendLine(" \"type\": \"bubble\", ");
messageContent.AppendLine(" \"header\": { ");
messageContent.AppendLine(" \"type\": \"box\", ");
messageContent.AppendLine(" \"layout\": \"vertical\", ");
messageContent.AppendLine(" \"contents\": [ ");
messageContent.AppendLine(" { ");
messageContent.AppendLine(" \"type\": \"text\", ");
messageContent.AppendLine($" \"text\": \"W{week.SEQ} {week.Topic} 分工表\", ");
messageContent.AppendLine(" \"flex\": 0, ");
messageContent.AppendLine(" \"size\": \"lg\", ");
messageContent.AppendLine(" \"weight\": \"bold\", ");
messageContent.AppendLine(" \"wrap\": false, ");
messageContent.AppendLine(" \"align\": \"center\" ");
messageContent.AppendLine(" } ");
messageContent.AppendLine(" ], ");
messageContent.AppendLine(" \"paddingAll\": \"sm\" ");
messageContent.AppendLine(" }, ");
messageContent.AppendLine(" \"hero\": { ");
messageContent.AppendLine(" \"type\": \"box\", ");
messageContent.AppendLine(" \"layout\": \"vertical\", ");
messageContent.AppendLine(" \"contents\": [ ");
messageContent.AppendLine(" { ");
messageContent.AppendLine(" \"type\": \"image\", ");
messageContent.AppendLine($" \"url\": \"https://happiness.tours/assets/images/HappinessGroup/week0{week.SEQ}.jpg\", ");
messageContent.AppendLine(" \"size\": \"full\", ");
messageContent.AppendLine(" \"aspectRatio\": \"1.5:1\" ");
messageContent.AppendLine(" } ");
messageContent.AppendLine(" ] ");
messageContent.AppendLine(" }, ");
messageContent.AppendLine(" \"body\": { ");
messageContent.AppendLine(" \"type\": \"box\", ");
messageContent.AppendLine(" \"layout\": \"vertical\", ");
messageContent.AppendLine(" \"contents\": [ ");
messageContent.AppendLine(" { ");
messageContent.AppendLine(" \"type\": \"text\", ");
messageContent.AppendLine(" \"text\": \"分工明細\", ");
messageContent.AppendLine(" \"flex\": 0, ");
messageContent.AppendLine(" \"size\": \"md\", ");
messageContent.AppendLine(" \"offsetBottom\": \"md\", ");
messageContent.AppendLine(" \"weight\": \"bold\", ");
messageContent.AppendLine(" \"wrap\": false ");
messageContent.AppendLine(" }, ");
foreach (var task in week.Tasks)
{
messageContent.AppendLine(" { ");
messageContent.AppendLine(" \"type\": \"box\", ");
messageContent.AppendLine(" \"layout\": \"baseline\", ");
messageContent.AppendLine(" \"contents\": [ ");
messageContent.AppendLine(" { ");
messageContent.AppendLine(" \"type\": \"text\", ");
messageContent.AppendLine($" \"text\": \"{task.Type.EnumToDescriptionString()}\", ");
messageContent.AppendLine(" \"flex\": 3, ");
messageContent.AppendLine(" \"size\": \"sm\", ");
messageContent.AppendLine(" \"weight\": \"regular\", ");
messageContent.AppendLine(" \"color\": \"#aaaaaa\", ");
messageContent.AppendLine(" \"wrap\": false ");
messageContent.AppendLine(" }, ");
messageContent.AppendLine(" { ");
messageContent.AppendLine(" \"type\": \"text\", ");
messageContent.AppendLine($" \"text\": \"{task.Tasker} \", ");
messageContent.AppendLine(" \"flex\": 3, ");
messageContent.AppendLine(" \"size\": \"sm\", ");
messageContent.AppendLine(" \"weight\": \"regular\", ");
messageContent.AppendLine(" \"color\": \"#666666\", ");
messageContent.AppendLine(" \"wrap\": true ");
messageContent.AppendLine(" }, ");
messageContent.AppendLine(" { ");
messageContent.AppendLine(" \"type\": \"text\", ");
messageContent.AppendLine($" \"text\": \"內容:{task.Content}\", ");
messageContent.AppendLine(" \"flex\": 7, ");
messageContent.AppendLine(" \"size\": \"sm\", ");
messageContent.AppendLine(" \"weight\": \"regular\", ");
messageContent.AppendLine(" \"color\": \"#666666\", ");
messageContent.AppendLine(" \"wrap\": true ");
messageContent.AppendLine(" } ");
messageContent.AppendLine(" ] ");
messageContent.AppendLine(" }, ");
}
messageContent.AppendLine(" { ");
messageContent.AppendLine(" \"type\": \"separator\", ");
messageContent.AppendLine(" \"margin\": \"md\" ");
messageContent.AppendLine(" } ");
messageContent.AppendLine(" ], ");
messageContent.AppendLine(" \"paddingBottom\": \"none\" ");
messageContent.AppendLine(" }, ");
messageContent.AppendLine(" \"footer\": { ");
messageContent.AppendLine(" \"type\": \"box\", ");
messageContent.AppendLine(" \"layout\": \"vertical\", ");
messageContent.AppendLine(" \"contents\": [ ");
messageContent.AppendLine(" { ");
messageContent.AppendLine(" \"type\": \"button\", ");
messageContent.AppendLine(" \"action\": { ");
messageContent.AppendLine(" \"type\": \"uri\", ");
messageContent.AppendLine(" \"label\": \"管理分工\", ");
messageContent.AppendLine($" \"uri\": \"https://happiness.tours/myapp/happinessWeeks/395BBPTU4NG3F?openExternalBrowser={week.SEQ}\" ");
messageContent.AppendLine(" }, ");
messageContent.AppendLine(" \"style\": \"link\", ");
messageContent.AppendLine(" \"height\": \"md\" ");
messageContent.AppendLine(" } ");
messageContent.AppendLine(" ], ");
messageContent.AppendLine(" \"paddingAll\": \"none\" ");
messageContent.AppendLine(" } ");
if (week.SEQ < 8)
{
messageContent.AppendLine(" }, ");
}
else
{
messageContent.AppendLine(" } ");
}
}
messageContent.AppendLine(" ] ");
messageContent.AppendLine(" } ");
messageContent.AppendLine(" } ");
this.jsonMessage = messageContent.ToString();
}
private void PrepareLineMessage()
{
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/myapp/happinessWeeks/{pastoralDomain.Id}",
Label = "管理分工"
}
}
);
#endregion
list.Insert(0, flexMessage);
this.lineMessages = list;
}
}
}
@@ -13,6 +13,7 @@ namespace WebAPI.Services.Interfaces
string Description { get; }
IEnumerable<string> Commands { get; }
string ReplyTextMessage { get; }
string ReplyJsonMessage { get; }
IEnumerable<DomainType> SupportGroups { get; }
IEnumerable<ILineMessage> LineMessage { get; }
bool Enabled(PastoralDomain pastoralDomain = null, string command = null);
@@ -8,6 +8,7 @@ namespace WebAPI.Services.Interfaces
{
public interface IScheduledTask
{
static DateTime? NextRunningTime { get; set; }
string Description { get; }
bool CheckTime(DateTime time);
Task<bool> RunTask();
+50 -10
View File
@@ -1,4 +1,5 @@
using Church.Net.Entity;
using Church.Net.DAL.EFCoreDBF;
using Church.Net.Entity;
using Church.Net.Entity.Messenger;
using Church.Net.Utility;
using LineMessaging;
@@ -35,6 +36,7 @@ namespace WebAPI.Services
private readonly ILoggingService loggingService;
private readonly ICrudLogic<LineMessageClient> clientLogic;
private readonly LineMessagingAccountLogic lineMessagingAccountLogic;
private readonly ICrudDAL<LineMessagingAccount> lineAccountCrudDAL;
private string chatToken;
private PastoralDomain cellGroup;
@@ -43,13 +45,15 @@ namespace WebAPI.Services
IEnumerable<IAutoReplyCommand> autoReplyCommands,
ILoggingService loggingService,
ICrudLogic<LineMessageClient> clientLogic,
LineMessagingAccountLogic lineMessagingAccountLogic
LineMessagingAccountLogic lineMessagingAccountLogic,
ICrudDAL<LineMessagingAccount> lineAccountCrudDAL
)
{
this.autoReplyCommands = autoReplyCommands;
this.loggingService = loggingService;
this.clientLogic = clientLogic;
this.lineMessagingAccountLogic = lineMessagingAccountLogic;
this.lineAccountCrudDAL = lineAccountCrudDAL;
}
public void SendTextMessage(string text, LineGroup target)
{
@@ -96,6 +100,35 @@ namespace WebAPI.Services
return false;
}
}
public async Task<bool> ReplyJsonMessage(string lineId, string jsonMessage)
{
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;
//test.ReplyMessage(replyMessage);
try
{
await test.PushJsonMessage(lineId, jsonMessage);
return true;
}
catch (Exception ex)
{
this.loggingService.Error(ex, "ReplyTextMessage:75", jsonMessage);
if (ex.Message == "You have reached your monthly limit.")
{
this.SendTextMessage("Line Bot Exist Monthly Limit!!!", LineGroup.Chris);
}
return false;
}
}
public async Task<bool> ReplyLineMessage(string lineId, IEnumerable<ILineMessage> lineMessages)
{
var test = new LineMessagingClient(this.chatToken);
@@ -212,6 +245,10 @@ namespace WebAPI.Services
{
await ReplyLineMessage(target, autoReply.LineMessage);
}
else if (autoReply.ReplyJsonMessage != null)
{
await ReplyJsonMessage(target, autoReply.ReplyJsonMessage);
}
else
{
await ReplyTextMessage(replyToken, autoReply.ReplyTextMessage);
@@ -260,7 +297,7 @@ namespace WebAPI.Services
{
try
{
cellGroup = group;
if (command.IndexOf("#") == 0)
{
command = command.ToLower().Substring(1);
@@ -271,15 +308,18 @@ namespace WebAPI.Services
if (autoReply != null)
{
if (autoReply.LineMessage != null)
this.chatToken = this.lineAccountCrudDAL.First(x => x.Id == group.LineAccountId)?.ChatToken;
if (false == string.IsNullOrEmpty(this.chatToken))
{
await ReplyLineMessage(cellGroup.LineGroupId, autoReply.LineMessage);
if (autoReply.LineMessage != null)
{
await ReplyLineMessage(cellGroup.LineGroupId, autoReply.LineMessage);
}
else
{
await ReplyTextMessage(cellGroup.LineGroupId, autoReply.ReplyTextMessage);
}
}
else
{
await ReplyTextMessage(cellGroup.LineGroupId, autoReply.ReplyTextMessage);
}
return true;
}
//else if (command == "help" || command == "?")
@@ -11,7 +11,8 @@ namespace WebAPI.Services.ScheduledTask
private readonly LineAutoBotService lineAutoBotService;
private readonly ILoggingService loggingService;
private readonly PastoralDomainLogic pastoralDomainLogic;
private DateTime? nextRunningTime = null;
public static DateTime? NextRunningTime = null;
public MorningPrayer(
LineAutoBotService lineAutoBotService,
ILoggingService loggingService,
@@ -21,19 +22,19 @@ namespace WebAPI.Services.ScheduledTask
this.lineAutoBotService = lineAutoBotService;
this.loggingService = loggingService;
this.pastoralDomainLogic = pastoralDomainLogic;
this.SetNextRunningTime();
//this.SetNextRunningTime();
}
public string Description => "Sent out Ark Morning Prayer";
public bool CheckTime(DateTime time)
{
if(nextRunningTime == null)
if(NextRunningTime == null)
{
this.SetNextRunningTime();
return true;
return false;
}
return time >= nextRunningTime.Value;
return time >= NextRunningTime.Value;
}
public Task<bool> RunTask()
@@ -53,8 +54,8 @@ namespace WebAPI.Services.ScheduledTask
}
private void SetNextRunningTime()
{
nextRunningTime = DateTimeHelper.Today().AddDays(1).AddHours(8);
loggingService.Log($"Scheduled Task {this.Description}", nextRunningTime.Value);
NextRunningTime = DateTimeHelper.Today().AddDays(1).AddHours(8);
loggingService.Log($"Scheduled Task {this.Description}", NextRunningTime.Value);
}
}
}
+3 -3
View File
@@ -70,7 +70,8 @@ namespace WebAPI
services.AddDbContext<ChurchNetContext>(options =>
options.UseNpgsql(
//Configuration.GetConnectionString()
"Host=192.168.86.131;Port=49154;Database=ChurchSandbox;Username=chris;Password=1124"
//"Host=192.168.86.131;Port=49154;Database=ChurchSandbox;Username=chris;Password=1124"
"Host=192.168.86.131;Port=49154;Database=Church;Username=chris;Password=1124"
));
services.AddScoped<LineAutoBotService>();
@@ -94,8 +95,7 @@ namespace WebAPI
services.AddScoped<LineMessagingAccountLogic>();
services.AddScoped<ILoggingService, DbLoggingService>();
services.AddScoped<IdentityService>();
services.AddScoped<ICrudLogic<FamilyMember>, MemberLogic>();
services.AddHostedService<WorkerService>();
//services.AddMvc(o=>o.Filters.Add(typeof(HandleExceptionFilter)));
//services.AddMvc(o => o.Filters.Add(new HandleExceptionFilter(services.BuildServiceProvider().GetService<ILoggingService>())));