zs hace 8 meses
padre
commit
9d073758e2
Se han modificado 1 ficheros con 222 adiciones y 5 borrados
  1. 222 5
      src/service/util.service.ts

+ 222 - 5
src/service/util.service.ts

@@ -21,6 +21,7 @@ import { CompanyYear } from '../entity/users/companyYear.entity';
 import { Expert } from '../entity/users/expert.entity';
 import { RoleService } from './system/role.service';
 import { Incubator } from '../entity/users/incubator.entity';
+import { SectorService } from './platform/sector.service';
 /**
  * 工具类服务,为其他地方提供一些通用的函数
  */
@@ -51,6 +52,8 @@ export class UtilService {
   @Inject()
   dictDataService: DictDataService;
   @Inject()
+  sectorService: SectorService;
+  @Inject()
   roleService: RoleService;
 
   @Config('PathConfig.path')
@@ -352,6 +355,29 @@ export class UtilService {
         }
       }
     }
+    //孵化器入驻数量
+    if (type === 'incubate') {
+      res = await this.incubatorModel.createQueryBuilder('incubator').getMany();
+      for (const val of res) {
+        nameList.push(val.name);
+        list.push(parseInt(val.company_num || 0));
+      }
+    }
+    //用户所属产业包含总数
+    if (type === 'user') {
+      req = await this.sectorService.query({ is_use: '0' }, {});
+      if (req.data) {
+        for (const val of req.data) {
+          const total = await this.userModel
+            .createQueryBuilder()
+            .where('industry IS NOT NULL') // 确保username字段不为空
+            .andWhere('JSONB_EXISTS(industry, :column)', { column: val.title }) // 使用数组作为查询条件
+            .getCount(); // 获取总数
+          nameList.push(val.title);
+          list.push({ name: val.title, value: total || 0 });
+        }
+      }
+    }
     return { nameList, list };
   }
 
@@ -424,9 +450,14 @@ export class UtilService {
         }
       }
     }
-    //孵化器统计数量
-    // if (type === 'incubate') {
-    // }
+    // 孵化器市级以上活动数统计数量
+    if (type === 'incubate') {
+      res = await this.incubatorModel.createQueryBuilder('incubator').getMany();
+      for (const val of res) {
+        nameList.push(val.name);
+        list.push({ name: val.name, value: parseInt(val.actCity_num) || 0 });
+      }
+    }
     // 用户角色统计
     if (type === 'user') {
       res = await this.userModel.createQueryBuilder('expert').select('expert.role', 'role').addSelect('COUNT(expert.id)', 'total').groupBy('expert.role').getRawMany();
@@ -459,15 +490,170 @@ export class UtilService {
   }
 
   async fourStatistics(type) {
-    console.log(type);
+    let list = [];
+    let res;
+    // 企业地区分布
+    if (type === 'company') {
+      res = await this.companyModel.createQueryBuilder('company').select('company.area', 'area').addSelect('COUNT(company.id)', 'total').groupBy('company.area').getRawMany();
+      for (const val of res) {
+        if (val.area && val.area.length > 1) {
+          const area = val.area[1];
+          list.push({ name: area, value: parseInt(val.total) });
+        }
+      }
+      list = list.reduce((acc, obj) => {
+        const existingObj = acc.find(item => item.name === obj.name);
+        if (existingObj) {
+          existingObj.value += obj.value;
+        } else {
+          acc.push({ ...obj });
+        }
+        return acc;
+      }, []);
+    }
+    // 专家地区分布
+    if (type === 'expert') {
+      res = await this.expertModel.createQueryBuilder('expert').select('expert.area', 'area').addSelect('COUNT(expert.id)', 'total').groupBy('expert.area').getRawMany();
+      for (const val of res) {
+        if (val.area && val.area.length > 1) {
+          const area = val.area[1];
+          list.push({ name: area, value: parseInt(val.total) });
+        }
+      }
+      list = list.reduce((acc, obj) => {
+        const existingObj = acc.find(item => item.name === obj.name);
+        if (existingObj) {
+          existingObj.value += obj.value;
+        } else {
+          acc.push({ ...obj });
+        }
+        return acc;
+      }, []);
+    }
+    // 需求地区分布
+    if (type === 'demand') {
+      res = await this.demandModel.createQueryBuilder('demand').select('demand.area', 'area').addSelect('COUNT(demand.id)', 'total').groupBy('demand.area').getRawMany();
+      for (const val of res) {
+        if (val.area && val.area.length > 1) {
+          const area = val.area[1];
+          list.push({ name: area, value: parseInt(val.total) });
+        }
+      }
+      list = list.reduce((acc, obj) => {
+        const existingObj = acc.find(item => item.name === obj.name);
+        if (existingObj) {
+          existingObj.value += obj.value;
+        } else {
+          acc.push({ ...obj });
+        }
+        return acc;
+      }, []);
+    }
+    // 供给地区分布
+    if (type === 'supply') {
+      res = await this.supplyModel.createQueryBuilder('supply').select('supply.area', 'area').addSelect('COUNT(supply.id)', 'total').groupBy('supply.area').getRawMany();
+      for (const val of res) {
+        if (val.area && val.area.length > 1) {
+          const area = val.area[1];
+          list.push({ name: area, value: parseInt(val.total) });
+        }
+      }
+      list = list.reduce((acc, obj) => {
+        const existingObj = acc.find(item => item.name === obj.name);
+        if (existingObj) {
+          existingObj.value += obj.value;
+        } else {
+          acc.push({ ...obj });
+        }
+        return acc;
+      }, []);
+    }
+    // 成果地区分布
+    if (type === 'achievement') {
+      res = await this.achievementModel.createQueryBuilder('achievement').select('achievement.area', 'area').addSelect('COUNT(achievement.id)', 'total').groupBy('achievement.area').getRawMany();
+      for (const val of res) {
+        if (val.area && val.area.length > 1) {
+          const area = val.area[1];
+          list.push({ name: area, value: parseInt(val.total) });
+        }
+      }
+      list = list.reduce((acc, obj) => {
+        const existingObj = acc.find(item => item.name === obj.name);
+        if (existingObj) {
+          existingObj.value += obj.value;
+        } else {
+          acc.push({ ...obj });
+        }
+        return acc;
+      }, []);
+    }
+    // 项目地区分布
+    if (type === 'project') {
+      res = await this.projectModel.createQueryBuilder('project').select('project.area', 'area').addSelect('COUNT(project.id)', 'total').groupBy('project.area').getRawMany();
+      for (const val of res) {
+        if (val.area && val.area.length > 1) {
+          const area = val.area[1];
+          list.push({ name: area, value: parseInt(val.total) });
+        }
+      }
+      list = list.reduce((acc, obj) => {
+        const existingObj = acc.find(item => item.name === obj.name);
+        if (existingObj) {
+          existingObj.value += obj.value;
+        } else {
+          acc.push({ ...obj });
+        }
+        return acc;
+      }, []);
+    }
+    // 孵化基地地区分布
+    if (type === 'incubate') {
+      res = await this.incubatorModel.createQueryBuilder('incubator').select('incubator.area', 'area').addSelect('COUNT(incubator.id)', 'total').groupBy('incubator.area').getRawMany();
+      for (const val of res) {
+        if (val.area && val.area.length > 1) {
+          const area = val.area[1];
+          list.push({ name: area, value: parseInt(val.total) });
+        }
+      }
+      list = list.reduce((acc, obj) => {
+        const existingObj = acc.find(item => item.name === obj.name);
+        if (existingObj) {
+          existingObj.value += obj.value;
+        } else {
+          acc.push({ ...obj });
+        }
+        return acc;
+      }, []);
+    }
+    return list;
   }
 
   async fiveStatistics(type) {
-    console.log(type);
+    let res;
+    let req;
+    const nameList = [];
+    const list = [];
+    //用户所属产业包含总数
+    if (type === 'user') {
+      req = await this.sectorService.query({ is_use: '0' }, {});
+      if (req.data) {
+        for (const val of req.data) {
+          const total = await this.userModel
+            .createQueryBuilder()
+            .where('industry IS NOT NULL') // 确保username字段不为空
+            .andWhere('JSONB_EXISTS(industry, :column)', { column: val.title }) // 使用数组作为查询条件
+            .getCount(); // 获取总数
+          nameList.push(val.title);
+          list.push({ name: val.title, value: total || 0 });
+        }
+      }
+    }
+    return { nameList, list };
   }
 
   async sixStatistics(type) {
     let res;
+    let req;
     const nameList = [];
     const list = [];
     let max = [];
@@ -483,6 +669,7 @@ export class UtilService {
     // 专家按职称统计
     if (type === 'expert') {
       res = await this.expertModel.createQueryBuilder('expert').select('expert.title', 'title').addSelect('COUNT(expert.id)', 'total').groupBy('expert.title').getRawMany();
+      res.sort((a, b) => b.total - a.total);
       for (const val of res.slice(0, 9)) {
         nameList.push(val.title);
         list.push(parseInt(val.total || 0));
@@ -492,6 +679,7 @@ export class UtilService {
     // 需求按行业领域统计
     if (type === 'demand') {
       res = await this.demandModel.createQueryBuilder('demand').select('demand.field', 'field').addSelect('COUNT(demand.id)', 'total').groupBy('demand.field').getRawMany();
+      res.sort((a, b) => b.total - a.total);
       for (const val of res.slice(0, 9)) {
         if (val.field) {
           nameList.push(val.field);
@@ -503,6 +691,7 @@ export class UtilService {
     // 供给按行业领域统计
     if (type === 'supply') {
       res = await this.supplyModel.createQueryBuilder('supply').select('supply.field', 'field').addSelect('COUNT(supply.id)', 'total').groupBy('supply.field').getRawMany();
+      res.sort((a, b) => b.total - a.total);
       for (const val of res.slice(0, 9)) {
         if (val.field) {
           nameList.push(val.field);
@@ -514,6 +703,7 @@ export class UtilService {
     // 项目按来源统计
     if (type === 'project') {
       res = await this.projectModel.createQueryBuilder('project').select('project.source', 'source').addSelect('COUNT(project.id)', 'total').groupBy('project.source').getRawMany();
+      res.sort((a, b) => b.total - a.total);
       for (const val of res.slice(0, 9)) {
         if (val.source) {
           nameList.push(val.source);
@@ -525,6 +715,7 @@ export class UtilService {
     // 成果按来源统计
     if (type === 'achievement') {
       res = await this.achievementModel.createQueryBuilder('achievement').select('achievement.source', 'source').addSelect('COUNT(achievement.id)', 'total').groupBy('achievement.source').getRawMany();
+      res.sort((a, b) => b.total - a.total);
       for (const val of res.slice(0, 9)) {
         if (val.source) {
           nameList.push(val.source);
@@ -533,6 +724,32 @@ export class UtilService {
       }
       max = [100, 100, 100, 100, 100, 100, 100, 100];
     }
+    //孵化器省级以上导师数排名
+    if (type === 'incubate') {
+      res = await this.incubatorModel.createQueryBuilder('incubator').getMany();
+      for (const val of res) {
+        nameList.push(val.name);
+        list.push({ name: val.name, value: parseInt(val.teacher_num) });
+      }
+      list.sort((a, b) => b.value - a.value);
+      max = [100, 100, 100, 100, 100, 100, 100, 100];
+    }
+    //用户男女比例排名
+    if (type === 'user') {
+      res = await this.userModel.createQueryBuilder('user').select('user.gender', 'gender').addSelect('COUNT(user.id)', 'total').groupBy('user.gender').getRawMany();
+      req = await this.dictDataService.query({ code: 'gender', is_use: '0' }, {});
+      res.sort((a, b) => b.total - a.total);
+      for (const val of res) {
+        if (req.data) {
+          const select = req.data.find(f => f.value === val.gender);
+          if (select) {
+            nameList.push(select.label);
+            list.push({ name: select.label, value: val.total });
+          }
+        }
+      }
+      max = [100, 100, 100, 100, 100, 100, 100, 100];
+    }
     return { nameList, list, max };
   }
   // 计算百分比