KKSU
2023-11-07 86d405a84645893cffd72934dc8e35a8b59e2fcf
消息红包记录只储存36个小时
4 files modified
117 ■■■■ changed files
src/main/java/cc/mrbird/febs/mall/mapper/ChatUserMapper.java 11 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/mall/quartz/ProfitJob.java 49 ●●●● patch | view | raw | blame | history
src/main/resources/mapper/modules/ChatUserMapper.xml 24 ●●●●● patch | view | raw | blame | history
src/test/java/cc/mrbird/febs/ProfitTest.java 33 ●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/mall/mapper/ChatUserMapper.java
@@ -4,6 +4,7 @@
import cc.mrbird.febs.mall.entity.DataDictionary;
import cc.mrbird.febs.mall.entity.MemberCoinWithdraw;
import cc.mrbird.febs.mall.vo.*;
import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -82,4 +83,14 @@
    void updatePortraitById(@Param("userId")Long userId, @Param("portrait")String portrait);
    void updateGetBoomByUserId(@Param("userId")String userId, @Param("getBoom")int i);
    void deleteMsgByCreateTime(@Param("dateTime")Date dateTime);
    List<Long> selectChatRedBagByCreateTime(@Param("dateTime")DateTime dateTime);
    void deleteChatRedBagById(@Param("id")Long aLong);
    List<Long> selectChatRedBagRecordByRebBagId(@Param("id")Long aLong);
    void deleteChatRedBagRecordById(@Param("id")Long aLong1);
}
src/main/java/cc/mrbird/febs/mall/quartz/ProfitJob.java
@@ -32,6 +32,7 @@
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;
@@ -52,19 +53,6 @@
    @Resource
    private AgentProducer agentProducer;
    public static void main(String[] args) {
        for(int i = 0; i< 10 ;i++){
            int randomInt = RandomUtil.randomInt(1, 5);
            System.out.println(randomInt);
            try {
                Thread.sleep(randomInt * 1000L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(i);
        }
    }
    /**
     * 自动发送红包定时器
@@ -103,4 +91,39 @@
            }
        }
    }
    @Scheduled(cron = "0 0 0 * * ? ")
    public void deleteMsg() {
        DateTime date = DateUtil.date();
        DateTime dateTime = DateUtil.offsetHour(date, -36);
        chatUserMapper.deleteMsgByCreateTime(dateTime);
        List<Long> ids = chatUserMapper.selectChatRedBagByCreateTime(dateTime);
        if(CollUtil.isNotEmpty(ids)){
            Long aLong = ids.get(0);
            chatUserMapper.deleteChatRedBagById(aLong);
            List<Long> recordIds = chatUserMapper.selectChatRedBagRecordByRebBagId(aLong);
            if(CollUtil.isNotEmpty(recordIds)){
                Long aLong1 = recordIds.get(0);
                chatUserMapper.deleteChatRedBagRecordById(aLong1);
            }
        }
    }
    public static void main(String[] args) {
        DateTime date = DateUtil.date();
        System.out.println(date);
        ArrayList<DateTime> objects = new ArrayList<>();
        for(int i = 0;i<= 10 ;i++){
            DateTime dateTime = DateUtil.offsetHour(date, -i);
            objects.add(dateTime);
        }
        System.out.println(objects.size());
        System.out.println(objects);
        objects.remove(0);
        System.out.println(objects);
        System.out.println(objects.size());
    }
}
src/main/resources/mapper/modules/ChatUserMapper.xml
@@ -452,5 +452,29 @@
        where user_id = #{userId}
    </update>
    <delete  id="deleteMsgByCreateTime">
        DELETE from chat_msg where create_time &lt; #{dateTime}
    </delete>
    <select id="selectChatRedBagByCreateTime" resultType="java.lang.Long">
        select id
        from chat_red_bag
        where create_time &lt; #{dateTime} order By create_time desc limit 1
    </select>
    <delete  id="deleteChatRedBagById">
        DELETE from chat_red_bag where id &lt; #{id}
    </delete>
    <select id="selectChatRedBagRecordByRebBagId" resultType="java.lang.Long">
        select id
        from chat_red_bag_record
        where red_bag_id = #{id}
    </select>
    <delete  id="deleteChatRedBagRecordById">
        DELETE from chat_red_bag_record where id &lt; #{id}
    </delete>
</mapper>
src/test/java/cc/mrbird/febs/ProfitTest.java
@@ -1,12 +1,17 @@
package cc.mrbird.febs;
import cc.mrbird.febs.mall.mapper.ChatUserMapper;
import cc.mrbird.febs.mall.service.IAgentService;
import cc.mrbird.febs.rabbit.producter.AgentProducer;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.math.BigDecimal;
import java.util.List;
/**
 * @author wzy
@@ -34,21 +39,39 @@
//
    @Autowired
    private AgentProducer agentProducer;
//
    @Autowired
    private ChatUserMapper chatUserMapper;
////
////    @Autowired
////    private IMemberProfitService memberProfitService;
////
    @Test
    public void dynamicProfit() {
        for(int i =0;i<400;i++){
        for(int i =0;i<75;i++){
            agentProducer.sendAddRobotMsg("32074345");
        }
//        agentService.autoUpAgentLevel(640L);
    }
//    @Test
//    public void agentProfit() {
//        memberProfitService.agentProfit(null);
//    }
    @Test
    public void agentProfit() {
        DateTime date = DateUtil.date();
        DateTime dateTime = DateUtil.offsetHour(date, -26);
        System.out.println("dateTime:"+dateTime);
        chatUserMapper.deleteMsgByCreateTime(dateTime);
        List<Long> ids = chatUserMapper.selectChatRedBagByCreateTime(dateTime);
        if(CollUtil.isNotEmpty(ids)){
            Long aLong = ids.get(0);
            chatUserMapper.deleteChatRedBagById(aLong);
            List<Long> recordIds = chatUserMapper.selectChatRedBagRecordByRebBagId(aLong);
            if(CollUtil.isNotEmpty(recordIds)){
                Long aLong1 = recordIds.get(0);
                chatUserMapper.deleteChatRedBagRecordById(aLong1);
            }
        }
    }
//
//
////    @Test