Browse Source

1.添加小组课,处理汇总统计错误

yuanliang 1 year ago
parent
commit
8d6cd69215

+ 27 - 6
mec-application/src/main/java/com/ym/mec/web/controller/open/OpenDouble11StaticsController.java

@@ -110,6 +110,13 @@ public class OpenDouble11StaticsController extends BaseController {
         result.setTotalSaleMaintenance(sporadic.getSaleAmount());
         result.setTotalUserMaintenancePurchaseNumber(sporadic.getUserPurchaseNumber());
 
+        // 小组课
+        query.setSaleStaticsType(7);
+        setQueryParam(query, configParam);
+        Double11StaticWrapper.SaleAmountAndUser smallGroups = studentPaymentOrderDao.saleStatics(query);
+        result.setSmallGroupsMaintenance(smallGroups.getSaleAmount());
+        result.setSmallGroupsPurchaseNumber(smallGroups.getUserPurchaseNumber());
+
         BigDecimal totalAmount = result.getTotalSale1V1()
                 .add(result.getTotalSale1V2())
                 .add(result.getTotalSaleMaintenance())
@@ -135,11 +142,15 @@ public class OpenDouble11StaticsController extends BaseController {
             Map<Integer, Organization> mapById = organizationService.getMapById(Arrays.stream(query.getOrganId()
                     .split(",")).map(Integer::valueOf).collect(Collectors.toList()));
             orgIdMap.putAll(mapById);
+            configParam.setOrganId(orgs.getParanValue());
         } else {
             List<Organization> allOrgans = organizationService.findAllOrgans(query.getTenantId());
             Map<Integer, Organization> mapById = allOrgans.stream()
                     .collect(Collectors.toMap(Organization::getId, Function.identity()));
             orgIdMap.putAll(mapById);
+            List<String> organId =
+                    allOrgans.stream().map(next -> String.valueOf(next.getId())).collect(Collectors.toList());
+            configParam.setOrganId(String.join(",", organId));
         }
         List<Double11StaticWrapper.SaleAmountAndUser> result;
         Integer saleStaticsType = query.getSaleStaticsType();
@@ -151,6 +162,13 @@ public class OpenDouble11StaticsController extends BaseController {
                 List<Double11StaticWrapper.SaleAmountAndUser> oneResult = queryOrgSaleAmount(query, orgIdMap);
                 allResult.addAll(oneResult);
             }
+
+            List<Double11StaticWrapper.StudentCount> studentNumByOrgan =
+                    studentPaymentOrderDao.count2023Double11StudentsByOrgan(configParam);
+            Map<Integer, Integer> countByOgranId = studentNumByOrgan.stream()
+                    .collect(Collectors.toMap(Double11StaticWrapper.StudentCount::getOrganId, Double11StaticWrapper.StudentCount::getCount));
+
+
             Map<Integer, List<Double11StaticWrapper.SaleAmountAndUser>> groupByOrg = allResult.stream()
                     .collect(Collectors.groupingBy(Double11StaticWrapper.SaleAmountAndUser::getOrganId));
             result = groupByOrg.entrySet().stream()
@@ -158,16 +176,11 @@ public class OpenDouble11StaticsController extends BaseController {
                         Double11StaticWrapper.SaleAmountAndUser amount = new Double11StaticWrapper.SaleAmountAndUser();
                         amount.setOrganId(entry.getKey());
                         amount.setOrganName(orgIdMap.getOrDefault(entry.getKey(), new Organization()).getName());
-                        Set<Integer> userIds = new HashSet<>();
                         for (Double11StaticWrapper.SaleAmountAndUser v : entry.getValue()) {
                             amount.setActualAmount(amount.getActualAmount().add(v.getActualAmount()));
                             amount.setBalancePaymentAmount(amount.getBalancePaymentAmount().add(v.getBalancePaymentAmount()));
-                            String userId = v.getUserIds();
-                            if (StringUtils.isNotEmpty(userId)) {
-                                userIds.addAll(Arrays.stream(userId.split(",")).map(Integer::valueOf).collect(Collectors.toList()));
-                            }
                         }
-                        amount.setUserPurchaseNumber(userIds.size());
+                        amount.setUserPurchaseNumber(countByOgranId.getOrDefault(entry.getKey(),0));
                         return amount;
                     }).collect(Collectors.toList());
         } else {
@@ -291,11 +304,19 @@ public class OpenDouble11StaticsController extends BaseController {
             query.setEndPayTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(
                     Optional.ofNullable(endTime.getParanValue()).orElse("2023-11-11 23:59:59"),
                     new ParsePosition(0)));
+            configParam.setStartPayTime(query.getStartPayTime());
+            configParam.setEndPayTime(query.getEndPayTime());
+            configParam.setGoodId(good.getParanValue());
         } else if (saleStaticsType == 6) {
             // 保价卡销售
             query.setGroupType(GroupType.SPORADIC);
             query.setType(OrderTypeEnum.SPORADIC);
             query.setMusicGroupId(configParam.getSporadic());
+        }else if (saleStaticsType == 7) {
+            // 小组课
+            query.setGroupType(GroupType.ACTIVITY);
+            query.setType(OrderTypeEnum.SMALL_CLASS_TO_BUY);
+            query.setActivityId(configParam.getTheory());
         }
     }
 

+ 2 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/StudentPaymentOrderDao.java

@@ -478,4 +478,6 @@ public interface StudentPaymentOrderDao extends BaseDAO<Long, StudentPaymentOrde
     List<Double11StaticWrapper.SaleStaticsStudent> queryPaymentStudentByPage(Map<String, Object> params);
 
     Integer queryPaymentStudentCount(Map<String, Object> params);
+
+    List<Double11StaticWrapper.StudentCount> count2023Double11StudentsByOrgan(@Param("param") Double11StaticWrapper.SaleStaticConfigParam configParam);
 }

+ 18 - 5
mec-biz/src/main/java/com/ym/mec/biz/dal/wrapper/Double11StaticWrapper.java

@@ -11,9 +11,7 @@ import javax.validation.constraints.NotNull;
 import javax.validation.constraints.Pattern;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
-import java.util.ArrayList;
 import java.util.Date;
-import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 
@@ -170,6 +168,12 @@ public class Double11StaticWrapper {
         @ApiModelProperty("保价卡销售购买人数")
         private Integer totalUserMaintenancePurchaseNumber;
 
+        @ApiModelProperty("小组课销售额")
+        private BigDecimal smallGroupsMaintenance;
+
+        @ApiModelProperty("小组课购买人数")
+        private Integer smallGroupsPurchaseNumber;
+
         @ApiModelProperty("分部ID")
         private Long orgId;
 
@@ -195,9 +199,6 @@ public class Double11StaticWrapper {
         private Integer userPurchaseNumber;
 
         @ApiModelProperty(hidden = true)
-        private String userIds;
-
-        @ApiModelProperty(hidden = true)
         private BigDecimal actualAmount = new BigDecimal(0);
 
         @ApiModelProperty(hidden = true)
@@ -221,6 +222,8 @@ public class Double11StaticWrapper {
         private String cloudTeacher;
         // 保价卡
         private String sporadic;
+        // 小组课
+        private String theory;
 
         private Map<String, Long> musical;
 
@@ -229,5 +232,15 @@ public class Double11StaticWrapper {
         private Date startPayTime;
 
         private Date endPayTime;
+
+        private String organId;
+
+        private String goodId;
+    }
+    @Data
+    public static class StudentCount {
+        private Integer organId;
+
+        private Integer count;
     }
 }

+ 55 - 1
mec-biz/src/main/resources/config/mybatis/StudentPaymentOrderMapper.xml

@@ -1294,7 +1294,6 @@
         , SUM(t.actual_amount_) AS 'actualAmount'
         , SUM(t.balance_payment_amount_) AS 'balancePaymentAmount'
         , COUNT(distinct t.user_id_) AS 'userPurchaseNumber'
-        , group_concat(distinct t.user_id_) AS 'userIds'
         FROM student_payment_order t
         <if test="param.goodId != null">
             LEFT JOIN sell_order so on t.order_no_ = so.order_no_
@@ -1418,4 +1417,59 @@
         </where>
     </select>
 
+    <select id="count2023Double11StudentsByOrgan" resultType="com.ym.mec.biz.dal.wrapper.Double11StaticWrapper$StudentCount">
+        select organ_id_ as organId, count(distinct user_id_) as count
+        from (select user_id_, organ_id_
+              from student_payment_order
+              where status_ = 'SUCCESS'
+                and group_type_ = 'VIP'
+                and type_ = 'SMALL_CLASS_TO_BUY'
+                and activity_id_ = #{param.v1}
+              union
+              select user_id_, organ_id_
+              from student_payment_order
+              where status_ = 'SUCCESS'
+                and group_type_ = 'VIP'
+                and type_ = 'SMALL_CLASS_TO_BUY'
+                and activity_id_ = #{param.v2}
+              union
+              SELECT user_id_, organ_id_
+              FROM student_payment_order
+              WHERE status_ = 'SUCCESS'
+                AND find_in_set(organ_id_, #{param.organId})
+                AND group_type_ = 'LIVE'
+                AND type_ = 'LIVE_GROUP_BUY'
+                AND find_in_set(music_group_id_, #{param.theoryLive})
+              union
+              select user_id_, organ_id_
+              from student_payment_order
+              where status_ = 'SUCCESS'
+                and group_type_ = 'MEMBER'
+                and type_ = 'MEMBER'
+                and activity_id_ = #{param.cloudTeacher}
+              union
+              select t.user_id_, t.organ_id_
+              from student_payment_order t
+                       LEFT join sell_order so on t.order_no_ = so.order_no_
+              where t.status_ = 'SUCCESS'
+                and find_in_set(so.goods_id_, #{param1.goodId})
+                and find_in_set(t.organ_id_, #{param.organId})
+                and t.pay_time_ between #{param.startPayTime} and #{param.endPayTime}
+              union
+              select user_id_
+                   , organ_id_
+              from student_payment_order
+              where status_ = 'SUCCESS'
+                and group_type_ = 'SPORADIC'
+                and type_ = 'SPORADIC'
+                and find_in_set(music_group_id_, #{param.sporadic})
+              union
+              select user_id_, organ_id_
+              from student_payment_order
+              where status_ = 'SUCCESS'
+                and group_type_ = 'VIP'
+                and type_ = 'SMALL_CLASS_TO_BUY'
+                and activity_id_ = #{param.theory}) t
+        group by organ_id_
+    </select>
 </mapper>