Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.96 KB | None | 0 0
  1. public List listarPlanClase(String idAnoLectivo, String idMes, String idAsignaturaGrado, String idDocente, String idCurso) {
  2.  
  3.         IDefinitionConnection con = null;
  4.  
  5.         List listaSemanasPeriodo = new ArrayList();
  6.         List listaDias = new ArrayList();
  7.  
  8.         PlanClaseDAO planClaseDAO = null;
  9.         PlanClaseDiaDAO planClaseDiaDAO = null;
  10.  
  11.         PlanClaseVO planClaseVO = null;
  12.         PlanClaseDiaVO planClaseDiaVO = null;
  13.  
  14.         Map mapaParametros = new HashMap();
  15.         mapaParametros.put("idAnoLectivo", idAnoLectivo);
  16.         mapaParametros.put("idMes", idMes);
  17.         mapaParametros.put("idAsignaturaGrado", idAsignaturaGrado);
  18.         mapaParametros.put("idDocente", idDocente);
  19.         mapaParametros.put("idCurso", idCurso);
  20.  
  21.         try {
  22.             con = new DefinitionConnectionAcademico();
  23.             planClaseDAO = new PlanClaseDAO(con);
  24.             planClaseDiaDAO = new PlanClaseDiaDAO(con);
  25.  
  26.             Object[] rangoFecha = null;
  27.             Object[] rangoDia = null;
  28.             int numeroSemana = 1;
  29.             Calendar fechaInicio = Calendar.getInstance();
  30.             fechaInicio.set(Integer.parseInt(idAnoLectivo), Integer.parseInt(idMes), 0);
  31.             fechaInicio.set(fechaInicio.get(Calendar.YEAR),
  32.                     fechaInicio.get(Calendar.MONTH),
  33.                     fechaInicio.getActualMinimum(Calendar.DAY_OF_MONTH),
  34.                     0,
  35.                     0,
  36.                     0);
  37.  
  38.             Calendar fechaFin = Calendar.getInstance();
  39.             fechaFin.set(Integer.parseInt(idAnoLectivo), Integer.parseInt(idMes), 0);
  40.             fechaFin.set(fechaFin.get(Calendar.YEAR),
  41.                     fechaFin.get(Calendar.MONTH),
  42.                     fechaFin.getActualMaximum(Calendar.DAY_OF_MONTH),
  43.                     0,
  44.                     0,
  45.                     0);
  46.  
  47.             for (Calendar fecha = (Calendar) fechaInicio.clone(); (fecha.before(fechaFin) || fecha.equals(fechaFin)); fecha.add(Calendar.DATE, 7)) {
  48.                 rangoFecha = new Object[5];                
  49.                
  50.                 Calendar fechaInicioSemana = Format.parseCalendar(UtilFecha.obtenerInicioSemana(fecha, Constantes.FORMATO_D_M_Y), Constantes.FORMATO_D_M_Y);
  51.                 //fecha del inicio de la semana
  52.                 rangoFecha[0] = fechaInicioSemana;
  53.  
  54.                 Calendar fechafinSemana = Format.parseCalendar(UtilFecha.obtenerInicioSemana(fecha, Constantes.FORMATO_D_M_Y), Constantes.FORMATO_D_M_Y);
  55.                 fechafinSemana.add(Calendar.DATE, 5);
  56.                 //fecha del fin de semana
  57.                 rangoFecha[1] = fechafinSemana;
  58.                
  59.                 /*Calendar fechaCalculoSemana = (Calendar) fecha.clone();
  60.                 fechaCalculoSemana.setMinimalDaysInFirstWeek(1);
  61.                 numeroSemana = fechaCalculoSemana.get(Calendar.WEEK_OF_MONTH);
  62.                 **/
  63.                 mapaParametros.put("numeroSemana", numeroSemana);
  64.                
  65.                 planClaseVO = (PlanClaseVO) planClaseDAO.consultar(mapaParametros);
  66.                 if (planClaseVO == null) {
  67.                     planClaseVO = new PlanClaseVO();
  68.                     planClaseVO.setIdDocente(idDocente);
  69.                     planClaseVO.setIdAsignaturaGrado(idAsignaturaGrado);
  70.                     planClaseVO.setIdAnoLectivo(idAnoLectivo);
  71.                     planClaseVO.setIdCurso(idCurso);
  72.                     planClaseVO.setIdMes(idMes);
  73.                     planClaseVO.setSemana(String.valueOf(numeroSemana));
  74.                    
  75.                 }
  76.  
  77.                 for (Calendar fechaDia = (Calendar) fechaInicioSemana.clone(); fechaDia.before((Calendar) fechafinSemana.clone()); fechaDia.add(Calendar.DATE, 1)) {
  78.                     if (UtilFecha.obtenerNumeroDiaSemana(fechaDia, Format.printString("Horario")) != 6 && UtilFecha.obtenerNumeroDiaSemana(fechaDia, Format.printString("Horario")) != 7) {
  79.                        
  80.                         if (UtilFecha.mayorIgualQue(fechaDia, fechaInicio) && UtilFecha.menorIgualQue(fechaDia, fechaFin)) {
  81.                             rangoDia = new Object[6];
  82.                             //día
  83.                             rangoDia[0] = Format.lPad(String.valueOf(fechaDia.get(Calendar.DATE)), 2, '0');                            
  84.                             //fecha del día
  85.                             rangoDia[1] = Format.formatCalendar(fechaDia, Constantes.FORMATO_D_M_Y);
  86.                             //numero del día
  87.                             rangoDia[2] = String.valueOf(UtilFecha.obtenerNumeroDiaSemana(fechaDia, Format.printString("Horario")));
  88.                             //habilitado
  89.                             rangoDia[3] = "";
  90.                             if (!Format.isEmptyString(planClaseVO.getIdPlanClase())) {
  91.                                 planClaseDiaVO = (PlanClaseDiaVO) planClaseDiaDAO.consultarPlanClaseDia(planClaseVO.getIdPlanClase(), fechaDia);
  92.                             } else {
  93.                                 planClaseDiaVO = new PlanClaseDiaVO();
  94.                                 planClaseDiaVO.setFecha((Calendar)fechaDia.clone());
  95.                             }
  96.                             //PlanClaseDia
  97.                             rangoDia[4] = planClaseDiaVO;
  98.                             //nombre día
  99.                             rangoDia[5] = UtilFecha.nombreDiaSemana(UtilFecha.obtenerNumeroDiaSemana(fechaDia, Format.printString("Calendar")));
  100.                             listaDias.add(rangoDia);  
  101.                         } else {
  102.                             /*//fecha del día
  103.                              rangoDia[1] = Format.formatCalendar(fechaDia, Constantes.FORMATO_D_M_Y);
  104.                              //numero del día
  105.                              rangoDia[2] = String.valueOf(UtilFecha.obtenerNumeroDiaSemana(fechaDia, Format.printString("Horario")));
  106.                              //deshabilitado
  107.                              rangoDia[3] = "OFF";
  108.                              //PlanClaseDia
  109.                              rangoDia[4] = null;
  110.                              **/
  111.                         }
  112.                      
  113.                     }
  114.                 }
  115.                 //lista de los dias de la semana
  116.                 rangoFecha[2] = listaDias;
  117.                 // numero semana                            
  118.                 rangoFecha[3] = numeroSemana;
  119.                 //PlanClase
  120.                 rangoFecha[4] = planClaseVO;
  121.                
  122.                 if(!listaDias.isEmpty()){
  123.                     numeroSemana++;
  124.                     listaSemanasPeriodo.add(rangoFecha);
  125.                 }
  126.                 listaDias = new ArrayList();
  127.                
  128.             }
  129.         } catch (Exception e) {
  130.             System.out.println(" :: Gnosoft :: MediadorHorarios :: listarPlanClase :: " + e.getMessage());
  131.             e.printStackTrace();
  132.  
  133.         } finally {
  134.             if (con != null) {
  135.                 con.close();
  136.             }
  137.         }
  138.  
  139.         return listaSemanasPeriodo;
  140.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement