diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/FlowReportHourMapper.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/FlowReportHourMapper.java new file mode 100644 index 00000000..fbfcfc42 --- /dev/null +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/FlowReportHourMapper.java @@ -0,0 +1,44 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.proxy.server.dal; + +import fun.asgc.neutrino.core.annotation.Component; +import fun.asgc.neutrino.core.annotation.Param; +import fun.asgc.neutrino.core.aop.Intercept; +import fun.asgc.neutrino.core.db.annotation.Insert; +import fun.asgc.neutrino.core.db.annotation.Select; +import fun.asgc.neutrino.core.db.mapper.SqlMapper; +import fun.asgc.neutrino.proxy.server.dal.entity.FlowReportHourDO; + +/** + * @author: aoshiguchen + * @date: 2022/10/28 + */ +@Intercept(ignoreGlobal = true) +@Component +public interface FlowReportHourMapper extends SqlMapper { + @Select("select * from flow_report_hour where license_id = :licenseId and date = :date") + FlowReportHourDO findOne(@Param("licenseId") Integer licenseId, @Param("date") String date); + + @Insert("insert into flow_report_hour(`user_id`,`license_id`,`write_bytes`,`read_bytes`,`date`,`date_str`,`create_time`) values(:userId,:licenseId,:writeBytes,:readBytes,:date,:dateStr,:createTime)") + void add(FlowReportHourDO flowReportHourDO); +} diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/FlowReportMinuteMapper.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/FlowReportMinuteMapper.java index 1f02dccd..e57a4801 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/FlowReportMinuteMapper.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/FlowReportMinuteMapper.java @@ -47,6 +47,6 @@ public interface FlowReportMinuteMapper extends SqlMapper { @Select("select * from flow_report_minute where license_id in (:licenseIds) and date = :date") List findList(@Param("licenseIds") Set licenseIds, @Param("date") String date); - @Insert("insert into flow_report_minute(`user_id`,`license_id`,`write_bytes`,`read_bytes`,`date`,`create_time`) values(:userId,:licenseId,:writeBytes,:readBytes,:date,:createTime)") + @Insert("insert into flow_report_minute(`user_id`,`license_id`,`write_bytes`,`read_bytes`,`date`,`date_str`,`create_time`) values(:userId,:licenseId,:writeBytes,:readBytes,:date,:dateStr,:createTime)") void add(FlowReportMinuteDO flowReportMinuteDO); } diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/entity/FlowReportHourDO.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/entity/FlowReportHourDO.java new file mode 100644 index 00000000..c3ee3057 --- /dev/null +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/entity/FlowReportHourDO.java @@ -0,0 +1,72 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.proxy.server.dal.entity; + +import fun.asgc.neutrino.core.db.annotation.Id; +import fun.asgc.neutrino.core.db.annotation.Table; +import lombok.Data; +import lombok.ToString; +import lombok.experimental.Accessors; + +import java.util.Date; + +/** + * @author: aoshiguchen + * @date: 2022/10/24 + */ +@ToString +@Accessors(chain = true) +@Data +@Table("flow_report_hour") +public class FlowReportHourDO { + @Id + private Integer id; + /** + * 用户ID + */ + private Integer userId; + /** + * licenseId + */ + private Integer licenseId; + /** + * 写入字节数 + */ + private Long writeBytes; + /** + * 读取字节数 + */ + private Long readBytes; + /** + * 报表统计时间 + */ + private Date date; + /** + * 报表统计时间 + * yyyy-MM-dd HH + */ + private String dateStr; + /** + * 创建时间 + */ + private Date createTime; +} diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/entity/FlowReportMinuteDO.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/entity/FlowReportMinuteDO.java index 437d3899..139e9363 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/entity/FlowReportMinuteDO.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/entity/FlowReportMinuteDO.java @@ -56,11 +56,15 @@ public class FlowReportMinuteDO { * 读取字节数 */ private Integer readBytes; + /** + * 报表统计时间 + */ + private Date date; /** * 报表统计时间 * yyyy-MM-dd HH:mm */ - private String date; + private String dateStr; /** * 创建时间 */ diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/job/FlowReportForHourJob.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/job/FlowReportForHourJob.java new file mode 100644 index 00000000..13bbcd12 --- /dev/null +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/job/FlowReportForHourJob.java @@ -0,0 +1,55 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.proxy.server.job; + +import fun.asgc.neutrino.core.annotation.Autowired; +import fun.asgc.neutrino.core.annotation.Component; +import fun.asgc.neutrino.core.annotation.NonIntercept; +import fun.asgc.neutrino.core.quartz.IJobHandler; +import fun.asgc.neutrino.core.quartz.annotation.JobHandler; +import fun.asgc.neutrino.proxy.server.dal.FlowReportMinuteMapper; +import fun.asgc.neutrino.proxy.server.dal.LicenseMapper; +import fun.asgc.neutrino.proxy.server.service.FlowReportService; +import lombok.extern.slf4j.Slf4j; + +/** + * @author: aoshiguchen + * @date: 2022/10/28 + */ +@Slf4j +@NonIntercept +@Component +@JobHandler(name = "FlowReportForHourJob", cron = "0 0 */1 * * ?", param = "") +public class FlowReportForHourJob implements IJobHandler { + @Autowired + private FlowReportService flowReportService; + @Autowired + private LicenseMapper licenseMapper; + @Autowired + private FlowReportMinuteMapper flowReportMinuteMapper; + + @Override + public void execute(String param) throws Exception { + // TODO + } + +} diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/job/FlowReportForMinuteJob.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/job/FlowReportForMinuteJob.java index 47922b35..5da9caa2 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/job/FlowReportForMinuteJob.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/job/FlowReportForMinuteJob.java @@ -65,8 +65,9 @@ public class FlowReportForMinuteJob implements IJobHandler { } Set licenseIds = list.stream().map(LicenseDO::getId).collect(Collectors.toSet()); Date now = new Date(); - String date = DateUtil.format(DateUtil.addDate(now, Calendar.MINUTE, -1), "yyyy-MM-dd HH:mm"); - List oldList = flowReportMinuteMapper.findList(licenseIds, date); + String dateStr = DateUtil.format(DateUtil.addDate(now, Calendar.MINUTE, -1), "yyyy-MM-dd HH:mm"); + Date date = DateUtil.parse(dateStr, "yyyy-MM-dd HH:mm"); + List oldList = flowReportMinuteMapper.findList(licenseIds, dateStr); Map oldMap = CollectionUtil.isEmpty(oldList) ? new HashMap<>() : oldList.stream().collect(Collectors.toMap(FlowReportMinuteDO::getLicenseId, Function.identity(), (a,b) -> a)); @@ -86,6 +87,7 @@ public class FlowReportForMinuteJob implements IJobHandler { flowReportMinuteDO.setWriteBytes(writeBytes); flowReportMinuteDO.setReadBytes(readBytes); flowReportMinuteDO.setDate(date); + flowReportMinuteDO.setDateStr(dateStr); flowReportMinuteDO.setCreateTime(now); flowReportMinuteMapper.add(flowReportMinuteDO); } diff --git a/neutrino-proxy-server/src/main/resources/sql/init-structure.sql b/neutrino-proxy-server/src/main/resources/sql/init-structure.sql index 4d855f07..97cfba85 100644 --- a/neutrino-proxy-server/src/main/resources/sql/init-structure.sql +++ b/neutrino-proxy-server/src/main/resources/sql/init-structure.sql @@ -139,7 +139,8 @@ CREATE TABLE IF NOT EXISTS `flow_report_minute` ( `license_id` INTEGER(20) NOT NULL, `write_bytes` INTEGER(20) NOT NULL, `read_bytes` INTEGER(20) NOT NULL, - `date` VARCHAR(20) NOT NULL, + `date` INTEGER(20) NOT NULL, + `date_str` VARCHAR(20) NOT NULL, `create_time` INTEGER(20) NOT NULL ); CREATE INDEX IF NOT EXISTS I_flow_report_minute_create_time ON flow_report_minute(create_time); @@ -154,7 +155,8 @@ CREATE TABLE IF NOT EXISTS `flow_report_hour` ( `license_id` INTEGER(20) NOT NULL, `write_bytes` INTEGER(20) NOT NULL, `read_bytes` INTEGER(20) NOT NULL, - `date` VARCHAR(20) NOT NULL, + `date` INTEGER(20) NOT NULL, + `date_str` VARCHAR(20) NOT NULL, `create_time` INTEGER(20) NOT NULL ); CREATE INDEX IF NOT EXISTS I_flow_report_hour_create_time ON flow_report_hour(create_time); @@ -169,7 +171,8 @@ CREATE TABLE IF NOT EXISTS `flow_report_day` ( `license_id` INTEGER(20) NOT NULL, `write_bytes` INTEGER(20) NOT NULL, `read_bytes` INTEGER(20) NOT NULL, - `date` VARCHAR(20) NOT NULL, + `date` INTEGER(20) NOT NULL, + `date_str` VARCHAR(20) NOT NULL, `create_time` INTEGER(20) NOT NULL ); CREATE INDEX IF NOT EXISTS I_flow_report_day_create_time ON flow_report_day(create_time); @@ -184,7 +187,8 @@ CREATE TABLE IF NOT EXISTS `flow_report_month` ( `license_id` INTEGER(20) NOT NULL, `write_bytes` INTEGER(20) NOT NULL, `read_bytes` INTEGER(20) NOT NULL, - `date` VARCHAR(20) NOT NULL, + `date` INTEGER(20) NOT NULL, + `date_str` VARCHAR(20) NOT NULL, `create_time` INTEGER(20) NOT NULL ); CREATE INDEX IF NOT EXISTS I_flow_report_month_create_time ON flow_report_month(create_time);