Authored by zhengwen.ge

短信

package com.monitor.model.request;
import com.monitor.model.page.PageRequest;
/**
* Created by yoho on 2016/11/29.
*/
public class SmsLogReq extends PageRequest {
private String mobile;
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
}
... ...
package com.model;
import java.util.Date;
/**
* Created by yoho on 2016/11/29.
*/
public class SMSLogs {
/**
* 手机号码
*/
private String mobile;
/**
* 创建时间
*/
private Date createTime;
/**
* 第一家短信运营商ID
*/
private Integer firstService;
public Integer getFirstServiceStatus() {
return firstServiceStatus;
}
public void setFirstServiceStatus(Integer firstServiceStatus) {
this.firstServiceStatus = firstServiceStatus;
}
/**
* 第一家短信运营商返回结果
*/
private String firstServiceReuslt;
/**
* 第一家短信运营商发送状态
*/
private Integer firstServiceStatus;
public Integer getFirstService() {
return firstService;
}
public void setFirstService(Integer firstService) {
this.firstService = firstService;
}
public String getFirstServiceReuslt() {
return firstServiceReuslt;
}
public void setFirstServiceReuslt(String firstServiceReuslt) {
this.firstServiceReuslt = firstServiceReuslt;
}
/**
* 短信发送内容
*/
private String content;
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
... ...
package com.monitor.mysql.mapper;
import com.model.SMSLogs;
import com.monitor.model.domain.PageBean;
import java.util.List;
/**
* Created by yoho on 2016/11/29.
*/
public interface SMSLogsMapper {
List<SMSLogs> selectByMobile(PageBean pageBean);
int selectCountByMobile(PageBean pageBean);
}
... ...
<?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.monitor.mysql.mapper.SMSLogsMapper" >
<resultMap id="BaseResultMap" type="com.model.SMSLogs" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="template_id" property="templateId" jdbcType="INTEGER" />
<result column="template_name" property="templateName" jdbcType="VARCHAR" />
<result column="ip" property="ip" jdbcType="VARCHAR" />
<result column="area" property="area" jdbcType="VARCHAR" />
<result column="mobile" property="mobile" jdbcType="VARCHAR" />
<result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
<result column="manage_status" property="manageStatus" jdbcType="INTEGER" />
<result column="first_service" property="firstService" jdbcType="INTEGER" />
<result column="first_service_reuslt" property="firstServiceReuslt" jdbcType="VARCHAR" />
<result column="first_service_status" property="firstServiceStatus" jdbcType="INTEGER" />
<result column="second_service" property="secondService" jdbcType="INTEGER" />
<result column="second_service_result" property="secondServiceResult" jdbcType="VARCHAR" />
<result column="second_service_status" property="secondServiceStatus" jdbcType="INTEGER" />
<result column="ext1" property="ext1" jdbcType="VARCHAR" />
<result column="ext2" property="ext2" jdbcType="VARCHAR" />
<result column="ext3" property="ext3" jdbcType="VARCHAR" />
</resultMap>
<resultMap id="ResultMapWithBLOBs" type="com.model.SMSLogs" extends="BaseResultMap" >
<result column="content" property="content" jdbcType="LONGVARCHAR" />
</resultMap>
<sql id="Base_Column_List" >
id, template_id, template_name, ip, area, mobile, create_time, update_time, manage_status,
first_service, first_service_reuslt, first_service_status, second_service, second_service_result,
second_service_status, ext1, ext2, ext3
</sql>
<sql id="Blob_Column_List" >
content
</sql>
<select id="selectByMobile" resultMap="ResultMapWithBLOBs">
select
<include refid="Base_Column_List" />
,
<include refid="Blob_Column_List" />
from sms_logs
where mobile = #{params.mobile}
order by create_time desc limit 10
</select>
<select id="selectCountByMobile" resultType="java.lang.Integer">
select
count(1)
from sms_logs where mobile = #{params.mobile}
</select>
</mapper>
\ No newline at end of file
... ...
package com.monitor.other.sms.ctrl;
import com.model.SMSLogs;
import com.monitor.model.request.SmsLogReq;
import com.monitor.model.response.BaseResponse;
import com.monitor.model.response.PageResponse;
import com.monitor.mysql.mapper.SMSLogsMapper;
import com.monitor.other.sms.service.SmsLogService;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
/**
* Created by yoho on 2016/11/29.
*/
@Controller
@RequestMapping("/sms")
public class SmsController {
Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
SmsLogService smsLogService;
@RequestMapping("/getSmsLogsByMobile")
@ResponseBody
public BaseResponse<PageResponse<SMSLogs>> getSmsLogsByMobile(@RequestBody SmsLogReq req){
logger.info("getSmsLogsByMobile mobile is {}",req.getMobile());
try {
String mobile = req.getMobile();
if(StringUtils.isEmpty(mobile)){
return new BaseResponse<>();
}
PageResponse<SMSLogs> pageResponse = smsLogService.getSmsLogs(req);
if (pageResponse == null ){
return new BaseResponse<>();
}
return new BaseResponse<PageResponse<SMSLogs>>(pageResponse);
}catch (Exception e){
logger.error("getSmsLogsByMobile ~",e);
return new BaseResponse<>();
}
}
}
... ...
package com.monitor.other.sms.service;
import com.model.SMSLogs;
import com.monitor.model.page.PageRequest;
import com.monitor.model.response.PageResponse;
/**
* Created by yoho on 2016/11/29.
*/
public interface SmsLogService {
PageResponse<SMSLogs> getSmsLogs(PageRequest req);
}
... ...
package com.monitor.other.sms.service.impl;
import com.model.SMSLogs;
import com.model.WorkJob;
import com.monitor.influxdb.util.DateFormatUtil;
import com.monitor.model.domain.PageBean;
import com.monitor.model.page.PageRequest;
import com.monitor.model.response.PageResponse;
import com.monitor.mysql.mapper.SMSLogsMapper;
import com.monitor.mysql.mapper.WorkJobMapper;
import com.monitor.other.sms.service.SmsLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* Created by yoho on 2016/11/29.
*/
@Service
public class SmsLogServiceImpl implements SmsLogService {
@Resource
private SMSLogsMapper smsLogsMapper;
public PageResponse<SMSLogs> getSmsLogs(PageRequest req){
// 组装分页对象
PageBean page = PageBean.initPageInfo(req.getCurrentPage(),
req.getPageSize(), req);
// 先查询符合条件的总数量
// int total = smsLogsMapper.selectCountByMobile(page);
int total = 10;
// 数量为0 直接返回
// if (total == 0) {
// // 返回初始page对象
// return null;
// }
// 获取列表
List<SMSLogs> list = new ArrayList<>();
SMSLogs smsLogs = new SMSLogs();
smsLogs.setContent("测试");
smsLogs.setCreateTime(DateFormatUtil.displayFormat("2016-05-09 17:01:33"));
smsLogs.setFirstService(13);
smsLogs.setFirstServiceStatus(1);
smsLogs.setMobile("15051889346");
list.add(smsLogs);
req.setCurrentPage(1);
req.setPageSize(10);
// List<SMSLogs> list = smsLogsMapper.selectByMobile(page);
// 获取列表
PageResponse<SMSLogs> response = new PageResponse<SMSLogs>();
response.setCurrentPage(req.getCurrentPage());
response.setPageSize(req.getPageSize());
response.setTotal(total);
response.setRows(list);
return response;
}
}
... ...