ソースを参照

酷乐秀优化

zouxuan 8 ヶ月 前
コミット
49ad23dabe

+ 10 - 8
cooleshow-app/src/main/java/com/yonge/cooleshow/student/task/TaskController.java

@@ -1,10 +1,7 @@
 package com.yonge.cooleshow.student.task;
 
 import com.yonge.cooleshow.biz.dal.entity.StudentTotal;
-import com.yonge.cooleshow.biz.dal.service.CourseRepliedService;
-import com.yonge.cooleshow.biz.dal.service.StudentTimeService;
-import com.yonge.cooleshow.biz.dal.service.StudentTotalService;
-import com.yonge.cooleshow.biz.dal.service.VipCardRecordService;
+import com.yonge.cooleshow.biz.dal.service.*;
 import com.yonge.cooleshow.common.controller.BaseController;
 import com.yonge.cooleshow.common.entity.HttpResponseResult;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -13,6 +10,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 import springfox.documentation.annotations.ApiIgnore;
 
+import javax.annotation.Resource;
 import java.util.List;
 
 /**
@@ -23,13 +21,15 @@ import java.util.List;
 @RequestMapping("${app-config.url.student:}/task")
 @ApiIgnore
 public class TaskController extends BaseController {
-    @Autowired
+    @Resource
     private StudentTotalService studentTotalService;
-    @Autowired
+    @Resource
     private StudentTimeService studentTimeService;
-    @Autowired
+    @Resource
     private VipCardRecordService vipCardRecordService;
-    @Autowired
+    @Resource
+    private DiscountCardRecordService discountCardRecordService;
+    @Resource
     private CourseRepliedService repliedService;
     /***
      * 查询所有学生统计数据
@@ -52,6 +52,8 @@ public class TaskController extends BaseController {
     public HttpResponseResult<Boolean> halfHourTask() {
         //会员卡到期提醒
         vipCardRecordService.pollExpireMsg();
+        //畅学卡到期提醒
+        discountCardRecordService.pollExpireMsg();
         return succeed(true);
     }
 

+ 1 - 1
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/entity/UserTenantAlbumRecord.java

@@ -87,7 +87,7 @@ public class UserTenantAlbumRecord implements Serializable {
 	@TableField(value = "times_")
     private Integer times;
 
-    @ApiModelProperty("消息发送 0、未发送 1、已发送提前3天消息 2、已发送会员过期消息 暂时不用") 
+    @ApiModelProperty("消息发送 0、未发送 1、已发送提前3天消息 2、已发送会员过期消息")
 	@TableField(value = "msg_status_")
     private Boolean msgStatus;
 

+ 6 - 1
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/enums/MessageTypeEnum.java

@@ -82,11 +82,15 @@ public enum MessageTypeEnum implements BaseEnum<String, MessageTypeEnum> {
     SMS_NEW_VIP_BUY_SUCCESS("会员购买成功(短信)"),
     SMS_TEACHER_NEW_VIP_BUY_SUCCESS("会员购买成功(短信)"),
 
+    DISCOUNT_EXPIRE_THIRTY_DAY("畅学卡到期前3天"),
+
     VIP_EXPIRE_THIRTY_DAY("VIP会员到期前3天"),
     SVIP_EXPIRE_THIRTY_DAY("SVIP会员到期前3天"),
     SMS_VIP_EXPIRE_THIRTY_DAY("VIP会员到期前3天(短信)"),
     SMS_SVIP_EXPIRE_THIRTY_DAY("SVIP会员到期前3天(短信)"),
 
+    DISCOUNT_EXPIRE("畅学卡到期"),
+
     VIP_EXPIRE("VIP会员到期"),
     SVIP_EXPIRE("SVIP会员到期"),
     SMS_VIP_EXPIRE("VIP会员到期(短信)"),
@@ -159,7 +163,8 @@ public enum MessageTypeEnum implements BaseEnum<String, MessageTypeEnum> {
     TENANT_VIP_EXPIRE("平台会员到期"),
     TENANT_PLATFORM_ADD_VIP("后台添加平台会员"),
     TENANT_ALBUM_BUY("购买训练教程"),
-    TENANT_ALBUM_EXPIRE("训练教程到期"),
+    TENANT_ALBUM_EXPIRE("训练教程即将到期"),
+    TENANT_ALBUM_EXPIRE_THIRTY_DAY("训练教程3天后到期"),
     TENANT_SEND_CODE("发放激活码"),
     TENANT_CODE_SENDCANCEL("激活码被撤回"),
     TENANT_MUSIC_BUY("购买曲目"),

+ 2 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/mapper/DiscountCardRecordMapper.java

@@ -17,4 +17,6 @@ import com.yonge.cooleshow.biz.dal.entity.DiscountCardRecord;
 public interface DiscountCardRecordMapper extends BaseMapper<DiscountCardRecord> {
 
     MemberPriceSettings detail(@Param("userId") Long userId, @Param("orderDetilId") Long orderDetilId);
+
+    void updateMsgStatus(@Param("ids") List<Long> ids, @Param("msgStatus") int msgStatus);
 }

+ 2 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/mapper/UserTenantAlbumRecordMapper.java

@@ -41,4 +41,6 @@ public interface UserTenantAlbumRecordMapper extends BaseMapper<UserTenantAlbumR
     List<UserTenantAlbumRecordWrapper.UserTenantAlbumRecord> selectTemporaryRecord();
 
     List<TenantGroupAlbumWrapper.TenantAlbumSort> getTenantAlbumMaxCreateTime(@Param("userId") Long userId, @Param("clientType") ClientEnum clientType, @Param("tenantAlbumIds") List<Long> tenantAlbumIds);
+
+    void updateMsgStatus(@Param("ids") List<Long> ids, @Param("msgStatus") int msgStatus);
 }

+ 2 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/DiscountCardRecordService.java

@@ -12,4 +12,6 @@ public interface DiscountCardRecordService extends IService<DiscountCardRecord>
 
 
     void orderSuccess(UserOrderDetailVo userPaymentOrder);
+
+    void pollExpireMsg();
 }

+ 70 - 10
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/DiscountCardRecordServiceImpl.java

@@ -1,31 +1,34 @@
 package com.yonge.cooleshow.biz.dal.service.impl;
 
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.microsvc.toolkit.common.webportal.exception.BizException;
 import com.yonge.cooleshow.biz.dal.entity.DiscountCardRecord;
 import com.yonge.cooleshow.biz.dal.entity.Student;
-import com.yonge.cooleshow.biz.dal.enums.EVipRecordStatus;
-import com.yonge.cooleshow.biz.dal.enums.EVipType;
-import com.yonge.cooleshow.biz.dal.enums.SourceTypeEnum;
+import com.yonge.cooleshow.biz.dal.entity.SysUser;
+import com.yonge.cooleshow.biz.dal.enums.*;
 import com.yonge.cooleshow.biz.dal.mapper.DiscountCardRecordMapper;
-import com.yonge.cooleshow.biz.dal.service.DiscountCardRecordService;
-import com.yonge.cooleshow.biz.dal.service.MemberPriceSettingsService;
-import com.yonge.cooleshow.biz.dal.service.StudentService;
-import com.yonge.cooleshow.biz.dal.service.VipCardRecordService;
+import com.yonge.cooleshow.biz.dal.service.*;
 import com.yonge.cooleshow.biz.dal.vo.MemberPriceSettingsVo;
 import com.yonge.cooleshow.biz.dal.vo.UserOrderDetailVo;
+import com.yonge.cooleshow.biz.dal.vo.VipCardRecordVo;
 import com.yonge.cooleshow.biz.dal.wrapper.VipCardRecordWrapper;
+import com.yonge.toolset.thirdparty.message.MessageSenderPluginContext;
 import com.yonge.toolset.utils.date.DateUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import javax.annotation.Resource;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.LocalTime;
 import java.time.ZoneId;
 import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * 购买会员卡记录表
@@ -35,11 +38,14 @@ import java.util.Date;
 @Service
 public class DiscountCardRecordServiceImpl extends ServiceImpl<DiscountCardRecordMapper, DiscountCardRecord> implements DiscountCardRecordService {
 
-    @Autowired
+    @Resource
     private MemberPriceSettingsService memberPriceSettingsService;
-
-    @Autowired
+    @Resource
     private StudentService studentService;
+    @Resource
+    private SysUserService sysUserService;
+    @Resource
+    private SysMessageService sysMessageService;
 
     @Override
     @Transactional(rollbackFor = Exception.class)
@@ -113,4 +119,58 @@ public class DiscountCardRecordServiceImpl extends ServiceImpl<DiscountCardRecor
                 .update();
 
     }
+
+    @Override
+    public void pollExpireMsg() {
+        //会员提前三天提示
+        List<DiscountCardRecord> records = this.lambdaQuery()
+                .eq(DiscountCardRecord::getEfficientFlag, true)
+                .eq(DiscountCardRecord::getMsgStatus, 0)
+                .lt(DiscountCardRecord::getEndTime, DateUtil.localDateTimeToDate(LocalDateTime.now().plusDays(4)))
+                .list();
+        if(CollectionUtils.isNotEmpty(records)){
+            //获取用户编号
+            List<Long> userIds = records.stream().map(DiscountCardRecord::getUserId).collect(Collectors.toList());
+            Map<Long,String> receivers = sysUserService.getDao().selectBatchIds(userIds).stream().collect(Collectors.toMap(SysUser::getId, SysUser::getPhone));
+            temporary3DaysSend(receivers);
+            //更新状态
+            List<Long> ids = records.stream().map(DiscountCardRecord::getId).collect(Collectors.toList());
+            baseMapper.updateMsgStatus(ids,1);
+        }
+
+        //会员到期提示
+        List<DiscountCardRecord> expireRecords = this.lambdaQuery()
+                .eq(DiscountCardRecord::getEfficientFlag, true)
+                .in(DiscountCardRecord::getMsgStatus, 0,1)
+                .lt(DiscountCardRecord::getEndTime, DateUtil.localDateTimeToDate(LocalDateTime.now().plusDays(1)))
+                .list();
+        if (CollectionUtils.isNotEmpty(expireRecords)) {
+            //获取用户编号
+            List<Long> userIds = expireRecords.stream().map(DiscountCardRecord::getUserId).collect(Collectors.toList());
+            Map<Long,String> receivers = sysUserService.getDao().selectBatchIds(userIds).stream().collect(Collectors.toMap(SysUser::getId, SysUser::getPhone));
+            expireSend(receivers);
+            //更新状态
+            List<Long> ids = expireRecords.stream().map(DiscountCardRecord::getId).collect(Collectors.toList());
+            baseMapper.updateMsgStatus(ids,2);
+        }
+    }
+
+    private void temporary3DaysSend(Map<Long, String> receivers) {
+        try {
+            sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG,MessageTypeEnum.DISCOUNT_EXPIRE_THIRTY_DAY
+                    , receivers, null, 0, null, ClientEnum.STUDENT.getCode());
+        } catch (Exception e) {
+            log.error("畅学卡到期3天极光消息推送异常");
+        }
+    }
+
+    private void expireSend(Map<Long, String> receivers) {
+        try {
+            sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG,MessageTypeEnum.DISCOUNT_EXPIRE
+                    ,receivers, null, 0, null, ClientEnum.STUDENT.getCode());
+        } catch (Exception e) {
+            log.error("畅学卡到期极光消息推送异常");
+        }
+    }
+
 }

+ 16 - 37
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/UserTenantAlbumRecordServiceImpl.java

@@ -11,7 +11,6 @@ import com.google.common.collect.Lists;
 import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
 import com.yonge.cooleshow.auth.api.entity.SysUser;
 import com.yonge.cooleshow.biz.dal.dao.StudentDao;
-import com.yonge.cooleshow.biz.dal.dto.search.StudentMusicSheetSearch;
 import com.yonge.cooleshow.biz.dal.entity.*;
 import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
 import com.yonge.cooleshow.biz.dal.enums.MessageTypeEnum;
@@ -19,29 +18,25 @@ import com.yonge.cooleshow.biz.dal.enums.PeriodEnum;
 import com.yonge.cooleshow.biz.dal.enums.SubjectTypeEnum;
 import com.yonge.cooleshow.biz.dal.mapper.*;
 import com.yonge.cooleshow.biz.dal.service.*;
-import com.yonge.cooleshow.biz.dal.vo.MusicSheetVo;
 import com.yonge.cooleshow.biz.dal.vo.StudentVo;
 import com.yonge.cooleshow.biz.dal.wrapper.TenantAlbumWrapper;
 import com.yonge.cooleshow.biz.dal.wrapper.TenantGroupAlbumWrapper;
+import com.yonge.cooleshow.biz.dal.wrapper.UserTenantAlbumRecordWrapper;
 import com.yonge.cooleshow.common.enums.YesOrNoEnum;
 import com.yonge.toolset.base.exception.BizException;
-import com.yonge.toolset.mybatis.support.PageUtil;
 import com.yonge.toolset.thirdparty.message.MessageSenderPluginContext;
 import com.yonge.toolset.utils.obj.ObjectUtil;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.jetbrains.annotations.Nullable;
 import org.joda.time.DateTime;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import org.springframework.beans.BeanUtils;
-import lombok.extern.slf4j.Slf4j;
-import com.yonge.cooleshow.biz.dal.wrapper.UserTenantAlbumRecordWrapper;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
 import java.util.*;
-import java.util.concurrent.CompletableFuture;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 
@@ -665,25 +660,18 @@ public class UserTenantAlbumRecordServiceImpl extends ServiceImpl<UserTenantAlbu
 
     @Override
     public void sendTenantAlbumMessage() {
+        //3天内到期的专辑
         List<UserTenantAlbumRecordWrapper.UserTenantAlbumRecord> userTenantAlbumRecords = baseMapper.selectTemporaryRecord();
-        if (CollectionUtils.isEmpty(userTenantAlbumRecords)) {
-            return;
-        }
-        //标识
-        Map<Long, Long> temporaryFlagMap = new HashMap<>();
-        for (UserTenantAlbumRecordWrapper.UserTenantAlbumRecord record : userTenantAlbumRecords) {
-            if (null != temporaryFlagMap.get(record.getUserId())) {
-                continue;
-            }
-            temporaryFlagMap.put(record.getUserId(), record.getUserId());
+        if (CollectionUtils.isNotEmpty(userTenantAlbumRecords)) {
+            //获取专辑名称
+            List<Long> tenantAlbumIds = userTenantAlbumRecords.stream().map(UserTenantAlbumRecordWrapper.UserTenantAlbumRecord::getTenantAlbumId).collect(Collectors.toList());
+            Map<Long, String> albumIdMap = tenantAlbumService.lambdaQuery()
+                    .in(TenantAlbum::getId, tenantAlbumIds)
+                    .list().stream().collect(Collectors.toMap(TenantAlbum::getId, TenantAlbum::getName));
             //发送消息
-            CompletableFuture.runAsync(() -> temporarySend(record.getUserId(), record.getTenantAlbumId()));
-            UserTenantAlbumRecord userTenantAlbumRecord = new UserTenantAlbumRecord();
-            userTenantAlbumRecord.setMsgStatus(true);
-            userTenantAlbumRecord.setUpdateTime(new Date());
-            userTenantAlbumRecord.setId(record.getId());
-
-            baseMapper.updateById(userTenantAlbumRecord);
+            userTenantAlbumRecords.forEach(record -> temporary3DaySend(record.getUserId(),record.getPhone(), albumIdMap.get(record.getTenantAlbumId())));
+            List<Long> ids = userTenantAlbumRecords.stream().map(UserTenantAlbumRecordWrapper.UserTenantAlbumRecord::getId).collect(Collectors.toList());
+            baseMapper.updateMsgStatus(ids,1);
         }
     }
 
@@ -748,21 +736,12 @@ public class UserTenantAlbumRecordServiceImpl extends ServiceImpl<UserTenantAlbu
     }
 
 
-    private void temporarySend(Long userId, Long tenantAlbumId) {
-        SysUser sysUser = sysUserFeignService.queryUserById(userId);
-        if (null == sysUser) {
-            return;
-        }
-        TenantAlbum tenantAlbum = tenantAlbumService.getById(tenantAlbumId);
-        if (tenantAlbum == null) {
-            return;
-        }
+    private void temporary3DaySend(Long userId,String phone, String tenantAlbumName) {
         Map<Long, String> receivers = new HashMap<>();
-        receivers.put(userId, sysUser.getPhone());
-
+        receivers.put(userId, phone);
         try {
-            sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, MessageTypeEnum.TENANT_ALBUM_EXPIRE,
-                    receivers, null, 0, null, ClientEnum.TENANT_STUDENT.getCode(), tenantAlbum.getName());
+            sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, MessageTypeEnum.TENANT_ALBUM_EXPIRE_THIRTY_DAY,
+                    receivers, null, 0, null, ClientEnum.TENANT_STUDENT.getCode(),tenantAlbumName);
         } catch (Exception e) {
             log.error("机构学生训练教材过期", e);
         }

+ 2 - 2
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/VipCardRecordServiceImpl.java

@@ -204,7 +204,7 @@ public class VipCardRecordServiceImpl extends ServiceImpl<VipCardRecordDao, VipC
 
     @Override
     public void pollExpireMsg() {
-        //提前三天提示
+        //会员提前三天提示
         List<VipCardRecordVo> temporaryRecords = baseMapper.selectTemporaryRecord();
         if(CollectionUtils.isNotEmpty(temporaryRecords)){
             Map<ClientEnum,List<VipCardRecordVo>> map = temporaryRecords.stream().collect(Collectors.groupingBy(VipCardRecordVo::getClientType));
@@ -223,7 +223,7 @@ public class VipCardRecordServiceImpl extends ServiceImpl<VipCardRecordDao, VipC
             baseMapper.updateMsgStatus(ids,1);
         }
 
-        //到期提示
+        //会员到期提示
         List<VipCardRecordVo> expireRecords = baseMapper.selectExpireRecord();
         if (CollectionUtils.isNotEmpty(expireRecords)){
             Map<ClientEnum,List<VipCardRecordVo>> map = expireRecords.stream().collect(Collectors.groupingBy(VipCardRecordVo::getClientType));

+ 8 - 0
cooleshow-user/user-biz/src/main/resources/config/mybatis/DiscountCardRecordMapper.xml

@@ -29,6 +29,14 @@
         , t.efficient_flag_ AS efficientFlag
         , t.send_msg_ AS sendMsg
         </sql>
+    <update id="updateMsgStatus">
+        update discount_card_record
+        set msg_status_ = #{msgStatus},update_time_ = now()
+        where id_ IN
+        <foreach collection="ids" item="item" index="index" open="(" separator="," close=")">
+            #{item}
+        </foreach>
+    </update>
 
     <select id="detail" resultType="com.yonge.cooleshow.biz.dal.entity.MemberPriceSettings">
         SELECT

+ 11 - 3
cooleshow-user/user-biz/src/main/resources/config/mybatis/UserTenantAlbumRecordMapper.xml

@@ -23,8 +23,16 @@
         , t.times_ AS times
         , t.msg_status_ AS msgStatus
         , t.reason_ AS reason
-        </sql> 
-    
+        </sql>
+    <update id="updateMsgStatus">
+        update user_tenant_album_record
+        set msg_status_ = #{msgStatus},update_time_ = now()
+        where id_ IN
+        <foreach collection="ids" item="item" index="index" open="(" separator="," close=")">
+            #{item}
+        </foreach>
+    </update>
+
     <select id="selectPage" resultType="com.yonge.cooleshow.biz.dal.wrapper.TenantAlbumWrapper$TenantAlbum">
 		SELECT         
         	<include refid="baseColumns" />
@@ -87,7 +95,7 @@
         ) a
         left join user_tenant_album_record t on a.id_ = t.id_
         left join sys_user u on t.user_id_ = u.id_
-        where t.end_time_ &lt;= now()
+        where DATE_ADD(now(), INTERVAL 4 DAY) > t.end_time_
         and (msg_status_ = 0 or msg_status_ is null)
         order by end_time_ desc
     </select>

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

@@ -100,7 +100,7 @@
         having 1
         order by end_time_ desc) t
         group by t.user_id_, t.client_type_, t.vip_type_
-        having (DATE_ADD(now(), INTERVAL 3 DAY) > vipEndTime or DATE_ADD(now(), INTERVAL 3 DAY) > svipEndTime)
+        having (DATE_ADD(now(), INTERVAL 4 DAY) > vipEndTime or DATE_ADD(now(), INTERVAL 4 DAY) > svipEndTime)
         ) a
         left join vip_card_record t on a.id_ = t.id_
         left join sys_user u on t.user_id_ = u.id_
@@ -125,7 +125,7 @@
             having 1
             order by end_time_ desc) t
             group by t.user_id_, t.client_type_, t.vip_type_
-            having ( now() > vipEndTime or now()> svipEndTime)
+            having (DATE_ADD(now(), INTERVAL 1 DAY) > vipEndTime or DATE_ADD(now(), INTERVAL 1 DAY) > svipEndTime)
         ) a
         left join vip_card_record t on a.id_ = t.id_
         left join sys_user u on t.user_id_ = u.id_