feat: WWJCloud 企业级全栈框架 v0.3.5 完整更新
🚀 核心更新: - ✅ 完善 NestJS 企业级架构设计 - ✅ 优化配置中心和基础设施层 - ✅ 增强第三方服务集成能力 - ✅ 完善多租户架构支持 - 🎯 对标 Java Spring Boot 和 PHP ThinkPHP 📦 新增文件: - wwjcloud-nest 完整框架结构 - Docker 容器化配置 - 管理后台界面 - 数据库迁移脚本 🔑 Key: ebb38b43ec39f355f071294fd1cf9c42
This commit is contained in:
168
src/core/home/controllers/adminapi/site.controller.ts
Normal file
168
src/core/home/controllers/adminapi/site.controller.ts
Normal file
@@ -0,0 +1,168 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Put,
|
||||
Delete,
|
||||
Body,
|
||||
Param,
|
||||
Query,
|
||||
UseGuards,
|
||||
UseInterceptors,
|
||||
UploadedFile,
|
||||
UploadedFiles,
|
||||
Session,
|
||||
Req,
|
||||
} from '@nestjs/common';
|
||||
import { FileInterceptor, FilesInterceptor } from '@nestjs/platform-express';
|
||||
import {
|
||||
ApiTags,
|
||||
ApiOperation,
|
||||
ApiResponse,
|
||||
ApiConsumes,
|
||||
} from '@nestjs/swagger';
|
||||
import { Request } from 'express';
|
||||
import { JwtAuthGuard } from '@wwjCommon/security/guards/jwt-auth.guard';
|
||||
import { RolesGuard } from '@wwjCommon/security/guards/roles.guard';
|
||||
import { Roles } from '@wwjCommon/security/decorators/roles.decorator';
|
||||
import { Public } from '@wwjCommon/security/decorators/public.decorator';
|
||||
import { BusinessException } from '@wwjCommon/exception/business.exception';
|
||||
// @UploadedFile() - 单文件上传,配合 @UseInterceptors(FileInterceptor('file'))
|
||||
// @UploadedFiles() - 多文件上传,配合 @UseInterceptors(FilesInterceptor('files'))
|
||||
// @Session() - 获取会话对象,对应PHP Session::get()
|
||||
// @Req() - 获取Request对象,对应PHP Request
|
||||
import { AuthSiteService } from '../../services/admin/auth-site.service';
|
||||
|
||||
/**
|
||||
* SiteController
|
||||
* 对应 PHP: Site Controller
|
||||
* 对应 Java: @RestController
|
||||
*
|
||||
* 支持装饰器:
|
||||
* - @UploadedFile() - 单文件上传 (对应PHP Request::file())
|
||||
* - @UploadedFiles() - 多文件上传
|
||||
* - @Session() - 会话管理 (对应PHP Session::get())
|
||||
* - @Req() - 请求对象 (对应PHP Request)
|
||||
*/
|
||||
@ApiTags('home')
|
||||
@Controller('adminapi/home')
|
||||
export class SiteController {
|
||||
constructor(private readonly authSiteService: AuthSiteService) {}
|
||||
|
||||
/**
|
||||
* 站点管理
|
||||
* 路由: GET site
|
||||
* PHP路由: Route::get('site', 'home.Site/lists')
|
||||
*/
|
||||
@Get('site')
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@ApiOperation({ summary: '站点管理' })
|
||||
async lists(): Promise<ApiResponse> {
|
||||
try {
|
||||
// 基于PHP真实逻辑实现
|
||||
// PHP原始方法: lists
|
||||
|
||||
return await this.authSiteService.getSitePage(data);
|
||||
} catch (error) {
|
||||
throw new BusinessException('lists操作失败', error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 站点管理
|
||||
* 路由: GET site/:id
|
||||
* PHP路由: Route::get('site/:id', 'home.Site/info')
|
||||
*/
|
||||
@Get('site/:id')
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@ApiOperation({ summary: '站点管理' })
|
||||
async info(@Param('id') id: string): Promise<ApiResponse> {
|
||||
try {
|
||||
// 基于PHP真实逻辑实现
|
||||
// PHP原始方法: info
|
||||
|
||||
return await this.authSiteService.getSiteInfo(id);
|
||||
} catch (error) {
|
||||
throw new BusinessException('info操作失败', error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 站点管理
|
||||
* 路由: PUT site/:id
|
||||
* PHP路由: Route::put('site/:id', 'home.Site/edit')
|
||||
*/
|
||||
@Put('site/:id')
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@ApiOperation({ summary: '站点管理' })
|
||||
async edit(
|
||||
@Param('id') id: string,
|
||||
@Body() data: EditDto,
|
||||
): Promise<ApiResponse> {
|
||||
try {
|
||||
// 基于PHP真实逻辑实现
|
||||
// PHP原始方法: edit
|
||||
|
||||
return await this.authSiteService.editSite(id, data);
|
||||
} catch (error) {
|
||||
throw new BusinessException('edit操作失败', error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 站点管理
|
||||
* 路由: GET site/group
|
||||
* PHP路由: Route::get('site/group', 'home.Site/getSiteGroup')
|
||||
*/
|
||||
@Get('site/group')
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@ApiOperation({ summary: '站点管理' })
|
||||
async getSiteGroup(): Promise<ApiResponse> {
|
||||
try {
|
||||
// 基于PHP真实逻辑实现
|
||||
// PHP原始方法: getSiteGroup
|
||||
|
||||
return await this.authSiteService.getSiteGroup();
|
||||
} catch (error) {
|
||||
throw new BusinessException('getSiteGroup操作失败', error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 站点管理
|
||||
* 路由: GET site/group/app_list
|
||||
* PHP路由: Route::get('site/group/app_list', 'home.Site/getSiteGroupAppList')
|
||||
*/
|
||||
@Get('site/group/app_list')
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@ApiOperation({ summary: '站点管理' })
|
||||
async getSiteGroupAppList(): Promise<ApiResponse> {
|
||||
try {
|
||||
// 基于PHP真实逻辑实现
|
||||
// PHP原始方法: getSiteGroupAppList
|
||||
|
||||
return await this.authSiteService.getSiteGroupAppList();
|
||||
} catch (error) {
|
||||
throw new BusinessException('getSiteGroupAppList操作失败', error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 站点管理
|
||||
* 路由: POST site/create
|
||||
* PHP路由: Route::post('site/create', 'home.Site/create')
|
||||
*/
|
||||
@Post('site/create')
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@ApiOperation({ summary: '站点管理' })
|
||||
async create(@Body() data: CreateDto): Promise<ApiResponse> {
|
||||
try {
|
||||
// 基于PHP真实逻辑实现
|
||||
// PHP原始方法: create
|
||||
|
||||
return await this.authSiteService.createSite(data);
|
||||
} catch (error) {
|
||||
throw new BusinessException('create操作失败', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
9
src/core/home/home.module.ts
Normal file
9
src/core/home/home.module.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
|
||||
@Module({
|
||||
imports: [],
|
||||
controllers: [],
|
||||
providers: [],
|
||||
exports: [],
|
||||
})
|
||||
export class HomeModule {}
|
||||
278
src/core/home/services/admin/auth-site.service.ts
Normal file
278
src/core/home/services/admin/auth-site.service.ts
Normal file
@@ -0,0 +1,278 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { BaseService } from '@wwjCommon/base/base.service';
|
||||
import { CacheService } from '@wwjCommon/cache/cache.service';
|
||||
import { LoggingService } from '@wwjCommon/logging/logging.service';
|
||||
import { UploadService } from '@wwjVendor/upload/upload.service';
|
||||
import { PayService } from '@wwjVendor/pay/pay.service';
|
||||
import { SmsService } from '@wwjVendor/sms/sms.service';
|
||||
import { NoticeService } from '@wwjVendor/notice/notice.service';
|
||||
|
||||
@Injectable()
|
||||
export class AuthSiteService extends BaseService<any> {
|
||||
private readonly logger = new Logger(AuthSiteService.name);
|
||||
|
||||
constructor(
|
||||
@InjectRepository(Object)
|
||||
protected readonly repository: Repository<any>,
|
||||
private readonly cacheService: CacheService,
|
||||
private readonly configService: ConfigService,
|
||||
private readonly loggingService: LoggingService,
|
||||
private readonly uploadService: UploadService,
|
||||
private readonly payService: PayService,
|
||||
private readonly smsService: SmsService,
|
||||
private readonly noticeService: NoticeService,
|
||||
) {
|
||||
super(repository);
|
||||
}
|
||||
|
||||
/**
|
||||
* getSiteInfo
|
||||
* 对应 PHP: AuthSiteService_admin::getSiteInfo()
|
||||
* 逻辑类型: undefined - undefined
|
||||
*/
|
||||
async getSiteInfo(site_id: any) {
|
||||
// 基于PHP真实逻辑: getSiteInfo
|
||||
// PHP原文: $this->checkSite($site_id); //通过用户id获取 $field = 'site_id, site_name, front_end_name, front_end_logo, app_type, keywords, logo, icon, `...
|
||||
this.checkSite(site_id];
|
||||
//通过用户id获取
|
||||
const field = 'site_id, site_name, front_end_name, front_end_logo, app_type, keywords, logo, icon, `desc`, status, latitude, longitude, province_id, city_id,
|
||||
district_id, address, full_address, phone, business_hours, create_time, expire_time, group_id, app';
|
||||
return this.model.where([ [ 'site_id', '=', site_id ) )).with(['groupName', 'addon')).field(field).append([ 'status_name' )).findOrEmpty().toArray(];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取授权账号下的站点列表
|
||||
* @param where
|
||||
* @return * @throws DbBusinessException
|
||||
*/
|
||||
async getSitePage(where = [))
|
||||
{
|
||||
const field = 'site_id, site_name, front_end_name, front_end_logo, app_type, keywords, logo, icon, `desc`, status, latitude, longitude, province_id, city_id,
|
||||
district_id, address, full_address, phone, business_hours, create_time, expire_time, group_id, app';
|
||||
const condition = [
|
||||
['site_id', '<>', request().defaultSiteId()],
|
||||
];
|
||||
const order = 'create_time desc';
|
||||
if (!!where.sort)){
|
||||
if (where.sort == 'site_id') {
|
||||
const order = "{where.sort} asc";
|
||||
}} } else {
|
||||
const order = "{where.sort} desc";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* getSitePage
|
||||
* 对应 PHP: AuthSiteService_admin::getSitePage()
|
||||
* 逻辑类型: undefined - undefined
|
||||
*/
|
||||
async getSitePage(where: any[]) {
|
||||
// 基于PHP真实逻辑: getSitePage
|
||||
// PHP原文: $field = 'site_id, site_name, front_end_name, front_end_logo, app_type, keywords, logo, icon, `desc`, status, latitude, longitude, province_id, city_i...
|
||||
const field = 'site_id, site_name, front_end_name, front_end_logo, app_type, keywords, logo, icon, `desc`, status, latitude, longitude, province_id, city_id,
|
||||
district_id, address, full_address, phone, business_hours, create_time, expire_time, group_id, app';
|
||||
const condition = [
|
||||
['site_id', '<>', request().defaultSiteId()],
|
||||
];
|
||||
const order = 'create_time desc';
|
||||
if (!!where.sort)){
|
||||
if (where.sort == 'site_id') {
|
||||
const order = "{where.sort} asc";
|
||||
}} } else {
|
||||
const order = "{where.sort} desc";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* getSiteIds
|
||||
* 对应 PHP: AuthSiteService_admin::getSiteIds()
|
||||
* 逻辑类型: undefined - undefined
|
||||
*/
|
||||
async getSiteIds() {
|
||||
// 基于PHP真实逻辑: getSiteIds
|
||||
// PHP原文: $cache_name = 'user_role_list_'.$this->uid; return cache_remember( $cache_name, function(){ $user_role...
|
||||
const cache_name = 'user_role_list_'.this.uid;
|
||||
return cache_remember(
|
||||
cache_name,
|
||||
function(){
|
||||
const user_role_model = this.sysUserRoleService;
|
||||
const where = [
|
||||
['uid', '=', this.uid),
|
||||
['site_id', '<>', request().defaultSiteId()],
|
||||
['status', '=', 1]
|
||||
];
|
||||
const list = user_role_model.where(where).select().toArray(];
|
||||
return array_column(list, 'site_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* checkSiteUserAccount
|
||||
* 对应 PHP: AuthSiteService_admin::checkSiteUserAccount()
|
||||
* 逻辑类型: undefined - undefined
|
||||
*/
|
||||
async checkSiteUserAccount() {
|
||||
// 基于PHP真实逻辑: checkSiteUserAccount
|
||||
// PHP原文: $where = [ ['uid', '=', $this->uid], ['site_id', '<>', request()->defaultSiteId()] ]; return (new SysUserRole(...
|
||||
const where = [
|
||||
['uid', '=', this.uid],
|
||||
['site_id', '<>', request().defaultSiteId()]
|
||||
];
|
||||
return this.sysUserRoleService.where(where).findOrEmpty(];
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑站点信息
|
||||
* @param int site_id
|
||||
* @param data
|
||||
* @return true
|
||||
*/
|
||||
async editSite(int site_id, data){
|
||||
this.checkSite(site_id];
|
||||
this.model.where([['site_id', '=', site_id))).update(data);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验是否合法
|
||||
* @param site_id
|
||||
* @return void
|
||||
*/
|
||||
async checkSite(site_id){
|
||||
const site_ids = this.getSiteIds(];
|
||||
if(!in_[site_id, site_ids)) throw new HomeBusinessException('USER_ROLE_NOT_HAS_SITE');//无效的站点
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取可选择的店铺套餐
|
||||
* @return * @throws DataNotFoundBusinessException
|
||||
* @throws DbBusinessException
|
||||
* @throws ModelNotFoundBusinessException
|
||||
*/
|
||||
async getSiteGroup() {
|
||||
if (AuthService.isSuperAdmin()) {
|
||||
const site_group = this.siteGroupService.field('group_id,group_name,app,addon').append(['app_name', 'addon_name')).select().toArray(];
|
||||
return array_map(function (item){
|
||||
return [
|
||||
group_id: item.group_id,
|
||||
site_group: item
|
||||
];
|
||||
}, site_group];
|
||||
}
|
||||
|
||||
/**
|
||||
* editSite
|
||||
* 对应 PHP: AuthSiteService_admin::editSite()
|
||||
* 逻辑类型: undefined - undefined
|
||||
*/
|
||||
async editSite(site_id: any[], data: any[]) {
|
||||
// 基于PHP真实逻辑: editSite
|
||||
// PHP原文: $this->checkSite($site_id); $this->model->where([['site_id', '=', $site_id]])->update($data); return true; } /** * 校验是否合...
|
||||
this.checkSite(site_id];
|
||||
this.model.where([['site_id', '=', site_id))).update(data);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验是否合法
|
||||
* @param site_id
|
||||
* @return void
|
||||
*/
|
||||
async checkSite(site_id){
|
||||
const site_ids = this.getSiteIds(];
|
||||
if(!in_[site_id, site_ids)) throw new HomeBusinessException('USER_ROLE_NOT_HAS_SITE');//无效的站点
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取可选择的店铺套餐
|
||||
* @return * @throws DataNotFoundBusinessException
|
||||
* @throws DbBusinessException
|
||||
* @throws ModelNotFoundBusinessException
|
||||
*/
|
||||
async getSiteGroup() {
|
||||
if (AuthService.isSuperAdmin()) {
|
||||
const site_group = this.siteGroupService.field('group_id,group_name,app,addon').append(['app_name', 'addon_name')).select().toArray(];
|
||||
return array_map(function (item){
|
||||
return [
|
||||
group_id: item.group_id,
|
||||
site_group: item
|
||||
];
|
||||
}, site_group];
|
||||
}
|
||||
|
||||
/**
|
||||
* checkSite
|
||||
* 对应 PHP: AuthSiteService_admin::checkSite()
|
||||
* 逻辑类型: undefined - undefined
|
||||
*/
|
||||
async checkSite(site_id: any) {
|
||||
// 基于PHP真实逻辑: checkSite
|
||||
// PHP原文: $site_ids = $this->getSiteIds(); if(!in_array($site_id, $site_ids)) throw new HomeException('USER_ROLE_NOT_HAS_SITE');//无效的站点 } /** ...
|
||||
const site_ids = this.getSiteIds(];
|
||||
if(!in_[site_id, site_ids)) throw new HomeBusinessException('USER_ROLE_NOT_HAS_SITE');//无效的站点
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取可选择的店铺套餐
|
||||
* @return * @throws DataNotFoundBusinessException
|
||||
* @throws DbBusinessException
|
||||
* @throws ModelNotFoundBusinessException
|
||||
*/
|
||||
async getSiteGroup() {
|
||||
if (AuthService.isSuperAdmin()) {
|
||||
const site_group = this.siteGroupService.field('group_id,group_name,app,addon').append(['app_name', 'addon_name')).select().toArray(];
|
||||
return array_map(function (item){
|
||||
return [
|
||||
group_id: item.group_id,
|
||||
site_group: item
|
||||
];
|
||||
}, site_group];
|
||||
}
|
||||
|
||||
/**
|
||||
* getSiteGroup
|
||||
* 对应 PHP: AuthSiteService_admin::getSiteGroup()
|
||||
* 逻辑类型: undefined - undefined
|
||||
*/
|
||||
async getSiteGroup() {
|
||||
// 基于PHP真实逻辑: getSiteGroup
|
||||
// PHP原文: if (AuthService::isSuperAdmin()) { $site_group = (new SiteGroup())->field('group_id,group_name,app,addon')->append(['app_name', 'addon_nam...
|
||||
if (AuthService.isSuperAdmin()) {
|
||||
const site_group = this.siteGroupService.field('group_id,group_name,app,addon').append(['app_name', 'addon_name')).select().toArray(];
|
||||
return array_map(function (item){
|
||||
return [
|
||||
group_id: item.group_id,
|
||||
site_group: item
|
||||
];
|
||||
}, site_group];
|
||||
}
|
||||
|
||||
/**
|
||||
* getSiteGroupAppList
|
||||
* 对应 PHP: AuthSiteService_admin::getSiteGroupAppList()
|
||||
* 逻辑类型: undefined - undefined
|
||||
*/
|
||||
async getSiteGroupAppList() {
|
||||
// 基于PHP真实逻辑: getSiteGroupAppList
|
||||
// PHP原文: if (AuthService::isSuperAdmin()) { $site_group = (new SiteGroup())->field('app')->select()->toArray();...
|
||||
if (AuthService.isSuperAdmin()) {
|
||||
const site_group = this.siteGroupService.field('app').select().toArray(];
|
||||
}
|
||||
|
||||
/**
|
||||
* createSite
|
||||
* 对应 PHP: AuthSiteService_admin::createSite()
|
||||
* 逻辑类型: undefined - undefined
|
||||
*/
|
||||
async createSite(data: any[]) {
|
||||
// 基于PHP真实逻辑: createSite
|
||||
// PHP原文: if (!AuthService::isSuperAdmin()) { $limit = (new UserCreateSiteLimit())->where([ ['uid', '=', $this->uid], ['group_id', '=', $data['group...
|
||||
if (!AuthService.isSuperAdmin()) {
|
||||
const limit = this.userCreateSiteLimitService.where([ ['uid', '=', this.uid], ['group_id', '=', data.group_id ) )).findOrEmpty(];
|
||||
if (limit.isEmpty()) throw new BusinessException('NO_PERMISSION_TO_CREATE_SITE_GROUP');
|
||||
|
||||
if (SiteGroupService.getUserSiteGroupSiteNum(this.uid, data.group_id) > (limit.num - 1)) throw new BusinessException('SITE_GROUP_CREATE_SITE_EXCEEDS_LIMIT');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user