m
This commit is contained in:
+157
@@ -0,0 +1,157 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
var TaskInstallService_1;
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.TaskInstallService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const typeorm_1 = require("@nestjs/typeorm");
|
||||
const system_config_model_1 = require("../../../model/system_config.model");
|
||||
const user_model_1 = require("../../../model/user.model");
|
||||
const wallet_model_1 = require("../../../model/wallet.model");
|
||||
const team_relation_model_1 = require("../../../model/team_relation.model");
|
||||
const invite_code_pool_model_1 = require("../../../model/invite_code_pool.model");
|
||||
const user_sign_in_model_1 = require("../../../model/user_sign_in.model");
|
||||
const typeorm_2 = require("typeorm");
|
||||
const data_source_context_1 = require("../../common/context/data_source.context");
|
||||
const im_help_1 = require("../../common/util/im_help");
|
||||
const app_env_1 = require("../../../app.env");
|
||||
let TaskInstallService = TaskInstallService_1 = class TaskInstallService {
|
||||
systemConfigModel;
|
||||
userModel;
|
||||
walletModel;
|
||||
teamRelationModel;
|
||||
inviteCodePoolModel;
|
||||
userSignInModel;
|
||||
dataSource;
|
||||
logger = new common_1.Logger(TaskInstallService_1.name);
|
||||
constructor(systemConfigModel, userModel, walletModel, teamRelationModel, inviteCodePoolModel, userSignInModel, dataSource) {
|
||||
this.systemConfigModel = systemConfigModel;
|
||||
this.userModel = userModel;
|
||||
this.walletModel = walletModel;
|
||||
this.teamRelationModel = teamRelationModel;
|
||||
this.inviteCodePoolModel = inviteCodePoolModel;
|
||||
this.userSignInModel = userSignInModel;
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
onModuleInit() {
|
||||
void this.install();
|
||||
}
|
||||
async install() {
|
||||
this.logger.verbose('正在执行安装任务');
|
||||
const systemConfigCount = await this.systemConfigModel.count();
|
||||
if (!systemConfigCount) {
|
||||
this.logger.verbose('系统配置表为空,正在初始化...');
|
||||
await this.systemConfigModel.insert({});
|
||||
this.logger.verbose('系统配置初始化完成');
|
||||
}
|
||||
else {
|
||||
this.logger.verbose('系统配置已存在,跳过初始化');
|
||||
}
|
||||
this.logger.verbose('开始创建顶级用户...');
|
||||
const topUser = await this.createTopUser();
|
||||
await this.initImGroup(topUser.id);
|
||||
this.logger.verbose('安装任务执行完成,即将退出进程');
|
||||
process.exit(0);
|
||||
}
|
||||
async createTopUser() {
|
||||
const queryRunner = this.dataSource.createQueryRunner();
|
||||
return await data_source_context_1.DataSourceContext.startTransactionToQueryRunner(queryRunner, async (transaction) => {
|
||||
const userRepo = transaction.getRepository(user_model_1.UserModel);
|
||||
const walletRepo = transaction.getRepository(wallet_model_1.WalletModel);
|
||||
const teamRelationRepo = transaction.getRepository(team_relation_model_1.TeamRelationModel);
|
||||
const inviteCodeRepo = transaction.getRepository(invite_code_pool_model_1.InviteCodePoolModel);
|
||||
const userSignInRepo = transaction.getRepository(user_sign_in_model_1.UserSignInModel);
|
||||
const existingUser = await userRepo.findOne({
|
||||
where: { id: 1 },
|
||||
});
|
||||
if (existingUser) {
|
||||
this.logger.verbose(`顶级用户已存在,账号:${existingUser.phone} ,邀请码: ${existingUser.inviteCode}`);
|
||||
return existingUser;
|
||||
}
|
||||
const topUser = userRepo.create({
|
||||
id: 1,
|
||||
phone: '13800138000',
|
||||
password: 'Aa123123.',
|
||||
inviteCode: '888888',
|
||||
});
|
||||
await userRepo.save(topUser);
|
||||
await walletRepo.insert({
|
||||
userId: topUser.id,
|
||||
});
|
||||
const teamRelation = teamRelationRepo.create({
|
||||
userId: topUser.id,
|
||||
parentId: 0,
|
||||
grandparentId: 0,
|
||||
greatGrandparentId: 0,
|
||||
path: `${topUser.id}`,
|
||||
level: 1,
|
||||
});
|
||||
await teamRelationRepo.save(teamRelation);
|
||||
await inviteCodeRepo.insert({
|
||||
id: topUser.id,
|
||||
code: '888888',
|
||||
});
|
||||
await userRepo.update({ id: topUser.id }, { inviteCode: '888888' });
|
||||
const userSignIn = userSignInRepo.create({
|
||||
userId: topUser.id,
|
||||
consecutiveDays: 0,
|
||||
makeUpCount: 2,
|
||||
});
|
||||
await userSignInRepo.save(userSignIn);
|
||||
this.logger.verbose(`顶级用户创建成功,账号:${topUser.phone} ,邀请码: ${topUser.inviteCode}`);
|
||||
return topUser;
|
||||
});
|
||||
}
|
||||
async initImGroup(topUserId) {
|
||||
const IM_USER_ID_PREFIX = 'IM_ENERGY_TEST_';
|
||||
this.logger.verbose('正在初始化群组');
|
||||
const groupInfo = await im_help_1.IMHelp.getGroupInfo([app_env_1.AppEnv.IM_DEFAULT_GROUP_ID]);
|
||||
if (groupInfo.GroupInfo?.length && groupInfo.GroupInfo[0].ErrorCode == 0) {
|
||||
this.logger.verbose(`群租已存在:${groupInfo.GroupInfo[0].Name}`);
|
||||
}
|
||||
else {
|
||||
const res = await im_help_1.IMHelp.createGroup({
|
||||
Owner_Account: `${IM_USER_ID_PREFIX}${topUserId}`,
|
||||
Type: app_env_1.AppEnv.IM_DEFAULT_GROUP_TYPE,
|
||||
GroupId: app_env_1.AppEnv.IM_DEFAULT_GROUP_ID,
|
||||
FaceUrl: '',
|
||||
Name: app_env_1.AppEnv.IM_DEFAULT_GROUP_NAME,
|
||||
});
|
||||
if (res.ErrorCode != 0) {
|
||||
this.logger.verbose(`正初始化群组失败,${res.ErrorInfo},code: ${res.ErrorCode}`);
|
||||
}
|
||||
else {
|
||||
this.logger.verbose(`正初始化群组完成`);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
exports.TaskInstallService = TaskInstallService;
|
||||
exports.TaskInstallService = TaskInstallService = TaskInstallService_1 = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__param(0, (0, typeorm_1.InjectRepository)(system_config_model_1.SystemConfigModel)),
|
||||
__param(1, (0, typeorm_1.InjectRepository)(user_model_1.UserModel)),
|
||||
__param(2, (0, typeorm_1.InjectRepository)(wallet_model_1.WalletModel)),
|
||||
__param(3, (0, typeorm_1.InjectRepository)(team_relation_model_1.TeamRelationModel)),
|
||||
__param(4, (0, typeorm_1.InjectRepository)(invite_code_pool_model_1.InviteCodePoolModel)),
|
||||
__param(5, (0, typeorm_1.InjectRepository)(user_sign_in_model_1.UserSignInModel)),
|
||||
__metadata("design:paramtypes", [typeorm_2.Repository,
|
||||
typeorm_2.Repository,
|
||||
typeorm_2.Repository,
|
||||
typeorm_2.Repository,
|
||||
typeorm_2.Repository,
|
||||
typeorm_2.Repository,
|
||||
typeorm_2.DataSource])
|
||||
], TaskInstallService);
|
||||
//# sourceMappingURL=task_install.service.js.map
|
||||
Reference in New Issue
Block a user