Facebook
From Diminutive Teal, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 40
  1. public TodoDataDto getTodoData() throws Exception {
  2.         TodoDataDto todoDataDto = new TodoDataDto();
  3.         try (MYSQL mysql = new MYSQL("speedrent")) {
  4.             SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  5.  
  6.             Calendar start = Calendar.getInstance();
  7.             start.set(Calendar.HOUR_OF_DAY, 0);
  8.             start.set(Calendar.MINUTE, 0);
  9.             start.set(Calendar.SECOND, 0);
  10.             String date = df.format(start.getTime());
  11.  
  12.             int totalToday = 0;
  13.             String sql = "SELECT COUNT(*) FROM callcenter_sales WHERE date_created >= '" + date + "'";
  14.             ResultSet rs = mysql.query(sql);
  15.             while (rs.next()) {
  16.                 totalToday = rs.getInt(1);
  17.             }
  18.  
  19.             int ptotalToday = 0;
  20.             sql = "SELECT COUNT(*) FROM property WHERE date_created >= '" + date + "' AND created_by LIKE '%SYSTEM%'";
  21.             rs = mysql.query(sql);
  22.             while (rs.next()) {
  23.                 ptotalToday = rs.getInt(1);
  24.             }
  25.  
  26.             start.add(Calendar.DAY_OF_YEAR, -1);
  27.  
  28.             Calendar end = Calendar.getInstance();
  29.             end.add(Calendar.DAY_OF_YEAR, -1);
  30.  
  31.             String startDate = df.format(start.getTime());
  32.             String endDate = df.format(end.getTime());
  33.  
  34.             int totalYesterday = 0;
  35.             sql = "SELECT COUNT(*) FROM callcenter_sales WHERE date_created >= '" + startDate + "' AND date_created <= '" + endDate + "'";
  36.             rs = mysql.query(sql);
  37.             while (rs.next()) {
  38.                 totalYesterday = rs.getInt(1);
  39.             }
  40.  
  41.             int ptotalYesterday = 0;
  42.             sql = "SELECT COUNT(*) FROM property WHERE date_created >= '" + startDate + "' AND date_created <= '" + endDate + "' AND created_by LIKE '%SYSTEM%'";
  43.             rs = mysql.query(sql);
  44.             while (rs.next()) {
  45.                 ptotalYesterday = rs.getInt(1);
  46.             }
  47.  
  48.             start = Calendar.getInstance();
  49.             start.set(Calendar.HOUR_OF_DAY, 0);
  50.             start.set(Calendar.MINUTE, 0);
  51.             start.set(Calendar.SECOND, 0);
  52.             start.add(Calendar.DAY_OF_YEAR, -6);
  53.  
  54.             startDate = df.format(start.getTime());
  55.  
  56.             int totalLastWeek = 0;
  57.             sql = "SELECT COUNT(*) FROM callcenter_sales WHERE date_created >= '" + startDate + "'";
  58.             rs = mysql.query(sql);
  59.             while (rs.next()) {
  60.                 totalLastWeek = rs.getInt(1);
  61.             }
  62.  
  63.             int ptotalLastWeek = 0;
  64.             sql = "SELECT COUNT(*) FROM property WHERE date_created >= '" + startDate + "' AND created_by LIKE '%SYSTEM%'";
  65.             rs = mysql.query(sql);
  66.             while (rs.next()) {
  67.                 ptotalLastWeek = rs.getInt(1);
  68.             }
  69.  
  70.             start = Calendar.getInstance();
  71.             start.set(Calendar.HOUR_OF_DAY, 0);
  72.             start.set(Calendar.MINUTE, 0);
  73.             start.set(Calendar.SECOND, 0);
  74.             start.set(Calendar.DAY_OF_MONTH, 1);
  75.  
  76.             int day = Calendar
  77.                     .getInstance()
  78.                     .get(Calendar.DAY_OF_MONTH) + 1;
  79.  
  80.             startDate = df.format(start.getTime());
  81.  
  82.             int totalLastMonth = 0;
  83.             sql = "SELECT COUNT(*) FROM callcenter_sales WHERE date_created >= '" + startDate + "'";
  84.             rs = mysql.query(sql);
  85.             while (rs.next()) {
  86.                 totalLastMonth = rs.getInt(1);
  87.             }
  88.  
  89.             int ptotalLastMonth = 0;
  90.             sql = "SELECT COUNT(*) FROM property WHERE date_created >= '" + startDate + "' AND created_by LIKE '%SYSTEM%'";
  91.             rs = mysql.query(sql);
  92.             while (rs.next()) {
  93.                 ptotalLastMonth = rs.getInt(1);
  94.             }
  95.  
  96.             Calendar c = Calendar.getInstance();
  97.             int hour = c.get(Calendar.HOUR_OF_DAY) + 1;
  98.  
  99.             DecimalFormat decimalFormat = new DecimalFormat("#.00");
  100.             SimpleDateFormat format = new SimpleDateFormat("dd MMM hh:mmaa");
  101.  
  102.             String data = "";
  103.             for (int i = 0; i < 30; i++) {
  104.                 Calendar cal = Calendar.getInstance();
  105.                 cal.set(Calendar.HOUR_OF_DAY, 0);
  106.                 cal.set(Calendar.MINUTE, 0);
  107.                 cal.set(Calendar.SECOND, 0);
  108.                 cal.add(Calendar.DAY_OF_YEAR, -1 * i);
  109.  
  110.                 long time = cal
  111.                         .getTime()
  112.                         .getTime();
  113.  
  114.                 String sd = df.format(cal.getTime());
  115.  
  116.                 cal.set(Calendar.HOUR_OF_DAY, 0);
  117.                 cal.set(Calendar.MINUTE, 0);
  118.                 cal.set(Calendar.SECOND, 0);
  119.                 cal.add(Calendar.DAY_OF_YEAR, 1);
  120.  
  121.                 String ed = df.format(cal.getTime());
  122.  
  123.                 sql = "SELECT COUNT(*) FROM callcenter_sales WHERE date_created >= '" + sd + "' AND date_created < '" + ed + "'";
  124.                 rs = mysql.query(sql);
  125.                 while (rs.next()) {
  126.                     int count = rs.getInt(1);
  127.                     data += "cr.push([" + time + ", " + count + "]);n";
  128.                 }
  129.             }
  130.  
  131.             for (int i = 0; i < 30; i++) {
  132.                 Calendar cal = Calendar.getInstance();
  133.                 cal.set(Calendar.HOUR_OF_DAY, 0);
  134.                 cal.set(Calendar.MINUTE, 0);
  135.                 cal.set(Calendar.SECOND, 0);
  136.                 cal.add(Calendar.DAY_OF_YEAR, -1 * i);
  137.  
  138.                 long time = cal
  139.                         .getTime()
  140.                         .getTime();
  141.  
  142.                 String sd = df.format(cal.getTime());
  143.  
  144.                 cal.set(Calendar.HOUR_OF_DAY, 0);
  145.                 cal.set(Calendar.MINUTE, 0);
  146.                 cal.set(Calendar.SECOND, 0);
  147.                 cal.add(Calendar.DAY_OF_YEAR, 1);
  148.  
  149.                 String ed = df.format(cal.getTime());
  150.  
  151.                 sql = "SELECT COUNT(*) FROM property WHERE date_created >= '" + sd + "' AND date_created < '" + ed + "' AND created_by LIKE '%SYSTEM%'";
  152.                 rs = mysql.query(sql);
  153.                 while (rs.next()) {
  154.                     int count = rs.getInt(1);
  155.                     data += "cl.push([" + time + ", " + count + "]);n";
  156.                 }
  157.             }
  158.  
  159.             todoDataDto.lastUpdate = format.format(new Date());
  160.             todoDataDto.countToday = totalToday + "";
  161.             todoDataDto.avgToday = (decimalFormat.format((double) totalToday / (double) hour)) + "";
  162.             todoDataDto.countYesterday = totalYesterday + "";
  163.             todoDataDto.avgYesterday = (decimalFormat.format((double) totalYesterday / (double) hour)) + "";
  164.             todoDataDto.countLastWeek = totalLastWeek + "";
  165.             todoDataDto.avgLastWeek = (decimalFormat.format((double) totalLastWeek / 7.0)) + "";
  166.             todoDataDto.countLastMonth = totalLastMonth + "";
  167.             todoDataDto.avgLastMonth = (decimalFormat.format((double) totalLastMonth / (double) day)) + "";
  168.             todoDataDto.pcountToday = ptotalToday + "";
  169.             todoDataDto.pavgToday = (decimalFormat.format((double) ptotalToday / (double) hour)) + "";
  170.             todoDataDto.pcountYesterday = ptotalYesterday + "";
  171.             todoDataDto.pavgYesterday = (decimalFormat.format((double) ptotalYesterday / (double) hour)) + "";
  172.             todoDataDto.pcountLastWeek = ptotalLastWeek + "";
  173.             todoDataDto.pavgLastWeek = (decimalFormat.format((double) ptotalLastWeek / 7.0)) + "";
  174.             todoDataDto.pcountLastMonth = ptotalLastMonth + "";
  175.             todoDataDto.pavgLastMonth = (decimalFormat.format((double) ptotalLastMonth / (double) day)) + "";
  176.             todoDataDto.data = data;
  177.  
  178.         } catch (Exception ex) {
  179.             LOGGER.error(ex.getMessage(), ex);
  180.         }
  181.         return todoDataDto;
  182.     }