数据库:MySQL 5.0 以上版本
建表脚本:
DROP TABLE IF EXISTS `sms_record`;
CREATE TABLE `sms_record` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`message_id` varchar(255) DEFAULT NULL COMMENT '消息编号',
`push_type` varchar(255) DEFAULT NULL COMMENT '推送类型',
`telephone` varchar(255) DEFAULT NULL COMMENT '电话号码',
`jim` varchar(255) DEFAULT NULL COMMENT '极光推送账号',
`entrance_type` int(11) DEFAULT NULL COMMENT '0:用户 1:保安 3:其他',
`identification` int(11) DEFAULT '0' COMMENT '是否发送成功(0:未发送成功,1:发送成功)',
`create_time` datetime DEFAULT NULL COMMENT '创建日期',
`up_time` datetime DEFAULT NULL COMMENT '修改日期',
`app_type` varchar(255) DEFAULT NULL COMMENT 'app类型',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=239 DEFAULT CHARSET=utf8;
mybatis.xml 文件配置,以下两种方式都可以。
方式一:
insert into wlsq_data.sms_record (id, message_id, push_type,
telephone, jim, entrance_type,
identification, create_time, up_time,
app_type)
values (#{id,jdbcType=INTEGER}, #{messageId,jdbcType=VARCHAR}, #{pushType,jdbcType=VARCHAR},
#{telephone,jdbcType=VARCHAR}, #{jim,jdbcType=VARCHAR}, #{entranceType,jdbcType=INTEGER},
#{identification,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{upTime,jdbcType=TIMESTAMP},
#{appType,jdbcType=VARCHAR})
select @@IDENTITY
insert into wlsq_data.sms_record (id, message_id, push_type,
telephone, jim, entrance_type,
identification, create_time, up_time,
app_type)
values (#{id,jdbcType=INTEGER}, #{messageId,jdbcType=VARCHAR}, #{pushType,jdbcType=VARCHAR},
#{telephone,jdbcType=VARCHAR}, #{jim,jdbcType=VARCHAR}, #{entranceType,jdbcType=INTEGER},
#{identification,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{upTime,jdbcType=TIMESTAMP},
#{appType,jdbcType=VARCHAR})
业务代码:
//添加过滤极光推送功能
SmsRecord androidRecord = new SmsRecord();
androidRecord.setMessageId(message_id);
androidRecord.setPushType("push");
androidRecord.setJim(openid);
androidRecord.setEntranceType(1);
List androidList = smsRecordService.selectByObject(androidRecord);
if(androidList !=null && androidList.size()>0){
System.out.println("用户指定极光推送id("+openid+")已经发送过");
}else{
androidRecord.setIdentification(0);
androidRecord.setCreateTime(new Date());
androidRecord.setAppType("gridAndroid");
int num = smsRecordService.insert(androidRecord);
if(num > 0){
gridAndroidPushService.AndroidSendPush("网格报警",alarmDataObj.getAlarm_content(),extras,openid,1,androidRecord.getId());
}
}