修改mqtt各分类逻辑
This commit is contained in:
parent
72a8ce982a
commit
1494377b25
|
@ -271,7 +271,7 @@ class ClientMapper {
|
|||
left join app_status_infos ai on ai.app_id = app.app_id
|
||||
`;
|
||||
if (mpIdOrName) {
|
||||
arr.push(mpIdOrName, type);
|
||||
arr.push(mpIdOrName, mpIdOrName);
|
||||
bool = true;
|
||||
sql += `where (mp_id = ? or app.name = ?) `;
|
||||
}
|
||||
|
@ -324,9 +324,10 @@ class ClientMapper {
|
|||
let bool = false;
|
||||
const arr = [];
|
||||
let sql = `
|
||||
select i.app_user_id as appUserId,i.app_code as appCode,i.mobile,name,i.cert_code as certCode,i.identification_flag as identificationFlag,
|
||||
select i.app_user_id as appUserId,i.app_code as appCode,a.name as appName,i.mobile,i.name,i.cert_code as certCode,i.identification_flag as identificationFlag,
|
||||
i.nick_name as nickName,i.avatar,i.sex
|
||||
from szja_user_info i
|
||||
left join apps a on a.app_id = i.app_code
|
||||
`;
|
||||
// hcc需要做表关联
|
||||
if (hccId) {
|
||||
|
|
|
@ -227,11 +227,12 @@ export class ClientService {
|
|||
}
|
||||
data.forEach((e) => {
|
||||
// 处理身份认证标识
|
||||
if (e.certCode) {
|
||||
if (e.certCode || e.identificationFlag) {
|
||||
delete e.certCode;
|
||||
e.certType = 1;
|
||||
e.certAuth = 1;
|
||||
// e.certAuth =
|
||||
} else {
|
||||
e.certType = 0;
|
||||
e.certAuth = 0;
|
||||
}
|
||||
// 处理性别
|
||||
if (e.sex == 1) {
|
||||
|
|
|
@ -5,10 +5,6 @@ class MpMapper {
|
|||
return await db('select * from szja_mp_info');
|
||||
}
|
||||
|
||||
async getMpInfoV2() {
|
||||
return await db('select mp_id as mpId from szja_mp_info');
|
||||
}
|
||||
|
||||
async addClientInfo(clientId: string, clientSecret: string) {
|
||||
return await db('insert into szja_client_info set ?', [
|
||||
{
|
||||
|
@ -18,14 +14,6 @@ class MpMapper {
|
|||
},
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有已认证服务
|
||||
* @returns
|
||||
*/
|
||||
async getAllAuthMp() {
|
||||
return await db(`select mp_id,data_type_id from szja_mp_auth_data_type`);
|
||||
}
|
||||
}
|
||||
|
||||
export default new MpMapper();
|
||||
|
|
|
@ -38,9 +38,9 @@ export class MpService {
|
|||
if (clientTokenInfor?.length) {
|
||||
//有该clientId的数据,说明是token过期,更新token
|
||||
const result = await clientMapper.updateClientToken(
|
||||
clientId,
|
||||
token,
|
||||
expireTime,
|
||||
clientId,
|
||||
token,
|
||||
expireTime,
|
||||
);
|
||||
if (result.affectedRows) {
|
||||
return Base.success({
|
||||
|
@ -53,9 +53,9 @@ export class MpService {
|
|||
} else {
|
||||
//没有该clientId的数据,说明是新数据要存库
|
||||
const result = await clientMapper.addClientToken(
|
||||
clientId,
|
||||
token,
|
||||
expireTime,
|
||||
clientId,
|
||||
token,
|
||||
expireTime,
|
||||
);
|
||||
if (result.affectedRows) {
|
||||
return Base.success({
|
||||
|
@ -69,7 +69,6 @@ export class MpService {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// /**
|
||||
// * 查询应用服务用户信息权限
|
||||
// * @param req
|
||||
|
@ -221,31 +220,6 @@ export class MpService {
|
|||
}
|
||||
}
|
||||
|
||||
// 查询应用服务授权列表
|
||||
async getAuthMp() {
|
||||
// 获取所有已认证服务
|
||||
const [data, mpInfos] = await Promise.all([
|
||||
mpMapper.getAllAuthMp(),
|
||||
mpMapper.getMpInfoV2(),
|
||||
]);
|
||||
mpInfos.forEach((e) => {
|
||||
e.icon =
|
||||
'https://img.zcool.cn/community/018459568f541732f87574be60c997.jpg?x-oss-process=image/auto-orient,1/resize,m_lfit,w_1280,limit_1/sharpen,100';
|
||||
e.mpName = '示例数据';
|
||||
// 处理数据类型
|
||||
const authTypeList = [];
|
||||
data.forEach((m) => {
|
||||
if (e.mpId == m.mp_id) {
|
||||
authTypeList.push({
|
||||
dataTypeId: m.data_type_id,
|
||||
});
|
||||
}
|
||||
});
|
||||
e.authTypeList = authTypeList;
|
||||
});
|
||||
return mpInfos;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将从信息箱查询到的数据返回给应用服务
|
||||
* @param dataList
|
||||
|
|
|
@ -2,13 +2,27 @@ import db from '../utils/mysql';
|
|||
import { IAuthDataType, IDeviceAlarmInfo, IUserHome } from './mqtt.types';
|
||||
|
||||
class MqttMapper {
|
||||
async updateUserInfo(userInfo) {
|
||||
const info = await db(
|
||||
`insert into szja_user_info (app_user_id,app_code) values ?
|
||||
on duplicate key update
|
||||
app_code = values(app_code)
|
||||
`,
|
||||
[userInfo],
|
||||
);
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加家庭地址
|
||||
* @param param0
|
||||
*/
|
||||
async addUserHome(userHome: IUserHome[]) {
|
||||
const info = await db(
|
||||
'insert into szja_user_home (user_id,hcc_id,home_name,create_time) values ?',
|
||||
`insert into szja_user_home (user_id,hcc_id,home_name) values ?
|
||||
on duplicate key update
|
||||
home_name = values(home_name)
|
||||
`,
|
||||
[userHome],
|
||||
);
|
||||
return info;
|
||||
|
@ -101,6 +115,35 @@ class MqttMapper {
|
|||
[id, type, plaintext, ciphertext, status, reason],
|
||||
);
|
||||
}
|
||||
|
||||
// 查询所有小程序列表
|
||||
async appList() {
|
||||
const data = await db(`
|
||||
select
|
||||
name as appName,logo as icon,app_id as appId
|
||||
from apps
|
||||
`);
|
||||
return data;
|
||||
}
|
||||
|
||||
// 获取mp基本信息
|
||||
async getAuthMp() {
|
||||
const data = await db(`
|
||||
select mi.mp_id as mpId,a.logo as icon,a.name as mpName from szja_mp_info mi
|
||||
left join apps a on mi.mp_id = a.app_id
|
||||
`);
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有已认证服务的订阅类型
|
||||
* @returns
|
||||
*/
|
||||
async getAuthMpDataType() {
|
||||
return await db(
|
||||
`select mp_id as mpId,data_type_id as dataTypeId from szja_mp_auth_data_type`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default new MqttMapper();
|
||||
|
|
|
@ -3,6 +3,9 @@ import userMapper from '../user/user.mapper';
|
|||
import MqttMapper from './mqtt.mapper';
|
||||
import { SecureService } from 'src/secure/secure.service';
|
||||
import Axios from '../utils/axios';
|
||||
import mpMapper from 'src/mp/mp.mapper';
|
||||
import mqttMapper from './mqtt.mapper';
|
||||
import { IUserInfo } from './mqtt.types';
|
||||
|
||||
class MqttService {
|
||||
/**
|
||||
|
@ -14,12 +17,17 @@ class MqttService {
|
|||
if (!bindList?.length) {
|
||||
return;
|
||||
}
|
||||
// 先删除,再批量更新
|
||||
|
||||
const userHome = [];
|
||||
const userInfo = [];
|
||||
bindList?.forEach((e) => {
|
||||
userHome.push([e.appUserId, hccId, e.homeName, new Date()]);
|
||||
userInfo.push([e.appUserId, e.appcode]);
|
||||
userHome.push([e.appUserId, hccId, e.homeName]);
|
||||
});
|
||||
await userMapper.addUserHome(userHome);
|
||||
// 批量更新用户数据
|
||||
const result = await mqttMapper.updateUserInfo(userInfo);
|
||||
//新增家庭数据
|
||||
await mqttMapper.addUserHome(userHome);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -47,6 +55,37 @@ class MqttService {
|
|||
res.send(Base.success());
|
||||
}
|
||||
|
||||
// 查询应用服务授权列表
|
||||
async getAuthMp() {
|
||||
// 获取所有已认证服务
|
||||
const [data, mpInfos] = await Promise.all([
|
||||
mqttMapper.getAuthMpDataType(),
|
||||
mqttMapper.getAuthMp(),
|
||||
]);
|
||||
mpInfos.forEach((e) => {
|
||||
// 处理数据类型
|
||||
const authTypeList = [];
|
||||
data.forEach((m) => {
|
||||
if (e.mpId == m.mpId) {
|
||||
authTypeList.push({
|
||||
dataTypeId: m.dataTypeId,
|
||||
});
|
||||
}
|
||||
});
|
||||
e.authTypeList = authTypeList;
|
||||
});
|
||||
return mpInfos;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将从信息箱查询到的数据返回给应用服务
|
||||
* @param dataList
|
||||
*/
|
||||
// async pushInfo(dataList) {
|
||||
// // await
|
||||
// console.log(`家庭数据查询dataList:${dataList}`);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 数据推送,存储数据关系
|
||||
* @param req
|
||||
|
@ -88,7 +127,14 @@ class MqttService {
|
|||
* 修改家庭地址
|
||||
* @param param0
|
||||
*/
|
||||
async updateUserHome({ address_code, address_detail, hccId }) {
|
||||
async updateUserHome({
|
||||
address_code,
|
||||
address_detail,
|
||||
hccId,
|
||||
street_id,
|
||||
community_id,
|
||||
}) {
|
||||
address_code = `${address_code}${street_id}${community_id}`;
|
||||
await MqttMapper.updateUserHome({
|
||||
address_code,
|
||||
address_detail,
|
||||
|
|
|
@ -2,10 +2,15 @@ export interface IUserHome {
|
|||
user_id: string;
|
||||
hcc_id: string;
|
||||
home_name?: string;
|
||||
create_time: Date;
|
||||
create_time?: Date;
|
||||
update_time?: Date;
|
||||
}
|
||||
|
||||
export interface IUserInfo {
|
||||
appUserId: string;
|
||||
appcode: string;
|
||||
}
|
||||
|
||||
export interface IAuthDataType {
|
||||
id: string;
|
||||
mp_id: string;
|
||||
|
|
|
@ -43,6 +43,7 @@ client.on('message', async (topic, mes) => {
|
|||
const { seId, keyAlias, message } = reqData.data;
|
||||
// const { cmd, reqId, payload } = reqData.data;
|
||||
if (!seId || !keyAlias) {
|
||||
console.log('mqtt接受消息,缺少参数');
|
||||
return;
|
||||
}
|
||||
console.log(
|
||||
|
@ -80,7 +81,6 @@ client.on('message', async (topic, mes) => {
|
|||
return;
|
||||
}
|
||||
let info;
|
||||
// await mqttMapper.updateLog(0);
|
||||
// topic : 1/req/{hccId}
|
||||
if (arr[1] === 'req') {
|
||||
switch (cmd) {
|
||||
|
@ -88,38 +88,36 @@ client.on('message', async (topic, mes) => {
|
|||
// 家庭绑定同步
|
||||
const { bindList } = payload;
|
||||
await mqttService.bindInfo(bindList, hccId);
|
||||
info = await mqttService.encrypt(seId, keyAlias, res);
|
||||
break;
|
||||
case '2':
|
||||
// 家庭解绑同步
|
||||
await mqttService.unbind(payload);
|
||||
info = await mqttService.encrypt(seId, keyAlias, res);
|
||||
break;
|
||||
case '3':
|
||||
// 查询小程序列表
|
||||
data = await Status.list();
|
||||
data = await mqttMapper.appList();
|
||||
res.payload = {
|
||||
appInfos: data,
|
||||
};
|
||||
info = await mqttService.encrypt(seId, keyAlias, res);
|
||||
break;
|
||||
case '4':
|
||||
// 家庭地址同步
|
||||
const { address_code, address_detail } = payload;
|
||||
const { address_code, address_detail, street_id, community_id } =
|
||||
payload;
|
||||
await mqttService.updateUserHome({
|
||||
address_code,
|
||||
address_detail,
|
||||
hccId,
|
||||
street_id,
|
||||
community_id,
|
||||
});
|
||||
info = await mqttService.encrypt(seId, keyAlias, res);
|
||||
break;
|
||||
case '5':
|
||||
// 查询应用服务授权列表
|
||||
data = await new MpService().getAuthMp();
|
||||
data = await mqttService.getAuthMp();
|
||||
res.payload = {
|
||||
appInfos: data,
|
||||
};
|
||||
info = await mqttService.encrypt(seId, keyAlias, res);
|
||||
break;
|
||||
case '6':
|
||||
// 家庭数据推送
|
||||
|
@ -133,11 +131,11 @@ client.on('message', async (topic, mes) => {
|
|||
console.log('家庭数据推送数据成功');
|
||||
// 调用回调接口推送数据
|
||||
await mqttService.pushCallBackInfo(dataList);
|
||||
info = await mqttService.encrypt(seId, keyAlias, res);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
info = await mqttService.encrypt(seId, keyAlias, res);
|
||||
console.log(`mqtt---cmd:${cmd}---返回数据:`, info);
|
||||
client.publish(`2/rsp/${hccId}`, JSON.stringify({ message: info }));
|
||||
} else if (arr[1] === 'rep') {
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import db from '../utils/mysql';
|
||||
import { IUserHome } from './user.type';
|
||||
|
||||
class UserMapper {
|
||||
/**
|
||||
|
@ -19,18 +18,6 @@ class UserMapper {
|
|||
return await db('select * from szja_app_info');
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加家庭地址
|
||||
* @param param0
|
||||
*/
|
||||
async addUserHome(userHome: IUserHome[]) {
|
||||
const info = await db(
|
||||
'insert into szja_user_home (user_id,hcc_id,home_name,create_time) values ?',
|
||||
[userHome],
|
||||
);
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除家庭信息
|
||||
* @param appUserId
|
||||
|
|
|
@ -18,19 +18,6 @@ class Status {
|
|||
console.log(`${id}已下线`);
|
||||
return;
|
||||
}
|
||||
|
||||
async list() {
|
||||
// const data = await db('select * from ')
|
||||
const data = [
|
||||
{
|
||||
appId: '6433be833832fb000180193e',
|
||||
// icon: '',
|
||||
icon: 'https://img.zcool.cn/community/018459568f541732f87574be60c997.jpg?x-oss-process=image/auto-orient,1/resize,m_lfit,w_1280,limit_1/sharpen,100',
|
||||
appName: '小火箭',
|
||||
},
|
||||
];
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
export default new Status();
|
||||
|
|
Loading…
Reference in New Issue
Block a user