Authored by LiQZ

问题修复

package com.yoho.unions.channel.restapi;
import com.yoho.service.model.response.PageResponseBO;
import com.yoho.service.model.union.request.ChannelMessageRequest;
import com.yoho.service.model.union.request.ChannelUserBO;
import com.yoho.service.model.union.request.ChannelUserRequest;
import com.yoho.service.model.union.response.ChannelMessageDetailBO;
import com.yoho.unions.channel.service.IChannelUserService;
import com.yoho.unions.common.ApiResponse;
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.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
/**
... ... @@ -38,5 +38,13 @@ public class ChannelUserController {
return new ApiResponse.ApiResponseBuilder().data(page).build();
}
@ResponseBody
@RequestMapping("user_msg_list")
public ApiResponse userMessageList(ChannelMessageRequest request) {
logger.info("request params is {}", request);
PageResponseBO<ChannelMessageDetailBO> page = channelUserService.listMessage(request);
return new ApiResponse.ApiResponseBuilder().data(page).build();
}
}
... ...
package com.yoho.unions.channel.service;
import com.yoho.service.model.response.PageResponseBO;
import com.yoho.service.model.union.request.ChannelMessageRequest;
import com.yoho.service.model.union.request.ChannelUserBO;
import com.yoho.service.model.union.request.ChannelUserRequest;
import com.yoho.service.model.union.response.ChannelMessageDetailBO;
/**
* 渠道用户管理
... ... @@ -15,4 +17,10 @@ public interface IChannelUserService {
*/
PageResponseBO<ChannelUserBO> list(ChannelUserRequest request);
/**
* 查询手机号的发送记录
*/
PageResponseBO<ChannelMessageDetailBO> listMessage(ChannelMessageRequest request);
}
... ...
... ... @@ -4,13 +4,20 @@ import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.yoho.core.common.utils.Marker;
import com.yoho.error.exception.ServiceException;
import com.yoho.service.model.response.PageResponseBO;
import com.yoho.service.model.union.request.ChannelMessageRequest;
import com.yoho.service.model.union.request.ChannelUserBO;
import com.yoho.service.model.union.request.ChannelUserRequest;
import com.yoho.service.model.union.response.ChannelMessageDetailBO;
import com.yoho.unions.channel.service.IChannelUserService;
import com.yoho.unions.common.service.IBusinessExportService;
import com.yoho.unions.dal.IChannelGroupBatchDAO;
import com.yoho.unions.dal.IChannelSmsDetailDAO;
import com.yoho.unions.dal.IChannelUserDAO;
import com.yoho.unions.dal.model.ChannelGroupBatch;
import com.yoho.unions.dal.model.ChannelSmsDetail;
import com.yoho.unions.dal.model.ChannelUser;
import com.yoho.unions.utils.MapUtil;
import org.apache.commons.collections.CollectionUtils;
... ... @@ -24,6 +31,10 @@ import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import static com.yoho.unions.common.utils.YHPreconditions.*;
/**
* 范渠道用户管理
... ... @@ -37,6 +48,12 @@ public class ChannelUserServiceImpl implements IChannelUserService, IBusinessExp
@Autowired
private IChannelUserDAO channelUserDAO;
@Autowired
private IChannelSmsDetailDAO channelSmsDetailDAO;
@Autowired
private IChannelGroupBatchDAO channelGroupBatchDAO;
@Override
public PageResponseBO<ChannelUserBO> list(ChannelUserRequest request) {
// 设置查询参数
... ... @@ -59,6 +76,7 @@ public class ChannelUserServiceImpl implements IChannelUserService, IBusinessExp
List<ChannelUserBO> list = Lists.transform(users, input -> {
ChannelUserBO output = new ChannelUserBO();
BeanUtils.copyProperties(input, output);
output.setMobile(Marker.maskNumber(input.getMobile()));
return output;
});
... ... @@ -118,6 +136,49 @@ public class ChannelUserServiceImpl implements IChannelUserService, IBusinessExp
}
}
@Override
public PageResponseBO<ChannelMessageDetailBO> listMessage(ChannelMessageRequest request) {
ChannelUser channelUser = channelUserDAO.selectByPrimaryKey(request.getId());
checkNotNull(channelUser, "用户为空");
request.setMobile(channelUser.getMobile());
checkArgument(StringUtils.isNotBlank(request.getMobile()), "手机号不能为空");
// 先查手机号的发送记录
int count = channelSmsDetailDAO.selectCount(request.getMobile());
request.checkCurrentPage(count);
// 查询列表
List<ChannelSmsDetail> details = Collections.emptyList();
if (count > 0) {
details = channelSmsDetailDAO.selectPage(request.getMobile(), request.getStart(), request.getSize());
}
// 然后查询批次内容
List<Integer> batchIds = details.stream().map(ChannelSmsDetail::getGroupBatchId).collect(Collectors.toList());
List<ChannelGroupBatch> batchList = channelGroupBatchDAO.selectBatch(batchIds);
Map<Integer, ChannelGroupBatch> batchMap = batchList.stream().collect(Collectors.toMap(ChannelGroupBatch::getId, Function.identity()));
// 内容组装
List<ChannelMessageDetailBO> list = Lists.transform(details, input -> {
ChannelMessageDetailBO output = new ChannelMessageDetailBO();
output.setGroupBatchId(input.getGroupBatchId());
output.setStatus(input.getStatus() == null ? 0 : Integer.valueOf(input.getStatus()));
output.setSendTime(input.getCreateTime());
ChannelGroupBatch batch = batchMap.get(input.getGroupBatchId());
if (batch != null) {
output.setContent(batch.getContent());
}
return output;
});
// 设置返回参数
PageResponseBO<ChannelMessageDetailBO> page = new PageResponseBO<>();
page.setPage(request.getPage());
page.setPageSize(request.getSize());
page.setTotal(count);
page.setList(list);
return page;
}
}
... ...
... ... @@ -39,6 +39,7 @@
<value>/channel/getCondition</value>
<value>/channel/user_list</value>
<value>/channel/addGroup</value>
<value>/channel/user_msg_list</value>
<value>/LoginController/loginForPid.do</value>
<value>/batch/export.do</value>
</list>
... ...
package com.yoho.unions.dal;
import com.yoho.unions.dal.model.ChannelGroupBatch;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface IChannelGroupBatchDAO {
int deleteByPrimaryKey(Integer id);
... ... @@ -11,6 +14,8 @@ public interface IChannelGroupBatchDAO {
ChannelGroupBatch selectByPrimaryKey(Integer id);
List<ChannelGroupBatch> selectBatch(@Param("ids") List<Integer> ids);
int updateByPrimaryKeySelective(ChannelGroupBatch record);
int updateByPrimaryKey(ChannelGroupBatch record);
... ...
package com.yoho.unions.dal;
import com.yoho.unions.dal.model.ChannelSmsDetail;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
public interface IChannelSmsDetailDAO {
int deleteByPrimaryKey(Integer id);
... ... @@ -18,4 +20,9 @@ public interface IChannelSmsDetailDAO {
int updateByPrimaryKey(ChannelSmsDetail record);
int batchInsert(List<ChannelSmsDetail> list);
int selectCount(@Param("mobile") String mobile);
List<ChannelSmsDetail> selectPage(@Param("mobile") String mobile, @Param("offset") int offset, @Param("rows") int rows);
}
\ No newline at end of file
... ...
... ... @@ -21,6 +21,9 @@ public class ChannelGroupBatch {
this.sendUserName = sendUserName;
}
public ChannelGroupBatch() {
}
public ChannelGroupBatch(Integer groupId, String content, Integer sendTime, Integer sendUser, String sendUserName){
this.groupId = groupId;
this.content = content;
... ...
... ... @@ -11,6 +11,9 @@ public class ChannelSmsDetail {
private Integer createTime;
public ChannelSmsDetail() {
}
public ChannelSmsDetail(String mobile, Integer groupBatchId, Short status, Integer createTime) {
this.mobile = mobile;
this.groupBatchId = groupBatchId;
... ...
... ... @@ -18,6 +18,14 @@
from channel_group_batch
where id = #{id,jdbcType=INTEGER}
</select>
<select id="selectBatch" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from channel_group_batch
where id in <foreach item="item" index="index" collection="ids" open="(" separator="," close=")">
#{item}
</foreach>
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from channel_group_batch
where id = #{id,jdbcType=INTEGER}
... ...
... ... @@ -106,4 +106,18 @@
)
</foreach >
</insert >
<select id="selectCount" resultType="java.lang.Integer">
SELECT count(*) FROM channel_sms_detail c
WHERE c.mobile = #{mobile}
</select>
<select id="selectPage" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List" /> FROM channel_sms_detail c
WHERE c.mobile = #{mobile}
ORDER BY create_time DESC
limit #{offset}, #{rows}
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -92,6 +92,7 @@
</div>
<script type="text/javascript">
var checkedItems = [];
var smsId;
$(function () {
// 列表
var grid = $("#consultTable");
... ... @@ -195,7 +196,15 @@
title: "短信次数",
field: "smsNumber",
width: 80,
align: "center"
align: "center",
formatter: function (value, rowData, rowIndex) {
if(value > 0){
var str = "<a id='" + rowData.id + "' name='id' style='margin-left:10px'>"+value+"</a>";
return str;
}else{
return "-"
}
}
}, {
title: "最近一次短信时间",
field: "smsTime",
... ... @@ -208,7 +217,13 @@
pageList: [10],
idField: "id",
singleSelect: false,
checkOnSelect: false
checkOnSelect: false,
onLoadSuccess: function (data) {
$("a[name='id']").click(function () {
showMessageDetails(this.id);
return false;
});
}
});
function getParams() {
... ... @@ -304,6 +319,27 @@
});
function showMessageDetails(id) {
smsId = id;
var div = $("<div>").appendTo($(window.self.document.body));
window.self.$(div).myDialog({
modal : true,
collapsible : true,
cache : false,
title : "短信列表",
width: 600,
height: 600,
href: contextPath + "/html/channel/messageDetails.html?mobile="+id,
buttons : [{
id : "closeBtn",
text : "关闭",
iconCls : "icon-cancel",
handler : function() {
window.self.$(div).dialog('close');
}
}]
});
}
var fileview = $.extend({}, $.fn.datagrid.defaults.view, { onAfterRender: function (target) { isCheckItem(); } });
... ...
<table id="messageDetail"></table>
<script type="text/javascript">
$(function () {
// 列表
var grid2 = $("#messageDetail");
grid2.myDatagrid({
fit: true,
fitColumns: true,
nowrap: false,
url: contextPath + "/channel/user_msg_list",
method: 'POST',
queryParams: getId(),
loadFilter: function (data) {
var temp = defaultLoadFilter(data);
temp.rows = temp.list;
return temp;
},
columns: [[{
title: "批次号",
field: "groupBatchId",
width: 100,
align: "center"
}, {
title: "发送时间",
field: "sendTime",
width: 180,
align: "center"
}, {
title: "发送内容",
field: "content",
width: 120,
align: "center"
}, {
title: "发送结果",
field: "status",
width: 170,
align: "center"
}]],
cache: false,
pagination: true,
pageSize: 10,
pageList: [10],
singleSelect: false,
checkOnSelect: false
});
function getId() {
var params = {};
params["id"] = smsId;
return params;
}
});
</script>
\ No newline at end of file
... ...