diff --git a/qieziBackend/.gitignore b/qieziBackend/.gitignore index 549e00a..f19d3e8 100644 --- a/qieziBackend/.gitignore +++ b/qieziBackend/.gitignore @@ -31,3 +31,4 @@ build/ ### VS Code ### .vscode/ +/src/main/resources/application-local.yml diff --git a/qieziBackend/pom.xml b/qieziBackend/pom.xml index 0a5ead9..e3b1dd5 100644 --- a/qieziBackend/pom.xml +++ b/qieziBackend/pom.xml @@ -73,6 +73,13 @@ hutool-all 5.7.21 + + + + com.alibaba + easyexcel + 3.1.3 + diff --git a/qieziBackend/src/main/java/com/fanxb/backend/controller/ApplicationController.java b/qieziBackend/src/main/java/com/fanxb/backend/controller/ApplicationController.java index fdf27e5..9bdfbef 100644 --- a/qieziBackend/src/main/java/com/fanxb/backend/controller/ApplicationController.java +++ b/qieziBackend/src/main/java/com/fanxb/backend/controller/ApplicationController.java @@ -2,6 +2,7 @@ package com.fanxb.backend.controller; import com.fanxb.backend.entity.ResultObject; import com.fanxb.backend.entity.dto.ApplicationSignDto; +import com.fanxb.backend.entity.vo.ApplicationSignVo; import com.fanxb.backend.service.ApplicationService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; @@ -49,4 +50,28 @@ public class ApplicationController { , @NotBlank(message = "key不能为空") String key, @NotBlank(message = "path不能为空") String path, @RequestParam(defaultValue = "false") boolean notAdd) throws IOException { applicationService.visit(request, response, callBack, key, path, notAdd); } + + /** + * 检查key,secret是否存在 + * + * @author fanxb + * date 2022/2/16 15:24 + */ + @PostMapping("/check") + public ResultObject check(@Validated @RequestBody ApplicationSignVo body) { + return ResultObject.success(applicationService.check(body)); + } + + /** + * 下载统计数据 + * + * @return com.fanxb.backend.entity.ResultObject + * @author fanxb + * date 2022-11-25 15:26 + */ + @GetMapping("/download") + public void download(String key, String secret, HttpServletResponse response) throws Exception { + applicationService.download(key, secret, response); + + } } diff --git a/qieziBackend/src/main/java/com/fanxb/backend/dao/DetailPageDao.java b/qieziBackend/src/main/java/com/fanxb/backend/dao/DetailPageDao.java index 1a34251..6d8500f 100644 --- a/qieziBackend/src/main/java/com/fanxb/backend/dao/DetailPageDao.java +++ b/qieziBackend/src/main/java/com/fanxb/backend/dao/DetailPageDao.java @@ -4,6 +4,8 @@ import com.fanxb.backend.entity.po.DetailPagePo; import com.fanxb.backend.entity.po.HostPo; import org.apache.ibatis.annotations.*; +import java.util.List; + /** * @author fanxb * @date 2022/2/15 16:37 @@ -45,4 +47,15 @@ public interface DetailPageDao { */ @Update("update detail_page set uv=uv+#{uvIncrement},pv=pv+1 where id=#{id}") void updateUvPv(@Param("id") int id, @Param("uvIncrement") int uvIncrement); + + /** + * 根据hostId查询数据 + * + * @param hostId hostId + * @return java.util.List + * @author fanxb + * date 2022-11-25 15:47 + */ + @Select("select * from detail_page where hostId=#{hostId}") + List selectByHostId(int hostId); } diff --git a/qieziBackend/src/main/java/com/fanxb/backend/dao/HostDao.java b/qieziBackend/src/main/java/com/fanxb/backend/dao/HostDao.java index f0c6ce3..2db1b88 100644 --- a/qieziBackend/src/main/java/com/fanxb/backend/dao/HostDao.java +++ b/qieziBackend/src/main/java/com/fanxb/backend/dao/HostDao.java @@ -22,6 +22,18 @@ public interface HostDao { @Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id") void insertOne(HostPo host); + /** + * 检查key,secret是否存在 + * + * @param key key + * @param secret secret + * @return boolean + * @author fanxb + * date 2022-11-24 23:06 + */ + @Select("select * from host where `key`=#{key} and secret=#{secret} limit 1") + HostPo selectByKeyAndSecret(@Param("key") String key, @Param("secret") String secret); + /** * 根据key获取id * diff --git a/qieziBackend/src/main/java/com/fanxb/backend/dao/HostDayDao.java b/qieziBackend/src/main/java/com/fanxb/backend/dao/HostDayDao.java index d6b257d..96abff8 100644 --- a/qieziBackend/src/main/java/com/fanxb/backend/dao/HostDayDao.java +++ b/qieziBackend/src/main/java/com/fanxb/backend/dao/HostDayDao.java @@ -3,6 +3,8 @@ package com.fanxb.backend.dao; import com.fanxb.backend.entity.po.HostDayPo; import org.apache.ibatis.annotations.*; +import java.util.List; + /** * @author fanxb */ @@ -12,7 +14,7 @@ public interface HostDayDao { * 获取id * * @param hostId hostId - * @param dayNum day + * @param dayNum day * @author fanxb */ @Select("select id from host_day where hostId=#{hostId} and dayNum=#{dayNum}") @@ -38,4 +40,15 @@ public interface HostDayDao { */ @Update("update host_day set uv=uv+#{uvIncrement},pv=pv+#{pvIncrement} where id=#{id}") void updatePvUv(@Param("id") int id, @Param("pvIncrement") int pvIncrement, @Param("uvIncrement") int uvIncrement); + + /** + * 根据hostId查询 + * + * @param hostId hostId + * @return java.util.List + * @author fanxb + * date 2022-11-25 15:41 + */ + @Select("select * from host_day where hostId=#{hostId}") + List selectByHostId(int hostId); } diff --git a/qieziBackend/src/main/java/com/fanxb/backend/entity/bo/ReportDetailPageBo.java b/qieziBackend/src/main/java/com/fanxb/backend/entity/bo/ReportDetailPageBo.java new file mode 100644 index 0000000..bc53187 --- /dev/null +++ b/qieziBackend/src/main/java/com/fanxb/backend/entity/bo/ReportDetailPageBo.java @@ -0,0 +1,25 @@ +package com.fanxb.backend.entity.bo; + +import cn.hutool.core.bean.BeanUtil; +import com.alibaba.excel.annotation.ExcelProperty; +import com.fanxb.backend.entity.po.DetailPagePo; +import com.fanxb.backend.entity.po.HostDayPo; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; + +@Data +@Accessors(chain = true) +@NoArgsConstructor +public class ReportDetailPageBo { + @ExcelProperty(value = "页面路径") + private String path; + @ExcelProperty(value = "PV") + private long pv; + @ExcelProperty(value = "UV") + private long uv; + + public ReportDetailPageBo(DetailPagePo po) { + BeanUtil.copyProperties(po, this); + } +} diff --git a/qieziBackend/src/main/java/com/fanxb/backend/entity/bo/ReportHostBo.java b/qieziBackend/src/main/java/com/fanxb/backend/entity/bo/ReportHostBo.java new file mode 100644 index 0000000..e12f838 --- /dev/null +++ b/qieziBackend/src/main/java/com/fanxb/backend/entity/bo/ReportHostBo.java @@ -0,0 +1,26 @@ +package com.fanxb.backend.entity.bo; + +import cn.hutool.core.bean.BeanUtil; +import com.alibaba.excel.annotation.ExcelProperty; +import com.fanxb.backend.entity.po.HostPo; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; + +@Data +@Accessors(chain = true) +@NoArgsConstructor +public class ReportHostBo { + @ExcelProperty(value = "站点名称") + private String name; + @ExcelProperty(value = "站点地址") + private String host; + @ExcelProperty(value = "PV") + private Integer pv; + @ExcelProperty(value = "UV") + private Integer uv; + + public ReportHostBo(HostPo hostPo) { + BeanUtil.copyProperties(hostPo, this); + } +} diff --git a/qieziBackend/src/main/java/com/fanxb/backend/entity/bo/ReportHostDayBo.java b/qieziBackend/src/main/java/com/fanxb/backend/entity/bo/ReportHostDayBo.java new file mode 100644 index 0000000..8e62407 --- /dev/null +++ b/qieziBackend/src/main/java/com/fanxb/backend/entity/bo/ReportHostDayBo.java @@ -0,0 +1,29 @@ +package com.fanxb.backend.entity.bo; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.date.DateUtil; +import com.alibaba.excel.annotation.ExcelProperty; +import com.fanxb.backend.entity.po.HostDayPo; +import com.fanxb.backend.entity.po.HostPo; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; + +@Data +@Accessors(chain = true) +@NoArgsConstructor +public class ReportHostDayBo { + @ExcelProperty(value = "日期") + private String date; + @ExcelProperty(value = "PV") + private long pv; + @ExcelProperty(value = "UV") + private long uv; + + public ReportHostDayBo(HostDayPo po) { + String temp = String.valueOf(po.getDayNum()); + this.date = temp.substring(0, 4) + "-" + temp.substring(4, 6) + "-" + temp.substring(6); + this.pv = po.getPv(); + this.uv = po.getUv(); + } +} diff --git a/qieziBackend/src/main/java/com/fanxb/backend/entity/vo/ApplicationSignVo.java b/qieziBackend/src/main/java/com/fanxb/backend/entity/vo/ApplicationSignVo.java index 0815bb7..96b87cd 100644 --- a/qieziBackend/src/main/java/com/fanxb/backend/entity/vo/ApplicationSignVo.java +++ b/qieziBackend/src/main/java/com/fanxb/backend/entity/vo/ApplicationSignVo.java @@ -4,6 +4,8 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; +import javax.validation.constraints.NotBlank; + /** * 应用注册vo * @@ -14,6 +16,8 @@ import lombok.NoArgsConstructor; @NoArgsConstructor @AllArgsConstructor public class ApplicationSignVo { + @NotBlank(message = "key不能为空") private String key; + @NotBlank(message = "secret不能为空") private String secret; } diff --git a/qieziBackend/src/main/java/com/fanxb/backend/service/ApplicationService.java b/qieziBackend/src/main/java/com/fanxb/backend/service/ApplicationService.java index 894ff97..66cf1c9 100644 --- a/qieziBackend/src/main/java/com/fanxb/backend/service/ApplicationService.java +++ b/qieziBackend/src/main/java/com/fanxb/backend/service/ApplicationService.java @@ -38,4 +38,25 @@ public interface ApplicationService { * date 2022/2/16 10:20 */ void visit(HttpServletRequest request, HttpServletResponse response, String callBack, String key, String path, boolean notAdd) throws IOException; + + /** + * 检查key,secret是否存在 + * + * @param body body + * @return boolean + * @author fanxb + * date 2022-11-24 23:05 + */ + boolean check(ApplicationSignVo body); + + /** + * 下载站点数据 + * + * @param key key + * @param secret secret + * @param response response + * @author fanxb + * date 2022-11-25 15:27 + */ + void download(String key, String secret, HttpServletResponse response) throws Exception; } diff --git a/qieziBackend/src/main/java/com/fanxb/backend/service/impl/ApplicationServiceImpl.java b/qieziBackend/src/main/java/com/fanxb/backend/service/impl/ApplicationServiceImpl.java index ba793b0..4b3fd02 100644 --- a/qieziBackend/src/main/java/com/fanxb/backend/service/impl/ApplicationServiceImpl.java +++ b/qieziBackend/src/main/java/com/fanxb/backend/service/impl/ApplicationServiceImpl.java @@ -2,6 +2,8 @@ package com.fanxb.backend.service.impl; import cn.hutool.core.util.IdUtil; import cn.hutool.http.Header; +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.ExcelWriter; import com.alibaba.fastjson.JSON; import com.fanxb.backend.constants.CommonConstant; import com.fanxb.backend.constants.RedisConstant; @@ -9,6 +11,9 @@ import com.fanxb.backend.dao.DetailPageDao; import com.fanxb.backend.dao.DetailPageDayDao; import com.fanxb.backend.dao.HostDao; import com.fanxb.backend.dao.HostDayDao; +import com.fanxb.backend.entity.bo.ReportDetailPageBo; +import com.fanxb.backend.entity.bo.ReportHostBo; +import com.fanxb.backend.entity.bo.ReportHostDayBo; import com.fanxb.backend.entity.dto.ApplicationSignDto; import com.fanxb.backend.entity.exception.CustomBaseException; import com.fanxb.backend.entity.po.DetailPageDayPo; @@ -28,13 +33,17 @@ import org.springframework.stereotype.Service; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.time.LocalDate; import java.time.ZoneId; import java.time.format.DateTimeFormatter; +import java.util.Collections; +import java.util.List; import java.util.Locale; import java.util.concurrent.TimeUnit; import java.util.regex.Pattern; +import java.util.stream.Collectors; /** * 应用管理 @@ -75,6 +84,12 @@ public class ApplicationServiceImpl implements ApplicationService { return new ApplicationSignVo(po.getKey(), po.getSecret()); } + @Override + public boolean check(ApplicationSignVo body) { + HostPo po = hostDao.selectByKeyAndSecret(body.getKey(), body.getSecret()); + return po != null; + } + private static Pattern PATTERN = Pattern.compile("googlebot|bingbot|yandex|baiduspider|360Spider|Sogou Spider|Bytespider|twitterbot|facebookexternalhit|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest\\/0\\.|pinterestbot|slackbot|vkShare|W3C_Validator|whatsapp"); @Override @@ -201,4 +216,23 @@ public class ApplicationServiceImpl implements ApplicationService { return hostId; } + @Override + public void download(String key, String secret, HttpServletResponse response) throws Exception { + HostPo po = hostDao.selectByKeyAndSecret(key, secret); + if (po == null) { + throw new CustomBaseException("key,secret不存在"); + } + List hostList = Collections.singletonList(new ReportHostBo(po)); + List hostDayList = hostDayDao.selectByHostId(po.getId()).stream().map(ReportHostDayBo::new).collect(Collectors.toList()); + List detailPageList = detailPageDao.selectByHostId(po.getId()).stream().map(ReportDetailPageBo::new).collect(Collectors.toList()); + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setCharacterEncoding("utf-8"); + String fileName = URLEncoder.encode(po.getName() + "-站点导出数据", StandardCharsets.UTF_8).replaceAll("\\+", "%20"); + response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); + ExcelWriter writer = EasyExcel.write(response.getOutputStream()).build(); + writer.write(hostList, EasyExcel.writerSheet(0, "站点数据").head(ReportHostBo.class).build()); + writer.write(hostDayList, EasyExcel.writerSheet(1, "站点日数据").head(ReportHostDayBo.class).build()); + writer.write(detailPageList, EasyExcel.writerSheet(2, "页面数据").head(ReportDetailPageBo.class).build()); + writer.finish(); + } } diff --git a/qiezi_front/public/favicon.ico b/qiezi_front/public/favicon.ico deleted file mode 100644 index df36fcf..0000000 Binary files a/qiezi_front/public/favicon.ico and /dev/null differ diff --git a/qiezi_front/public/ico.png b/qiezi_front/public/ico.png new file mode 100644 index 0000000..c47139c Binary files /dev/null and b/qiezi_front/public/ico.png differ diff --git a/qiezi_front/public/index.html b/qiezi_front/public/index.html index 85b5740..3bc9ef3 100644 --- a/qiezi_front/public/index.html +++ b/qiezi_front/public/index.html @@ -1,11 +1,11 @@ - + - - <%= htmlWebpackPlugin.options.title %> + + 茄子统计 -
+
-
- -
- -
- - +
+
+ +
+ +
+ + +
diff --git a/qiezi_front/src/views/manage/index.vue b/qiezi_front/src/views/manage/index.vue deleted file mode 100644 index 43fc804..0000000 --- a/qiezi_front/src/views/manage/index.vue +++ /dev/null @@ -1,18 +0,0 @@ - - - - -