????
Current Path : C:/inetpub/vhost/sdoc.gdtsolutions.vn/package/app/controllers/ |
Current File : C:/inetpub/vhost/sdoc.gdtsolutions.vn/package/app/controllers/bieudo.js |
var moment = require('moment'); const Database = require('../models/Database'); const queryBuilder = require('../repositories/QueryBuilder'); class BieuDoController extends Database { constructor(params) { super(params); } static create(params) { return new BieuDoController(params); } async getFondData() { return await queryBuilder('Fond') .column(['Fond.FondNumber','Fond.FondCode','Fond.FondName','Fond.PaperDigital']) .countDistinct('File.UUID', {as: 'tongSoHS'}) .count('Document.UUID', {as: 'tongSoVB'}) .leftJoin('File', (j) => j.on('File.FondCode', 'Fond.FondCode').andOn('File.State', 1)) .leftJoin('Document', 'Document.FileId', 'File.UUID') .where('Fond.IsStatisticsVisible', 1) .groupBy('Fond.FondNumber','Fond.FondCode','Fond.FondName', 'Fond.PaperDigital') .orderBy('Fond.FondNumber'); // return this.select('select Fond.FondNumber,Fond.FondCode,Fond.FondName,COUNT(DISTINCT [File].UUID) as tongSoHS,COUNT(Document.UUID) tongSoVB,Fond.PaperDigital as tongSoTrang from Fond left join [File] on [File].FondCode = Fond.FondCode AND [File].[State] = 1 left join Document on Document.FileId = [File].UUID WHERE Fond.IsStatisticsVisible = 1 GROUP BY Fond.FondNumber,Fond.FondCode,Fond.FondName order by Fond.FondNumber'); // return this.select('select Fond.FondNumber,Fond.FondCode,Fond.FondName,COUNT(DISTINCT [File].UUID) as tongSoHS,COUNT(Document.UUID) tongSoVB,SUM(Document.PageAmount) as tongSoTrang from Fond inner join MasterFond on MasterFond.MasterFond = Fond.FondCode left join [File] on [File].FondCode = MasterFond.FondCode AND [File].[State] = 1 left join Document on Document.FileId = [File].UUID GROUP BY Fond.FondNumber,Fond.FondCode,Fond.FondName order by Fond.FondNumber'); // return this.select('WITH thongkeHS AS (SELECT [File].UUID,[File].FondCode,fromDoc.soVB,fromDoc.soTrang FROM [File] LEFT JOIN (SELECT FileId,COUNT(UUID) soVB, SUM(PageAmount) soTrang FROM Document GROUP BY FileId) fromDoc ON fromDoc.FileId = [File].UUID WHERE [File].EditedBy is not NULL AND [File].[State] = 1) SELECT FondName,Fond.FondCode,Fond.FondNumber, COUNT(thongkeHS.UUID) tongSoHS, SUM(soVB) tongSoVB, SUM(soTrang) tongSoTrang FROM Fond LEFT JOIN thongkeHS on thongkeHS.FondCode = Fond.FondCode GROUP BY FondName,Fond.FondCode,Fond.FondNumber ORDER BY Fond.FondNumber'); } getUserData(dateCreated) { let condition = ['[File].[State] = 1']; let input = { startDate: moment.utc(dateCreated['startDate'], 'DD/MM/YYYY').isValid() ? moment.utc(dateCreated['startDate'], 'DD/MM/YYYY').toDate() : null, endDate: moment.utc(dateCreated['endDate'], 'DD/MM/YYYY').isValid() ? moment.utc(dateCreated['endDate'], 'DD/MM/YYYY').toDate() : null } if (input['startDate']) condition.push('Document.DateCreated >= @startDate'); if (input['endDate']) condition.push('Document.DateCreated <= @endDate'); return this.select(`WITH thongKeNangSuat AS (SELECT Document.CreatedBy, COUNT(Document.UUID) docCount, SUM(Document.PageAmount) pageCount FROM Document INNER JOIN [File] ON [File].UUID = Document.FileId WHERE ${condition.join(' AND ')} GROUP BY Document.CreatedBy) SELECT UUID,FullName,Username,docCount,pageCount FROM thongKeNangSuat LEFT JOIN Account ON thongKeNangSuat.CreatedBy = Account.UUID`, input); } async getUserDetail(userId, dateCreated) { if (!userId) return []; let condition = ['[File].[State] = 1', 'Document.CreatedBy = @userId']; let input = { userId: userId, startDate: moment.utc(dateCreated['startDate'], 'DD/MM/YYYY').isValid() ? moment.utc(dateCreated['startDate'], 'DD/MM/YYYY').toDate() : null, endDate: moment.utc(dateCreated['endDate'], 'DD/MM/YYYY').isValid() ? moment.utc(dateCreated['endDate'], 'DD/MM/YYYY').toDate() : null }; if (input['startDate']) condition.push('Document.DateCreated >= @startDate'); if (input['endDate']) condition.push('Document.DateCreated <= @endDate'); return await this.select(`SELECT FORMAT(Document.DateCreated, 'yyyy-MM-dd') dateCreated, COUNT(Document.UUID) docCount, SUM(Document.PageAmount) pageCount FROM Document INNER JOIN [File] ON [File].UUID = Document.FileId WHERE ${condition.join(' AND ')} GROUP BY FORMAT(Document.DateCreated, 'yyyy-MM-dd')`, input); } async getServicesData(dateCreated) { let condition = ['[DocReq].[State] = 1']; let input = { startDate: moment.utc(dateCreated['startDate'], 'DD/MM/YYYY').isValid() ? moment.utc(dateCreated['startDate'], 'DD/MM/YYYY').toDate() : null, endDate: moment.utc(dateCreated['endDate'], 'DD/MM/YYYY').isValid() ? moment.utc(dateCreated['endDate'], 'DD/MM/YYYY').toDate() : null }; if (input['startDate']) condition.push('[DocReq].DateCreated >= @startDate'); if (input['endDate']) condition.push('[DocReq].DateCreated <= @endDate'); return await this.select('', input); } } module.exports = BieuDoController;