lrf 11 miesięcy temu
rodzic
commit
82f39c0a5f

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

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

+ 82 - 0
src/config/config.prod.ts

@@ -0,0 +1,82 @@
+import { MidwayConfig } from '@midwayjs/core';
+/**数据库ip */
+const ip = '10.120.114.5';
+/**数据库名 */
+const dbName = 'cxyy';
+/**日志数据库名 */
+const logsDB = 'cxyy_logs';
+/**数据库用户名 */
+const dbUsername = 'system';
+/**数据库密码 */
+const dbPwd = '1234qwer!@#$';
+/**redis ip */
+const redisHost = '10.120.114.6';
+/**redis 密码 */
+const redisPwd = '1234qwer!@#$';
+/**redis 使用第几个数据库 */
+const redisDB = 0;
+/**redis 记录登录的key */
+const loginSign = 'cxyy';
+export default {
+  // use for cookie sign key, should change to your own and keep security
+  keys: '1697684406848_4978',
+  loginSign,
+  // 请求记录在redis留存时间,超过时间.数据变化将不会记录.以秒为单位--5分钟
+  requestTimeLimit: 300,
+  jwt: {
+    secret: 'Ziyouyanfa!@#',
+    expiresIn: 3600, // 3600
+  },
+  koa: {
+    port: 9700,
+    globalPrefix: '/cxyy/api',
+    queryParseMode: 'extended',
+  },
+  swagger: {
+    swaggerPath: '/doc/api',
+  },
+  elasticsearch: {
+    node: 'http://192.168.1.197:9200',
+    auth: {
+      username: 'elastic',
+      password: 'NAjqFz_7tS2DkdpU7p*x',
+    },
+  },
+  typeorm: {
+    dataSource: {
+      default: {
+        database: dbName,
+        username: dbUsername,
+        password: dbPwd,
+        host: ip,
+        port: 54321,
+        entities: ['./entity'],
+        type: 'postgres',
+        synchronize: false, // 如果第一次使用,不存在表,有同步的需求可以写 true,注意会丢数据
+        logging: true,
+      },
+      logs: {
+        database: logsDB,
+        username: dbUsername,
+        password: dbPwd,
+        host: ip,
+        port: 54321,
+        entities: ['./entityLogs'],
+        type: 'postgres',
+        synchronize: false, // 如果第一次使用,不存在表,有同步的需求可以写 true,注意会丢数据
+        logging: true,
+      },
+    },
+  },
+  redis: {
+    client: {
+      port: 6379, // Redis port
+      host: redisHost, // Redis host
+      password: redisPwd,
+      db: redisDB,
+    },
+  },
+  upload: {
+    whitelist: null,
+  },
+} as MidwayConfig;

+ 1 - 1
src/controller/login.controller.ts

@@ -31,7 +31,7 @@ export class LoginController {
   @Post('/:type')
   async toLogin(@Body() data: LoginDTO, @Param('type') type: string) {
     const user = await this.loginService.loginByAccount(data, LoginType[type]);
-    if (type === 'Admin') user.role = [type];
+    // if (type === 'Admin') user.role = [type];
     let vo = new LoginVO(user);
     vo = JSON.parse(JSON.stringify(vo));
     vo.login_code = await this.loginService.onePointLogin(vo);

+ 5 - 5
src/controller/system/menus.controller.ts

@@ -16,11 +16,11 @@ export class MenusController implements BaseController {
   @Get('/')
   @ApiTags('列表查询')
   @ApiResponse({ type: QVO_menus })
-  async index(@Query() query: object) {
-    const qobj = omit(query, ['skip', 'limit']);
-    const others = pick(query, ['skip', 'limit']);
-    const qbr = this.service.queryBuilder(qobj);
-    const result = await this.service.query(qbr, others);
+  async index() {
+    // const qobj = omit(query, ['skip', 'limit']);
+    // const others = pick(query, ['skip', 'limit']);
+    // const qbr = this.service.queryBuilder(qobj);
+    const result = await this.service.queryMenu();
     return result;
   }
 

+ 3 - 1
src/entity/system/admin.entity.ts

@@ -27,11 +27,13 @@ export class Admin extends BaseModel {
   password: string; //TODO:需要重新加密
 
   @Column({ type: 'jsonb', nullable: true, comment: '角色id数组' })
-  role: number[];
+  role: string[];
 
   @Column({ type: 'integer', nullable: true, comment: '部门id' })
   dept: number;
 
+  @Column({ type: 'character varying', default: '0', comment: '是否使用: 0:使用;1:禁用' })
+  is_use: string;
   @Column({ type: 'character varying', default: '1', comment: '是否是超级管理员: 0:是;1否' })
   is_super: string;
 }

+ 2 - 0
src/entity/system/dept.entity.ts

@@ -15,4 +15,6 @@ export class Dept extends BaseModel {
   is_super: string;
   @Column({ type: 'integer', nullable: true, comment: '排序' })
   order_num: number;
+  @Column({ type: 'character varying', comment: '是否为默认菜单 默认:0,非默认:1; 默认不能删除', default: '0' })
+  is_default: string;
 }

+ 1 - 1
src/entity/system/menus.entity.ts

@@ -28,7 +28,7 @@ export class Menus extends BaseModel {
   icon: string;
   @Column({ type: 'jsonb', nullable: true, comment: '功能列表 不在功能列表中的功能不能使用' })
   config: Array<any>;
-  @Column({ type: 'character varying', comment: '是否为默认菜单 默认:0,非默认:1; 默认不能删除', default: '1' })
+  @Column({ type: 'character varying', comment: '是否为默认菜单 默认:0,非默认:1; 默认不能删除', default: '0' })
   is_default: string;
   @Column({ type: 'text', nullable: true, comment: '备注' })
   remark: string;

+ 1 - 1
src/entity/system/user.entity.ts

@@ -32,7 +32,7 @@ export class User extends BaseModel {
   @Column({ type: 'character varying', nullable: true, comment: '电子邮箱' })
   email: string;
   @Column({ type: 'jsonb', nullable: true, comment: '角色id数组' })
-  role: number[];
+  role: string[];
   @Column({ type: 'character varying', default: '1', comment: '状态: 0:未审核;1:已审核' })
   status: string;
 }

+ 4 - 3
src/service/login.service.ts

@@ -11,6 +11,7 @@ import { LoginDTO, LoginType, UPwdDTO } from '../interface/login.interface';
 import { Opera } from '../frame/dbOpera';
 import { Admin } from '../entity/system/admin.entity';
 import * as bcrypt from 'bcryptjs';
+import { User } from '../entity/system/user.entity';
 
 @Provide()
 export class LoginService {
@@ -29,6 +30,8 @@ export class LoginService {
 
   @InjectEntityModel(Admin)
   adminModel: Repository<Admin>;
+  @InjectEntityModel(User)
+  userModel: Repository<User>;
 
   async onePointLogin(loginVo) {
     const { id, role } = loginVo;
@@ -53,10 +56,8 @@ export class LoginService {
   async loginByAccount(data: LoginDTO, type: LoginType) {
     let model;
     if (type === LoginType.Admin) model = this.adminModel;
-    // TODO: 缺少user登录映射到model变量上
-    // const user = await model.findOne({ where: { account: Equal(data.account) }, select: ['password'] });
+    else model = this.userModel;
     const user = await model.createQueryBuilder('t').where('t.account = :account', { account: data.account }).addSelect('t.password').getOne();
-    // const user = await model.findOne({ account: data.account }, '+password').lean();
     if (!user) throw new ServiceError(ErrorCode.USER_NOT_FOUND);
     await this.checkAccountCanLogin(user, type);
     const result = bcrypt.compareSync(data.password, user.password);

+ 1 - 1
src/service/system/role.service.ts

@@ -140,7 +140,7 @@ export class RoleService extends BaseService<Role> {
       roleCodes.push(lowerFirst(rc));
       roleCodes.push(upperFirst(rc));
     }
-    const role = await this.model.find({ where: { code: In(roleCode), is_use: '0' } });
+    const role = await this.model.findOne({ where: { code: In(roleCode), is_use: '0' } });
     if (!role) return [];
     const roleMenu = get(role, 'menu', []);
     return roleMenu;