From 939909579a13a89f18cfc6bb132f040b659113db Mon Sep 17 00:00:00 2001 From: "Mac\\David" Date: Sun, 7 Jul 2024 20:37:26 +0800 Subject: [PATCH] update api --- .../modules/data/service/DashboardService.kt | 107 +++++++++++++----- 1 file changed, 78 insertions(+), 29 deletions(-) diff --git a/src/main/java/com/ffii/tsms/modules/data/service/DashboardService.kt b/src/main/java/com/ffii/tsms/modules/data/service/DashboardService.kt index 120bad3..e9c8b73 100644 --- a/src/main/java/com/ffii/tsms/modules/data/service/DashboardService.kt +++ b/src/main/java/com/ffii/tsms/modules/data/service/DashboardService.kt @@ -356,40 +356,89 @@ open class DashboardService( fun searchTeamConsumption(args: Map): List> { val sql = StringBuilder( - "select" - + " ROW_NUMBER() OVER (ORDER BY te.code, s.name, project.budgetedManhour) AS id," - + " te.code as team," - + " s.name as teamLead," - + " project.budgetedManhour as budgetedManhour," - + " COALESCE (sum(t.normalConsumed) + sum(t.otConsumed),0) as spentManhour," - + " COALESCE (project.budgetedManhour - sum(t.normalConsumed) - sum(t.otConsumed),0) as remainedManhour," - + " coalesce (round(((sum(t.normalConsumed) + sum(t.otConsumed))/project.budgetedManhour)*100,2),0) as manhourConsumptionPercentage," - + " case" - + " when COALESCE (project.budgetedManhour - sum(t.normalConsumed) - sum(t.otConsumed),0) > 0 then 0" - + " when COALESCE (project.budgetedManhour - sum(t.normalConsumed) - sum(t.otConsumed),0) <= 0 then 1" - + " end as alert" - + " from team te" - + " left join project p on p.teamLead = te.teamLead" - + " left join project_task pt on p.id = pt.project_id" - + " left join timesheet t on pt.id = t.projectTaskId" - + " left join staff s on te.teamLead = s.id" - + " left join (" - + " select sum(p2.totalManhour) as budgetedManhour" - + " from team t2" - + " left join project p2 on p2.teamLead = t2.teamLead" - + " where p2.teamLead in (:teamIds)" - + " ) as project on 1 = 1" - + " where p.teamLead in (:teamIds)" - + " and p.status not in ('Pending to Start','Completed','Deleted')" - + " group by te.code, s.name, project.budgetedManhour" +// "select" +// + " ROW_NUMBER() OVER (ORDER BY te.code, s.name, project.budgetedManhour) AS id," +// + " te.code as team," +// + " s.name as teamLead," +// + " project.budgetedManhour as budgetedManhour," +// + " COALESCE (sum(t.normalConsumed) + sum(t.otConsumed),0) as spentManhour," +// + " COALESCE (project.budgetedManhour - sum(t.normalConsumed) - sum(t.otConsumed),0) as remainedManhour," +// + " coalesce (round(((sum(t.normalConsumed) + sum(t.otConsumed))/project.budgetedManhour)*100,2),0) as manhourConsumptionPercentage," +// + " case" +// + " when COALESCE (project.budgetedManhour - sum(t.normalConsumed) - sum(t.otConsumed),0) > 0 then 0" +// + " when COALESCE (project.budgetedManhour - sum(t.normalConsumed) - sum(t.otConsumed),0) <= 0 then 1" +// + " end as alert" +// + " from team te" +// + " left join project p on p.teamLead = te.teamLead" +// + " left join project_task pt on p.id = pt.project_id" +// + " left join timesheet t on pt.id = t.projectTaskId" +// + " left join staff s on te.teamLead = s.id" +// + " left join (" +// + " select sum(p2.totalManhour) as budgetedManhour" +// + " from team t2" +// + " left join project p2 on p2.teamLead = t2.teamLead" +// + " where p2.teamLead in (:teamIds)" +// + " ) as project on 1 = 1" +// + " where p.teamLead in (:teamIds)" +// + " and p.status not in ('Pending to Start','Completed','Deleted')" +// + " group by te.code, s.name, project.budgetedManhour" + "select" + + " ROW_NUMBER() OVER (ORDER BY p.id, p.code, p.name, te.code, s.name, p.totalManhour, milestonePayment.comingPaymentMilestone) AS id," + + " p.id as id," + + " p.id as projectId," + + " p.code as projectCode," + + " p.name as projectName," + + " te.code as team," + + " s.name as teamLead," + + " GROUP_CONCAT(DISTINCT tg.name ORDER BY tg.name) as expectedStage," + + " p.totalManhour as budgetedManhour," + + " COALESCE (sum(t.normalConsumed) + sum(t.otConsumed),0) as spentManhour," + + " COALESCE (p.totalManhour - sum(t.normalConsumed) - sum(t.otConsumed),0) as remainedManhour," + + " coalesce (round(((sum(t.normalConsumed) + sum(t.otConsumed))/p.totalManhour)*100,2),0) as manhourConsumptionPercentage," + + " COALESCE (DATE_FORMAT(milestonePayment.comingPaymentMilestone, '%Y-%m-%d'),'NA') as comingPaymentMilestone," + + " case" + + " when COALESCE (p.totalManhour - sum(t.normalConsumed) - sum(t.otConsumed),0) > 0 then 0" + + " when COALESCE (p.totalManhour - sum(t.normalConsumed) - sum(t.otConsumed),0) <= 0 then 1" + + " end as alert" + + " from project p" + + " left join project_task pt on p.id = pt.project_id" + + " left join timesheet t on pt.id = t.projectTaskId" + + " left join team te on p.teamLead = te.teamLead" + + " left join staff s on te.teamLead = s.id" + + " left join milestone m on p.id = m.projectId and curdate() >= m.startDate and curdate() <= m.endDate" + + " left join task_group tg on m.taskGroupId = tg.id" + + " left join (" + + " SELECT pid, MIN(comingPaymentMilestone) AS comingPaymentMilestone" + + " FROM (" + + " SELECT p.id AS pid, mp.date AS comingPaymentMilestone" + + " FROM project p" + + " LEFT JOIN milestone m ON p.id = m.projectId" + + " LEFT JOIN milestone_payment mp ON m.id = mp.milestoneId" + + " WHERE p.teamLead in (:teamIds)" + + " AND p.status NOT IN ('Pending to Start', 'Completed', 'Deleted')" + + " AND mp.date >= CURDATE()" + + " ) AS subquery" + + " GROUP BY pid" + + " ORDER BY comingPaymentMilestone ASC" + + " ) milestonePayment on milestonePayment.pid = p.id" + + " where p.teamLead in (:teamIds)" + + " and p.status not in ('Pending to Start','Completed','Deleted')" + + " group by p.id, p.code, p.name, te.code, s.name, p.totalManhour, milestonePayment.comingPaymentMilestone" ) +// if (args["tableSorting"] == "ProjectName") { +// sql.append(" ORDER BY te.code ASC") +// } else if (args["tableSorting"] == "PercentageASC") { +// sql.append(" ORDER BY coalesce (round(((sum(t.normalConsumed) + sum(t.otConsumed))/project.budgetedManhour)*100,2),0) asc") +// } else if (args["tableSorting"] == "PercentageDESC") { +// sql.append(" ORDER BY coalesce (round(((sum(t.normalConsumed) + sum(t.otConsumed))/project.budgetedManhour)*100,2),0) desc") +// } if (args["tableSorting"] == "ProjectName") { - sql.append(" ORDER BY te.code ASC") + sql.append(" ORDER BY p.name ASC") } else if (args["tableSorting"] == "PercentageASC") { - sql.append(" ORDER BY coalesce (round(((sum(t.normalConsumed) + sum(t.otConsumed))/project.budgetedManhour)*100,2),0) asc") + sql.append(" ORDER BY coalesce (round(((sum(t.normalConsumed) + sum(t.otConsumed))/p.totalManhour)*100,2),0) asc") } else if (args["tableSorting"] == "PercentageDESC") { - sql.append(" ORDER BY coalesce (round(((sum(t.normalConsumed) + sum(t.otConsumed))/project.budgetedManhour)*100,2),0) desc") + sql.append(" ORDER BY coalesce (round(((sum(t.normalConsumed) + sum(t.otConsumed))/p.totalManhour)*100,2),0) desc") } return jdbcDao.queryForList(sql.toString(), args)