发表于: 2017-11-01 21:56:45

2 732


一.今天完成的主要事情

1.完成批量任务的最后两个功能的实现(方案中只有一个,但是又加了一个功能,定时扫描消息表,向用户发送消息)

首先是销量统计的实现,该功能也是每天执行一次,所以使用cronTriggerBean

配置文件的配置为

该功能,每天上午四点,也就是凌晨四点统计一次,

实现逻辑依然是先获取数据,然后根据每个产品的id,统计销量,最后在销量统计表中新增相应记录

以下是获取产品IDList

然后是执行相应操作

 private void processForData(List<Long> productIds) throws ServiceException, ServiceDaoException, ParseException {

        log.info("process for data begin......");

        //获取前一天的0点和24点的时间戳

        Long[] times = SalesStatisticsUtil.getDate(SalesStatisticsUtil.STATUS_YESTERDAY);

        List<Sales> salesList = new ArrayList<Sales>();

        for (Long productId : productIds) {

            Map<String, Object> map = DynamicUtil.getUserProductRelationByStatusAndProductId(times,

                    UserProductRelation.STATUS_INVESTING, productId, false);

            List<Long> userProductRelationIds = userProductRelationService.getIdsByDynamicCondition(

                    UserProductRelation.class, map, 0, Integer.MAX_VALUE);

            log.info("get userProductRelationIds success, size is : " + userProductRelationIds.size());

            BigDecimal buyAmount = new BigDecimal("0");

            int buyTimes = 0;

            int buyerAmount = 0;

            if (CollectionUtils.isNotEmpty(userProductRelationIds)) {

                //获取符合条件的用户已投资产品

                List<UserProductRelation> userProductRelations = userProductRelationService.getObjectsByIds(

                        userProductRelationIds);

                //统计总购买次数

                buyTimes = userProductRelations.size();

                List<Long> userIds = new ArrayList<Long>();

                for (UserProductRelation userProductRelation : userProductRelations) {

                    userIds.add(userProductRelation.getUserId());

                    //计算总购买金额

                    buyAmount = buyAmount.add(userProductRelation.getInvestAmount());

                }

                //对用户进行除重后,得到总购买人数

                List<Long> buyerAmounts = SalesStatisticsUtil.removeDuplicatesList(userIds);

                buyerAmount = buyerAmounts.size();

            }

            Sales sales = new Sales();

            sales.setProductId(productId);

            sales.setDate(System.currentTimeMillis());

            sales.setBuyerAmount(buyerAmount);

            sales.setBuyAmount(buyAmount);

            sales.setBuyTimes(buyTimes);

            sales.setCreateBy(-1L);

            sales.setUpdateBy(-1L);

            salesList.add(sales);

        }

        //将插入销量表中的数据组合成为一个List,批量插入

        salesService.insertList(salesList);

    }

其次是完成定时消息发送的功能实现

实现逻辑如下:

先获取符合条件的公告消息,条件为:消息类型是公告消息,消息状态是草稿,发送时间>0并且小于当前时间

然后遍历该MessageList,根据发送人群字段统计要给所有用户发送多少条消息,给验证用户发送多少条消息,统计完毕之后,更新消息表,设置状态为上线

然后再依次遍历用户表中的记录,更改用户记录的相应字段

不同的用户新增的消息数不同

考虑到用户表的规模可能会越来越大,所以一次只执行100条用户的更新操作,循环操作,直至执行完毕,为简化代码,采用了do...while语句

二.明天计划完成的事情

1.实现上传图片功能

2.重构批量任务部分的代码

3.准备小课堂

三.遇到的问题

暂无

四.收获

以上,对定时任务的使用和执行流程更加熟悉

五.项目进度情况

个人负责的任务基本完成,至于整个项目,希望能够不用再次延期...


返回列表 返回列表
评论

    分享到