Datasets:

ArXiv:
License:
File size: 3,486 Bytes
c574d3a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package model.dao;

import beans.Reporte;
import beans.ReporteDictamen;
import beans.ReporteResumido;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import model.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;

/**
 *
 * @author Juan Carlos
 */
public class ReporteDAO {

    public static int agregarReporte(Reporte reporte) {
        int res = 0;
        SqlSession conn = null;
        res = validarReporte(reporte);
        System.out.println(res);
        if (res != 0) {
            return res;
        }
        try {
            conn = MyBatisUtils.getSession();
            res = conn.update("Reporte.registrar", reporte);
            conn.commit();
            if (res < 0) {
                return -2;
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            if (conn != null) {
                conn.close();
            }
        }
        return res;
    }
    
    public static ReporteDictamen getDetallesReporte(int idReporte){
        ReporteDictamen reporte = new ReporteDictamen();
        SqlSession conn = null;
        try {
            conn = MyBatisUtils.getSession();
            List<ReporteDictamen> reportes;
            reportes= conn.selectList("Reporte.obtenerDetallesReporte", idReporte);
            if(!reportes.isEmpty()){
                reporte = reportes.get(0);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }finally{
            if(conn!=null){
                conn.close();
            }
        }
        
        return reporte;
    }

    public static List<ReporteResumido> getReportes(int idConductor) {
        List<ReporteResumido> list = new ArrayList<>();
        SqlSession conn = null;
        try {
            List<ReporteResumido>listAux = new ArrayList<>();
            conn = MyBatisUtils.getSession();
            list = conn.selectList("Reporte.buscarReportes", idConductor);
            List<Integer>arrayIds = new ArrayList<>();
            for(ReporteResumido reporte:list){
                int id = reporte.getIdReporte();
                if(!arrayIds.contains(id)){
                    listAux.add(reporte);
                    arrayIds.add(id);
                }
            }
            list = listAux;
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            if (conn != null) {
                conn.close();
            }
        }
        return list;
    }

    private static int validarReporte(Reporte reporte) {
        int res = 0;
        if (reporte.getLatitud() == null
                || reporte.getLatitud().toString().trim().isEmpty()) {
            return -1;
        }
        if (reporte.getLongitud() == null
                || reporte.getLongitud().toString().trim().isEmpty()) {
            return -1;
        }
        if (reporte.getDescripcion() == null
                || reporte.getDescripcion().toString().trim().isEmpty()) {
            return -1;
        }
        if (reporte.getPlacasVehiculos() == null
                || reporte.getPlacasVehiculos().toString().trim().isEmpty()) {
            return -1;
        }
        if (reporte.getIdConductor() == 0) {
            return -1;
        }
        return res;
    }
}