修改命名以及主要逻辑

This commit is contained in:
wuhan 2024-09-02 14:31:49 +08:00
parent c229cfd4cc
commit 2c259f354c
11 changed files with 60 additions and 20 deletions

View File

@ -1,10 +1,12 @@
import { Module } from '@nestjs/common';
import { GatewayModule } from './gateway/gateway.module';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { ClientModule } from './client/client.module';
import { GatewayModule } from './gateway/gateway.module';
import { MqttService } from './mqtt/mqtt.service';
import { TypeOrmModule, TypeOrmModuleAsyncOptions } from '@nestjs/typeorm';
import { getDriveDb, getSshDb } from './utils/config';
import { EventEmitterModule } from '@nestjs/event-emitter';
// import 'winston-daily-rotate-file';
@Module({
@ -32,9 +34,13 @@ import { getDriveDb, getSshDb } from './utils/config';
}),
ClientModule,
GatewayModule,
EventEmitterModule.forRoot()
],
controllers: [AppController],
providers: [AppService],
providers: [
GatewayModule,
AppService,
MqttService
]
})
// eslint-disable-next-line prettier/prettier
export class AppModule { }

View File

@ -1,13 +1,15 @@
import { Injectable } from '@nestjs/common/decorators';
import { UserNum } from '../entities/user-num.entity';
import { UserInfo } from 'src/entities/user-info.entity';
import { MpInfo } from 'src/entities/mp-info.entity';
import { UserArchieve } from 'src/entities/user-archieve.entity';
import { Between, getConnection, Like, Repository } from 'typeorm';
import { UserHealth } from 'src/entities/user-health.entity';
import { HomeInfo } from 'src/entities/home-linfo.entity';
import { UserNum } from '../entities/user_num.entity';
import { UserInfo } from 'src/entities/user_info.entity';
import { MpInfo } from 'src/entities/mp_info.entity';
import { UserArchieve } from 'src/entities/user_archieve.entity';
import { Between, In, Not } from 'typeorm';
import { UserHealth } from 'src/entities/user_health.entity';
import { HomeInfo } from 'src/entities/home_info.entity';
import { AlarmInfo } from 'src/entities/alarm_info.entity';
import { HccAlarmInfo } from 'src/entities/hcc_alarm_info.entity';
import { AgentIdInfo } from 'src/entities/agentId.entity';
import { HccInfo } from 'src/entities/hcc_info.entity';
const moment = require('moment');
moment.locale('zh_CN');
@ -442,6 +444,7 @@ class ClientMapper {
const obj: any = {}
const { pageSize, pageIndex } = page
obj.createTime = Between(startTime, endTime);
obj.msgType = Not(In([1]))
// const r = getConnection('ssh').manager.find(HccAlarmInfo, {
// where: obj,
// select: ['content', 'createTime', 'msgType'],
@ -452,7 +455,7 @@ class ClientMapper {
const [data, count] = await HccAlarmInfo.findAndCount({
where: obj,
select: ['content', 'createTime', 'msgType'],
select: ['content', 'createTime', 'msgType', 'title'],
take: Number(pageSize),
skip: Number(pageIndex - 1) * Number(pageSize),
})
@ -509,6 +512,19 @@ class ClientMapper {
.select('sum(num)', 'sum')
.getRawOne()
}
async getAgentId() {
return await AgentIdInfo.find()
}
/**
*
* @returns
*/
async getHccAddress() {
const hcc = await HccInfo.find();
return hcc.length ? hcc[0] : null
}
}
export default new ClientMapper();

View File

@ -1,9 +1,8 @@
import { Injectable } from '@nestjs/common';
import clientMapper from './client.mapper';
import AppLogger from '../utils/logger';
import { UserNum } from 'src/entities/user-num.entity';
import { UserNum } from 'src/entities/user_num.entity';
import axios from 'axios';
import { ConnectedSocket } from '@nestjs/websockets';
import Time from '../utils/time'
const moment = require('moment');
moment.locale('zh_CN');
@ -365,7 +364,7 @@ export class ClientService {
let clientId = '8b55d6ed3cf34322b9a94f0a0655f197'
let clientSecret = '025f1a91b9ff4004ab0d5120709b76b4'
// 判断如果是张家港开头,则请求张家港生产地址
if ((areaCode as string).includes('320582')) {
if ((areaCode as string)?.includes('320582')) {
url = `http://218.4.146.42:60036/`;
clientId = '5c1c29c35ada4a43b284ea43047720e7';
clientSecret = 'c2fbbdea051f4ea0bcea18455180b133';
@ -486,11 +485,15 @@ export class ClientService {
startTime = moment().format('YYYY-MM-01')
endTime = moment().day(31).format('YYYY-MM-DD 23:59:59')
}
const { data, count } = await clientMapper.queryWarnListV2({ code, startTime, endTime, page });
const [{ data, count }, address] = await Promise.all([
clientMapper.queryWarnListV2({ code, startTime, endTime, page }),
clientMapper.getHccAddress()
])
data.forEach((e: any) => {
e.homeCode = e?.addressCode || ''
e.address = e?.address || ''
e.typeName = e?.typeName || ''
e.typeName = e?.typeName || e.title
e.address = address.addressDetail
e.alarmDate = moment(e.createTime).format('YYYY-MM-DD hh:mm:ss');
delete e.createTime
})

View File

@ -0,0 +1,12 @@
import { Entity, PrimaryColumn, Column, BaseEntity } from 'typeorm';
/**
*
*/
@Entity({ name: 'agent_id', database: 'drive' })
export class AgentIdInfo extends BaseEntity {
//id
@PrimaryColumn({ type: 'int' })
id: number;
}

View File

@ -19,4 +19,7 @@ export class UserNum extends BaseEntity {
@Column({ type: 'int', comment: '地区用户总数' })
totalUserNum: number;
@Column({ type: 'varchar', name: 'parent_code', comment: '地区名称' })
parentCode: string;
}

View File

@ -2,8 +2,8 @@
import { parse } from 'yaml';
const path = require('path');
const fs = require('fs');
import { TypeOrmModuleOptions, TypeOrmOptionsFactory } from '@nestjs/typeorm';
import { Injectable } from '@nestjs/common';
// import { TypeOrmModuleOptions, TypeOrmOptionsFactory } from '@nestjs/typeorm';
// import { Injectable } from '@nestjs/common';
// 获取项目运行环境
export const getEnv = () => {
@ -17,8 +17,8 @@ export const getConfig = () => {
return configAll
}
const environment = getEnv();
// const yamlPath = path.join(process.cwd(), `./.config/.${environment}.yaml`);
const yamlPath = path.join(process.cwd(), `./${environment}.yaml`);
const yamlPath = path.join(process.cwd(), `./.config/.${environment}.yaml`);
// const yamlPath = path.join(process.cwd(), `./${environment}.yaml`);
const file = fs.readFileSync(yamlPath, 'utf8');
let config = parse(file);
console.log('读取配置', JSON.stringify(config))