Merge branch 'main' into ec

This commit is contained in:
橙子
2021-11-09 17:05:59 +08:00
9 changed files with 74 additions and 11 deletions

View File

@@ -19,6 +19,8 @@
**Yi.Vue**Vue2.0配合CC.Yi.Framework使用前端项目正在更新 **Yi.Vue**Vue2.0配合CC.Yi.Framework使用前端项目正在更新
**分支ec**基于Yi.Framework微服务电商项目同步更新
**** ****
#### 支持: #### 支持:

View File

@@ -30,7 +30,8 @@ namespace Yi.Framework.ApiMicroservice.Controllers
private RabbitMQInvoker _rabbitMQInvoker; private RabbitMQInvoker _rabbitMQInvoker;
private CacheClientDB _cacheClientDB; private CacheClientDB _cacheClientDB;
private IRoleService _roleService; private IRoleService _roleService;
public AccountController(ILogger<UserController> logger, IUserService userService, IMenuService menuService,RabbitMQInvoker rabbitMQInvoker,CacheClientDB cacheClientDB, IRoleService roleService) private IHttpContextAccessor _httpContext;
public AccountController(ILogger<UserController> logger, IUserService userService, IMenuService menuService,RabbitMQInvoker rabbitMQInvoker,CacheClientDB cacheClientDB, IRoleService roleService, IHttpContextAccessor httpContext)
{ {
_logger = logger; _logger = logger;
_userService = userService; _userService = userService;
@@ -38,6 +39,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
_rabbitMQInvoker = rabbitMQInvoker; _rabbitMQInvoker = rabbitMQInvoker;
_cacheClientDB = cacheClientDB; _cacheClientDB = cacheClientDB;
_roleService = roleService; _roleService = roleService;
_httpContext = httpContext;
} }
@@ -94,6 +96,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
//设置默认头像 //设置默认头像
var setting = JsonHelper.StrToObj<SettingDto>(_cacheClientDB.Get<string>(RedisConst.key)); var setting = JsonHelper.StrToObj<SettingDto>(_cacheClientDB.Get<string>(RedisConst.key));
_user.icon = setting.InitIcon; _user.icon = setting.InitIcon;
_user.ip = _httpContext.HttpContext.Request.Headers["X-Real-IP"].FirstOrDefault();//通过上下文获取ip
//设置默认角色 //设置默认角色
if (string.IsNullOrEmpty(setting.InitRole)) if (string.IsNullOrEmpty(setting.InitRole))
{ {
@@ -117,6 +120,10 @@ namespace Yi.Framework.ApiMicroservice.Controllers
[HttpPost] [HttpPost]
public async Task<Result> SendSMS(string SMSAddress) public async Task<Result> SendSMS(string SMSAddress)
{ {
if (string.IsNullOrEmpty(SMSAddress))
{
return Result.Error("请输入电话号码");
}
SMSAddress = SMSAddress.Trim(); SMSAddress = SMSAddress.Trim();
if (!await _userService.PhoneIsExsit(SMSAddress)) if (!await _userService.PhoneIsExsit(SMSAddress))
{ {

View File

@@ -0,0 +1,53 @@
using Microsoft.Extensions.Options;
using Nest;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Common.IOCOptions;
namespace Yi.Framework.Core
{
public class ElasticSearchInvoker
{
private readonly ElasticSearchOptions _elasticSearchOptions;
public ElasticSearchInvoker(IOptionsMonitor<ElasticSearchOptions> optionsMonitor)
{
_elasticSearchOptions = optionsMonitor.CurrentValue;
var settings = new ConnectionSettings(new Uri(_elasticSearchOptions.Url)).DefaultIndex(this._elasticSearchOptions.IndexName);
Client = new ElasticClient(settings);
}
private ElasticClient Client;
public ElasticClient GetElasticClient()
{
return Client;
}
public void Send<T>(List<T> model) where T : class
{
Client.IndexMany(model);
}
public void InsertOrUpdata<T>(T model) where T : class
{
Client.IndexDocument(model);
}
public bool Delete<T>(string id) where T : class
{
var response = Client.Delete<T>(id);
return response.IsValid;
}
public bool DropIndex(string indexName)
{
return Client.Indices.Delete(Indices.Parse(indexName)).IsValid;
}
public void CreateIndex(string indexName)
{
var settings = new ConnectionSettings(new Uri(_elasticSearchOptions.Url)).DefaultIndex(indexName);
this.Client = new ElasticClient(settings);
}
}
}

View File

@@ -12,6 +12,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="5.0.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="5.0.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="5.0.0" /> <PackageReference Include="Microsoft.Extensions.Options" Version="5.0.0" />
<PackageReference Include="NEST" Version="7.15.2" />
<PackageReference Include="RabbitMQ.Client" Version="6.2.2" /> <PackageReference Include="RabbitMQ.Client" Version="6.2.2" />
</ItemGroup> </ItemGroup>

View File

@@ -4,10 +4,6 @@
<TargetFramework>net5.0</TargetFramework> <TargetFramework>net5.0</TargetFramework>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Folder Include="Search\" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="T4DataContext.cs"> <None Include="T4DataContext.cs">
<DesignTime>True</DesignTime> <DesignTime>True</DesignTime>

View File

@@ -59,7 +59,7 @@ namespace Yi.Framework.Service
public async Task<List<menu>> GetTopMenuByUserId(int userId) public async Task<List<menu>> GetTopMenuByUserId(int userId)
{ {
var user_data = await _DbRead.Set<user>().Include(u => u.roles).ThenInclude(u => u.menus).FirstOrDefaultAsync(); var user_data = await _DbRead.Set<user>().Include(u => u.roles).ThenInclude(u => u.menus).Where(u=>u.id==userId).FirstOrDefaultAsync();
List<menu> menuList = new(); List<menu> menuList = new();
user_data.roles.ForEach(u => user_data.roles.ForEach(u =>
{ {

View File

@@ -16,7 +16,8 @@ namespace Yi.Framework.Service
public async Task<List<role>> GetRolesByUserId(int userId) public async Task<List<role>> GetRolesByUserId(int userId)
{ {
var user_data =await _Db.Set<user>().Include(u => u.roles).Where(u => u.id==userId).FirstOrDefaultAsync(); var user_data =await _Db.Set<user>().Include(u => u.roles).Where(u => u.id==userId).FirstOrDefaultAsync();
var roleList = user_data.roles.Where(u=>u.is_delete==Normal).ToList(); var roleList = user_data.roles.Where(u=>u.is_delete==Normal).ToList();
roleList.ForEach(u => u.users = null);
return roleList; return roleList;
} }

View File

@@ -1,6 +1,7 @@
using Autofac; using Autofac;
using Autofac.Extras.DynamicProxy; using Autofac.Extras.DynamicProxy;
using Castle.DynamicProxy; using Castle.DynamicProxy;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.ApplicationParts; using Microsoft.AspNetCore.Mvc.ApplicationParts;
using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
@@ -36,11 +37,11 @@ namespace Yi.Framework.WebCore.Utility
containerBuilder.RegisterType<DbContextFactory>().As<IDbContextFactory>().InstancePerDependency().EnableInterfaceInterceptors(); containerBuilder.RegisterType<DbContextFactory>().As<IDbContextFactory>().InstancePerDependency().EnableInterfaceInterceptors();
containerBuilder.RegisterType< HttpContextAccessor>().As<IHttpContextAccessor>().SingleInstance();
///反射注入服务层及接口层
///反射注入服务层及接口层
var assemblysServices = GetDll( "Yi.Framework.Service.dll"); var assemblysServices = GetDll( "Yi.Framework.Service.dll");
containerBuilder.RegisterAssemblyTypes(assemblysServices) containerBuilder.RegisterAssemblyTypes(assemblysServices)
.AsImplementedInterfaces() .AsImplementedInterfaces()

View File

@@ -57,7 +57,7 @@
</v-text-field> </v-text-field>
</v-col> </v-col>
<v-col cols="3"> <v-col cols="3">
<app-btn @click="sendSMS" class="mb-1 mt-1">验证码</app-btn> <v-btn color="secondary" @click="sendSMS" class="mb-1 mt-1" :disabled="is_en">验证码</v-btn>
</v-col> </v-col>
</v-row> </v-row>
<v-text-field <v-text-field
@@ -113,6 +113,7 @@ import accoutAPI from "../api/accountApi";
export default { export default {
methods: { methods: {
sendSMS() { sendSMS() {
this.is_en=true
accoutAPI.SendSMS(this.form.phone).then(resp=>{ accoutAPI.SendSMS(this.form.phone).then(resp=>{
if (resp.status) { if (resp.status) {
this.$dialog.notify.success(resp.msg, { this.$dialog.notify.success(resp.msg, {
@@ -171,6 +172,7 @@ export default {
], ],
isPasswordVisible: false, isPasswordVisible: false,
code: "", code: "",
is_en:false,
form: { form: {
phone: "", phone: "",
username: "", username: "",