Jelajahi Sumber

Merge branch 'dev_v1.3.5_20220927'

Eric 3 tahun lalu
induk
melakukan
c2ad77d8ce

+ 8 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/mapper/CouponIssueMapper.java

@@ -33,4 +33,12 @@ public interface CouponIssueMapper extends BaseMapper<CouponIssue> {
      * @return List<StatGroupWrapper>
      */
     List<StatGroupWrapper> selectCouponStateStatInfo(@Param("userId") Long id, @Param("record") CouponInfoQuery.CouponStateStatQuery query);
+
+    /**
+     * 用户发送优惠券统计
+     * @param couponId 优惠券ID
+     * @param statQuery CouponInfoQuery.IssueStatQuery
+     * @return List<StatGroupWrapper>
+     */
+    List<StatGroupWrapper> selectCouponIssueStatInfo(@Param("couponId") Long couponId, @Param("record") CouponInfoQuery.IssueStatQuery statQuery);
 }

+ 3 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/queryInfo/CouponInfoQuery.java

@@ -68,6 +68,9 @@ public class CouponInfoQuery implements Serializable {
 
         // 状态排除
         private List<CouponUseStateEnum> excludeUseState;
+
+        // 发送用户
+        private List<Long> userIds;
     }
 
     /**

+ 18 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/CouponIssueServiceImp.java

@@ -26,6 +26,7 @@ import com.yonge.cooleshow.biz.dal.vo.coupon.CouponIssueWrapper;
 import com.yonge.cooleshow.biz.dal.wrapper.StatGroupWrapper;
 import com.yonge.cooleshow.common.enums.EStatus;
 import com.yonge.toolset.base.exception.BizException;
+import com.yonge.toolset.base.string.MessageFormatter;
 import com.yonge.toolset.thirdparty.message.MessageSenderPluginContext;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
@@ -36,6 +37,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.text.MessageFormat;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.LocalTime;
@@ -167,6 +169,22 @@ public class CouponIssueServiceImp extends ServiceImpl<CouponIssueMapper, Coupon
             if (!throwE) return false;
             throw new BizException("优惠券已被禁用");
         }
+
+        List<Long> userIds = userParam.stream()
+                .map(UserParam::getUserId).distinct().collect(Collectors.toList());
+        // 判断用户领取数据限制
+        if (Optional.ofNullable(couponInfo.getQuantityLimit()).orElse(0) > 0
+                && CollectionUtils.isNotEmpty(userIds)) {
+
+            CouponInfoQuery.IssueStatQuery statQuery = CouponInfoQuery.IssueStatQuery.builder().userIds(userIds).build();
+            // 统计用户领取优惠券数量
+            List<StatGroupWrapper> groupWrappers = getBaseMapper().selectCouponIssueStatInfo(couponId, statQuery);
+
+            if (groupWrappers.stream().anyMatch(x -> x.getTotal() >= couponInfo.getQuantityLimit())) {
+                throw new BizException(MessageFormat.format("优惠券已领取,每人仅限{0}张", couponInfo.getQuantityLimit()));
+            }
+        }
+
         // 判断优惠券类型 设置优惠券时间
         Long startTime = null;
         Long endTime = null;

+ 15 - 1
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/vo/CourseStudent.java

@@ -5,6 +5,8 @@ import io.swagger.annotations.ApiModelProperty;
 
 import java.io.Serializable;
 import java.util.Date;
+import java.util.Objects;
+import java.util.Optional;
 
 /**
  * @Author: cy
@@ -65,6 +67,9 @@ public class CourseStudent implements Serializable {
     @ApiModelProperty(value = "老师评价 0:未评价 1:已评价")
     private Integer teacherReplied;
 
+    @ApiModelProperty(value = "课程名称")
+    private String courseName;
+
     public Integer getStudentReplied() {
         return studentReplied;
     }
@@ -154,7 +159,8 @@ public class CourseStudent implements Serializable {
     }
 
     public String getName() {
-        return name;
+
+        return Optional.ofNullable(name).orElse(getCourseName());
     }
 
     public void setName(String name) {
@@ -208,5 +214,13 @@ public class CourseStudent implements Serializable {
     public void setImGroupId(String imGroupId) {
         this.imGroupId = imGroupId;
     }
+
+    public String getCourseName() {
+        return courseName;
+    }
+
+    public void setCourseName(String courseName) {
+        this.courseName = courseName;
+    }
 }
 

+ 15 - 0
cooleshow-user/user-biz/src/main/resources/config/mybatis/CouponIssueMapper.xml

@@ -159,4 +159,19 @@
         <if test="record.groupByState != null">GROUP BY t1.use_state_</if>
     </select>
     <!--用户优惠券状态统计-->
+
+    <!--用户发送优惠券统计-->
+    <select id="selectCouponIssueStatInfo" resultType="com.yonge.cooleshow.biz.dal.wrapper.StatGroupWrapper">
+        SELECT t1.user_id_ AS id, COUNT(DISTINCT t1.id_) AS total FROM coupon_issue t1
+        <where>
+            <if test="couponId != null">
+                AND t1.coupon_id_ = #{couponId}
+            </if>
+            <if test="record.userIds != null">
+                AND t1.user_id_ IN (<foreach collection="record.userIds" separator="," item="item">#{item}</foreach>)
+            </if>
+        </where>
+        GROUP BY t1.user_id_
+    </select>
+    <!--用户发送优惠券统计-->
 </mapper>

+ 6 - 2
cooleshow-user/user-biz/src/main/resources/config/mybatis/CourseScheduleMapper.xml

@@ -331,8 +331,9 @@
             cs.end_time_ AS endTime,
             cs.status_ AS `status`,
             cs.type_ AS courseType,
+            CONCAT(g.name_,'-第',cs.class_num_,'课') AS courseName,
             NULL AS userId,
-            CONCAT(g.name_,'-第',cs.class_num_,'课') AS name,
+            NULL AS name,
             NULL AS realName,
             p.payCount AS payCount,
             g.background_pic_ AS cover,
@@ -371,6 +372,7 @@
             cs.end_time_ AS endTime,
             cs.status_ AS `status`,
             cs.type_ AS courseType,
+            NULL AS courseName,
             u.id_ AS userId,
             u.username_ AS name,
             u.real_name_ AS realName,
@@ -467,6 +469,7 @@
             s.end_time_ AS endTime,
             s.type_ AS courseType,
             s.status_ AS `status`,
+            NULL AS courseName,
             u.id_ AS userId,
             u.username_ AS name,
             u.real_name_ AS realName,
@@ -497,8 +500,9 @@
             s.end_time_ AS endTime,
             s.type_ AS courseType,
             s.status_ AS `status`,
+            CONCAT(g.name_,'-第',s.class_num_,'课') AS courseName,
             NULL AS userId,
-            CONCAT(g.name_,'-第',s.class_num_,'课') AS name,
+            NULL AS name,
             NULL AS realName,
             g.background_pic_ AS cover,
             g.subject_id_ AS subjectId,