|
@@ -19,7 +19,7 @@ class IndexService extends CrudService {
|
|
|
this.organizationModel = this.ctx.model.Organization;
|
|
|
this.surveyModel = this.ctx.model.Survey;
|
|
|
this.dockUser = this.ctx.model.Dock.DockUser; // 没改
|
|
|
- this.tranModel = this.ctx.model.Dock.DockTranscation;// 没改
|
|
|
+ this.tranModel = this.ctx.model.Dock.DockTranscation; // 没改
|
|
|
}
|
|
|
/**
|
|
|
* 首页专利统计
|
|
@@ -38,15 +38,13 @@ class IndexService extends CrudService {
|
|
|
for (const i of res) {
|
|
|
const { _id, value } = i;
|
|
|
const unitList = this.patentUnitList();
|
|
|
- const unit = unitList.find(
|
|
|
- f => (_id && _id.includes(f.name)) || f.name.includes(_id)
|
|
|
- );
|
|
|
+ const unit = unitList.find((f) => (_id && _id.includes(f.name)) || f.name.includes(_id));
|
|
|
if (unit) {
|
|
|
// 说明是需要单拎出来的数据,现查arr中是否有该单位:有=>数字合并;没有=>创建条目
|
|
|
const { name } = unit;
|
|
|
- const arrItem = arr.find(f => f.name === name);
|
|
|
+ const arrItem = arr.find((f) => f.name === name);
|
|
|
if (arrItem) {
|
|
|
- const index = arr.findIndex(f => f.name === name);
|
|
|
+ const index = arr.findIndex((f) => f.name === name);
|
|
|
arr[index] = { name, value: (arrItem.value || 0) + value };
|
|
|
} else {
|
|
|
arr.push({ name, value });
|
|
@@ -55,7 +53,7 @@ class IndexService extends CrudService {
|
|
|
other.value += value;
|
|
|
}
|
|
|
}
|
|
|
- arr = _.orderBy(arr, [ 'value' ], [ 'desc' ]);
|
|
|
+ arr = _.orderBy(arr, ['value'], ['desc']);
|
|
|
arr.push(other);
|
|
|
return arr;
|
|
|
}
|
|
@@ -95,15 +93,13 @@ class IndexService extends CrudService {
|
|
|
for (const i of res) {
|
|
|
const { _id, value } = i;
|
|
|
const unitList = this.expertList();
|
|
|
- const unit = unitList.find(
|
|
|
- f => (_id && _id.includes(f.name)) || f.name.includes(_id)
|
|
|
- );
|
|
|
+ const unit = unitList.find((f) => (_id && _id.includes(f.name)) || f.name.includes(_id));
|
|
|
if (unit) {
|
|
|
// 说明是需要单拎出来的数据,现查arr中是否有该单位:有=>数字合并;没有=>创建条目
|
|
|
const { name, sort } = unit;
|
|
|
- const arrItem = arr.find(f => f.name === name);
|
|
|
+ const arrItem = arr.find((f) => f.name === name);
|
|
|
if (arrItem) {
|
|
|
- const index = arr.findIndex(f => f.name === name);
|
|
|
+ const index = arr.findIndex((f) => f.name === name);
|
|
|
arr[index] = { ...arr[index], value: (arrItem.value || 0) + value };
|
|
|
} else {
|
|
|
arr.push({ name, value, sort });
|
|
@@ -112,11 +108,11 @@ class IndexService extends CrudService {
|
|
|
other.value += value;
|
|
|
}
|
|
|
}
|
|
|
- arr = _.orderBy(arr, [ 'sort' ], [ 'asc' ]);
|
|
|
+ arr = _.orderBy(arr, ['sort'], ['asc']);
|
|
|
arr.push(other);
|
|
|
// 换名
|
|
|
- arr.map(i => {
|
|
|
- const r = this.expertList().find(f => f.name === i.name);
|
|
|
+ arr.map((i) => {
|
|
|
+ const r = this.expertList().find((f) => f.name === i.name);
|
|
|
if (r && r.alias) i.name = r.alias;
|
|
|
return i;
|
|
|
});
|
|
@@ -158,7 +154,7 @@ class IndexService extends CrudService {
|
|
|
value: surveys,
|
|
|
});
|
|
|
const trans = await this.tranModel.aggregate([
|
|
|
- { $match: { status: { $in: [ '0', '1', '3' ] } } },
|
|
|
+ { $match: { status: { $in: ['0', '1', '3'] } } },
|
|
|
{
|
|
|
$group: {
|
|
|
_id: '$status',
|
|
@@ -169,7 +165,7 @@ class IndexService extends CrudService {
|
|
|
arr.push({
|
|
|
name: '正在洽谈',
|
|
|
value: _.get(
|
|
|
- trans.find(f => f._id === '0'),
|
|
|
+ trans.find((f) => f._id === '0'),
|
|
|
'value',
|
|
|
0
|
|
|
),
|
|
@@ -177,7 +173,7 @@ class IndexService extends CrudService {
|
|
|
arr.push({
|
|
|
name: '达成意向',
|
|
|
value: _.get(
|
|
|
- trans.find(f => f._id === '1'),
|
|
|
+ trans.find((f) => f._id === '1'),
|
|
|
'value',
|
|
|
0
|
|
|
),
|
|
@@ -185,7 +181,7 @@ class IndexService extends CrudService {
|
|
|
arr.push({
|
|
|
name: '对接完成',
|
|
|
value: _.get(
|
|
|
- trans.find(f => f._id === '3'),
|
|
|
+ trans.find((f) => f._id === '3'),
|
|
|
'value',
|
|
|
0
|
|
|
),
|
|
@@ -231,14 +227,17 @@ class IndexService extends CrudService {
|
|
|
// 展会首页统计
|
|
|
async dockIndex({ dock_id }) {
|
|
|
// 同时在线人数(伪)
|
|
|
- const tszx = await this.redis.get('login_number');
|
|
|
+ let tszx = _.random(100, 1000);
|
|
|
+ if(this.redis) {
|
|
|
+ tszx = (await this.redis.get('login_number')) || tszx;
|
|
|
+ }
|
|
|
// 特邀嘉宾
|
|
|
// const tyjb = await this.personalModel.count({ is_expert: true });
|
|
|
const tyjb = 81;
|
|
|
console.log(tyjb);
|
|
|
// 洽谈合作 达成意向 交易完成
|
|
|
const trans = await this.tranModel.aggregate([
|
|
|
- { $match: { status: { $in: [ '0', '1', '3' ] } } },
|
|
|
+ { $match: { status: { $in: ['0', '1', '3'] } } },
|
|
|
{
|
|
|
$group: {
|
|
|
_id: '$status',
|
|
@@ -247,17 +246,17 @@ class IndexService extends CrudService {
|
|
|
},
|
|
|
]);
|
|
|
const qthz = _.get(
|
|
|
- trans.find(f => f._id === '0'),
|
|
|
+ trans.find((f) => f._id === '0'),
|
|
|
'value',
|
|
|
0
|
|
|
);
|
|
|
const dcyx = _.get(
|
|
|
- trans.find(f => f._id === '1'),
|
|
|
+ trans.find((f) => f._id === '1'),
|
|
|
'value',
|
|
|
0
|
|
|
);
|
|
|
const jywc = _.get(
|
|
|
- trans.find(f => f._id === '3'),
|
|
|
+ trans.find((f) => f._id === '3'),
|
|
|
'value',
|
|
|
0
|
|
|
);
|
|
@@ -293,10 +292,12 @@ class IndexService extends CrudService {
|
|
|
const gq = await this.ctx.model.Declare.count({ is_cashing: '1' });
|
|
|
const yfjl = await this.ctx.model.Reward.aggregate([
|
|
|
{ $match: { is_cashing: '1' } },
|
|
|
- { $group: {
|
|
|
- _id: '$type',
|
|
|
- count: { $sum: 1 },
|
|
|
- } },
|
|
|
+ {
|
|
|
+ $group: {
|
|
|
+ _id: '$type',
|
|
|
+ count: { $sum: 1 },
|
|
|
+ },
|
|
|
+ },
|
|
|
]);
|
|
|
const arr = [
|
|
|
{ key: '奖励兑现', name: '奖励兑现' },
|
|
@@ -312,10 +313,12 @@ class IndexService extends CrudService {
|
|
|
*/
|
|
|
async declare() {
|
|
|
const res = await this.ctx.model.Declare.aggregate([
|
|
|
- { $group: {
|
|
|
- _id: '$status',
|
|
|
- count: { $sum: 1 },
|
|
|
- } },
|
|
|
+ {
|
|
|
+ $group: {
|
|
|
+ _id: '$status',
|
|
|
+ count: { $sum: 1 },
|
|
|
+ },
|
|
|
+ },
|
|
|
]);
|
|
|
const arr = [
|
|
|
{ key: '0', name: '企业信息待审中' },
|
|
@@ -337,7 +340,7 @@ class IndexService extends CrudService {
|
|
|
const obj = [];
|
|
|
for (const i of meta) {
|
|
|
const { key, name } = i;
|
|
|
- const r = list.find(f => f._id === key);
|
|
|
+ const r = list.find((f) => f._id === key);
|
|
|
if (r) {
|
|
|
obj.push({ name, value: r.count });
|
|
|
} else {
|
|
@@ -357,23 +360,16 @@ class IndexService extends CrudService {
|
|
|
if (key.includes('.')) productQuery[key] = query[key];
|
|
|
else userQuery[key] = query[key];
|
|
|
}
|
|
|
- const publics = [
|
|
|
- { $match: userQuery },
|
|
|
- { $project: { productList: 1, _id: 0 } },
|
|
|
- { $unwind: '$productList' },
|
|
|
- { $match: productQuery },
|
|
|
- ];
|
|
|
- const data = await this.ctx.model.Dock.DockUser.aggregate([
|
|
|
- ...publics,
|
|
|
- { $skip: parseInt(skip) },
|
|
|
- { $limit: parseInt(limit) },
|
|
|
- ]).replaceRoot('productList');
|
|
|
+ const publics = [{ $match: userQuery }, { $project: { productList: 1, _id: 0 } }, { $unwind: '$productList' }, { $match: productQuery }];
|
|
|
+ const data = await this.ctx.model.Dock.DockUser.aggregate([...publics, { $skip: parseInt(skip) }, { $limit: parseInt(limit) }]).replaceRoot('productList');
|
|
|
let total = await this.ctx.model.Dock.DockUser.aggregate([
|
|
|
...publics,
|
|
|
- { $group: {
|
|
|
- _id: null,
|
|
|
- count: { $sum: 1 },
|
|
|
- } },
|
|
|
+ {
|
|
|
+ $group: {
|
|
|
+ _id: null,
|
|
|
+ count: { $sum: 1 },
|
|
|
+ },
|
|
|
+ },
|
|
|
]);
|
|
|
if (total && _.isArray(total)) {
|
|
|
total = _.get(_.head(total), 'count', 0);
|
|
@@ -388,32 +384,34 @@ class IndexService extends CrudService {
|
|
|
const unread = await patentExamine.count({ to: id, is_read: false });
|
|
|
// 专利申请
|
|
|
const papply = this.ctx.model.Patent.Patentapply;
|
|
|
- const apply = await papply.count({ status: [ '0', '1', '-1', '2', '-2', '3', '-3', '4', '5' ], user_id: id });
|
|
|
+ const apply = await papply.count({ status: ['0', '1', '-1', '2', '-2', '3', '-3', '4', '5'], user_id: id });
|
|
|
// 查询检索
|
|
|
const palysis = this.ctx.model.Patent.Patentanalysis;
|
|
|
- const analysis = await palysis.count({ status: [ '0', '1', '-1', '2' ], user_id: id });
|
|
|
+ const analysis = await palysis.count({ status: ['0', '1', '-1', '2'], user_id: id });
|
|
|
// 价值评估
|
|
|
const paccess = this.ctx.model.Patent.Patentassess;
|
|
|
- const access = await paccess.count({ status: [ '0', '1', '-1', '2' ], user_id: id });
|
|
|
+ const access = await paccess.count({ status: ['0', '1', '-1', '2'], user_id: id });
|
|
|
// 专利信息
|
|
|
const patentInfo = this.ctx.model.Patent.Patentinfo;
|
|
|
const information = await patentInfo.count({ inventor: { $elemMatch: { user_id: ObjectId(id) } } });
|
|
|
// 专利维权
|
|
|
const patentsafeg = this.ctx.model.Patent.Patentsafeg;
|
|
|
- const safeg = await patentsafeg.count({ status: [ '0', '1', '2' ], user_id: id });
|
|
|
+ const safeg = await patentsafeg.count({ status: ['0', '1', '2'], user_id: id });
|
|
|
// 专利预警
|
|
|
const patentEarly = this.ctx.model.Patent.Patentearly;
|
|
|
- const early = await patentEarly.count({ user_id: { $elemMatch: { $in: [ ObjectId(id) ] } } });
|
|
|
+ const early = await patentEarly.count({ user_id: { $elemMatch: { $in: [ObjectId(id)] } } });
|
|
|
// 专利交易
|
|
|
const patentTrans = this.ctx.model.Patent.Patenttrans;
|
|
|
const trans1 = await patentTrans.count({ type: '转让', user_id: id });
|
|
|
const trans2 = await patentTrans.count({ type: '许可', user_id: id });
|
|
|
const trans3 = await patentTrans.count({ type: '招商', user_id: id });
|
|
|
return {
|
|
|
- message: { unread }, apply: { apply, analysis, access }, patent: { information, safeg, early }, transaction: { trans1, trans2, trans3 },
|
|
|
+ message: { unread },
|
|
|
+ apply: { apply, analysis, access },
|
|
|
+ patent: { information, safeg, early },
|
|
|
+ transaction: { trans1, trans2, trans3 },
|
|
|
};
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
module.exports = IndexService;
|