Browse Source

Merge branch 'feature/1.0.0' of github.com:ab-inbev-apac/abi-cloud-qr-platform into feature/1.0.0

tanzhongran 3 years ago
parent
commit
4d89672f2f

+ 42 - 0
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/controller/wx/WxFactoryController.java

@@ -0,0 +1,42 @@
+package com.abi.qms.platform.controller.wx;
+
+import com.abi.qms.platform.dto.req.QueryWxFactoryReq;
+import com.abi.qms.platform.dto.res.QueryWxFactoryRes;
+import com.abi.qms.platform.service.ReportService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import com.abi.task.common.api.base.BaseResponse;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @author lu
+ * @date 2021年06月09日 16:45
+ */
+@Slf4j
+@RestController
+@RequestMapping("/wxFactory")
+@Api(tags = "微信报表")
+public class WxFactoryController {
+
+    @Autowired
+    private ReportService reportService;
+
+    /**
+     *统计下单量
+     * @author lu
+     * @date 2021/6/10 11:35
+     * @param queryWxFactoryReq
+     * @return com.abi.task.common.api.base.BaseResponse<com.abi.qms.platform.dto.res.QueryWxFactoryRes>
+     */
+    @ApiOperation("统计下单量")
+    @GetMapping("/queryWxFactory")
+    public BaseResponse<QueryWxFactoryRes> queryWxFactory(@Validated QueryWxFactoryReq queryWxFactoryReq) {
+        QueryWxFactoryRes queryWxFactoryRes = reportService.queryWxFactory(queryWxFactoryReq);
+        return BaseResponse.create(queryWxFactoryRes);
+    }
+}

+ 12 - 4
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/dao/mapper/ReportServiceMapper.java

@@ -1,9 +1,7 @@
 package com.abi.qms.platform.dao.mapper;
 
-import com.abi.qms.platform.dao.vo.result.ListBrandCodeReportVO;
-import com.abi.qms.platform.dao.vo.result.ListFactoryCodeReportVO;
-import com.abi.qms.platform.dao.vo.result.ListPackageCodeVo;
-import com.abi.qms.platform.dao.vo.result.ListMaterialCodeReportVO;
+import com.abi.qms.platform.dao.vo.result.*;
+import com.abi.qms.platform.dto.req.QueryWxFactoryReq;
 import com.abi.qms.platform.dto.req.ReportReq;
 import org.apache.ibatis.annotations.Param;
 
@@ -56,4 +54,14 @@ public interface ReportServiceMapper  {
      * @return
      */
     List<ListFactoryCodeReportVO> queryFactoryCodeTotal(@Param("reportReq") ReportReq reportReq, @Param("isDownload") Integer isDownload);
+
+    /**
+     * 统计下单量
+     * @author lu
+     * @date 2021/6/10 11:36
+     * @param req
+     * @return java.util.List<com.abi.qms.platform.dao.vo.result.QueryWxFactoryVO>
+     */
+    List<QueryWxFactoryVO> queryWxFactory(@Param("req")QueryWxFactoryReq req);
+
 }

+ 27 - 0
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/dao/vo/result/QueryWxFactoryVO.java

@@ -0,0 +1,27 @@
+package com.abi.qms.platform.dao.vo.result;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.time.LocalDateTime;
+
+/**
+ * @author lu
+ * @date 2021年06月09日 17:09
+ */
+@Data
+@ApiModel
+public class QueryWxFactoryVO implements Serializable {
+
+    @ApiModelProperty("下单量")
+    private Long total;
+
+    @ApiModelProperty("激活量")
+    private Long activation;
+
+    @ApiModelProperty(value = "月")
+    private String march;
+
+}

+ 5 - 1
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/dto/req/QueryListBreweryProductionLineReq.java

@@ -15,8 +15,12 @@ import java.io.Serializable;
 @ApiModel
 public class QueryListBreweryProductionLineReq implements Serializable {
 
-    @NotNull(message = "用户ID")
+    @NotNull(message = "用户ID为空")
     @ApiModelProperty(value = "用户ID")
     private Long userId;
 
+    @NotNull(message = "啤酒厂ID为空")
+    @ApiModelProperty(value = "啤酒厂ID")
+    private Long beerFactoryId;
+
 }

+ 29 - 0
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/dto/req/QueryWxFactoryReq.java

@@ -0,0 +1,29 @@
+package com.abi.qms.platform.dto.req;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+import java.io.Serializable;
+import java.time.LocalDateTime;
+
+/**
+ * @author lu
+ * @date 2021年06月09日 17:03
+ */
+@Data
+@ApiModel
+public class QueryWxFactoryReq implements Serializable {
+
+    @NotNull(message = "啤酒厂ID为空")
+    @ApiModelProperty(value = "啤酒厂ID")
+    private Long factoryBeerId;
+
+    @ApiModelProperty(value = "现在时间")
+    private LocalDateTime now;
+
+    @ApiModelProperty(value = "前三个月时间")
+    private LocalDateTime month;
+
+}

+ 44 - 0
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/dto/res/QueryWxFactoryRes.java

@@ -0,0 +1,44 @@
+package com.abi.qms.platform.dto.res;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.ToString;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * @author lu
+ * @date 2021年06月09日 17:12
+ */
+@Data
+@ApiModel
+public class QueryWxFactoryRes implements Serializable {
+
+    @ApiModelProperty("报表列表")
+    List<QueryWxFactoryBean> queryWxFactoryBeanList;
+
+    @Data
+    @NoArgsConstructor
+    @AllArgsConstructor
+    @ToString
+    @ApiModel(value = "QueryOrderFormLimitRes_QueryWxFactoryBean")
+    public static class QueryWxFactoryBean implements Serializable{
+
+        @ApiModelProperty("下单量")
+        private Long total;
+
+        @ApiModelProperty("激活量")
+        private Long activation;
+
+        @ApiModelProperty("库存")
+        private Long inStock;
+
+        @ApiModelProperty(value = "月")
+        private String march;
+    }
+
+}

+ 12 - 4
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/service/ReportService.java

@@ -1,10 +1,8 @@
 package com.abi.qms.platform.service;
 
+import com.abi.qms.platform.dto.req.QueryWxFactoryReq;
 import com.abi.qms.platform.dto.req.ReportReq;
-import com.abi.qms.platform.dto.res.ListBrandCodeReportRes;
-import com.abi.qms.platform.dto.res.ListFactoryCodeReportRes;
-import com.abi.qms.platform.dto.res.PackageCodeTypeRes;
-import com.abi.qms.platform.dto.res.ListMaterialCodeRankingReportRes;
+import com.abi.qms.platform.dto.res.*;
 
 /**
  * @author ludashi
@@ -45,4 +43,14 @@ public interface ReportService {
      * @return
      */
     ListFactoryCodeReportRes queryFactoryCodeTotalReport(ReportReq reportReq);
+
+    /**
+     * 统计下单量
+     * @author lu
+     * @date 2021/6/10 11:35
+     * @param queryWxFactoryReq
+     * @return com.abi.qms.platform.dto.res.QueryWxFactoryRes
+     */
+    QueryWxFactoryRes queryWxFactory(QueryWxFactoryReq queryWxFactoryReq);
+
 }

+ 11 - 1
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/service/impl/BreweryProductionLineServiceImpl.java

@@ -7,6 +7,7 @@ import com.abi.qms.platform.dto.req.QueryListBreweryProductionLineReq;
 import com.abi.qms.platform.dto.req.SaveBreweryProductionLineReq;
 import com.abi.qms.platform.dto.res.QueryListBreweryProductionLineRes;
 import com.abi.qms.platform.infrastructure.util.AssertUtil;
+import com.abi.qms.platform.infrastructure.util.UserUtil;
 import com.abi.qms.platform.service.BreweryProductionLineService;
 import com.abi.task.common.api.exception.BusinessException;
 import com.abi.task.common.utils.PojoConverterUtils;
@@ -26,6 +27,9 @@ public class BreweryProductionLineServiceImpl implements BreweryProductionLineSe
     @Autowired
     private BreweryProductionLineMapper breweryProductionLineMapper;
 
+    @Autowired
+    private UserUtil userUtil;
+
     /**
      * 新增接口
      * @author lu
@@ -74,9 +78,15 @@ public class BreweryProductionLineServiceImpl implements BreweryProductionLineSe
      */
     @Override
     public QueryListBreweryProductionLineRes queryListBreweryProductionLine(QueryListBreweryProductionLineReq req) {
+        // 是小程序用户主账号 1-是 0-不是
+        Integer isMainAccount = userUtil.getWholeUser().getIsMainAccount();
         QueryWrapper<BreweryProductionLine> query = new QueryWrapper<>();
-        query.eq("user_id",req.getUserId());
         query.eq("is_delete",0);
+        if (isMainAccount.equals(0)) {
+            query.eq("user_id",req.getUserId());
+        } else {
+            query.eq("beer_factory_id",req.getBeerFactoryId());
+        }
         List<BreweryProductionLine> breweryProductionLines = breweryProductionLineMapper.selectList(query);
         //封装出参
         QueryListBreweryProductionLineRes res = new QueryListBreweryProductionLineRes();

+ 67 - 8
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/service/impl/ReportServiceImpl.java

@@ -2,15 +2,12 @@ package com.abi.qms.platform.service.impl;
 
 import com.abi.qms.platform.dao.enums.QrTypeEnum;
 import com.abi.qms.platform.dao.mapper.ReportServiceMapper;
-import com.abi.qms.platform.dao.vo.result.ListBrandCodeReportVO;
-import com.abi.qms.platform.dao.vo.result.ListFactoryCodeReportVO;
-import com.abi.qms.platform.dao.vo.result.ListMaterialCodeReportVO;
-import com.abi.qms.platform.dao.vo.result.ListPackageCodeVo;
+import com.abi.qms.platform.dao.vo.result.*;
+import com.abi.qms.platform.dto.req.QueryWxFactoryReq;
 import com.abi.qms.platform.dto.req.ReportReq;
-import com.abi.qms.platform.dto.res.ListBrandCodeReportRes;
-import com.abi.qms.platform.dto.res.ListFactoryCodeReportRes;
-import com.abi.qms.platform.dto.res.ListMaterialCodeRankingReportRes;
-import com.abi.qms.platform.dto.res.PackageCodeTypeRes;
+import com.abi.qms.platform.dto.res.*;
+import com.abi.qms.platform.infrastructure.util.AssertUtil;
+import com.abi.qms.platform.infrastructure.util.UserUtil;
 import com.abi.qms.platform.service.ReportService;
 import com.abi.task.common.utils.PojoConverterUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -40,6 +37,10 @@ public class ReportServiceImpl implements ReportService {
     @Autowired
     private ReportServiceMapper reportServiceMapper;
 
+    @Autowired
+    private UserUtil userUtil;
+
+
     /**
      * 品牌使用码量占比(603版 已废弃)
      *
@@ -117,6 +118,51 @@ public class ReportServiceImpl implements ReportService {
         return res;
     }
 
+    /**
+     * 统计下单量
+     * @author lu
+     * @date 2021/6/10 11:35
+     * @param queryWxFactoryReq
+     * @return com.abi.qms.platform.dto.res.QueryWxFactoryRes
+     */
+    @Override
+    public QueryWxFactoryRes queryWxFactory(QueryWxFactoryReq queryWxFactoryReq) {
+        // 是小程序用户主账号 1-是 0-不是
+        Integer isMainAccount = userUtil.getWholeUser().getIsMainAccount();
+        QueryWxFactoryRes res = new QueryWxFactoryRes();
+        if (isMainAccount.equals(0)) {
+            //子账号报表
+            //获取现在时间
+            queryWxFactoryReq.setNow(LocalDateTime.now());
+            //获取前三个月的时间
+            queryWxFactoryReq.setMonth(getMonth());
+            List<QueryWxFactoryVO> queryWxFactoryVO = reportServiceMapper.queryWxFactory(queryWxFactoryReq);
+            AssertUtil.isNull(queryWxFactoryVO,"报表数据查询为空");
+            List<QueryWxFactoryRes.QueryWxFactoryBean> queryWxFactoryBeans = PojoConverterUtils.copyList(queryWxFactoryVO, QueryWxFactoryRes.QueryWxFactoryBean.class);
+            queryWxFactoryBeans.forEach(beans->{
+                beans.setInStock(beans.getTotal() - beans.getActivation());
+            });
+            res.setQueryWxFactoryBeanList(queryWxFactoryBeans);
+            return res;
+        }
+        //下单量-激活量-库存
+        List<QueryWxFactoryVO> queryWxFactoryVO = reportServiceMapper.queryWxFactory(queryWxFactoryReq);
+        AssertUtil.isNull(queryWxFactoryVO,"查询为空");
+        List<QueryWxFactoryRes.QueryWxFactoryBean> queryWxFactoryBeans = PojoConverterUtils.copyList(queryWxFactoryVO, QueryWxFactoryRes.QueryWxFactoryBean.class);
+        Long total = queryWxFactoryBeans.stream().mapToLong(QueryWxFactoryRes.QueryWxFactoryBean::getTotal).sum();
+        Long activation = queryWxFactoryBeans.stream().mapToLong(QueryWxFactoryRes.QueryWxFactoryBean::getActivation).sum();
+        Long stock= total-activation;
+        QueryWxFactoryRes.QueryWxFactoryBean factoryBean= new QueryWxFactoryRes.QueryWxFactoryBean();
+        factoryBean.setActivation(activation);
+        factoryBean.setInStock(stock);
+        factoryBean.setTotal(total);
+        List<QueryWxFactoryRes.QueryWxFactoryBean> list = new ArrayList<>();
+        list.add(factoryBean);
+        res.setQueryWxFactoryBeanList(list);
+        return res;
+
+    }
+
     /**
      * 设置时间区间值
      * @param reportReq
@@ -366,4 +412,17 @@ public class ReportServiceImpl implements ReportService {
         return map;
     }
 
+
+    private LocalDateTime getMonth(){
+        Calendar calStart = Calendar.getInstance();
+        calStart.add(Calendar.MONTH, -3);//上一月
+        calStart.set(Calendar.DAY_OF_MONTH, 1);
+        calStart.set(Calendar.HOUR_OF_DAY, 0);
+        calStart.set(Calendar.SECOND, 0);
+        calStart.set(Calendar.MINUTE, 0);
+        calStart.set(Calendar.MILLISECOND, 0);
+        Instant instant = calStart.toInstant();
+        ZoneId zoneId = ZoneId.systemDefault();
+        return instant.atZone(zoneId).toLocalDateTime();
+    }
 }

+ 19 - 0
abi-cloud-qr-platform-server/src/main/resources/dao/mapper/ReportServiceMapper.xml

@@ -100,6 +100,25 @@
         </where>
     </select>
 
+    <select id="queryWxFactory" resultType="com.abi.qms.platform.dao.vo.result.QueryWxFactoryVO">
+        SELECT
+            SUM( mapping.qr_code_count ) activation,
+            SUM( qpackage.qr_number ) total,
+            DATE_FORMAT( qpackage.create_time, "%Y-%m" ) march
+        FROM
+            qr_package AS qpackage
+            LEFT JOIN qr_box_mapping AS mapping ON qpackage.id = mapping.package_id
+        <where>
+            mapping.active_status = 1 AND qpackage.is_delete = 0
+            <if test="null != req.factoryBeerId and req.factoryBeerId != ''">
+                AND qpackage.factory_beer_id = #{req.factoryBeerId}
+            </if>
+            <if test="null != req.now and null != req.month">
+                AND #{req.month} <![CDATA[<=]]> qpackage.create_time <![CDATA[<=]]> #{req.now}
+            </if>
+        </where>
+        GROUP BY march
+    </select>
 
 
 </mapper>