????

Your IP : 3.144.201.213


Current Path : C:/inetpub/vhost/binhdinhinvest.gdtvietnam.com/api/dist/xtdt/service/
Upload File :
Current File : C:/inetpub/vhost/binhdinhinvest.gdtvietnam.com/api/dist/xtdt/service/dashboard.service.js

"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DashboardService = void 0;
const common_1 = require("@nestjs/common");
const typeorm_1 = require("@nestjs/typeorm");
const typeorm_2 = require("typeorm");
const entity_1 = require("../entity");
const entity_2 = require("../../category/entity");
let DashboardService = class DashboardService {
    constructor(entity) {
        this.entity = entity;
    }
    tkeLoaiKhu(loaiKhu) {
        return this.entity.createQueryBuilder(entity_1.RanhGioiKhu, 'khu')
            .select("OBJECTID").where("khu.LoaiKhu = :loaiKhu", { loaiKhu }).getCount();
    }
    tkeLinhVuc() {
        return this.entity.createQueryBuilder(entity_1.QuyHoachSDD, 'quyHoach')
            .select("lv.TenLinhVuc", "linhVucDauTu").addSelect("lv.Code", "maLinhVuc")
            .addSelect("COUNT(quyHoach.OBJECTID)", "tongSo")
            .innerJoin(entity_2.LinhVucDauTu, "lv", "lv.Code = quyHoach.LinhVucDauTu")
            .groupBy("lv.Code").addGroupBy("lv.TenLinhVuc").getRawMany();
    }
    tkeDoanhNghiep() {
        return this.entity.query(`
        SELECT 
            count(distinct t.DoanhNghiepID) as TongSo,
            COUNT(DISTINCT CASE WHEN t.LoaiDoanhNghiep = 'TN' THEN t.DoanhNghiepID ELSE null END) AS TrongNuoc,
            COUNT(DISTINCT CASE WHEN t.LoaiDoanhNghiep = 'NN' THEN t.DoanhNghiepID ELSE null END) AS NgoaiNuoc,
            SUM ( CASE WHEN t.Loai = 'DDT' AND t.LoaiDoanhNghiep = 'TN' THEN 1 ELSE 0 END ) DDTTrongNuoc,
            SUM ( CASE WHEN t.Loai = 'DDT' AND t.LoaiDoanhNghiep = 'NN' THEN 1 ELSE 0 END ) DDTNgoaiNuoc,
            SUM ( CASE WHEN t.Loai = 'KCN' and t.LoaiDoanhNghiep = 'TN' THEN 1 ELSE 0 END ) KCNTrongNuoc,
            SUM ( CASE WHEN t.Loai = 'KCN' and t.LoaiDoanhNghiep = 'NN' THEN 1 ELSE 0 END ) KCNNgoaiNuoc,
            SUM ( CASE WHEN t.Loai = 'CCN' and t.LoaiDoanhNghiep = 'TN' THEN 1 ELSE 0 END ) CCNTrongNuoc,
            SUM ( CASE WHEN t.Loai = 'CCN' and t.LoaiDoanhNghiep = 'NN' THEN 1 ELSE 0 END ) CCNNgoaiNuoc
        FROM
            (
            SELECT DISTINCT
                dntt.DoanhNghiepID,
                r.LoaiKhu AS Loai,
                dn.LoaiDoanhNghiep 
            FROM
                DOANHNGHIEP_THONGTINTHUE dntt
                JOIN RANHGIOIKHU r ON r.MaKhu = dntt.MaKhu
                JOIN DOANHNGHIEP dn ON dn.OBJECTID = dntt.DoanhNghiepID UNION ALL
            SELECT DISTINCT
                dntt.DoanhNghiepID,
                'DDT' AS Loai,
                dn.LoaiDoanhNghiep 
            FROM
                DOANHNGHIEP_THONGTINTHUE dntt
                JOIN DIEMDAUTU d ON d.DiemDauTuID = dntt.DiemDauTuId
            JOIN DOANHNGHIEP dn ON dn.OBJECTID = dntt.DoanhNghiepID 
            ) t
        `).then(result => result[0]);
    }
    tkeVonDauTu() {
        return this.entity.query(`
            SELECT SUM(tt.TongVonDauTu) TongSo,
                SUM(CASE WHEN dn.LoaiDoanhNghiep = N'TN' THEN tt.TongVonDauTu ELSE 0 END) TrongNuoc,
                SUM(CASE WHEN dn.LoaiDoanhNghiep = N'NN' THEN tt.TongVonDauTu ELSE 0 END) NgoaiNuoc
                FROM DOANHNGHIEP_THONGTINTHUE tt
                JOIN DOANHNGHIEP dn ON dn.ObjectID = tt.DoanhNghiepID
        `).then(result => result[0]);
    }
    tkeQuocGia() {
        return this.entity.query(`
            SELECT qg.TenQuocGia, qg.Code as MaQuocGia, SUM(tt.TongVonDauTu) TongVonDauTu
                FROM DOANHNGHIEP_THONGTINTHUE tt
                JOIN DOANHNGHIEP dn ON dn.ObjectID = tt.DoanhNghiepID
                JOIN DM_QuocGia qg ON qg.ID = dn.QuocGiaID
                GROUP BY qg.TenQuocGia,qg.Code
                ORDER BY TongVonDauTu DESC
        `);
    }
    tkDauTu() {
        return this.entity.query(`
        SELECT SUM
            ( CASE WHEN LoaiHinhDauTu = N'TN' THEN 1 ELSE 0 END ) TrongNuoc,
            SUM ( CASE WHEN LoaiHinhDauTu = N'NN' THEN 1 ELSE 0 END ) NgoaiNuoc,
            SUM ( CASE WHEN TinhTrang = N'DKG' THEN 1 ELSE 0 END ) MoiGoi,
            SUM ( CASE WHEN LoaiHinhDauTu = N'TN' THEN TongMucDauTuDuKien ELSE 0 END ) VonTrongNuoc,
            SUM ( CASE WHEN LoaiHinhDauTu = N'NN' THEN TongMucDauTuDuKien ELSE 0 END ) VonNgoaiNuoc,
            SUM ( CASE WHEN TinhTrang = N'DKG' THEN TongMucDauTuDuKien ELSE 0 END ) VonMoiGoi 
        FROM
            DIEMDAUTU ddt
        `).then(result => result[0]);
    }
};
DashboardService = __decorate([
    (0, common_1.Injectable)(),
    __param(0, (0, typeorm_1.InjectEntityManager)()),
    __metadata("design:paramtypes", [typeorm_2.EntityManager])
], DashboardService);
exports.DashboardService = DashboardService;