瀏覽代碼

Merge branch 'main' of http://git.cc-lotus.info/shuiTou/admin-service into main

zs 5 天之前
父節點
當前提交
616173c9bf

+ 0 - 2
service/bootstrap.js

@@ -1,2 +0,0 @@
-const { Bootstrap } = require('@midwayjs/bootstrap');
-Bootstrap.run();

+ 0 - 20
service/ecosystem.config.js

@@ -1,20 +0,0 @@
-'use strict';
-// 开发服务设置
-const app = 'service-admin';
-module.exports = {
-  apps: [
-    {
-      name: app, // 应用名称
-      script: './bootstrap.js', // 实际启动脚本
-      out: `./logs/${app}.log`,
-      error: `./logs/${app}.err`,
-      watch: [
-        // 监控变化的目录,一旦变化,自动重启
-        'dist',
-      ],
-      env: {
-        NODE_ENV: 'production', // 环境参数,当前指定为生产环境
-      },
-    },
-  ],
-};

+ 0 - 54
service/package.json

@@ -1,54 +0,0 @@
-{
-  "name": "my-midway-project",
-  "version": "1.0.0",
-  "description": "",
-  "private": true,
-  "dependencies": {
-    "@midwayjs/bootstrap": "^3.19.3",
-    "@midwayjs/busboy": "^3.19.3",
-    "@midwayjs/core": "^3.19.0",
-    "@midwayjs/info": "^3.19.2",
-    "@midwayjs/jwt": "^3.19.3",
-    "@midwayjs/koa": "^3.19.2",
-    "@midwayjs/logger": "^3.1.0",
-    "@midwayjs/typeorm": "^3.19.2",
-    "@midwayjs/validate": "^3.19.2",
-    "bcryptjs": "^3.0.2",
-    "dayjs": "^1.11.13",
-    "fs-extra": "^11.2.0",
-    "lodash": "^4.17.21",
-    "mysql2": "^3.11.5",
-    "typeorm": "^0.3.20"
-  },
-  "devDependencies": {
-    "@midwayjs/mock": "^3.19.2",
-    "@types/jest": "^29.2.0",
-    "@types/lodash": "^4.17.13",
-    "@types/node": "14",
-    "cross-env": "^6.0.0",
-    "jest": "^29.2.2",
-    "mwts": "^1.3.0",
-    "mwtsc": "^1.4.0",
-    "ts-jest": "^29.0.3",
-    "typescript": "~4.8.0"
-  },
-  "engines": {
-    "node": ">=12.0.0"
-  },
-  "scripts": {
-    "start": "NODE_ENV=production node ./bootstrap.js",
-    "dev": "cross-env NODE_ENV=local mwtsc --watch --run @midwayjs/mock/app.js",
-    "test": "cross-env NODE_ENV=unittest jest",
-    "cov": "jest --coverage",
-    "lint": "mwts check",
-    "lint:fix": "mwts fix",
-    "ci": "npm run cov",
-    "build": "mwtsc --cleanOutDir"
-  },
-  "repository": {
-    "type": "git",
-    "url": ""
-  },
-  "author": "anonymous",
-  "license": "MIT"
-}

+ 1 - 1
src/config/config.local.ts

@@ -31,7 +31,7 @@ export default {
         username: dbUsername,
         password: dbPwd,
         entities: ['./entity'],
-        synchronize: true, // 如果第一次使用,不存在表,有同步的需求可以写 true,注意会丢数据
+        synchronize: false, // 如果第一次使用,不存在表,有同步的需求可以写 true,注意会丢数据
         logging: true,
       }
     },

+ 3 - 1
src/entity/frame/loginRecord.entity.ts

@@ -3,8 +3,10 @@ import { BaseModel } from '../../frame/BaseModel';
 
 @Entity('loginRecord', { comment: '登陆记录' })
 export class LoginRecord extends BaseModel {
-  @Column({ comment: '用户id' })
+  @Column({ comment: '用户id', nullable: true })
   user_id: number;
+  @Column({ comment: '用户角色:Admin;User', nullable: true })
+  role: string;
   @Column({ comment: 'token', nullable: true })
   token: string
   @Column({ comment: '最后使用时间', nullable: true })

+ 8 - 4
src/service/frame/LoginRecord.service.ts

@@ -28,17 +28,19 @@ export class LoginRecordService {
     if (!userInfo) return;
     const user_id = get(userInfo, 'id', get(userInfo, '_id'));
     if (!user_id) return;
+    const role = get(userInfo, 'role');
+    if (!role) return;
     const last_time = dayjs().format(this.timeFormat);
     const expire_time = dayjs()
       .add(this.expire_step, 's')
       .format(this.timeFormat);
     const req = this.ctx.request;
     const last_ip = get(req, 'header.x-forwarded-for', req.ip);
-    const data: any = { token, last_time, expire_time, last_ip };
-    const num = await this.model.count({ where: { user_id } });
+    const data: any = { token, last_time, expire_time, last_ip, role };
+    const num = await this.model.count({ where: { user_id, role } });
     if (num > 0) {
       // 有过登录记录,那就直接更新token,last_time,expire_time,last_ip就行
-      const q1: any = { user_id }
+      const q1: any = { user_id, role }
       await this.model.update(q1, data);
     } else {
       // 没有记录,那就创建
@@ -73,7 +75,9 @@ export class LoginRecordService {
     if (!userInfo) return;
     const user_id = get(userInfo, 'id', get(userInfo, '_id'));
     if (!user_id) return;
-    const q1: any = { user_id }
+    const role = get(userInfo, 'role')
+    if (!role) return
+    const q1: any = { user_id, role }
     const data = await this.model.findOne({ where: q1 });
     if (!data) throw new ServiceError(ErrorCode.NOT_LOGIN);
     const utoken = get(data, 'token');