gaodm 5 éve
szülő
commit
a0b93fb77e

+ 4 - 0
config-server/src/main/resources/shared/zzcx-service-dev.yml

@@ -94,3 +94,7 @@ mybatis-plus:
   configuration:
     map-underscore-to-camel-case: true
     cache-enabled: false
+
+io.github.lvyahui8.spring:
+  base-packages: com.diagbot.aggregate
+  thread-number: 12

+ 4 - 0
config-server/src/main/resources/shared/zzcx-service-local.yml

@@ -94,3 +94,7 @@ mybatis-plus:
   configuration:
     map-underscore-to-camel-case: true
     cache-enabled: false
+
+io.github.lvyahui8.spring:
+  base-packages: com.diagbot.aggregate
+  thread-number: 12

+ 4 - 0
config-server/src/main/resources/shared/zzcx-service-pre.yml

@@ -94,3 +94,7 @@ mybatis-plus:
   configuration:
     map-underscore-to-camel-case: true
     cache-enabled: false
+
+io.github.lvyahui8.spring:
+  base-packages: com.diagbot.aggregate
+  thread-number: 12

+ 4 - 0
config-server/src/main/resources/shared/zzcx-service-pro.yml

@@ -94,3 +94,7 @@ mybatis-plus:
   configuration:
     map-underscore-to-camel-case: true
     cache-enabled: false
+
+io.github.lvyahui8.spring:
+  base-packages: com.diagbot.aggregate
+  thread-number: 12

+ 4 - 0
config-server/src/main/resources/shared/zzcx-service-test.yml

@@ -94,3 +94,7 @@ mybatis-plus:
   configuration:
     map-underscore-to-camel-case: true
     cache-enabled: false
+
+io.github.lvyahui8.spring:
+  base-packages: com.diagbot.aggregate
+  thread-number: 12

+ 5 - 0
zzcx-service/pom.xml

@@ -154,6 +154,11 @@
             <artifactId>spring-cloud-starter-stream-rabbit</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>io.github.lvyahui8</groupId>
+            <artifactId>spring-boot-data-aggregator-starter</artifactId>
+        </dependency>
+
     </dependencies>
 
     <build>

+ 88 - 0
zzcx-service/src/main/java/com/diagbot/aggregate/OptAggregate.java

@@ -0,0 +1,88 @@
+package com.diagbot.aggregate;
+
+import com.diagbot.dto.OptDTO;
+import com.diagbot.dto.PVDTO;
+import com.diagbot.dto.UVDTO;
+import com.diagbot.dto.ZZDTO;
+import com.diagbot.facade.OptInfoFacade;
+import com.diagbot.util.ListUtil;
+import com.diagbot.vo.OptVO;
+import io.github.lvyahui8.spring.annotation.DataConsumer;
+import io.github.lvyahui8.spring.annotation.DataProvider;
+import io.github.lvyahui8.spring.annotation.InvokeParameter;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+/**
+ * @Description:
+ * @author: gaodm
+ * @time: 2020/2/3 10:38
+ */
+@Component
+public class OptAggregate {
+    @Autowired
+    private OptInfoFacade optInfoFacade;
+
+    @DataProvider("getAllOptSum")
+    public OptDTO getAllOptSum(
+            @InvokeParameter("optVO") OptVO optVO,
+            @DataConsumer("getPV") List<PVDTO> pvdtoList,
+            @DataConsumer("getPVSum") Long pvSum,
+            @DataConsumer("getUV") List<UVDTO> uvdtoList,
+            @DataConsumer("getUVSum") Long uvSum,
+            @DataConsumer("getZZ") List<ZZDTO> zzdtoList,
+            @DataConsumer("getZZSum") Long zzSum){
+        OptDTO optDTO = new OptDTO();
+        if(ListUtil.isNotEmpty(pvdtoList)){
+            optDTO.setPvdto(pvdtoList);
+        }
+        if (null != pvSum){
+            optDTO.setPvSum(pvSum);
+        }
+        if(ListUtil.isNotEmpty(uvdtoList)){
+            optDTO.setUvdto(uvdtoList);
+        }
+        if (null != uvSum){
+            optDTO.setUvSum(uvSum);
+        }
+        if(ListUtil.isNotEmpty(zzdtoList)){
+            optDTO.setZzdto(zzdtoList);
+        }
+        if (null != zzSum){
+            optDTO.setZzSum(zzSum);
+        }
+        return optDTO;
+    }
+
+    @DataProvider("getPV")
+    public List<PVDTO> getPV(@InvokeParameter("optVO") OptVO optVO) {
+        return optInfoFacade.getPV(optVO);
+    }
+
+    @DataProvider("getPVSum")
+    public Long getPVSum(@InvokeParameter("optVO") OptVO optVO) {
+        return optInfoFacade.getPVSum(optVO);
+    }
+
+    @DataProvider("getUV")
+    public List<UVDTO> getUV(@InvokeParameter("optVO") OptVO optVO) {
+        return optInfoFacade.getUV(optVO);
+    }
+
+    @DataProvider("getUVSum")
+    public Long getUVSum(@InvokeParameter("optVO") OptVO optVO) {
+        return optInfoFacade.getUVSum(optVO);
+    }
+
+    @DataProvider("getZZ")
+    public List<ZZDTO> getZZ(@InvokeParameter("optVO") OptVO optVO) {
+        return optInfoFacade.getZZ(optVO);
+    }
+
+    @DataProvider("getZZSum")
+    public Long getZZSum(@InvokeParameter("optVO") OptVO optVO) {
+        return optInfoFacade.getZZSum(optVO);
+    }
+}

+ 22 - 0
zzcx-service/src/main/java/com/diagbot/dto/OptDTO.java

@@ -0,0 +1,22 @@
+package com.diagbot.dto;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.List;
+
+/**
+ * @Description:
+ * @author: gaodm
+ * @time: 2020/2/3 9:50
+ */
+@Getter
+@Setter
+public class OptDTO {
+    private List<PVDTO> pvdto;
+    private Long pvSum;
+    private List<UVDTO> uvdto;
+    private Long uvSum;
+    private List<ZZDTO> zzdto;
+    private Long zzSum;
+}

+ 16 - 0
zzcx-service/src/main/java/com/diagbot/dto/PVDTO.java

@@ -0,0 +1,16 @@
+package com.diagbot.dto;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * @Description:
+ * @author: gaodm
+ * @time: 2020/2/3 9:27
+ */
+@Getter
+@Setter
+public class PVDTO {
+    private String days;
+    private Long pvCnt;
+}

+ 16 - 0
zzcx-service/src/main/java/com/diagbot/dto/UVDTO.java

@@ -0,0 +1,16 @@
+package com.diagbot.dto;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * @Description:
+ * @author: gaodm
+ * @time: 2020/2/3 9:27
+ */
+@Getter
+@Setter
+public class UVDTO {
+    private String days;
+    private Long uvCnt;
+}

+ 16 - 0
zzcx-service/src/main/java/com/diagbot/dto/ZZDTO.java

@@ -0,0 +1,16 @@
+package com.diagbot.dto;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * @Description:
+ * @author: gaodm
+ * @time: 2020/2/3 9:27
+ */
+@Getter
+@Setter
+public class ZZDTO {
+    private String days;
+    private Long zzCnt;
+}

+ 44 - 1
zzcx-service/src/main/java/com/diagbot/facade/OptInfoFacade.java

@@ -1,12 +1,20 @@
 package com.diagbot.facade;
 
+import com.diagbot.dto.OptDTO;
 import com.diagbot.entity.OptInfo;
+import com.diagbot.exception.CommonErrorCode;
+import com.diagbot.exception.CommonException;
 import com.diagbot.service.impl.OptInfoServiceImpl;
 import com.diagbot.util.DateUtil;
 import com.diagbot.util.HttpUtils;
+import com.diagbot.vo.OptVO;
+import io.github.lvyahui8.spring.aggregate.facade.DataBeanAggregateQueryFacade;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
 
 /**
  * @Description:
@@ -15,8 +23,10 @@ import java.util.Date;
  */
 @Component
 public class OptInfoFacade extends OptInfoServiceImpl {
+    @Autowired
+    DataBeanAggregateQueryFacade dataBeanAggregateQueryFacade;
 
-    public Boolean saveOptOnfo(String optType){
+    public Boolean saveOptOnfo(String optType) {
         OptInfo optInfo = new OptInfo();
         Date now = DateUtil.now();
         optInfo.setGmtModified(now);
@@ -26,4 +36,37 @@ public class OptInfoFacade extends OptInfoServiceImpl {
         Boolean res = this.save(optInfo);
         return res;
     }
+
+    public OptDTO getOptSum(OptVO optVO) {
+        if (null != optVO && null != optVO.getStartDate()) {
+            optVO.setStartDate(DateUtil.getFirstTimeOfDay(optVO.getStartDate()));
+        }
+        if (null != optVO && null != optVO.getEndDate()) {
+            optVO.setEndDate(DateUtil.getLastTimeOfDay(optVO.getEndDate()));
+        }
+
+        if (null != optVO && null != optVO.getStartDate() && null != optVO.getEndDate()) {
+            if (DateUtil.after(optVO.getStartDate(), optVO.getEndDate())) {
+                throw new CommonException(CommonErrorCode.PARAM_IS_ERROR, "开始时间大于结束时间!");
+            }
+        }
+
+        OptDTO optDTO = new OptDTO();
+
+        try {
+            Map<String, Object> invokeParams = new HashMap<>();
+            invokeParams.put("optVO",optVO);
+            optDTO
+                    = dataBeanAggregateQueryFacade.get("getAllOptSum", invokeParams, OptDTO.class);
+        } catch (Exception e) {
+            throw new CommonException(CommonErrorCode.SERVER_IS_ERROR);
+        }
+//        optDTO.setPvdto(this.getPV(optVO));
+//        optDTO.setPvSum(this.getPVSum(optVO));
+//        optDTO.setUvdto(this.getUV(optVO));
+//        optDTO.setUvSum(this.getUVSum(optVO));
+//        optDTO.setZzdto(this.getZZ(optVO));
+//        optDTO.setZzSum(this.getZZSum(optVO));
+        return optDTO;
+    }
 }

+ 16 - 0
zzcx-service/src/main/java/com/diagbot/mapper/OptInfoMapper.java

@@ -1,7 +1,13 @@
 package com.diagbot.mapper;
 
+import com.diagbot.dto.PVDTO;
+import com.diagbot.dto.UVDTO;
+import com.diagbot.dto.ZZDTO;
 import com.diagbot.entity.OptInfo;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.diagbot.vo.OptVO;
+
+import java.util.List;
 
 /**
  * <p>
@@ -12,5 +18,15 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  * @since 2020-02-02
  */
 public interface OptInfoMapper extends BaseMapper<OptInfo> {
+    List<PVDTO> getPV(OptVO optVO);
+
+    Long getPVSum(OptVO optVO);
+
+    List<UVDTO> getUV(OptVO optVO);
+
+    Long getUVSum(OptVO optVO);
+
+    List<ZZDTO> getZZ(OptVO optVO);
 
+    Long getZZSum(OptVO optVO);
 }

+ 18 - 0
zzcx-service/src/main/java/com/diagbot/service/OptInfoService.java

@@ -1,7 +1,13 @@
 package com.diagbot.service;
 
+import com.diagbot.dto.PVDTO;
+import com.diagbot.dto.UVDTO;
+import com.diagbot.dto.ZZDTO;
 import com.diagbot.entity.OptInfo;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.diagbot.vo.OptVO;
+
+import java.util.List;
 
 /**
  * <p>
@@ -13,4 +19,16 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface OptInfoService extends IService<OptInfo> {
 
+    List<PVDTO> getPV(OptVO optVO);
+
+    Long getPVSum(OptVO optVO);
+
+    List<UVDTO> getUV(OptVO optVO);
+
+    Long getUVSum(OptVO optVO);
+
+    List<ZZDTO> getZZ(OptVO optVO);
+
+    Long getZZSum(OptVO optVO);
+
 }

+ 29 - 1
zzcx-service/src/main/java/com/diagbot/service/impl/OptInfoServiceImpl.java

@@ -1,11 +1,17 @@
 package com.diagbot.service.impl;
 
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.diagbot.dto.PVDTO;
+import com.diagbot.dto.UVDTO;
+import com.diagbot.dto.ZZDTO;
 import com.diagbot.entity.OptInfo;
 import com.diagbot.mapper.OptInfoMapper;
 import com.diagbot.service.OptInfoService;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.diagbot.vo.OptVO;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 /**
  * <p>
  * 操作信息 服务实现类
@@ -16,5 +22,27 @@ import org.springframework.stereotype.Service;
  */
 @Service
 public class OptInfoServiceImpl extends ServiceImpl<OptInfoMapper, OptInfo> implements OptInfoService {
+    public List<PVDTO> getPV(OptVO optVO) {
+        return this.baseMapper.getPV(optVO);
+    }
+
+    public Long getPVSum(OptVO optVO) {
+        return this.baseMapper.getPVSum(optVO);
+    }
+
+    public List<UVDTO> getUV(OptVO optVO) {
+        return this.baseMapper.getUV(optVO);
+    }
+
+    public Long getUVSum(OptVO optVO) {
+        return this.baseMapper.getUVSum(optVO);
+    }
+
+    public List<ZZDTO> getZZ(OptVO optVO) {
+        return this.baseMapper.getZZ(optVO);
+    }
 
+    public Long getZZSum(OptVO optVO) {
+        return this.baseMapper.getZZSum(optVO);
+    }
 }

+ 20 - 0
zzcx-service/src/main/java/com/diagbot/vo/OptVO.java

@@ -0,0 +1,20 @@
+package com.diagbot.vo;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.Date;
+
+/**
+ * @Description:
+ * @author: gaodm
+ * @time: 2020/2/3 9:21
+ */
+@Getter
+@Setter
+public class OptVO {
+    //开始时间
+    private Date startDate;
+    //结束时间
+    private Date endDate;
+}

+ 10 - 0
zzcx-service/src/main/java/com/diagbot/web/OptInfoController.java

@@ -1,13 +1,16 @@
 package com.diagbot.web;
 
 import com.diagbot.annotation.SysLogger;
+import com.diagbot.dto.OptDTO;
 import com.diagbot.dto.RespDTO;
 import com.diagbot.facade.OptInfoFacade;
+import com.diagbot.vo.OptVO;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
@@ -34,4 +37,11 @@ public class OptInfoController {
     public RespDTO<Boolean> saveOptOnfo() {
         return RespDTO.onSuc(optInfoFacade.saveOptOnfo("1"));
     }
+
+    @ApiOperation(value = "获取合计数据[by:gaodm]")
+    @PostMapping("/getOptSum")
+    @SysLogger("getOptSum")
+    public RespDTO<OptDTO> getOptSum(@RequestBody OptVO optVO){
+        return RespDTO.onSuc(optInfoFacade.getOptSum(optVO));
+    }
 }

+ 129 - 0
zzcx-service/src/main/resources/mapper/OptInfoMapper.xml

@@ -15,4 +15,133 @@
         <result column="remark" property="remark" />
     </resultMap>
 
+    <select id="getPV" parameterType="com.diagbot.vo.OptVO" resultType="com.diagbot.dto.PVDTO">
+        SELECT
+        DATE_FORMAT(gmt_create, '%Y-%m-%d') AS days,
+        count(1) AS pvCnt
+        FROM
+        zzcx_opt_info
+        WHERE
+        opt_type = 1
+        <if test="startDate!=null">
+          AND gmt_create &gt;= #{startDate}
+        </if>
+        <if test="endDate!=null">
+          AND gmt_create &lt;= #{endDate}
+        </if>
+        GROUP BY
+        DATE_FORMAT(gmt_create, '%Y-%m-%d')
+        ORDER BY
+        DATE_FORMAT(gmt_create, '%Y-%m-%d');
+    </select>
+
+    <select id="getPVSum" parameterType="com.diagbot.vo.OptVO" resultType="java.lang.Long">
+        SELECT
+        count(1) AS pvSum
+        FROM
+        zzcx_opt_info
+        WHERE
+        opt_type = 1
+        <if test="startDate!=null">
+            AND gmt_create &gt;= #{startDate}
+        </if>
+        <if test="endDate!=null">
+            AND gmt_create &lt;= #{endDate}
+        </if>
+    </select>
+
+    <select id="getUV" parameterType="com.diagbot.vo.OptVO" resultType="com.diagbot.dto.UVDTO">
+        SELECT
+        t.days AS days,
+        count(ip) AS uvCnt
+        FROM
+        (
+        SELECT DISTINCT
+        DATE_FORMAT(gmt_create, '%Y-%m-%d') AS days,
+        ip
+        FROM
+        zzcx_opt_info
+        WHERE
+        opt_type = 1
+        <if test="startDate!=null">
+            AND gmt_create &gt;= #{startDate}
+        </if>
+        <if test="endDate!=null">
+            AND gmt_create &lt;= #{endDate}
+        </if>
+        ) t
+        GROUP BY
+        days
+        ORDER BY
+        days;
+    </select>
+
+    <select id="getUVSum" parameterType="com.diagbot.vo.OptVO" resultType="java.lang.Long">
+        SELECT
+        count(ip) AS uvSum
+        FROM
+        (
+        SELECT DISTINCT
+        DATE_FORMAT(gmt_create, '%Y-%m-%d') AS days,
+        ip
+        FROM
+        zzcx_opt_info
+        WHERE
+        opt_type = 1
+        <if test="startDate!=null">
+            AND gmt_create &gt;= #{startDate}
+        </if>
+        <if test="endDate!=null">
+            AND gmt_create &lt;= #{endDate}
+        </if>
+        ) t;
+    </select>
+
+    <select id="getZZ" parameterType="com.diagbot.vo.OptVO" resultType="com.diagbot.dto.ZZDTO">
+        SELECT
+        t.days AS days,
+        count(ip) AS zzCnt
+        FROM
+        (
+        SELECT DISTINCT
+        DATE_FORMAT(gmt_create, '%Y-%m-%d') AS days,
+        ip
+        FROM
+        zzcx_opt_info
+        WHERE
+        opt_type = 2
+        <if test="startDate!=null">
+            AND gmt_create &gt;= #{startDate}
+        </if>
+        <if test="endDate!=null">
+            AND gmt_create &lt;= #{endDate}
+        </if>
+        ) t
+        GROUP BY
+        days
+        ORDER BY
+        days;
+    </select>
+
+    <select id="getZZSum" parameterType="com.diagbot.vo.OptVO" resultType="java.lang.Long">
+        SELECT
+        count(ip) AS zzSum
+        FROM
+        (
+        SELECT DISTINCT
+        DATE_FORMAT(gmt_create, '%Y-%m-%d') AS days,
+        ip
+        FROM
+        zzcx_opt_info
+        WHERE
+        opt_type = 2
+        <if test="startDate!=null">
+            AND gmt_create &gt;= #{startDate}
+        </if>
+        <if test="endDate!=null">
+            AND gmt_create &lt;= #{endDate}
+        </if>
+        ) t;
+    </select>
+
 </mapper>