驾驶舱接口改动

This commit is contained in:
lingwentao 2023-08-07 10:18:25 +08:00
parent 29f90e2f54
commit 69e158f2a2
3 changed files with 66 additions and 18 deletions

View File

@ -2,6 +2,7 @@ import { Controller, Post, Body, UseGuards } from '@nestjs/common';
import { OpenDataService } from './open-data.service';
import { RolesGuard } from './open_data.middleware';
import { BusinessException } from 'src/common/exceptions/business.exception';
import Axios from "../utils/axios";
@Controller('api/v1/szjt')
@UseGuards(RolesGuard)
@ -39,17 +40,28 @@ export class OpenDataController {
}
@Post('/user/queryArchiveList')
userFile(@Body() { pageNo=0, pageSize=10, type=0 }) {
userFile(@Body() { pageNo=1, pageSize=10, type=0 }) {
return this.openDataService.userFile({pageNo, pageSize, type});
}
@Post('/user/queryDataList')
userHealthFile(@Body() { pageNo=0, pageSize=10, archiveId, hccId, dataType, dataTypeSub }) {
userHealthFile(@Body() { pageNo=1, pageSize=10, archiveId, hccId, dataType, dataTypeSub }) {
return this.openDataService.userHealthFile({pageNo, pageSize, archiveId, hccId, dataType, dataTypeSub});
}
@Post('/hcc/queryList')
homeList(@Body() { pageNo=0, pageSize =10, areaCode }) {
homeList(@Body() { pageNo=1, pageSize =10, areaCode }) {
return this.openDataService.homeList({pageNo, pageSize, areaCode});
}
@Post('/hcc/pushCallGetToken')
pushCallGetToken(@Body() { userName, passWord }) {
return this.openDataService.pushCallGetToken({ userName, passWord })
}
@Post('/hcc/pushCallBackHomeData')
pushCallBackHomeData(@Body() {dataList, authorization}) {
return this.openDataService.pushCallBackHomeData({dataList, authorization})
}
}

View File

@ -75,7 +75,7 @@ class OpenDataMapper {
*/
async getUserArchiveInfor(pageNo: number, pageSize: number, type: number) {
let sql =
'SELECT a.archive_id as archiveId,a.name,a.sex,a.birthday,a.height FROM szja_person_archive_info a';
'SELECT a.archive_id as archiveId,a.hcc_id as hccId,a.name,a.sex,a.birthday,a.height FROM szja_person_archive_info a ';
switch (type) {
case 0:
break;
@ -116,7 +116,7 @@ class OpenDataMapper {
*/
async getUserArchiveFlagInfor(id) {
return await db(
'SELECT a.flag_id as flagId,a.hcc_id as hccId,a.id,b.address_detail as addressDetail FROM szja_person_archive_flag a LEFT JOIN szja_hcc_info b ON b.id=a.hcc_id WHERE a.archive_id = ?',
'SELECT a.archive_id as archiveId,a.flag_id as flagId,c.`name`,b.address_detail as addressDetail FROM szja_person_archive_flag a LEFT JOIN szja_hcc_info b ON b.id=a.hcc_id LEFT JOIN szja_person_flag_info c on c.id=a.flag_id WHERE a.archive_id = ?',
[id],
);
}

View File

@ -5,6 +5,8 @@ import OpenDataMapper from '../open-data/open-data.mapper';
import { BusinessException } from 'src/common/exceptions/business.exception';
import { v4 } from 'uuid';
import clientMapper from '../client/client.mapper';
import {AxiosResult} from "../utils/axios";
@Injectable()
export class OpenDataService {
@ -68,6 +70,16 @@ export class OpenDataService {
}
async homeData({areaCode}) {
//判断地区编码是否存在
if (!areaCode){
throw BusinessException.throwValidateError()
}else {
//存在再判断是否为6位标准编码
if (areaCode.length == 6) {
//去除末尾0如440300变为4403
areaCode = areaCode.replace(/(0+)$/g, "")
}
}
const homeData = await OpenDataMapper.getHomeData(areaCode);
if (homeData?.length) {
const homeDataMap = new Map();
@ -76,7 +88,7 @@ export class OpenDataService {
totalNum: 0,
childAreaList: [],
};
// 计算家庭总数以及在线家庭总数并且依照区域编码存入map
homeData.forEach((val) => {
data.totalNum += val.sum;
if (val.onlineStatus == 1) {
@ -88,7 +100,7 @@ export class OpenDataService {
homeDataMap.set(val.areaCode, [val]);
}
});
// 从map中获取每个子地区家庭信息并填充childAreaList
homeDataMap.forEach((val) => {
let [totalNum, onlineNum] = [0, 0];
let areaCode, areaName;
@ -118,10 +130,11 @@ export class OpenDataService {
async userFile({pageNo, pageSize, type}) {
//获取指定类型的所有用户档案信息
const userFile = await OpenDataMapper.getUserArchiveInfor(
Number(pageNo),
(Number(pageNo) - 1) * pageSize,
Number(pageSize),
Number(type),
);
//获取指定类型的所有用户档案数量
const number = await OpenDataMapper.getUserArchiveNumber(Number(type));
if (number?.length) {
if (userFile?.length) {
@ -132,24 +145,24 @@ export class OpenDataService {
totalPage: Math.ceil(number[0].num / Number(pageSize)),
dataList: [],
};
if ((Number(pageNo) + 1) * Number(pageSize) < number[0].num) {
if (Number(pageNo) * Number(pageSize) < number[0].num) {
data.hasNext = true;
}
//根据每个用户档案中的档案id查找标签id再根据标签id获得用户标签最后填充data数据
for (const val of userFile) {
const flag = [];
let addressDetail=null
// 根据档案id查标签信息以及家庭住址最后填充dataList
const userArchiveFlagInfor = await OpenDataMapper.getUserArchiveFlagInfor(val.archiveId);
for (const item of userArchiveFlagInfor) {
if (item.addressDetail){
if (item.archiveId == val.archiveId){
addressDetail=item.addressDetail
flag.push(item.name);
}
const UserFlagInfor = await OpenDataMapper.getUserFlagInfor(
item.flagId,
);
flag.push(UserFlagInfor[0].name);
}
data.dataList.push({
hccId:val.hccId,
archiveId:val.archiveId,
name: val.name,
birthday: dayjs(val.birthday).format('YYYY-MM-DD'),
sex: val.sex,
@ -171,7 +184,7 @@ export class OpenDataService {
async userHealthFile({pageNo, pageSize, archiveId, hccId, dataType, dataTypeSub}) {
const userHealthFile = await OpenDataMapper.getUserHealthFile(
Number(pageNo),
(Number(pageNo) - 1) * pageSize,
Number(pageSize),
Number(archiveId),
hccId,
@ -194,7 +207,7 @@ export class OpenDataService {
//填充总数与页数相关的数据
data.totalNum = number[0].sum;
data.totalPage = Math.ceil(data.totalNum / Number(pageSize));
if ((Number(pageNo) + 1) * Number(pageSize) < data.totalNum) {
if (Number(pageNo) * Number(pageSize) < data.totalNum) {
data.hasNext = true;
}
@ -220,7 +233,7 @@ export class OpenDataService {
async homeList({pageNo, pageSize, areaCode}) {
const homeList = await OpenDataMapper.getHomeList(
Number(pageNo),
(Number(pageNo) - 1) * pageSize,
Number(pageSize),
areaCode,
);
@ -233,7 +246,7 @@ export class OpenDataService {
homeList: [],
};
data.totalPage = Math.ceil(data.totalNum / Number(pageSize));
if ((Number(pageNo) + 1) * Number(pageSize) < data.totalNum) {
if (Number(pageNo) * Number(pageSize) < data.totalNum) {
data.hasNext = true;
}
homeList.forEach((val) => {
@ -325,4 +338,27 @@ export class OpenDataService {
data: data,
};
}
async pushCallGetToken({userName, passWord}) {
const data = await AxiosResult(`http://47.106.225.195:8081/auth/login`, {
"username": userName,
"password": passWord
},{});
return data.data;
}
async pushCallBackHomeData({dataList, authorization}) {
const data = await AxiosResult(`http://47.106.225.195:8081/cockpit/api/callback`, {
"cmd":"0",
"payload":{
"dataList":dataList
}
}, {
headers: {
"Authorization":authorization
}
});
return data.data;
}
}