Authored by Amos_sdy

发短信日志记数据库

package com.yoho.message.dal;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.yoho.message.dal.model.MessageSmsLog;
public interface MessageSmsLogMapper {
int deleteByPrimaryKey(Integer id);
int insert(MessageSmsLog record);
int insertSelective(MessageSmsLog record);
MessageSmsLog selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(MessageSmsLog record);
int updateByPrimaryKeyWithBLOBs(MessageSmsLog record);
int updateByPrimaryKey(MessageSmsLog record);
void insertSmsLogBatch(@Param("logList") List<MessageSmsLog> logList);
}
\ No newline at end of file
... ...
package com.yoho.message.dal.model;
public class MessageSmsLog {
private Integer id;
private String mobile;
private Integer createTime;
private String sendScene;
private String content;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile == null ? null : mobile.trim();
}
public Integer getCreateTime() {
return createTime;
}
public void setCreateTime(Integer createTime) {
this.createTime = createTime;
}
public String getSendScene() {
return sendScene;
}
public void setSendScene(String sendScene) {
this.sendScene = sendScene == null ? null : sendScene.trim();
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content == null ? null : content.trim();
}
}
\ No newline at end of file
... ...
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.yoho.message.dal.MessageSmsLogMapper" >
<resultMap id="BaseResultMap" type="com.yoho.message.dal.model.MessageSmsLog" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="mobile" property="mobile" jdbcType="VARCHAR" />
<result column="create_time" property="createTime" jdbcType="INTEGER" />
<result column="send_scene" property="sendScene" jdbcType="VARCHAR" />
</resultMap>
<resultMap id="ResultMapWithBLOBs" type="com.yoho.message.dal.model.MessageSmsLog" extends="BaseResultMap" >
<result column="content" property="content" jdbcType="LONGVARCHAR" />
</resultMap>
<sql id="Base_Column_List" >
id, mobile, create_time, send_scene
</sql>
<sql id="Blob_Column_List" >
content
</sql>
<select id="selectByPrimaryKey" resultMap="ResultMapWithBLOBs" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
,
<include refid="Blob_Column_List" />
from message_sms_log
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from message_sms_log
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yoho.message.dal.model.MessageSmsLog" >
insert into message_sms_log (id, mobile, create_time,
send_scene, content)
values (#{id,jdbcType=INTEGER}, #{mobile,jdbcType=VARCHAR}, #{createTime,jdbcType=INTEGER},
#{sendScene,jdbcType=VARCHAR}, #{content,jdbcType=LONGVARCHAR})
</insert>
<insert id="insertSelective" parameterType="com.yoho.message.dal.model.MessageSmsLog" >
insert into message_sms_log
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="mobile != null" >
mobile,
</if>
<if test="createTime != null" >
create_time,
</if>
<if test="sendScene != null" >
send_scene,
</if>
<if test="content != null" >
content,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=INTEGER},
</if>
<if test="mobile != null" >
#{mobile,jdbcType=VARCHAR},
</if>
<if test="createTime != null" >
#{createTime,jdbcType=INTEGER},
</if>
<if test="sendScene != null" >
#{sendScene,jdbcType=VARCHAR},
</if>
<if test="content != null" >
#{content,jdbcType=LONGVARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yoho.message.dal.model.MessageSmsLog" >
update message_sms_log
<set >
<if test="mobile != null" >
mobile = #{mobile,jdbcType=VARCHAR},
</if>
<if test="createTime != null" >
create_time = #{createTime,jdbcType=INTEGER},
</if>
<if test="sendScene != null" >
send_scene = #{sendScene,jdbcType=VARCHAR},
</if>
<if test="content != null" >
content = #{content,jdbcType=LONGVARCHAR},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKeyWithBLOBs" parameterType="com.yoho.message.dal.model.MessageSmsLog" >
update message_sms_log
set mobile = #{mobile,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=INTEGER},
send_scene = #{sendScene,jdbcType=VARCHAR},
content = #{content,jdbcType=LONGVARCHAR}
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.yoho.message.dal.model.MessageSmsLog" >
update message_sms_log
set mobile = #{mobile,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=INTEGER},
send_scene = #{sendScene,jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER}
</update>
<insert id="insertSmsLogBatch" parameterType="com.yoho.message.dal.model.MessageSmsLog"
useGeneratedKeys="false">
INSERT INTO message_sms_log
(mobile, content, create_time, send_scene
)
VALUES
<foreach collection="logList" item="model" separator=",">
(
#{model.mobile}, #{model.content}, #{model.createTime}, #{model.sendScene}
)
</foreach>
</insert>
</mapper>
\ No newline at end of file
... ...
package com.yoho.yhmessage.sms.service.impl;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSONObject;
import com.yoho.message.dal.MessageSmsLogMapper;
import com.yoho.message.dal.model.MessageSmsLog;
import com.yoho.yhmessage.sms.service.ISmsLogService;
import com.yoho.yhmessage.sms.service.model.SmsLog;
... ... @@ -22,6 +30,9 @@ import com.yoho.yhmessage.sms.service.model.SmsLog;
public class SmsLogServiceImpl implements ISmsLogService {
private static final Logger sendSmsLog = LoggerFactory.getLogger("smsSendLog");
private static final Logger Logger = LoggerFactory.getLogger(SmsLogServiceImpl.class);
@Autowired
private MessageSmsLogMapper messageSmsLogMapper;
/**
*
* Description: 记录日志<br>
... ... @@ -39,5 +50,24 @@ public class SmsLogServiceImpl implements ISmsLogService {
smsLog.setMobile(StringUtils.trimToEmpty(mobile));
smsLog.setScene(StringUtils.trimToEmpty(scene));
sendSmsLog.info(JSONObject.toJSONString(smsLog));
// 记数据库
try {
List<String> mobileList = Arrays.asList(mobile.substring(1, mobile.length() - 1).split(","));
if (CollectionUtils.isNotEmpty(mobileList)) {
List<MessageSmsLog> messageSmsLogs = new ArrayList<MessageSmsLog>();
for (String temp : mobileList) {
MessageSmsLog log = new MessageSmsLog();
log.setMobile(temp);
log.setCreateTime((int) System.currentTimeMillis() / 1000);
log.setSendScene(scene);
log.setContent(content);
messageSmsLogs.add(log);
}
messageSmsLogMapper.insertSmsLogBatch(messageSmsLogs);
}
} catch (Exception e) {
Logger.error(e.getMessage(), e);
}
}
}
... ...
... ... @@ -28,6 +28,7 @@ datasources:
- com.yoho.message.dal.IRecycleTaskUserDao
- com.yoho.message.dal.SendTaskMapper
- com.yoho.message.dal.MessageFilterMapper
- com.yoho.message.dal.MessageSmsLogMapper
yoho_passport:
servers:
... ...
... ... @@ -38,6 +38,7 @@ datasources:
- com.yoho.message.dal.IRecycleTaskUserDao
- com.yoho.message.dal.SendTaskMapper
- com.yoho.message.dal.MessageFilterMapper
- com.yoho.message.dal.MessageSmsLogMapper
yoho_passport:
servers:
... ...