Browse Source

统计数据

XMTT 6 years ago
parent
commit
3638fa03fe

+ 29 - 4
src/main/java/com/ekexiu/project/platform/views/handler/db/TimeLogHandler.java

80
            ps.setString(2, id);
80
            ps.setString(2, id);
81
            ps.setString(3, day);
81
            ps.setString(3, day);
82
            ps.setString(4, source);
82
            ps.setString(4, source);
83
            int p = ps.executeUpdate();
84
            ps = this.con.prepareStatement(this.updateSumSql);
83
            return ps.executeUpdate()==1;
84
        } finally {
85
            try {
86
                ps.close();
87
            } catch (Exception e) {
88
            }
89
        }
90
    }
91
92
    private boolean updateSum(String id, int pv) throws SQLException {
93
        PreparedStatement ps =this.con.prepareStatement(this.updateSumSql);
94
95
        try {
85
            ps.setInt(1, pv);
96
            ps.setInt(1, pv);
86
            ps.setString(2, id);
97
            ps.setString(2, id);
87
            return p==1&&ps.executeUpdate() == 1;
98
            return ps.executeUpdate() == 1;
88
        } finally {
99
        } finally {
89
            try {
100
            try {
90
                ps.close();
101
                ps.close();
101
            ps.setString(3, day);
112
            ps.setString(3, day);
102
            ps.setString(4, source);
113
            ps.setString(4, source);
103
            ps.executeUpdate();
114
            ps.executeUpdate();
104
            ps = this.con.prepareStatement(this.insertSumSql);
115
        } finally {
116
            try {
117
                ps.close();
118
            } catch (Exception e) {
119
            }
120
        }
121
122
    }
123
124
    public void insertSum(String id) throws SQLException {
125
        PreparedStatement ps = this.con.prepareStatement(this.insertSumSql);
126
        try {
105
            ps.setString(1, id);
127
            ps.setString(1, id);
106
            ps.setInt(2, 1);
128
            ps.setInt(2, 1);
107
            ps.executeUpdate();
129
            ps.executeUpdate();
122
            String source = day.substring(8, 9);
144
            String source = day.substring(8, 9);
123
            String id = day.substring(9);
145
            String id = day.substring(9);
124
            day = day.substring(0, 8);
146
            day = day.substring(0, 8);
147
            if (!this.updateSum(id, pv)) {
148
                this.insertSum(id);
149
            }
125
            if (!this.update(id, day, source, pv)) {
150
            if (!this.update(id, day, source, pv)) {
126
                this.insert(id, day, source, pv);
151
                this.insert(id, day, source, pv);
127
            }
152
            }

+ 42 - 6
src/main/java/com/ekexiu/project/platform/views/service/Main.java

12
import org.jfw.apt.web.annotation.param.JdbcConn;
12
import org.jfw.apt.web.annotation.param.JdbcConn;
13
import org.jfw.apt.web.annotation.param.ParameterMap;
13
import org.jfw.apt.web.annotation.param.ParameterMap;
14
import org.jfw.util.PageQueryResult;
14
import org.jfw.util.PageQueryResult;
15
import org.jfw.util.exception.JfwBaseException;
15
import org.jfw.util.jdbc.JdbcUtil;
16
import org.jfw.util.jdbc.JdbcUtil;
16
import org.jfw.util.jdbc.PreparedStatementConfig;
17
import org.jfw.util.jdbc.PreparedStatementConfig;
17
18
27
    public static final String MIN_DAY = "00000000";
28
    public static final String MIN_DAY = "00000000";
28
29
29
30
31
    private List<String> tns;
30
    private List<LogHandler> handlers;
32
    private List<LogHandler> handlers;
31
33
32
    @Autowrie
34
    @Autowrie
33
    private DayDao dayDao;
35
    private DayDao dayDao;
34
36
37
    public List<String> getTns() {
38
        return tns;
39
    }
40
41
    public void setTns(List<String> tns) {
42
        this.tns = tns;
43
    }
44
35
    public List<LogHandler> getHandlers() {
45
    public List<LogHandler> getHandlers() {
36
        return handlers;
46
        return handlers;
37
    }
47
    }
59
    @Get
69
    @Get
60
    @Path("/qm")
70
    @Path("/qm")
61
    public List<DayData> query(@JdbcConn Connection con, String tn, @Nullable String[] src, @Nullable String[] id, @DefaultValue("com.ekexiu.project.platform.views.service.Main.MIN_DAY") String bt,
71
    public List<DayData> query(@JdbcConn Connection con, String tn, @Nullable String[] src, @Nullable String[] id, @DefaultValue("com.ekexiu.project.platform.views.service.Main.MIN_DAY") String bt,
62
                               @DefaultValue("com.ekexiu.project.platform.views.service.Main.MAX_DAY") String et, @Nullable String sort) throws SQLException {
72
                               @DefaultValue("com.ekexiu.project.platform.views.service.Main.MAX_DAY") String et, @Nullable String sort) throws SQLException, JfwBaseException {
73
        if (!this.tns.contains(tn)) {
74
            throw new JfwBaseException(-101, "unavailable tn");
75
        }
63
        return dayDao.query(con, tn, src, id, bt, et, sort);
76
        return dayDao.query(con, tn, src, id, bt, et, sort);
64
    }
77
    }
65
78
66
    @Get
79
    @Get
67
    @Path("/qo")
80
    @Path("/qo")
68
    public List<DayData> query(@JdbcConn Connection con, String tn, String id, @DefaultValue("com.ekexiu.project.platform.views.service.Main.MIN_DAY") String bt,
81
    public List<DayData> query(@JdbcConn Connection con, String tn, String id, @DefaultValue("com.ekexiu.project.platform.views.service.Main.MIN_DAY") String bt,
69
                               @DefaultValue("com.ekexiu.project.platform.views.service.Main.MAX_DAY") String et) throws SQLException {
82
                               @DefaultValue("com.ekexiu.project.platform.views.service.Main.MAX_DAY") String et) throws SQLException, JfwBaseException {
83
        if (!this.tns.contains(tn)) {
84
            throw new JfwBaseException(-101, "unavailable tn");
85
        }
70
        return dayDao.query(con, tn, id, bt, et);
86
        return dayDao.query(con, tn, id, bt, et);
71
    }
87
    }
72
88
89
    @Get
90
    @Path("/qo/sum")
91
    public int query(@JdbcConn Connection con, String tn, final String id) throws SQLException,JfwBaseException {
92
        if (!this.tns.contains(tn)) {
93
            throw new JfwBaseException(-101, "unavailable tn");
94
        }
95
        return JdbcUtil.queryInt(con, "SELECT SUM FROM " + tn + "_DAY_SUM WHERE ID = ?", new PreparedStatementConfig() {
96
            @Override
97
            public void config(PreparedStatement preparedStatement) throws SQLException {
98
                preparedStatement.setString(1, id);
99
            }
100
        }, 0);
101
    }
102
73
    @Get
103
    @Get
74
    @Path("/qs")
104
    @Path("/qs")
75
    public List<DayData> query(@JdbcConn Connection con, String tn, @Nullable String[] src, @DefaultValue("com.ekexiu.project.platform.views.service.Main.MIN_DAY") String bt,
105
    public List<DayData> query(@JdbcConn Connection con, String tn, @Nullable String[] src, @DefaultValue("com.ekexiu.project.platform.views.service.Main.MIN_DAY") String bt,
76
                               @DefaultValue("com.ekexiu.project.platform.views.service.Main.MAX_DAY") String et, @DefaultValue("20") int rows) throws SQLException {
106
                               @DefaultValue("com.ekexiu.project.platform.views.service.Main.MAX_DAY") String et, @DefaultValue("20") int rows) throws SQLException, JfwBaseException {
107
        if (!this.tns.contains(tn)) {
108
            throw new JfwBaseException(-101, "unavailable tn");
109
        }
77
        return dayDao.query(con, tn, bt, et, src, rows);
110
        return dayDao.query(con, tn, bt, et, src, rows);
78
    }
111
    }
79
112
89
    }
122
    }
90
123
91
    @Get
124
    @Get
92
    @Path("/article/total")
93
    public List<Map<String, Object>> total(@JdbcConn Connection con, @DefaultValue("com.ekexiu.project.platform.views.service.Main.MIN_DAY") final String bt) throws SQLException {
94
        return JdbcUtil.queryMaps(con, "SELECT day,sum(pv)as pv,source FROM article_day WHERE day>=? GROUP BY day,source ORDER BY day DESC ", new PreparedStatementConfig() {
125
    @Path("/total")
126
    public List<Map<String, Object>> total(@JdbcConn Connection con,String tn, @DefaultValue("com.ekexiu.project.platform.views.service.Main.MIN_DAY") final String bt) throws SQLException, JfwBaseException {
127
        if (!this.tns.contains(tn)) {
128
            throw new JfwBaseException(-101, "unavailable tn");
129
        }
130
        return JdbcUtil.queryMaps(con, "SELECT day,sum(pv)as pv,source FROM "+tn+"_day WHERE day>=? GROUP BY day,source ORDER BY day DESC ", new PreparedStatementConfig() {
95
            @Override
131
            @Override
96
            public void config(PreparedStatement preparedStatement) throws SQLException {
132
            public void config(PreparedStatement preparedStatement) throws SQLException {
97
                preparedStatement.setString(1, bt);
133
                preparedStatement.setString(1, bt);

+ 4 - 0
src/main/resources/database.sql

439
INSERT INTO "public"."console_config" ("cfg_name", "cfg_value") VALUES ('main_log_handlers.collection-eleRef-0','article_log_handler');
439
INSERT INTO "public"."console_config" ("cfg_name", "cfg_value") VALUES ('main_log_handlers.collection-eleRef-0','article_log_handler');
440
INSERT INTO "public"."console_config" ("cfg_name", "cfg_value") VALUES ('com_ekexiu_project_platform_views_service_Main.handlers-ref','main_log_handlers');
440
INSERT INTO "public"."console_config" ("cfg_name", "cfg_value") VALUES ('com_ekexiu_project_platform_views_service_Main.handlers-ref','main_log_handlers');
441
441
442
INSERT INTO "public"."console_config" ("cfg_name", "cfg_value") VALUES ('tns_list::collection','java.util.ArrayList');
443
INSERT INTO "public"."console_config" ("cfg_name", "cfg_value") VALUES ('tns_list.collection-ele-0','article');
444
INSERT INTO "public"."console_config" ("cfg_name", "cfg_value") VALUES ('com_ekexiu_project_platform_views_service_Main.tns-ref','tns_list');
445