|
@@ -0,0 +1,125 @@
|
|
|
|
+'use strict';
|
|
|
|
+const { CrudService } = require('naf-framework-mongoose/lib/service');
|
|
|
|
+const { BusinessError, ErrorCode } = require('naf-core').Error;
|
|
|
|
+const { ObjectId } = require('mongoose').Types;
|
|
|
|
+const _ = require('lodash');
|
|
|
|
+const assert = require('assert');
|
|
|
|
+
|
|
|
|
+// 首页-数据动态统计
|
|
|
|
+class IndexService extends CrudService {
|
|
|
|
+ constructor(ctx) {
|
|
|
|
+ super(ctx, 'index');
|
|
|
|
+ this.redis = this.app.redis;
|
|
|
|
+ this.patentModel = this.ctx.model.Patent; // 专利
|
|
|
|
+ this.code = this.ctx.model.Code; // 字典
|
|
|
|
+ this.productModel = this.ctx.model.Product; // 产品
|
|
|
|
+ this.expertModel = this.ctx.model.Expert; // 专家
|
|
|
|
+ this.mechanismModel = this.ctx.model.Mechanism;// 机构
|
|
|
|
+ this.orgModel = this.ctx.model.Organization; // 企业
|
|
|
|
+ this.policyModel = this.ctx.model.Policy; // 高企政策
|
|
|
|
+ this.ticketModel = this.ctx.model.Ticket; // 创新券
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * 首页专利统计
|
|
|
|
+ */
|
|
|
|
+ async patent() {
|
|
|
|
+ const res = await this.patentModel.aggregate([
|
|
|
|
+ {
|
|
|
|
+ $group: {
|
|
|
|
+ _id: '$apply_personal',
|
|
|
|
+ value: { $sum: 1 },
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ ]);
|
|
|
|
+ let arr = [];
|
|
|
|
+ const other = { name: '其他', value: 0 };
|
|
|
|
+ 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)
|
|
|
|
+ );
|
|
|
|
+ if (unit) {
|
|
|
|
+ // 说明是需要单拎出来的数据,现查arr中是否有该单位:有=>数字合并;没有=>创建条目
|
|
|
|
+ const { name } = unit;
|
|
|
|
+ const arrItem = arr.find(f => f.name === name);
|
|
|
|
+ if (arrItem) {
|
|
|
|
+ const index = arr.findIndex(f => f.name === name);
|
|
|
|
+ arr[index] = { name, value: (arrItem.value || 0) + value };
|
|
|
|
+ } else {
|
|
|
|
+ arr.push({ name, value });
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ other.value += value;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ arr = _.orderBy(arr, [ 'value' ], [ 'desc' ]);
|
|
|
|
+ arr.push(other);
|
|
|
|
+ return arr;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 首页成果统计
|
|
|
|
+ */
|
|
|
|
+ async product() {
|
|
|
|
+ const categroy = await this.code.find({ category: '01' });
|
|
|
|
+ const condition = { type: '1', status: '2' };
|
|
|
|
+ const arr = [];
|
|
|
|
+ for (const c of categroy) {
|
|
|
|
+ const { name } = c;
|
|
|
|
+ const value = await this.productModel.count({
|
|
|
|
+ ...condition,
|
|
|
|
+ field: name,
|
|
|
|
+ });
|
|
|
|
+ arr.push({ value, name });
|
|
|
|
+ }
|
|
|
|
+ return arr;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 统计用户(企业,专家,机构)数量
|
|
|
|
+ */
|
|
|
|
+ async users() {
|
|
|
|
+ const org = await this.orgModel.count({ status: '1' });
|
|
|
|
+ const expert = await this.expertModel.count({ status: '1' });
|
|
|
|
+ const mech = await this.mechanismModel.count({ status: '1' });
|
|
|
|
+ return { organization: org, expert, mechanism: mech };
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * 统计各种数据
|
|
|
|
+ */
|
|
|
|
+ async data() {
|
|
|
|
+ // 高企政策服务通过数量 1
|
|
|
|
+ const policy = await this.policyModel.count({ status: '1' });
|
|
|
|
+ // 创新券领取成果数量 4
|
|
|
|
+ const ticket = await this.ticketModel.count({ status: '4' });
|
|
|
|
+ // 科技成果成功的数量 8
|
|
|
|
+ const product = await this.productModel.count({ status: '6' });
|
|
|
|
+ return { policy, ticket, product };
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 专利单位列表
|
|
|
|
+ */
|
|
|
|
+ patentUnitList() {
|
|
|
|
+ return [
|
|
|
|
+ { name: '吉林大学' },
|
|
|
|
+ { name: '长春理工大学' },
|
|
|
|
+ { name: '东北电力大学' },
|
|
|
|
+ { name: '吉林工程技术师范学院' },
|
|
|
|
+ { name: '长春工业大学' },
|
|
|
|
+ { name: '北华大学' },
|
|
|
|
+ { name: '吉林农业大学' },
|
|
|
|
+ { name: '吉林师范大学' },
|
|
|
|
+ { name: '长春工程学院' },
|
|
|
|
+ { name: '吉林建筑大学' },
|
|
|
|
+ { name: '通化师范学院' },
|
|
|
|
+ { name: '长春大学' },
|
|
|
|
+ { name: '东北师范大学' },
|
|
|
|
+ { name: '吉林农业科技学院' },
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+module.exports = IndexService;
|