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 f29b702..47a7b4b 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 @@ -1307,26 +1307,54 @@ open class DashboardService( } fun monthlyActualTeamTotalManhoursSpent(args: Map): List> { val sql = StringBuilder( - " WITH RECURSIVE date_series AS (" - + " SELECT DATE_FORMAT(:startdate, '%Y-%m-01') AS month" - + " UNION ALL" - + " SELECT DATE_FORMAT(DATE_ADD(month, INTERVAL 1 MONTH), '%Y-%m-01')" - + " FROM date_series" - + " WHERE month < DATE_FORMAT(:enddate, '%Y-%m-01')" - + " )" - + " SELECT" - + " ds.month AS yearMonth," - + " IFNULL(SUM(IFNULL(ts.normalConsumed, 0) + IFNULL(ts.otConsumed, 0)), 0) AS 'TotalManhourConsumed'," - + " :teamId AS teamId" - + " FROM date_series ds" - + " LEFT JOIN staff st" - + " on st.teamId = :teamId" - + " LEFT JOIN timesheet ts" - + " ON DATE_FORMAT(ts.recordDate, '%Y-%m') = DATE_FORMAT(ds.month, '%Y-%m') and ts.staffID = st.id" - + " WHERE ds.month BETWEEN DATE_FORMAT(:startdate, '%Y-%m-01') AND DATE_FORMAT(:enddate, '%Y-%m-01')" - + " and ts.recordDate BETWEEN DATE_FORMAT(:startdate, '%Y-%m-%d') AND DATE_FORMAT(DATE_ADD(:startdate, INTERVAL 6 DAY), '%Y-%m-%d')" - + " GROUP BY ds.month, st.teamId" - + " ORDER BY ds.month" +// " WITH RECURSIVE date_series AS (" +// + " SELECT DATE_FORMAT(:startdate, '%Y-%m-01') AS month" +// + " UNION ALL" +// + " SELECT DATE_FORMAT(DATE_ADD(month, INTERVAL 1 MONTH), '%Y-%m-01')" +// + " FROM date_series" +// + " WHERE month < DATE_FORMAT(:enddate, '%Y-%m-01')" +// + " )" +// + " SELECT" +// + " ds.month AS yearMonth," +// + " IFNULL(SUM(IFNULL(ts.normalConsumed, 0) + IFNULL(ts.otConsumed, 0)), 0) AS 'TotalManhourConsumed'," +// + " :teamId AS teamId" +// + " FROM date_series ds" +// + " LEFT JOIN staff st" +// + " on st.teamId = :teamId" +// + " LEFT JOIN timesheet ts" +// + " ON DATE_FORMAT(ts.recordDate, '%Y-%m') = DATE_FORMAT(ds.month, '%Y-%m') and ts.staffID = st.id" +// + " WHERE ds.month BETWEEN DATE_FORMAT(:startdate, '%Y-%m-01') AND DATE_FORMAT(:enddate, '%Y-%m-01')" +// + " and ts.recordDate BETWEEN DATE_FORMAT(:startdate, '%Y-%m-01') AND DATE_FORMAT(:enddate, '%Y-%m-01')" +// + " GROUP BY ds.month, st.teamId" +// + " ORDER BY ds.month" + "WITH RECURSIVE date_series AS (" + + " SELECT DATE_FORMAT(:startdate, '%Y-%m-01') AS month" + + " UNION ALL" + + " SELECT DATE_FORMAT(DATE_ADD(month, INTERVAL 1 MONTH), '%Y-%m-01')" + + " FROM date_series" + + " WHERE month < DATE_FORMAT(:enddate, '%Y-%m-01')" + + " )" + + " SELECT" + + " ds.month AS yearMonth," + + " COALESCE(SUM(COALESCE(ts.normalConsumed, 0) + COALESCE(ts.otConsumed, 0)), 0) AS 'TotalManhourConsumed'," + + " :teamId AS teamId" + + " FROM date_series ds" + + " LEFT JOIN (" + + " SELECT" + + " DATE_FORMAT(ts.recordDate, '%Y-%m-01') AS recordMonth," + + " ts.staffID," + + " SUM(ts.normalConsumed) AS normalConsumed," + + " SUM(ts.otConsumed) AS otConsumed" + + " FROM staff st" + + " LEFT JOIN timesheet ts" + + " on ts.staffID = st.id" + + " WHERE ts.recordDate BETWEEN DATE_FORMAT(:startdate, '%Y-%m-01') AND LAST_DAY(DATE_FORMAT(:enddate, '%Y-%m-%d'))" + + " and st.teamId = :teamId" + + " GROUP BY DATE_FORMAT(ts.recordDate, '%Y-%m-01'), staffID" + + " ) ts ON ds.month = ts.recordMonth" + + " GROUP BY ds.month" + + " ORDER BY ds.month;" + ) return jdbcDao.queryForList(sql.toString(), args) @@ -1365,26 +1393,54 @@ open class DashboardService( } fun weeklyActualTeamTotalManhoursSpent(args: Map): List> { val sql = StringBuilder( - "WITH RECURSIVE date_series AS (" - + " SELECT DATE_FORMAT(:startdate, '%Y-%m-%d') AS day" - + " UNION ALL" - + " SELECT DATE_FORMAT(DATE_ADD(day, INTERVAL 1 DAY), '%Y-%m-%d')" - + " FROM date_series" - + " WHERE day < DATE_FORMAT(DATE_ADD(:startdate, INTERVAL 6 DAY), '%Y-%m-%d')" - + " )" - + " SELECT" - + " ds.day AS yearMonth," - + " IFNULL(SUM(IFNULL(ts.normalConsumed, 0) + IFNULL(ts.otConsumed, 0)), 0) AS 'TotalManhourConsumed'," - + " :teamId AS teamId" - + " FROM date_series ds" - + " LEFT JOIN staff st" - + " on st.teamId = :teamId" - + " LEFT JOIN timesheet ts" - + " ON DATE_FORMAT(ts.recordDate, '%m-%d') = DATE_FORMAT(ds.day, '%m-%d') and ts.staffID = st.id" - + " WHERE ds.day BETWEEN DATE_FORMAT(:startdate, '%Y-%m-%d') AND DATE_FORMAT(DATE_ADD(:startdate, INTERVAL 6 DAY), '%Y-%m-%d')" - + " and ts.recordDate BETWEEN DATE_FORMAT(:startdate, '%Y-%m-%d') AND DATE_FORMAT(DATE_ADD(:startdate, INTERVAL 6 DAY), '%Y-%m-%d')" - + " GROUP BY ds.day, st.teamId" - + " ORDER BY ds.day" +// "WITH RECURSIVE date_series AS (" +// + " SELECT DATE_FORMAT(:startdate, '%Y-%m-%d') AS day" +// + " UNION ALL" +// + " SELECT DATE_FORMAT(DATE_ADD(day, INTERVAL 1 DAY), '%Y-%m-%d')" +// + " FROM date_series" +// + " WHERE day < DATE_FORMAT(DATE_ADD(:startdate, INTERVAL 6 DAY), '%Y-%m-%d')" +// + " )" +// + " SELECT" +// + " ds.day AS yearMonth," +// + " IFNULL(SUM(IFNULL(ts.normalConsumed, 0) + IFNULL(ts.otConsumed, 0)), 0) AS 'TotalManhourConsumed'," +// + " :teamId AS teamId" +// + " FROM date_series ds" +// + " LEFT JOIN staff st" +// + " on st.teamId = :teamId" +// + " LEFT JOIN timesheet ts" +// + " ON DATE_FORMAT(ts.recordDate, '%m-%d') = DATE_FORMAT(ds.day, '%m-%d') and ts.staffID = st.id" +// + " WHERE ds.day BETWEEN DATE_FORMAT(:startdate, '%Y-%m-%d') AND DATE_FORMAT(DATE_ADD(:startdate, INTERVAL 6 DAY), '%Y-%m-%d')" +// + " and ts.recordDate BETWEEN DATE_FORMAT(:startdate, '%Y-%m-%d') AND DATE_FORMAT(DATE_ADD(:startdate, INTERVAL 6 DAY), '%Y-%m-%d')" +// + " GROUP BY ds.day, st.teamId" +// + " ORDER BY ds.day" + "WITH RECURSIVE date_series AS (" + + " SELECT DATE_FORMAT(:startdate, '%Y-%m-%d') AS day" + + " UNION ALL" + + " SELECT DATE_FORMAT(DATE_ADD(day, INTERVAL 1 DAY), '%Y-%m-%d')" + + " FROM date_series" + + " WHERE day < DATE_FORMAT(DATE_ADD(:startdate, INTERVAL 6 DAY), '%Y-%m-%d')" + + " )" + + " SELECT" + + " ds.day AS yearMonth," + + " COALESCE(SUM(COALESCE(ts.normalConsumed, 0) + COALESCE(ts.otConsumed, 0)), 0) AS 'TotalManhourConsumed'," + + " :teamId AS teamId" + + " FROM date_series ds" + + " LEFT JOIN (" + + " SELECT" + + " DATE_FORMAT(ts.recordDate, '%Y-%m-%d') AS recordDate," + + " ts.staffID," + + " SUM(ts.normalConsumed) AS normalConsumed," + + " SUM(ts.otConsumed) AS otConsumed" + + " FROM staff st" + + " LEFT JOIN timesheet ts" + + " on ts.staffID = st.id" + + " WHERE ts.recordDate BETWEEN DATE_FORMAT(:startdate, '%Y-%m-%d') AND DATE_FORMAT(DATE_ADD(:startdate, INTERVAL 6 DAY), '%Y-%m-%d')" + + " and st.teamId = :teamId" + + " GROUP BY DATE_FORMAT(ts.recordDate, '%Y-%m-%d'), ts.staffID" + + " ) ts ON ds.day = ts.recordDate" + + " GROUP BY ds.day" + + " ORDER BY ds.day;" + ) return jdbcDao.queryForList(sql.toString(), args)