| @@ -20,6 +20,9 @@ import org.springframework.stereotype.Component; | |||||
| import java.util.List; | import java.util.List; | ||||
| /** | |||||
| * @author gongbiao | |||||
| */ | |||||
| @Component | @Component | ||||
| public class MsgSendingSchedule { | public class MsgSendingSchedule { | ||||
| @@ -31,26 +34,25 @@ public class MsgSendingSchedule { | |||||
| @Autowired | @Autowired | ||||
| private WxMsgConfigMapper wxMsgConfigMapper; | private WxMsgConfigMapper wxMsgConfigMapper; | ||||
| @Autowired | |||||
| private PushLimitService pushLimitService; | |||||
| @Scheduled(cron = "0 46 * * * ?") // 每小时第一分钟执行 | |||||
| /** | |||||
| * 每小时第一分钟执行 | |||||
| */ | |||||
| @Scheduled(cron = "0 1 * * * ?") | |||||
| public void sendmsgschedule() { | public void sendmsgschedule() { | ||||
| logger.info("sendmsg定时任务启动"); | logger.info("sendmsg定时任务启动"); | ||||
| String systemTime = DateUtils.getSystemTime("yyyy-MM-dd 14:00:00"); | |||||
| String systemTime = DateUtils.getSystemTime("yyyy-MM-dd HH:00:00"); | |||||
| WxMsg wxMsg = new WxMsg(); | WxMsg wxMsg = new WxMsg(); | ||||
| wxMsg.setIsright(0); | wxMsg.setIsright(0); | ||||
| wxMsg.setSendtime(systemTime); | wxMsg.setSendtime(systemTime); | ||||
| List<WxMsg> list = wxMsgMapper.findList(wxMsg); | List<WxMsg> list = wxMsgMapper.findList(wxMsg); | ||||
| logger.info("将要发送的短信列表:" + JSONArray.toJSONString(list)); | logger.info("将要发送的短信列表:" + JSONArray.toJSONString(list)); | ||||
| for(WxMsg msg:list){ | |||||
| for (WxMsg msg : list) { | |||||
| sendmsg(msg); | sendmsg(msg); | ||||
| } | } | ||||
| logger.info("sendmsg定时任务结束"); | logger.info("sendmsg定时任务结束"); | ||||
| } | } | ||||
| public void sendmsg(WxMsg wxMsg){ | |||||
| public void sendmsg(WxMsg wxMsg) { | |||||
| logger.info("发送短信开始----------"); | logger.info("发送短信开始----------"); | ||||
| //从短信配置中查询密钥 bid 等信息 | //从短信配置中查询密钥 bid 等信息 | ||||
| WxMsgConfig wxMsgConfig = new WxMsgConfig(); | WxMsgConfig wxMsgConfig = new WxMsgConfig(); | ||||
| @@ -61,11 +63,11 @@ public class MsgSendingSchedule { | |||||
| return; | return; | ||||
| } | } | ||||
| wxMsgConfig = wxMsgConfigs.get(0); | wxMsgConfig = wxMsgConfigs.get(0); | ||||
| if(wxMsgConfig.getRemains()==0){ | |||||
| if (wxMsgConfig.getRemains() == 0) { | |||||
| logger.info("短信数量为0"); | logger.info("短信数量为0"); | ||||
| return; | return; | ||||
| } | } | ||||
| if(wxMsgConfig.getRemains()<wxMsg.getExpectSendNumber()){ | |||||
| if (wxMsgConfig.getRemains() < wxMsg.getExpectSendNumber()) { | |||||
| logger.info("短信数量不足"); | logger.info("短信数量不足"); | ||||
| return; | return; | ||||
| } | } | ||||
| @@ -76,7 +78,7 @@ public class MsgSendingSchedule { | |||||
| String signature = wxMsg.getSignature(); | String signature = wxMsg.getSignature(); | ||||
| String msg = wxMsg.getMsg(); | String msg = wxMsg.getMsg(); | ||||
| String notifyUrl = wxMsgConfig.getNotifyurl(); | String notifyUrl = wxMsgConfig.getNotifyurl(); | ||||
| String result = WiwideUtil.sendMsg(secret, bid, publickey, phone, signature, msg, notifyUrl,EnumVerifyCode.NO.getCode().toString()); | |||||
| String result = WiwideUtil.sendMsg(secret, bid, publickey, phone, signature, msg, notifyUrl, EnumVerifyCode.NO.getCode().toString()); | |||||
| logger.info("短信返回结果:" + result); | logger.info("短信返回结果:" + result); | ||||
| JSONObject jsonObjectResult = JSONObject.parseObject(result); | JSONObject jsonObjectResult = JSONObject.parseObject(result); | ||||
| String ret = jsonObjectResult.get("ret").toString(); | String ret = jsonObjectResult.get("ret").toString(); | ||||