Ver código fonte

update api

tags/Baseline_30082024_BACKEND_UAT
Mac\David 1 ano atrás
pai
commit
939909579a
1 arquivos alterados com 78 adições e 29 exclusões
  1. +78
    -29
      src/main/java/com/ffii/tsms/modules/data/service/DashboardService.kt

+ 78
- 29
src/main/java/com/ffii/tsms/modules/data/service/DashboardService.kt Ver arquivo

@@ -356,40 +356,89 @@ open class DashboardService(
fun searchTeamConsumption(args: Map<String, Any>): List<Map<String, Any>>
{
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)


Carregando…
Cancelar
Salvar