From 9a34e63d5fde5e201542c7004e2735cdd40c91a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=B7=B3?= Date: Tue, 29 Nov 2022 18:47:26 +0800 Subject: [PATCH] =?UTF-8?q?=E7=82=B9=E8=B5=9E=E5=8A=9F=E8=83=BD=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WebFirst/database/sqlite.db | Bin 651264 -> 651264 bytes .../Config/SwaggerDoc.xml | 42 ++++--- .../Controllers/Community/AgreeController.cs | 66 +++++++++++ .../ArticleController.cs | 5 +- .../Controllers/TestController.cs | 4 +- .../Yi.Framework.ApiMicroservice/Program.cs | 6 +- .../yi-sqlsugar-dev.db | Bin 241664 -> 253952 bytes .../Yi.Framework.Core.csproj | 2 - .../{ => Vo}/ArticleVo.cs | 22 ++-- .../Yi.Framework.DTOModel/{ => Vo}/UserVo.cs | 2 +- .../IServiceTemplate/IAgreeService.cs | 9 ++ .../ModelsTemplate/AgreeEntity.cs | 47 ++++++++ .../ModelsTemplate/ArticleEntity.cs | 15 ++- .../ServiceTemplate/AgreeService.cs | 14 +++ .../Mapper/Profile/AutoMapperProfile.cs | 2 +- Yi.Vue3.x.Vant/components.d.ts | 3 - Yi.Vue3.x.Vant/index.html | 2 +- Yi.Vue3.x.Vant/src/view/login.vue | 4 +- Yi.Vue3.x.Vant/src/view/main/recommend.vue | 60 ++++++---- Yi.Vue3.x.Vant/src/view/send/imageText.vue | 109 ++++++++++-------- 20 files changed, 296 insertions(+), 118 deletions(-) create mode 100644 Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/Community/AgreeController.cs rename Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/{Article => Community}/ArticleController.cs (95%) rename Yi.Framework.Net6/Yi.Framework.DTOModel/{ => Vo}/ArticleVo.cs (89%) rename Yi.Framework.Net6/Yi.Framework.DTOModel/{ => Vo}/UserVo.cs (95%) create mode 100644 Yi.Framework.Net6/Yi.Framework.Interface/IServiceTemplate/IAgreeService.cs create mode 100644 Yi.Framework.Net6/Yi.Framework.Model/ModelsTemplate/AgreeEntity.cs create mode 100644 Yi.Framework.Net6/Yi.Framework.Service/ServiceTemplate/AgreeService.cs diff --git a/WebFirst/database/sqlite.db b/WebFirst/database/sqlite.db index df70988a1e8f5a132f8a1432d7a40a20fdd5f300..bf89162082cbc0cac57157d642fa0da6f3aa3e33 100644 GIT binary patch delta 406 zcmZp8px*F6eS)-LG6Ms{d?1E_`4e@F8Iw0Ai0LziPA=D%Wqj5=Rlj|zKI8VO`b_x( z%z_-Brn5URDKc?<+UzKBg2Or?l$(K3TwLDS*qDQZ#WB4oH5E)eZ`%1{>%12WR~Q)> z8R;4t>Ka)p7+P2vn^>6`>KParn46kUE_|WBJ;ak~1Ct0`+SJOxK+n|7#N6C?x}qVI zdb_<36A&{4F$)m00x=s9vjZ{5c6%Srqm!9cIjyF%Kj5_G=85zJX^DE7T(GW*Io4Vm;dw*tLiJwM$%Jc?BCUurjllJ84 zj$as!SweN&lcp;kW7L?wL70ifFjT8Ok()tY9%!JfDA2&7lFa0sRL>MRYi.Framework.ApiMicroservice - - - 动态条件分页查询 - - - - - - - - 添加 - - - - Json To Sql 类比模式,通用模型 @@ -150,6 +135,33 @@ + + + 点赞操作 + + + + + + + 文章控制器 + + + + + 动态条件分页查询 + + + + + + + + 添加 + + + + 动态条件分页查询 diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/Community/AgreeController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/Community/AgreeController.cs new file mode 100644 index 00000000..721882b3 --- /dev/null +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/Community/AgreeController.cs @@ -0,0 +1,66 @@ +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; +using Org.BouncyCastle.Asn1.IsisMtt.X509; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Yi.Framework.Common.Models; +using Yi.Framework.DTOModel.Vo; +using Yi.Framework.Interface; +using Yi.Framework.Model.Models; +using Yi.Framework.Repository; +using Yi.Framework.Service; +using Yi.Framework.WebCore; +using Yi.Framework.WebCore.AttributeExtend; +using Yi.Framework.WebCore.AuthorizationPolicy; + +namespace Yi.Framework.ApiMicroservice.Controllers +{ + [ApiController] + [Route("api/[controller]/[action]")] + public class AgreeController : ControllerBase + { + [Autowired] + public IAgreeService _iAgreeService { get; set; } + [Autowired] + public IArticleService _iArticleService { get; set; } + [Autowired] + public ILogger _logger { get; set; } + + /// + /// 点赞操作 + /// + /// + /// + [HttpGet] + public async Task Operate(long articleId) + { + //long userId = HttpContext.GetUserIdInfo(); + long userId = 1L; + var article = await _iArticleService._repository.GetByIdAsync(articleId); + if (await _iAgreeService._repository.IsAnyAsync(u => u.UserId == userId && u.ArticleId == articleId)) + { + //已点赞,取消点赞 + await _iAgreeService._repository.UseTranAsync(async () => + { + await _iAgreeService._repository.DeleteAsync(u => u.UserId == userId && u.ArticleId == articleId); + await _iArticleService._repository.UpdateIgnoreNullAsync(new ArticleEntity { Id = articleId, AgreeNum = article.AgreeNum - 1 }); + + }); + } + else + { + //未点赞,添加点赞记录 + await _iAgreeService._repository.UseTranAsync(async () => + { + await _iAgreeService._repository.InsertAsync(new AgreeEntity { UserId = userId, ArticleId = articleId }); + await _iArticleService._repository.UpdateIgnoreNullAsync(new ArticleEntity { Id = articleId, AgreeNum = article.AgreeNum + 1 }); + }); + + } + return Result.Success("这里业务全部拆开放service层去"); + } + } +} diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/Article/ArticleController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/Community/ArticleController.cs similarity index 95% rename from Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/Article/ArticleController.cs rename to Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/Community/ArticleController.cs index 36ee1e7a..644e1e5c 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/Article/ArticleController.cs +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/Community/ArticleController.cs @@ -7,7 +7,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Yi.Framework.Common.Models; -using Yi.Framework.DTOModel; +using Yi.Framework.DTOModel.Vo; using Yi.Framework.Interface; using Yi.Framework.Model.Models; using Yi.Framework.Repository; @@ -17,6 +17,9 @@ using Yi.Framework.WebCore.AuthorizationPolicy; namespace Yi.Framework.ApiMicroservice.Controllers { + /// + /// 文章控制器 + /// [ApiController] [Route("api/[controller]/[action]")] public class ArticleController : BaseSimpleCrudController diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/TestController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/TestController.cs index e218d8e4..c577da40 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/TestController.cs +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/TestController.cs @@ -1,6 +1,4 @@ -using Hangfire; -using Hangfire.MemoryStorage.Database; -using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.SignalR; using Microsoft.Extensions.Localization; diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Program.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Program.cs index bd4402c8..403da255 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Program.cs +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Program.cs @@ -18,8 +18,6 @@ using Yi.Framework.WebCore.LogExtend; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.AspNetCore.Mvc.Controllers; using Yi.Framework.WebCore.AutoFacExtend; -using Hangfire; -using Hangfire.MemoryStorage; var builder = WebApplication.CreateBuilder(args); builder.Configuration.AddCommandLine(args); @@ -43,14 +41,14 @@ builder.Host.ConfigureContainer(containerBuilder => #region //עģ #endregion - //containerBuilder.RegisterModule(); + containerBuilder.RegisterModule(); #region //ʹAppServiceŵĽԶע,ִʹøַʽԶע #endregion containerBuilder.AddAutoIocService("Yi.Framework.Repository", "Yi.Framework.Service"); }); ////ע룬mvcģתӸioc -//builder.Services.Replace(ServiceDescriptor.Transient()); +builder.Services.Replace(ServiceDescriptor.Transient()); builder.Host.ConfigureLogging(loggingBuilder => { diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db index 8aa31d6c5f18f103c57084003674265a14602bc6..25d6f2151221723ba5c26e855f1e405b8dd65b5c 100644 GIT binary patch delta 3026 zcmb`Jd2AF_7{KSvYk_cY$8NP1wtv15UZl12LG@afsp7Q2qB^Yqi=S*wd`tz)JgX3eDmJC z-+b5mzRVB4OdouuBCrC(usZb1UlTjSLU0Afgcp~fM+CfSP1M1=@K<>A{jJZ#iAbC} z9S!5k(NOC3q7lGt7~FO=;BSTL9d_We)3hC%gJC3^Yc8vfe{#9sk6k_4eeKZ6s~;Y? zzJKp_bQQ{FMBU)PPCv%8JWq2R&1)1VMnoaPX^f^SEHCq`LY$;2qRR2I%5$QiumUTF z!Xuta<0X+}RgG6et6kYIyN$uy=*xbB9yeik=0D~Qf5VXu(Czg3F)!AMVV#D{5B9ir z%>#~LMFn^7!BSe8UHrEwUYpkNcH1iz_L|nM9-n>=?RuVR3 zy1iZ9CFO>{8rV#o0ULl_@Y#b;O) z-7)wv@^+5a+>&hA(fzDN6S=6OXfc6i6 zSV-#_{9yJ-*b+~gwP=DC)#N0r&}vMQX_4i0T9;XoPVz}k)uK^B(_^F41U2O=ruE_@ zX>XQa&L9}CB@~`hMLNnUi8L*8adfN7G98WToE}wGO_kWuX{?s=7SrAx*3EL;lUFPl zCMA=anvi)q&gn^76nF`_O-a(c!b=hxPm4-I;z#kD#AuqB@)XgUz8ltUEJ2da=Prs8 zAtI`bCQB)IG41PN-TtQ_$-%_5oN^V@F64!}>F2eGRqHrmDF>NEYsq5+Fz8g?8HzZKx=gRk!!P)c?@BjjkFS zkwivH%c{V$LW(HVFMjIoefo{H3S?_Dt1_ynr0~CCx>fX1nLTxVc3!_RSaaBzd72{2 z#y~yL9uL4U2JgWe@JIL!JP(h>Xd!B;XQWMjjY6LM}N@`7bmoFGW2)fSXGE*g%-pb~dnM2f!c2yQ6# z+XK@lPn=S1wO{BWktYs#jnhq_!r!uZeS2G?<>{pqConuC7?~yz95>Wv@ey8PWJwe? zO)~47z&Qs|3WHsa%rvy~&pyk9q_tJQA1gJdwuA5cXs{pkP6Fmz4_@_#oeLe?9m`94 z9AV;0$yU%$oWKP4LeE*}CHHveA?G2JVew{Qb8g3MMm+;-eFQ1)5q39lxxQ%S<;Y?e-CjN7^jVkS<4s?G4Ek8W}M3Nm;XGsFV7Lq8{8s1N7%);>lrYmGfuyJpILYNAw#A;>@3`_ z3{le!Y?;Eg->_uLW#r)b%D@410K@jg+sx&R(~sCN8FB!F5F*BSm-!OY^c#1WHQ9km VKw_K!>oYnm3Qz!|We1o(004@4b=?2} diff --git a/Yi.Framework.Net6/Yi.Framework.Core/Yi.Framework.Core.csproj b/Yi.Framework.Net6/Yi.Framework.Core/Yi.Framework.Core.csproj index ecc2430b..52c81d84 100644 --- a/Yi.Framework.Net6/Yi.Framework.Core/Yi.Framework.Core.csproj +++ b/Yi.Framework.Net6/Yi.Framework.Core/Yi.Framework.Core.csproj @@ -8,8 +8,6 @@ - - diff --git a/Yi.Framework.Net6/Yi.Framework.DTOModel/ArticleVo.cs b/Yi.Framework.Net6/Yi.Framework.DTOModel/Vo/ArticleVo.cs similarity index 89% rename from Yi.Framework.Net6/Yi.Framework.DTOModel/ArticleVo.cs rename to Yi.Framework.Net6/Yi.Framework.DTOModel/Vo/ArticleVo.cs index c862535e..bbe8fd48 100644 --- a/Yi.Framework.Net6/Yi.Framework.DTOModel/ArticleVo.cs +++ b/Yi.Framework.Net6/Yi.Framework.DTOModel/Vo/ArticleVo.cs @@ -4,32 +4,32 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Yi.Framework.DTOModel +namespace Yi.Framework.DTOModel.Vo { public class ArticleVo { public long Id { get; set; } - + public string Title { get; set; } - + public string Content { get; set; } - + public long? UserId { get; set; } public long? CreateUser { get; set; } - + public DateTime? CreateTime { get; set; } - + public long? ModifyUser { get; set; } - + public DateTime? ModifyTime { get; set; } - + public bool? IsDeleted { get; set; } - + public long? TenantId { get; set; } - + public int? OrderNum { get; set; } - + public string Remark { get; set; } public List Images { get; set; } diff --git a/Yi.Framework.Net6/Yi.Framework.DTOModel/UserVo.cs b/Yi.Framework.Net6/Yi.Framework.DTOModel/Vo/UserVo.cs similarity index 95% rename from Yi.Framework.Net6/Yi.Framework.DTOModel/UserVo.cs rename to Yi.Framework.Net6/Yi.Framework.DTOModel/Vo/UserVo.cs index fb183e36..3620f95d 100644 --- a/Yi.Framework.Net6/Yi.Framework.DTOModel/UserVo.cs +++ b/Yi.Framework.Net6/Yi.Framework.DTOModel/Vo/UserVo.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Yi.Framework.DTOModel +namespace Yi.Framework.DTOModel.Vo { /// /// 前端只需要这些数据即可 diff --git a/Yi.Framework.Net6/Yi.Framework.Interface/IServiceTemplate/IAgreeService.cs b/Yi.Framework.Net6/Yi.Framework.Interface/IServiceTemplate/IAgreeService.cs new file mode 100644 index 00000000..6d7ccb97 --- /dev/null +++ b/Yi.Framework.Net6/Yi.Framework.Interface/IServiceTemplate/IAgreeService.cs @@ -0,0 +1,9 @@ +using Yi.Framework.Model.Models; +using Yi.Framework.Repository; + +namespace Yi.Framework.Interface +{ + public partial interface IAgreeService:IBaseService + { + } +} diff --git a/Yi.Framework.Net6/Yi.Framework.Model/ModelsTemplate/AgreeEntity.cs b/Yi.Framework.Net6/Yi.Framework.Model/ModelsTemplate/AgreeEntity.cs new file mode 100644 index 00000000..b66856e6 --- /dev/null +++ b/Yi.Framework.Net6/Yi.Framework.Model/ModelsTemplate/AgreeEntity.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text.Json.Serialization; +using SqlSugar; +namespace Yi.Framework.Model.Models +{ + /// + /// 点赞表 + /// + [SugarTable("Agree")] + public partial class AgreeEntity + { + public AgreeEntity() + { + this.CreateTime = DateTime.Now; + } + [JsonConverter(typeof(ValueToStringConverter))] + [SugarColumn(ColumnName="Id" ,IsPrimaryKey = true )] + public long Id { get; set; } + /// + /// 用户id + /// + [SugarColumn(ColumnName="UserId" )] + public long? UserId { get; set; } + /// + /// 文章id + /// + [SugarColumn(ColumnName="ArticleId" )] + public long? ArticleId { get; set; } + /// + /// 创建者 + /// + [SugarColumn(ColumnName="CreateUser" )] + public long? CreateUser { get; set; } + /// + /// 创建时间 + /// + [SugarColumn(ColumnName="CreateTime" )] + public DateTime? CreateTime { get; set; } + /// + /// 租户Id + /// + [SugarColumn(ColumnName="TenantId" )] + public long? TenantId { get; set; } + } +} diff --git a/Yi.Framework.Net6/Yi.Framework.Model/ModelsTemplate/ArticleEntity.cs b/Yi.Framework.Net6/Yi.Framework.Model/ModelsTemplate/ArticleEntity.cs index c1dceebc..7151223a 100644 --- a/Yi.Framework.Net6/Yi.Framework.Model/ModelsTemplate/ArticleEntity.cs +++ b/Yi.Framework.Net6/Yi.Framework.Model/ModelsTemplate/ArticleEntity.cs @@ -22,12 +22,12 @@ namespace Yi.Framework.Model.Models /// 文章标题 /// [SugarColumn(ColumnName="Title" )] - public string? Title { get; set; } + public string Title { get; set; } /// /// 文章内容 /// [SugarColumn(ColumnName="Content" )] - public string? Content { get; set; } + public string Content { get; set; } /// /// 用户id /// @@ -72,11 +72,16 @@ namespace Yi.Framework.Model.Models /// 描述 /// [SugarColumn(ColumnName="Remark" )] - public string? Remark { get; set; } + public string Remark { get; set; } /// /// 图片列表 /// - [SugarColumn(ColumnName="Images",IsJson = true)] - public List? Images { get; set; } + [SugarColumn(ColumnName="Images" )] + public string Images { get; set; } + /// + /// 点赞数量 + /// + [SugarColumn(ColumnName="AgreeNum" )] + public int? AgreeNum { get; set; } } } diff --git a/Yi.Framework.Net6/Yi.Framework.Service/ServiceTemplate/AgreeService.cs b/Yi.Framework.Net6/Yi.Framework.Service/ServiceTemplate/AgreeService.cs new file mode 100644 index 00000000..27d48eee --- /dev/null +++ b/Yi.Framework.Net6/Yi.Framework.Service/ServiceTemplate/AgreeService.cs @@ -0,0 +1,14 @@ +using SqlSugar; +using Yi.Framework.Interface; +using Yi.Framework.Model.Models; +using Yi.Framework.Repository; + +namespace Yi.Framework.Service +{ + public partial class AgreeService : BaseService, IAgreeService + { + public AgreeService(IRepository repository) : base(repository) + { + } + } +} diff --git a/Yi.Framework.Net6/Yi.Framework.WebCore/Mapper/Profile/AutoMapperProfile.cs b/Yi.Framework.Net6/Yi.Framework.WebCore/Mapper/Profile/AutoMapperProfile.cs index da65a8c3..0f1929e4 100644 --- a/Yi.Framework.Net6/Yi.Framework.WebCore/Mapper/Profile/AutoMapperProfile.cs +++ b/Yi.Framework.Net6/Yi.Framework.WebCore/Mapper/Profile/AutoMapperProfile.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using Yi.Framework.DTOModel; +using Yi.Framework.DTOModel.Vo; using Yi.Framework.Model.Models; namespace Yi.Framework.WebCore.Mapper diff --git a/Yi.Vue3.x.Vant/components.d.ts b/Yi.Vue3.x.Vant/components.d.ts index 26d80cd0..a63a89cb 100644 --- a/Yi.Vue3.x.Vant/components.d.ts +++ b/Yi.Vue3.x.Vant/components.d.ts @@ -14,9 +14,6 @@ declare module '@vue/runtime-core' { HelloWorld: typeof import('./src/components/HelloWorld.vue')['default'] RouterLink: typeof import('vue-router')['RouterLink'] RouterView: typeof import('vue-router')['RouterView'] - VanActionBar: typeof import('vant/es')['ActionBar'] - VanActionBarButton: typeof import('vant/es')['ActionBarButton'] - VanActionBarIcon: typeof import('vant/es')['ActionBarIcon'] VanActionSheet: typeof import('vant/es')['ActionSheet'] VanButton: typeof import('vant/es')['Button'] VanCell: typeof import('vant/es')['Cell'] diff --git a/Yi.Vue3.x.Vant/index.html b/Yi.Vue3.x.Vant/index.html index 5e7092b5..3372eb7f 100644 --- a/Yi.Vue3.x.Vant/index.html +++ b/Yi.Vue3.x.Vant/index.html @@ -4,7 +4,7 @@ - 大白荟 + 意框架
diff --git a/Yi.Vue3.x.Vant/src/view/login.vue b/Yi.Vue3.x.Vant/src/view/login.vue index 6b1b917a..0bd37a7e 100644 --- a/Yi.Vue3.x.Vant/src/view/login.vue +++ b/Yi.Vue3.x.Vant/src/view/login.vue @@ -1,6 +1,6 @@ \ No newline at end of file diff --git a/Yi.Vue3.x.Vant/src/view/send/imageText.vue b/Yi.Vue3.x.Vant/src/view/send/imageText.vue index 6fbf7933..50026ea1 100644 --- a/Yi.Vue3.x.Vant/src/view/send/imageText.vue +++ b/Yi.Vue3.x.Vant/src/view/send/imageText.vue @@ -9,7 +9,12 @@ 发图文 - 发布 + 发布 @@ -39,28 +44,33 @@ - + \ No newline at end of file