1. 程式人生 > >釘釘機器人推送資料

釘釘機器人推送資料

釘釘開放平臺地址:https://open-doc.dingtalk.com/docs/doc.htm?spm=a219a.7629140.0.0.karFPe&treeId=257&articleId=105735&docType=1

需求:統計14個抽獎指標的時-日-周-月以及環比的抽獎資料,格式如下

****************************
          抽獎活動
****************************
2018-12-12 14:00 - 15:00
-----------概況-----------
抽獎次數 500
(日 n% 周 m%)
抽獎人數 480
(日 n% 周 m%)
--------獎勵發放資料--------
抽得邀約資格次數 1000
(日 n% 周 m%)
抽得邀約資格人數 1000
(日 n% 周 m%)
抽得商城券次數 800
(日 n% 周 m%)
抽的商城券人數 800
(日 n% 周 m%)
抽得1元紅包次數 600
(日 n% 周 m%)
抽的1元紅包人數 600
(日 n% 周 m%)
--------獎勵使用資料--------
邀約資格使用數 200
(日 n% 周 m%)
邀約資格使用人數 200
(日 n% 周 m%)
商城券使用數 200元
(日 n% 周 m%)
商城券使用人數 200元
(日 n% 周 m%)
1元紅包提現數 1元
(日 n% 周 m%)
1元紅包提現人數 1元
(日 n% 周 m%)

****************************
當天截止到2018-12-12 15:00
-----------概況-----------
抽獎次數 500
(日 n% 周 m%)
抽獎人數 480
(日 n% 周 m%)
--------獎勵發放資料--------
抽得邀約資格次數 1000
(日 n% 周 m%)
抽得邀約資格人數 1000
(日 n% 周 m%)
抽得商城券次數 800
(日 n% 周 m%)
抽的商城券人數 800
(日 n% 周 m%)
抽得1元紅包次數 600
(日 n% 周 m%)
抽的1元紅包人數 600
(日 n% 周 m%)
--------獎勵使用資料--------
邀約資格使用數 200
(日 n% 周 m%)
邀約資格使用人數 200
(日 n% 周 m%)
商城券使用數 200元
(日 n% 周 m%)
商城券使用人數 200元
(日 n% 周 m%)
1元紅包提現數 1元
(日 n% 周 m%)
1元紅包提現人數 1元
(日 n% 周 m%)

****************************
本月截止到2018-12-12 15:00
-----------概況-----------
抽獎次數 500
(月 m%)
抽獎人數 480
(月 m%)
--------獎勵發放資料--------
抽得邀約資格次數 1000
(月 m%)
抽得邀約資格人數 1000
(月 m%)
抽得商城券次數 800
(月 m%)
抽的商城券人數 800
(月 m%)
抽得1元紅包次數 600
(月 m%)
抽的1元紅包人數 600
(月 m%)
--------獎勵使用資料--------
邀約資格使用數 200
(月 m%)
邀約資格使用人數 200
(月 m%)
商城券使用數 200元
(月 m%)
商城券使用人數 200元
(月 m%)
1元紅包提現數 1元
(月 m%)
1元紅包提現人數 1元
(月 m%)

抽象出一個公用的統計函式,14個指標公用即可

/**
 * 獲得統計指標的各項資料
 * @param className
 * @param methodName
 * @return
 */
public Map<String,String> getStatisticsInfo(String className, String methodName){
    try {

        Map<String, String> result = new HashMap<>();

        //通過Spring容器獲得Dao物件,不能直接獲取
        WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext();
        Class<?>  cls = wac.getBean(className).getClass();
        Method method = cls.getMethod(methodName, Map.class);


        //分時-今日數量
        Date now = new Date();
        String nowDate = DateTimeUtils.formatDateHH(now);
        String beginDate = DateTimeUtils.formatDateHH(DateTimeUtils.addHours(now, -1));
        Map<String, Object> drawPrizeHourParams = new HashMap<>();
        drawPrizeHourParams.put("beginDate", beginDate);
        drawPrizeHourParams.put("endDate", nowDate);
        Integer drawPrizeHour = (Integer) method.invoke(wac.getBean(className), drawPrizeHourParams);
        if(drawPrizeHour == null) {
            drawPrizeHour = 0;
        }
        result.put("drawPrizeHour", drawPrizeHour.toString());

        //分時-日環比
        String dayBeforeEndDate = DateTimeUtils.formatDateHH(DateTimeUtils.addDays(now, -1));
        String dayBeforeBeginDate = DateTimeUtils.formatDateHH(DateTimeUtils.addHours(DateTimeUtils.addDays(now, -1), -1));
        Map<String, Object> drawPrizeHourBeforeParams = new HashMap<>();
        drawPrizeHourBeforeParams.put("beginDate", dayBeforeBeginDate);
        drawPrizeHourBeforeParams.put("endDate", dayBeforeEndDate);
        Integer drawPrizeHourBefore = (Integer) method.invoke(wac.getBean(className), drawPrizeHourBeforeParams);
        if(drawPrizeHourBefore == null || drawPrizeHourBefore.intValue() == 0) {
            drawPrizeHourBefore = 1;
        }
        String hourDayBeforePercent = getPercent(drawPrizeHour.intValue(), drawPrizeHourBefore.intValue());
        result.put("hourDayCmpPercent", hourDayBeforePercent);

        //分時-周環比
        String weekBeforeEndDate = DateTimeUtils.formatDateHH(DateTimeUtils.addDays(now, -7));
        String weekBeforeBeginDate = DateTimeUtils.formatDateHH(DateTimeUtils.addHours(DateTimeUtils.addDays(now, -7), -1));
        Map<String, Object> drawPrizeHourWeekBeforeParams = new HashMap<>();
        drawPrizeHourWeekBeforeParams.put("beginDate", weekBeforeBeginDate);
        drawPrizeHourWeekBeforeParams.put("endDate", weekBeforeEndDate);
        Integer drawPrizeWeekBefore = (Integer) method.invoke(wac.getBean(className), drawPrizeHourWeekBeforeParams);
        if(drawPrizeWeekBefore == null || drawPrizeWeekBefore.intValue() == 0) {
            drawPrizeWeekBefore = 1;
        }
        String hourWeekBeforePercent = getPercent(drawPrizeHour.intValue(), drawPrizeWeekBefore.intValue());
        result.put("hourWeekCmpPercent", hourWeekBeforePercent);

        //當日截止統計時間-今日數量
        String dayDeadlineDate = DateTimeUtils.formatDateHH(now);
        String dayDeadlineBeginDate = DateTimeUtils.formatDate(now) + " 00:00:00";
        Map<String, Object> drawPrizeTodayParams = new HashMap<>();
        drawPrizeTodayParams.put("beginDate", dayDeadlineBeginDate);
        drawPrizeTodayParams.put("endDate", dayDeadlineDate);
        Integer drawPrizeToday = (Integer) method.invoke(wac.getBean(className), drawPrizeTodayParams);
        if(drawPrizeToday == null) {
            drawPrizeToday = 0;
        }
        result.put("drawPrizeToday", drawPrizeToday.toString());


        //當日截止統計時間-日環比
        String dayDeadlineBeforeEndDate = DateTimeUtils.formatDateHH(DateTimeUtils.addDays(now, -1));
        String dayDeadlineBeforeBeginDate = DateTimeUtils.formatDate(DateTimeUtils.addDays(now, -1)) + " 00:00:00";
        Map<String, Object> drawPrizeDayDeadlineBeforeParams = new HashMap<>();
        drawPrizeDayDeadlineBeforeParams.put("beginDate", dayDeadlineBeforeBeginDate);
        drawPrizeDayDeadlineBeforeParams.put("endDate", dayDeadlineBeforeEndDate);
        Integer drawPrizeDayDeadlineBefore = (Integer) method.invoke(wac.getBean(className), drawPrizeDayDeadlineBeforeParams);
        if(drawPrizeDayDeadlineBefore == null || drawPrizeDayDeadlineBefore.intValue() == 0) {
            drawPrizeDayDeadlineBefore = 1;
        }
        String dayDeadlineBeforePercent = getPercent(drawPrizeToday.intValue(), drawPrizeDayDeadlineBefore.intValue());
        result.put("dayDeadlineCmpPercent", dayDeadlineBeforePercent);

        //當日截止統計時間-周環比
        String weekDeadlineBeforeEndDate = DateTimeUtils.formatDateHH(DateTimeUtils.addDays(now, -7));
        String weekDeadlineBeforeBeginDate = DateTimeUtils.formatDate(DateTimeUtils.addDays(now, -7)) + " 00:00:00";
        Map<String, Object> drawPrizeWeekDeadlineBeforeParams = new HashMap<>();
        drawPrizeWeekDeadlineBeforeParams.put("beginDate", weekDeadlineBeforeBeginDate);
        drawPrizeWeekDeadlineBeforeParams.put("endDate", weekDeadlineBeforeEndDate);
        Integer drawPrizeWeekDeadlineBefore = (Integer) method.invoke(wac.getBean(className), drawPrizeWeekDeadlineBeforeParams);
        if(drawPrizeWeekDeadlineBefore == null || drawPrizeWeekDeadlineBefore.intValue() == 0) {
            drawPrizeWeekDeadlineBefore = 1;
        }
        String weekDeadlineBeforePercent = getPercent(drawPrizeToday.intValue(), drawPrizeWeekDeadlineBefore.intValue());
        result.put("weekDeadlineCmpPercent", weekDeadlineBeforePercent);

        //當日截止統計時間-本月數量
        String monthDeadlineDate = DateTimeUtils.formatDateHH(now);
        String monthDeadlineBeginDate = DateTimeUtils.formatDate(DateTimeUtils.beginDateOfMonth(now,0,1)) + " 00:00:00";
        Map<String, Object> drawPrizeMonthParams = new HashMap<>();
        drawPrizeMonthParams.put("beginDate", monthDeadlineBeginDate);
        drawPrizeMonthParams.put("endDate", monthDeadlineDate);
        Integer drawPrizeMonth = (Integer) method.invoke(wac.getBean(className), drawPrizeMonthParams);
        if(drawPrizeMonth == null) {
            drawPrizeMonth = 0;
        }
        result.put("drawPrizeMonth", drawPrizeMonth.toString());

        //當日截止統計時間-月環比
        String monthBeforeDeadlineDate = DateTimeUtils.formatDateHH(DateTimeUtils.addMonths(now,-1));
        String monthBeforeDeadlineBeginDate = DateTimeUtils.formatDate(DateTimeUtils.beginDateOfMonth(now,-1,1)) + " 00:00:00";
        Map<String, Object> drawPrizeMonthBeforeParams = new HashMap<>();
        drawPrizeMonthBeforeParams.put("beginDate", monthBeforeDeadlineBeginDate);
        drawPrizeMonthBeforeParams.put("endDate", monthBeforeDeadlineDate);
        Integer drawPrizeMonthBefore = (Integer) method.invoke(wac.getBean(className), drawPrizeMonthBeforeParams);
        if(drawPrizeMonthBefore == null || drawPrizeMonthBefore.intValue() == 0) {
            drawPrizeMonthBefore = 1;
        }
        String monthBeforePercent = getPercent(drawPrizeMonth.intValue(), drawPrizeMonthBefore.intValue());
        result.put("monthCmpPercent", monthBeforePercent);

        return result;
    } catch (NoSuchMethodException e) {
        LOG.error("DrawPrizeDingTalkSchedule.getStatisticsInfo 獲取統計指標NoSuchMethodException異常, className:{}, methodName:{},exp:{}",className,methodName,e);
        return null;
    } catch (IllegalAccessException e) {
        LOG.error("DrawPrizeDingTalkSchedule.getStatisticsInfo 獲取統計指標IllegalAccessException異常, className:{}, methodName:{},exp:{}",className,methodName,e);
        return null;
    } catch (InvocationTargetException e) {
        LOG.error("DrawPrizeDingTalkSchedule.getStatisticsInfo 獲取統計指標InvocationTargetException異常, className:{}, methodName:{},exp:{}",className,methodName,e);
        return null;
    } catch (Exception e){
        LOG.error("DrawPrizeDingTalkSchedule.getStatisticsInfo 獲取統計指標Exception異常, className:{}, methodName:{},exp:{}",className,methodName,e);
        return null;
    }
}

值得注意的是className不能傳Dao介面名,而必須傳Dao實現類的名稱(如activTaskLogDaoImpl),不然會因為Spring的動態代理,不能注入Dao,而且由於是統計資料,Dao走從庫,且SQL需要命中索引(SQL索引調優見https://blog.csdn.net/Wengzhengcun/article/details/85319453),另外,跨天時需要特殊處理(如2019-01-01 00:00:00需要轉為2018-12-31 23:59:59),完整程式碼如下:

@Service
public class DrawPrizeDingTalkSchedule {

    @Value(value = "${dingtalk.redpackage.data}")
    private String redPackageDingTalkAddress;

    private static final Logger LOG = LoggerFactory.getLogger(DrawPrizeDingTalkSchedule.class);

    /**
     * 定時排程
     * 每個整點統計抽獎活動資料
     */
    public void pushDrawInfo(){

        /**抽獎次數*/
        Map<String,String> drawPrizeNumberInfo = getStatisticsInfo("activTaskLogDaoImpl", "countDrawNumber");

        /**抽獎人數*/
        Map<String,String> manTimeInfo = getStatisticsInfo("activTaskLogDaoImpl", "countDrawPeople");

        /**抽得邀約資格次數*/
        Map<String,String> invitationNumberInfo = getStatisticsInfo("shareInventoryDetailDaoImpl", "countInvitationNumber");

        /**抽得邀約資格人數*/
        Map<String,String> invitationPeopleInfo = getStatisticsInfo("shareInventoryDetailDaoImpl", "countInvitationPeople");

        /**邀約資格使用數*/
        Map<String,String> invitationUsedNumberInfo = getStatisticsInfo("shareInventoryDetailDaoImpl", "countInvitationUsedNumber");

        /**邀約資格使用人數*/
        Map<String,String> invitationUsedPeopleInfo = getStatisticsInfo("shareInventoryDetailDaoImpl", "countInvitationUsedPeople");

        /**抽得1元紅包次數*/
        Map<String,String> oneYuanRpNumberInfo = getStatisticsInfo("activeCouponDetailDaoImpl", "countOneYuanRpNumber");

        /**抽得1元紅包人數*/
        Map<String,String> oneYuanRpPeopleInfo = getStatisticsInfo("activeCouponDetailDaoImpl", "countOneYuanRpPeople");

        /**1元紅包提現數*/
        Map<String,String> oneYuanRpWithdrawNumberInfo = getStatisticsInfo("activeCouponDetailDaoImpl", "countOneYuanRpWithdrawNumber");

        /**1元紅包提現人數*/
        Map<String,String> oneYuanRpWithdrawPeopleInfo = getStatisticsInfo("activeCouponDetailDaoImpl", "countOneYuanRpWithdrawPeople");

        /**抽得商城券次數*/
        Map<String,String> shopRpNumberInfo = getStatisticsInfo("activeCouponDetailDaoImpl", "countShopRpNumber");

        /**抽得商城券人數*/
        Map<String,String> shopRpPeopleInfo = getStatisticsInfo("activeCouponDetailDaoImpl", "countShopRpPeople");

        /**商城券使用數*/
        Map<String,String> shopRpWithdrawNumberInfo = getStatisticsInfo("activeCouponDetailDaoImpl", "countShopRpWithdrawNumber");

        /**商城券使用人數*/
        Map<String,String> shopRpWithdrawPeopleInfo = getStatisticsInfo("activeCouponDetailDaoImpl", "countShopRpWithdrawPeople");

        /**拼接釘釘訊息*/
        try {
            String content = "****************************\n"
                    +"          抽獎活動          "+"\n"
                    +"****************************\n"
                    + getHourZone() + "\n"
                    + "-----------概況-----------\n"
                    +"抽獎次數 " + drawPrizeNumberInfo.get("drawPrizeHour") + "\n"
                    +"(日 " + drawPrizeNumberInfo.get("hourDayCmpPercent") + " 周 " + drawPrizeNumberInfo.get("hourWeekCmpPercent") + ")\n"
                    +"抽獎人數 " + manTimeInfo.get("drawPrizeHour") + "\n"
                    +"(日 " + manTimeInfo.get("hourDayCmpPercent") + " 周 " + manTimeInfo.get("hourWeekCmpPercent") + ")\n"

                    +"--------獎勵發放資料--------\n"
                    +"抽得邀約資格次數 " + invitationNumberInfo.get("drawPrizeHour") + "\n"
                    +"(日 " + invitationNumberInfo.get("hourDayCmpPercent") + " 周 " + invitationNumberInfo.get("hourWeekCmpPercent") + ")\n"
                    +"抽得邀約資格次人數 " + invitationPeopleInfo.get("drawPrizeHour") + "\n"
                    +"(日 " + invitationPeopleInfo.get("hourDayCmpPercent") + " 周 " + invitationPeopleInfo.get("hourWeekCmpPercent") + ")\n"
                    +"抽得商城券次數 " + shopRpNumberInfo.get("drawPrizeHour") + "\n"
                    +"(日 " + shopRpNumberInfo.get("hourDayCmpPercent") + " 周 " + shopRpNumberInfo.get("hourWeekCmpPercent") + ")\n"
                    +"抽得商城券人數 " + shopRpPeopleInfo.get("drawPrizeHour") + "\n"
                    +"(日 " + shopRpPeopleInfo.get("hourDayCmpPercent") + " 周 " + shopRpPeopleInfo.get("hourWeekCmpPercent") + ")\n"
                    +"抽得1元紅包次數 " + oneYuanRpNumberInfo.get("drawPrizeHour") + "\n"
                    +"(日 " + oneYuanRpNumberInfo.get("hourDayCmpPercent") + " 周 " + oneYuanRpNumberInfo.get("hourWeekCmpPercent") + ")\n"
                    +"抽得1元紅包人數 " + oneYuanRpPeopleInfo.get("drawPrizeHour") + "\n"
                    +"(日 " + oneYuanRpPeopleInfo.get("hourDayCmpPercent") + " 周 " + oneYuanRpPeopleInfo.get("hourWeekCmpPercent") + ")\n"

                    +"--------獎勵使用資料--------\n"
                    +"邀約資格使用數 " + invitationUsedNumberInfo.get("drawPrizeHour") + "\n"
                    +"(日 " + invitationUsedNumberInfo.get("hourDayCmpPercent") + " 周 " + invitationUsedNumberInfo.get("hourWeekCmpPercent") + ")\n"
                    +"邀約資格使用人數 " + invitationUsedPeopleInfo.get("drawPrizeHour") + "\n"
                    +"(日 " + invitationUsedPeopleInfo.get("hourDayCmpPercent") + " 周 " + invitationUsedPeopleInfo.get("hourWeekCmpPercent") + ")\n"
                    +"商城券使用數 " + shopRpWithdrawNumberInfo.get("drawPrizeHour") + "\n"
                    +"(日 " + shopRpWithdrawNumberInfo.get("hourDayCmpPercent") + " 周 " + shopRpWithdrawNumberInfo.get("hourWeekCmpPercent") + ")\n"
                    +"商城券使用人數 " + shopRpWithdrawPeopleInfo.get("drawPrizeHour") + "\n"
                    +"(日 " + shopRpWithdrawPeopleInfo.get("hourDayCmpPercent") + " 周 " + shopRpWithdrawPeopleInfo.get("hourWeekCmpPercent") + ")\n"
                    +"1元紅包提現數 " + oneYuanRpWithdrawNumberInfo.get("drawPrizeHour") + "\n"
                    +"(日 " + oneYuanRpWithdrawNumberInfo.get("hourDayCmpPercent") + " 周 " + oneYuanRpWithdrawNumberInfo.get("hourWeekCmpPercent") + ")\n"
                    +"1元紅包提現人數 " + oneYuanRpWithdrawPeopleInfo.get("drawPrizeHour") + "\n"
                    +"(日 " + oneYuanRpWithdrawPeopleInfo.get("hourDayCmpPercent") + " 周 " + oneYuanRpWithdrawPeopleInfo.get("hourWeekCmpPercent") + ")\n"

                    +"****************************\n"
                    +"當天截止到" + getDeadlineTime() +"\n"
                    + "-----------概況-----------\n"
                    +"抽獎次數 " + drawPrizeNumberInfo.get("drawPrizeToday") + "\n"
                    +"(日 " + drawPrizeNumberInfo.get("dayDeadlineCmpPercent") + " 周 " + drawPrizeNumberInfo.get("weekDeadlineCmpPercent") + ")\n"
                    +"抽獎人數 " + manTimeInfo.get("drawPrizeToday") + "\n"
                    +"(日 " + manTimeInfo.get("dayDeadlineCmpPercent") + " 周 " + manTimeInfo.get("weekDeadlineCmpPercent") + ")\n"

                    +"--------獎勵發放資料--------\n"
                    +"抽得邀約資格次數 " + invitationNumberInfo.get("drawPrizeToday") + "\n"
                    +"(日 " + invitationNumberInfo.get("dayDeadlineCmpPercent") + " 周 " + invitationNumberInfo.get("weekDeadlineCmpPercent") + ")\n"
                    +"抽得邀約資格人數 " + invitationPeopleInfo.get("drawPrizeToday") + "\n"
                    +"(日 " + invitationPeopleInfo.get("dayDeadlineCmpPercent") + " 周 " + invitationPeopleInfo.get("weekDeadlineCmpPercent") + ")\n"
                    +"抽得商城券次數 " + shopRpNumberInfo.get("drawPrizeToday") + "\n"
                    +"(日 " + shopRpNumberInfo.get("dayDeadlineCmpPercent") + " 周 " + shopRpNumberInfo.get("weekDeadlineCmpPercent") + ")\n"
                    +"抽得商城券人數 " + shopRpPeopleInfo.get("drawPrizeToday") + "\n"
                    +"(日 " + shopRpPeopleInfo.get("dayDeadlineCmpPercent") + " 周 " + shopRpPeopleInfo.get("weekDeadlineCmpPercent") + ")\n"
                    +"抽得1元紅包次數 " + oneYuanRpNumberInfo.get("drawPrizeToday") + "\n"
                    +"(日 " + oneYuanRpNumberInfo.get("dayDeadlineCmpPercent") + " 周 " + oneYuanRpNumberInfo.get("weekDeadlineCmpPercent") + ")\n"
                    +"抽得1元紅包人數 " + oneYuanRpPeopleInfo.get("drawPrizeToday") + "\n"
                    +"(日 " + oneYuanRpPeopleInfo.get("dayDeadlineCmpPercent") + " 周 " + oneYuanRpPeopleInfo.get("weekDeadlineCmpPercent") + ")\n"

                    +"--------獎勵使用資料--------\n"
                    +"邀約資格使用數 " + invitationUsedNumberInfo.get("drawPrizeToday") + "\n"
                    +"(日 " + invitationUsedNumberInfo.get("dayDeadlineCmpPercent") + " 周 " + invitationUsedNumberInfo.get("weekDeadlineCmpPercent") + ")\n"
                    +"邀約資格使用人數 " + invitationUsedPeopleInfo.get("drawPrizeToday") + "\n"
                    +"(日 " + invitationUsedPeopleInfo.get("dayDeadlineCmpPercent") + " 周 " + invitationUsedPeopleInfo.get("weekDeadlineCmpPercent") + ")\n"
                    +"商城券使用數 " + shopRpWithdrawNumberInfo.get("drawPrizeToday") + "\n"
                    +"(日 " + shopRpWithdrawNumberInfo.get("dayDeadlineCmpPercent") + " 周 " + shopRpWithdrawNumberInfo.get("weekDeadlineCmpPercent") + ")\n"
                    +"商城券使用人數 " + shopRpWithdrawPeopleInfo.get("drawPrizeToday") + "\n"
                    +"(日 " + shopRpWithdrawPeopleInfo.get("dayDeadlineCmpPercent") + " 周 " + shopRpWithdrawPeopleInfo.get("weekDeadlineCmpPercent") + ")\n"
                    +"1元紅包提現數 " + oneYuanRpWithdrawNumberInfo.get("drawPrizeToday") + "\n"
                    +"(日 " + oneYuanRpWithdrawNumberInfo.get("dayDeadlineCmpPercent") + " 周 " + oneYuanRpWithdrawNumberInfo.get("weekDeadlineCmpPercent") + ")\n"
                    +"1元紅包提現人數 " + oneYuanRpWithdrawPeopleInfo.get("drawPrizeToday") + "\n"
                    +"(日 " + oneYuanRpWithdrawPeopleInfo.get("dayDeadlineCmpPercent") + " 周 " + oneYuanRpWithdrawPeopleInfo.get("weekDeadlineCmpPercent") + ")\n"


                    +"****************************\n"
                    +"本月截止到" + getDeadlineTime() +"\n"
                    + "-----------概況-----------\n"
                    +"抽獎次數 " + drawPrizeNumberInfo.get("drawPrizeMonth") + "\n"
                    +"(月 " + drawPrizeNumberInfo.get("monthCmpPercent") + ")\n"
                    +"抽獎人數 " + manTimeInfo.get("drawPrizeMonth") + "\n"
                    +"(月 " + manTimeInfo.get("monthCmpPercent") + ")\n"

                    +"--------獎勵發放資料--------\n"
                    +"抽得邀約資格次數 " + invitationNumberInfo.get("drawPrizeMonth") + "\n"
                    +"(月 " + invitationNumberInfo.get("monthCmpPercent")  + ")\n"
                    +"抽得邀約資格人數 " + invitationPeopleInfo.get("drawPrizeMonth") + "\n"
                    +"(月 " + invitationPeopleInfo.get("monthCmpPercent")  + ")\n"
                    +"抽得商城券次數 " + shopRpNumberInfo.get("drawPrizeMonth") + "\n"
                    +"(月 " + shopRpNumberInfo.get("monthCmpPercent")  + ")\n"
                    +"抽得商城券人數 " + shopRpPeopleInfo.get("drawPrizeMonth") + "\n"
                    +"(月 " + shopRpPeopleInfo.get("monthCmpPercent")  + ")\n"
                    +"抽得1元紅包次數 " + oneYuanRpNumberInfo.get("drawPrizeMonth") + "\n"
                    +"(月 " + oneYuanRpNumberInfo.get("monthCmpPercent")  + ")\n"
                    +"抽得1元紅包人數 " + oneYuanRpPeopleInfo.get("drawPrizeMonth") + "\n"
                    +"(月 " + oneYuanRpPeopleInfo.get("monthCmpPercent")  + ")\n"

                    +"--------獎勵使用資料--------\n"
                    +"邀約資格使用數 " + invitationUsedNumberInfo.get("drawPrizeMonth") + "\n"
                    +"(月 " + invitationUsedNumberInfo.get("monthCmpPercent") + ")\n"
                    +"邀約資格使用人數 " + invitationUsedPeopleInfo.get("drawPrizeMonth") + "\n"
                    +"(月 " + invitationUsedPeopleInfo.get("monthCmpPercent")  + ")\n"
                    +"商城券使用數 " + shopRpWithdrawNumberInfo.get("drawPrizeMonth") + "\n"
                    +"(月 " + shopRpWithdrawNumberInfo.get("monthCmpPercent")  + ")\n"
                    +"商城券使用人數 " + shopRpWithdrawPeopleInfo.get("drawPrizeMonth") + "\n"
                    +"(月 " + shopRpWithdrawPeopleInfo.get("monthCmpPercent")  + ")\n"
                    +"1元紅包提現數 " + oneYuanRpWithdrawNumberInfo.get("drawPrizeMonth") + "\n"
                    +"(月 " + oneYuanRpWithdrawNumberInfo.get("monthCmpPercent")  + ")\n"
                    +"1元紅包提現人數 " + oneYuanRpWithdrawPeopleInfo.get("drawPrizeMonth") + "\n"
                    +"(月 " + oneYuanRpWithdrawPeopleInfo.get("monthCmpPercent") + ")\n";

            Map<String, Object> text = new HashMap<>();
            text.put("content", content);
            Map<String, Object> at = new HashMap<>();
            at.put("atMobiles", new String[]{});
            at.put("isAtAll", false);

            Map<String, Object> param = new HashMap<>();
            param.put("text", text);
            param.put("msgtype", "text");
            param.put("at", at);
            HttpUtil.post(redPackageDingTalkAddress, JsonUtil.toString(param));
            LOG.info("[DrawPrizeDingTalkSchedule.pushDrawInfo] 傳送完成,傳送資訊:{}",JsonUtil.toString(param));

        }catch (Exception e){
            LOG.info("[DrawPrizeDingTalkSchedule.pushDrawInfo] 傳送資訊異常,時間:{}exp:{}",DateTimeUtils.formatDateHH(new Date()),e);
        }
    }

    /**
     * 獲取抽獎活動的小時區間
     * @return
     */
    private String getHourZone(){
        Date now= new Date();
        String nowDate = DateTimeUtils.formatDateHH(now);
        String beginDate = DateTimeUtils.formatDateHH(DateTimeUtils.addHours(now, -1));
        return  nowDate.substring(0,10) + beginDate.substring(10,16) + " - " + nowDate.substring(10,16);
    }

    private String getDeadlineTime() {
        Date now= new Date();
        String nowDate = DateTimeUtils.formatDateHH(now);
        return  nowDate.substring(0,16);
    }

    /**
     * 獲得統計指標的各項資料
     * @param className
     * @param methodName
     * @return
     */
    public Map<String,String> getStatisticsInfo(String className, String methodName){
        try {

            Map<String, String> result = new HashMap<>();

            //通過Spring容器獲得Dao物件,不能直接獲取
            WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext();
            Class<?>  cls = wac.getBean(className).getClass();
            Method method = cls.getMethod(methodName, Map.class);


            //分時-今日數量
            Date now = new Date();
            String nowDate = DateTimeUtils.formatDateHH(now);
            String beginDate = DateTimeUtils.formatDateHH(DateTimeUtils.addHours(now, -1));
            Map<String, Object> drawPrizeHourParams = new HashMap<>();
            drawPrizeHourParams.put("beginDate", beginDate);
            drawPrizeHourParams.put("endDate", nowDate);
            Integer drawPrizeHour = (Integer) method.invoke(wac.getBean(className), drawPrizeHourParams);
            if(drawPrizeHour == null) {
                drawPrizeHour = 0;
            }
            result.put("drawPrizeHour", drawPrizeHour.toString());

            //分時-日環比
            String dayBeforeEndDate = DateTimeUtils.formatDateHH(DateTimeUtils.addDays(now, -1));
            String dayBeforeBeginDate = DateTimeUtils.formatDateHH(DateTimeUtils.addHours(DateTimeUtils.addDays(now, -1), -1));
            Map<String, Object> drawPrizeHourBeforeParams = new HashMap<>();
            drawPrizeHourBeforeParams.put("beginDate", dayBeforeBeginDate);
            drawPrizeHourBeforeParams.put("endDate", dayBeforeEndDate);
            Integer drawPrizeHourBefore = (Integer) method.invoke(wac.getBean(className), drawPrizeHourBeforeParams);
            if(drawPrizeHourBefore == null || drawPrizeHourBefore.intValue() == 0) {
                drawPrizeHourBefore = 1;
            }
            String hourDayBeforePercent = getPercent(drawPrizeHour.intValue(), drawPrizeHourBefore.intValue());
            result.put("hourDayCmpPercent", hourDayBeforePercent);

            //分時-周環比
            String weekBeforeEndDate = DateTimeUtils.formatDateHH(DateTimeUtils.addDays(now, -7));
            String weekBeforeBeginDate = DateTimeUtils.formatDateHH(DateTimeUtils.addHours(DateTimeUtils.addDays(now, -7), -1));
            Map<String, Object> drawPrizeHourWeekBeforeParams = new HashMap<>();
            drawPrizeHourWeekBeforeParams.put("beginDate", weekBeforeBeginDate);
            drawPrizeHourWeekBeforeParams.put("endDate", weekBeforeEndDate);
            Integer drawPrizeWeekBefore = (Integer) method.invoke(wac.getBean(className), drawPrizeHourWeekBeforeParams);
            if(drawPrizeWeekBefore == null || drawPrizeWeekBefore.intValue() == 0) {
                drawPrizeWeekBefore = 1;
            }
            String hourWeekBeforePercent = getPercent(drawPrizeHour.intValue(), drawPrizeWeekBefore.intValue());
            result.put("hourWeekCmpPercent", hourWeekBeforePercent);

            //當日截止統計時間-今日數量
            String dayDeadlineDate = DateTimeUtils.formatDateHH(now);
            String dayDeadlineBeginDate = DateTimeUtils.formatDate(now) + " 00:00:00";
            Map<String, Object> drawPrizeTodayParams = new HashMap<>();
            drawPrizeTodayParams.put("beginDate", dayDeadlineBeginDate);
            drawPrizeTodayParams.put("endDate", dayDeadlineDate);
            Integer drawPrizeToday = (Integer) method.invoke(wac.getBean(className), drawPrizeTodayParams);
            if(drawPrizeToday == null) {
                drawPrizeToday = 0;
            }
            result.put("drawPrizeToday", drawPrizeToday.toString());


            //當日截止統計時間-日環比
            String dayDeadlineBeforeEndDate = DateTimeUtils.formatDateHH(DateTimeUtils.addDays(now, -1));
            String dayDeadlineBeforeBeginDate = DateTimeUtils.formatDate(DateTimeUtils.addDays(now, -1)) + " 00:00:00";
            Map<String, Object> drawPrizeDayDeadlineBeforeParams = new HashMap<>();
            drawPrizeDayDeadlineBeforeParams.put("beginDate", dayDeadlineBeforeBeginDate);
            drawPrizeDayDeadlineBeforeParams.put("endDate", dayDeadlineBeforeEndDate);
            Integer drawPrizeDayDeadlineBefore = (Integer) method.invoke(wac.getBean(className), drawPrizeDayDeadlineBeforeParams);
            if(drawPrizeDayDeadlineBefore == null || drawPrizeDayDeadlineBefore.intValue() == 0) {
                drawPrizeDayDeadlineBefore = 1;
            }
            String dayDeadlineBeforePercent = getPercent(drawPrizeToday.intValue(), drawPrizeDayDeadlineBefore.intValue());
            result.put("dayDeadlineCmpPercent", dayDeadlineBeforePercent);

            //當日截止統計時間-周環比
            String weekDeadlineBeforeEndDate = DateTimeUtils.formatDateHH(DateTimeUtils.addDays(now, -7));
            String weekDeadlineBeforeBeginDate = DateTimeUtils.formatDate(DateTimeUtils.addDays(now, -7)) + " 00:00:00";
            Map<String, Object> drawPrizeWeekDeadlineBeforeParams = new HashMap<>();
            drawPrizeWeekDeadlineBeforeParams.put("beginDate", weekDeadlineBeforeBeginDate);
            drawPrizeWeekDeadlineBeforeParams.put("endDate", weekDeadlineBeforeEndDate);
            Integer drawPrizeWeekDeadlineBefore = (Integer) method.invoke(wac.getBean(className), drawPrizeWeekDeadlineBeforeParams);
            if(drawPrizeWeekDeadlineBefore == null || drawPrizeWeekDeadlineBefore.intValue() == 0) {
                drawPrizeWeekDeadlineBefore = 1;
            }
            String weekDeadlineBeforePercent = getPercent(drawPrizeToday.intValue(), drawPrizeWeekDeadlineBefore.intValue());
            result.put("weekDeadlineCmpPercent", weekDeadlineBeforePercent);

            //當日截止統計時間-本月數量
            String monthDeadlineDate = DateTimeUtils.formatDateHH(now);
            String monthDeadlineBeginDate = DateTimeUtils.formatDate(DateTimeUtils.beginDateOfMonth(now,0,1)) + " 00:00:00";
            Map<String, Object> drawPrizeMonthParams = new HashMap<>();
            drawPrizeMonthParams.put("beginDate", monthDeadlineBeginDate);
            drawPrizeMonthParams.put("endDate", monthDeadlineDate);
            Integer drawPrizeMonth = (Integer) method.invoke(wac.getBean(className), drawPrizeMonthParams);
            if(drawPrizeMonth == null) {
                drawPrizeMonth = 0;
            }
            result.put("drawPrizeMonth", drawPrizeMonth.toString());

            //當日截止統計時間-月環比
            String monthBeforeDeadlineDate = DateTimeUtils.formatDateHH(DateTimeUtils.addMonths(now,-1));
            String monthBeforeDeadlineBeginDate = DateTimeUtils.formatDate(DateTimeUtils.beginDateOfMonth(now,-1,1)) + " 00:00:00";
            Map<String, Object> drawPrizeMonthBeforeParams = new HashMap<>();
            drawPrizeMonthBeforeParams.put("beginDate", monthBeforeDeadlineBeginDate);
            drawPrizeMonthBeforeParams.put("endDate", monthBeforeDeadlineDate);
            Integer drawPrizeMonthBefore = (Integer) method.invoke(wac.getBean(className), drawPrizeMonthBeforeParams);
            if(drawPrizeMonthBefore == null || drawPrizeMonthBefore.intValue() == 0) {
                drawPrizeMonthBefore = 1;
            }
            String monthBeforePercent = getPercent(drawPrizeMonth.intValue(), drawPrizeMonthBefore.intValue());
            result.put("monthCmpPercent", monthBeforePercent);

            return result;
        } catch (NoSuchMethodException e) {
            LOG.error("DrawPrizeDingTalkSchedule.getStatisticsInfo 獲取統計指標NoSuchMethodException異常, className:{}, methodName:{},exp:{}",className,methodName,e);
            return null;
        } catch (IllegalAccessException e) {
            LOG.error("DrawPrizeDingTalkSchedule.getStatisticsInfo 獲取統計指標IllegalAccessException異常, className:{}, methodName:{},exp:{}",className,methodName,e);
            return null;
        } catch (InvocationTargetException e) {
            LOG.error("DrawPrizeDingTalkSchedule.getStatisticsInfo 獲取統計指標InvocationTargetException異常, className:{}, methodName:{},exp:{}",className,methodName,e);
            return null;
        } catch (Exception e){
            LOG.error("DrawPrizeDingTalkSchedule.getStatisticsInfo 獲取統計指標Exception異常, className:{}, methodName:{},exp:{}",className,methodName,e);
            return null;
        }
    }


private String getPercent(int x, int y) {
    DecimalFormat df = new DecimalFormat("0.00%");
    if(y != 0){
        return df.format((x * 1.0 - y * 1.0) / (y * 1.0));
    }
    return df.format((x * 1.0) /1.0);
}
}